From 9c2b6db81b9d6870185cf825c4fcc801d27091db Mon Sep 17 00:00:00 2001 From: Kogepan229 Date: Mon, 23 Feb 2026 00:32:13 +0900 Subject: [PATCH] Add generic type support for interface --- .../github/util/DualityFluidInterface.java | 61 ++++++++++++++----- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/glodblock/github/util/DualityFluidInterface.java b/src/main/java/com/glodblock/github/util/DualityFluidInterface.java index e85e64365..b3c613925 100644 --- a/src/main/java/com/glodblock/github/util/DualityFluidInterface.java +++ b/src/main/java/com/glodblock/github/util/DualityFluidInterface.java @@ -3,7 +3,9 @@ import static appeng.util.item.AEFluidStackType.FLUID_STACK_TYPE; import static appeng.util.item.AEItemStackType.ITEM_STACK_TYPE; +import java.util.IdentityHashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import net.minecraft.inventory.IInventory; @@ -16,6 +18,9 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.AEFluidInventory; @@ -38,8 +43,10 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.IMEMonitor; import appeng.api.storage.IStorageMonitorable; +import appeng.api.storage.data.AEStackTypeRegistry; import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStackType; import appeng.api.util.IConfigManager; import appeng.core.settings.TickRates; import appeng.helpers.IInterfaceHost; @@ -67,12 +74,7 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable private final AEFluidInventory config = new AEFluidInventory(this, NUMBER_OF_TANKS, Integer.MAX_VALUE); private final IAEFluidStack[] requireWork; private int isWorking = -1; - private final MEMonitorPassThrough items = new MEMonitorPassThrough( - new NullInventory<>(), - ITEM_STACK_TYPE); - private final MEMonitorPassThrough fluids = new MEMonitorPassThrough( - new NullInventory<>(), - FLUID_STACK_TYPE); + private final Map, MEMonitorPassThrough> monitorMap; private boolean resetConfigCache = true; public DualityFluidInterface(final AENetworkProxy networkProxy, final IInterfaceHost ih) { @@ -80,8 +82,14 @@ public DualityFluidInterface(final AENetworkProxy networkProxy, final IInterface this.gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); this.iHost = ih; this.mySource = new MachineSource(this.iHost); - this.fluids.setChangeSource(this.mySource); - this.items.setChangeSource(this.mySource); + + this.monitorMap = new IdentityHashMap<>(); + for (IAEStackType type : AEStackTypeRegistry.getAllTypes()) { + MEMonitorPassThrough monitor = new MEMonitorPassThrough(new NullInventory<>(), type); + monitor.setChangeSource(mySource); + this.monitorMap.put(type, monitor); + } + this.requireWork = new IAEFluidStack[6]; for (int i = 0; i < 6; ++i) { @@ -113,13 +121,18 @@ public void onPowerStateChange(final MENetworkPowerStatusChange c) { this.notifyNeighbors(); } + @SuppressWarnings({ "unchecked", "rawtypes" }) public void gridChanged() { try { - this.items.setInternal(this.gridProxy.getStorage().getItemInventory()); - this.fluids.setInternal(this.gridProxy.getStorage().getFluidInventory()); - } catch (GridAccessException var2) { - this.items.setInternal(new NullInventory<>()); - this.fluids.setInternal(new NullInventory<>()); + for (var entry : this.monitorMap.entrySet()) { + MEMonitorPassThrough monitor = entry.getValue(); + IMEMonitor internal = this.gridProxy.getStorage().getMEMonitor(entry.getKey()); + monitor.setInternal(internal); + } + } catch (final GridAccessException gae) { + for (var monitor : this.monitorMap.values()) { + monitor.setInternal(new NullInventory<>()); + } } this.notifyNeighbors(); } @@ -198,14 +211,16 @@ public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) } @Override + @SuppressWarnings("unchecked") public IMEMonitor getItemInventory() { if (this.hasConfig) { return null; } - return this.items; + return (IMEMonitor) this.monitorMap.get(ITEM_STACK_TYPE); } @Override + @SuppressWarnings("unchecked") public IMEMonitor getFluidInventory() { if (this.hasConfig) { if (this.resetConfigCache) { @@ -213,7 +228,23 @@ public IMEMonitor getFluidInventory() { return new InterfaceInventory(this); } } - return this.fluids; + return (IMEMonitor) this.monitorMap.get(FLUID_STACK_TYPE); + } + + @Override + @Nullable + public IMEMonitor getMEMonitor(@NotNull IAEStackType type) { + if (type == ITEM_STACK_TYPE) { + return this.getItemInventory(); + } else if (type == FLUID_STACK_TYPE) { + return this.getFluidInventory(); + } + + if (this.hasConfig) { + return null; + } + + return this.monitorMap.get(type); } @Override