Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/gregtech/api/enums/MetaTileEntityIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,22 @@ public enum MetaTileEntityIDs {
SOLAR_PANEL_UV(2740),
VENDING_MACHINE_CONTROLLER(2741),
VENDING_MACHINE_UPLINK_ME(2742),
HATCH_OUTPUT_BUS_COMPRESSED_1(2743),
HATCH_OUTPUT_BUS_COMPRESSED_2(2744),
HATCH_OUTPUT_BUS_COMPRESSED_3(2745),
HATCH_OUTPUT_BUS_COMPRESSED_4(2746),
HATCH_OUTPUT_BUS_QUANTUM_1(2747),
HATCH_OUTPUT_BUS_QUANTUM_2(2748),
HATCH_OUTPUT_BUS_QUANTUM_3(2749),
HATCH_OUTPUT_BUS_QUANTUM_4(2750),
HATCH_INPUT_BUS_COMPRESSED_1(2751),
HATCH_INPUT_BUS_COMPRESSED_2(2752),
HATCH_INPUT_BUS_COMPRESSED_3(2753),
HATCH_INPUT_BUS_COMPRESSED_4(2754),
HATCH_INPUT_BUS_QUANTUM_1(2755),
HATCH_INPUT_BUS_QUANTUM_2(2756),
HATCH_INPUT_BUS_QUANTUM_3(2757),
HATCH_INPUT_BUS_QUANTUM_4(2758),
INDUSTRIAL_LASER_ENGRAVER_CONTROLLER(3004),
INDUSTRIAL_COMPRESSOR_CONTROLLER(3005),
HIP_COMPRESSOR_CONTROLLER(3006),
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/gregtech/api/enums/OutputBusType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
public enum OutputBusType {

Void,
CompressedFiltered,
StandardFiltered,
MEFiltered,
CompressedUnfiltered,
StandardUnfiltered,
MEUnfiltered,
//
;

public boolean isFiltered() {
return switch (this) {
case Void, StandardFiltered, MEFiltered -> true;
case StandardUnfiltered, MEUnfiltered -> false;
case Void, StandardFiltered, MEFiltered, CompressedFiltered -> true;
case StandardUnfiltered, MEUnfiltered, CompressedUnfiltered -> false;
};
}
}
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/gui/modularui/GTUITextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,5 @@ public static FallbackableUITexture fallbackableProgressbar(String name, UITextu
public static final UITexture PICTURE_ITEM_OUT = UITexture.fullImage(GregTech.ID, "gui/picture/item_out");
public static final UITexture PICTURE_FLUID_IN = UITexture.fullImage(GregTech.ID, "gui/picture/fluid_in");
public static final UITexture PICTURE_FLUID_OUT = UITexture.fullImage(GregTech.ID, "gui/picture/fluid_out");
public static final UITexture SCREWDRIVER = UITexture.fullImage(GregTech.ID, "gui/overlay_button/screwdriver");
}
30 changes: 30 additions & 0 deletions src/main/java/gregtech/api/implementation/items/GTItemSink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gregtech.api.implementation.items;

import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;

import com.gtnewhorizon.gtnhlib.capability.item.InventoryItemSink;

import gregtech.api.interfaces.metatileentity.IMetaTileEntity;

public class GTItemSink extends InventoryItemSink {

public GTItemSink(IMetaTileEntity imte, ForgeDirection side) {
super(imte, side);
}

@Override
protected int getSlotStackLimit(int slot, ItemStack stack) {
// Cast here instead of storing it as a field because this is called in the super ctor, and by that point a
// field wouldn't have been set, leading to an NPE
int invStackLimit = ((IMetaTileEntity) inv).getStackSizeLimit(slot, stack);

int existingMaxStack = stack == null ? 64 : stack.getMaxStackSize();

if (invStackLimit > 64) {
return invStackLimit / 64 * existingMaxStack;
} else {
return Math.min(invStackLimit, existingMaxStack);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gregtech.api.interfaces.item;

import net.minecraft.item.ItemStack;

public interface ItemStackSizeCalculator {

int getSlotStackLimit(int slot, ItemStack stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ default void onUnload() {}
*/
boolean isValidSlot(int aIndex);

/**
* Gets the max stack size limit for a slot and a stack.
*
* @param slot The slot, or -1 for a general 'lowest slot' query.
* @param stack The stack, or null for a general 'any standard stack' query (getMaxStackSize() == 64).
*/
default int getStackSizeLimit(int slot, @Nullable ItemStack stack) {
return Math.min(getInventoryStackLimit(), stack == null ? 64 : stack.getMaxStackSize());
}

/**
* Check if the item at the specified index should be dropped
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ protected void saveMetaTileNBT(NBTTagCompound aNBT) {
final NBTTagCompound tTag = new NBTTagCompound();
tTag.setInteger("IntSlot", i);
tStack.writeToNBT(tTag);
if (tStack.stackSize > Byte.MAX_VALUE) {
tTag.setInteger("Count", tStack.stackSize);
}
tItemList.appendTag(tTag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.UISettings;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.gtnewhorizon.gtnhlib.capability.item.IItemIO;
import com.gtnewhorizon.gtnhlib.capability.item.IItemSink;
import com.gtnewhorizon.gtnhlib.capability.item.IItemSource;
import com.gtnewhorizon.gtnhlib.capability.item.InventoryItemSource;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand All @@ -34,6 +38,7 @@
import gregtech.api.GregTechAPI;
import gregtech.api.enums.GTValues;
import gregtech.api.gui.modularui.GTUIInfos;
import gregtech.api.implementation.items.GTItemSink;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
Expand Down Expand Up @@ -109,6 +114,28 @@ protected CommonMetaTileEntity(String name, int invSlotCount) {
@Nullable
@Override
public <T> T getCapability(@NotNull Class<T> capability, @NotNull ForgeDirection side) {
if (capability == IItemSink.class) {
return capability.cast(getItemSink(side));
}
if (capability == IItemSource.class) {
return capability.cast(getItemSource(side));
}
if (capability == IItemIO.class) {
return capability.cast(getItemIO(side));
}

return null;
}

protected IItemSink getItemSink(ForgeDirection side) {
return new GTItemSink(this, side);
}

protected IItemSource getItemSource(ForgeDirection side) {
return new InventoryItemSource(this, side);
}

protected IItemIO getItemIO(ForgeDirection side) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static gregtech.api.metatileentity.BaseTileEntity.UNUSED_SLOT_TOOLTIP;
import static gregtech.api.util.GTRecipeConstants.EXPLODE;
import static gregtech.api.util.GTRecipeConstants.ON_FIRE;
import static gregtech.api.util.GTUtility.moveMultipleItemStacks;
import static net.minecraft.util.StatCollector.translateToLocal;
import static net.minecraft.util.StatCollector.translateToLocalFormatted;
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
Expand Down Expand Up @@ -84,6 +83,7 @@
import gregtech.api.recipe.metadata.CompressionTierKey;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTClientPreference;
import gregtech.api.util.GTItemTransfer;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTRecipe;
Expand Down Expand Up @@ -604,18 +604,14 @@ else if (mOutputFluid.isFluidEqual(getDrainableStack()))
int tMaxStacks = (int) (tStoredEnergy / 64L);
if (tMaxStacks > mOutputItems.length) tMaxStacks = mOutputItems.length;

moveMultipleItemStacks(
aBaseMetaTileEntity,
tTileEntity2,
aBaseMetaTileEntity.getFrontFacing(),
aBaseMetaTileEntity.getBackFacing(),
null,
false,
(byte) 64,
(byte) 1,
(byte) 64,
(byte) 1,
tMaxStacks);
GTItemTransfer transfer = new GTItemTransfer();

transfer.outOfMachine(this, aBaseMetaTileEntity.getFrontFacing());
transfer.dropItems(this);

transfer.setStacksToTransfer(tMaxStacks);

transfer.transfer();
}

if (mOutputBlocked != 0) if (isOutputEmpty()) mOutputBlocked = 0;
Expand Down Expand Up @@ -956,12 +952,17 @@ public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aInde
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
if (side == mMainFacing || aIndex < getInputSlot()
|| aIndex >= getInputSlot() + mInputSlotCount
|| (!mAllowInputFromOutputSide && side == aBaseMetaTileEntity.getFrontFacing())) return false;
for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++)
if (GTUtility.areStacksEqual(GTOreDictUnificator.get(aStack), mInventory[i]) && mDisableMultiStack)
if (side == mMainFacing) return false;
if (aIndex < getInputSlot()) return false;
if (aIndex >= getInputSlot() + mInputSlotCount) return false;
if (!mAllowInputFromOutputSide && side == aBaseMetaTileEntity.getFrontFacing()) return false;

for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) {
if (GTUtility.areStacksEqual(GTOreDictUnificator.get(aStack), mInventory[i]) && mDisableMultiStack) {
return i == aIndex;
}
}

return mDisableFilter || allowPutStackValidated(aBaseMetaTileEntity, aIndex, side, aStack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT;
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.OptionalInt;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.IntStream;
Expand All @@ -28,6 +26,7 @@
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;

import com.gtnewhorizon.gtnhlib.capability.item.IItemSink;
import com.gtnewhorizons.modularui.api.drawable.UITexture;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
Expand All @@ -40,6 +39,7 @@
import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTItemTransfer;
import gregtech.api.util.GTTooltipDataCache;
import gregtech.api.util.GTUtility;

Expand Down Expand Up @@ -334,7 +334,6 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
|| aTimer % 200 == 0
|| mSuccess > 0)) {
mSuccess--;
updateSlots();
moveItems(aBaseMetaTileEntity, aTimer);
handleRedstoneOutput(aBaseMetaTileEntity);
}
Expand All @@ -344,35 +343,40 @@ protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
moveItems(aBaseMetaTileEntity, aTimer, 1);
}

protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long ignoredTimer, int stacks) {
int tCost;
if (bStockingMode) tCost = GTUtility.moveMultipleItemStacks(
aBaseMetaTileEntity,
aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getBackFacing()),
aBaseMetaTileEntity.getBackFacing(),
aBaseMetaTileEntity.getFrontFacing(),
null,
false,
mTargetStackSize == 0 ? 64 : (byte) mTargetStackSize,
mTargetStackSize == 0 ? 1 : (byte) mTargetStackSize,
(byte) 64,
(byte) 1,
stacks);
else tCost = GTUtility.moveMultipleItemStacks(
aBaseMetaTileEntity,
aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getBackFacing()),
aBaseMetaTileEntity.getBackFacing(),
aBaseMetaTileEntity.getFrontFacing(),
null,
false,
(byte) 64,
(byte) 1,
mTargetStackSize == 0 ? 64 : (byte) mTargetStackSize,
mTargetStackSize == 0 ? 1 : (byte) mTargetStackSize,
stacks);

if (tCost > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) {
protected void moveItems(IGregTechTileEntity igte, long ignoredTimer, int stacks) {
GTItemTransfer transfer = new GTItemTransfer();

transfer.source(igte, ForgeDirection.UNKNOWN);
transfer.sink(igte.getTileEntityAtSide(igte.getBackFacing()), igte.getFrontFacing());

transfer.setStacksToTransfer(stacks);

if (mTargetStackSize > 0) {
if (bStockingMode) {
IItemSink sink = transfer.getSink();

if (sink == null) return;

OptionalInt stored = sink.getStoredAmount(null);

if (!stored.isPresent()) return;

int toTransfer = mTargetStackSize - stored.getAsInt();

transfer.setMaxTotalTransferred(toTransfer);
} else {
transfer.setFilter(stack -> stack.stackSize >= mTargetStackSize);
transfer.setMaxItemsPerTransfer(mTargetStackSize);
}
}

if (transfer.transfer() > 0 || igte.hasInventoryBeenModified()) {
mSuccess = 50;

GTUtility.cleanInventory(this);
if (bSortStacks) {
GTUtility.compactInventory(this);
}
}
}

Expand All @@ -393,42 +397,6 @@ public boolean allowGeneralRedstoneOutput() {
return true;
}

public void updateSlots() {
for (int i = 0; i < mInventory.length; i++)
if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null;
if (bSortStacks) fillStacksIntoFirstSlots();
}

protected void fillStacksIntoFirstSlots() {
HashMap<GTUtility.ItemId, Integer> slots = new HashMap<>(mInventory.length);
HashMap<GTUtility.ItemId, ItemStack> stacks = new HashMap<>(mInventory.length);
List<GTUtility.ItemId> order = new ArrayList<>(mInventory.length);
List<Integer> validSlots = new ArrayList<>(mInventory.length);
for (int i = 0; i < mInventory.length - 1; i++) {
if (!isValidSlot(i)) continue;
validSlots.add(i);
ItemStack s = mInventory[i];
if (s == null) continue;
GTUtility.ItemId sID = GTUtility.ItemId.createNoCopy(s);
slots.merge(sID, s.stackSize, Integer::sum);
if (!stacks.containsKey(sID)) stacks.put(sID, s);
order.add(sID);
mInventory[i] = null;
}
int slotindex = 0;
for (GTUtility.ItemId sID : order) {
int toSet = slots.get(sID);
if (toSet == 0) continue;
int slot = validSlots.get(slotindex);
slotindex++;
mInventory[slot] = stacks.get(sID)
.copy();
toSet = Math.min(toSet, mInventory[slot].getMaxStackSize());
mInventory[slot].stackSize = toSet;
slots.merge(sID, toSet, (a, b) -> a - b);
}
}

@Override
public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide,
EntityPlayer entityPlayer, float aX, float aY, float aZ, ItemStack aTool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,16 @@ protected void addOneStackLimitButton(ModularWindow.Builder builder) {
}, GTUITextures.OVERLAY_BUTTON_ONE_STACK_LIMIT, () -> mTooltipCache.getData(ONE_STACK_LIMIT_TOOLTIP)));
}

@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
protected void addInputBusUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
buildContext.addCloseListener(() -> uiButtonCount = 0);
addSortStacksButton(builder);
addOneStackLimitButton(builder);
}

@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
addInputBusUIWidgets(builder, buildContext);

// Remove one for ghost circuit slot
int slotCount = getSizeInventory();
if (allowSelectCircuit()) {
Expand Down
Loading