aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech
diff options
context:
space:
mode:
authorJaiden Baker <jaidencolebaker@gmail.com>2023-09-13 20:44:42 +1200
committerGitHub <noreply@github.com>2023-09-13 10:44:42 +0200
commit62bb20ef6271b09dab45d66103a185774aba523e (patch)
tree220291daf534c7a4eb0fa2d8331c97ff132c9781 /src/main/java/gregtech
parent999327f2e4e7a4c9d4e1a8dbd2ad11c4ced1d4a5 (diff)
downloadGT5-Unofficial-62bb20ef6271b09dab45d66103a185774aba523e.tar.gz
GT5-Unofficial-62bb20ef6271b09dab45d66103a185774aba523e.tar.bz2
GT5-Unofficial-62bb20ef6271b09dab45d66103a185774aba523e.zip
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
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java34
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java15
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java10
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java5
4 files changed, 58 insertions, 6 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index ff2ecfa83f..8890f025e9 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.TestOnly;
import org.lwjgl.input.Keyboard;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
@@ -82,11 +83,7 @@ import gregtech.client.GT_SoundLoop;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.modularui.widget.CheckRecipeResultSyncer;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
-import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME;
-import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME;
-import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME;
-import gregtech.common.tileentities.machines.IDualInputHatch;
-import gregtech.common.tileentities.machines.IDualInputInventory;
+import gregtech.common.tileentities.machines.*;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
@@ -1330,6 +1327,19 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
public ArrayList<FluidStack> getStoredFluids() {
+ if (supportsCraftingMEBuffer()) {
+ for (IDualInputHatch tHatch : mDualInputHatches) {
+ if (tHatch.supportsFluids()) {
+ Optional<IDualInputInventory> inventory = tHatch.getFirstNonEmptyInventory();
+ if (inventory.isPresent()) {
+ return Lists.newArrayList(
+ inventory.get()
+ .getFluidInputs());
+ }
+ }
+ }
+ }
+
ArrayList<FluidStack> rList = new ArrayList<>();
for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
tHatch.mRecipeMap = getRecipeMap();
@@ -1349,12 +1359,25 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
}
}
+
return rList;
}
public ArrayList<ItemStack> getStoredInputs() {
+ if (supportsCraftingMEBuffer()) {
+ for (IDualInputHatch tHatch : mDualInputHatches) {
+ Optional<IDualInputInventory> inventory = tHatch.getFirstNonEmptyInventory();
+ if (inventory.isPresent()) {
+ return Lists.newArrayList(
+ inventory.get()
+ .getItemInputs());
+ }
+ }
+ }
+
ArrayList<ItemStack> rList = new ArrayList<>();
HashMap<String, ItemStack> rInputBusMeList = new HashMap<>();
+
for (GT_MetaTileEntity_Hatch_InputBus tHatch : mInputBusses) {
tHatch.mRecipeMap = getRecipeMap();
if (isValidMetaTileEntity(tHatch)) {
@@ -1372,6 +1395,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
}
}
}
+
if (getStackInSlot(1) != null && getStackInSlot(1).getUnlocalizedName()
.startsWith("gt.integrated_circuit")) rList.add(getStackInSlot(1));
if (!rInputBusMeList.isEmpty()) rList.addAll(rInputBusMeList.values());
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<IDualInputInventory> 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
@@ -144,6 +144,16 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti
}
@Override
+ public Optional<IDualInputInventory> 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<IDualInputInventory> getFirstNonEmptyInventory();
+
+ public boolean supportsFluids();
}