From 62bb20ef6271b09dab45d66103a185774aba523e Mon Sep 17 00:00:00 2001 From: Jaiden Baker Date: Wed, 13 Sep 2023 20:44:42 +1200 Subject: Make Crafting Input Bus / Hatch compatible with some non-GPL multis (#2266) * Add crafting input bus items to getStoredInputs * Add crafting input hatch fluids to getStoredFluids * Respect internal input isolation * List.of -> Arrays.asList * Skip fluids on non-supporting bus * Fix NPE * Change return type to Optional & add Slave support --- .../GT_MetaTileEntity_Hatch_CraftingInput_ME.java | 15 ++++++++++++++- .../GT_MetaTileEntity_Hatch_CraftingInput_Slave.java | 10 ++++++++++ .../common/tileentities/machines/IDualInputHatch.java | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java index 83a5789430..e7af09ef90 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java @@ -715,7 +715,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ needPatternSync = true; } - private ItemStack[] getSharedItems() { + public ItemStack[] getSharedItems() { ItemStack[] sharedItems = new ItemStack[SLOT_MANUAL_SIZE + 1]; sharedItems[0] = mInventory[SLOT_CIRCUIT]; System.arraycopy(mInventory, SLOT_MANUAL_START, sharedItems, 1, SLOT_MANUAL_SIZE); @@ -952,4 +952,17 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ public void setCustomName(String name) { customName = name; } + + @Override + public Optional getFirstNonEmptyInventory() { + for (PatternSlot slot : internalInventory) { + if (slot != null && !slot.isEmpty()) return Optional.of(slot); + } + return Optional.empty(); + } + + @Override + public boolean supportsFluids() { + return this.supportFluids; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java index 2ea053995c..f2048f82ce 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java @@ -143,6 +143,16 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti return getMaster() != null ? getMaster().inventories() : Collections.emptyIterator(); } + @Override + public Optional getFirstNonEmptyInventory() { + return getMaster() != null ? getMaster().getFirstNonEmptyInventory() : Optional.empty(); + } + + @Override + public boolean supportsFluids() { + return getMaster() != null && getMaster().supportsFluids(); + } + @Override public boolean justUpdated() { return getMaster() != null && getMaster().justUpdated(); diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index 54b1acbdfa..c89aaaff40 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -1,6 +1,7 @@ package gregtech.common.tileentities.machines; import java.util.Iterator; +import java.util.Optional; import net.minecraft.item.ItemStack; @@ -13,4 +14,8 @@ public interface IDualInputHatch { void updateTexture(int id); void updateCraftingIcon(ItemStack icon); + + Optional getFirstNonEmptyInventory(); + + public boolean supportsFluids(); } -- cgit