From 1e83be0d4708d1133a876c733bbedb8707a08ce6 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:01:56 -0700 Subject: [PATCH 001/103] initial work of multi abilities --- .../multiblock/IMultiblockAbilityPart.java | 10 ++- .../multiblock/MultiblockAbility.java | 16 ++++- .../multiblock/MultiblockControllerBase.java | 14 ++-- .../electric/MetaTileEntityDiode.java | 5 +- .../electric/MetaTileEntityHull.java | 5 +- .../multi/MetaTileEntityPumpHatch.java | 6 +- .../multi/MetaTileEntityTankValve.java | 5 +- .../MetaTileEntityAutoMaintenanceHatch.java | 6 +- .../MetaTileEntityComputationHatch.java | 5 +- .../MetaTileEntityDataAccessHatch.java | 4 +- .../MetaTileEntityEnergyHatch.java | 5 +- .../MetaTileEntityFluidHatch.java | 69 +++++++++++++++++-- .../multiblockpart/MetaTileEntityItemBus.java | 4 +- .../MetaTileEntityLaserHatch.java | 4 +- .../MetaTileEntityMachineHatch.java | 5 +- .../MetaTileEntityMaintenanceHatch.java | 5 +- .../MetaTileEntityMufflerHatch.java | 5 +- .../MetaTileEntityMultiFluidHatch.java | 6 +- .../MetaTileEntityObjectHolder.java | 5 +- .../MetaTileEntityOpticalDataHatch.java | 5 +- .../MetaTileEntityPassthroughHatchFluid.java | 5 +- .../MetaTileEntityPassthroughHatchItem.java | 5 +- .../MetaTileEntityReservoirHatch.java | 5 +- .../MetaTileEntityRotorHolder.java | 5 +- .../appeng/MetaTileEntityMEInputBus.java | 5 +- .../appeng/MetaTileEntityMEInputHatch.java | 5 +- .../appeng/MetaTileEntityMEOutputBus.java | 5 +- .../appeng/MetaTileEntityMEOutputHatch.java | 5 +- .../hpca/MetaTileEntityHPCAComponent.java | 5 +- .../MetaTileEntitySteamHatch.java | 5 +- .../MetaTileEntitySteamItemBus.java | 5 +- 31 files changed, 179 insertions(+), 65 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index d71121f196d..2f535feafd7 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -1,10 +1,18 @@ package gregtech.api.metatileentity.multiblock; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; import java.util.List; public interface IMultiblockAbilityPart extends IMultiblockPart { MultiblockAbility getAbility(); - void registerAbilities(List abilityList); + default @NotNull List> getAbilities() { + return Collections.singletonList(getAbility()); + } + + @NotNull + List registerAbilities(@NotNull MultiblockAbility key); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 4c23893823c..b5187267437 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -83,7 +83,21 @@ public static void registerMultiblockAbility(MultiblockAbility ability, MetaT REGISTRY.get(ability).add(part); } + private final String name; + public MultiblockAbility(String name) { - NAME_REGISTRY.put(name.toLowerCase(), this); + this.name = name.toLowerCase(); + NAME_REGISTRY.put(this.name, this); + } + + @Override + public String toString() { + return name; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof MultiblockAbilityother && + this.name.equals(other.toString()); } } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index ff3848b1557..0034534fe12 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -333,6 +333,7 @@ protected Function multiblockPartSorter() { return BlockPos::hashCode; } + @SuppressWarnings({ "rawtypes", "unchecked" }) public void checkStructurePattern() { if (structurePattern == null) return; PatternMatchContext context = structurePattern.checkPatternFastAt(getWorld(), getPos(), @@ -351,12 +352,13 @@ public void checkStructurePattern() { parts.sort(Comparator.comparing(it -> multiblockPartSorter().apply(((MetaTileEntity) it).getPos()))); Map, List> abilities = new HashMap<>(); for (IMultiblockPart multiblockPart : parts) { - if (multiblockPart instanceof IMultiblockAbilityPart) { - @SuppressWarnings("unchecked") - IMultiblockAbilityPart abilityPart = (IMultiblockAbilityPart) multiblockPart; - List abilityInstancesList = abilities.computeIfAbsent(abilityPart.getAbility(), - k -> new ArrayList<>()); - abilityPart.registerAbilities(abilityInstancesList); + if (multiblockPart instanceof IMultiblockAbilityPart multiblockAbilityPart) { + List m = multiblockAbilityPart.getAbilities(); + for (MultiblockAbility ability : m) { + List abilityInstancesList = abilities.computeIfAbsent(ability, + k -> new ArrayList<>()); + abilityInstancesList.addAll(multiblockAbilityPart.registerAbilities(ability)); + } } } this.multiblockParts.addAll(parts); diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index c19b1797f96..3fb8af48f16 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static gregtech.api.capability.GregtechDataCodes.AMP_INDEX; @@ -177,8 +178,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java index 328c9d08884..45231ed2fe8 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java @@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityHull extends MetaTileEntityMultiblockPart @@ -110,8 +111,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java index dc158cd074a..f4d29e296f5 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java @@ -32,8 +32,10 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityPumpHatch extends MetaTileEntityMultiblockPart @@ -103,8 +105,8 @@ public ICubeRenderer getBaseTexture() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(exportFluids.getTankAt(0)); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(exportFluids.getTankAt(0)); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java index 13f9c9657f3..8d3e3f44297 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityTankValve extends MetaTileEntityMultiblockPart @@ -122,8 +123,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this.getImportFluids()); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this.getImportFluids()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java index c1ac8373b43..82f58689c89 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java @@ -20,8 +20,10 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityAutoMaintenanceHatch extends MetaTileEntityMultiblockPart implements @@ -104,8 +106,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java index 85c2bc25173..ac4817088ef 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Collections; import java.util.List; public class MetaTileEntityComputationHatch extends MetaTileEntityMultiblockPart implements @@ -151,8 +152,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index a50acc06ba0..1a849aab8ec 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -213,8 +213,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index fd79fc8811d..e99df927acc 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -34,6 +34,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.lang.ref.WeakReference; import java.util.List; @@ -116,8 +117,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(energyContainer); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(energyContainer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 935d40d451f..8d8290374be 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -1,8 +1,14 @@ package gregtech.common.metatileentities.multi.multiblockpart; -import gregtech.api.capability.*; +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IControllable; +import gregtech.api.capability.IFilter; +import gregtech.api.capability.IFilteredFluidContainer; +import gregtech.api.capability.IGhostSlotConfigurable; import gregtech.api.capability.impl.FilteredItemHandler; import gregtech.api.capability.impl.FluidTankList; +import gregtech.api.capability.impl.GhostCircuitItemStackHandler; import gregtech.api.capability.impl.NotifiableFluidTank; import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; @@ -48,10 +54,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiablePart - implements IMultiblockAbilityPart, IControllable { + implements IMultiblockAbilityPart, IControllable, + IGhostSlotConfigurable { public static final int INITIAL_INVENTORY_SIZE = 8000; public static final int LOCK_FILL = GregtechDataCodes.assignId(); @@ -59,6 +68,7 @@ public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiable // only holding this for convenience protected final HatchFluidTank fluidTank; protected boolean workingEnabled; + private GhostCircuitItemStackHandler circuitInventory; // export hatch-only fields protected boolean locked; @@ -72,6 +82,31 @@ public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boo initializeInventory(); } + @Override + protected void initializeInventory() { + super.initializeInventory(); + if (!this.hasGhostCircuitInventory()) return; + + this.circuitInventory = new GhostCircuitItemStackHandler(this); + this.circuitInventory.addNotifiableMetaTileEntity(this); + } + + @Override + public boolean hasGhostCircuitInventory() { + return !isExportHatch; + } + + @Override + public void setGhostCircuitConfig(int config) { + if (this.circuitInventory == null || this.circuitInventory.getCircuitValue() == config) { + return; + } + this.circuitInventory.setCircuitValue(config); + if (!getWorld().isRemote) { + markDirty(); + } + } + @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { return new MetaTileEntityFluidHatch(metaTileEntityId, getTier(), isExportHatch); @@ -216,8 +251,20 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(fluidTank); + public @NotNull List> getAbilities() { + return isExportHatch ? + Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS): + Arrays.asList(MultiblockAbility.IMPORT_FLUIDS, MultiblockAbility.IMPORT_ITEMS); + } + + @Override + public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { + if (key.equals(MultiblockAbility.EXPORT_FLUIDS) || key.equals(MultiblockAbility.IMPORT_FLUIDS)) { + return Collections.singletonList(fluidTank); + } else if (key.equals(MultiblockAbility.IMPORT_ITEMS)) { + return Collections.singletonList(circuitInventory); + } + return Collections.emptyList(); } @Override @@ -254,6 +301,20 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) .addTooltip(true, IKey.lang("gregtech.gui.fluid_lock.tooltip.enabled")) .addTooltip(false, IKey.lang("gregtech.gui.fluid_lock.tooltip.disabled"))) +// if (this.circuitInventory != null) { +// SlotWidget circuitSlot = new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62) +// .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.INT_CIRCUIT_OVERLAY); +// builder.widget(circuitSlot.setConsumer(slotWidget -> { +// String configString; +// if (circuitInventory == null || circuitInventory.getCircuitValue() == GhostCircuitItemStackHandler.NO_CONFIG) { +// configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value").getFormattedText(); +// } else { +// configString = String.valueOf(circuitInventory.getCircuitValue()); +// } +// +// slotWidget.setTooltipText("gregtech.gui.configurator_slot.tooltip", configString); +// })); +// } // import specific .childIf(!isExportHatch, GTGuiTextures.TANK_ICON.asWidget() .pos(91, 36) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java index a549ccbf81f..c1128786b9c 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java @@ -251,12 +251,14 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { } @Override - public void registerAbilities(List abilityList) { + public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { + var abilityList = new ArrayList<>(); if (this.hasGhostCircuitInventory() && this.actualImportItems != null) { abilityList.add(isExportHatch ? this.exportItems : this.actualImportItems); } else { abilityList.add(isExportHatch ? this.exportItems : this.importItems); } + return abilityList; } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java index f47d35c0377..1353a2780a3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java @@ -71,8 +71,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this.buffer); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this.buffer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index 47b88bb6ef0..9b795b57ed8 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityMachineHatch extends MetaTileEntityMultiblockNotifiablePart @@ -52,8 +53,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(machineHandler); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(machineHandler); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java index 31c87a58251..fb70cecb3f8 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java @@ -51,6 +51,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Consumer; @@ -498,8 +499,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index 4634293686a..e856a01658a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -37,6 +37,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityMufflerHatch extends MetaTileEntityMultiblockPart implements @@ -153,8 +154,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index 6ac0ad4ee05..86554798e05 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -35,8 +35,10 @@ import com.cleanroommc.modularui.screen.ModularPanel; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widgets.layout.Grid; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.ArrayList; import java.util.List; @@ -197,8 +199,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.addAll(fluidTankList.getFluidTanks()); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return fluidTankList.getFluidTanks(); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java index c55fcbfeaa8..750b29948e0 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java @@ -34,6 +34,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityObjectHolder extends MetaTileEntityMultiblockNotifiablePart @@ -84,8 +85,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java index b86782957d2..681d4ff9ce3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Collections; import java.util.List; public class MetaTileEntityOpticalDataHatch extends MetaTileEntityMultiblockNotifiablePart implements @@ -128,8 +129,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java index 84c388dece1..666fba216ab 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityPassthroughHatchFluid extends MetaTileEntityMultiblockPart implements IPassthroughHatch, @@ -155,8 +156,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java index febd79c80d6..a2f31a1f3df 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityPassthroughHatchItem extends MetaTileEntityMultiblockPart implements IPassthroughHatch, @@ -157,8 +158,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index e8cf6d7b59b..16675a8a9a3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -38,6 +38,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -112,8 +113,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(fluidTank); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(fluidTank); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java index 1fd863b864f..c0c623eea7f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java @@ -40,6 +40,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class MetaTileEntityRotorHolder extends MetaTileEntityMultiblockNotifiablePart @@ -146,8 +147,8 @@ void setRotorSpinning(boolean spinning) { } @Override - public void registerAbilities(@NotNull List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java index b1e53f22f4a..f16f331f861 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java @@ -51,6 +51,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class MetaTileEntityMEInputBus extends MetaTileEntityAEHostablePart @@ -330,8 +331,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List list) { - list.add(this.actualImportItems); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this.actualImportItems); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java index 2bcdc10f542..72ce10d6358 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java @@ -43,6 +43,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class MetaTileEntityMEInputHatch extends MetaTileEntityAEHostablePart @@ -270,8 +271,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List list) { - list.addAll(Arrays.asList(this.getAEFluidHandler().getInventory())); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.unmodifiableList(Arrays.asList(this.getAEFluidHandler().getInventory())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java index 9e008b857e3..318094a30bc 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java @@ -41,6 +41,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class MetaTileEntityMEOutputBus extends MetaTileEntityAEHostablePart @@ -196,8 +197,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java index 26a8fcc7947..4991bb47eb1 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java @@ -43,6 +43,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class MetaTileEntityMEOutputHatch extends MetaTileEntityAEHostablePart @@ -198,8 +199,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List list) { - list.add(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index dba69e698e8..c6ab8bd7aa4 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public abstract class MetaTileEntityHPCAComponent extends MetaTileEntityMultiblockPart implements @@ -67,8 +68,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(this); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java index abccdb7183a..8e9dc7115a0 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java @@ -36,6 +36,7 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -119,8 +120,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.addAll(this.importFluids.getFluidTanks()); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return this.importFluids.getFluidTanks(); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java index 56b15d8c93f..896ab92ac38 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java @@ -34,6 +34,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class MetaTileEntitySteamItemBus extends MetaTileEntityItemBus { @@ -56,8 +57,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(List abilityList) { - abilityList.add(isExportHatch ? this.exportItems : this.importItems); + public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + return Collections.singletonList(isExportHatch ? this.exportItems : this.importItems); } // Override base texture to have a bus with 4 slots, but ULV textures From f6daf313e46eace1dbee58ea667372ef9d2a2518 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:38:53 -0700 Subject: [PATCH 002/103] add controller to notifiable --- .../multiblockpart/MetaTileEntityFluidHatch.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 8d8290374be..1afb9483232 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -15,6 +15,7 @@ import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; +import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import gregtech.api.mui.GTGuiTextures; import gregtech.api.mui.GTGuis; import gregtech.client.renderer.texture.Textures; @@ -363,6 +364,18 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) .bindPlayerInventory(); } + @Override + public void addToMultiBlock(MultiblockControllerBase controllerBase) { + super.addToMultiBlock(controllerBase); + this.circuitInventory.addNotifiableMetaTileEntity(controllerBase); + } + + @Override + public void removeFromMultiBlock(MultiblockControllerBase controllerBase) { + super.removeFromMultiBlock(controllerBase); + this.circuitInventory.removeNotifiableMetaTileEntity(controllerBase); + } + @Override public void addInformation(ItemStack stack, @Nullable World player, @NotNull List tooltip, boolean advanced) { From d4b52ffae26e8d9f4025c08117bd1392c1b3f5f0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:46:20 -0700 Subject: [PATCH 003/103] save to nbt --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 1afb9483232..02ae089170e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -122,6 +122,8 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) { if (locked && lockedFluid != null) { data.setTag("LockedFluid", lockedFluid.writeToNBT(new NBTTagCompound())); } + } else { + this.circuitInventory.write(data); } return data; } @@ -140,6 +142,8 @@ public void readFromNBT(NBTTagCompound data) { this.locked = data.getBoolean("IsLocked"); this.lockedFluid = this.locked ? FluidStack.loadFluidStackFromNBT(data.getCompoundTag("LockedFluid")) : null; + } else { + this.circuitInventory.read(data); } } From 1f2915963bcb905b0fdd2bdf57140571a3287f29 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:57:56 -0700 Subject: [PATCH 004/103] renames --- .../multiblock/MultiblockControllerBase.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index 0034534fe12..53c53ffdbf5 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -351,13 +351,13 @@ public void checkStructurePattern() { this.setFlipped(context.neededFlip()); parts.sort(Comparator.comparing(it -> multiblockPartSorter().apply(((MetaTileEntity) it).getPos()))); Map, List> abilities = new HashMap<>(); - for (IMultiblockPart multiblockPart : parts) { - if (multiblockPart instanceof IMultiblockAbilityPart multiblockAbilityPart) { - List m = multiblockAbilityPart.getAbilities(); - for (MultiblockAbility ability : m) { + for (IMultiblockPart part : parts) { + if (part instanceof IMultiblockAbilityPart abilityPart) { + List abilityList = abilityPart.getAbilities(); + for (MultiblockAbility ability : abilityList) { List abilityInstancesList = abilities.computeIfAbsent(ability, k -> new ArrayList<>()); - abilityInstancesList.addAll(multiblockAbilityPart.registerAbilities(ability)); + abilityInstancesList.addAll(abilityPart.registerAbilities(ability)); } } } From 1a9347fd8830b6270d48af0ff2748d43f83f49d7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:00:28 -0700 Subject: [PATCH 005/103] spotless --- .../multiblockpart/MetaTileEntityFluidHatch.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 02ae089170e..2bfd4ff43b7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -61,7 +61,7 @@ public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiablePart implements IMultiblockAbilityPart, IControllable, - IGhostSlotConfigurable { + IGhostSlotConfigurable { public static final int INITIAL_INVENTORY_SIZE = 8000; public static final int LOCK_FILL = GregtechDataCodes.assignId(); @@ -258,7 +258,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List> getAbilities() { return isExportHatch ? - Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS): + Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS) : Arrays.asList(MultiblockAbility.IMPORT_FLUIDS, MultiblockAbility.IMPORT_ITEMS); } @@ -305,14 +305,15 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) .value(new BooleanSyncValue(this::isLocked, b -> fluidSyncHandler.lockFluid(b, false))) .addTooltip(true, IKey.lang("gregtech.gui.fluid_lock.tooltip.enabled")) .addTooltip(false, IKey.lang("gregtech.gui.fluid_lock.tooltip.disabled"))) - // if (this.circuitInventory != null) { // SlotWidget circuitSlot = new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62) // .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.INT_CIRCUIT_OVERLAY); // builder.widget(circuitSlot.setConsumer(slotWidget -> { // String configString; -// if (circuitInventory == null || circuitInventory.getCircuitValue() == GhostCircuitItemStackHandler.NO_CONFIG) { -// configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value").getFormattedText(); +// if (circuitInventory == null || +// circuitInventory.getCircuitValue() == GhostCircuitItemStackHandler.NO_CONFIG) { +// configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value") +// .getFormattedText(); // } else { // configString = String.valueOf(circuitInventory.getCircuitValue()); // } From 48692b7990b88485626695cbc25ac888939fbea8 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:08:20 -0700 Subject: [PATCH 006/103] initial impl of dual handlers --- src/main/java/gregtech/api/DualHandler.java | 147 ++++++++++++++++++ .../multiblock/MultiblockAbility.java | 4 + .../RecipeMapMultiblockController.java | 1 + 3 files changed, 152 insertions(+) create mode 100644 src/main/java/gregtech/api/DualHandler.java diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java new file mode 100644 index 00000000000..941f597d6c6 --- /dev/null +++ b/src/main/java/gregtech/api/DualHandler.java @@ -0,0 +1,147 @@ +package gregtech.api; + +import gregtech.api.capability.INotifiableHandler; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.util.IDirtyNotifiable; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidTankProperties; +import net.minecraftforge.items.IItemHandlerModifiable; + +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public final class DualHandler implements IItemHandlerModifiable, IFluidHandler, INotifiableHandler { + + @Nullable + IItemHandlerModifiable itemDelegate; + @Nullable + IFluidHandler fluidDelegate; + @Nullable + IDirtyNotifiable dirtyNotifiable; + private final boolean isExport; + + private final List notifiables = new ArrayList<>(); + + public DualHandler(IItemHandlerModifiable itemDelegate, IFluidHandler fluidDelegate, IDirtyNotifiable notifiable, boolean isExport) { + this.itemDelegate = itemDelegate; + this.fluidDelegate = fluidDelegate; + this.dirtyNotifiable = notifiable; + this.isExport = isExport; + } + + @Override + public int getSlots() { + return itemDelegate == null ? 0 : itemDelegate.getSlots(); + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (itemDelegate == null) return ItemStack.EMPTY; + return itemDelegate.getStackInSlot(slot); + } + + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (itemDelegate == null) return stack; + return itemDelegate.insertItem(slot, stack, simulate); + } + + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (itemDelegate == null) return ItemStack.EMPTY; + return itemDelegate.extractItem(slot, amount, simulate); + } + + @Override + public int getSlotLimit(int slot) { + return itemDelegate.getSlotLimit(slot); + } + + public void onContentsCahgned() { + if (this.dirtyNotifiable != null) { + this.dirtyNotifiable.markAsDirty(); + } + notifiables.forEach(mte -> { + if (isExport) { + mte.addNotifiedOutput(this); + } else { + mte.addNotifiedInput(this); + } + }); + } + + @Override + public void setStackInSlot(int slot, ItemStack stack) { + if (itemDelegate == null) return; + itemDelegate.setStackInSlot(slot, stack); + } + + @Override + public IFluidTankProperties[] getTankProperties() { + return fluidDelegate == null ? + new IFluidTankProperties[0] : + fluidDelegate.getTankProperties(); + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + if (fluidDelegate == null) return 0; + return fluidDelegate.fill(resource, doFill); + } + + @Override + public FluidStack drain(FluidStack resource, boolean doDrain) { + if (fluidDelegate == null) return null; + return fluidDelegate.drain(resource, doDrain); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + if (fluidDelegate == null) return null; + return fluidDelegate.drain(maxDrain, doDrain); + } + + @Override + public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + this.notifiables.add(metaTileEntity); + } + + @Override + public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + this.notifiables.remove(metaTileEntity); + } + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + IItemHandlerModifiable itemHandler; + IFluidHandler fluidHandler; + IDirtyNotifiable notifiable; + + public Builder itemHandler(IItemHandlerModifiable itemHandler) { + this.itemHandler = itemHandler; + return this; + } + + public Builder fluidTank(IFluidHandler fluidTank) { + this.fluidHandler = fluidTank; + return this; + } + + public Builder notifiable(IDirtyNotifiable notifiable) { + this.notifiable = notifiable; + return this; + } + + public DualHandler build(boolean isExport) { + return new DualHandler(this.itemHandler, this.fluidHandler, this.notifiable, isExport); + } + } +} diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index b5187267437..e43374ad379 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -1,5 +1,6 @@ package gregtech.api.metatileentity.multiblock; +import gregtech.api.DualHandler; import gregtech.api.capability.*; import gregtech.api.metatileentity.MetaTileEntity; @@ -28,6 +29,9 @@ public class MultiblockAbility { public static final MultiblockAbility EXPORT_FLUIDS = new MultiblockAbility<>("export_fluids"); public static final MultiblockAbility IMPORT_FLUIDS = new MultiblockAbility<>("import_fluids"); + public static final MultiblockAbility EXPORT_DUAL = new MultiblockAbility<>("export_dual"); + public static final MultiblockAbility IMPORT_DUAL = new MultiblockAbility<>("import_dual"); + public static final MultiblockAbility INPUT_ENERGY = new MultiblockAbility<>("input_energy"); public static final MultiblockAbility OUTPUT_ENERGY = new MultiblockAbility<>("output_energy"); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 4949074c91a..85c6d2a11a7 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -253,6 +253,7 @@ public void setDistinct(boolean isDistinct) { getMultiblockParts().forEach(part -> part.onDistinctChange(isDistinct)); // mark buses as changed on distinct toggle if (this.isDistinct) { + //todo use dual handlers this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); } else { this.notifiedItemInputList.add(this.inputInventory); From 97879c3b6043ac1ccec8affb3eda81fa88545f73 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:09:42 -0700 Subject: [PATCH 007/103] sbobl --- src/main/java/gregtech/api/DualHandler.java | 4 +++- .../multiblock/RecipeMapMultiblockController.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 941f597d6c6..8666a9468b6 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -27,7 +27,8 @@ public final class DualHandler implements IItemHandlerModifiable, IFluidHandler, private final List notifiables = new ArrayList<>(); - public DualHandler(IItemHandlerModifiable itemDelegate, IFluidHandler fluidDelegate, IDirtyNotifiable notifiable, boolean isExport) { + public DualHandler(IItemHandlerModifiable itemDelegate, IFluidHandler fluidDelegate, IDirtyNotifiable notifiable, + boolean isExport) { this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; this.dirtyNotifiable = notifiable; @@ -115,6 +116,7 @@ public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiables.remove(metaTileEntity); } + public static Builder builder() { return new Builder(); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 85c6d2a11a7..8e20b865a32 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -253,7 +253,7 @@ public void setDistinct(boolean isDistinct) { getMultiblockParts().forEach(part -> part.onDistinctChange(isDistinct)); // mark buses as changed on distinct toggle if (this.isDistinct) { - //todo use dual handlers + // todo use dual handlers this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); } else { this.notifiedItemInputList.add(this.inputInventory); From 32fcbca06c17eb3d10f36f2660d87590e3a5a005 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:42:55 -0700 Subject: [PATCH 008/103] some work on combining abilities --- src/main/java/gregtech/api/DualHandler.java | 37 ++++++++++++++++--- .../impl/MultiblockRecipeLogic.java | 6 ++- .../api/metatileentity/MetaTileEntity.java | 4 +- .../multiblock/MultiblockControllerBase.java | 9 +++-- .../multiblock/MultiblockWithDisplayBase.java | 1 + .../RecipeMapMultiblockController.java | 2 + .../java/gregtech/api/recipes/Recipe.java | 7 ++++ .../electric/MetaTileEntityRockBreaker.java | 2 +- 8 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 8666a9468b6..5a86952d085 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -1,33 +1,39 @@ package gregtech.api; +import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.INotifiableHandler; +import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.IDirtyNotifiable; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -public final class DualHandler implements IItemHandlerModifiable, IFluidHandler, INotifiableHandler { +public final class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler { @Nullable IItemHandlerModifiable itemDelegate; @Nullable - IFluidHandler fluidDelegate; + IMultipleTankHandler fluidDelegate; @Nullable IDirtyNotifiable dirtyNotifiable; private final boolean isExport; + private static final MultiFluidTankEntry EMPTY = new MultiFluidTankEntry(new FluidTankList(false, new FluidTank[0]), new FluidTank(0)); private final List notifiables = new ArrayList<>(); - public DualHandler(IItemHandlerModifiable itemDelegate, IFluidHandler fluidDelegate, IDirtyNotifiable notifiable, + public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler fluidDelegate, IDirtyNotifiable notifiable, boolean isExport) { this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; @@ -121,10 +127,31 @@ public static Builder builder() { return new Builder(); } + @Override + public @NotNull List getFluidTanks() { + if (this.fluidDelegate == null) return Collections.emptyList(); + return this.fluidDelegate.getFluidTanks(); + } + + @Override + public int getTanks() { + return this.fluidDelegate == null ? 0 : this.fluidDelegate.getTanks(); + } + + @Override + public @NotNull MultiFluidTankEntry getTankAt(int index) { + return this.fluidDelegate == null ? EMPTY : this.fluidDelegate.getTankAt(index); + } + + @Override + public boolean allowSameFluidFill() { + return this.fluidDelegate != null && this.fluidDelegate.allowSameFluidFill(); + } + public static class Builder { IItemHandlerModifiable itemHandler; - IFluidHandler fluidHandler; + IMultipleTankHandler fluidHandler; IDirtyNotifiable notifiable; public Builder itemHandler(IItemHandlerModifiable itemHandler) { @@ -132,7 +159,7 @@ public Builder itemHandler(IItemHandlerModifiable itemHandler) { return this; } - public Builder fluidTank(IFluidHandler fluidTank) { + public Builder fluidTank(IMultipleTankHandler fluidTank) { this.fluidHandler = fluidTank; return this; } diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ff95f0fbb0c..ecb9dfbbc62 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -84,7 +85,10 @@ protected IItemHandlerModifiable getInputInventory() { // Used for distinct bus recipe checking protected List getInputBuses() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; - return controller.getAbilities(MultiblockAbility.IMPORT_ITEMS); + List l = new ArrayList<>(); + l.addAll(controller.getAbilitiesModifiable(MultiblockAbility.IMPORT_ITEMS)); + l.addAll(controller.getAbilitiesModifiable(MultiblockAbility.IMPORT_DUAL)); + return Collections.unmodifiableList(l); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 723df6f6808..9424c6bb5ca 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -393,7 +393,7 @@ public final String getMetaFullName() { return getMetaName() + ".name"; } - public void addNotifiedInput(T input) { + public void addNotifiedInput(Object input) { if (input instanceof IItemHandlerModifiable) { if (!notifiedItemInputList.contains(input)) { this.notifiedItemInputList.add((IItemHandlerModifiable) input); @@ -405,7 +405,7 @@ public void addNotifiedInput(T input) { } } - public void addNotifiedOutput(T output) { + public void addNotifiedOutput(Object output) { if (output instanceof IItemHandlerModifiable) { if (!notifiedItemOutputList.contains(output)) { this.notifiedItemOutputList.add((IItemHandlerModifiable) output); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index 53c53ffdbf5..fa76b69930e 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -396,10 +396,13 @@ public void onRemoval() { } } - @SuppressWarnings("unchecked") public List getAbilities(MultiblockAbility ability) { - List rawList = (List) multiblockAbilities.getOrDefault(ability, Collections.emptyList()); - return Collections.unmodifiableList(rawList); + return Collections.unmodifiableList(getAbilitiesModifiable(ability)); + } + + @SuppressWarnings("unchecked") + public List getAbilitiesModifiable(MultiblockAbility ability) { + return (List) multiblockAbilities.getOrDefault(ability, Collections.emptyList()); } public List getMultiblockParts() { diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java index 55723ef456d..4254640206d 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java @@ -547,6 +547,7 @@ protected void setVoidingMode(int mode) { this.getNotifiedFluidInputList().add((IFluidHandler) tank); } this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); + this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_DUAL)); markDirty(); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 8e20b865a32..48120c614dd 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -1,5 +1,6 @@ package gregtech.api.metatileentity.multiblock; +import gregtech.api.DualHandler; import gregtech.api.GTValues; import gregtech.api.capability.IDistinctBusController; import gregtech.api.capability.IEnergyContainer; @@ -255,6 +256,7 @@ public void setDistinct(boolean isDistinct) { if (this.isDistinct) { // todo use dual handlers this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); + this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_DUAL)); } else { this.notifiedItemInputList.add(this.inputInventory); } diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index ff495651ac5..260770014c6 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -1,6 +1,8 @@ package gregtech.api.recipes; +import gregtech.api.DualHandler; import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.impl.FluidTankList; import gregtech.api.recipes.category.GTRecipeCategory; import gregtech.api.recipes.chance.boost.ChanceBoostFunction; import gregtech.api.recipes.chance.output.ChancedOutputList; @@ -17,6 +19,8 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.oredict.OreDictionary; @@ -188,6 +192,9 @@ public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable IMultipleTankHandler fluidInputs) { Pair fluids = null; Pair items = null; + if (inputs instanceof IFluidTank tank) { + fluidInputs = new FluidTankList(false, tank); + } if (fluidInputs.getFluidTanks().size() > 0) { fluids = matchesFluid(GTUtility.fluidHandlerToList(fluidInputs)); diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityRockBreaker.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityRockBreaker.java index 7ff2b055358..db5f83778f6 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityRockBreaker.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityRockBreaker.java @@ -75,7 +75,7 @@ private void checkAdjacentFluids() { } @Override - public void addNotifiedInput(T input) { + public void addNotifiedInput(Object input) { super.addNotifiedInput(input); onNeighborChanged(); } From ce8a6f41566e16444be79eed603875833841ec53 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:42:13 -0700 Subject: [PATCH 009/103] remove builder --- src/main/java/gregtech/api/DualHandler.java | 30 --------------------- 1 file changed, 30 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 5a86952d085..95d7d15dc3d 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -123,10 +123,6 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiables.remove(metaTileEntity); } - public static Builder builder() { - return new Builder(); - } - @Override public @NotNull List getFluidTanks() { if (this.fluidDelegate == null) return Collections.emptyList(); @@ -147,30 +143,4 @@ public int getTanks() { public boolean allowSameFluidFill() { return this.fluidDelegate != null && this.fluidDelegate.allowSameFluidFill(); } - - public static class Builder { - - IItemHandlerModifiable itemHandler; - IMultipleTankHandler fluidHandler; - IDirtyNotifiable notifiable; - - public Builder itemHandler(IItemHandlerModifiable itemHandler) { - this.itemHandler = itemHandler; - return this; - } - - public Builder fluidTank(IMultipleTankHandler fluidTank) { - this.fluidHandler = fluidTank; - return this; - } - - public Builder notifiable(IDirtyNotifiable notifiable) { - this.notifiable = notifiable; - return this; - } - - public DualHandler build(boolean isExport) { - return new DualHandler(this.itemHandler, this.fluidHandler, this.notifiable, isExport); - } - } } From 9adc0616f030c8413c47be3dc5345405e39d787c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:46:21 -0700 Subject: [PATCH 010/103] dual handler probably works now --- src/main/java/gregtech/api/DualHandler.java | 7 ++++--- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 7 ++++++- .../multiblock/RecipeMapMultiblockController.java | 1 - src/main/java/gregtech/api/recipes/Recipe.java | 2 -- src/main/java/gregtech/api/recipes/RecipeMap.java | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 95d7d15dc3d..0c975034b85 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -9,7 +9,6 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; @@ -29,11 +28,13 @@ public final class DualHandler implements IItemHandlerModifiable, IMultipleTankH @Nullable IDirtyNotifiable dirtyNotifiable; private final boolean isExport; - private static final MultiFluidTankEntry EMPTY = new MultiFluidTankEntry(new FluidTankList(false, new FluidTank[0]), new FluidTank(0)); + private static final MultiFluidTankEntry EMPTY = new MultiFluidTankEntry(new FluidTankList(false, new FluidTank[0]), + new FluidTank(0)); private final List notifiables = new ArrayList<>(); - public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler fluidDelegate, IDirtyNotifiable notifiable, + public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler fluidDelegate, + IDirtyNotifiable notifiable, boolean isExport) { this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 455ae3afd47..9766d9b6134 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -1,5 +1,6 @@ package gregtech.api.capability.impl; +import gregtech.api.DualHandler; import gregtech.api.GTValues; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; @@ -626,7 +627,11 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul return null; } - return map.findRecipe(maxVoltage, inputs, fluidInputs); + if (inputs instanceof DualHandler dualHandler) { + return map.findRecipe(maxVoltage, dualHandler, dualHandler); + } else { + return map.findRecipe(maxVoltage, inputs, fluidInputs); + } } /** diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 48120c614dd..2fae17a2528 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -1,6 +1,5 @@ package gregtech.api.metatileentity.multiblock; -import gregtech.api.DualHandler; import gregtech.api.GTValues; import gregtech.api.capability.IDistinctBusController; import gregtech.api.capability.IEnergyContainer; diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index 260770014c6..089be4aa7ac 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -1,6 +1,5 @@ package gregtech.api.recipes; -import gregtech.api.DualHandler; import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.recipes.category.GTRecipeCategory; @@ -20,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.oredict.OreDictionary; diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index a2c2ef7b1f4..f463f34744e 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMap.java +++ b/src/main/java/gregtech/api/recipes/RecipeMap.java @@ -534,7 +534,7 @@ amount, getMaxFluidOutputs()), @Nullable public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { - return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs)); + return findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs)); } /** From 3f1a93ef05a75aa0aa3183c1454fb4f15085666c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:52:58 -0700 Subject: [PATCH 011/103] small fixes --- src/main/java/gregtech/api/recipes/Recipe.java | 3 --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 9 +++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index 089be4aa7ac..4f2b34c10ac 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -190,9 +190,6 @@ public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable IMultipleTankHandler fluidInputs) { Pair fluids = null; Pair items = null; - if (inputs instanceof IFluidTank tank) { - fluidInputs = new FluidTankList(false, tank); - } if (fluidInputs.getFluidTanks().size() > 0) { fluids = matchesFluid(GTUtility.fluidHandlerToList(fluidInputs)); diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 2bfd4ff43b7..d33c56ff7dc 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -1,5 +1,6 @@ package gregtech.common.metatileentities.multi.multiblockpart; +import gregtech.api.DualHandler; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; @@ -259,15 +260,15 @@ public MultiblockAbility getAbility() { public @NotNull List> getAbilities() { return isExportHatch ? Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS) : - Arrays.asList(MultiblockAbility.IMPORT_FLUIDS, MultiblockAbility.IMPORT_ITEMS); + Collections.singletonList(MultiblockAbility.IMPORT_DUAL); } @Override public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { - if (key.equals(MultiblockAbility.EXPORT_FLUIDS) || key.equals(MultiblockAbility.IMPORT_FLUIDS)) { + if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(fluidTank); - } else if (key.equals(MultiblockAbility.IMPORT_ITEMS)) { - return Collections.singletonList(circuitInventory); + } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { + return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids, null, false)); } return Collections.emptyList(); } From d875cbbbd57b054dd8919e47212864fa475723af Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 6 Apr 2024 17:51:27 -0700 Subject: [PATCH 012/103] a bit more work --- src/main/java/gregtech/api/DualHandler.java | 7 ------- .../capability/impl/AbstractRecipeLogic.java | 18 ++++++++++++++++-- .../RecipeMapMultiblockController.java | 6 +++++- .../MetaTileEntityFluidHatch.java | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 0c975034b85..5b0bb0b0f69 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -25,8 +25,6 @@ public final class DualHandler implements IItemHandlerModifiable, IMultipleTankH IItemHandlerModifiable itemDelegate; @Nullable IMultipleTankHandler fluidDelegate; - @Nullable - IDirtyNotifiable dirtyNotifiable; private final boolean isExport; private static final MultiFluidTankEntry EMPTY = new MultiFluidTankEntry(new FluidTankList(false, new FluidTank[0]), new FluidTank(0)); @@ -34,11 +32,9 @@ public final class DualHandler implements IItemHandlerModifiable, IMultipleTankH private final List notifiables = new ArrayList<>(); public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler fluidDelegate, - IDirtyNotifiable notifiable, boolean isExport) { this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; - this.dirtyNotifiable = notifiable; this.isExport = isExport; } @@ -71,9 +67,6 @@ public int getSlotLimit(int slot) { } public void onContentsCahgned() { - if (this.dirtyNotifiable != null) { - this.dirtyNotifiable.markAsDirty(); - } notifiables.forEach(mte -> { if (isExport) { mte.addNotifiedOutput(this); diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 9766d9b6134..b2e1a7c8001 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -36,6 +36,8 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -627,9 +629,21 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul return null; } - if (inputs instanceof DualHandler dualHandler) { + if (inputs instanceof ItemHandlerList list) { + List items = new ArrayList<>(); + List fluids = new ArrayList<>(); + for (var handler : list.getBackingHandlers()) { + if (handler instanceof DualHandler dualHandler) { + items.add(dualHandler); + fluids.addAll(dualHandler.getFluidTanks()); + } else { + items.add(handler); + } + } + return map.findRecipe(maxVoltage, new ItemHandlerList(items), new FluidTankList(false, fluids)); + } else if (inputs instanceof DualHandler dualHandler) { return map.findRecipe(maxVoltage, dualHandler, dualHandler); - } else { + } else { return map.findRecipe(maxVoltage, inputs, fluidInputs); } } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 2fae17a2528..7092e29063b 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public abstract class RecipeMapMultiblockController extends MultiblockWithDisplayBase implements IDataInfoProvider, @@ -118,7 +119,10 @@ public boolean isActive() { } protected void initializeAbilities() { - this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS)); + List l = new ArrayList<>(); + l.addAll(getAbilitiesModifiable(MultiblockAbility.IMPORT_ITEMS)); + l.addAll(getAbilitiesModifiable(MultiblockAbility.IMPORT_DUAL)); + this.inputInventory = new ItemHandlerList(Collections.unmodifiableList(l)); this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index d33c56ff7dc..96ca04eafea 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -268,7 +268,7 @@ public MultiblockAbility getAbility() { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { - return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids, null, false)); + return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids,false)); } return Collections.emptyList(); } From 3008757f4f860cbbfdaa50b345b66bf451041fd6 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 14 Apr 2024 08:38:23 -0700 Subject: [PATCH 013/103] try fix tests spotless --- src/main/java/gregtech/api/DualHandler.java | 1 - .../api/capability/impl/AbstractRecipeLogic.java | 16 ++++++---------- src/main/java/gregtech/api/recipes/Recipe.java | 2 -- .../multiblockpart/MetaTileEntityFluidHatch.java | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 5b0bb0b0f69..a0acfd3f46b 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -4,7 +4,6 @@ import gregtech.api.capability.INotifiableHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.util.IDirtyNotifiable; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index b2e1a7c8001..c3c11f12380 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -36,8 +36,6 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -630,20 +628,18 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul } if (inputs instanceof ItemHandlerList list) { - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); + List items = new ArrayList<>(); + List fluids = new ArrayList<>(); for (var handler : list.getBackingHandlers()) { if (handler instanceof DualHandler dualHandler) { - items.add(dualHandler); - fluids.addAll(dualHandler.getFluidTanks()); - } else { - items.add(handler); + fluids.addAll(GTUtility.fluidHandlerToList(dualHandler)); } + items.addAll(GTUtility.itemHandlerToList((IItemHandlerModifiable) handler)); } - return map.findRecipe(maxVoltage, new ItemHandlerList(items), new FluidTankList(false, fluids)); + return map.findRecipe(maxVoltage, items, fluids); } else if (inputs instanceof DualHandler dualHandler) { return map.findRecipe(maxVoltage, dualHandler, dualHandler); - } else { + } else { return map.findRecipe(maxVoltage, inputs, fluidInputs); } } diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index 4f2b34c10ac..ff495651ac5 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -1,7 +1,6 @@ package gregtech.api.recipes; import gregtech.api.capability.IMultipleTankHandler; -import gregtech.api.capability.impl.FluidTankList; import gregtech.api.recipes.category.GTRecipeCategory; import gregtech.api.recipes.chance.boost.ChanceBoostFunction; import gregtech.api.recipes.chance.output.ChancedOutputList; @@ -18,7 +17,6 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.oredict.OreDictionary; diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 96ca04eafea..cf947445c06 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -56,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -268,7 +267,7 @@ public MultiblockAbility getAbility() { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { - return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids,false)); + return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids, false)); } return Collections.emptyList(); } From 0e7c8dffb8c33d4c5cd494a3ff6dbea970d9a925 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 14 Apr 2024 09:05:45 -0700 Subject: [PATCH 014/103] fix ghost circ init --- .../MetaTileEntityFluidHatch.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index cf947445c06..a875cae69be 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -80,16 +80,10 @@ public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boo super(metaTileEntityId, tier, isExportHatch); this.fluidTank = new HatchFluidTank(getInventorySize(), this, isExportHatch); this.workingEnabled = true; - initializeInventory(); - } - - @Override - protected void initializeInventory() { - super.initializeInventory(); - if (!this.hasGhostCircuitInventory()) return; - - this.circuitInventory = new GhostCircuitItemStackHandler(this); - this.circuitInventory.addNotifiableMetaTileEntity(this); + if (this.hasGhostCircuitInventory()) { + this.circuitInventory = new GhostCircuitItemStackHandler(this); + this.circuitInventory.addNotifiableMetaTileEntity(this); + } } @Override @@ -372,13 +366,15 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) @Override public void addToMultiBlock(MultiblockControllerBase controllerBase) { super.addToMultiBlock(controllerBase); - this.circuitInventory.addNotifiableMetaTileEntity(controllerBase); + if (hasGhostCircuitInventory()) + this.circuitInventory.addNotifiableMetaTileEntity(controllerBase); } @Override public void removeFromMultiBlock(MultiblockControllerBase controllerBase) { super.removeFromMultiBlock(controllerBase); - this.circuitInventory.removeNotifiableMetaTileEntity(controllerBase); + if (hasGhostCircuitInventory()) + this.circuitInventory.removeNotifiableMetaTileEntity(controllerBase); } @Override From edfc5eccd516ee9f1c52ec5f43923bcb99b78e30 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 14 Apr 2024 09:51:52 -0700 Subject: [PATCH 015/103] fix inventory init --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index a875cae69be..f9f21e9532e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -79,6 +79,7 @@ public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiable public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) { super(metaTileEntityId, tier, isExportHatch); this.fluidTank = new HatchFluidTank(getInventorySize(), this, isExportHatch); + initializeInventory(); // the fact that this has to be called three times is so dumb this.workingEnabled = true; if (this.hasGhostCircuitInventory()) { this.circuitInventory = new GhostCircuitItemStackHandler(this); From c856a109aa2f827921c4f15ec3edc95714d923c9 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:15:35 -0700 Subject: [PATCH 016/103] add and use better utility methods --- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 4 ++-- src/main/java/gregtech/api/util/GTUtility.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index c3c11f12380..d107c441f5f 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -632,9 +632,9 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul List fluids = new ArrayList<>(); for (var handler : list.getBackingHandlers()) { if (handler instanceof DualHandler dualHandler) { - fluids.addAll(GTUtility.fluidHandlerToList(dualHandler)); + GTUtility.addHandlerToCollection(fluids, dualHandler); } - items.addAll(GTUtility.itemHandlerToList((IItemHandlerModifiable) handler)); + GTUtility.addHandlerToCollection(items, handler); } return map.findRecipe(maxVoltage, items, fluids); } else if (inputs instanceof DualHandler dualHandler) { diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 39b4a6a0d65..6f2357eb1d7 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -64,6 +64,7 @@ import java.util.AbstractList; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; From 1a0c0a0832a235e8d662782e0bd71ecc45181dbc Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:29:48 -0700 Subject: [PATCH 017/103] add method overloads for multiple abilities --- .../multiblock/MultiblockControllerBase.java | 16 ++++++++++++++++ .../RecipeMapMultiblockController.java | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index fa76b69930e..cd590aa7590 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -400,6 +400,22 @@ public List getAbilities(MultiblockAbility ability) { return Collections.unmodifiableList(getAbilitiesModifiable(ability)); } + public List getAbilities(MultiblockAbility ability1, MultiblockAbility ability2) { + var combined = new ArrayList(); + combined.addAll(getAbilitiesModifiable(ability1)); + combined.addAll(getAbilitiesModifiable(ability2)); + return Collections.unmodifiableList(combined); + } + + @SafeVarargs + public final List getAbilities(MultiblockAbility... abilities) { + var combined = new ArrayList(); + for (var ability : abilities) { + combined.addAll(getAbilitiesModifiable(ability)); + } + return Collections.unmodifiableList(combined); + } + @SuppressWarnings("unchecked") public List getAbilitiesModifiable(MultiblockAbility ability) { return (List) multiblockAbilities.getOrDefault(ability, Collections.emptyList()); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 7092e29063b..068aa06faa7 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -257,9 +257,7 @@ public void setDistinct(boolean isDistinct) { getMultiblockParts().forEach(part -> part.onDistinctChange(isDistinct)); // mark buses as changed on distinct toggle if (this.isDistinct) { - // todo use dual handlers - this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); - this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_DUAL)); + this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); } else { this.notifiedItemInputList.add(this.inputInventory); } From 94ea753ff93ba2f3a41950c0e3ee70733db34dff Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:56:02 -0700 Subject: [PATCH 018/103] misc + spotless --- .../gregtech/api/capability/impl/MultiblockRecipeLogic.java | 6 +----- .../metatileentity/multiblock/MultiblockControllerBase.java | 3 ++- .../multiblock/RecipeMapMultiblockController.java | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ecb9dfbbc62..ad05173d5c6 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -85,10 +84,7 @@ protected IItemHandlerModifiable getInputInventory() { // Used for distinct bus recipe checking protected List getInputBuses() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; - List l = new ArrayList<>(); - l.addAll(controller.getAbilitiesModifiable(MultiblockAbility.IMPORT_ITEMS)); - l.addAll(controller.getAbilitiesModifiable(MultiblockAbility.IMPORT_DUAL)); - return Collections.unmodifiableList(l); + return new ArrayList<>(controller.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index cd590aa7590..bf51955313e 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -400,7 +400,8 @@ public List getAbilities(MultiblockAbility ability) { return Collections.unmodifiableList(getAbilitiesModifiable(ability)); } - public List getAbilities(MultiblockAbility ability1, MultiblockAbility ability2) { + public List getAbilities(MultiblockAbility ability1, + MultiblockAbility ability2) { var combined = new ArrayList(); combined.addAll(getAbilitiesModifiable(ability1)); combined.addAll(getAbilitiesModifiable(ability2)); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 068aa06faa7..5e5dff522b3 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -257,7 +257,8 @@ public void setDistinct(boolean isDistinct) { getMultiblockParts().forEach(part -> part.onDistinctChange(isDistinct)); // mark buses as changed on distinct toggle if (this.isDistinct) { - this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + this.notifiedItemInputList + .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); } else { this.notifiedItemInputList.add(this.inputInventory); } From 74951689e3fb18edae6a8fcfa01261194ce22672 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:42:46 -0700 Subject: [PATCH 019/103] wtf distillation tower slightly change signature of registerAbilities() make dual handler implement IFluidTank --- src/main/java/gregtech/api/DualHandler.java | 61 +++++++++++++++---- .../multiblock/IMultiblockAbilityPart.java | 2 +- .../java/gregtech/api/util/GTUtility.java | 20 ++++++ .../electric/MetaTileEntityDiode.java | 3 +- .../electric/MetaTileEntityHull.java | 3 +- .../multi/MetaTileEntityPumpHatch.java | 3 +- .../multi/MetaTileEntityTankValve.java | 3 +- .../MetaTileEntityAutoMaintenanceHatch.java | 3 +- .../MetaTileEntityComputationHatch.java | 3 +- .../MetaTileEntityDataAccessHatch.java | 3 +- .../MetaTileEntityEnergyHatch.java | 3 +- .../MetaTileEntityFluidHatch.java | 2 +- .../multiblockpart/MetaTileEntityItemBus.java | 5 +- .../MetaTileEntityLaserHatch.java | 3 +- .../MetaTileEntityMachineHatch.java | 3 +- .../MetaTileEntityMaintenanceHatch.java | 3 +- .../MetaTileEntityMufflerHatch.java | 3 +- .../MetaTileEntityMultiFluidHatch.java | 3 +- .../MetaTileEntityObjectHolder.java | 3 +- .../MetaTileEntityOpticalDataHatch.java | 3 +- .../MetaTileEntityPassthroughHatchFluid.java | 3 +- .../MetaTileEntityPassthroughHatchItem.java | 3 +- .../MetaTileEntityReservoirHatch.java | 3 +- .../MetaTileEntityRotorHolder.java | 3 +- .../appeng/MetaTileEntityMEInputBus.java | 3 +- .../appeng/MetaTileEntityMEInputHatch.java | 3 +- .../appeng/MetaTileEntityMEOutputBus.java | 3 +- .../appeng/MetaTileEntityMEOutputHatch.java | 3 +- .../hpca/MetaTileEntityHPCAComponent.java | 3 +- .../MetaTileEntitySteamHatch.java | 3 +- .../MetaTileEntitySteamItemBus.java | 3 +- 31 files changed, 127 insertions(+), 41 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index a0acfd3f46b..2fd2851f7ea 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; @@ -18,15 +20,16 @@ import java.util.Collections; import java.util.List; -public final class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler { +public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler, INotifiableHandler { + + private static final IFluidTank NULL_TANK = new FluidTank(0); + private static final IMultipleTankHandler NULL_HANDLER = new FluidTankList(false, NULL_TANK); @Nullable IItemHandlerModifiable itemDelegate; @Nullable IMultipleTankHandler fluidDelegate; private final boolean isExport; - private static final MultiFluidTankEntry EMPTY = new MultiFluidTankEntry(new FluidTankList(false, new FluidTank[0]), - new FluidTank(0)); private final List notifiables = new ArrayList<>(); @@ -81,11 +84,40 @@ public void setStackInSlot(int slot, ItemStack stack) { itemDelegate.setStackInSlot(slot, stack); } + @NotNull + private IFluidTank getFirstTank() { + if (fluidDelegate == null) + return NULL_TANK; + + var tanks = this.fluidDelegate.getFluidTanks(); + tanks.sort(ENTRY_COMPARATOR); + return tanks.get(0); + + } + + @Override + public FluidStack getFluid() { + return getFirstTank().getFluid(); + } + + @Override + public int getFluidAmount() { + return getFirstTank().getFluidAmount(); + } + + @Override + public int getCapacity() { + return getFirstTank().getCapacity(); + } + + @Override + public FluidTankInfo getInfo() { + return getFirstTank().getInfo(); + } + @Override public IFluidTankProperties[] getTankProperties() { - return fluidDelegate == null ? - new IFluidTankProperties[0] : - fluidDelegate.getTankProperties(); + return new IFluidTankProperties[0]; } @Override @@ -118,22 +150,29 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { @Override public @NotNull List getFluidTanks() { - if (this.fluidDelegate == null) return Collections.emptyList(); - return this.fluidDelegate.getFluidTanks(); + return this.fluidDelegate == null ? + NULL_HANDLER.getFluidTanks() : + this.fluidDelegate.getFluidTanks(); } @Override public int getTanks() { - return this.fluidDelegate == null ? 0 : this.fluidDelegate.getTanks(); + return this.fluidDelegate == null ? + NULL_HANDLER.getTanks() : + this.fluidDelegate.getTanks(); } @Override public @NotNull MultiFluidTankEntry getTankAt(int index) { - return this.fluidDelegate == null ? EMPTY : this.fluidDelegate.getTankAt(index); + return this.fluidDelegate == null ? + NULL_HANDLER.getTankAt(0) : + this.fluidDelegate.getTankAt(index); } @Override public boolean allowSameFluidFill() { - return this.fluidDelegate != null && this.fluidDelegate.allowSameFluidFill(); + return this.fluidDelegate == null ? + NULL_HANDLER.allowSameFluidFill() : + this.fluidDelegate.allowSameFluidFill(); } } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 2f535feafd7..445deb0dee0 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -14,5 +14,5 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { } @NotNull - List registerAbilities(@NotNull MultiblockAbility key); + List registerAbilities(@NotNull MultiblockAbility key); } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 6f2357eb1d7..7764a457125 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -458,6 +458,26 @@ public int size() { }; } + public static void addHandlerToCollection(Collection collection, IItemHandler handler) { + for (int i = 0; i < handler.getSlots(); i++) { + var stack = handler.getStackInSlot(i); + if (stack.isEmpty() || collection.contains(stack)) + continue; + + collection.add(stack); + } + } + + public static void addHandlerToCollection(Collection collection, IMultipleTankHandler handler) { + for (var entry : handler.getFluidTanks()) { + var fluid = entry.getFluid(); + if (fluid == null || collection.contains(fluid)) + continue; + + collection.add(fluid); + } + } + public static NBTTagCompound getOrCreateNbtCompound(ItemStack stack) { NBTTagCompound compound = stack.getTagCompound(); if (compound == null) { diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index 3fb8af48f16..d191d4a2dab 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -178,7 +178,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java index 45231ed2fe8..02c25bc04d9 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java @@ -111,7 +111,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java index f4d29e296f5..9e5de853646 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java @@ -105,7 +105,8 @@ public ICubeRenderer getBaseTexture() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(exportFluids.getTankAt(0)); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java index 8d3e3f44297..1f3c440ed97 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java @@ -123,7 +123,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.getImportFluids()); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java index 82f58689c89..b23916492d2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java @@ -106,7 +106,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java index ac4817088ef..27ef218229b 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java @@ -152,7 +152,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index 1a849aab8ec..588b401c9c4 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -213,7 +213,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index e99df927acc..65ca101baf8 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -117,7 +117,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(energyContainer); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index f9f21e9532e..15ca0b0aab7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -258,7 +258,7 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { + public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java index c1128786b9c..ed872914429 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java @@ -251,8 +251,9 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { - var abilityList = new ArrayList<>(); + public @NotNull List registerAbilities( + @NotNull MultiblockAbility key) { + List abilityList = new ArrayList<>(); if (this.hasGhostCircuitInventory() && this.actualImportItems != null) { abilityList.add(isExportHatch ? this.exportItems : this.actualImportItems); } else { diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java index 1353a2780a3..a7c86e2d4f7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java @@ -71,7 +71,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.buffer); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index 9b795b57ed8..aeedea99da6 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -53,7 +53,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(machineHandler); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java index fb70cecb3f8..20f996f33eb 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java @@ -499,7 +499,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index e856a01658a..b72f2a9644d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -154,7 +154,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index 86554798e05..d0bea00cbb3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -199,7 +199,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return fluidTankList.getFluidTanks(); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java index 750b29948e0..33ddd4faf33 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java @@ -85,7 +85,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java index 681d4ff9ce3..5f394caa0ed 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java @@ -129,7 +129,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java index 666fba216ab..9f63f3ed479 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java @@ -156,7 +156,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java index a2f31a1f3df..05518b5901b 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java @@ -158,7 +158,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index 16675a8a9a3..b2a3c615dfd 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -113,7 +113,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(fluidTank); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java index c0c623eea7f..e5fd3bc31dd 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java @@ -147,7 +147,8 @@ void setRotorSpinning(boolean spinning) { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java index f16f331f861..8af88f7a352 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java @@ -331,7 +331,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.actualImportItems); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java index 72ce10d6358..7f96d8c9a08 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java @@ -271,7 +271,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.unmodifiableList(Arrays.asList(this.getAEFluidHandler().getInventory())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java index 318094a30bc..e1450d05a46 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java @@ -197,7 +197,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java index 4991bb47eb1..5a995eeb0d6 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java @@ -199,7 +199,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index c6ab8bd7aa4..30a5bdac587 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -68,7 +68,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java index 8e9dc7115a0..9cca569d09d 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java @@ -120,7 +120,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return this.importFluids.getFluidTanks(); } diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java index 896ab92ac38..a97c0ca0819 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java @@ -57,7 +57,8 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility multiblockAbility) { + public @NotNull List registerAbilities( + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(isExportHatch ? this.exportItems : this.importItems); } From 4f089376d6478d312be04bd8fb748328fbc64f3a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:52:15 -0700 Subject: [PATCH 020/103] fix typo + spotless --- src/main/java/gregtech/api/DualHandler.java | 5 ++--- .../metatileentities/electric/MetaTileEntityDiode.java | 2 +- .../common/metatileentities/electric/MetaTileEntityHull.java | 2 +- .../metatileentities/multi/MetaTileEntityPumpHatch.java | 2 +- .../metatileentities/multi/MetaTileEntityTankValve.java | 2 +- .../multiblockpart/MetaTileEntityAutoMaintenanceHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityComputationHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityDataAccessHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityEnergyHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityItemBus.java | 2 +- .../multi/multiblockpart/MetaTileEntityLaserHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityMachineHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityMaintenanceHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityMufflerHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityMultiFluidHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityObjectHolder.java | 2 +- .../multi/multiblockpart/MetaTileEntityOpticalDataHatch.java | 2 +- .../multiblockpart/MetaTileEntityPassthroughHatchFluid.java | 2 +- .../multiblockpart/MetaTileEntityPassthroughHatchItem.java | 2 +- .../multi/multiblockpart/MetaTileEntityReservoirHatch.java | 2 +- .../multi/multiblockpart/MetaTileEntityRotorHolder.java | 2 +- .../multiblockpart/appeng/MetaTileEntityMEInputBus.java | 2 +- .../multiblockpart/appeng/MetaTileEntityMEInputHatch.java | 2 +- .../multiblockpart/appeng/MetaTileEntityMEOutputBus.java | 2 +- .../multiblockpart/appeng/MetaTileEntityMEOutputHatch.java | 2 +- .../multiblockpart/hpca/MetaTileEntityHPCAComponent.java | 2 +- .../steam/multiblockpart/MetaTileEntitySteamHatch.java | 2 +- .../steam/multiblockpart/MetaTileEntitySteamItemBus.java | 2 +- 28 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 2fd2851f7ea..56a304de97f 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -17,7 +17,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler, INotifiableHandler { @@ -68,7 +67,8 @@ public int getSlotLimit(int slot) { return itemDelegate.getSlotLimit(slot); } - public void onContentsCahgned() { + // todo actually use this + public void onContentsChanged() { notifiables.forEach(mte -> { if (isExport) { mte.addNotifiedOutput(this); @@ -92,7 +92,6 @@ private IFluidTank getFirstTank() { var tanks = this.fluidDelegate.getFluidTanks(); tanks.sort(ENTRY_COMPARATOR); return tanks.get(0); - } @Override diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index d191d4a2dab..1f5ed2f332b 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -179,7 +179,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java index 02c25bc04d9..0b08cd68a1f 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java @@ -112,7 +112,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java index 9e5de853646..98c68354f48 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java @@ -106,7 +106,7 @@ public ICubeRenderer getBaseTexture() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(exportFluids.getTankAt(0)); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java index 1f3c440ed97..e24a90affcf 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java @@ -124,7 +124,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.getImportFluids()); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java index b23916492d2..4e4767f16d2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java @@ -107,7 +107,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java index 27ef218229b..c3b3a830009 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java @@ -153,7 +153,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index 588b401c9c4..cd07a9c585a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -214,7 +214,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index 65ca101baf8..66d7a07264e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -118,7 +118,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(energyContainer); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java index ed872914429..6c32ceae01a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java @@ -252,7 +252,7 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility key) { + @NotNull MultiblockAbility key) { List abilityList = new ArrayList<>(); if (this.hasGhostCircuitInventory() && this.actualImportItems != null) { abilityList.add(isExportHatch ? this.exportItems : this.actualImportItems); diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java index a7c86e2d4f7..1911b532b0a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java @@ -72,7 +72,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.buffer); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index aeedea99da6..d74c87ff903 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -54,7 +54,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(machineHandler); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java index 20f996f33eb..8b3b4f80f5e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java @@ -500,7 +500,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index b72f2a9644d..452848e2de2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -155,7 +155,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index d0bea00cbb3..3ee3dbbffa8 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -200,7 +200,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return fluidTankList.getFluidTanks(); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java index 33ddd4faf33..4820e9cfeb7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java @@ -86,7 +86,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java index 5f394caa0ed..f85fdc6d157 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java @@ -130,7 +130,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java index 9f63f3ed479..167362304ee 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java @@ -157,7 +157,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java index 05518b5901b..87ceca6b288 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java @@ -159,7 +159,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index b2a3c615dfd..972f0cbf9e0 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -114,7 +114,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(fluidTank); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java index e5fd3bc31dd..391e2b8a3e1 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java @@ -148,7 +148,7 @@ void setRotorSpinning(boolean spinning) { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java index 8af88f7a352..87fa8c4f390 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java @@ -332,7 +332,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this.actualImportItems); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java index 7f96d8c9a08..91e1b81544f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java @@ -272,7 +272,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.unmodifiableList(Arrays.asList(this.getAEFluidHandler().getInventory())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java index e1450d05a46..3985b3e4a32 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java @@ -198,7 +198,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java index 5a995eeb0d6..b8a32f2a6bd 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java @@ -200,7 +200,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index 30a5bdac587..06073332875 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -69,7 +69,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(this); } diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java index 9cca569d09d..4a4d57811be 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java @@ -121,7 +121,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return this.importFluids.getFluidTanks(); } diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java index a97c0ca0819..aa76f0864fb 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java @@ -58,7 +58,7 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { + @NotNull MultiblockAbility multiblockAbility) { return Collections.singletonList(isExportHatch ? this.exportItems : this.importItems); } From 8198390fbf1ee50fdf7281d055282e8dd4853155 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:54:27 -0700 Subject: [PATCH 021/103] forgor tank props --- src/main/java/gregtech/api/DualHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 56a304de97f..4b7266707b0 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -116,7 +116,9 @@ public FluidTankInfo getInfo() { @Override public IFluidTankProperties[] getTankProperties() { - return new IFluidTankProperties[0]; + return this.fluidDelegate == null ? + NULL_HANDLER.getTankProperties() : + this.fluidDelegate.getTankProperties(); } @Override From a6c25cd8e0019ec14ac3ce03ef12a23d282956c7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:59:02 -0700 Subject: [PATCH 022/103] use new method --- .../metatileentity/multiblock/MultiblockWithDisplayBase.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java index 4254640206d..54335f504c6 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java @@ -546,8 +546,7 @@ protected void setVoidingMode(int mode) { for (IFluidTank tank : this.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) { this.getNotifiedFluidInputList().add((IFluidHandler) tank); } - this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); - this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_DUAL)); + this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); markDirty(); } From 647d0620b8bd770427d9fc6223b08f0acfc0d25a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:38:26 -0700 Subject: [PATCH 023/103] try and improve checks for dual handlers --- .../capability/impl/AbstractRecipeLogic.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index d107c441f5f..3435bcdfe1d 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -627,21 +627,27 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul return null; } - if (inputs instanceof ItemHandlerList list) { - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); + List items = new ArrayList<>(); + List fluids = new ArrayList<>(); + + GTUtility.addHandlerToCollection(fluids, fluidInputs); + GTUtility.addHandlerToCollection(items, inputs); + + if (fluidInputs instanceof DualHandler dualHandler) { + GTUtility.addHandlerToCollection(items, dualHandler); + } + + if (inputs instanceof DualHandler dualHandler) { + GTUtility.addHandlerToCollection(fluids, dualHandler); + } else if (inputs instanceof ItemHandlerList list) { for (var handler : list.getBackingHandlers()) { if (handler instanceof DualHandler dualHandler) { GTUtility.addHandlerToCollection(fluids, dualHandler); } - GTUtility.addHandlerToCollection(items, handler); } - return map.findRecipe(maxVoltage, items, fluids); - } else if (inputs instanceof DualHandler dualHandler) { - return map.findRecipe(maxVoltage, dualHandler, dualHandler); - } else { - return map.findRecipe(maxVoltage, inputs, fluidInputs); } + + return map.findRecipe(maxVoltage, items, fluids); } /** From 14e1f5a9a28f402dc6e6637956f17142658db382 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:41:04 -0700 Subject: [PATCH 024/103] remove contains check --- src/main/java/gregtech/api/util/GTUtility.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 7764a457125..e038f497c85 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -461,7 +461,7 @@ public int size() { public static void addHandlerToCollection(Collection collection, IItemHandler handler) { for (int i = 0; i < handler.getSlots(); i++) { var stack = handler.getStackInSlot(i); - if (stack.isEmpty() || collection.contains(stack)) + if (stack.isEmpty()) continue; collection.add(stack); @@ -471,7 +471,7 @@ public static void addHandlerToCollection(Collection collection, IIte public static void addHandlerToCollection(Collection collection, IMultipleTankHandler handler) { for (var entry : handler.getFluidTanks()) { var fluid = entry.getFluid(); - if (fluid == null || collection.contains(fluid)) + if (fluid == null) continue; collection.add(fluid); From 82abff1d0eab6decd7ff3d638aed9942bfb3f76d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 12:43:27 -0700 Subject: [PATCH 025/103] mark delegates nonnull use onContentsChanged --- src/main/java/gregtech/api/DualHandler.java | 85 +++++++++---------- .../multiblock/MultiblockWithDisplayBase.java | 3 +- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 4b7266707b0..cb697762b79 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -2,37 +2,32 @@ import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.INotifiableHandler; -import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler, INotifiableHandler { - private static final IFluidTank NULL_TANK = new FluidTank(0); - private static final IMultipleTankHandler NULL_HANDLER = new FluidTankList(false, NULL_TANK); - - @Nullable + @NotNull IItemHandlerModifiable itemDelegate; - @Nullable + @NotNull IMultipleTankHandler fluidDelegate; private final boolean isExport; private final List notifiables = new ArrayList<>(); - public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler fluidDelegate, + public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, + @NotNull IMultipleTankHandler fluidDelegate, boolean isExport) { this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; @@ -41,25 +36,32 @@ public DualHandler(IItemHandlerModifiable itemDelegate, IMultipleTankHandler flu @Override public int getSlots() { - return itemDelegate == null ? 0 : itemDelegate.getSlots(); + return itemDelegate.getSlots(); } @Override public ItemStack getStackInSlot(int slot) { - if (itemDelegate == null) return ItemStack.EMPTY; return itemDelegate.getStackInSlot(slot); } @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (itemDelegate == null) return stack; - return itemDelegate.insertItem(slot, stack, simulate); + var inserted = itemDelegate.insertItem(slot, stack, simulate); + + if (!simulate && inserted.getCount() != stack.getCount()) + onContentsChanged(); + + return inserted; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (itemDelegate == null) return ItemStack.EMPTY; - return itemDelegate.extractItem(slot, amount, simulate); + var extracted = itemDelegate.extractItem(slot, amount, simulate); + + if (!simulate && !extracted.isEmpty()) + onContentsChanged(); + + return extracted; } @Override @@ -67,28 +69,23 @@ public int getSlotLimit(int slot) { return itemDelegate.getSlotLimit(slot); } - // todo actually use this public void onContentsChanged() { - notifiables.forEach(mte -> { + for (var mte : this.notifiables) { if (isExport) { mte.addNotifiedOutput(this); } else { mte.addNotifiedInput(this); } - }); + } } @Override public void setStackInSlot(int slot, ItemStack stack) { - if (itemDelegate == null) return; itemDelegate.setStackInSlot(slot, stack); } @NotNull private IFluidTank getFirstTank() { - if (fluidDelegate == null) - return NULL_TANK; - var tanks = this.fluidDelegate.getFluidTanks(); tanks.sort(ENTRY_COMPARATOR); return tanks.get(0); @@ -116,27 +113,37 @@ public FluidTankInfo getInfo() { @Override public IFluidTankProperties[] getTankProperties() { - return this.fluidDelegate == null ? - NULL_HANDLER.getTankProperties() : - this.fluidDelegate.getTankProperties(); + return this.fluidDelegate.getTankProperties(); } @Override public int fill(FluidStack resource, boolean doFill) { - if (fluidDelegate == null) return 0; - return fluidDelegate.fill(resource, doFill); + int filled = fluidDelegate.fill(resource, doFill); + + if (doFill && filled > 0) + onContentsChanged(); + + return filled; } @Override public FluidStack drain(FluidStack resource, boolean doDrain) { - if (fluidDelegate == null) return null; - return fluidDelegate.drain(resource, doDrain); + var drained = fluidDelegate.drain(resource, doDrain); + + if (doDrain && drained != null && drained.amount > 0) + onContentsChanged(); + + return drained; } @Override public FluidStack drain(int maxDrain, boolean doDrain) { - if (fluidDelegate == null) return null; - return fluidDelegate.drain(maxDrain, doDrain); + var drained = fluidDelegate.drain(maxDrain, doDrain); + + if (doDrain && drained != null && drained.amount > 0) + onContentsChanged(); + + return drained; } @Override @@ -151,29 +158,21 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { @Override public @NotNull List getFluidTanks() { - return this.fluidDelegate == null ? - NULL_HANDLER.getFluidTanks() : - this.fluidDelegate.getFluidTanks(); + return this.fluidDelegate.getFluidTanks(); } @Override public int getTanks() { - return this.fluidDelegate == null ? - NULL_HANDLER.getTanks() : - this.fluidDelegate.getTanks(); + return this.fluidDelegate.getTanks(); } @Override public @NotNull MultiFluidTankEntry getTankAt(int index) { - return this.fluidDelegate == null ? - NULL_HANDLER.getTankAt(0) : - this.fluidDelegate.getTankAt(index); + return this.fluidDelegate.getTankAt(index); } @Override public boolean allowSameFluidFill() { - return this.fluidDelegate == null ? - NULL_HANDLER.allowSameFluidFill() : - this.fluidDelegate.allowSameFluidFill(); + return this.fluidDelegate.allowSameFluidFill(); } } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java index 54335f504c6..a2fe0d9d2a0 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java @@ -546,7 +546,8 @@ protected void setVoidingMode(int mode) { for (IFluidTank tank : this.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) { this.getNotifiedFluidInputList().add((IFluidHandler) tank); } - this.getNotifiedItemInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + this.getNotifiedItemInputList() + .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); markDirty(); } From 63c2d41b18d5eb0c7408205a950440aae420f1d7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:01:53 -0700 Subject: [PATCH 026/103] INotifiable is not needed add field for dual handler in fluid hatch --- src/main/java/gregtech/api/DualHandler.java | 55 ++----------------- .../MetaTileEntityFluidHatch.java | 6 +- 2 files changed, 9 insertions(+), 52 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index cb697762b79..b9ee884d9de 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -16,7 +16,7 @@ import java.util.ArrayList; import java.util.List; -public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler, INotifiableHandler { +public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler { @NotNull IItemHandlerModifiable itemDelegate; @@ -24,8 +24,6 @@ public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipl IMultipleTankHandler fluidDelegate; private final boolean isExport; - private final List notifiables = new ArrayList<>(); - public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, @NotNull IMultipleTankHandler fluidDelegate, boolean isExport) { @@ -48,20 +46,12 @@ public ItemStack getStackInSlot(int slot) { public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { var inserted = itemDelegate.insertItem(slot, stack, simulate); - if (!simulate && inserted.getCount() != stack.getCount()) - onContentsChanged(); - return inserted; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { - var extracted = itemDelegate.extractItem(slot, amount, simulate); - - if (!simulate && !extracted.isEmpty()) - onContentsChanged(); - - return extracted; + return itemDelegate.extractItem(slot, amount, simulate); } @Override @@ -69,16 +59,6 @@ public int getSlotLimit(int slot) { return itemDelegate.getSlotLimit(slot); } - public void onContentsChanged() { - for (var mte : this.notifiables) { - if (isExport) { - mte.addNotifiedOutput(this); - } else { - mte.addNotifiedInput(this); - } - } - } - @Override public void setStackInSlot(int slot, ItemStack stack) { itemDelegate.setStackInSlot(slot, stack); @@ -118,42 +98,17 @@ public IFluidTankProperties[] getTankProperties() { @Override public int fill(FluidStack resource, boolean doFill) { - int filled = fluidDelegate.fill(resource, doFill); - - if (doFill && filled > 0) - onContentsChanged(); - - return filled; + return fluidDelegate.fill(resource, doFill); } @Override public FluidStack drain(FluidStack resource, boolean doDrain) { - var drained = fluidDelegate.drain(resource, doDrain); - - if (doDrain && drained != null && drained.amount > 0) - onContentsChanged(); - - return drained; + return fluidDelegate.drain(resource, doDrain); } @Override public FluidStack drain(int maxDrain, boolean doDrain) { - var drained = fluidDelegate.drain(maxDrain, doDrain); - - if (doDrain && drained != null && drained.amount > 0) - onContentsChanged(); - - return drained; - } - - @Override - public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.notifiables.add(metaTileEntity); - } - - @Override - public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.notifiables.remove(metaTileEntity); + return fluidDelegate.drain(maxDrain, doDrain); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 15ca0b0aab7..98aa16ff3c2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -70,6 +70,7 @@ public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiable protected final HatchFluidTank fluidTank; protected boolean workingEnabled; private GhostCircuitItemStackHandler circuitInventory; + private DualHandler dualHandler; // export hatch-only fields protected boolean locked; @@ -84,6 +85,7 @@ public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boo if (this.hasGhostCircuitInventory()) { this.circuitInventory = new GhostCircuitItemStackHandler(this); this.circuitInventory.addNotifiableMetaTileEntity(this); + this.dualHandler = new DualHandler(this.circuitInventory, this.importFluids, isExportHatch); } } @@ -260,9 +262,9 @@ public MultiblockAbility getAbility() { @Override public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { - return Collections.singletonList(fluidTank); + return Collections.singletonList(this.fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { - return Collections.singletonList(new DualHandler(this.circuitInventory, this.importFluids, false)); + return Collections.singletonList(this.dualHandler); } return Collections.emptyList(); } From 55bda4c2ced15cd3c17919ae5c1dcb91dc231cbf Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:17:15 -0700 Subject: [PATCH 027/103] use new method --- .../multiblock/RecipeMapMultiblockController.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 5e5dff522b3..7e104835847 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -119,10 +119,7 @@ public boolean isActive() { } protected void initializeAbilities() { - List l = new ArrayList<>(); - l.addAll(getAbilitiesModifiable(MultiblockAbility.IMPORT_ITEMS)); - l.addAll(getAbilitiesModifiable(MultiblockAbility.IMPORT_DUAL)); - this.inputInventory = new ItemHandlerList(Collections.unmodifiableList(l)); + this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); From 1da6d2b6e4067a737b64c4dfbb8d602164610fde Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:18:12 -0700 Subject: [PATCH 028/103] improve handler checking --- .../api/capability/impl/AbstractRecipeLogic.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 3435bcdfe1d..0f3e8b9dfd0 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -633,13 +633,14 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul GTUtility.addHandlerToCollection(fluids, fluidInputs); GTUtility.addHandlerToCollection(items, inputs); - if (fluidInputs instanceof DualHandler dualHandler) { - GTUtility.addHandlerToCollection(items, dualHandler); + if (fluidInputs instanceof FluidTankList tankList) { + for (var tank : tankList.getFluidTanks()) { + if (tank.getDelegate() instanceof DualHandler dualHandler) + GTUtility.addHandlerToCollection(items, dualHandler); + } } - if (inputs instanceof DualHandler dualHandler) { - GTUtility.addHandlerToCollection(fluids, dualHandler); - } else if (inputs instanceof ItemHandlerList list) { + if (inputs instanceof ItemHandlerList list) { for (var handler : list.getBackingHandlers()) { if (handler instanceof DualHandler dualHandler) { GTUtility.addHandlerToCollection(fluids, dualHandler); From cb8b678ac749885bfc8fb2e8d88076be77313184 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:25:35 -0700 Subject: [PATCH 029/103] forgor --- src/main/java/gregtech/api/DualHandler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index b9ee884d9de..4e041d61cd4 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -44,9 +44,7 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - var inserted = itemDelegate.insertItem(slot, stack, simulate); - - return inserted; + return itemDelegate.insertItem(slot, stack, simulate); } @Override From 0c5b3fcd238652bbfd376f3f6ac130d206c4cc95 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:25:56 -0700 Subject: [PATCH 030/103] spobl --- src/main/java/gregtech/api/DualHandler.java | 3 --- .../multiblock/RecipeMapMultiblockController.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/DualHandler.java index 4e041d61cd4..6185f2c3456 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/DualHandler.java @@ -1,8 +1,6 @@ package gregtech.api; import gregtech.api.capability.IMultipleTankHandler; -import gregtech.api.capability.INotifiableHandler; -import gregtech.api.metatileentity.MetaTileEntity; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -13,7 +11,6 @@ import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler { diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 7e104835847..a679df2aba1 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -36,7 +36,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public abstract class RecipeMapMultiblockController extends MultiblockWithDisplayBase implements IDataInfoProvider, @@ -119,7 +118,8 @@ public boolean isActive() { } protected void initializeAbilities() { - this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + this.inputInventory = new ItemHandlerList( + getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); From ac7c42d9c49aea21de7f5255e7ebb9645318782c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:01:32 -0700 Subject: [PATCH 031/103] move DualHandler to capability package --- src/main/java/gregtech/api/{ => capability}/DualHandler.java | 4 +--- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 2 +- .../api/metatileentity/multiblock/MultiblockAbility.java | 2 +- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) rename src/main/java/gregtech/api/{ => capability}/DualHandler.java (97%) diff --git a/src/main/java/gregtech/api/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java similarity index 97% rename from src/main/java/gregtech/api/DualHandler.java rename to src/main/java/gregtech/api/capability/DualHandler.java index 6185f2c3456..dd9c1981ea2 100644 --- a/src/main/java/gregtech/api/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -1,6 +1,4 @@ -package gregtech.api; - -import gregtech.api.capability.IMultipleTankHandler; +package gregtech.api.capability; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 0f3e8b9dfd0..9331d056e96 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -1,6 +1,6 @@ package gregtech.api.capability.impl; -import gregtech.api.DualHandler; +import gregtech.api.capability.DualHandler; import gregtech.api.GTValues; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index e43374ad379..4edfe1cd9af 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -1,6 +1,6 @@ package gregtech.api.metatileentity.multiblock; -import gregtech.api.DualHandler; +import gregtech.api.capability.DualHandler; import gregtech.api.capability.*; import gregtech.api.metatileentity.MetaTileEntity; diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 98aa16ff3c2..3d348ae5734 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -1,6 +1,6 @@ package gregtech.common.metatileentities.multi.multiblockpart; -import gregtech.api.DualHandler; +import gregtech.api.capability.DualHandler; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; From c67797adac7eb44b26426e97e55f468ecbbda735 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:17:31 -0700 Subject: [PATCH 032/103] add method for checking the ability at pos --- .../multiblock/MultiblockControllerBase.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index bf51955313e..6cb3b20c73b 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -355,6 +355,9 @@ public void checkStructurePattern() { if (part instanceof IMultiblockAbilityPart abilityPart) { List abilityList = abilityPart.getAbilities(); for (MultiblockAbility ability : abilityList) { + if (!checkAbilityPart(ability, ((MetaTileEntity) abilityPart).getPos())) + continue; + List abilityInstancesList = abilities.computeIfAbsent(ability, k -> new ArrayList<>()); abilityInstancesList.addAll(abilityPart.registerAbilities(ability)); @@ -377,6 +380,10 @@ public void checkStructurePattern() { } } + protected boolean checkAbilityPart(MultiblockAbility ability, BlockPos pos) { + return true; + } + protected void formStructure(PatternMatchContext context) {} public void invalidateStructure() { From 85b0cc24913da26644631f9345a16b6d08a49142 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:21:33 -0700 Subject: [PATCH 033/103] remove unnecessary methods and usages --- .../capability/impl/MultiblockRecipeLogic.java | 2 +- .../multiblock/MultiblockControllerBase.java | 17 ----------------- .../multiblock/MultiblockWithDisplayBase.java | 2 +- .../RecipeMapMultiblockController.java | 5 ++--- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ad05173d5c6..ff95f0fbb0c 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -84,7 +84,7 @@ protected IItemHandlerModifiable getInputInventory() { // Used for distinct bus recipe checking protected List getInputBuses() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; - return new ArrayList<>(controller.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + return controller.getAbilities(MultiblockAbility.IMPORT_ITEMS); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index 6cb3b20c73b..d218d095904 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -407,23 +407,6 @@ public List getAbilities(MultiblockAbility ability) { return Collections.unmodifiableList(getAbilitiesModifiable(ability)); } - public List getAbilities(MultiblockAbility ability1, - MultiblockAbility ability2) { - var combined = new ArrayList(); - combined.addAll(getAbilitiesModifiable(ability1)); - combined.addAll(getAbilitiesModifiable(ability2)); - return Collections.unmodifiableList(combined); - } - - @SafeVarargs - public final List getAbilities(MultiblockAbility... abilities) { - var combined = new ArrayList(); - for (var ability : abilities) { - combined.addAll(getAbilitiesModifiable(ability)); - } - return Collections.unmodifiableList(combined); - } - @SuppressWarnings("unchecked") public List getAbilitiesModifiable(MultiblockAbility ability) { return (List) multiblockAbilities.getOrDefault(ability, Collections.emptyList()); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java index a2fe0d9d2a0..b1339bb6fb5 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java @@ -547,7 +547,7 @@ protected void setVoidingMode(int mode) { this.getNotifiedFluidInputList().add((IFluidHandler) tank); } this.getNotifiedItemInputList() - .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); markDirty(); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index a679df2aba1..c8f477d6d12 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -118,8 +118,7 @@ public boolean isActive() { } protected void initializeAbilities() { - this.inputInventory = new ItemHandlerList( - getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS)); this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); @@ -255,7 +254,7 @@ public void setDistinct(boolean isDistinct) { // mark buses as changed on distinct toggle if (this.isDistinct) { this.notifiedItemInputList - .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_DUAL)); + .addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS)); } else { this.notifiedItemInputList.add(this.inputInventory); } From f4726f65ba886767bc344b3203f4bc8c648df486 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:33:45 -0700 Subject: [PATCH 034/103] move find recipe changes to MultiblockRecipeLogic --- .../capability/impl/AbstractRecipeLogic.java | 23 +-------------- .../impl/MultiblockRecipeLogic.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 9331d056e96..ed94a99955c 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -627,28 +627,7 @@ protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMul return null; } - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); - - GTUtility.addHandlerToCollection(fluids, fluidInputs); - GTUtility.addHandlerToCollection(items, inputs); - - if (fluidInputs instanceof FluidTankList tankList) { - for (var tank : tankList.getFluidTanks()) { - if (tank.getDelegate() instanceof DualHandler dualHandler) - GTUtility.addHandlerToCollection(items, dualHandler); - } - } - - if (inputs instanceof ItemHandlerList list) { - for (var handler : list.getBackingHandlers()) { - if (handler instanceof DualHandler dualHandler) { - GTUtility.addHandlerToCollection(fluids, dualHandler); - } - } - } - - return map.findRecipe(maxVoltage, items, fluids); + return map.findRecipe(maxVoltage, inputs, fluidInputs); } /** diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ff95f0fbb0c..2d6aa772921 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -1,6 +1,7 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; +import gregtech.api.capability.DualHandler; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; @@ -16,7 +17,9 @@ import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; +import net.minecraft.item.ItemStack; import net.minecraft.util.Tuple; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -240,6 +243,31 @@ protected void trySearchNewRecipeDistinct() { } } + @Override + protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, + IMultipleTankHandler fluidInputs) { + RecipeMap map = getRecipeMap(); + if (map == null || !isRecipeMapValid(map)) { + return null; + } + + List items = new ArrayList<>(); + List fluids = new ArrayList<>(); + + GTUtility.addHandlerToCollection(fluids, fluidInputs); + GTUtility.addHandlerToCollection(items, inputs); + + if (fluidInputs instanceof DualHandler dualHandler) { + GTUtility.addHandlerToCollection(items, dualHandler); + } + + if (inputs instanceof DualHandler dualHandler) { + GTUtility.addHandlerToCollection(fluids, dualHandler); + } + + return map.findRecipe(maxVoltage, items, fluids); + } + @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; From 352654d8be7a4412daeb96850d5edec739e35589 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:34:47 -0700 Subject: [PATCH 035/103] remove unnecessary abilities --- .../api/metatileentity/multiblock/MultiblockAbility.java | 3 --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 4edfe1cd9af..209f8f56724 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -29,9 +29,6 @@ public class MultiblockAbility { public static final MultiblockAbility EXPORT_FLUIDS = new MultiblockAbility<>("export_fluids"); public static final MultiblockAbility IMPORT_FLUIDS = new MultiblockAbility<>("import_fluids"); - public static final MultiblockAbility EXPORT_DUAL = new MultiblockAbility<>("export_dual"); - public static final MultiblockAbility IMPORT_DUAL = new MultiblockAbility<>("import_dual"); - public static final MultiblockAbility INPUT_ENERGY = new MultiblockAbility<>("input_energy"); public static final MultiblockAbility OUTPUT_ENERGY = new MultiblockAbility<>("output_energy"); diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 3d348ae5734..6f34dee7d52 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -56,6 +56,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -256,14 +257,14 @@ public MultiblockAbility getAbility() { public @NotNull List> getAbilities() { return isExportHatch ? Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS) : - Collections.singletonList(MultiblockAbility.IMPORT_DUAL); + Collections.singletonList(MultiblockAbility.IMPORT_FLUIDS); } @Override public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(this.fluidTank); - } else if (key.equals(MultiblockAbility.IMPORT_DUAL)) { + } else if (key.equals(MultiblockAbility.IMPORT_FLUIDS)) { return Collections.singletonList(this.dualHandler); } return Collections.emptyList(); From af5fa0c3dd21bfeb06211975f568db4efdf25b44 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:54:31 -0700 Subject: [PATCH 036/103] return key set which is the correct size --- src/main/java/gregtech/api/capability/impl/ItemHandlerList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/capability/impl/ItemHandlerList.java b/src/main/java/gregtech/api/capability/impl/ItemHandlerList.java index c696ee00759..05ce255f6ae 100644 --- a/src/main/java/gregtech/api/capability/impl/ItemHandlerList.java +++ b/src/main/java/gregtech/api/capability/impl/ItemHandlerList.java @@ -76,6 +76,6 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { @NotNull public Collection getBackingHandlers() { - return Collections.unmodifiableCollection(handlerBySlotIndex.values()); + return Collections.unmodifiableCollection(baseIndexOffset.keySet()); } } From 23576e07f75f94545c020154e1243fe389d8a3ed Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:57:31 -0700 Subject: [PATCH 037/103] actually check correctly remove sort --- .../java/gregtech/api/capability/DualHandler.java | 4 +--- .../api/capability/impl/MultiblockRecipeLogic.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index dd9c1981ea2..8294216e3bd 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -59,9 +59,7 @@ public void setStackInSlot(int slot, ItemStack stack) { @NotNull private IFluidTank getFirstTank() { - var tanks = this.fluidDelegate.getFluidTanks(); - tanks.sort(ENTRY_COMPARATOR); - return tanks.get(0); + return this.fluidDelegate.getTankAt(0); } @Override diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 2d6aa772921..43cf7ec8013 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Tuple; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -257,12 +258,18 @@ protected void trySearchNewRecipeDistinct() { GTUtility.addHandlerToCollection(fluids, fluidInputs); GTUtility.addHandlerToCollection(items, inputs); - if (fluidInputs instanceof DualHandler dualHandler) { - GTUtility.addHandlerToCollection(items, dualHandler); + for (IFluidTank tank : fluidInputs.getFluidTanks()) { + if (tank instanceof DualHandler dualHandler) + GTUtility.addHandlerToCollection(items, dualHandler); } if (inputs instanceof DualHandler dualHandler) { GTUtility.addHandlerToCollection(fluids, dualHandler); + } else if (inputs instanceof ItemHandlerList handlerList) { + for (IItemHandler handler : handlerList.getBackingHandlers()) { + if (handler instanceof DualHandler dualHandler) + GTUtility.addHandlerToCollection(fluids, dualHandler); + } } return map.findRecipe(maxVoltage, items, fluids); From 3d6ad01fe3f8602c10b86b06c80abc20bea5d904 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:25:47 -0700 Subject: [PATCH 038/103] minor oopsie --- .../gregtech/api/capability/impl/MultiblockRecipeLogic.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 43cf7ec8013..4a7c1a510f8 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -258,8 +258,8 @@ protected void trySearchNewRecipeDistinct() { GTUtility.addHandlerToCollection(fluids, fluidInputs); GTUtility.addHandlerToCollection(items, inputs); - for (IFluidTank tank : fluidInputs.getFluidTanks()) { - if (tank instanceof DualHandler dualHandler) + for (var tank : fluidInputs.getFluidTanks()) { + if (tank.getDelegate() instanceof DualHandler dualHandler) GTUtility.addHandlerToCollection(items, dualHandler); } From ba3300c258a10c8a17b005986d27695acf8fb838 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:37:17 -0700 Subject: [PATCH 039/103] fix issue in prepareRecipe --- .../capability/impl/AbstractRecipeLogic.java | 31 +++++++++++++++++++ .../impl/MultiblockRecipeLogic.java | 21 ++----------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index ed94a99955c..d63937eb501 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -36,6 +36,7 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -742,6 +743,36 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti return true; } + protected List gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + List items = new ArrayList<>(); + + GTUtility.addHandlerToCollection(items, inputInventory); + + for (var tank : inputFluids.getFluidTanks()) { + if (tank.getDelegate() instanceof IItemHandlerModifiable modifiable) + GTUtility.addHandlerToCollection(items, modifiable); + } + + return items; + } + + protected List gatherFluids(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + List fluids = new ArrayList<>(); + + GTUtility.addHandlerToCollection(fluids, inputFluids); + + if (inputInventory instanceof IMultipleTankHandler tankHandler) { + GTUtility.addHandlerToCollection(fluids, tankHandler); + } else if (inputInventory instanceof ItemHandlerList handlerList) { + for (IItemHandler handler : handlerList.getBackingHandlers()) { + if (handler instanceof IMultipleTankHandler tankHandler) + GTUtility.addHandlerToCollection(fluids, tankHandler); + } + } + + return fluids; + } + /** * Overclock a recipe beyond a duration of 1 tick using parallelization. * diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 4a7c1a510f8..9e1ac1f0f88 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -252,25 +252,8 @@ protected void trySearchNewRecipeDistinct() { return null; } - List items = new ArrayList<>(); - List fluids = new ArrayList<>(); - - GTUtility.addHandlerToCollection(fluids, fluidInputs); - GTUtility.addHandlerToCollection(items, inputs); - - for (var tank : fluidInputs.getFluidTanks()) { - if (tank.getDelegate() instanceof DualHandler dualHandler) - GTUtility.addHandlerToCollection(items, dualHandler); - } - - if (inputs instanceof DualHandler dualHandler) { - GTUtility.addHandlerToCollection(fluids, dualHandler); - } else if (inputs instanceof ItemHandlerList handlerList) { - for (IItemHandler handler : handlerList.getBackingHandlers()) { - if (handler instanceof DualHandler dualHandler) - GTUtility.addHandlerToCollection(fluids, dualHandler); - } - } + List items = gatherItems(inputs, fluidInputs); + List fluids = gatherFluids(inputs, fluidInputs); return map.findRecipe(maxVoltage, items, fluids); } From 6c2e89dce0bf691abe55906b014d748bcfc95c90 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:43:05 -0700 Subject: [PATCH 040/103] spblss --- .../java/gregtech/api/capability/impl/AbstractRecipeLogic.java | 1 - .../gregtech/api/capability/impl/MultiblockRecipeLogic.java | 2 -- .../api/metatileentity/multiblock/MultiblockAbility.java | 1 - .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 1 - 4 files changed, 5 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index d63937eb501..f362bd86a97 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -1,6 +1,5 @@ package gregtech.api.capability.impl; -import gregtech.api.capability.DualHandler; import gregtech.api.GTValues; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 9e1ac1f0f88..7f5a4bf79a6 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -1,7 +1,6 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; -import gregtech.api.capability.DualHandler; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; @@ -20,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Tuple; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 209f8f56724..b5187267437 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -1,6 +1,5 @@ package gregtech.api.metatileentity.multiblock; -import gregtech.api.capability.DualHandler; import gregtech.api.capability.*; import gregtech.api.metatileentity.MetaTileEntity; diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 6f34dee7d52..a1444b9d73a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -56,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; import java.util.Collections; import java.util.List; From 06fad3b99559d277c01e7ed6e713222abaa0c16a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:41:18 -0700 Subject: [PATCH 041/103] add DualEntry to implement IFluidTank unwrap dual handler into a list of entries --- .../gregtech/api/capability/DualHandler.java | 141 ++++++++++++++---- .../MetaTileEntityFluidHatch.java | 2 +- 2 files changed, 116 insertions(+), 27 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 8294216e3bd..fe89397dd8d 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -9,9 +9,10 @@ import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; -public class DualHandler implements IItemHandlerModifiable, IFluidTank, IMultipleTankHandler { +public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler { @NotNull IItemHandlerModifiable itemDelegate; @@ -27,6 +28,10 @@ public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, this.isExport = isExport; } + public boolean isExport() { + return this.isExport; + } + @Override public int getSlots() { return itemDelegate.getSlots(); @@ -57,31 +62,6 @@ public void setStackInSlot(int slot, ItemStack stack) { itemDelegate.setStackInSlot(slot, stack); } - @NotNull - private IFluidTank getFirstTank() { - return this.fluidDelegate.getTankAt(0); - } - - @Override - public FluidStack getFluid() { - return getFirstTank().getFluid(); - } - - @Override - public int getFluidAmount() { - return getFirstTank().getFluidAmount(); - } - - @Override - public int getCapacity() { - return getFirstTank().getCapacity(); - } - - @Override - public FluidTankInfo getInfo() { - return getFirstTank().getInfo(); - } - @Override public IFluidTankProperties[] getTankProperties() { return this.fluidDelegate.getTankProperties(); @@ -121,4 +101,113 @@ public int getTanks() { public boolean allowSameFluidFill() { return this.fluidDelegate.allowSameFluidFill(); } + + public List unwrap() { + int items = itemDelegate.getSlots(); + int fluids = fluidDelegate.getTanks(); + int max = Math.max(items, fluids); + + List list = new ArrayList<>(max); + for (int i = 0; i < max; i++) { + int itemIndex = -1; + if (i < items) + itemIndex = i; + + int fluidIndex = -1; + if (i < fluids) + fluidIndex = i; + + list.add(new DualEntry(this, itemIndex, fluidIndex)); + } + + return list; + } + + public static class DualEntry implements IItemHandlerModifiable, IFluidTank { + + private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); + + private final DualHandler delegate; + private final int itemIndex; + private final int fluidIndex; + + public DualEntry(DualHandler delegate, int itemIndex, int fluidIndex) { + this.delegate = delegate; + this.itemIndex = itemIndex; + this.fluidIndex = fluidIndex; + } + + public DualHandler getDelegate() { + return this.delegate; + } + + @Override + public FluidStack getFluid() { + if (fluidIndex == -1) return null; + return this.delegate.getTankAt(this.fluidIndex).getFluid(); + } + + @Override + public int getFluidAmount() { + if (fluidIndex == -1) return 0; + return this.delegate.getTankAt(this.fluidIndex).getFluidAmount(); + } + + @Override + public int getCapacity() { + if (fluidIndex == -1) return 0; + return this.delegate.getTankAt(this.fluidIndex).getCapacity(); + } + + @Override + public FluidTankInfo getInfo() { + if (fluidIndex == -1) return NULL; + return this.delegate.getTankAt(this.fluidIndex).getInfo(); + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + if (fluidIndex == -1) return 0; + return this.delegate.getTankAt(this.fluidIndex).fill(resource, doFill); + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + if (fluidIndex == -1) return null; + return this.delegate.getTankAt(this.fluidIndex).drain(maxDrain, doDrain); + } + + @Override + public int getSlots() { + return itemIndex == -1 ? 0 : 1; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (itemIndex == -1) return ItemStack.EMPTY; + return this.delegate.getStackInSlot(this.itemIndex); + } + + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + return this.delegate.insertItem(this.itemIndex, stack, simulate); + } + + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate) { + return this.delegate.extractItem(this.itemIndex, amount, simulate); + } + + @Override + public int getSlotLimit(int slot) { + if (itemIndex == -1) return 0; + return this.delegate.getSlotLimit(this.itemIndex); + } + + @Override + public void setStackInSlot(int slot, ItemStack stack) { + if (itemIndex == -1) return; + this.delegate.setStackInSlot(this.itemIndex, stack); + } + } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index a1444b9d73a..6e4c3b4f333 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -264,7 +264,7 @@ public MultiblockAbility getAbility() { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { return Collections.singletonList(this.fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_FLUIDS)) { - return Collections.singletonList(this.dualHandler); + return this.dualHandler.unwrap(); } return Collections.emptyList(); } From 235523832b27eb33adab3528611fbd6caba0671e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:11:51 -0700 Subject: [PATCH 042/103] lower interface check --- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index f362bd86a97..820a9c214e0 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -748,8 +748,8 @@ protected List gatherItems(IItemHandlerModifiable inputInventory, IMu GTUtility.addHandlerToCollection(items, inputInventory); for (var tank : inputFluids.getFluidTanks()) { - if (tank.getDelegate() instanceof IItemHandlerModifiable modifiable) - GTUtility.addHandlerToCollection(items, modifiable); + if (tank.getDelegate() instanceof IItemHandler handler) + GTUtility.addHandlerToCollection(items, handler); } return items; From 2aeaffe643e29de5be0edce5fb2b702ccbea4251 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:13:33 -0700 Subject: [PATCH 043/103] move more logic to MultiblockRecipeLogic fix small issue with recipe matching lists --- .../capability/impl/AbstractRecipeLogic.java | 6 +- .../impl/MultiblockRecipeLogic.java | 8 +++ .../java/gregtech/api/recipes/Recipe.java | 57 ++++++++----------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 820a9c214e0..a285581442e 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -407,7 +407,7 @@ protected void trySearchNewRecipe() { protected boolean checkPreviousRecipe() { if (this.previousRecipe == null) return false; if (this.previousRecipe.getEUt() > this.getMaxVoltage()) return false; - return this.previousRecipe.matches(false, getInputInventory(), getInputTank()); + return recipeMatch(this.previousRecipe, getInputInventory(), getInputTank()); } /** @@ -742,6 +742,10 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti return true; } + protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) { + return recipe.matches(true, inputItems, inputFluids); + } + protected List gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { List items = new ArrayList<>(); diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 7f5a4bf79a6..cef960d99c6 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -256,6 +256,14 @@ protected void trySearchNewRecipeDistinct() { return map.findRecipe(maxVoltage, items, fluids); } + @Override + protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) { + List items = gatherItems(inputItems, inputFluids); + List fluids = gatherFluids(inputItems, inputFluids); + + return recipe.matches(true, items, fluids); + } + @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index ff495651ac5..dc955c65530 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -245,46 +245,37 @@ public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable * @return true if the recipe matches the given inputs false otherwise. */ public boolean matches(boolean consumeIfSuccessful, List inputs, List fluidInputs) { - Pair fluids = null; - Pair items = null; - - if (fluidInputs.size() > 0) { - fluids = matchesFluid(fluidInputs); - if (!fluids.getKey()) { - return false; - } + Pair fluids = matchesFluid(fluidInputs); + if (!fluids.getKey()) { + return false; } - if (inputs.size() > 0) { - items = matchesItems(inputs); - if (!items.getKey()) { - return false; - } + Pair items = matchesItems(inputs); + if (!items.getKey()) { + return false; } if (consumeIfSuccessful) { - if (fluids != null) { - int[] fluidAmountInTank = fluids.getValue(); + int[] fluidAmountInTank = fluids.getValue(); - for (int i = 0; i < fluidAmountInTank.length; i++) { - FluidStack fluidStack = fluidInputs.get(i); - int fluidAmount = fluidAmountInTank[i]; - if (fluidStack == null || fluidStack.amount == fluidAmount) - continue; - fluidStack.amount = fluidAmount; - if (fluidStack.amount == 0) - fluidInputs.set(i, null); - } + for (int i = 0; i < fluidAmountInTank.length; i++) { + FluidStack fluidStack = fluidInputs.get(i); + int fluidAmount = fluidAmountInTank[i]; + if (fluidStack == null || fluidStack.amount == fluidAmount) + continue; + fluidStack.amount = fluidAmount; + if (fluidStack.amount == 0) + fluidInputs.set(i, null); } - if (items != null) { - int[] itemAmountInSlot = items.getValue(); - for (int i = 0; i < itemAmountInSlot.length; i++) { - ItemStack itemInSlot = inputs.get(i); - int itemAmount = itemAmountInSlot[i]; - if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount) - continue; - itemInSlot.setCount(itemAmountInSlot[i]); - } + + int[] itemAmountInSlot = items.getValue(); + + for (int i = 0; i < itemAmountInSlot.length; i++) { + ItemStack itemInSlot = inputs.get(i); + int itemAmount = itemAmountInSlot[i]; + if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount) + continue; + itemInSlot.setCount(itemAmountInSlot[i]); } } From 496107f83d17611d48354c41c577f8743aee68c0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:50:25 -0700 Subject: [PATCH 044/103] fix dt rebase make dual entry IFluidHandler --- .../gregtech/api/capability/DualHandler.java | 21 ++++++++++++++++++- .../impl/DistillationTowerLogicHandler.java | 5 +++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index fe89397dd8d..3bf65a736db 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -4,6 +4,8 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.fluids.capability.FluidTankProperties; +import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; @@ -123,18 +125,22 @@ public List unwrap() { return list; } - public static class DualEntry implements IItemHandlerModifiable, IFluidTank { + public static class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler { private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); private final DualHandler delegate; private final int itemIndex; private final int fluidIndex; + private final IFluidTankProperties[] props; public DualEntry(DualHandler delegate, int itemIndex, int fluidIndex) { this.delegate = delegate; this.itemIndex = itemIndex; this.fluidIndex = fluidIndex; + this.props = new IFluidTankProperties[] { + new FluidTankProperties(getFluid(), getCapacity()) + }; } public DualHandler getDelegate() { @@ -165,12 +171,23 @@ public FluidTankInfo getInfo() { return this.delegate.getTankAt(this.fluidIndex).getInfo(); } + @Override + public IFluidTankProperties[] getTankProperties() { + return this.props; + } + @Override public int fill(FluidStack resource, boolean doFill) { if (fluidIndex == -1) return 0; return this.delegate.getTankAt(this.fluidIndex).fill(resource, doFill); } + @Override + public FluidStack drain(FluidStack resource, boolean doDrain) { + if (fluidIndex == -1) return null; + return this.delegate.getTankAt(this.fluidIndex).drain(resource, doDrain); + } + @Override public FluidStack drain(int maxDrain, boolean doDrain) { if (fluidIndex == -1) return null; @@ -190,11 +207,13 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (itemIndex == -1) return stack; return this.delegate.insertItem(this.itemIndex, stack, simulate); } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (itemIndex == -1) return ItemStack.EMPTY; return this.delegate.extractItem(this.itemIndex, amount, simulate); } diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index e674db66763..41bbba3bae7 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -18,6 +18,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -92,9 +93,9 @@ public void determineOrderedFluidOutputs() { } MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex); if (part.getPos().getY() == y) { - List hatchTanks = new ObjectArrayList<>(); // noinspection unchecked - ((IMultiblockAbilityPart) part).registerAbilities(hatchTanks); + List hatchTanks = ((IMultiblockAbilityPart) part) + .registerAbilities(MultiblockAbility.EXPORT_FLUIDS); orderedHandlerList.add(new FluidTankList(false, hatchTanks)); tankList.addAll(hatchTanks); exportIndex++; From ebccd041358ee6bbdb053178a936aced91c368ba Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:50:57 -0700 Subject: [PATCH 045/103] sblss --- .../api/capability/impl/DistillationTowerLogicHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index 41bbba3bae7..1a0be3c3c22 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -18,7 +18,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; From 7666816afc9c920931a746e797b07857d8fe07b7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:56:23 -0700 Subject: [PATCH 046/103] fix props --- src/main/java/gregtech/api/capability/DualHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 3bf65a736db..ededd1b93cf 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -4,7 +4,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.FluidTankProperties; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; @@ -138,9 +137,9 @@ public DualEntry(DualHandler delegate, int itemIndex, int fluidIndex) { this.delegate = delegate; this.itemIndex = itemIndex; this.fluidIndex = fluidIndex; - this.props = new IFluidTankProperties[] { - new FluidTankProperties(getFluid(), getCapacity()) - }; + this.props = this.fluidIndex == -1 ? + new IFluidTankProperties[0] : + this.delegate.getTankAt(this.fluidIndex).getTankProperties(); } public DualHandler getDelegate() { From ac3aa2d9531d321fc010d12b7d91127e57806a3e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 13 Jul 2024 14:34:18 -0700 Subject: [PATCH 047/103] add constructor add getters for delegates --- .../gregtech/api/capability/DualHandler.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index ededd1b93cf..304247ca826 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -1,5 +1,7 @@ package gregtech.api.capability; +import gregtech.api.capability.impl.FluidTankList; + import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; @@ -29,6 +31,22 @@ public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, this.isExport = isExport; } + public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, + @NotNull IFluidTank fluidTank, + boolean isExport) { + this.itemDelegate = itemDelegate; + this.fluidDelegate = new FluidTankList(false, fluidTank); + this.isExport = isExport; + } + + public IItemHandlerModifiable getItemDelegate() { + return this.itemDelegate; + } + + public IMultipleTankHandler getFluidDelegate() { + return this.fluidDelegate; + } + public boolean isExport() { return this.isExport; } From 21d2a7a8515e28116fa47bbd9f233c5c7365ae8d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:24:13 -0700 Subject: [PATCH 048/103] fix issue with tests and recipe matching --- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 6 +++--- .../api/capability/impl/MultiblockRecipeLogic.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index a285581442e..3b25b4e0fc7 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -407,7 +407,7 @@ protected void trySearchNewRecipe() { protected boolean checkPreviousRecipe() { if (this.previousRecipe == null) return false; if (this.previousRecipe.getEUt() > this.getMaxVoltage()) return false; - return recipeMatch(this.previousRecipe, getInputInventory(), getInputTank()); + return recipeMatch(this.previousRecipe, false); } /** @@ -742,8 +742,8 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti return true; } - protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) { - return recipe.matches(true, inputItems, inputFluids); + protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { + return recipe.matches(shouldConsume, getInputInventory(), getInputTank()); } protected List gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index cef960d99c6..923a4bed480 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -257,11 +257,11 @@ protected void trySearchNewRecipeDistinct() { } @Override - protected boolean recipeMatch(Recipe recipe, IItemHandlerModifiable inputItems, IMultipleTankHandler inputFluids) { - List items = gatherItems(inputItems, inputFluids); - List fluids = gatherFluids(inputItems, inputFluids); + protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { + List items = gatherItems(getInputInventory(), getInputTank()); + List fluids = gatherFluids(getInputInventory(), getInputTank()); - return recipe.matches(true, items, fluids); + return recipe.matches(shouldConsume, items, fluids); } @Override From 88cf1ef1fd433f97bb1b21a764ad6114f4397c7f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:37:15 -0700 Subject: [PATCH 049/103] fix distinct recipe checking + misc --- .../api/capability/impl/MultiblockRecipeLogic.java | 5 ++++- src/main/java/gregtech/api/util/GTUtility.java | 10 ++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 923a4bed480..3321c9bddf9 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -277,7 +277,10 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank()); + List items = gatherItems(previousBus, getInputTank()); + List fluids = gatherFluids(previousBus, getInputTank()); + + return previousRecipe != null && previousRecipe.matches(false, items, fluids); } protected boolean prepareRecipeDistinct(Recipe recipe) { diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index e038f497c85..47b7ae85bb3 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -461,20 +461,14 @@ public int size() { public static void addHandlerToCollection(Collection collection, IItemHandler handler) { for (int i = 0; i < handler.getSlots(); i++) { var stack = handler.getStackInSlot(i); - if (stack.isEmpty()) - continue; - - collection.add(stack); + if (!stack.isEmpty()) collection.add(stack); } } public static void addHandlerToCollection(Collection collection, IMultipleTankHandler handler) { for (var entry : handler.getFluidTanks()) { var fluid = entry.getFluid(); - if (fluid == null) - continue; - - collection.add(fluid); + if (fluid != null) collection.add(fluid); } } From 671f64bc9dbfd58d7d774e5a1c597fdce0c7389f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:40:27 -0700 Subject: [PATCH 050/103] refactor IMultiblockAbilityPart to reduce list instantiations --- .../impl/DistillationTowerLogicHandler.java | 6 ++++-- .../multiblock/IMultiblockAbilityPart.java | 3 +-- .../multiblock/MultiblockControllerBase.java | 2 +- .../electric/MetaTileEntityDiode.java | 8 ++++---- .../metatileentities/electric/MetaTileEntityHull.java | 8 ++++---- .../multi/MetaTileEntityPumpHatch.java | 8 ++++---- .../multi/MetaTileEntityTankValve.java | 8 ++++---- .../MetaTileEntityAutoMaintenanceHatch.java | 8 ++++---- .../MetaTileEntityComputationHatch.java | 8 ++++---- .../multiblockpart/MetaTileEntityDataAccessHatch.java | 7 ++++--- .../multiblockpart/MetaTileEntityEnergyHatch.java | 7 ++++--- .../multiblockpart/MetaTileEntityFluidHatch.java | 8 ++++---- .../multi/multiblockpart/MetaTileEntityItemBus.java | 11 +++++------ .../multiblockpart/MetaTileEntityLaserHatch.java | 7 ++++--- .../multiblockpart/MetaTileEntityMachineHatch.java | 8 ++++---- .../MetaTileEntityMaintenanceHatch.java | 8 ++++---- .../multiblockpart/MetaTileEntityMufflerHatch.java | 8 ++++---- .../multiblockpart/MetaTileEntityMultiFluidHatch.java | 7 ++++--- .../multiblockpart/MetaTileEntityObjectHolder.java | 8 ++++---- .../MetaTileEntityOpticalDataHatch.java | 8 ++++---- .../MetaTileEntityPassthroughHatchFluid.java | 8 ++++---- .../MetaTileEntityPassthroughHatchItem.java | 8 ++++---- .../multiblockpart/MetaTileEntityReservoirHatch.java | 8 ++++---- .../multiblockpart/MetaTileEntityRotorHolder.java | 8 ++++---- .../appeng/MetaTileEntityMEInputBus.java | 8 ++++---- .../appeng/MetaTileEntityMEInputHatch.java | 8 ++++---- .../appeng/MetaTileEntityMEOutputBus.java | 8 ++++---- .../appeng/MetaTileEntityMEOutputHatch.java | 8 ++++---- .../hpca/MetaTileEntityHPCAComponent.java | 8 ++++---- .../multiblockpart/MetaTileEntitySteamHatch.java | 7 ++++--- .../multiblockpart/MetaTileEntitySteamItemBus.java | 8 ++++---- 31 files changed, 119 insertions(+), 114 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index 1a0be3c3c22..4f48af9fb98 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -18,6 +18,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -92,9 +93,10 @@ public void determineOrderedFluidOutputs() { } MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex); if (part.getPos().getY() == y) { + List hatchTanks = new ArrayList<>(); // noinspection unchecked - List hatchTanks = ((IMultiblockAbilityPart) part) - .registerAbilities(MultiblockAbility.EXPORT_FLUIDS); + ((IMultiblockAbilityPart) part) + .registerAbilities(MultiblockAbility.EXPORT_FLUIDS, hatchTanks); orderedHandlerList.add(new FluidTankList(false, hatchTanks)); tankList.addAll(hatchTanks); exportIndex++; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 445deb0dee0..140e286acda 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -13,6 +13,5 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { return Collections.singletonList(getAbility()); } - @NotNull - List registerAbilities(@NotNull MultiblockAbility key); + void registerAbilities(@NotNull MultiblockAbility key, @NotNull List abilities); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index d218d095904..ba0dfc1f5bf 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -360,7 +360,7 @@ public void checkStructurePattern() { List abilityInstancesList = abilities.computeIfAbsent(ability, k -> new ArrayList<>()); - abilityInstancesList.addAll(abilityPart.registerAbilities(ability)); + abilityPart.registerAbilities(ability, abilityInstancesList); } } } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index 1f5ed2f332b..e8ac72545a0 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -36,7 +36,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.Collections; import java.util.List; import static gregtech.api.capability.GregtechDataCodes.AMP_INDEX; @@ -178,9 +177,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java index 0b08cd68a1f..e32479f0466 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java @@ -29,7 +29,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityHull extends MetaTileEntityMultiblockPart @@ -111,9 +110,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java index 98c68354f48..b21fb2e4aff 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java @@ -35,7 +35,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityPumpHatch extends MetaTileEntityMultiblockPart @@ -105,9 +104,10 @@ public ICubeRenderer getBaseTexture() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(exportFluids.getTankAt(0)); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(exportFluids.getTankAt(0)); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java index e24a90affcf..28db2c710d8 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java @@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityTankValve extends MetaTileEntityMultiblockPart @@ -123,9 +122,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this.getImportFluids()); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this.getImportFluids()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java index 4e4767f16d2..59cab3b3c2e 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java @@ -23,7 +23,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityAutoMaintenanceHatch extends MetaTileEntityMultiblockPart implements @@ -106,9 +105,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java index c3b3a830009..155cdef3e8f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java @@ -27,7 +27,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.Collections; import java.util.List; public class MetaTileEntityComputationHatch extends MetaTileEntityMultiblockPart implements @@ -152,9 +151,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index cd07a9c585a..12ece6a08ca 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -213,9 +213,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index 66d7a07264e..27e09974239 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -117,9 +117,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(energyContainer); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(energyContainer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 6e4c3b4f333..a796a8e8c65 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -260,13 +260,13 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities(@NotNull MultiblockAbility key) { + public void registerAbilities(@NotNull MultiblockAbility key, + @NotNull List abilities) { if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { - return Collections.singletonList(this.fluidTank); + abilities.add(this.fluidTank); } else if (key.equals(MultiblockAbility.IMPORT_FLUIDS)) { - return this.dualHandler.unwrap(); + abilities.addAll(this.dualHandler.unwrap()); } - return Collections.emptyList(); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java index 6c32ceae01a..d43f93bc0f9 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java @@ -251,15 +251,14 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility key) { - List abilityList = new ArrayList<>(); + public void registerAbilities( + @NotNull MultiblockAbility key, + @NotNull List abilities) { if (this.hasGhostCircuitInventory() && this.actualImportItems != null) { - abilityList.add(isExportHatch ? this.exportItems : this.actualImportItems); + abilities.add(isExportHatch ? this.exportItems : this.actualImportItems); } else { - abilityList.add(isExportHatch ? this.exportItems : this.importItems); + abilities.add(isExportHatch ? this.exportItems : this.importItems); } - return abilityList; } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java index 1911b532b0a..03d8537fedc 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java @@ -71,9 +71,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this.buffer); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this.buffer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index d74c87ff903..31f16a4e3da 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityMachineHatch extends MetaTileEntityMultiblockNotifiablePart @@ -53,9 +52,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(machineHandler); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(machineHandler); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java index 8b3b4f80f5e..670cd50ad81 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java @@ -51,7 +51,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Consumer; @@ -499,9 +498,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index 452848e2de2..acd240ed5d1 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -37,7 +37,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityMufflerHatch extends MetaTileEntityMultiblockPart implements @@ -154,9 +153,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index 3ee3dbbffa8..7fa99239983 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -199,9 +199,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return fluidTankList.getFluidTanks(); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.addAll(fluidTankList.getFluidTanks()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java index 4820e9cfeb7..7fe40d12c32 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java @@ -34,7 +34,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityObjectHolder extends MetaTileEntityMultiblockNotifiablePart @@ -85,9 +84,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java index f85fdc6d157..251613e4b2d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.Collections; import java.util.List; public class MetaTileEntityOpticalDataHatch extends MetaTileEntityMultiblockNotifiablePart implements @@ -129,9 +128,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java index 167362304ee..2c9439ca2af 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java @@ -32,7 +32,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityPassthroughHatchFluid extends MetaTileEntityMultiblockPart implements IPassthroughHatch, @@ -156,9 +155,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java index 87ceca6b288..79a4a416895 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java @@ -32,7 +32,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityPassthroughHatchItem extends MetaTileEntityMultiblockPart implements IPassthroughHatch, @@ -158,9 +157,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index 972f0cbf9e0..c8d989200ba 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -38,7 +38,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -113,9 +112,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(fluidTank); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(fluidTank); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java index 391e2b8a3e1..33cb7807963 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java @@ -40,7 +40,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityRotorHolder extends MetaTileEntityMultiblockNotifiablePart @@ -147,9 +146,10 @@ void setRotorSpinning(boolean spinning) { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java index 87fa8c4f390..c97cf65f551 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java @@ -51,7 +51,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.Collections; import java.util.List; public class MetaTileEntityMEInputBus extends MetaTileEntityAEHostablePart @@ -331,9 +330,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this.actualImportItems); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this.actualImportItems); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java index 91e1b81544f..2eb5c4cf95f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java @@ -43,7 +43,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; -import java.util.Collections; import java.util.List; public class MetaTileEntityMEInputHatch extends MetaTileEntityAEHostablePart @@ -271,9 +270,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.unmodifiableList(Arrays.asList(this.getAEFluidHandler().getInventory())); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.addAll(Arrays.asList(this.getAEFluidHandler().getInventory())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java index 3985b3e4a32..0f48a189228 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java @@ -41,7 +41,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class MetaTileEntityMEOutputBus extends MetaTileEntityAEHostablePart @@ -197,9 +196,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java index b8a32f2a6bd..5c3505c26ea 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java @@ -43,7 +43,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class MetaTileEntityMEOutputHatch extends MetaTileEntityAEHostablePart @@ -199,9 +198,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index 06073332875..027105c0e47 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -33,7 +33,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public abstract class MetaTileEntityHPCAComponent extends MetaTileEntityMultiblockPart implements @@ -68,9 +67,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(this); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java index 4a4d57811be..45bf2e7703e 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java @@ -120,9 +120,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return this.importFluids.getFluidTanks(); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.addAll(this.importFluids.getFluidTanks()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java index aa76f0864fb..68cb9c126b0 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java @@ -34,7 +34,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class MetaTileEntitySteamItemBus extends MetaTileEntityItemBus { @@ -57,9 +56,10 @@ public MultiblockAbility getAbility() { } @Override - public @NotNull List registerAbilities( - @NotNull MultiblockAbility multiblockAbility) { - return Collections.singletonList(isExportHatch ? this.exportItems : this.importItems); + public void registerAbilities( + @NotNull MultiblockAbility multiblockAbility, + @NotNull List abilities) { + abilities.add(isExportHatch ? this.exportItems : this.importItems); } // Override base texture to have a bus with 4 slots, but ULV textures From fa2a6a6a83f5e8558e0d4fe3cf97bfe4b07b8567 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:42:29 -0700 Subject: [PATCH 051/103] use ObjectArrayList --- .../api/capability/impl/DistillationTowerLogicHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index 4f48af9fb98..cd8a6108bc7 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -18,7 +18,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -93,7 +92,7 @@ public void determineOrderedFluidOutputs() { } MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex); if (part.getPos().getY() == y) { - List hatchTanks = new ArrayList<>(); + List hatchTanks = new ObjectArrayList<>(); // noinspection unchecked ((IMultiblockAbilityPart) part) .registerAbilities(MultiblockAbility.EXPORT_FLUIDS, hatchTanks); From 6c5c857e221cc2d17005a0db3cca7298b7163fc7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:45:03 -0700 Subject: [PATCH 052/103] no need to use this method here --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index a796a8e8c65..b7c528aaf66 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -56,7 +56,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.List; public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiablePart @@ -252,13 +251,6 @@ public MultiblockAbility getAbility() { return isExportHatch ? MultiblockAbility.EXPORT_FLUIDS : MultiblockAbility.IMPORT_FLUIDS; } - @Override - public @NotNull List> getAbilities() { - return isExportHatch ? - Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS) : - Collections.singletonList(MultiblockAbility.IMPORT_FLUIDS); - } - @Override public void registerAbilities(@NotNull MultiblockAbility key, @NotNull List abilities) { From 11fe7249699487ddd9a50e5e10ad17e8363f6dd4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:01:57 -0700 Subject: [PATCH 053/103] fix rebase --- .../java/gregtech/api/capability/impl/AbstractRecipeLogic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 3b25b4e0fc7..2352f7009fb 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -702,7 +702,7 @@ protected static boolean areItemStacksEqual(@NotNull ItemStack stackA, @NotNull if (checkOutputSpaceItems(recipe, getOutputInventory()) && checkOutputSpaceFluids(recipe, getOutputTank())) { this.isOutputsFull = false; - if (recipe.matches(true, importInventory, importFluids)) { + if (recipeMatch(recipe, true)) { this.metaTileEntity.addNotifiedInput(importInventory); return recipe; } From d6a948455fd75798e767877a6e2ac06b8d2a22a5 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:10:00 -0700 Subject: [PATCH 054/103] return if there's nothing to check --- src/main/java/gregtech/api/recipes/Recipe.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index dc955c65530..fc275cdf52f 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -245,6 +245,9 @@ public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable * @return true if the recipe matches the given inputs false otherwise. */ public boolean matches(boolean consumeIfSuccessful, List inputs, List fluidInputs) { + if (inputs.size() == 0 && fluidInputs.size() == 0) + return false; + Pair fluids = matchesFluid(fluidInputs); if (!fluids.getKey()) { return false; From 6526f61fdfc8d5dbcb58c391192c7366458b62e1 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:51:55 -0700 Subject: [PATCH 055/103] attempt to retain references to the handlers --- .../capability/impl/AbstractRecipeLogic.java | 24 +++++++++---------- .../impl/MultiblockRecipeLogic.java | 12 +++++----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 2352f7009fb..42851d27f06 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -746,34 +746,32 @@ protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { return recipe.matches(shouldConsume, getInputInventory(), getInputTank()); } - protected List gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { - List items = new ArrayList<>(); + protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + List items = new ArrayList<>(); - GTUtility.addHandlerToCollection(items, inputInventory); + items.add(inputInventory); for (var tank : inputFluids.getFluidTanks()) { - if (tank.getDelegate() instanceof IItemHandler handler) - GTUtility.addHandlerToCollection(items, handler); + if (tank.getDelegate() instanceof IItemHandlerModifiable handler) + items.add(handler); } - return items; + return new ItemHandlerList(items); } - protected List gatherFluids(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { - List fluids = new ArrayList<>(); - - GTUtility.addHandlerToCollection(fluids, inputFluids); + protected IMultipleTankHandler gatherFluids(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + List fluids = new ArrayList<>(inputFluids.getFluidTanks()); if (inputInventory instanceof IMultipleTankHandler tankHandler) { - GTUtility.addHandlerToCollection(fluids, tankHandler); + fluids.addAll(tankHandler.getFluidTanks()); } else if (inputInventory instanceof ItemHandlerList handlerList) { for (IItemHandler handler : handlerList.getBackingHandlers()) { if (handler instanceof IMultipleTankHandler tankHandler) - GTUtility.addHandlerToCollection(fluids, tankHandler); + fluids.addAll(tankHandler.getFluidTanks()); } } - return fluids; + return new FluidTankList(inputFluids.allowSameFluidFill(), fluids); } /** diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 3321c9bddf9..ee9b1bc814d 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -250,16 +250,16 @@ protected void trySearchNewRecipeDistinct() { return null; } - List items = gatherItems(inputs, fluidInputs); - List fluids = gatherFluids(inputs, fluidInputs); + IItemHandlerModifiable items = gatherItems(inputs, fluidInputs); + IMultipleTankHandler fluids = gatherFluids(inputs, fluidInputs); return map.findRecipe(maxVoltage, items, fluids); } @Override protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { - List items = gatherItems(getInputInventory(), getInputTank()); - List fluids = gatherFluids(getInputInventory(), getInputTank()); + IItemHandlerModifiable items = gatherItems(getInputInventory(), getInputTank()); + IMultipleTankHandler fluids = gatherFluids(getInputInventory(), getInputTank()); return recipe.matches(shouldConsume, items, fluids); } @@ -277,8 +277,8 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - List items = gatherItems(previousBus, getInputTank()); - List fluids = gatherFluids(previousBus, getInputTank()); + IItemHandlerModifiable items = gatherItems(previousBus, getInputTank()); + IMultipleTankHandler fluids = gatherFluids(previousBus, getInputTank()); return previousRecipe != null && previousRecipe.matches(false, items, fluids); } From a355042fef22556f139bda6ca9c222e44aa6c9f0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:52:51 -0700 Subject: [PATCH 056/103] remove unused methods + spotless --- .../api/capability/impl/AbstractRecipeLogic.java | 6 ++++-- .../api/capability/impl/MultiblockRecipeLogic.java | 6 ++---- src/main/java/gregtech/api/util/GTUtility.java | 14 -------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 42851d27f06..2ecc59a92bb 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -746,7 +746,8 @@ protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { return recipe.matches(shouldConsume, getInputInventory(), getInputTank()); } - protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInventory, + IMultipleTankHandler inputFluids) { List items = new ArrayList<>(); items.add(inputInventory); @@ -759,7 +760,8 @@ protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInvento return new ItemHandlerList(items); } - protected IMultipleTankHandler gatherFluids(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { + protected IMultipleTankHandler gatherFluids(IItemHandlerModifiable inputInventory, + IMultipleTankHandler inputFluids) { List fluids = new ArrayList<>(inputFluids.getFluidTanks()); if (inputInventory instanceof IMultipleTankHandler tankHandler) { diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ee9b1bc814d..08c62bbcd87 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -16,9 +16,7 @@ import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; -import net.minecraft.item.ItemStack; import net.minecraft.util.Tuple; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -258,8 +256,8 @@ protected void trySearchNewRecipeDistinct() { @Override protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { - IItemHandlerModifiable items = gatherItems(getInputInventory(), getInputTank()); - IMultipleTankHandler fluids = gatherFluids(getInputInventory(), getInputTank()); + IItemHandlerModifiable items = gatherItems(getInputInventory(), getInputTank()); + IMultipleTankHandler fluids = gatherFluids(getInputInventory(), getInputTank()); return recipe.matches(shouldConsume, items, fluids); } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 47b7ae85bb3..6f2357eb1d7 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -458,20 +458,6 @@ public int size() { }; } - public static void addHandlerToCollection(Collection collection, IItemHandler handler) { - for (int i = 0; i < handler.getSlots(); i++) { - var stack = handler.getStackInSlot(i); - if (!stack.isEmpty()) collection.add(stack); - } - } - - public static void addHandlerToCollection(Collection collection, IMultipleTankHandler handler) { - for (var entry : handler.getFluidTanks()) { - var fluid = entry.getFluid(); - if (fluid != null) collection.add(fluid); - } - } - public static NBTTagCompound getOrCreateNbtCompound(ItemStack stack) { NBTTagCompound compound = stack.getTagCompound(); if (compound == null) { From b7dc3bcddfa77d8450669012beb1c24a5cc55dfd Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:00:57 -0700 Subject: [PATCH 057/103] try reduce list depth --- .../api/capability/impl/AbstractRecipeLogic.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 2ecc59a92bb..1a73c85ddb5 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -748,12 +748,16 @@ protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInventory, IMultipleTankHandler inputFluids) { - List items = new ArrayList<>(); + List items = new ArrayList<>(); - items.add(inputInventory); + if (inputInventory instanceof ItemHandlerList list) { + items.addAll(list.getBackingHandlers()); + } else { + items.add(inputInventory); + } for (var tank : inputFluids.getFluidTanks()) { - if (tank.getDelegate() instanceof IItemHandlerModifiable handler) + if (tank.getDelegate() instanceof IItemHandler handler) items.add(handler); } From e8fd9baafa9a84cb9c96cd8a9374c194c3a75f9a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:36:10 -0700 Subject: [PATCH 058/103] dual handler notifiable --- .../gregtech/api/capability/DualHandler.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 304247ca826..98fb027b7b9 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -2,6 +2,8 @@ import gregtech.api.capability.impl.FluidTankList; +import gregtech.api.metatileentity.MetaTileEntity; + import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; @@ -15,12 +17,14 @@ import java.util.ArrayList; import java.util.List; -public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler { +public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler { @NotNull IItemHandlerModifiable itemDelegate; @NotNull IMultipleTankHandler fluidDelegate; + + List notifiableEntities = new ArrayList<>(); private final boolean isExport; public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, @@ -63,11 +67,13 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (!simulate) onContentsChanged(); return itemDelegate.insertItem(slot, stack, simulate); } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (!simulate) onContentsChanged(); return itemDelegate.extractItem(slot, amount, simulate); } @@ -79,6 +85,7 @@ public int getSlotLimit(int slot) { @Override public void setStackInSlot(int slot, ItemStack stack) { itemDelegate.setStackInSlot(slot, stack); + if (!stack.isEmpty()) onContentsChanged(); } @Override @@ -88,16 +95,19 @@ public IFluidTankProperties[] getTankProperties() { @Override public int fill(FluidStack resource, boolean doFill) { + if (doFill) onContentsChanged(); return fluidDelegate.fill(resource, doFill); } @Override public FluidStack drain(FluidStack resource, boolean doDrain) { + if (doDrain) onContentsChanged(); return fluidDelegate.drain(resource, doDrain); } @Override public FluidStack drain(int maxDrain, boolean doDrain) { + if (doDrain) onContentsChanged(); return fluidDelegate.drain(maxDrain, doDrain); } @@ -142,6 +152,25 @@ public List unwrap() { return list; } + public void onContentsChanged() { + for (MetaTileEntity metaTileEntity : notifiableEntities) { + if (metaTileEntity != null && metaTileEntity.isValid()) { + addToNotifiedList(metaTileEntity, this, isExport); + } + } + } + + @Override + public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + if (metaTileEntity == null) return; + this.notifiableEntities.add(metaTileEntity); + } + + @Override + public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + this.notifiableEntities.remove(metaTileEntity); + } + public static class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler { private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); From c6356f08df3fe078a24d004c848f06f40f588884 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:40:12 -0700 Subject: [PATCH 059/103] size for notifiables --- .../api/capability/INotifiableHandler.java | 13 ++++++++++++ ...etaTileEntityMultiblockNotifiablePart.java | 20 +++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/capability/INotifiableHandler.java b/src/main/java/gregtech/api/capability/INotifiableHandler.java index 8dddb60482d..c9362912594 100644 --- a/src/main/java/gregtech/api/capability/INotifiableHandler.java +++ b/src/main/java/gregtech/api/capability/INotifiableHandler.java @@ -2,6 +2,9 @@ import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.items.IItemHandler; + /** * For Item and Fluid handlers capable of notifying entities when * their contents change @@ -30,4 +33,14 @@ default void addToNotifiedList(MetaTileEntity metaTileEntity, T handler, boo void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity); void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity); + + default int size() { + if (this instanceof IFluidTank) + return 1; + else if (this instanceof IItemHandler handler) + return handler.getSlots(); + else if (this instanceof IMultipleTankHandler tankHandler) + return tankHandler.getTanks(); + return 0; + } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java index 1d3d2be909f..2a97edf4fae 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java @@ -21,14 +21,14 @@ public MetaTileEntityMultiblockNotifiablePart(ResourceLocation metaTileEntityId, this.isExportHatch = isExportHatch; } - private NotifiableItemStackHandler getItemHandler() { - NotifiableItemStackHandler handler = null; - if (isExportHatch && getExportItems() instanceof NotifiableItemStackHandler) { - handler = (NotifiableItemStackHandler) getExportItems(); - } else if (!isExportHatch && getImportItems() instanceof NotifiableItemStackHandler) { - handler = (NotifiableItemStackHandler) getImportItems(); - } else if (getItemInventory() instanceof NotifiableItemStackHandler) { - handler = (NotifiableItemStackHandler) getItemInventory(); + private INotifiableHandler getItemHandler() { + INotifiableHandler handler = null; + if (isExportHatch && getExportItems() instanceof INotifiableHandler) { + handler = (INotifiableHandler) getExportItems(); + } else if (!isExportHatch && getImportItems() instanceof INotifiableHandler) { + handler = (INotifiableHandler) getImportItems(); + } else if (getItemInventory() instanceof INotifiableHandler) { + handler = (INotifiableHandler) getItemInventory(); } return handler; } @@ -46,8 +46,8 @@ private FluidTankList getFluidHandlers() { private List getPartHandlers() { List handlerList = new ArrayList<>(); - NotifiableItemStackHandler itemHandler = getItemHandler(); - if (itemHandler != null && itemHandler.getSlots() > 0) { + INotifiableHandler itemHandler = getItemHandler(); + if (itemHandler != null && itemHandler.size() > 0) { handlerList.add(itemHandler); } From d945704b35e329bf4184e53f22c72f2253c9829d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:31:37 -0700 Subject: [PATCH 060/103] casually refactor notifiables spotless --- .../gregtech/api/capability/DualHandler.java | 1 - .../api/metatileentity/MetaTileEntity.java | 9 +++--- ...etaTileEntityMultiblockNotifiablePart.java | 32 +++++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 98fb027b7b9..3c077c86143 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -1,7 +1,6 @@ package gregtech.api.capability; import gregtech.api.capability.impl.FluidTankList; - import gregtech.api.metatileentity.MetaTileEntity; import net.minecraft.item.ItemStack; diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 9424c6bb5ca..70cec89e9be 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -12,7 +12,6 @@ import gregtech.api.capability.impl.FluidHandlerProxy; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerProxy; -import gregtech.api.capability.impl.NotifiableFluidTank; import gregtech.api.cover.Cover; import gregtech.api.cover.CoverHolder; import gregtech.api.cover.CoverRayTracer; @@ -398,7 +397,8 @@ public void addNotifiedInput(Object input) { if (!notifiedItemInputList.contains(input)) { this.notifiedItemInputList.add((IItemHandlerModifiable) input); } - } else if (input instanceof IFluidHandler) { + } + if (input instanceof IFluidHandler) { if (!notifiedFluidInputList.contains(input)) { this.notifiedFluidInputList.add((IFluidHandler) input); } @@ -410,9 +410,10 @@ public void addNotifiedOutput(Object output) { if (!notifiedItemOutputList.contains(output)) { this.notifiedItemOutputList.add((IItemHandlerModifiable) output); } - } else if (output instanceof NotifiableFluidTank) { + } + if (output instanceof IFluidHandler) { if (!notifiedFluidOutputList.contains(output)) { - this.notifiedFluidOutputList.add((NotifiableFluidTank) output); + this.notifiedFluidOutputList.add((IFluidHandler) output); } } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java index 2a97edf4fae..148f40613f0 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java @@ -3,7 +3,7 @@ import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.INotifiableHandler; import gregtech.api.capability.impl.FluidTankList; -import gregtech.api.capability.impl.NotifiableItemStackHandler; +import gregtech.api.capability.impl.ItemHandlerList; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import net.minecraft.util.ResourceLocation; @@ -21,16 +21,21 @@ public MetaTileEntityMultiblockNotifiablePart(ResourceLocation metaTileEntityId, this.isExportHatch = isExportHatch; } - private INotifiableHandler getItemHandler() { - INotifiableHandler handler = null; - if (isExportHatch && getExportItems() instanceof INotifiableHandler) { - handler = (INotifiableHandler) getExportItems(); - } else if (!isExportHatch && getImportItems() instanceof INotifiableHandler) { - handler = (INotifiableHandler) getImportItems(); - } else if (getItemInventory() instanceof INotifiableHandler) { - handler = (INotifiableHandler) getItemInventory(); + private List getItemHandlers() { + List notifiables = new ArrayList<>(); + var mteHandler = isExportHatch ? getExportItems() : getImportItems(); + if (mteHandler instanceof INotifiableHandler notifiable) { + notifiables.add(notifiable); + } else if (mteHandler instanceof ItemHandlerList list) { + for (var handler : list.getBackingHandlers()) { + if (handler instanceof INotifiableHandler notifiable) + notifiables.add(notifiable); + } } - return handler; + if (getItemInventory() instanceof INotifiableHandler notifiable) { + notifiables.add(notifiable); + } + return notifiables; } private FluidTankList getFluidHandlers() { @@ -46,9 +51,10 @@ private FluidTankList getFluidHandlers() { private List getPartHandlers() { List handlerList = new ArrayList<>(); - INotifiableHandler itemHandler = getItemHandler(); - if (itemHandler != null && itemHandler.size() > 0) { - handlerList.add(itemHandler); + for (var notif : getItemHandlers()) { + if (notif.size() > 0) { + handlerList.add(notif); + } } if (this.fluidInventory.getTankProperties().length > 0) { From 7d2f3acb0e7a543fad3af303322419fb68c5f4af Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:25:23 -0700 Subject: [PATCH 061/103] fix issues with distinct consuming items --- .../api/capability/impl/AbstractRecipeLogic.java | 4 ++-- .../api/capability/impl/MultiblockRecipeLogic.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 1a73c85ddb5..c0f7c9f5dc0 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -746,7 +746,7 @@ protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { return recipe.matches(shouldConsume, getInputInventory(), getInputTank()); } - protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInventory, + protected IItemHandlerModifiable gatherItems(IItemHandler inputInventory, IMultipleTankHandler inputFluids) { List items = new ArrayList<>(); @@ -764,7 +764,7 @@ protected IItemHandlerModifiable gatherItems(IItemHandlerModifiable inputInvento return new ItemHandlerList(items); } - protected IMultipleTankHandler gatherFluids(IItemHandlerModifiable inputInventory, + protected IMultipleTankHandler gatherFluids(IItemHandler inputInventory, IMultipleTankHandler inputFluids) { List fluids = new ArrayList<>(inputFluids.getFluidTanks()); diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 08c62bbcd87..d05422dcf38 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -1,6 +1,7 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; +import gregtech.api.capability.IDistinctBusController; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; @@ -256,8 +257,13 @@ protected void trySearchNewRecipeDistinct() { @Override protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { - IItemHandlerModifiable items = gatherItems(getInputInventory(), getInputTank()); - IMultipleTankHandler fluids = gatherFluids(getInputInventory(), getInputTank()); + IItemHandler input = getInputInventory(); + if (metaTileEntity instanceof IDistinctBusController distinct && distinct.isDistinct()) { + input = currentDistinctInputBus; + } + + IItemHandlerModifiable items = gatherItems(input, getInputTank()); + IMultipleTankHandler fluids = gatherFluids(input, getInputTank()); return recipe.matches(shouldConsume, items, fluids); } From 24917279432f44694772641a1565d8f7c228c8a5 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:52:22 -0700 Subject: [PATCH 062/103] address reviews --- .../gregtech/api/capability/DualHandler.java | 37 +++++++++++++------ .../impl/MultiblockRecipeLogic.java | 4 +- .../multiblock/MultiblockAbility.java | 2 +- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 3c077c86143..29db8f00d9c 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -2,6 +2,7 @@ import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.util.ItemStackHashStrategy; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -18,6 +19,11 @@ public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler { + private static final ItemStackHashStrategy strategy = ItemStackHashStrategy.builder() + .compareItem(true) + .compareDamage(true) + .compareTag(true) + .build(); @NotNull IItemHandlerModifiable itemDelegate; @NotNull @@ -66,14 +72,18 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (!simulate) onContentsChanged(); - return itemDelegate.insertItem(slot, stack, simulate); + var remainder = itemDelegate.insertItem(slot, stack, simulate); + if (!simulate && !strategy.equals(remainder, stack)) + onContentsChanged(); + return remainder; } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (!simulate) onContentsChanged(); - return itemDelegate.extractItem(slot, amount, simulate); + var extracted = itemDelegate.extractItem(slot, amount, simulate); + if (!simulate && !extracted.isEmpty()) + onContentsChanged(); + return extracted; } @Override @@ -83,8 +93,10 @@ public int getSlotLimit(int slot) { @Override public void setStackInSlot(int slot, ItemStack stack) { + var oldStack = itemDelegate.getStackInSlot(slot); itemDelegate.setStackInSlot(slot, stack); - if (!stack.isEmpty()) onContentsChanged(); + if (!strategy.equals(oldStack, stack)) + onContentsChanged(); } @Override @@ -94,20 +106,23 @@ public IFluidTankProperties[] getTankProperties() { @Override public int fill(FluidStack resource, boolean doFill) { - if (doFill) onContentsChanged(); - return fluidDelegate.fill(resource, doFill); + int filled = fluidDelegate.fill(resource, doFill); + if (doFill && filled > 0) onContentsChanged(); + return filled; } @Override public FluidStack drain(FluidStack resource, boolean doDrain) { - if (doDrain) onContentsChanged(); - return fluidDelegate.drain(resource, doDrain); + var drained = fluidDelegate.drain(resource, doDrain); + if (doDrain && drained != null) onContentsChanged(); + return drained; } @Override public FluidStack drain(int maxDrain, boolean doDrain) { - if (doDrain) onContentsChanged(); - return fluidDelegate.drain(maxDrain, doDrain); + var drained = fluidDelegate.drain(maxDrain, doDrain); + if (doDrain && drained != null) onContentsChanged(); + return drained; } @Override diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index d05422dcf38..fa81ac0b5eb 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -281,10 +281,12 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { + if (previousRecipe == null) return false; + IItemHandlerModifiable items = gatherItems(previousBus, getInputTank()); IMultipleTankHandler fluids = gatherFluids(previousBus, getInputTank()); - return previousRecipe != null && previousRecipe.matches(false, items, fluids); + return previousRecipe.matches(false, items, fluids); } protected boolean prepareRecipeDistinct(Recipe recipe) { diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index b5187267437..2859348bdec 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -98,6 +98,6 @@ public String toString() { @Override public boolean equals(Object obj) { return obj instanceof MultiblockAbilityother && - this.name.equals(other.toString()); + this.name.equals(other.name); } } From 7786efc09fa8649feccec57d5e5443feb6ecf34e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:02:18 -0700 Subject: [PATCH 063/103] store class for type checking add special list for instances --- .../multiblock/AbilityInstances.java | 37 +++++ .../multiblock/MultiblockAbility.java | 141 +++++++++++------- 2 files changed, 122 insertions(+), 56 deletions(-) create mode 100644 src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java new file mode 100644 index 00000000000..7960b80898b --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -0,0 +1,37 @@ +package gregtech.api.metatileentity.multiblock; + +import org.jetbrains.annotations.Nullable; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.List; + +public class AbilityInstances extends AbstractList { + + private final MultiblockAbility key; + private final List instances = new ArrayList<>(); + + public AbilityInstances(MultiblockAbility key) { + this.key = key; + } + + @Override + public Object get(int index) { + return instances.get(index); + } + + public @Nullable R getAndCast(int index, MultiblockAbility key) { + return key.checkAndCast(get(index)); + } + + @Override + public boolean add(Object o) { + if (!key.checkType(o)) return false; + return instances.add(o); + } + + @Override + public int size() { + return instances.size(); + } +} diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 2859348bdec..745991654a5 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -8,6 +8,7 @@ import net.minecraftforge.items.IItemHandlerModifiable; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -20,61 +21,73 @@ public class MultiblockAbility { public static final Map> NAME_REGISTRY = new HashMap<>(); public static final Map, List> REGISTRY = new Object2ObjectOpenHashMap<>(); - public static final MultiblockAbility EXPORT_ITEMS = new MultiblockAbility<>( - "export_items"); - public static final MultiblockAbility IMPORT_ITEMS = new MultiblockAbility<>( - "import_items"); - - public static final MultiblockAbility EXPORT_FLUIDS = new MultiblockAbility<>("export_fluids"); - public static final MultiblockAbility IMPORT_FLUIDS = new MultiblockAbility<>("import_fluids"); - - public static final MultiblockAbility INPUT_ENERGY = new MultiblockAbility<>("input_energy"); - public static final MultiblockAbility OUTPUT_ENERGY = new MultiblockAbility<>("output_energy"); - - public static final MultiblockAbility SUBSTATION_INPUT_ENERGY = new MultiblockAbility<>( - "substation_input_energy"); - public static final MultiblockAbility SUBSTATION_OUTPUT_ENERGY = new MultiblockAbility<>( - "substation_output_energy"); - - public static final MultiblockAbility ROTOR_HOLDER = new MultiblockAbility<>("rotor_holder"); - - public static final MultiblockAbility PUMP_FLUID_HATCH = new MultiblockAbility<>("pump_fluid_hatch"); - - public static final MultiblockAbility STEAM = new MultiblockAbility<>("steam"); - public static final MultiblockAbility STEAM_IMPORT_ITEMS = new MultiblockAbility<>( - "steam_import_items"); - public static final MultiblockAbility STEAM_EXPORT_ITEMS = new MultiblockAbility<>( - "steam_export_items"); - - public static final MultiblockAbility MAINTENANCE_HATCH = new MultiblockAbility<>( - "maintenance_hatch"); - public static final MultiblockAbility MUFFLER_HATCH = new MultiblockAbility<>("muffler_hatch"); - - public static final MultiblockAbility MACHINE_HATCH = new MultiblockAbility<>( - "machine_hatch"); - - public static final MultiblockAbility TANK_VALVE = new MultiblockAbility<>("tank_valve"); - - public static final MultiblockAbility PASSTHROUGH_HATCH = new MultiblockAbility<>( - "passthrough_hatch"); - - public static final MultiblockAbility DATA_ACCESS_HATCH = new MultiblockAbility<>( - "data_access_hatch"); - public static final MultiblockAbility OPTICAL_DATA_RECEPTION = new MultiblockAbility<>( - "optical_data_reception"); - public static final MultiblockAbility OPTICAL_DATA_TRANSMISSION = new MultiblockAbility<>( - "optical_data_transmission"); - public static final MultiblockAbility INPUT_LASER = new MultiblockAbility<>("input_laser"); - public static final MultiblockAbility OUTPUT_LASER = new MultiblockAbility<>("output_laser"); - - public static final MultiblockAbility COMPUTATION_DATA_RECEPTION = new MultiblockAbility<>( - "computation_data_reception"); - public static final MultiblockAbility COMPUTATION_DATA_TRANSMISSION = new MultiblockAbility<>( - "computation_data_transmission"); - - public static final MultiblockAbility HPCA_COMPONENT = new MultiblockAbility<>( - "hpca_component"); - public static final MultiblockAbility OBJECT_HOLDER = new MultiblockAbility<>("object_holder"); + public static final MultiblockAbility EXPORT_ITEMS = ability( + "export_items", IItemHandlerModifiable.class); + public static final MultiblockAbility IMPORT_ITEMS = ability( + "import_items", IItemHandlerModifiable.class); + + public static final MultiblockAbility EXPORT_FLUIDS = ability( + "export_fluids", IFluidTank.class); + public static final MultiblockAbility IMPORT_FLUIDS = ability( + "import_fluids", IFluidTank.class); + + public static final MultiblockAbility INPUT_ENERGY = ability( + "input_energy", IEnergyContainer.class); + public static final MultiblockAbility OUTPUT_ENERGY = ability( + "output_energy", IEnergyContainer.class); + + public static final MultiblockAbility SUBSTATION_INPUT_ENERGY = ability( + "substation_input_energy", IEnergyContainer.class); + public static final MultiblockAbility SUBSTATION_OUTPUT_ENERGY = ability( + "substation_output_energy", IEnergyContainer.class); + + public static final MultiblockAbility ROTOR_HOLDER = ability( + "rotor_holder", IRotorHolder.class); + + public static final MultiblockAbility PUMP_FLUID_HATCH = ability( + "pump_fluid_hatch", IFluidTank.class); + + public static final MultiblockAbility STEAM = new MultiblockAbility<>( + "steam", IFluidTank.class); + public static final MultiblockAbility STEAM_IMPORT_ITEMS = ability( + "steam_import_items", IItemHandlerModifiable.class); + public static final MultiblockAbility STEAM_EXPORT_ITEMS = ability( + "steam_export_items", IItemHandlerModifiable.class); + + public static final MultiblockAbility MAINTENANCE_HATCH = ability( + "maintenance_hatch", IMaintenanceHatch.class); + public static final MultiblockAbility MUFFLER_HATCH = ability( + "muffler_hatch", IMufflerHatch.class); + + public static final MultiblockAbility MACHINE_HATCH = ability( + "machine_hatch", IItemHandlerModifiable.class); + + public static final MultiblockAbility TANK_VALVE = ability( + "tank_valve", IFluidHandler.class); + + public static final MultiblockAbility PASSTHROUGH_HATCH = ability( + "passthrough_hatch", IPassthroughHatch.class); + + public static final MultiblockAbility DATA_ACCESS_HATCH = ability( + "data_access_hatch", IDataAccessHatch.class); + public static final MultiblockAbility OPTICAL_DATA_RECEPTION = ability( + "optical_data_reception", IOpticalDataAccessHatch.class); + public static final MultiblockAbility OPTICAL_DATA_TRANSMISSION = ability( + "optical_data_transmission", IOpticalDataAccessHatch.class); + public static final MultiblockAbility INPUT_LASER = ability( + "input_laser", ILaserContainer.class); + public static final MultiblockAbility OUTPUT_LASER = ability( + "output_laser", ILaserContainer.class); + + public static final MultiblockAbility COMPUTATION_DATA_RECEPTION = ability( + "computation_data_reception", IOpticalComputationHatch.class); + public static final MultiblockAbility COMPUTATION_DATA_TRANSMISSION = ability( + "computation_data_transmission", IOpticalComputationHatch.class); + + public static final MultiblockAbility HPCA_COMPONENT = ability( + "hpca_component", IHPCAComponentHatch.class); + public static final MultiblockAbility OBJECT_HOLDER = ability( + "object_holder", IObjectHolder.class); public static void registerMultiblockAbility(MultiblockAbility ability, MetaTileEntity part) { if (!REGISTRY.containsKey(ability)) { @@ -83,10 +96,16 @@ public static void registerMultiblockAbility(MultiblockAbility ability, MetaT REGISTRY.get(ability).add(part); } + public static MultiblockAbility ability(String name, Class clazz) { + return new MultiblockAbility<>(name, clazz); + } + private final String name; + private final Class clazz; - public MultiblockAbility(String name) { + public MultiblockAbility(String name, Class clazz) { this.name = name.toLowerCase(); + this.clazz = clazz; NAME_REGISTRY.put(this.name, this); } @@ -100,4 +119,14 @@ public boolean equals(Object obj) { return obj instanceof MultiblockAbilityother && this.name.equals(other.name); } + + public boolean checkType(Object o) { + return clazz.isAssignableFrom(o.getClass()); + } + + public @Nullable T checkAndCast(Object o) { + if (checkType(o)) + return clazz.cast(o); + else return null; + } } From 8d833368979a2eb041642864118d4ed26d0bdefe Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:14:41 -0700 Subject: [PATCH 064/103] utilize new list --- .../multiblock/AbilityInstances.java | 27 +++++++++++++++++++ .../multiblock/MultiblockControllerBase.java | 11 ++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 7960b80898b..7c66053e8af 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -1,5 +1,6 @@ package gregtech.api.metatileentity.multiblock; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.AbstractList; @@ -8,6 +9,23 @@ public class AbilityInstances extends AbstractList { + public static final AbilityInstances EMPTY = new AbilityInstances(null) { + + @Override + public boolean isKey(MultiblockAbility key) { + return false; + } + + @Override + public boolean add(Object o) { + return false; + } + + @Override + public Object get(int index) { + return null; + } + }; private final MultiblockAbility key; private final List instances = new ArrayList<>(); @@ -20,10 +38,19 @@ public Object get(int index) { return instances.get(index); } + public boolean isKey(MultiblockAbility key) { + return this.key.equals(key); + } + public @Nullable R getAndCast(int index, MultiblockAbility key) { return key.checkAndCast(get(index)); } + @SuppressWarnings("unchecked") + public @NotNull List cast() { + return (List) this; + } + @Override public boolean add(Object o) { if (!key.checkType(o)) return false; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index ba0dfc1f5bf..45fa03841b1 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -80,7 +80,7 @@ public abstract class MultiblockControllerBase extends MetaTileEntity implements @Nullable public BlockPattern structurePattern; - private final Map, List> multiblockAbilities = new HashMap<>(); + private final Map, AbilityInstances> multiblockAbilities = new HashMap<>(); private final List multiblockParts = new ArrayList<>(); private boolean structureFormed; @@ -350,7 +350,7 @@ public void checkStructurePattern() { } this.setFlipped(context.neededFlip()); parts.sort(Comparator.comparing(it -> multiblockPartSorter().apply(((MetaTileEntity) it).getPos()))); - Map, List> abilities = new HashMap<>(); + Map, AbilityInstances> abilities = new HashMap<>(); for (IMultiblockPart part : parts) { if (part instanceof IMultiblockAbilityPart abilityPart) { List abilityList = abilityPart.getAbilities(); @@ -358,8 +358,8 @@ public void checkStructurePattern() { if (!checkAbilityPart(ability, ((MetaTileEntity) abilityPart).getPos())) continue; - List abilityInstancesList = abilities.computeIfAbsent(ability, - k -> new ArrayList<>()); + AbilityInstances abilityInstancesList = abilities.computeIfAbsent(ability, + AbilityInstances::new); abilityPart.registerAbilities(ability, abilityInstancesList); } } @@ -407,9 +407,8 @@ public List getAbilities(MultiblockAbility ability) { return Collections.unmodifiableList(getAbilitiesModifiable(ability)); } - @SuppressWarnings("unchecked") public List getAbilitiesModifiable(MultiblockAbility ability) { - return (List) multiblockAbilities.getOrDefault(ability, Collections.emptyList()); + return multiblockAbilities.getOrDefault(ability, AbilityInstances.EMPTY).cast(); } public List getMultiblockParts() { From bbf145bc39bafdc2785afd4e87966a08cd96b6f4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:25:47 -0700 Subject: [PATCH 065/103] update registration to new list --- .../impl/DistillationTowerLogicHandler.java | 9 +++++---- .../multiblock/IMultiblockAbilityPart.java | 2 +- .../multiblock/MultiblockControllerBase.java | 4 ++-- .../electric/MetaTileEntityDiode.java | 7 +++---- .../electric/MetaTileEntityHull.java | 7 +++---- .../multi/MetaTileEntityPumpHatch.java | 7 +++---- .../multi/MetaTileEntityTankValve.java | 7 +++---- .../MetaTileEntityAutoMaintenanceHatch.java | 7 +++---- .../MetaTileEntityComputationHatch.java | 7 +++---- .../MetaTileEntityDataAccessHatch.java | 7 +++---- .../multiblockpart/MetaTileEntityEnergyHatch.java | 7 +++---- .../multiblockpart/MetaTileEntityFluidHatch.java | 12 ++++++------ .../multi/multiblockpart/MetaTileEntityItemBus.java | 9 ++++----- .../multiblockpart/MetaTileEntityLaserHatch.java | 7 +++---- .../multiblockpart/MetaTileEntityMachineHatch.java | 7 +++---- .../MetaTileEntityMaintenanceHatch.java | 11 +++-------- .../multiblockpart/MetaTileEntityMufflerHatch.java | 11 +++-------- .../MetaTileEntityMultiFluidHatch.java | 7 +++---- .../multiblockpart/MetaTileEntityObjectHolder.java | 7 +++---- .../MetaTileEntityOpticalDataHatch.java | 7 +++---- .../MetaTileEntityPassthroughHatchFluid.java | 7 +++---- .../MetaTileEntityPassthroughHatchItem.java | 7 +++---- .../multiblockpart/MetaTileEntityReservoirHatch.java | 7 +++---- .../multiblockpart/MetaTileEntityRotorHolder.java | 7 +++---- .../appeng/MetaTileEntityMEInputBus.java | 7 +++---- .../appeng/MetaTileEntityMEInputHatch.java | 7 +++---- .../appeng/MetaTileEntityMEOutputBus.java | 11 +++-------- .../appeng/MetaTileEntityMEOutputHatch.java | 11 +++-------- .../hpca/MetaTileEntityHPCAComponent.java | 8 ++++---- .../multiblockpart/MetaTileEntitySteamHatch.java | 7 +++---- .../multiblockpart/MetaTileEntitySteamItemBus.java | 7 +++---- 31 files changed, 97 insertions(+), 138 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index cd8a6108bc7..0f5ad3e1bc6 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -2,6 +2,7 @@ import gregtech.api.capability.IDistillationTower; import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.pattern.BlockPattern; @@ -92,12 +93,12 @@ public void determineOrderedFluidOutputs() { } MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex); if (part.getPos().getY() == y) { - List hatchTanks = new ObjectArrayList<>(); + AbilityInstances hatchTanks = new AbilityInstances(MultiblockAbility.EXPORT_FLUIDS); // noinspection unchecked ((IMultiblockAbilityPart) part) - .registerAbilities(MultiblockAbility.EXPORT_FLUIDS, hatchTanks); - orderedHandlerList.add(new FluidTankList(false, hatchTanks)); - tankList.addAll(hatchTanks); + .registerAbilities(hatchTanks); + orderedHandlerList.add(new FluidTankList(false, hatchTanks.cast())); + tankList.addAll(hatchTanks.cast()); exportIndex++; } else if (part.getPos().getY() > y) { orderedHandlerList.add(FakeTank.INSTANCE); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 140e286acda..8e019d5524d 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -13,5 +13,5 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { return Collections.singletonList(getAbility()); } - void registerAbilities(@NotNull MultiblockAbility key, @NotNull List abilities); + void registerAbilities(@NotNull AbilityInstances abilityInstances); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index 45fa03841b1..593c55db8da 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -358,9 +358,9 @@ public void checkStructurePattern() { if (!checkAbilityPart(ability, ((MetaTileEntity) abilityPart).getPos())) continue; - AbilityInstances abilityInstancesList = abilities.computeIfAbsent(ability, + AbilityInstances instances = abilities.computeIfAbsent(ability, AbilityInstances::new); - abilityPart.registerAbilities(ability, abilityInstancesList); + abilityPart.registerAbilities(instances); } } } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java index e8ac72545a0..8dbd3e19fc2 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.java @@ -9,6 +9,7 @@ import gregtech.api.metatileentity.MTETrait; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.IPassthroughHatch; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -177,10 +178,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java index e32479f0466..bc194d85474 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityHull.java @@ -5,6 +5,7 @@ import gregtech.api.capability.impl.EnergyContainerHandler; import gregtech.api.metatileentity.MetaTileEntityHolder; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.IPassthroughHatch; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -110,10 +111,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java index b21fb2e4aff..0191eac49cc 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityPumpHatch.java @@ -11,6 +11,7 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.ICubeRenderer; @@ -104,10 +105,8 @@ public ICubeRenderer getBaseTexture() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(exportFluids.getTankAt(0)); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(exportFluids.getTankAt(0)); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java index 28db2c710d8..231a19fee37 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityTankValve.java @@ -4,6 +4,7 @@ import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -122,10 +123,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this.getImportFluids()); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this.getImportFluids()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java index 59cab3b3c2e..1159bbb558c 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityAutoMaintenanceHatch.java @@ -3,6 +3,7 @@ import gregtech.api.capability.IMaintenanceHatch; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.texture.Textures; @@ -105,10 +106,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java index 155cdef3e8f..61c7e343392 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityComputationHatch.java @@ -6,6 +6,7 @@ import gregtech.api.capability.IOpticalComputationProvider; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.util.GTLog; @@ -151,10 +152,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index 12ece6a08ca..ee036b768a2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -9,6 +9,7 @@ import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -213,10 +214,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index 27e09974239..473034a2ab1 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -8,6 +8,7 @@ import gregtech.api.capability.impl.EnergyContainerHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.util.GTUtility; @@ -117,10 +118,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(energyContainer); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(energyContainer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index b7c528aaf66..840869a3039 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -14,6 +14,7 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -252,12 +253,11 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities(@NotNull MultiblockAbility key, - @NotNull List abilities) { - if (key.equals(MultiblockAbility.EXPORT_FLUIDS)) { - abilities.add(this.fluidTank); - } else if (key.equals(MultiblockAbility.IMPORT_FLUIDS)) { - abilities.addAll(this.dualHandler.unwrap()); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + if (abilityInstances.isKey(MultiblockAbility.EXPORT_FLUIDS)) { + abilityInstances.add(this.fluidTank); + } else if (abilityInstances.isKey(MultiblockAbility.IMPORT_FLUIDS)) { + abilityInstances.addAll(this.dualHandler.unwrap()); } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java index d43f93bc0f9..2a78d2d4d89 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityItemBus.java @@ -7,6 +7,7 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -251,13 +252,11 @@ public void receiveCustomData(int dataId, PacketBuffer buf) { } @Override - public void registerAbilities( - @NotNull MultiblockAbility key, - @NotNull List abilities) { + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { if (this.hasGhostCircuitInventory() && this.actualImportItems != null) { - abilities.add(isExportHatch ? this.exportItems : this.actualImportItems); + abilityInstances.add(isExportHatch ? this.exportItems : this.actualImportItems); } else { - abilities.add(isExportHatch ? this.exportItems : this.importItems); + abilityInstances.add(isExportHatch ? this.exportItems : this.importItems); } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java index 03d8537fedc..b87055eca56 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityLaserHatch.java @@ -6,6 +6,7 @@ import gregtech.api.metatileentity.IDataInfoProvider; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.texture.Textures; @@ -71,10 +72,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this.buffer); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this.buffer); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index 31f16a4e3da..e8f8a8b40d5 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -7,6 +7,7 @@ import gregtech.api.metatileentity.IMachineHatchMultiblock; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -52,10 +53,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(machineHandler); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(machineHandler); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java index 670cd50ad81..1b9a9eb07d3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMaintenanceHatch.java @@ -13,10 +13,7 @@ import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMaintenance; -import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; -import gregtech.api.metatileentity.multiblock.MultiblockAbility; -import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; +import gregtech.api.metatileentity.multiblock.*; import gregtech.api.util.GTUtility; import gregtech.client.renderer.texture.Textures; import gregtech.client.utils.TooltipHelper; @@ -498,10 +495,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java index acd240ed5d1..8403088ffa7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMufflerHatch.java @@ -9,10 +9,7 @@ import gregtech.api.metatileentity.ITieredMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; -import gregtech.api.metatileentity.multiblock.MultiblockAbility; -import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; -import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; +import gregtech.api.metatileentity.multiblock.*; import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; import gregtech.client.particle.VanillaParticleEffects; @@ -153,10 +150,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index 7fa99239983..534be6a22f1 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -8,6 +8,7 @@ import gregtech.api.capability.impl.NotifiableFluidTank; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.mui.GTGuis; @@ -199,10 +200,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.addAll(fluidTankList.getFluidTanks()); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.addAll(fluidTankList.getFluidTanks()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java index 7fe40d12c32..324e16a3743 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java @@ -12,6 +12,7 @@ import gregtech.api.items.metaitem.stats.IItemBehaviour; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -84,10 +85,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java index 251613e4b2d..204dfd6c9c6 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityOpticalDataHatch.java @@ -6,6 +6,7 @@ import gregtech.api.capability.IOpticalDataAccessHatch; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -128,10 +129,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java index 2c9439ca2af..fd20cf63255 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchFluid.java @@ -9,6 +9,7 @@ import gregtech.api.gui.widgets.TankWidget; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.IPassthroughHatch; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -155,10 +156,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java index 79a4a416895..66fb6695881 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityPassthroughHatchItem.java @@ -8,6 +8,7 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.IPassthroughHatch; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -157,10 +158,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @NotNull diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index c8d989200ba..23af5369c0a 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -9,6 +9,7 @@ import gregtech.api.gui.widgets.*; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.texture.Textures; @@ -112,10 +113,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(fluidTank); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(fluidTank); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java index 33cb7807963..f531259f1b2 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityRotorHolder.java @@ -10,6 +10,7 @@ import gregtech.api.metatileentity.ITieredMetaTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.util.RelativeDirection; @@ -146,10 +147,8 @@ void setRotorSpinning(boolean spinning) { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java index c97cf65f551..23f1ab2899b 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputBus.java @@ -15,6 +15,7 @@ import gregtech.api.gui.widgets.SlotWidget; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -330,10 +331,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this.actualImportItems); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this.actualImportItems); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java index 2eb5c4cf95f..120b25e8827 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEInputHatch.java @@ -10,6 +10,7 @@ import gregtech.api.gui.widgets.ImageWidget; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.texture.Textures; @@ -270,10 +271,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.addAll(Arrays.asList(this.getAEFluidHandler().getInventory())); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.addAll(Arrays.asList(this.getAEFluidHandler().getInventory())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java index 0f48a189228..de44e64b339 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputBus.java @@ -8,10 +8,7 @@ import gregtech.api.gui.ModularUI; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; -import gregtech.api.metatileentity.multiblock.MultiblockAbility; -import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; -import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; +import gregtech.api.metatileentity.multiblock.*; import gregtech.client.renderer.texture.Textures; import gregtech.common.gui.widget.appeng.AEItemGridWidget; import gregtech.common.inventory.appeng.SerializableItemList; @@ -196,10 +193,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(new InaccessibleInfiniteSlot(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java index 5c3505c26ea..77ba57bf656 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEOutputHatch.java @@ -8,10 +8,7 @@ import gregtech.api.gui.ModularUI; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; -import gregtech.api.metatileentity.multiblock.MultiblockAbility; -import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; -import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; +import gregtech.api.metatileentity.multiblock.*; import gregtech.client.renderer.texture.Textures; import gregtech.common.gui.widget.appeng.AEFluidGridWidget; import gregtech.common.inventory.appeng.SerializableFluidList; @@ -198,10 +195,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(new InaccessibleInfiniteTank(this, this.internalBuffer, this.getController())); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index 027105c0e47..7f0bf1830ee 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -5,6 +5,8 @@ import gregtech.api.capability.IHPCAComponentHatch; import gregtech.api.capability.IHPCAComputationProvider; import gregtech.api.capability.IHPCACoolantProvider; +import gregtech.api.gui.ModularUI; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.unification.material.Materials; @@ -67,10 +69,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(this); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(this); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java index 45bf2e7703e..adf128a3dff 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamHatch.java @@ -13,6 +13,7 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -120,10 +121,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.addAll(this.importFluids.getFluidTanks()); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.addAll(this.importFluids.getFluidTanks()); } @Override diff --git a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java index 68cb9c126b0..633ca974bac 100644 --- a/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java +++ b/src/main/java/gregtech/common/metatileentities/steam/multiblockpart/MetaTileEntitySteamItemBus.java @@ -2,6 +2,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import gregtech.api.mui.GTGuiTheme; @@ -56,10 +57,8 @@ public MultiblockAbility getAbility() { } @Override - public void registerAbilities( - @NotNull MultiblockAbility multiblockAbility, - @NotNull List abilities) { - abilities.add(isExportHatch ? this.exportItems : this.importItems); + public void registerAbilities(@NotNull AbilityInstances abilityInstances) { + abilityInstances.add(isExportHatch ? this.exportItems : this.importItems); } // Override base texture to have a bus with 4 slots, but ULV textures From b5370c35442163d6692f33f068977f7a34fafb8c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:34:30 -0700 Subject: [PATCH 066/103] no need for dual handler here anymore --- .../MetaTileEntityFluidHatch.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 840869a3039..da37f4d9024 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -57,6 +57,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiablePart @@ -70,7 +72,6 @@ public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockNotifiable protected final HatchFluidTank fluidTank; protected boolean workingEnabled; private GhostCircuitItemStackHandler circuitInventory; - private DualHandler dualHandler; // export hatch-only fields protected boolean locked; @@ -85,7 +86,6 @@ public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boo if (this.hasGhostCircuitInventory()) { this.circuitInventory = new GhostCircuitItemStackHandler(this); this.circuitInventory.addNotifiableMetaTileEntity(this); - this.dualHandler = new DualHandler(this.circuitInventory, this.importFluids, isExportHatch); } } @@ -252,12 +252,20 @@ public MultiblockAbility getAbility() { return isExportHatch ? MultiblockAbility.EXPORT_FLUIDS : MultiblockAbility.IMPORT_FLUIDS; } + @Override + public @NotNull List> getAbilities() { + return isExportHatch ? + Collections.singletonList(MultiblockAbility.EXPORT_FLUIDS) : + Arrays.asList(MultiblockAbility.IMPORT_FLUIDS, MultiblockAbility.IMPORT_ITEMS); + } + @Override public void registerAbilities(@NotNull AbilityInstances abilityInstances) { - if (abilityInstances.isKey(MultiblockAbility.EXPORT_FLUIDS)) { + if (abilityInstances.isKey(MultiblockAbility.EXPORT_FLUIDS) || + abilityInstances.isKey(MultiblockAbility.IMPORT_FLUIDS)) { abilityInstances.add(this.fluidTank); - } else if (abilityInstances.isKey(MultiblockAbility.IMPORT_FLUIDS)) { - abilityInstances.addAll(this.dualHandler.unwrap()); + } else if (abilityInstances.isKey(MultiblockAbility.IMPORT_ITEMS)) { + abilityInstances.add(this.circuitInventory); } } From 694532c8c7aef507d7910f8b1a5c97ff74579f2c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:42:24 -0700 Subject: [PATCH 067/103] mark ability as nullable and add default --- .../metatileentity/multiblock/IMultiblockAbilityPart.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 8e019d5524d..8b501b6f634 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -1,16 +1,19 @@ package gregtech.api.metatileentity.multiblock; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; public interface IMultiblockAbilityPart extends IMultiblockPart { - MultiblockAbility getAbility(); + default @Nullable MultiblockAbility getAbility() { + return null; + } default @NotNull List> getAbilities() { - return Collections.singletonList(getAbility()); + return getAbility() == null ? Collections.emptyList() : Collections.singletonList(getAbility()); } void registerAbilities(@NotNull AbilityInstances abilityInstances); From 9e83d605aa8536812fd5805ad26654af23d4ed7f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 16:56:13 -0700 Subject: [PATCH 068/103] changes to recipe logic are no longer necessary spotless --- .../capability/impl/AbstractRecipeLogic.java | 43 +------------------ .../impl/MultiblockRecipeLogic.java | 35 +-------------- .../java/gregtech/api/recipes/RecipeMap.java | 2 +- .../MetaTileEntityFluidHatch.java | 1 - 4 files changed, 4 insertions(+), 77 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index c0f7c9f5dc0..455ae3afd47 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -35,7 +35,6 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -407,7 +406,7 @@ protected void trySearchNewRecipe() { protected boolean checkPreviousRecipe() { if (this.previousRecipe == null) return false; if (this.previousRecipe.getEUt() > this.getMaxVoltage()) return false; - return recipeMatch(this.previousRecipe, false); + return this.previousRecipe.matches(false, getInputInventory(), getInputTank()); } /** @@ -702,7 +701,7 @@ protected static boolean areItemStacksEqual(@NotNull ItemStack stackA, @NotNull if (checkOutputSpaceItems(recipe, getOutputInventory()) && checkOutputSpaceFluids(recipe, getOutputTank())) { this.isOutputsFull = false; - if (recipeMatch(recipe, true)) { + if (recipe.matches(true, importInventory, importFluids)) { this.metaTileEntity.addNotifiedInput(importInventory); return recipe; } @@ -742,44 +741,6 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti return true; } - protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { - return recipe.matches(shouldConsume, getInputInventory(), getInputTank()); - } - - protected IItemHandlerModifiable gatherItems(IItemHandler inputInventory, - IMultipleTankHandler inputFluids) { - List items = new ArrayList<>(); - - if (inputInventory instanceof ItemHandlerList list) { - items.addAll(list.getBackingHandlers()); - } else { - items.add(inputInventory); - } - - for (var tank : inputFluids.getFluidTanks()) { - if (tank.getDelegate() instanceof IItemHandler handler) - items.add(handler); - } - - return new ItemHandlerList(items); - } - - protected IMultipleTankHandler gatherFluids(IItemHandler inputInventory, - IMultipleTankHandler inputFluids) { - List fluids = new ArrayList<>(inputFluids.getFluidTanks()); - - if (inputInventory instanceof IMultipleTankHandler tankHandler) { - fluids.addAll(tankHandler.getFluidTanks()); - } else if (inputInventory instanceof ItemHandlerList handlerList) { - for (IItemHandler handler : handlerList.getBackingHandlers()) { - if (handler instanceof IMultipleTankHandler tankHandler) - fluids.addAll(tankHandler.getFluidTanks()); - } - } - - return new FluidTankList(inputFluids.allowSameFluidFill(), fluids); - } - /** * Overclock a recipe beyond a duration of 1 tick using parallelization. * diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index fa81ac0b5eb..ff95f0fbb0c 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -1,7 +1,6 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; -import gregtech.api.capability.IDistinctBusController; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; @@ -241,33 +240,6 @@ protected void trySearchNewRecipeDistinct() { } } - @Override - protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, - IMultipleTankHandler fluidInputs) { - RecipeMap map = getRecipeMap(); - if (map == null || !isRecipeMapValid(map)) { - return null; - } - - IItemHandlerModifiable items = gatherItems(inputs, fluidInputs); - IMultipleTankHandler fluids = gatherFluids(inputs, fluidInputs); - - return map.findRecipe(maxVoltage, items, fluids); - } - - @Override - protected boolean recipeMatch(Recipe recipe, boolean shouldConsume) { - IItemHandler input = getInputInventory(); - if (metaTileEntity instanceof IDistinctBusController distinct && distinct.isDistinct()) { - input = currentDistinctInputBus; - } - - IItemHandlerModifiable items = gatherItems(input, getInputTank()); - IMultipleTankHandler fluids = gatherFluids(input, getInputTank()); - - return recipe.matches(shouldConsume, items, fluids); - } - @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; @@ -281,12 +253,7 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - if (previousRecipe == null) return false; - - IItemHandlerModifiable items = gatherItems(previousBus, getInputTank()); - IMultipleTankHandler fluids = gatherFluids(previousBus, getInputTank()); - - return previousRecipe.matches(false, items, fluids); + return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank()); } protected boolean prepareRecipeDistinct(Recipe recipe) { diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index f463f34744e..a2c2ef7b1f4 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMap.java +++ b/src/main/java/gregtech/api/recipes/RecipeMap.java @@ -534,7 +534,7 @@ amount, getMaxFluidOutputs()), @Nullable public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { - return findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs)); + return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs)); } /** diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index da37f4d9024..b1a3399a973 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -1,6 +1,5 @@ package gregtech.common.metatileentities.multi.multiblockpart; -import gregtech.api.capability.DualHandler; import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IControllable; From 6376a610c8497c66a284e195326f50bc4b08d9e6 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:05:08 -0700 Subject: [PATCH 069/103] override more methods --- .../multiblock/AbilityInstances.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 7c66053e8af..1eaba5cb0f0 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -57,6 +57,23 @@ public boolean add(Object o) { return instances.add(o); } + @Override + public void add(int index, Object element) { + if (key.checkType(element)) + instances.add(index, element); + } + + @Override + public Object set(int index, Object element) { + if (!key.checkType(element)) return null; + return instances.set(index, element); + } + + @Override + public Object remove(int index) { + return instances.remove(index); + } + @Override public int size() { return instances.size(); From 0fb50cc3b585aa66d5935b1418015e6b8c59309c Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:21:44 -0700 Subject: [PATCH 070/103] simplify DualHandler and improve notifiability --- .../gregtech/api/capability/DualHandler.java | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 29db8f00d9c..0699a51ebb7 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -29,6 +29,8 @@ public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler @NotNull IMultipleTankHandler fluidDelegate; + private final List unwrapped; + List notifiableEntities = new ArrayList<>(); private final boolean isExport; @@ -38,14 +40,23 @@ public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; this.isExport = isExport; + int items = itemDelegate.getSlots(); + int fluids = fluidDelegate.getTanks(); + int max = Math.max(items, fluids); + + List list = new ArrayList<>(max); + for (int i = 0; i < max; i++) { + list.add(new DualEntry(this, + i < items ? i : -1, + i < fluids ? i : -1)); + } + this.unwrapped = list; } public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, @NotNull IFluidTank fluidTank, boolean isExport) { - this.itemDelegate = itemDelegate; - this.fluidDelegate = new FluidTankList(false, fluidTank); - this.isExport = isExport; + this(itemDelegate, new FluidTankList(false, fluidTank), isExport); } public IItemHandlerModifiable getItemDelegate() { @@ -146,24 +157,7 @@ public boolean allowSameFluidFill() { } public List unwrap() { - int items = itemDelegate.getSlots(); - int fluids = fluidDelegate.getTanks(); - int max = Math.max(items, fluids); - - List list = new ArrayList<>(max); - for (int i = 0; i < max; i++) { - int itemIndex = -1; - if (i < items) - itemIndex = i; - - int fluidIndex = -1; - if (i < fluids) - fluidIndex = i; - - list.add(new DualEntry(this, itemIndex, fluidIndex)); - } - - return list; + return this.unwrapped; } public void onContentsChanged() { @@ -185,7 +179,7 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiableEntities.remove(metaTileEntity); } - public static class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler { + public class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler, INotifiableHandler { private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); @@ -200,7 +194,7 @@ public DualEntry(DualHandler delegate, int itemIndex, int fluidIndex) { this.fluidIndex = fluidIndex; this.props = this.fluidIndex == -1 ? new IFluidTankProperties[0] : - this.delegate.getTankAt(this.fluidIndex).getTankProperties(); + getTank().getTankProperties(); } public DualHandler getDelegate() { @@ -210,25 +204,25 @@ public DualHandler getDelegate() { @Override public FluidStack getFluid() { if (fluidIndex == -1) return null; - return this.delegate.getTankAt(this.fluidIndex).getFluid(); + return getTank().getFluid(); } @Override public int getFluidAmount() { if (fluidIndex == -1) return 0; - return this.delegate.getTankAt(this.fluidIndex).getFluidAmount(); + return getTank().getFluidAmount(); } @Override public int getCapacity() { if (fluidIndex == -1) return 0; - return this.delegate.getTankAt(this.fluidIndex).getCapacity(); + return getTank().getCapacity(); } @Override public FluidTankInfo getInfo() { if (fluidIndex == -1) return NULL; - return this.delegate.getTankAt(this.fluidIndex).getInfo(); + return getTank().getInfo(); } @Override @@ -239,19 +233,29 @@ public IFluidTankProperties[] getTankProperties() { @Override public int fill(FluidStack resource, boolean doFill) { if (fluidIndex == -1) return 0; - return this.delegate.getTankAt(this.fluidIndex).fill(resource, doFill); + int filled = getTank().fill(resource, doFill); + if (doFill && filled > 0) onContentsChanged(); + return filled; } @Override public FluidStack drain(FluidStack resource, boolean doDrain) { if (fluidIndex == -1) return null; - return this.delegate.getTankAt(this.fluidIndex).drain(resource, doDrain); + var drained = getTank().drain(resource, doDrain); + if (doDrain && drained != null) onContentsChanged(); + return drained; } @Override public FluidStack drain(int maxDrain, boolean doDrain) { if (fluidIndex == -1) return null; - return this.delegate.getTankAt(this.fluidIndex).drain(maxDrain, doDrain); + var drained = getTank().drain(maxDrain, doDrain); + if (doDrain && drained != null) onContentsChanged(); + return drained; + } + + private MultiFluidTankEntry getTank() { + return this.delegate.getTankAt(this.fluidIndex); } @Override @@ -288,5 +292,15 @@ public void setStackInSlot(int slot, ItemStack stack) { if (itemIndex == -1) return; this.delegate.setStackInSlot(this.itemIndex, stack); } + + @Override + public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + DualHandler.this.addNotifiableMetaTileEntity(metaTileEntity); + } + + @Override + public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { + DualHandler.this.removeNotifiableMetaTileEntity(metaTileEntity); + } } } From 48c3ac96ab392e2d12ccdb9f32d49f8ca7a090cb Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:23:17 -0700 Subject: [PATCH 071/103] make entry static again --- .../java/gregtech/api/capability/DualHandler.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 0699a51ebb7..25e70f8d5c5 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -179,7 +179,7 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiableEntities.remove(metaTileEntity); } - public class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler, INotifiableHandler { + public static class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler, INotifiableHandler { private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); @@ -234,7 +234,8 @@ public IFluidTankProperties[] getTankProperties() { public int fill(FluidStack resource, boolean doFill) { if (fluidIndex == -1) return 0; int filled = getTank().fill(resource, doFill); - if (doFill && filled > 0) onContentsChanged(); + if (doFill && filled > 0) + delegate.onContentsChanged(); return filled; } @@ -242,7 +243,8 @@ public int fill(FluidStack resource, boolean doFill) { public FluidStack drain(FluidStack resource, boolean doDrain) { if (fluidIndex == -1) return null; var drained = getTank().drain(resource, doDrain); - if (doDrain && drained != null) onContentsChanged(); + if (doDrain && drained != null) + delegate.onContentsChanged(); return drained; } @@ -250,7 +252,8 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { public FluidStack drain(int maxDrain, boolean doDrain) { if (fluidIndex == -1) return null; var drained = getTank().drain(maxDrain, doDrain); - if (doDrain && drained != null) onContentsChanged(); + if (doDrain && drained != null) + delegate.onContentsChanged(); return drained; } @@ -295,12 +298,12 @@ public void setStackInSlot(int slot, ItemStack stack) { @Override public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - DualHandler.this.addNotifiableMetaTileEntity(metaTileEntity); + this.delegate.addNotifiableMetaTileEntity(metaTileEntity); } @Override public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - DualHandler.this.removeNotifiableMetaTileEntity(metaTileEntity); + this.delegate.removeNotifiableMetaTileEntity(metaTileEntity); } } } From ecab010db6c13226cda86305f5cf71570f4f4f40 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:04:36 -0700 Subject: [PATCH 072/103] add back simple checking of extra fluids from items only when distinct is enabled --- .../capability/impl/MultiblockRecipeLogic.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ff95f0fbb0c..f6c537c142c 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -17,6 +17,7 @@ import gregtech.common.ConfigHolder; import net.minecraft.util.Tuple; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -253,24 +254,26 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank()); + return previousRecipe != null && previousRecipe.matches(false, previousBus, checkExtraFluids(previousBus)); } protected boolean prepareRecipeDistinct(Recipe recipe) { recipe = Recipe.trimRecipeOutputs(recipe, getRecipeMap(), metaTileEntity.getItemOutputLimit(), metaTileEntity.getFluidOutputLimit()); + var extraFluids = checkExtraFluids(currentDistinctInputBus); + recipe = findParallelRecipe( recipe, currentDistinctInputBus, - getInputTank(), + extraFluids, getOutputInventory(), getOutputTank(), getMaxParallelVoltage(), getParallelLimit()); if (recipe != null) { - recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus); + recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, extraFluids); if (recipe != null) { setupRecipe(recipe); return true; @@ -280,6 +283,14 @@ protected boolean prepareRecipeDistinct(Recipe recipe) { return false; } + protected IMultipleTankHandler checkExtraFluids(IItemHandler items) { + List tanks = new ArrayList<>(getInputTank().getFluidTanks()); + if (items instanceof IMultipleTankHandler multipleTankHandler) { + tanks.addAll(multipleTankHandler.getFluidTanks()); + } + return new FluidTankList(getInputTank().allowSameFluidFill(), tanks); + } + @Override protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPre(ocParams, storage); From 8a28d6f2ca9c8d3f4e3364978346adad26ac517f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:44:32 -0700 Subject: [PATCH 073/103] fix dual handler a bit missed spot for checking fluids in mrl --- .../gregtech/api/capability/DualHandler.java | 19 +++++++++++-------- .../impl/MultiblockRecipeLogic.java | 3 +-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 25e70f8d5c5..10cc7dd80f3 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -160,17 +160,20 @@ public List unwrap() { return this.unwrapped; } - public void onContentsChanged() { + public void onContentsChanged(Object handler) { for (MetaTileEntity metaTileEntity : notifiableEntities) { - if (metaTileEntity != null && metaTileEntity.isValid()) { - addToNotifiedList(metaTileEntity, this, isExport); - } + addToNotifiedList(metaTileEntity, handler, isExport); } } + public void onContentsChanged() { + onContentsChanged(this); + } + @Override public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - if (metaTileEntity == null) return; + if (metaTileEntity == null || this.notifiableEntities.contains(metaTileEntity)) + return; this.notifiableEntities.add(metaTileEntity); } @@ -235,7 +238,7 @@ public int fill(FluidStack resource, boolean doFill) { if (fluidIndex == -1) return 0; int filled = getTank().fill(resource, doFill); if (doFill && filled > 0) - delegate.onContentsChanged(); + delegate.onContentsChanged(this); return filled; } @@ -244,7 +247,7 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { if (fluidIndex == -1) return null; var drained = getTank().drain(resource, doDrain); if (doDrain && drained != null) - delegate.onContentsChanged(); + delegate.onContentsChanged(this); return drained; } @@ -253,7 +256,7 @@ public FluidStack drain(int maxDrain, boolean doDrain) { if (fluidIndex == -1) return null; var drained = getTank().drain(maxDrain, doDrain); if (doDrain && drained != null) - delegate.onContentsChanged(); + delegate.onContentsChanged(this); return drained; } diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index f6c537c142c..13e3fe103d0 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -201,7 +201,6 @@ protected void trySearchNewRecipeDistinct() { long maxVoltage = getMaxVoltage(); Recipe currentRecipe; List importInventory = getInputBuses(); - IMultipleTankHandler importFluids = getInputTank(); // Our caching implementation // This guarantees that if we get a recipe cache hit, our efficiency is no different from other machines @@ -224,7 +223,7 @@ protected void trySearchNewRecipeDistinct() { continue; } // Look for a new recipe after a cache miss - currentRecipe = findRecipe(maxVoltage, bus, importFluids); + currentRecipe = findRecipe(maxVoltage, bus, checkExtraFluids(bus)); // Cache the current recipe, if one is found if (currentRecipe != null && checkRecipe(currentRecipe)) { this.previousRecipe = currentRecipe; From e75c48f3eea90fc82604b647bec1e33ed5a3aa33 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:16:34 -0700 Subject: [PATCH 074/103] improve add method --- .../metatileentity/multiblock/AbilityInstances.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 1eaba5cb0f0..a0a39fefb80 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -1,10 +1,13 @@ package gregtech.api.metatileentity.multiblock; +import gregtech.api.util.GTLog; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.AbstractList; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class AbilityInstances extends AbstractList { @@ -53,8 +56,14 @@ public boolean isKey(MultiblockAbility key) { @Override public boolean add(Object o) { - if (!key.checkType(o)) return false; - return instances.add(o); + if (o instanceof Collectioncollection) { + GTLog.logger.warn(new IllegalArgumentException( + "Passed in a collection of elements to \"add()\"! Please use \"addAll()\" instead.")); + return addAll(collection); + } + int s = size(); + add(s, o); + return s != size(); } @Override From 040a5a5bab83c72adb942e88b8f2ede7cd5707f3 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:19:56 -0700 Subject: [PATCH 075/103] update to `getAbilities()` --- .../impl/DistillationTowerLogicHandler.java | 2 +- .../multiblock/MultiblockControllerBase.java | 16 +++++++++++----- .../metatileentities/MetaTileEntities.java | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index 0f5ad3e1bc6..e4dff86749b 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -76,7 +76,7 @@ public void determineOrderedFluidOutputs() { // noinspection SimplifyStreamApiCallChains List fluidExportParts = tower.getMultiblockParts().stream() .filter(iMultiblockPart -> iMultiblockPart instanceof IMultiblockAbilityPartabilityPart && - abilityPart.getAbility() == MultiblockAbility.EXPORT_FLUIDS && + abilityPart.getAbilities().contains(MultiblockAbility.EXPORT_FLUIDS) && abilityPart instanceof MetaTileEntityMultiblockPart) .map(iMultiblockPart -> (MetaTileEntityMultiblockPart) iMultiblockPart) .collect(Collectors.toList()); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java index 593c55db8da..494ab651b54 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockControllerBase.java @@ -231,11 +231,17 @@ private static Supplier getCandidates(IBlockState... allowedStates) } public static TraceabilityPredicate abilities(MultiblockAbility... allowedAbilities) { - return tilePredicate((state, tile) -> tile instanceof IMultiblockAbilityPart && - ArrayUtils.contains(allowedAbilities, ((IMultiblockAbilityPart) tile).getAbility()), - getCandidates(Arrays.stream(allowedAbilities) - .flatMap(ability -> MultiblockAbility.REGISTRY.get(ability).stream()) - .toArray(MetaTileEntity[]::new))); + return tilePredicate((state, tile) -> { + if (tile instanceof IMultiblockAbilityPartabilityPart) { + for (var ability : abilityPart.getAbilities()) { + if (ArrayUtils.contains(allowedAbilities, ability)) + return true; + } + } + return false; + }, getCandidates(Arrays.stream(allowedAbilities) + .flatMap(ability -> MultiblockAbility.REGISTRY.get(ability).stream()) + .toArray(MetaTileEntity[]::new))); } public static TraceabilityPredicate states(IBlockState... allowedStates) { diff --git a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java index dbe94985456..52fb9a9baaa 100644 --- a/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java +++ b/src/main/java/gregtech/common/metatileentities/MetaTileEntities.java @@ -1279,7 +1279,8 @@ public static void registerMetaTileEntities( */ public static @NotNull T registerMetaTileEntity(int id, @NotNull T mte) { if (mte instanceof IMultiblockAbilityPartabilityPart) { - MultiblockAbility.registerMultiblockAbility(abilityPart.getAbility(), mte); + for (var ability : abilityPart.getAbilities()) + MultiblockAbility.registerMultiblockAbility(ability, mte); } if (Mods.JustEnoughItems.isModLoaded() && mte instanceof MultiblockControllerBase controller && From 7e04dffd781032b9baedcba3a65da528f308d68d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:24:29 -0700 Subject: [PATCH 076/103] fix warning --- .../api/metatileentity/multiblock/AbilityInstances.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index a0a39fefb80..54739680ab6 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -57,8 +57,8 @@ public boolean isKey(MultiblockAbility key) { @Override public boolean add(Object o) { if (o instanceof Collectioncollection) { - GTLog.logger.warn(new IllegalArgumentException( - "Passed in a collection of elements to \"add()\"! Please use \"addAll()\" instead.")); + GTLog.logger.warn("Passed in a collection of elements to \"add()\"! Please use \"addAll()\" instead.", + new IllegalArgumentException()); return addAll(collection); } int s = size(); From bce0914d1907b62a080a22f9dbc35be385970069 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:10:29 -0700 Subject: [PATCH 077/103] check object type and collect if iterable remove warn --- .../multiblock/AbilityInstances.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 54739680ab6..a0c32632926 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -1,13 +1,10 @@ package gregtech.api.metatileentity.multiblock; -import gregtech.api.util.GTLog; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.AbstractList; import java.util.ArrayList; -import java.util.Collection; import java.util.List; public class AbilityInstances extends AbstractList { @@ -20,8 +17,13 @@ public boolean isKey(MultiblockAbility key) { } @Override - public boolean add(Object o) { - return false; + public void add(int index, Object element) { + // do nothing + } + + @Override + public Object set(int index, Object element) { + return null; } @Override @@ -29,6 +31,7 @@ public Object get(int index) { return null; } }; + private final MultiblockAbility key; private final List instances = new ArrayList<>(); @@ -54,14 +57,21 @@ public boolean isKey(MultiblockAbility key) { return (List) this; } + /** + * @param o element to try and add to this list of instances + * @return + */ @Override public boolean add(Object o) { - if (o instanceof Collectioncollection) { - GTLog.logger.warn("Passed in a collection of elements to \"add()\"! Please use \"addAll()\" instead.", - new IllegalArgumentException()); - return addAll(collection); - } int s = size(); + // if what's added isn't what the key expects, + // and it's an iterable, try to add all of its elements instead + if (!this.key.checkType(o) && o instanceof Iterableiterable) { + for (var e : iterable) + add(size(), e); + return s != size(); + } + // otherwise add as normal add(s, o); return s != size(); } From 4cd8e62233e997bb954d1227e061556ca76cff88 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:18:42 -0700 Subject: [PATCH 078/103] unneeded javadoc --- .../api/metatileentity/multiblock/AbilityInstances.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index a0c32632926..3173a23091f 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -57,10 +57,6 @@ public boolean isKey(MultiblockAbility key) { return (List) this; } - /** - * @param o element to try and add to this list of instances - * @return - */ @Override public boolean add(Object o) { int s = size(); From 4b62204d983de77d22ef96426142f971e64001de Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:31:00 -0700 Subject: [PATCH 079/103] throw exception on adding or setting invalid element --- .../metatileentity/multiblock/AbilityInstances.java | 10 +++++++--- .../metatileentity/multiblock/MultiblockAbility.java | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 3173a23091f..b3944be6463 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -74,13 +74,17 @@ public boolean add(Object o) { @Override public void add(int index, Object element) { - if (key.checkType(element)) - instances.add(index, element); + if (!key.checkType(element)) + throw new IllegalArgumentException( + String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); + instances.add(index, element); } @Override public Object set(int index, Object element) { - if (!key.checkType(element)) return null; + if (!key.checkType(element)) + throw new IllegalArgumentException( + String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); return instances.set(index, element); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 745991654a5..1a9eac30790 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -124,6 +124,10 @@ public boolean checkType(Object o) { return clazz.isAssignableFrom(o.getClass()); } + public String getType() { + return this.clazz.toString(); + } + public @Nullable T checkAndCast(Object o) { if (checkType(o)) return clazz.cast(o); From b75f2e80ecf908b4d4650f751987bbd94ccc4722 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:40:21 -0700 Subject: [PATCH 080/103] better javadocs --- .../multiblock/AbilityInstances.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index b3944be6463..876aa359a39 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -7,6 +7,13 @@ import java.util.ArrayList; import java.util.List; +/** + * Stores a list of {@link MultiblockAbility} instances. + *
+ *
+ * Make sure to use {@link AbilityInstances#isKey(MultiblockAbility)} to check what kind of + * instances to add to this list. + */ public class AbilityInstances extends AbstractList { public static final AbilityInstances EMPTY = new AbilityInstances(null) { @@ -57,6 +64,14 @@ public boolean isKey(MultiblockAbility key) { return (List) this; } + /** + * Adds an instance of a MultiblockAbility to this list. If the object + * passed in is a list of instances that match the key, they will all be added. + * if the object is not what the key expects, an exception will be thrown. + * + * @param o element whose class matches the type from the key + * @return true if the list was modified + */ @Override public boolean add(Object o) { int s = size(); @@ -76,15 +91,24 @@ public boolean add(Object o) { public void add(int index, Object element) { if (!key.checkType(element)) throw new IllegalArgumentException( - String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); + String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), + this.key.getType())); instances.add(index, element); } + /** + * Replaces the element at the index. Will throw and exception if the element is not what the key expects. + * + * @param index index of the element to replace + * @param element element to be stored at the specified position + * @return the element previously stored at the index + */ @Override public Object set(int index, Object element) { if (!key.checkType(element)) throw new IllegalArgumentException( - String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); + String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), + this.key.getType())); return instances.set(index, element); } From 5c7bfa4cb028f872b900fdac9a7fd2e51e48c505 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 14 Aug 2024 09:01:56 -0700 Subject: [PATCH 081/103] remove unnecessary override some javadocs --- .../multiblock/IMultiblockAbilityPart.java | 11 +++++++++++ .../multiblockpart/MetaTileEntityFluidHatch.java | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 8b501b6f634..8a9b23dbbe7 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -8,10 +8,21 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { + /** + * Returns only one ability for this multiblock part. + * If you need more than one, override {@link #getAbilities()} instead. + * + * @return The MultiblockAbility this part has + */ default @Nullable MultiblockAbility getAbility() { return null; } + /** + * Returns a list of abilities that this multiblock part may have. + * + * @return a list of MultiblockAbilities + */ default @NotNull List> getAbilities() { return getAbility() == null ? Collections.emptyList() : Collections.singletonList(getAbility()); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index b1a3399a973..c9071d413cf 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -246,11 +246,6 @@ protected IItemHandlerModifiable createExportItemHandler() { return new GTItemStackHandler(this, 1); } - @Override - public MultiblockAbility getAbility() { - return isExportHatch ? MultiblockAbility.EXPORT_FLUIDS : MultiblockAbility.IMPORT_FLUIDS; - } - @Override public @NotNull List> getAbilities() { return isExportHatch ? From 8b3d528342e962ab544831f3516f4c8eb5dd0d88 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 15 Aug 2024 22:08:43 -0700 Subject: [PATCH 082/103] always assume a size of one --- .../java/gregtech/api/capability/INotifiableHandler.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/capability/INotifiableHandler.java b/src/main/java/gregtech/api/capability/INotifiableHandler.java index c9362912594..9a8c915e9eb 100644 --- a/src/main/java/gregtech/api/capability/INotifiableHandler.java +++ b/src/main/java/gregtech/api/capability/INotifiableHandler.java @@ -2,7 +2,6 @@ import gregtech.api.metatileentity.MetaTileEntity; -import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandler; /** @@ -35,12 +34,10 @@ default void addToNotifiedList(MetaTileEntity metaTileEntity, T handler, boo void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity); default int size() { - if (this instanceof IFluidTank) - return 1; - else if (this instanceof IItemHandler handler) + if (this instanceof IItemHandler handler) return handler.getSlots(); else if (this instanceof IMultipleTankHandler tankHandler) return tankHandler.getTanks(); - return 0; + return 1; } } From ccff22d3b73b3ecee9bb72f7446b79d5f834f3b7 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 15 Aug 2024 22:17:06 -0700 Subject: [PATCH 083/103] fix potential npe with EMPTY --- .../metatileentity/multiblock/AbilityInstances.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 876aa359a39..8330410e13d 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -23,6 +23,11 @@ public boolean isKey(MultiblockAbility key) { return false; } + @Override + protected boolean canAdd(Object o) { + return false; + } + @Override public void add(int index, Object element) { // do nothing @@ -77,7 +82,7 @@ public boolean add(Object o) { int s = size(); // if what's added isn't what the key expects, // and it's an iterable, try to add all of its elements instead - if (!this.key.checkType(o) && o instanceof Iterableiterable) { + if (!canAdd(o) && o instanceof Iterableiterable) { for (var e : iterable) add(size(), e); return s != size(); @@ -87,6 +92,10 @@ public boolean add(Object o) { return s != size(); } + protected boolean canAdd(Object o) { + return this.key.checkType(o); + } + @Override public void add(int index, Object element) { if (!key.checkType(element)) From 66183ffd1ad46c0c6da09d128e3bad22be3a2f95 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:29:03 -0700 Subject: [PATCH 084/103] always check for extra fluids, but only for multis --- .../impl/MultiblockRecipeLogic.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 13e3fe103d0..d22f5f90666 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -240,6 +240,12 @@ protected void trySearchNewRecipeDistinct() { } } + @Override + protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, + IMultipleTankHandler fluidInputs) { + return super.findRecipe(maxVoltage, inputs, checkExtraFluids(inputs)); + } + @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; @@ -284,9 +290,20 @@ protected boolean prepareRecipeDistinct(Recipe recipe) { protected IMultipleTankHandler checkExtraFluids(IItemHandler items) { List tanks = new ArrayList<>(getInputTank().getFluidTanks()); - if (items instanceof IMultipleTankHandler multipleTankHandler) { + if (items instanceof ItemHandlerList list) { + for (var handler : list.getBackingHandlers()) { + if (handler instanceof IFluidTank tank) { + tanks.add(tank); + } else if (handler instanceof IMultipleTankHandler multipleTankHandler) { + tanks.addAll(multipleTankHandler.getFluidTanks()); + } + } + } else if (items instanceof IFluidTank tank) { + tanks.add(tank); + } else if (items instanceof IMultipleTankHandler multipleTankHandler) { tanks.addAll(multipleTankHandler.getFluidTanks()); } + return new FluidTankList(getInputTank().allowSameFluidFill(), tanks); } From ff47a7ad50e33cf4cccb8f0f6d47627dcf4219e6 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 16 Aug 2024 00:51:42 -0700 Subject: [PATCH 085/103] do not allow duplicate instances --- .../api/metatileentity/multiblock/AbilityInstances.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 8330410e13d..56f2333ecd7 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -102,7 +102,8 @@ public void add(int index, Object element) { throw new IllegalArgumentException( String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); - instances.add(index, element); + if (!instances.contains(element)) + instances.add(index, element); } /** @@ -118,6 +119,9 @@ public Object set(int index, Object element) { throw new IllegalArgumentException( String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), this.key.getType())); + if (instances.contains(element)) + return null; + return instances.set(index, element); } From b3387eb3c33469bd4fc6e4ac88cbe9c336a7da33 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 16 Aug 2024 00:52:16 -0700 Subject: [PATCH 086/103] check fluids in controller init instead of recipe logic --- .../impl/MultiblockRecipeLogic.java | 35 +++---------------- .../RecipeMapMultiblockController.java | 20 ++++++++--- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index d22f5f90666..ea1c72b56f9 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -223,7 +223,7 @@ protected void trySearchNewRecipeDistinct() { continue; } // Look for a new recipe after a cache miss - currentRecipe = findRecipe(maxVoltage, bus, checkExtraFluids(bus)); + currentRecipe = findRecipe(maxVoltage, bus, getInputTank()); // Cache the current recipe, if one is found if (currentRecipe != null && checkRecipe(currentRecipe)) { this.previousRecipe = currentRecipe; @@ -240,12 +240,6 @@ protected void trySearchNewRecipeDistinct() { } } - @Override - protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, - IMultipleTankHandler fluidInputs) { - return super.findRecipe(maxVoltage, inputs, checkExtraFluids(inputs)); - } - @Override public void invalidateInputs() { MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity; @@ -259,26 +253,24 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - return previousRecipe != null && previousRecipe.matches(false, previousBus, checkExtraFluids(previousBus)); + return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank()); } protected boolean prepareRecipeDistinct(Recipe recipe) { recipe = Recipe.trimRecipeOutputs(recipe, getRecipeMap(), metaTileEntity.getItemOutputLimit(), metaTileEntity.getFluidOutputLimit()); - var extraFluids = checkExtraFluids(currentDistinctInputBus); - recipe = findParallelRecipe( recipe, currentDistinctInputBus, - extraFluids, + getInputTank(), getOutputInventory(), getOutputTank(), getMaxParallelVoltage(), getParallelLimit()); if (recipe != null) { - recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, extraFluids); + recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, getInputTank()); if (recipe != null) { setupRecipe(recipe); return true; @@ -288,25 +280,6 @@ protected boolean prepareRecipeDistinct(Recipe recipe) { return false; } - protected IMultipleTankHandler checkExtraFluids(IItemHandler items) { - List tanks = new ArrayList<>(getInputTank().getFluidTanks()); - if (items instanceof ItemHandlerList list) { - for (var handler : list.getBackingHandlers()) { - if (handler instanceof IFluidTank tank) { - tanks.add(tank); - } else if (handler instanceof IMultipleTankHandler multipleTankHandler) { - tanks.addAll(multipleTankHandler.getFluidTanks()); - } - } - } else if (items instanceof IFluidTank tank) { - tanks.add(tank); - } else if (items instanceof IMultipleTankHandler multipleTankHandler) { - tanks.addAll(multipleTankHandler.getFluidTanks()); - } - - return new FluidTankList(getInputTank().allowSameFluidFill(), tanks); - } - @Override protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPre(ocParams, storage); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index c8f477d6d12..cae0d0661d0 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -26,6 +26,7 @@ import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandlerModifiable; import codechicken.lib.render.CCRenderState; @@ -119,11 +120,9 @@ public boolean isActive() { protected void initializeAbilities() { this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS)); - this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), - getAbilities(MultiblockAbility.IMPORT_FLUIDS)); + this.inputFluidInventory = createFluidList(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_FLUIDS); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); - this.outputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), - getAbilities(MultiblockAbility.EXPORT_FLUIDS)); + this.outputFluidInventory = createFluidList(MultiblockAbility.EXPORT_ITEMS, MultiblockAbility.EXPORT_FLUIDS); List inputEnergy = new ArrayList<>(getAbilities(MultiblockAbility.INPUT_ENERGY)); inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY)); @@ -139,6 +138,19 @@ private void resetTileAbilities() { this.energyContainer = new EnergyContainerList(Lists.newArrayList()); } + protected IMultipleTankHandler createFluidList(MultiblockAbility items, MultiblockAbility fluids) { + List tanks = getAbilitiesModifiable(fluids); + for (var handler : getAbilities(items)) { + if (handler instanceof IFluidTank tank) { + tanks.add(tank); + } else if (handler instanceof IMultipleTankHandler multipleTankHandler) { + tanks.addAll(multipleTankHandler.getFluidTanks()); + } + } + + return new FluidTankList(allowSameFluidFillForOutputs(), tanks); + } + protected boolean allowSameFluidFillForOutputs() { return true; } From 9b0295f2a600a936f650e5d895098d1f703a8588 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 16 Aug 2024 01:52:54 -0700 Subject: [PATCH 087/103] fix fluid voiding? spotless --- .../gregtech/api/capability/impl/MultiblockRecipeLogic.java | 1 - .../multiblock/RecipeMapMultiblockController.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ea1c72b56f9..30815a37276 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -17,7 +17,6 @@ import gregtech.common.ConfigHolder; import net.minecraft.util.Tuple; -import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index cae0d0661d0..83c4316eab3 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -138,8 +138,9 @@ private void resetTileAbilities() { this.energyContainer = new EnergyContainerList(Lists.newArrayList()); } - protected IMultipleTankHandler createFluidList(MultiblockAbility items, MultiblockAbility fluids) { - List tanks = getAbilitiesModifiable(fluids); + protected IMultipleTankHandler createFluidList(MultiblockAbility items, + MultiblockAbility fluids) { + List tanks = new ArrayList<>(getAbilities(fluids)); for (var handler : getAbilities(items)) { if (handler instanceof IFluidTank tank) { tanks.add(tank); From 92caafea0e79a6e5725667cb402252d35c525b04 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:13:17 -0700 Subject: [PATCH 088/103] fix tank list creation --- .../multiblock/RecipeMapMultiblockController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index 83c4316eab3..bbf7504acb5 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -140,7 +140,8 @@ private void resetTileAbilities() { protected IMultipleTankHandler createFluidList(MultiblockAbility items, MultiblockAbility fluids) { - List tanks = new ArrayList<>(getAbilities(fluids)); + var tanks = new AbilityInstances(fluids); + tanks.addAll(getAbilities(fluids)); for (var handler : getAbilities(items)) { if (handler instanceof IFluidTank tank) { tanks.add(tank); @@ -149,7 +150,7 @@ protected IMultipleTankHandler createFluidList(MultiblockAbility Date: Sat, 17 Aug 2024 13:29:10 -0700 Subject: [PATCH 089/103] casually rework IMultipleTankHandler to use an extendable interface instead of sealed class casually rework DualEntry to not be an item handler --- .../gregtech/api/capability/DualHandler.java | 117 +++--------- .../api/capability/IMultipleTankHandler.java | 167 ++++-------------- .../api/capability/impl/FluidTankList.java | 148 ++++++++++++++-- .../java/gregtech/api/util/GTUtility.java | 2 +- .../api/util/OverlayedFluidHandler.java | 5 +- ...etaTileEntityMultiblockNotifiablePart.java | 2 +- .../capability/impl/FluidTankListTest.java | 3 +- 7 files changed, 200 insertions(+), 244 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 10cc7dd80f3..ceab3674089 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -6,9 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.items.IItemHandlerModifiable; @@ -29,7 +27,7 @@ public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler @NotNull IMultipleTankHandler fluidDelegate; - private final List unwrapped; + private final List unwrapped; List notifiableEntities = new ArrayList<>(); private final boolean isExport; @@ -40,15 +38,10 @@ public DualHandler(@NotNull IItemHandlerModifiable itemDelegate, this.itemDelegate = itemDelegate; this.fluidDelegate = fluidDelegate; this.isExport = isExport; - int items = itemDelegate.getSlots(); - int fluids = fluidDelegate.getTanks(); - int max = Math.max(items, fluids); - - List list = new ArrayList<>(max); - for (int i = 0; i < max; i++) { - list.add(new DualEntry(this, - i < items ? i : -1, - i < fluids ? i : -1)); + + List list = new ArrayList<>(); + for (var tank : this.fluidDelegate) { + list.add(new DualEntry(this, tank)); } this.unwrapped = list; } @@ -137,8 +130,8 @@ public FluidStack drain(int maxDrain, boolean doDrain) { } @Override - public @NotNull List getFluidTanks() { - return this.fluidDelegate.getFluidTanks(); + public @NotNull List getFluidTanks() { + return this.unwrapped; } @Override @@ -147,8 +140,8 @@ public int getTanks() { } @Override - public @NotNull MultiFluidTankEntry getTankAt(int index) { - return this.fluidDelegate.getTankAt(index); + public @NotNull ITankEntry getTankAt(int index) { + return this.unwrapped.get(index); } @Override @@ -156,10 +149,6 @@ public boolean allowSameFluidFill() { return this.fluidDelegate.allowSameFluidFill(); } - public List unwrap() { - return this.unwrapped; - } - public void onContentsChanged(Object handler) { for (MetaTileEntity metaTileEntity : notifiableEntities) { addToNotifiedList(metaTileEntity, handler, isExport); @@ -182,60 +171,35 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiableEntities.remove(metaTileEntity); } - public static class DualEntry implements IItemHandlerModifiable, IFluidTank, IFluidHandler, INotifiableHandler { - - private static final FluidTankInfo NULL = new FluidTankInfo(null, 0); + public static class DualEntry implements ITankEntry, INotifiableHandler { private final DualHandler delegate; - private final int itemIndex; - private final int fluidIndex; - private final IFluidTankProperties[] props; - - public DualEntry(DualHandler delegate, int itemIndex, int fluidIndex) { - this.delegate = delegate; - this.itemIndex = itemIndex; - this.fluidIndex = fluidIndex; - this.props = this.fluidIndex == -1 ? - new IFluidTankProperties[0] : - getTank().getTankProperties(); - } - public DualHandler getDelegate() { - return this.delegate; - } - - @Override - public FluidStack getFluid() { - if (fluidIndex == -1) return null; - return getTank().getFluid(); - } + @NotNull + private final ITankEntry tank; - @Override - public int getFluidAmount() { - if (fluidIndex == -1) return 0; - return getTank().getFluidAmount(); + public DualEntry(DualHandler delegate, ITankEntry tank) { + this.delegate = delegate; + this.tank = tank; } @Override - public int getCapacity() { - if (fluidIndex == -1) return 0; - return getTank().getCapacity(); + public @NotNull IMultipleTankHandler getParent() { + return this.delegate; } @Override - public FluidTankInfo getInfo() { - if (fluidIndex == -1) return NULL; - return getTank().getInfo(); + public @NotNull IFluidTank getDelegate() { + return this.tank; } @Override public IFluidTankProperties[] getTankProperties() { - return this.props; + return this.getTank().getTankProperties(); } @Override public int fill(FluidStack resource, boolean doFill) { - if (fluidIndex == -1) return 0; int filled = getTank().fill(resource, doFill); if (doFill && filled > 0) delegate.onContentsChanged(this); @@ -244,7 +208,6 @@ public int fill(FluidStack resource, boolean doFill) { @Override public FluidStack drain(FluidStack resource, boolean doDrain) { - if (fluidIndex == -1) return null; var drained = getTank().drain(resource, doDrain); if (doDrain && drained != null) delegate.onContentsChanged(this); @@ -253,50 +216,14 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { @Override public FluidStack drain(int maxDrain, boolean doDrain) { - if (fluidIndex == -1) return null; var drained = getTank().drain(maxDrain, doDrain); if (doDrain && drained != null) delegate.onContentsChanged(this); return drained; } - private MultiFluidTankEntry getTank() { - return this.delegate.getTankAt(this.fluidIndex); - } - - @Override - public int getSlots() { - return itemIndex == -1 ? 0 : 1; - } - - @Override - public ItemStack getStackInSlot(int slot) { - if (itemIndex == -1) return ItemStack.EMPTY; - return this.delegate.getStackInSlot(this.itemIndex); - } - - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (itemIndex == -1) return stack; - return this.delegate.insertItem(this.itemIndex, stack, simulate); - } - - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (itemIndex == -1) return ItemStack.EMPTY; - return this.delegate.extractItem(this.itemIndex, amount, simulate); - } - - @Override - public int getSlotLimit(int slot) { - if (itemIndex == -1) return 0; - return this.delegate.getSlotLimit(this.itemIndex); - } - - @Override - public void setStackInSlot(int slot, ItemStack stack) { - if (itemIndex == -1) return; - this.delegate.setStackInSlot(this.itemIndex, stack); + private @NotNull ITankEntry getTank() { + return this.tank; } @Override diff --git a/src/main/java/gregtech/api/capability/IMultipleTankHandler.java b/src/main/java/gregtech/api/capability/IMultipleTankHandler.java index b9e89c71d30..4a36b4dcafe 100644 --- a/src/main/java/gregtech/api/capability/IMultipleTankHandler.java +++ b/src/main/java/gregtech/api/capability/IMultipleTankHandler.java @@ -1,5 +1,6 @@ package gregtech.api.capability; +import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.fluids.FluidStack; @@ -7,7 +8,6 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.IFluidTankProperties; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,12 +22,12 @@ * * @see gregtech.api.capability.impl.FluidTankList FluidTankList */ -public interface IMultipleTankHandler extends IFluidHandler, Iterable { +public interface IMultipleTankHandler extends IFluidHandler, Iterable { /** * Comparator for entries that can be used in insertion logic */ - Comparator ENTRY_COMPARATOR = (o1, o2) -> { + Comparator ENTRY_COMPARATOR = (o1, o2) -> { // #1: non-empty tank first boolean empty1 = o1.getFluidAmount() <= 0; boolean empty2 = o2.getFluidAmount() <= 0; @@ -46,7 +46,7 @@ public interface IMultipleTankHandler extends IFluidHandler, Iterable getFluidTanks(); + List getFluidTanks(); /** * @return Number of tanks in this tank handler @@ -54,7 +54,7 @@ public interface IMultipleTankHandler extends IFluidHandler, Iterable fluidTanks = getFluidTanks(); + List fluidTanks = getFluidTanks(); for (int i = 0; i < fluidTanks.size(); i++) { FluidStack tankStack = fluidTanks.get(i).getFluid(); if (fluidStack == tankStack || tankStack != null && tankStack.isFluidEqual(fluidStack)) { @@ -81,7 +81,7 @@ default int getIndexOfFluid(@Nullable FluidStack fluidStack) { } @Override - default Iterator iterator() { + default Iterator iterator() { return getFluidTanks().iterator(); } @@ -89,160 +89,65 @@ default Iterator iterator() { * Entry of multi fluid tanks. Retains reference to original {@link IMultipleTankHandler} for accessing * information such as {@link IMultipleTankHandler#allowSameFluidFill()}. */ - final class MultiFluidTankEntry implements IFluidTank, IFluidHandler, IFilteredFluidContainer { - - private final IMultipleTankHandler tank; - private final IFluidTank delegate; - - public MultiFluidTankEntry(@NotNull IMultipleTankHandler tank, @NotNull IFluidTank delegate) { - this.tank = tank; - this.delegate = delegate; - } + interface ITankEntry extends IFluidTank, IFluidHandler, IFilteredFluidContainer, INBTSerializable { @NotNull - public IMultipleTankHandler getTank() { - return tank; - } + IMultipleTankHandler getParent(); @NotNull - public IFluidTank getDelegate() { - return delegate; - } + IFluidTank getDelegate(); - public boolean allowSameFluidFill() { - return tank.allowSameFluidFill(); + default boolean allowSameFluidFill() { + return getParent().allowSameFluidFill(); } - @Nullable - @Override - public IFilter getFilter() { - return this.delegate instanceof IFilteredFluidContainer filtered ? filtered.getFilter() : null; + default IFilter getFilter() { + return getDelegate() instanceof IFilteredFluidContainer filtered ? filtered.getFilter() : null; } - @NotNull - public IFluidTankProperties[] getTankProperties() { - return delegate instanceof IFluidHandler fluidHandler ? - fluidHandler.getTankProperties() : - new IFluidTankProperties[] { new FallbackTankProperty() }; - } - - public NBTTagCompound trySerialize() { - if (delegate instanceof FluidTank fluidTank) { + @Override + default NBTTagCompound serializeNBT() { + if (getDelegate() instanceof FluidTank fluidTank) { return fluidTank.writeToNBT(new NBTTagCompound()); - } else if (delegate instanceof INBTSerializable serializable) { - try { - return (NBTTagCompound) serializable.serializeNBT(); - } catch (ClassCastException ignored) {} + } else if (getDelegate() instanceof INBTSerializableserializable) { + if (serializable.serializeNBT() instanceof NBTTagCompound compound) { + return compound; + } } return new NBTTagCompound(); } - @SuppressWarnings({ "unchecked" }) - public void tryDeserialize(NBTTagCompound tag) { - if (delegate instanceof FluidTank fluidTank) { - fluidTank.readFromNBT(tag); - } else if (delegate instanceof INBTSerializable serializable) { + @Override + @SuppressWarnings("unchecked") + default void deserializeNBT(NBTTagCompound nbt) { + if (getDelegate() instanceof FluidTank fluidTank) { + fluidTank.readFromNBT(nbt); + } else if (getDelegate() instanceof INBTSerializableserializable) { try { - serializable.deserializeNBT(tag); + ((INBTSerializable) serializable).deserializeNBT(nbt); } catch (ClassCastException ignored) {} } } @Nullable @Override - public FluidStack getFluid() { - return delegate.getFluid(); - } - - @Override - public int getFluidAmount() { - return delegate.getFluidAmount(); - } - - @Override - public int getCapacity() { - return delegate.getCapacity(); - } - - @Override - public FluidTankInfo getInfo() { - return delegate.getInfo(); - } - - @Override - public int fill(FluidStack resource, boolean doFill) { - return delegate.fill(resource, doFill); - } - - @Nullable - @Override - public FluidStack drain(FluidStack resource, boolean doDrain) { - if (resource == null || resource.amount <= 0) { - return null; - } - if (delegate instanceof IFluidHandler fluidHandler) { - return fluidHandler.drain(resource, doDrain); - } - // just imitate the logic - FluidStack fluid = delegate.getFluid(); - return fluid != null && fluid.isFluidEqual(resource) ? drain(resource.amount, doDrain) : null; - } - - @Nullable - @Override - public FluidStack drain(int maxDrain, boolean doDrain) { - return delegate.drain(maxDrain, doDrain); + default FluidStack getFluid() { + return getDelegate().getFluid(); } @Override - public int hashCode() { - return delegate.hashCode(); + default int getFluidAmount() { + return getDelegate().getFluidAmount(); } @Override - @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") - public boolean equals(Object obj) { - return this == obj || delegate.equals(obj); + default int getCapacity() { + return getDelegate().getCapacity(); } @Override - public String toString() { - return delegate.toString(); - } - - private final class FallbackTankProperty implements IFluidTankProperties { - - @Nullable - @Override - public FluidStack getContents() { - return delegate.getFluid(); - } - - @Override - public int getCapacity() { - return delegate.getCapacity(); - } - - @Override - public boolean canFill() { - return true; - } - - @Override - public boolean canDrain() { - return true; - } - - @Override - public boolean canFillFluidType(FluidStack fluidStack) { - IFilter filter = getFilter(); - return filter == null || filter.test(fluidStack); - } - - @Override - public boolean canDrainFluidType(FluidStack fluidStack) { - return true; - } + default FluidTankInfo getInfo() { + return getDelegate().getInfo(); } } } diff --git a/src/main/java/gregtech/api/capability/impl/FluidTankList.java b/src/main/java/gregtech/api/capability/impl/FluidTankList.java index 29594258fb4..0ac625f934c 100644 --- a/src/main/java/gregtech/api/capability/impl/FluidTankList.java +++ b/src/main/java/gregtech/api/capability/impl/FluidTankList.java @@ -1,5 +1,7 @@ package gregtech.api.capability.impl; +import gregtech.api.capability.IFilter; +import gregtech.api.capability.IFilteredFluidContainer; import gregtech.api.capability.IMultipleTankHandler; import net.minecraft.nbt.NBTTagCompound; @@ -8,6 +10,7 @@ import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; +import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; import org.jetbrains.annotations.NotNull; @@ -20,7 +23,7 @@ public class FluidTankList implements IMultipleTankHandler, INBTSerializable { - private final MultiFluidTankEntry[] fluidTanks; + private final ITankEntry[] fluidTanks; private final boolean allowSameFluidFill; public FluidTankList(boolean allowSameFluidFill, IFluidTank... fluidTanks) { @@ -39,9 +42,9 @@ public FluidTankList(boolean allowSameFluidFill, @NotNull List list = new ArrayList<>(parent.getFluidTanks()); + ArrayList list = new ArrayList<>(parent.getFluidTanks()); for (IFluidTank tank : additionalTanks) list.add(wrapIntoEntry(tank)); - this.fluidTanks = list.toArray(new MultiFluidTankEntry[0]); + this.fluidTanks = list.toArray(new ITankEntry[0]); this.allowSameFluidFill = allowSameFluidFill; } @@ -51,7 +54,7 @@ private MultiFluidTankEntry wrapIntoEntry(IFluidTank tank) { @NotNull @Override - public List getFluidTanks() { + public List getFluidTanks() { return Collections.unmodifiableList(Arrays.asList(fluidTanks)); } @@ -62,7 +65,7 @@ public int getTanks() { @NotNull @Override - public MultiFluidTankEntry getTankAt(int index) { + public ITankEntry getTankAt(int index) { return fluidTanks[index]; } @@ -70,7 +73,7 @@ public MultiFluidTankEntry getTankAt(int index) { @Override public IFluidTankProperties[] getTankProperties() { ArrayList propertiesList = new ArrayList<>(); - for (MultiFluidTankEntry fluidTank : fluidTanks) { + for (ITankEntry fluidTank : fluidTanks) { Collections.addAll(propertiesList, fluidTank.getTankProperties()); } return propertiesList.toArray(new IFluidTankProperties[0]); @@ -91,11 +94,11 @@ public int fill(FluidStack resource, boolean doFill) { // flag value indicating whether the fluid was stored in 'distinct' slot at least once boolean distinctSlotVisited = false; - MultiFluidTankEntry[] fluidTanks = this.fluidTanks.clone(); + ITankEntry[] fluidTanks = this.fluidTanks.clone(); Arrays.sort(fluidTanks, IMultipleTankHandler.ENTRY_COMPARATOR); // search for tanks with same fluid type first - for (MultiFluidTankEntry tank : fluidTanks) { + for (ITankEntry tank : fluidTanks) { // if the fluid to insert matches the tank, insert the fluid if (resource.isFluidEqual(tank.getFluid())) { int inserted = tank.fill(resource, doFill); @@ -118,7 +121,7 @@ public int fill(FluidStack resource, boolean doFill) { } } // if we still have fluid to insert, loop through empty tanks until we find one that can accept the fluid - for (MultiFluidTankEntry tank : fluidTanks) { + for (ITankEntry tank : fluidTanks) { // if the tank uses distinct fluid fill (allowSameFluidFill disabled) and another distinct tank had // received the fluid, skip this tank boolean usesDistinctFluidFill = tank.allowSameFluidFill(); @@ -207,7 +210,7 @@ public NBTTagCompound serializeNBT() { NBTTagCompound fluidInventory = new NBTTagCompound(); NBTTagList tanks = new NBTTagList(); for (int i = 0; i < this.getTanks(); i++) { - tanks.appendTag(this.fluidTanks[i].trySerialize()); + tanks.appendTag(this.fluidTanks[i].serializeNBT()); } fluidInventory.setTag("Tanks", tanks); return fluidInventory; @@ -217,7 +220,7 @@ public NBTTagCompound serializeNBT() { public void deserializeNBT(NBTTagCompound nbt) { NBTTagList tanks = nbt.getTagList("Tanks", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < Math.min(fluidTanks.length, tanks.tagCount()); i++) { - this.fluidTanks[i].tryDeserialize(tanks.getCompoundTagAt(i)); + this.fluidTanks[i].deserializeNBT(tanks.getCompoundTagAt(i)); } } @@ -243,4 +246,127 @@ public String toString(boolean lineBreak) { if (lineBreak) stb.append('\n'); return stb.append(']').toString(); } + + /** + * Entry of multi fluid tanks. Retains reference to original {@link IMultipleTankHandler} for accessing + * information such as {@link IMultipleTankHandler#allowSameFluidFill()}. + */ + private static final class MultiFluidTankEntry implements ITankEntry { + + private final IMultipleTankHandler tank; + private final IFluidTank delegate; + private final IFluidTankProperties[] fallback; + + public MultiFluidTankEntry(@NotNull IMultipleTankHandler tank, @NotNull IFluidTank delegate) { + this.tank = tank; + this.delegate = delegate; + this.fallback = new IFluidTankProperties[] { + new FallbackTankProperty() + }; + } + + @NotNull + @Override + public IMultipleTankHandler getParent() { + return tank; + } + + @NotNull + @Override + public IFluidTank getDelegate() { + return delegate; + } + + public boolean allowSameFluidFill() { + return tank.allowSameFluidFill(); + } + + @Nullable + @Override + public IFilter getFilter() { + return this.delegate instanceof IFilteredFluidContainer filtered ? filtered.getFilter() : null; + } + + @NotNull + public IFluidTankProperties[] getTankProperties() { + return delegate instanceof IFluidHandler fluidHandler ? + fluidHandler.getTankProperties() : fallback; + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + return delegate.fill(resource, doFill); + } + + @Nullable + @Override + public FluidStack drain(FluidStack resource, boolean doDrain) { + if (resource == null || resource.amount <= 0) { + return null; + } + if (delegate instanceof IFluidHandler fluidHandler) { + return fluidHandler.drain(resource, doDrain); + } + // just imitate the logic + FluidStack fluid = delegate.getFluid(); + return fluid != null && fluid.isFluidEqual(resource) ? drain(resource.amount, doDrain) : null; + } + + @Nullable + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return delegate.drain(maxDrain, doDrain); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + public boolean equals(Object obj) { + return this == obj || delegate.equals(obj); + } + + @Override + public String toString() { + return delegate.toString(); + } + + private final class FallbackTankProperty implements IFluidTankProperties { + + @Nullable + @Override + public FluidStack getContents() { + return delegate.getFluid(); + } + + @Override + public int getCapacity() { + return delegate.getCapacity(); + } + + @Override + public boolean canFill() { + return true; + } + + @Override + public boolean canDrain() { + return true; + } + + @Override + public boolean canFillFluidType(FluidStack fluidStack) { + IFilter filter = getFilter(); + return filter == null || filter.test(fluidStack); + } + + @Override + public boolean canDrainFluidType(FluidStack fluidStack) { + return true; + } + } + } } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 6f2357eb1d7..e2f56ffecf2 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -433,7 +433,7 @@ public int size() { * modifications in list will reflect on fluid handler and wise-versa */ public static List fluidHandlerToList(IMultipleTankHandler fluidInputs) { - List backedList = fluidInputs.getFluidTanks(); + List backedList = fluidInputs.getFluidTanks(); return new AbstractList() { @Override diff --git a/src/main/java/gregtech/api/util/OverlayedFluidHandler.java b/src/main/java/gregtech/api/util/OverlayedFluidHandler.java index ece86333d65..d2d0dafb239 100644 --- a/src/main/java/gregtech/api/util/OverlayedFluidHandler.java +++ b/src/main/java/gregtech/api/util/OverlayedFluidHandler.java @@ -1,7 +1,6 @@ package gregtech.api.util; import gregtech.api.capability.IMultipleTankHandler; -import gregtech.api.capability.IMultipleTankHandler.MultiFluidTankEntry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidTankProperties; @@ -22,9 +21,9 @@ public class OverlayedFluidHandler { public OverlayedFluidHandler(@NotNull IMultipleTankHandler tank) { this.overlayedTanks = new ArrayList<>(); - MultiFluidTankEntry[] entries = tank.getFluidTanks().toArray(new MultiFluidTankEntry[0]); + var entries = tank.getFluidTanks().toArray(new IMultipleTankHandler.ITankEntry[0]); Arrays.sort(entries, IMultipleTankHandler.ENTRY_COMPARATOR); - for (MultiFluidTankEntry fluidTank : entries) { + for (var fluidTank : entries) { for (IFluidTankProperties property : fluidTank.getTankProperties()) { this.overlayedTanks.add(new OverlayedTank(property, fluidTank.allowSameFluidFill())); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java index 148f40613f0..7efd88c5471 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java @@ -61,7 +61,7 @@ private List getPartHandlers() { FluidTankList fluidTankList = getFluidHandlers(); if (fluidTankList != null) { for (IFluidTank fluidTank : fluidTankList) { - if (fluidTank instanceof IMultipleTankHandler.MultiFluidTankEntry entry) { + if (fluidTank instanceof IMultipleTankHandler.ITankEntry entry) { fluidTank = entry.getDelegate(); } if (fluidTank instanceof INotifiableHandler) { diff --git a/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java b/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java index a734933b9fe..c6a04043724 100644 --- a/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java +++ b/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java @@ -1,7 +1,6 @@ package gregtech.api.capability.impl; import gregtech.Bootstrap; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.unification.material.Materials; import gregtech.api.util.OverlayedFluidHandler; @@ -409,7 +408,7 @@ FluidHandlerTester expectContents(@NotNull FluidStack... optionalFluidStacks) { "expected: " + this.tank.getTanks() + ", provided: " + optionalFluidStacks.length); } for (int i = 0; i < optionalFluidStacks.length; i++) { - IMultipleTankHandler.MultiFluidTankEntry tank = this.tank.getTankAt(i); + var tank = this.tank.getTankAt(i); if (!eq(tank.getFluid(), optionalFluidStacks[i])) { throw new AssertionError("Contents of the tank don't match expected state.\n" + "Expected: [\n " + Arrays.stream(optionalFluidStacks) From e716fffb20fc887fdac135e3c3676b284a5e921f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:02:00 -0700 Subject: [PATCH 090/103] add overloaded method fix distinct fluids --- .../impl/MultiblockRecipeLogic.java | 25 ++++++++++++++++--- .../RecipeMapMultiblockController.java | 23 ++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 30815a37276..29bb7db77cd 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -1,6 +1,7 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; +import gregtech.api.capability.DualHandler; import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; @@ -99,6 +100,21 @@ protected IMultipleTankHandler getInputTank() { return controller.getInputFluidInventory(); } + /** + * Overload of {@link #getInputTank()} to gather extra fluid tanks + * that could exist in a distinct item handler (such as a {@link DualHandler}) + * + * @param items Handler to gather fluid tanks from + * @return a new FluidTankList with extra fluid tanks on top of the existing fluid tanks + */ + protected IMultipleTankHandler getInputTank(IItemHandler items) { + var tanks = new ArrayList<>(getInputTank().getFluidTanks()); + if (items instanceof IMultipleTankHandler tankHandler) { + tanks.addAll(tankHandler.getFluidTanks()); + } + return new FluidTankList(getInputTank().allowSameFluidFill(), tanks); + } + @Override protected IMultipleTankHandler getOutputTank() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; @@ -222,7 +238,7 @@ protected void trySearchNewRecipeDistinct() { continue; } // Look for a new recipe after a cache miss - currentRecipe = findRecipe(maxVoltage, bus, getInputTank()); + currentRecipe = findRecipe(maxVoltage, bus, getInputTank(bus)); // Cache the current recipe, if one is found if (currentRecipe != null && checkRecipe(currentRecipe)) { this.previousRecipe = currentRecipe; @@ -252,7 +268,7 @@ public void invalidateInputs() { } protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) { - return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank()); + return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank(previousBus)); } protected boolean prepareRecipeDistinct(Recipe recipe) { @@ -262,14 +278,15 @@ protected boolean prepareRecipeDistinct(Recipe recipe) { recipe = findParallelRecipe( recipe, currentDistinctInputBus, - getInputTank(), + getInputTank(currentDistinctInputBus), getOutputInventory(), getOutputTank(), getMaxParallelVoltage(), getParallelLimit()); if (recipe != null) { - recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, getInputTank()); + recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, + getInputTank(currentDistinctInputBus)); if (recipe != null) { setupRecipe(recipe); return true; diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java index bbf7504acb5..4b5ab335739 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -48,6 +48,7 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla protected IItemHandlerModifiable outputInventory; protected IMultipleTankHandler inputFluidInventory; protected IMultipleTankHandler outputFluidInventory; + protected IMultipleTankHandler extendedFluidInputs; protected IEnergyContainer energyContainer; private boolean isDistinct = false; @@ -74,7 +75,10 @@ public IItemHandlerModifiable getOutputInventory() { } public IMultipleTankHandler getInputFluidInventory() { - return inputFluidInventory; + // if distinct, return the normal input fluid inventory, + // as recipe logic handles gathering extra fluids + // if not distinct, return all the fluids instead + return isDistinct() ? inputFluidInventory : extendedFluidInputs; } public IMultipleTankHandler getOutputFluidInventory() { @@ -120,9 +124,12 @@ public boolean isActive() { protected void initializeAbilities() { this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS)); - this.inputFluidInventory = createFluidList(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_FLUIDS); + this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), + getAbilities(MultiblockAbility.IMPORT_FLUIDS)); + this.extendedFluidInputs = extendedImportFluidList(this.inputFluidInventory); this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS)); - this.outputFluidInventory = createFluidList(MultiblockAbility.EXPORT_ITEMS, MultiblockAbility.EXPORT_FLUIDS); + this.outputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(), + getAbilities(MultiblockAbility.EXPORT_FLUIDS)); List inputEnergy = new ArrayList<>(getAbilities(MultiblockAbility.INPUT_ENERGY)); inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY)); @@ -138,11 +145,9 @@ private void resetTileAbilities() { this.energyContainer = new EnergyContainerList(Lists.newArrayList()); } - protected IMultipleTankHandler createFluidList(MultiblockAbility items, - MultiblockAbility fluids) { - var tanks = new AbilityInstances(fluids); - tanks.addAll(getAbilities(fluids)); - for (var handler : getAbilities(items)) { + protected IMultipleTankHandler extendedImportFluidList(IMultipleTankHandler fluids) { + List tanks = new ArrayList<>(fluids.getFluidTanks()); + for (var handler : getAbilities(MultiblockAbility.IMPORT_ITEMS)) { if (handler instanceof IFluidTank tank) { tanks.add(tank); } else if (handler instanceof IMultipleTankHandler multipleTankHandler) { @@ -150,7 +155,7 @@ protected IMultipleTankHandler createFluidList(MultiblockAbility Date: Sat, 17 Aug 2024 16:53:26 -0700 Subject: [PATCH 091/103] remove unnecessary overrides --- .../gregtech/api/capability/impl/FluidTankList.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/FluidTankList.java b/src/main/java/gregtech/api/capability/impl/FluidTankList.java index 0ac625f934c..2895b0c0cee 100644 --- a/src/main/java/gregtech/api/capability/impl/FluidTankList.java +++ b/src/main/java/gregtech/api/capability/impl/FluidTankList.java @@ -1,7 +1,6 @@ package gregtech.api.capability.impl; import gregtech.api.capability.IFilter; -import gregtech.api.capability.IFilteredFluidContainer; import gregtech.api.capability.IMultipleTankHandler; import net.minecraft.nbt.NBTTagCompound; @@ -277,16 +276,6 @@ public IFluidTank getDelegate() { return delegate; } - public boolean allowSameFluidFill() { - return tank.allowSameFluidFill(); - } - - @Nullable - @Override - public IFilter getFilter() { - return this.delegate instanceof IFilteredFluidContainer filtered ? filtered.getFilter() : null; - } - @NotNull public IFluidTankProperties[] getTankProperties() { return delegate instanceof IFluidHandler fluidHandler ? From f15c3b8ffc2d793b32f5c26e80c2b2aac89984d3 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:19:56 -0700 Subject: [PATCH 092/103] spotless --- src/main/java/gregtech/api/util/GTUtility.java | 1 - .../multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index e2f56ffecf2..568dff8c8ff 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -64,7 +64,6 @@ import java.util.AbstractList; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java index 7f0bf1830ee..c70e83674cd 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/hpca/MetaTileEntityHPCAComponent.java @@ -5,7 +5,6 @@ import gregtech.api.capability.IHPCAComponentHatch; import gregtech.api.capability.IHPCAComputationProvider; import gregtech.api.capability.IHPCACoolantProvider; -import gregtech.api.gui.ModularUI; import gregtech.api.metatileentity.multiblock.AbilityInstances; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; From 3df691c71c42aa2888f41639ebe2f649c333a021 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:29:01 -0700 Subject: [PATCH 093/103] add javadoc spotless --- .../metatileentity/multiblock/IMultiblockAbilityPart.java | 7 +++++++ .../multi/multiblockpart/MetaTileEntityEnergyHatch.java | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index 8a9b23dbbe7..dcc6e9b501e 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -27,5 +27,12 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { return getAbility() == null ? Collections.emptyList() : Collections.singletonList(getAbility()); } + /** + * Register abilities to the multiblock here + *
+ * Check {@link AbilityInstances#isKey(MultiblockAbility)} if you return a list of abilities + * + * @param abilityInstances list to register abilities to + */ void registerAbilities(@NotNull AbilityInstances abilityInstances); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index 473034a2ab1..e3ed8949d85 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -35,7 +35,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.lang.ref.WeakReference; import java.util.List; From a70e49d5f1e3aa43213f044fd403315310507993 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:31:01 -0700 Subject: [PATCH 094/103] improve javadoc slightly --- .../api/metatileentity/multiblock/IMultiblockAbilityPart.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index dcc6e9b501e..dcaeb179d22 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -30,7 +30,7 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { /** * Register abilities to the multiblock here *
- * Check {@link AbilityInstances#isKey(MultiblockAbility)} if you return a list of abilities + * Check {@link AbilityInstances#isKey(MultiblockAbility) AbiliteInstances.isKey()} if you override {@link IMultiblockAbilityPart#getAbilities()} * * @param abilityInstances list to register abilities to */ From d9656da34e4c8464e9c930bc7d415b4973065673 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:08:28 -0700 Subject: [PATCH 095/103] improve javadoc slightly clarify existing check at set use simple name instead of class string --- .../multiblock/AbilityInstances.java | 15 ++++++++++++--- .../multiblock/IMultiblockAbilityPart.java | 3 ++- .../multiblock/MultiblockAbility.java | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 56f2333ecd7..5f69ac57bde 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -1,5 +1,7 @@ package gregtech.api.metatileentity.multiblock; +import gregtech.api.util.GTLog; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -100,7 +102,8 @@ protected boolean canAdd(Object o) { public void add(int index, Object element) { if (!key.checkType(element)) throw new IllegalArgumentException( - String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), + String.format("element \"%s\" does not extend/implement \"%s\"", + element.getClass().getSimpleName(), this.key.getType())); if (!instances.contains(element)) instances.add(index, element); @@ -117,10 +120,16 @@ public void add(int index, Object element) { public Object set(int index, Object element) { if (!key.checkType(element)) throw new IllegalArgumentException( - String.format("element's class \"%s\" is not of type \"%s\"", element.getClass(), + String.format("element \"%s\" does not extend/implement \"%s\"", + element.getClass().getSimpleName(), this.key.getType())); - if (instances.contains(element)) + + int existing = instances.indexOf(element); + if (existing != -1) { + GTLog.logger.warn("attempted to set \"{}\" at index {} when we already have it at {}", + element.getClass().getSimpleName(), index, existing); return null; + } return instances.set(index, element); } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java index dcaeb179d22..d66334adf4c 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IMultiblockAbilityPart.java @@ -30,7 +30,8 @@ public interface IMultiblockAbilityPart extends IMultiblockPart { /** * Register abilities to the multiblock here *
- * Check {@link AbilityInstances#isKey(MultiblockAbility) AbiliteInstances.isKey()} if you override {@link IMultiblockAbilityPart#getAbilities()} + * Check {@link AbilityInstances#isKey(MultiblockAbility) AbiliteInstances.isKey()} if you override + * {@link IMultiblockAbilityPart#getAbilities()} * * @param abilityInstances list to register abilities to */ diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 1a9eac30790..8ce0e0d7273 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -125,7 +125,7 @@ public boolean checkType(Object o) { } public String getType() { - return this.clazz.toString(); + return this.clazz.getSimpleName(); } public @Nullable T checkAndCast(Object o) { From 69f24e725dc7ac2c448de07cd5355ebb09f51bb5 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:13:00 -0700 Subject: [PATCH 096/103] d --- .../api/metatileentity/multiblock/AbilityInstances.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java index 5f69ac57bde..d9c2517bb3c 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/AbilityInstances.java @@ -110,7 +110,7 @@ public void add(int index, Object element) { } /** - * Replaces the element at the index. Will throw and exception if the element is not what the key expects. + * Replaces the element at the index. Will throw an exception if the element is not what the key expects. * * @param index index of the element to replace * @param element element to be stored at the specified position From 52177f464b10649bf775b7a748f63d5be937dca9 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:30:37 -0700 Subject: [PATCH 097/103] fix rebase --- .../MetaTileEntityFluidHatch.java | 24 +++++-------------- .../MetaTileEntityMultiFluidHatch.java | 1 - 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index c9071d413cf..3f3e7bda447 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -19,6 +19,7 @@ import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; import gregtech.api.mui.GTGuiTextures; import gregtech.api.mui.GTGuis; +import gregtech.api.mui.widget.GhostCircuitSlotWidget; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer; import gregtech.common.metatileentities.storage.MetaTileEntityQuantumTank; @@ -291,27 +292,10 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) .childIf(isExportHatch, new ToggleButton() .pos(7, 63) .overlay(GTGuiTextures.BUTTON_LOCK) - // todo doing things this way causes flickering if it fails - // due to sync value cache .value(new BooleanSyncValue(this::isLocked, b -> fluidSyncHandler.lockFluid(b, false))) .addTooltip(true, IKey.lang("gregtech.gui.fluid_lock.tooltip.enabled")) .addTooltip(false, IKey.lang("gregtech.gui.fluid_lock.tooltip.disabled"))) -// if (this.circuitInventory != null) { -// SlotWidget circuitSlot = new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62) -// .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.INT_CIRCUIT_OVERLAY); -// builder.widget(circuitSlot.setConsumer(slotWidget -> { -// String configString; -// if (circuitInventory == null || -// circuitInventory.getCircuitValue() == GhostCircuitItemStackHandler.NO_CONFIG) { -// configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value") -// .getFormattedText(); -// } else { -// configString = String.valueOf(circuitInventory.getCircuitValue()); -// } -// -// slotWidget.setTooltipText("gregtech.gui.configurator_slot.tooltip", configString); -// })); -// } + // import specific .childIf(!isExportHatch, GTGuiTextures.TANK_ICON.asWidget() .pos(91, 36) @@ -321,6 +305,10 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) .background(GTGuiTextures.SLOT, GTGuiTextures.OUT_SLOT_OVERLAY) .slot(new ModularSlot(exportItems, 0) .accessibility(false, true))) + .childIf(!isExportHatch, new GhostCircuitSlotWidget() + .slot(circuitInventory, 0) + .background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY) + .pos(124, 62)) // common ui .child(new RichTextWidget() diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java index 534be6a22f1..347265bd387 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiFluidHatch.java @@ -39,7 +39,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.ArrayList; import java.util.List; From f268ffab67c0a11a38187daaa1abe18face5c1be Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:08:06 -0700 Subject: [PATCH 098/103] use reference equals instead --- .../api/metatileentity/multiblock/MultiblockAbility.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java index 8ce0e0d7273..f515806e997 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockAbility.java @@ -114,12 +114,6 @@ public String toString() { return name; } - @Override - public boolean equals(Object obj) { - return obj instanceof MultiblockAbilityother && - this.name.equals(other.name); - } - public boolean checkType(Object o) { return clazz.isAssignableFrom(o.getClass()); } From 1d4e47bdafa6f15ff5659d6e32fb28a762a5f11d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:32:54 -0700 Subject: [PATCH 099/103] move circuit inventory to `initializeInventory()` initial sync circuit value --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index 3f3e7bda447..dc4c82f6700 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -83,6 +83,11 @@ public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boo this.fluidTank = new HatchFluidTank(getInventorySize(), this, isExportHatch); initializeInventory(); // the fact that this has to be called three times is so dumb this.workingEnabled = true; + } + + @Override + protected void initializeInventory() { + super.initializeInventory(); if (this.hasGhostCircuitInventory()) { this.circuitInventory = new GhostCircuitItemStackHandler(this); this.circuitInventory.addNotifiableMetaTileEntity(this); @@ -188,6 +193,8 @@ public void writeInitialSyncData(PacketBuffer buf) { buf.writeBoolean(workingEnabled); if (isExportHatch) { buf.writeBoolean(locked); + } else { + buf.writeVarInt(this.circuitInventory.getCircuitValue()); } } @@ -197,6 +204,8 @@ public void receiveInitialSyncData(PacketBuffer buf) { this.workingEnabled = buf.readBoolean(); if (isExportHatch) { this.locked = buf.readBoolean(); + } else { + this.circuitInventory.setCircuitValue(buf.readVarInt()); } } From e80cedda75cfc137ea3242666371994913d141ab Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:34:01 -0700 Subject: [PATCH 100/103] switch variable names to match MultiFluidTankEntry --- .../gregtech/api/capability/DualHandler.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index ceab3674089..78c0e46ebc3 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -21,6 +21,7 @@ public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler .compareItem(true) .compareDamage(true) .compareTag(true) + .compareCount(true) .build(); @NotNull IItemHandlerModifiable itemDelegate; @@ -173,24 +174,25 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { public static class DualEntry implements ITankEntry, INotifiableHandler { - private final DualHandler delegate; + @NotNull + private final DualHandler tank; @NotNull - private final ITankEntry tank; + private final ITankEntry delegate; - public DualEntry(DualHandler delegate, ITankEntry tank) { + public DualEntry(@NotNull DualHandler tank, @NotNull ITankEntry delegate) { this.delegate = delegate; this.tank = tank; } @Override public @NotNull IMultipleTankHandler getParent() { - return this.delegate; + return this.tank; } @Override public @NotNull IFluidTank getDelegate() { - return this.tank; + return this.delegate; } @Override @@ -202,7 +204,7 @@ public IFluidTankProperties[] getTankProperties() { public int fill(FluidStack resource, boolean doFill) { int filled = getTank().fill(resource, doFill); if (doFill && filled > 0) - delegate.onContentsChanged(this); + tank.onContentsChanged(this); return filled; } @@ -210,7 +212,7 @@ public int fill(FluidStack resource, boolean doFill) { public FluidStack drain(FluidStack resource, boolean doDrain) { var drained = getTank().drain(resource, doDrain); if (doDrain && drained != null) - delegate.onContentsChanged(this); + tank.onContentsChanged(this); return drained; } @@ -218,22 +220,23 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { public FluidStack drain(int maxDrain, boolean doDrain) { var drained = getTank().drain(maxDrain, doDrain); if (doDrain && drained != null) - delegate.onContentsChanged(this); + tank.onContentsChanged(this); return drained; } + // this method might be redundant private @NotNull ITankEntry getTank() { - return this.tank; + return this.delegate; } @Override public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.delegate.addNotifiableMetaTileEntity(metaTileEntity); + this.tank.addNotifiableMetaTileEntity(metaTileEntity); } @Override public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.delegate.removeNotifiableMetaTileEntity(metaTileEntity); + this.tank.removeNotifiableMetaTileEntity(metaTileEntity); } } } From 0bd9b2a31d2cfe24c5a3afa44c2ea34099b6b38f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:11:37 -0700 Subject: [PATCH 101/103] use better method --- .../multi/multiblockpart/MetaTileEntityFluidHatch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java index dc4c82f6700..7ce2a2d1367 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -205,7 +205,7 @@ public void receiveInitialSyncData(PacketBuffer buf) { if (isExportHatch) { this.locked = buf.readBoolean(); } else { - this.circuitInventory.setCircuitValue(buf.readVarInt()); + setGhostCircuitConfig(buf.readVarInt()); } } From 89e65ac33f119baa9faa7f1c2b783551bd4842c9 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 25 Jan 2025 15:11:41 -0700 Subject: [PATCH 102/103] add circuit slot to reservoir hatch --- .../MetaTileEntityReservoirHatch.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index 23af5369c0a..9ce8dd35617 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -1,8 +1,10 @@ package gregtech.common.metatileentities.multi.multiblockpart; import gregtech.api.GTValues; +import gregtech.api.capability.IGhostSlotConfigurable; import gregtech.api.capability.impl.FilteredItemHandler; import gregtech.api.capability.impl.FluidTankList; +import gregtech.api.capability.impl.GhostCircuitItemStackHandler; import gregtech.api.capability.impl.NotifiableFluidTank; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; @@ -39,18 +41,25 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.List; import java.util.function.Consumer; public class MetaTileEntityReservoirHatch extends MetaTileEntityMultiblockNotifiablePart - implements IMultiblockAbilityPart { + implements IMultiblockAbilityPart, + IGhostSlotConfigurable { private static final int FLUID_AMOUNT = 2_000_000_000; private final InfiniteWaterTank fluidTank; + private GhostCircuitItemStackHandler circuitInventory; public MetaTileEntityReservoirHatch(ResourceLocation metaTileEntityId) { super(metaTileEntityId, GTValues.EV, false); this.fluidTank = new InfiniteWaterTank(getInventorySize(), this); + if (this.hasGhostCircuitInventory()) { + this.circuitInventory = new GhostCircuitItemStackHandler(this); + this.circuitInventory.addNotifiableMetaTileEntity(this); + } initializeInventory(); } @@ -108,13 +117,17 @@ protected IItemHandlerModifiable createExportItemHandler() { } @Override - public MultiblockAbility getAbility() { - return MultiblockAbility.IMPORT_FLUIDS; + public @NotNull List> getAbilities() { + return Arrays.asList(MultiblockAbility.IMPORT_FLUIDS, MultiblockAbility.IMPORT_ITEMS); } @Override public void registerAbilities(@NotNull AbilityInstances abilityInstances) { - abilityInstances.add(fluidTank); + if (abilityInstances.isKey(MultiblockAbility.IMPORT_FLUIDS)) + abilityInstances.add(fluidTank); + else if (abilityInstances.isKey(MultiblockAbility.IMPORT_ITEMS)) { + abilityInstances.add(circuitInventory); + } } @Override @@ -136,6 +149,8 @@ public ModularUI.Builder createTankUI(IFluidTank fluidTank, String title, Entity .widget(new SlotWidget(exportItems, 0, 90, 53, true, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY)); + builder.widget(new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62)); + // Add general widgets return builder.label(6, 6, title) .label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF) @@ -178,6 +193,22 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t super.addToolUsages(stack, world, tooltip, advanced); } + @Override + public boolean hasGhostCircuitInventory() { + return true; + } + + @Override + public void setGhostCircuitConfig(int config) { + if (this.circuitInventory.getCircuitValue() == config) { + return; + } + this.circuitInventory.setCircuitValue(config); + if (!getWorld().isRemote) { + markDirty(); + } + } + private static class InfiniteWaterTank extends NotifiableFluidTank { public InfiniteWaterTank(int capacity, MetaTileEntity entityToNotify) { From 7f5f0be7a505bda2d0be4d00d68f9ff496e842da Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 25 Jan 2025 15:19:33 -0700 Subject: [PATCH 103/103] fix circuit slot --- .../MetaTileEntityReservoirHatch.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index 9ce8dd35617..0b9214f9e53 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -149,7 +149,20 @@ public ModularUI.Builder createTankUI(IFluidTank fluidTank, String title, Entity .widget(new SlotWidget(exportItems, 0, 90, 53, true, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY)); - builder.widget(new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62)); + builder.widget(new GhostCircuitSlotWidget(circuitInventory, 0, 124, 62) + .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.INT_CIRCUIT_OVERLAY) + .setConsumer(w -> { + String configString; + if (circuitInventory == null || + circuitInventory.getCircuitValue() == GhostCircuitItemStackHandler.NO_CONFIG) { + configString = new TextComponentTranslation("gregtech.gui.configurator_slot.no_value") + .getFormattedText(); + } else { + configString = String.valueOf(circuitInventory.getCircuitValue()); + } + + w.setTooltipText("gregtech.gui.configurator_slot.tooltip", configString); + })); // Add general widgets return builder.label(6, 6, title)