diff --git a/src/main/java/gregtech/api/capability/IDualHandler.java b/src/main/java/gregtech/api/capability/IDualHandler.java index 595efc6a9f2..42ad1dfb0dd 100644 --- a/src/main/java/gregtech/api/capability/IDualHandler.java +++ b/src/main/java/gregtech/api/capability/IDualHandler.java @@ -8,7 +8,7 @@ public interface IDualHandler { boolean hasItemHandlers(); - IMultipleTankHandler getFluidTanks(); + MultipleTankHandler getFluidTanks(); IItemHandler getItemHandlers(); } diff --git a/src/main/java/gregtech/api/capability/IFilteredFluidContainer.java b/src/main/java/gregtech/api/capability/IFilteredFluidContainer.java index c1920fda635..a1f3aae6e75 100644 --- a/src/main/java/gregtech/api/capability/IFilteredFluidContainer.java +++ b/src/main/java/gregtech/api/capability/IFilteredFluidContainer.java @@ -2,26 +2,5 @@ import net.minecraftforge.fluids.FluidStack; -import org.jetbrains.annotations.Nullable; - -import java.util.Comparator; - -/** - * Interface for fluid containers ({@link net.minecraftforge.fluids.IFluidTank IFluidTank} or - * {@link net.minecraftforge.fluids.capability.IFluidHandler IFluidHandler}) associated with {@link IFilter}. - */ -public interface IFilteredFluidContainer { - - /** - * Compare logic for filtered instances. - */ - Comparator COMPARATOR = Comparator.nullsLast( - Comparator.comparing(IFilteredFluidContainer::getFilter, IFilter.FILTER_COMPARATOR)); - - /** - * @return instance of {@link IFilter} associated to this object, or {@code null} if there's no filter - * associated. - */ - @Nullable - IFilter getFilter(); -} +// for type safe casting +public interface IFilteredFluidContainer extends IFilteredHandler {} diff --git a/src/main/java/gregtech/api/capability/IFilteredHandler.java b/src/main/java/gregtech/api/capability/IFilteredHandler.java new file mode 100644 index 00000000000..5b8c6143253 --- /dev/null +++ b/src/main/java/gregtech/api/capability/IFilteredHandler.java @@ -0,0 +1,25 @@ +package gregtech.api.capability; + +import org.jetbrains.annotations.Nullable; + +import java.util.Comparator; + +/** + * Interface for fluid containers ({@link net.minecraftforge.fluids.IFluidTank IFluidTank} or + * {@link net.minecraftforge.fluids.capability.IFluidHandler IFluidHandler}) associated with {@link IFilter}. + */ +public interface IFilteredHandler { + + /** + * Compare logic for filtered instances. + */ + Comparator> COMPARATOR = Comparator.nullsLast( + Comparator.comparing(IFilteredHandler::getFilter, IFilter.FILTER_COMPARATOR)); + + /** + * @return instance of {@link IFilter} associated to this object, or {@code null} if there's no filter + * associated. + */ + @Nullable + IFilter getFilter(); +} diff --git a/src/main/java/gregtech/api/capability/IFilteredItemContainer.java b/src/main/java/gregtech/api/capability/IFilteredItemContainer.java new file mode 100644 index 00000000000..3ad2c845c18 --- /dev/null +++ b/src/main/java/gregtech/api/capability/IFilteredItemContainer.java @@ -0,0 +1,5 @@ +package gregtech.api.capability; + +import net.minecraft.item.ItemStack; + +public interface IFilteredItemContainer extends IFilteredHandler {} diff --git a/src/main/java/gregtech/api/capability/IMultipleTankHandler.java b/src/main/java/gregtech/api/capability/IMultipleTankHandler.java deleted file mode 100644 index b9e89c71d30..00000000000 --- a/src/main/java/gregtech/api/capability/IMultipleTankHandler.java +++ /dev/null @@ -1,248 +0,0 @@ -package gregtech.api.capability; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.INBTSerializable; -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.IFluidHandler; -import net.minecraftforge.fluids.capability.IFluidTankProperties; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -/** - * Base class for multi-tank fluid handlers. Handles insertion logic, along with other standard - * {@link IFluidHandler} functionalities. - * - * @see gregtech.api.capability.impl.FluidTankList FluidTankList - */ -public interface IMultipleTankHandler extends IFluidHandler, Iterable { - - /** - * Comparator for entries that can be used in insertion logic - */ - Comparator ENTRY_COMPARATOR = (o1, o2) -> { - // #1: non-empty tank first - boolean empty1 = o1.getFluidAmount() <= 0; - boolean empty2 = o2.getFluidAmount() <= 0; - if (empty1 != empty2) return empty1 ? 1 : -1; - - // #2: filter priority - IFilter filter1 = o1.getFilter(); - IFilter filter2 = o2.getFilter(); - if (filter1 == null) return filter2 == null ? 0 : 1; - if (filter2 == null) return -1; - return IFilter.FILTER_COMPARATOR.compare(filter1, filter2); - }; - - /** - * @return unmodifiable view of {@code MultiFluidTankEntry}s. Note that it's still possible to access - * and modify inner contents of the tanks. - */ - @NotNull - List getFluidTanks(); - - /** - * @return Number of tanks in this tank handler - */ - int getTanks(); - - @NotNull - MultiFluidTankEntry getTankAt(int index); - - /** - * @return {@code false} if insertion to this fluid handler enforces input to be - * filled in one slot at max. {@code true} if it bypasses the rule. - */ - boolean allowSameFluidFill(); - - /** - * Tries to search tank with contents equal to {@code fluidStack}. If {@code fluidStack} is - * {@code null}, an empty tank is searched instead. - * - * @param fluidStack Fluid stack to search index - * @return Index corresponding to tank at {@link #getFluidTanks()} with matching - */ - default int getIndexOfFluid(@Nullable FluidStack fluidStack) { - 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)) { - return i; - } - } - return -1; - } - - @Override - default Iterator iterator() { - return getFluidTanks().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; - } - - @NotNull - public IMultipleTankHandler getTank() { - return tank; - } - - @NotNull - 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() : - new IFluidTankProperties[] { new FallbackTankProperty() }; - } - - public NBTTagCompound trySerialize() { - if (delegate instanceof FluidTank fluidTank) { - return fluidTank.writeToNBT(new NBTTagCompound()); - } else if (delegate instanceof INBTSerializable serializable) { - try { - return (NBTTagCompound) serializable.serializeNBT(); - } catch (ClassCastException ignored) {} - } - return new NBTTagCompound(); - } - - @SuppressWarnings({ "unchecked" }) - public void tryDeserialize(NBTTagCompound tag) { - if (delegate instanceof FluidTank fluidTank) { - fluidTank.readFromNBT(tag); - } else if (delegate instanceof INBTSerializable serializable) { - try { - serializable.deserializeNBT(tag); - } 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); - } - - @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/capability/MultipleTankHandler.java b/src/main/java/gregtech/api/capability/MultipleTankHandler.java new file mode 100644 index 00000000000..312cf7971b4 --- /dev/null +++ b/src/main/java/gregtech/api/capability/MultipleTankHandler.java @@ -0,0 +1,226 @@ +package gregtech.api.capability; + +import gregtech.api.capability.impl.FluidTankList; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.INBTSerializable; +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.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidTankProperties; + +import org.apache.commons.lang3.ArrayUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +/** + * Base class for multi-tank fluid handlers. Handles insertion logic, along with other standard + * {@link IFluidHandler} functionalities. + * + * @see FluidTankList FluidTankList + */ +public abstract class MultipleTankHandler implements IFluidHandler, Iterable, + INBTSerializable { + + /** + * Comparator for entries that can be used in insertion logic + */ + public static final Comparator ENTRY_COMPARATOR = (o1, o2) -> { + // #1: non-empty tank first + boolean empty1 = o1.getFluidAmount() <= 0; + boolean empty2 = o2.getFluidAmount() <= 0; + if (empty1 != empty2) return empty1 ? 1 : -1; + + // #2: filter priority + IFilter filter1 = o1.getFilter(); + IFilter filter2 = o2.getFilter(); + if (filter1 == null) return filter2 == null ? 0 : 1; + if (filter2 == null) return -1; + return IFilter.FILTER_COMPARATOR.compare(filter1, filter2); + }; + + /** + * @return unmodifiable view of {@code Entry}s. Note that it's still possible to access + * and modify inner contents of the tanks. + */ + @NotNull + public abstract List getFluidTanks(); + + /** + * @return Number of tanks in this tank handler + */ + public abstract int size(); + + @NotNull + public abstract Entry getTankAt(int index); + + /** + * @return {@code false} if insertion to this fluid handler enforces input to be + * filled in one slot at max. {@code true} if it bypasses the rule. + */ + public abstract boolean allowSameFluidFill(); + + /** + * Tries to search tank with contents equal to {@code fluidStack}. If {@code fluidStack} is + * {@code null}, an empty tank is searched instead. + * + * @param fluidStack Fluid stack to search index + * @return Index corresponding to tank at {@link #getFluidTanks()} with matching + */ + public final int getIndexOfFluid(@Nullable FluidStack fluidStack) { + 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)) { + return i; + } + } + return -1; + } + + public int simulateFill(FluidStack stack, int amount) { + var insertable = stack.copy(); + insertable.amount = amount; + return fill(insertable, false); + } + + @Override + public final @NotNull Iterator iterator() { + return getFluidTanks().iterator(); + } + + protected final Entry wrap(IFluidTank tank) { + return tank instanceof Entry ? (Entry) tank : new Entry(tank, this); + } + + public MultipleTankHandler addTanks(IFluidTank... tanks) { + if (ArrayUtils.isEmpty(tanks)) return this; + return new FluidTankList(allowSameFluidFill(), this, tanks); + } + + /** + * Entry of multi fluid tanks. Retains reference to original {@link MultipleTankHandler} for accessing + * information such as {@link MultipleTankHandler#allowSameFluidFill()}. + */ + public static class Entry implements IFluidTank, IFilteredHandler, INBTSerializable, + IFluidTankProperties { + + private final IFluidTank tank; + private final MultipleTankHandler parent; + + private Entry(IFluidTank tank, MultipleTankHandler parent) { + this.tank = tank; + this.parent = parent; + } + + public @NotNull MultipleTankHandler getParentHandler() { + return parent; + } + + public @NotNull IFluidTank getDelegate() { + return tank; + } + + public boolean allowSameFluidFill() { + return getParentHandler().allowSameFluidFill(); + } + + @Nullable + @Override + public IFilter getFilter() { + return getDelegate() instanceof IFilteredFluidContainer filter ? filter.getFilter() : null; + } + + @Nullable + @Override + public FluidStack getFluid() { + return getDelegate().getFluid(); + } + + @Override + public int getFluidAmount() { + return getDelegate().getFluidAmount(); + } + + @Override + public int getCapacity() { + return getDelegate().getCapacity(); + } + + @Override + public FluidTankInfo getInfo() { + return getDelegate().getInfo(); + } + + @Override + public FluidStack getContents() { + return getFluid() == null ? null : getFluid().copy(); + } + + @Override + public boolean canFill() { + return true; + } + + @Override + public boolean canDrain() { + return true; + } + + @Override + public boolean canFillFluidType(FluidStack fluidStack) { + if (allowSameFluidFill() || fluidStack == null) return true; + for (Entry tank : getParentHandler()) { + // only consider other tanks that do not allow same fluid fill + if (tank.allowSameFluidFill() || this == tank) continue; + if (fluidStack.isFluidEqual(tank.getFluid())) { + return tank.getFluidAmount() + fluidStack.amount <= tank.getCapacity(); + } + } + return true; + } + + @Override + public boolean canDrainFluidType(FluidStack fluidStack) { + return true; + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + return getDelegate().fill(resource, doFill); + } + + @Nullable + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + return getDelegate().drain(maxDrain, doDrain); + } + + @SuppressWarnings("rawtypes") + @Override + public NBTTagCompound serializeNBT() { + if (getDelegate() instanceof FluidTank fluidTank) { + return fluidTank.writeToNBT(new NBTTagCompound()); + } else if (getDelegate() instanceof INBTSerializable serializable) { + return (NBTTagCompound) serializable.serializeNBT(); + } + return new NBTTagCompound(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void deserializeNBT(NBTTagCompound nbt) { + if (getDelegate() instanceof FluidTank fluidTank) { + fluidTank.readFromNBT(nbt); + } else if (getDelegate() instanceof INBTSerializable serializable) { + serializable.deserializeNBT(nbt); + } + } + } +} diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 455ae3afd47..632ae451b32 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -4,8 +4,8 @@ import gregtech.api.capability.GregtechDataCodes; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IMultiblockController; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.IWorkable; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.MTETrait; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.multiblock.CleanroomType; @@ -152,14 +152,14 @@ protected IItemHandlerModifiable getOutputInventory() { /** * @return the fluid inventory to input fluids from */ - protected IMultipleTankHandler getInputTank() { + protected MultipleTankHandler getInputTank() { return metaTileEntity.getImportFluids(); } /** * @return the fluid inventory to output fluids to */ - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { return metaTileEntity.getExportFluids(); } @@ -379,7 +379,7 @@ protected void trySearchNewRecipe() { long maxVoltage = getMaxVoltage(); Recipe currentRecipe; IItemHandlerModifiable importInventory = getInputInventory(); - IMultipleTankHandler importFluids = getInputTank(); + MultipleTankHandler importFluids = getInputTank(); // see if the last recipe we used still works if (checkPreviousRecipe()) { @@ -463,7 +463,7 @@ protected boolean checkDimensionRequirement(@NotNull Recipe recipe) { * @return true if the recipe was successfully prepared, else false */ public boolean prepareRecipe(Recipe recipe, IItemHandlerModifiable inputInventory, - IMultipleTankHandler inputFluidInventory) { + MultipleTankHandler inputFluidInventory) { recipe = Recipe.trimRecipeOutputs(recipe, getRecipeMap(), metaTileEntity.getItemOutputLimit(), metaTileEntity.getFluidOutputLimit()); @@ -600,8 +600,8 @@ public ParallelLogicType getParallelLogicType() { * @param tanks the tanks to check * @return the minimum fluid capacity of the tanks */ - protected static int getMinTankCapacity(@NotNull IMultipleTankHandler tanks) { - if (tanks.getTanks() == 0) { + protected static int getMinTankCapacity(@NotNull MultipleTankHandler tanks) { + if (tanks.size() == 0) { return 0; } int result = Integer.MAX_VALUE; @@ -620,7 +620,7 @@ protected static int getMinTankCapacity(@NotNull IMultipleTankHandler tanks) { * @return the recipe if found, otherwise null */ @Nullable - protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { + protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, MultipleTankHandler fluidInputs) { RecipeMap map = getRecipeMap(); if (map == null || !isRecipeMapValid(map)) { return null; @@ -681,7 +681,7 @@ protected static boolean areItemStacksEqual(@NotNull ItemStack stackA, @NotNull */ protected final @Nullable Recipe setupAndConsumeRecipeInputs(@NotNull Recipe recipe, @NotNull IItemHandlerModifiable importInventory, - @NotNull IMultipleTankHandler importFluids) { + @NotNull MultipleTankHandler importFluids) { calculateOverclock(recipe); modifyOverclockPost(ocResult, recipe.propertyStorage()); @@ -731,10 +731,10 @@ protected boolean checkOutputSpaceItems(@NotNull Recipe recipe, @NotNull IItemHa * @param exportFluids the inventory to output to * @return if the recipe can be successfully output to the inventory */ - protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMultipleTankHandler exportFluids) { + protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull MultipleTankHandler exportFluids) { // We have already trimmed fluid outputs at this time if (!metaTileEntity.canVoidRecipeFluidOutputs() && - !GTTransferUtils.addFluidsToFluidHandler(exportFluids, true, recipe.getAllFluidOutputs())) { + !GTTransferUtils.addFluidsToFluidHandler(recipe.getAllFluidOutputs(), exportFluids, true)) { this.isOutputsFull = true; return false; } @@ -752,7 +752,7 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti */ protected @Nullable Recipe subTickOC(@NotNull OCResult ocResult, @NotNull Recipe recipe, @NotNull IItemHandlerModifiable importInventory, - @NotNull IMultipleTankHandler importFluids) { + @NotNull MultipleTankHandler importFluids) { RecipeMap map = getRecipeMap(); if (map == null) { return null; @@ -982,7 +982,7 @@ protected void completeRecipe() { */ protected void outputRecipeOutputs() { GTTransferUtils.addItemsToItemHandler(getOutputInventory(), false, itemOutputs); - GTTransferUtils.addFluidsToFluidHandler(getOutputTank(), false, fluidOutputs); + GTTransferUtils.addFluidsToFluidHandler(fluidOutputs, getOutputTank(), false); } /** diff --git a/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java index 28b2ee7afd0..e3bed4bf0e4 100644 --- a/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java @@ -2,7 +2,7 @@ import gregtech.api.GTValues; import gregtech.api.capability.IMultiblockController; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.RecipeMaps; @@ -77,7 +77,7 @@ protected void trySearchNewRecipe() { // can optimize with an override of checkPreviousRecipe() and a check here - IMultipleTankHandler importFluids = boiler.getImportFluids(); + MultipleTankHandler importFluids = boiler.getImportFluids(); boolean didStartRecipe = false; for (IFluidTank fluidTank : importFluids.getFluidTanks()) { diff --git a/src/main/java/gregtech/api/capability/impl/CommonFluidFilters.java b/src/main/java/gregtech/api/capability/impl/CommonFluidFilters.java index bca26ca9f25..38f907084d3 100644 --- a/src/main/java/gregtech/api/capability/impl/CommonFluidFilters.java +++ b/src/main/java/gregtech/api/capability/impl/CommonFluidFilters.java @@ -11,12 +11,14 @@ import org.jetbrains.annotations.NotNull; +import static gregtech.api.capability.IFilter.*; + /** * Common fluid filter implementations. */ -public enum CommonFluidFilters implements IFilter { +public class CommonFluidFilters { - ALLOW_ALL { + public static final IFilter ALLOW_ALL = new IFilter<>() { @Override public boolean test(@NotNull FluidStack fluid) { @@ -29,11 +31,12 @@ public int getPriority() { } @Override - public IFilter negate() { + public @NotNull IFilter negate() { return DISALLOW_ALL; } - }, - DISALLOW_ALL { + }; + + public static final IFilter DISALLOW_ALL = new IFilter<>() { @Override public boolean test(@NotNull FluidStack fluid) { @@ -46,11 +49,12 @@ public int getPriority() { } @Override - public IFilter negate() { + public @NotNull IFilter negate() { return ALLOW_ALL; } - }, - BOILER_FLUID { + }; + + public static final IFilter BOILER_FLUID = new IFilter<>() { @Override public boolean test(@NotNull FluidStack fluid) { @@ -69,10 +73,11 @@ public boolean test(@NotNull FluidStack fluid) { @Override public int getPriority() { - return IFilter.whitelistLikePriority(); + return whitelistLikePriority(); } - }, - STEAM { + }; + + public static final IFilter STEAM = new IFilter<>() { @Override public boolean test(@NotNull FluidStack fluid) { @@ -81,10 +86,11 @@ public boolean test(@NotNull FluidStack fluid) { @Override public int getPriority() { - return IFilter.whitelistPriority(1); + return whitelistPriority(1); } - }, - LIGHTER_FUEL { + }; + + public static final IFilter LIGHTER_FUEL = new IFilter<>() { @Override public boolean test(@NotNull FluidStack fluidStack) { @@ -93,7 +99,7 @@ public boolean test(@NotNull FluidStack fluidStack) { @Override public int getPriority() { - return IFilter.whitelistPriority(2); + return whitelistPriority(2); } }; diff --git a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java index e674db66763..8e99c04e370 100644 --- a/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java +++ b/src/main/java/gregtech/api/capability/impl/DistillationTowerLogicHandler.java @@ -1,7 +1,7 @@ package gregtech.api.capability.impl; import gregtech.api.capability.IDistillationTower; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.pattern.BlockPattern; @@ -31,7 +31,7 @@ public class DistillationTowerLogicHandler { private int layerCount; private List orderedFluidOutputs; - private IMultipleTankHandler fluidTanks; + private MultipleTankHandler fluidTanks; public DistillationTowerLogicHandler(IDistillationTower tower) { this.tower = tower; @@ -138,11 +138,11 @@ public List getOrderedFluidOutputs() { return orderedFluidOutputs; } - protected void setFluidTanks(IMultipleTankHandler fluidTanks) { + protected void setFluidTanks(MultipleTankHandler fluidTanks) { this.fluidTanks = fluidTanks; } - public IMultipleTankHandler getFluidTanks() { + public MultipleTankHandler getFluidTanks() { return fluidTanks; } diff --git a/src/main/java/gregtech/api/capability/impl/FilteredFluidHandler.java b/src/main/java/gregtech/api/capability/impl/FilteredFluidHandler.java index 7d6e2f6d811..60b925c5094 100644 --- a/src/main/java/gregtech/api/capability/impl/FilteredFluidHandler.java +++ b/src/main/java/gregtech/api/capability/impl/FilteredFluidHandler.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@Deprecated public class FilteredFluidHandler extends FluidTank implements IFilteredFluidContainer { @Nullable diff --git a/src/main/java/gregtech/api/capability/impl/FilteredItemHandler.java b/src/main/java/gregtech/api/capability/impl/FilteredItemHandler.java index 63e3131365e..0e5da9afca8 100644 --- a/src/main/java/gregtech/api/capability/impl/FilteredItemHandler.java +++ b/src/main/java/gregtech/api/capability/impl/FilteredItemHandler.java @@ -1,5 +1,6 @@ package gregtech.api.capability.impl; +import gregtech.api.capability.IFilter; import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,14 +12,13 @@ import java.util.function.Predicate; +@Deprecated public class FilteredItemHandler extends GTItemStackHandler { public static Predicate getCapabilityFilter(Capability cap) { return stack -> stack.hasCapability(cap, null); } - private Predicate fillPredicate; - public FilteredItemHandler(MetaTileEntity metaTileEntity) { super(metaTileEntity, 1); } @@ -32,12 +32,18 @@ public FilteredItemHandler(MetaTileEntity metaTileEntity, NonNullList } public FilteredItemHandler setFillPredicate(Predicate fillPredicate) { - this.fillPredicate = fillPredicate; + setFilter(new IFilter<>() { + + @Override + public boolean test(@NotNull ItemStack stack) { + return fillPredicate.test(stack); + } + + @Override + public int getPriority() { + return IFilter.noPriority(); + } + }); return this; } - - @Override - public boolean isItemValid(int slot, @NotNull ItemStack stack) { - return fillPredicate == null || fillPredicate.test(stack); - } } diff --git a/src/main/java/gregtech/api/capability/impl/FluidTankList.java b/src/main/java/gregtech/api/capability/impl/FluidTankList.java index 29594258fb4..f68e3b2fd20 100644 --- a/src/main/java/gregtech/api/capability/impl/FluidTankList.java +++ b/src/main/java/gregtech/api/capability/impl/FluidTankList.java @@ -1,79 +1,72 @@ package gregtech.api.capability.impl; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.Constants; -import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.IFluidTankProperties; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -public class FluidTankList implements IMultipleTankHandler, INBTSerializable { +public final class FluidTankList extends MultipleTankHandler { - private final MultiFluidTankEntry[] fluidTanks; private final boolean allowSameFluidFill; + private Entry[] tanks = new Entry[0]; public FluidTankList(boolean allowSameFluidFill, IFluidTank... fluidTanks) { - ArrayList list = new ArrayList<>(); - for (IFluidTank tank : fluidTanks) list.add(wrapIntoEntry(tank)); - this.fluidTanks = list.toArray(new MultiFluidTankEntry[0]); + if (!ArrayUtils.isEmpty(fluidTanks)) { + tanks = new Entry[fluidTanks.length]; + Arrays.setAll(tanks, value -> wrap(fluidTanks[value])); + } this.allowSameFluidFill = allowSameFluidFill; } public FluidTankList(boolean allowSameFluidFill, @NotNull List fluidTanks) { - ArrayList list = new ArrayList<>(); - for (IFluidTank tank : fluidTanks) list.add(wrapIntoEntry(tank)); - this.fluidTanks = list.toArray(new MultiFluidTankEntry[0]); - this.allowSameFluidFill = allowSameFluidFill; + this(allowSameFluidFill, fluidTanks.toArray(new IFluidTank[0])); } - public FluidTankList(boolean allowSameFluidFill, @NotNull IMultipleTankHandler parent, + public FluidTankList(boolean allowSameFluidFill, @NotNull MultipleTankHandler parent, IFluidTank... additionalTanks) { - ArrayList list = new ArrayList<>(parent.getFluidTanks()); - for (IFluidTank tank : additionalTanks) list.add(wrapIntoEntry(tank)); - this.fluidTanks = list.toArray(new MultiFluidTankEntry[0]); - this.allowSameFluidFill = allowSameFluidFill; - } + int tanks = parent.size(); + int additional = ArrayUtils.getLength(additionalTanks); + + this.tanks = new Entry[tanks + additional]; - private MultiFluidTankEntry wrapIntoEntry(IFluidTank tank) { - return tank instanceof MultiFluidTankEntry entry ? entry : new MultiFluidTankEntry(this, tank); + Arrays.setAll(this.tanks, value -> { + if (value < tanks) return parent.getTankAt(value); + else return wrap(additionalTanks[value - tanks]); + }); + + this.allowSameFluidFill = allowSameFluidFill; } - @NotNull @Override - public List getFluidTanks() { - return Collections.unmodifiableList(Arrays.asList(fluidTanks)); + public @NotNull List getFluidTanks() { + return Collections.unmodifiableList(Arrays.asList(this.tanks)); } @Override - public int getTanks() { - return fluidTanks.length; + public int size() { + return tanks.length; } - @NotNull @Override - public MultiFluidTankEntry getTankAt(int index) { - return fluidTanks[index]; + public @NotNull Entry getTankAt(int index) { + return tanks[index]; } - @NotNull @Override public IFluidTankProperties[] getTankProperties() { - ArrayList propertiesList = new ArrayList<>(); - for (MultiFluidTankEntry fluidTank : fluidTanks) { - Collections.addAll(propertiesList, fluidTank.getTankProperties()); - } - return propertiesList.toArray(new IFluidTankProperties[0]); + return this.tanks; } @Override @@ -83,63 +76,43 @@ public boolean allowSameFluidFill() { @Override public int fill(FluidStack resource, boolean doFill) { - if (resource == null || resource.amount <= 0) { + if (resource == null || resource.amount <= 0) return 0; - } + + FluidStack copy = resource.copy(); + int totalInserted = 0; - boolean inputFluidCopied = false; - // flag value indicating whether the fluid was stored in 'distinct' slot at least once - boolean distinctSlotVisited = false; - MultiFluidTankEntry[] fluidTanks = this.fluidTanks.clone(); - Arrays.sort(fluidTanks, IMultipleTankHandler.ENTRY_COMPARATOR); + Entry[] fluidTanks = this.tanks.clone(); + Arrays.sort(fluidTanks, ENTRY_COMPARATOR); + + boolean overflow = false; // search for tanks with same fluid type first - for (MultiFluidTankEntry tank : fluidTanks) { + for (Entry tank : fluidTanks) { + boolean empty = tank.getFluidAmount() == 0; + + // if we still have fluid to insert, loop through empty tanks until we find one that can accept the fluid + if (empty) { + // if the tank uses distinct fluid fill (allowSameFluidFill disabled) and another distinct tank had + // received the fluid, skip this tank + if (overflow && !tank.allowSameFluidFill()) continue; + if (tank.getFluidAmount() > 0 || !tank.canFillFluidType(doFill ? copy : resource)) continue; + + // if not empty fluid doesn't match, skip + } else if (!resource.isFluidEqual(tank.getFluid())) + continue; + // if the fluid to insert matches the tank, insert the fluid - if (resource.isFluidEqual(tank.getFluid())) { - int inserted = tank.fill(resource, doFill); - if (inserted > 0) { - totalInserted += inserted; - if (resource.amount - inserted <= 0) { - return totalInserted; - } - if (!inputFluidCopied) { - inputFluidCopied = true; - resource = resource.copy(); - } - resource.amount -= inserted; - } - // regardless of whether the insertion succeeded, presence of identical fluid in - // a slot prevents distinct fill to other slots - if (!tank.allowSameFluidFill()) { - distinctSlotVisited = true; - } - } - } - // if we still have fluid to insert, loop through empty tanks until we find one that can accept the fluid - for (MultiFluidTankEntry 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(); - if ((usesDistinctFluidFill || !distinctSlotVisited) && tank.getFluidAmount() == 0) { - int inserted = tank.fill(resource, doFill); - if (inserted > 0) { - totalInserted += inserted; - if (resource.amount - inserted <= 0) { - return totalInserted; - } - if (!inputFluidCopied) { - inputFluidCopied = true; - resource = resource.copy(); - } - resource.amount -= inserted; - if (!usesDistinctFluidFill) { - distinctSlotVisited = true; - } - } - } + int inserted = tank.fill(copy, doFill); + if (inserted <= 0) continue; + + totalInserted += inserted; + copy.amount -= inserted; + if (copy.amount <= 0) return totalInserted; + else if (empty) overflow = true; } + // return the amount of fluid that was inserted return totalInserted; } @@ -147,12 +120,12 @@ public int fill(FluidStack resource, boolean doFill) { @Nullable @Override public FluidStack drain(FluidStack resource, boolean doDrain) { - if (resource == null || resource.amount <= 0) { + if (resource == null || resource.amount <= 0) return null; - } + int amountLeft = resource.amount; FluidStack totalDrained = null; - for (IFluidTank handler : fluidTanks) { + for (IFluidTank handler : tanks) { if (!resource.isFluidEqual(handler.getFluid())) { continue; } @@ -175,29 +148,28 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { @Nullable @Override public FluidStack drain(int maxDrain, boolean doDrain) { - if (maxDrain <= 0) { - return null; - } + if (maxDrain <= 0) return null; + FluidStack totalDrained = null; - for (IFluidTank handler : fluidTanks) { + for (IFluidTank handler : tanks) { if (totalDrained == null) { - totalDrained = handler.drain(maxDrain, doDrain); - if (totalDrained != null) { - maxDrain -= totalDrained.amount; - } + var drained = handler.drain(maxDrain, doDrain); + if (drained == null) continue; + + totalDrained = drained.copy(); + maxDrain -= totalDrained.amount; + } else { - if (!totalDrained.isFluidEqual(handler.getFluid())) { + if (!totalDrained.isFluidEqual(handler.getFluid())) continue; - } + FluidStack drain = handler.drain(maxDrain, doDrain); - if (drain != null) { - totalDrained.amount += drain.amount; - maxDrain -= drain.amount; - } - } - if (maxDrain <= 0) { - return totalDrained; + if (drain == null) continue; + + totalDrained.amount += drain.amount; + maxDrain -= drain.amount; } + if (maxDrain <= 0) return totalDrained; } return totalDrained; } @@ -206,8 +178,8 @@ public FluidStack drain(int maxDrain, boolean doDrain) { 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()); + for (Entry tank : this.tanks) { + tanks.appendTag(tank.serializeNBT()); } fluidInventory.setTag("Tanks", tanks); return fluidInventory; @@ -216,8 +188,8 @@ public NBTTagCompound serializeNBT() { @Override 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)); + for (int i = 0; i < tanks.tagCount(); i++) { + this.tanks[i].deserializeNBT(tanks.getCompoundTagAt(i)); } } @@ -227,17 +199,17 @@ public String toString() { } public String toString(boolean lineBreak) { - StringBuilder stb = new StringBuilder("FluidTankList[").append(this.fluidTanks.length).append(";"); - for (int i = 0; i < this.fluidTanks.length; i++) { + StringBuilder stb = new StringBuilder("FluidTankList[").append(this.tanks.length).append(";"); + for (int i = 0; i < this.tanks.length; i++) { if (i != 0) stb.append(','); stb.append(lineBreak ? "\n " : " "); - FluidStack fluid = this.fluidTanks[i].getFluid(); + FluidStack fluid = this.tanks[i].getFluid(); if (fluid == null || fluid.amount == 0) { - stb.append("None 0 / ").append(this.fluidTanks[i].getCapacity()); + stb.append("None 0 / ").append(this.tanks[i].getCapacity()); } else { stb.append(fluid.getFluid().getName()).append(' ').append(fluid.amount) - .append(" / ").append(this.fluidTanks[i].getCapacity()); + .append(" / ").append(this.tanks[i].getCapacity()); } } if (lineBreak) stb.append('\n'); diff --git a/src/main/java/gregtech/api/capability/impl/GTSimpleFluidHandlerItemStack.java b/src/main/java/gregtech/api/capability/impl/GTSimpleFluidHandlerItemStack.java index 8e1116ceb5b..4bf71590c3d 100644 --- a/src/main/java/gregtech/api/capability/impl/GTSimpleFluidHandlerItemStack.java +++ b/src/main/java/gregtech/api/capability/impl/GTSimpleFluidHandlerItemStack.java @@ -11,7 +11,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class GTSimpleFluidHandlerItemStack extends FluidHandlerItemStackSimple implements IFilteredFluidContainer { +public class GTSimpleFluidHandlerItemStack extends FluidHandlerItemStackSimple + implements IFilteredFluidContainer { @Nullable private IFilter filter; diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index ff95f0fbb0c..aff48abec99 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -4,7 +4,7 @@ import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.IMultiblockController; import gregtech.api.capability.IMultipleRecipeMaps; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; @@ -94,13 +94,13 @@ protected IItemHandlerModifiable getOutputInventory() { } @Override - protected IMultipleTankHandler getInputTank() { + protected MultipleTankHandler getInputTank() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; return controller.getInputFluidInventory(); } @Override - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity; return controller.getOutputFluidInventory(); } @@ -200,7 +200,7 @@ protected void trySearchNewRecipeDistinct() { long maxVoltage = getMaxVoltage(); Recipe currentRecipe; List importInventory = getInputBuses(); - IMultipleTankHandler importFluids = getInputTank(); + MultipleTankHandler importFluids = getInputTank(); // Our caching implementation // This guarantees that if we get a recipe cache hit, our efficiency is no different from other machines diff --git a/src/main/java/gregtech/api/capability/impl/NotifiableFilteredFluidHandler.java b/src/main/java/gregtech/api/capability/impl/NotifiableFilteredFluidHandler.java index fe44ad8db4a..78b69fbee7f 100644 --- a/src/main/java/gregtech/api/capability/impl/NotifiableFilteredFluidHandler.java +++ b/src/main/java/gregtech/api/capability/impl/NotifiableFilteredFluidHandler.java @@ -1,39 +1,11 @@ package gregtech.api.capability.impl; -import gregtech.api.capability.INotifiableHandler; import gregtech.api.metatileentity.MetaTileEntity; -import java.util.ArrayList; -import java.util.List; - -public class NotifiableFilteredFluidHandler extends FilteredFluidHandler implements INotifiableHandler { - - List notifiableEntities = new ArrayList<>(); - private final boolean isExport; +@Deprecated +public class NotifiableFilteredFluidHandler extends NotifiableFluidTank { public NotifiableFilteredFluidHandler(int capacity, MetaTileEntity entityToNotify, boolean isExport) { - super(capacity); - this.notifiableEntities.add(entityToNotify); - this.isExport = isExport; - } - - @Override - protected void onContentsChanged() { - super.onContentsChanged(); - for (MetaTileEntity metaTileEntity : notifiableEntities) { - if (metaTileEntity != null && metaTileEntity.isValid()) { - addToNotifiedList(metaTileEntity, this, isExport); - } - } - } - - @Override - public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.notifiableEntities.add(metaTileEntity); - } - - @Override - public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { - this.notifiableEntities.remove(metaTileEntity); + super(capacity, entityToNotify, isExport); } } diff --git a/src/main/java/gregtech/api/capability/impl/NotifiableFluidTank.java b/src/main/java/gregtech/api/capability/impl/NotifiableFluidTank.java index 2669fa35097..9ddd1e05fd2 100644 --- a/src/main/java/gregtech/api/capability/impl/NotifiableFluidTank.java +++ b/src/main/java/gregtech/api/capability/impl/NotifiableFluidTank.java @@ -1,17 +1,24 @@ package gregtech.api.capability.impl; +import gregtech.api.capability.IFilter; +import gregtech.api.capability.IFilteredFluidContainer; import gregtech.api.capability.INotifiableHandler; import gregtech.api.metatileentity.MetaTileEntity; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; -public class NotifiableFluidTank extends FluidTank implements INotifiableHandler { +public class NotifiableFluidTank extends FluidTank implements INotifiableHandler, IFilteredFluidContainer { List notifiableEntities = new ArrayList<>(); private final boolean isExport; + private IFilter filter; public NotifiableFluidTank(int capacity, MetaTileEntity entityToNotify, boolean isExport) { super(capacity); @@ -38,4 +45,27 @@ public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { this.notifiableEntities.remove(metaTileEntity); } + + @Nullable + @Override + public IFilter getFilter() { + return this.filter; + } + + /** + * Set filter instance. If {@code null} is given, then the filter is set to be + * + * @param filter new filter instance + * @return this + */ + @NotNull + public NotifiableFluidTank setFilter(@Nullable IFilter filter) { + this.filter = filter; + return this; + } + + @Override + public boolean canFillFluidType(FluidStack fluid) { + return canFill() && (this.filter == null || this.filter.test(fluid)); + } } diff --git a/src/main/java/gregtech/api/capability/impl/NotifiableItemStackHandler.java b/src/main/java/gregtech/api/capability/impl/NotifiableItemStackHandler.java index 472c29e033f..ec6a44ba6a6 100644 --- a/src/main/java/gregtech/api/capability/impl/NotifiableItemStackHandler.java +++ b/src/main/java/gregtech/api/capability/impl/NotifiableItemStackHandler.java @@ -4,13 +4,10 @@ import gregtech.api.items.itemhandlers.GTItemStackHandler; import gregtech.api.metatileentity.MetaTileEntity; -import net.minecraftforge.items.IItemHandlerModifiable; - import java.util.ArrayList; import java.util.List; -public class NotifiableItemStackHandler extends GTItemStackHandler - implements IItemHandlerModifiable, INotifiableHandler { +public class NotifiableItemStackHandler extends GTItemStackHandler implements INotifiableHandler { List notifiableEntities = new ArrayList<>(); private final boolean isExport; diff --git a/src/main/java/gregtech/api/capability/impl/SingleFluidFilter.java b/src/main/java/gregtech/api/capability/impl/SingleFluidFilter.java index 51c1d8eb682..1f164f9353c 100644 --- a/src/main/java/gregtech/api/capability/impl/SingleFluidFilter.java +++ b/src/main/java/gregtech/api/capability/impl/SingleFluidFilter.java @@ -43,7 +43,7 @@ public int getPriority() { } @Override - public IFilter negate() { + public @NotNull IFilter negate() { return new SingleFluidFilter(this.fluid, !this.blacklist); } diff --git a/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java index 2c05b255d40..94674cda7ff 100644 --- a/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/SteamMultiblockRecipeLogic.java @@ -1,7 +1,7 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.multiblock.RecipeMapSteamMultiblockController; import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMap; @@ -27,14 +27,14 @@ public class SteamMultiblockRecipeLogic extends AbstractRecipeLogic { - private IMultipleTankHandler steamFluidTank; + private MultipleTankHandler steamFluidTank; private IFluidTank steamFluidTankCombined; // EU per mB private final double conversionRate; public SteamMultiblockRecipeLogic(RecipeMapSteamMultiblockController tileEntity, RecipeMap recipeMap, - IMultipleTankHandler steamFluidTank, double conversionRate) { + MultipleTankHandler steamFluidTank, double conversionRate) { super(tileEntity, recipeMap); this.steamFluidTank = steamFluidTank; this.conversionRate = conversionRate; @@ -59,7 +59,7 @@ protected IItemHandlerModifiable getOutputInventory() { return controller.getOutputInventory(); } - protected IMultipleTankHandler getSteamFluidTank() { + protected MultipleTankHandler getSteamFluidTank() { RecipeMapSteamMultiblockController controller = (RecipeMapSteamMultiblockController) metaTileEntity; return controller.getSteamFluidTank(); } @@ -69,7 +69,7 @@ private void combineSteamTanks() { if (steamFluidTank == null) steamFluidTankCombined = new FluidTank(0); else { - int capacity = steamFluidTank.getTanks() * 64000; + int capacity = steamFluidTank.size() * 64000; steamFluidTankCombined = new FluidTank(capacity); steamFluidTankCombined.fill(steamFluidTank.drain(capacity, false), true); } diff --git a/src/main/java/gregtech/api/gui/widgets/TankWidget.java b/src/main/java/gregtech/api/gui/widgets/TankWidget.java index 44e04a2768d..c915ec8c875 100644 --- a/src/main/java/gregtech/api/gui/widgets/TankWidget.java +++ b/src/main/java/gregtech/api/gui/widgets/TankWidget.java @@ -25,7 +25,6 @@ import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -102,9 +101,6 @@ public TankWidget setFluidRenderOffset(int fluidRenderOffset) { } public TankWidget setContainerClicking(boolean allowClickContainerFilling, boolean allowClickContainerEmptying) { - if (!(fluidTank instanceof IFluidHandler)) - throw new IllegalStateException( - "Container IO is only supported for fluid tanks that implement IFluidHandler"); this.allowClickFilling = allowClickContainerFilling; this.allowClickEmptying = allowClickContainerEmptying; return this; diff --git a/src/main/java/gregtech/api/items/itemhandlers/GTItemStackHandler.java b/src/main/java/gregtech/api/items/itemhandlers/GTItemStackHandler.java index eab9612c747..b4e22bf2beb 100644 --- a/src/main/java/gregtech/api/items/itemhandlers/GTItemStackHandler.java +++ b/src/main/java/gregtech/api/items/itemhandlers/GTItemStackHandler.java @@ -1,14 +1,20 @@ package gregtech.api.items.itemhandlers; +import gregtech.api.capability.IFilter; +import gregtech.api.capability.IFilteredItemContainer; import gregtech.api.metatileentity.MetaTileEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraftforge.items.ItemStackHandler; -public class GTItemStackHandler extends ItemStackHandler { +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; - final private MetaTileEntity metaTileEntity; +public class GTItemStackHandler extends ItemStackHandler implements IFilteredItemContainer { + + private final MetaTileEntity metaTileEntity; + private IFilter filter; public GTItemStackHandler(MetaTileEntity metaTileEntity) { super(); @@ -30,4 +36,25 @@ public void onContentsChanged(int slot) { super.onContentsChanged(slot); metaTileEntity.markDirty(); } + + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (!isItemValid(slot, stack)) return stack; + return super.insertItem(slot, stack, simulate); + } + + @Override + public boolean isItemValid(int slot, @NotNull ItemStack stack) { + return filter == null || filter.test(stack); + } + + public GTItemStackHandler setFilter(IFilter filter) { + this.filter = filter; + return this; + } + + @Override + public @Nullable IFilter getFilter() { + return null; + } } diff --git a/src/main/java/gregtech/api/items/metaitem/MetaItem.java b/src/main/java/gregtech/api/items/metaitem/MetaItem.java index a17559b05b2..3801ce50a83 100644 --- a/src/main/java/gregtech/api/items/metaitem/MetaItem.java +++ b/src/main/java/gregtech/api/items/metaitem/MetaItem.java @@ -1,10 +1,7 @@ package gregtech.api.items.metaitem; import gregtech.api.GTValues; -import gregtech.api.capability.GregtechCapabilities; -import gregtech.api.capability.IElectricItem; -import gregtech.api.capability.IFilteredFluidContainer; -import gregtech.api.capability.IPropertyFluidFilter; +import gregtech.api.capability.*; import gregtech.api.capability.impl.CombinedCapabilityProvider; import gregtech.api.capability.impl.ElectricItem; import gregtech.api.gui.ModularUI; diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index b0648610103..71877e85cae 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -71,6 +71,7 @@ import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.fluids.FluidActionResult; import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fml.common.FMLCommonHandler; @@ -155,8 +156,8 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder, protected List notifiedItemOutputList = new ArrayList<>(); protected List notifiedItemInputList = new ArrayList<>(); - protected List notifiedFluidInputList = new ArrayList<>(); - protected List notifiedFluidOutputList = new ArrayList<>(); + protected List notifiedFluidInputList = new ArrayList<>(); + protected List notifiedFluidOutputList = new ArrayList<>(); protected boolean muffled = false; @@ -386,9 +387,9 @@ public void addNotifiedInput(T input) { if (!notifiedItemInputList.contains(input)) { this.notifiedItemInputList.add((IItemHandlerModifiable) input); } - } else if (input instanceof IFluidHandler) { + } else if (input instanceof IFluidTank) { if (!notifiedFluidInputList.contains(input)) { - this.notifiedFluidInputList.add((IFluidHandler) input); + this.notifiedFluidInputList.add((IFluidTank) input); } } } @@ -1462,11 +1463,11 @@ public List getNotifiedItemInputList() { return notifiedItemInputList; } - public List getNotifiedFluidInputList() { + public List getNotifiedFluidInputList() { return notifiedFluidInputList; } - public List getNotifiedFluidOutputList() { + public List getNotifiedFluidOutputList() { return notifiedFluidOutputList; } diff --git a/src/main/java/gregtech/api/metatileentity/SimpleMachineMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/SimpleMachineMetaTileEntity.java index 64b8d3c86eb..3db5a293efb 100644 --- a/src/main/java/gregtech/api/metatileentity/SimpleMachineMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/SimpleMachineMetaTileEntity.java @@ -182,7 +182,7 @@ public void addCover(@NotNull EnumFacing side, @NotNull Cover cover) { @SideOnly(Side.CLIENT) public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { super.renderMetaTileEntity(renderState, translation, pipeline); - if (outputFacingFluids != null && getExportFluids().getTanks() > 0) { + if (outputFacingFluids != null && getExportFluids().size() > 0) { Textures.PIPE_OUT_OVERLAY.renderSided(outputFacingFluids, renderState, RenderUtil.adjustTrans(translation, outputFacingFluids, 2), pipeline); } @@ -508,7 +508,7 @@ protected ModularUI.Builder createGuiTemplate(EntityPlayer player) { .shouldUseBaseBackground()); leftButtonStartX += 18; } - if (exportFluids.getTanks() > 0) { + if (exportFluids.size() > 0) { builder.widget(new ToggleButtonWidget(leftButtonStartX, 62 + yOffset, 18, 18, GuiTextures.BUTTON_FLUID_OUTPUT, this::isAutoOutputFluids, this::setAutoOutputFluids) .setTooltipText("gregtech.gui.fluid_auto_output.tooltip") @@ -521,7 +521,7 @@ protected ModularUI.Builder createGuiTemplate(EntityPlayer player) { .setTooltipHoverString("gregtech.gui.overclock.description") .setButtonTexture(GuiTextures.BUTTON_OVERCLOCK)); - if (exportItems.getSlots() + exportFluids.getTanks() <= 9) { + if (exportItems.getSlots() + exportFluids.size() <= 9) { ImageWidget logo = new ImageWidget(152, 63 + yOffset, 17, 17, GTValues.XMAS.get() ? getXmasLogo() : getLogo()).setIgnoreColor(true); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java index 790a150ec0c..7fe5302040c 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java @@ -2,7 +2,7 @@ import gregtech.api.GTValues; import gregtech.api.capability.IEnergyContainer; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.EnergyContainerList; import gregtech.api.capability.impl.MultiblockFuelRecipeLogic; import gregtech.api.recipes.RecipeMap; @@ -123,12 +123,12 @@ public List getDataInfo() { return list; } - protected int[] getTotalFluidAmount(FluidStack testStack, IMultipleTankHandler multiTank) { + protected int[] getTotalFluidAmount(FluidStack testStack, MultipleTankHandler multiTank) { int fluidAmount = 0; int fluidCapacity = 0; for (var tank : multiTank) { if (tank != null) { - FluidStack drainStack = tank.drain(testStack, false); + FluidStack drainStack = tank.drain(testStack.amount, false); if (drainStack != null && drainStack.amount > 0) { fluidAmount += drainStack.amount; fluidCapacity += tank.getCapacity(); diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java index 55723ef456d..8620bc55774 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/MultiblockWithDisplayBase.java @@ -28,8 +28,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -543,9 +541,7 @@ protected void setVoidingMode(int mode) { // After changing the voiding mode, reset the notified buses in case a recipe can run now that voiding mode has // been changed - for (IFluidTank tank : this.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) { - this.getNotifiedFluidInputList().add((IFluidHandler) tank); - } + this.getNotifiedFluidInputList().addAll(this.getAbilities(MultiblockAbility.IMPORT_FLUIDS)); this.getNotifiedItemInputList().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 4949074c91a..bedf55286dc 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java @@ -3,7 +3,7 @@ import gregtech.api.GTValues; import gregtech.api.capability.IDistinctBusController; import gregtech.api.capability.IEnergyContainer; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.EnergyContainerList; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; @@ -45,8 +45,8 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla protected MultiblockRecipeLogic recipeMapWorkable; protected IItemHandlerModifiable inputInventory; protected IItemHandlerModifiable outputInventory; - protected IMultipleTankHandler inputFluidInventory; - protected IMultipleTankHandler outputFluidInventory; + protected MultipleTankHandler inputFluidInventory; + protected MultipleTankHandler outputFluidInventory; protected IEnergyContainer energyContainer; private boolean isDistinct = false; @@ -72,11 +72,11 @@ public IItemHandlerModifiable getOutputInventory() { return outputInventory; } - public IMultipleTankHandler getInputFluidInventory() { + public MultipleTankHandler getInputFluidInventory() { return inputFluidInventory; } - public IMultipleTankHandler getOutputFluidInventory() { + public MultipleTankHandler getOutputFluidInventory() { return outputFluidInventory; } diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapSteamMultiblockController.java b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapSteamMultiblockController.java index fd396609419..0d0e6b93bd3 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapSteamMultiblockController.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapSteamMultiblockController.java @@ -1,6 +1,6 @@ package gregtech.api.metatileentity.multiblock; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.ItemHandlerList; import gregtech.api.capability.impl.SteamMultiblockRecipeLogic; @@ -41,7 +41,7 @@ public abstract class RecipeMapSteamMultiblockController extends MultiblockWithD protected IItemHandlerModifiable inputInventory; protected IItemHandlerModifiable outputInventory; - protected IMultipleTankHandler steamFluidTank; + protected MultipleTankHandler steamFluidTank; public RecipeMapSteamMultiblockController(ResourceLocation metaTileEntityId, RecipeMap recipeMap, double conversionRate) { @@ -59,7 +59,7 @@ public IItemHandlerModifiable getOutputInventory() { return outputInventory; } - public IMultipleTankHandler getSteamFluidTank() { + public MultipleTankHandler getSteamFluidTank() { return steamFluidTank; } diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index ff495651ac5..f1abc7b3271 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -1,6 +1,6 @@ package gregtech.api.recipes; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.recipes.category.GTRecipeCategory; import gregtech.api.recipes.chance.boost.ChanceBoostFunction; import gregtech.api.recipes.chance.output.ChancedOutputList; @@ -185,7 +185,7 @@ public static Recipe trimRecipeOutputs(Recipe currentRecipe, RecipeMap recipe } public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable inputs, - IMultipleTankHandler fluidInputs) { + MultipleTankHandler fluidInputs) { Pair fluids = null; Pair items = null; diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index a2c2ef7b1f4..3abda0813fa 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMap.java +++ b/src/main/java/gregtech/api/recipes/RecipeMap.java @@ -2,7 +2,7 @@ import gregtech.api.GTValues; import gregtech.api.GregTechAPI; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.gui.ModularUI; import gregtech.api.gui.resources.TextureArea; @@ -533,7 +533,7 @@ amount, getMaxFluidOutputs()), } @Nullable - public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { + public Recipe findRecipe(long voltage, IItemHandlerModifiable inputs, MultipleTankHandler fluidInputs) { return this.findRecipe(voltage, GTUtility.itemHandlerToList(inputs), GTUtility.fluidHandlerToList(fluidInputs)); } diff --git a/src/main/java/gregtech/api/recipes/logic/IParallelableRecipeLogic.java b/src/main/java/gregtech/api/recipes/logic/IParallelableRecipeLogic.java index 423c1e4357d..06b93367537 100644 --- a/src/main/java/gregtech/api/recipes/logic/IParallelableRecipeLogic.java +++ b/src/main/java/gregtech/api/recipes/logic/IParallelableRecipeLogic.java @@ -1,6 +1,6 @@ package gregtech.api.recipes.logic; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.IVoidable; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.multiblock.ParallelLogicType; @@ -42,9 +42,9 @@ default void applyParallelBonus(@NotNull RecipeBuilder builder) {} default RecipeBuilder findMultipliedParallelRecipe(@NotNull RecipeMap recipeMap, @NotNull Recipe currentRecipe, @NotNull IItemHandlerModifiable inputs, - @NotNull IMultipleTankHandler fluidInputs, + @NotNull MultipleTankHandler fluidInputs, @NotNull IItemHandlerModifiable outputs, - @NotNull IMultipleTankHandler fluidOutputs, int parallelLimit, + @NotNull MultipleTankHandler fluidOutputs, int parallelLimit, long maxVoltage, @NotNull IVoidable voidable) { return ParallelLogic.doParallelRecipes( currentRecipe, @@ -85,9 +85,9 @@ default RecipeBuilder findAppendedParallelItemRecipe(@NotNull RecipeMap re // Recipes passed in here should be already trimmed, if desired default Recipe findParallelRecipe(@NotNull Recipe currentRecipe, @NotNull IItemHandlerModifiable inputs, - @NotNull IMultipleTankHandler fluidInputs, + @NotNull MultipleTankHandler fluidInputs, @NotNull IItemHandlerModifiable outputs, - @NotNull IMultipleTankHandler fluidOutputs, long maxVoltage, int parallelLimit) { + @NotNull MultipleTankHandler fluidOutputs, long maxVoltage, int parallelLimit) { if (parallelLimit > 1 && getRecipeMap() != null) { RecipeBuilder parallelBuilder = switch (getParallelLogicType()) { case MULTIPLY -> findMultipliedParallelRecipe(getRecipeMap(), currentRecipe, inputs, fluidInputs, diff --git a/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java b/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java index c056890d086..75189b98576 100644 --- a/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java +++ b/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java @@ -1,6 +1,6 @@ package gregtech.api.recipes.logic; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.IVoidable; import gregtech.api.recipes.FluidKey; import gregtech.api.recipes.Recipe; @@ -10,7 +10,6 @@ import gregtech.api.util.GTHashMaps; import gregtech.api.util.GTUtility; import gregtech.api.util.ItemStackHashStrategy; -import gregtech.api.util.OverlayedFluidHandler; import gregtech.api.util.OverlayedItemHandler; import net.minecraft.item.ItemStack; @@ -41,7 +40,7 @@ public abstract class ParallelLogic { */ public static int getMaxRecipeMultiplier(@NotNull Recipe recipe, @NotNull IItemHandlerModifiable inputs, - @NotNull IMultipleTankHandler fluidInputs, int parallelAmount) { + @NotNull MultipleTankHandler fluidInputs, int parallelAmount) { // Find all the items in the combined Item Input inventories and create oversized ItemStacks Object2IntMap ingredientStacks = GTHashMaps.fromItemHandler(inputs); @@ -71,7 +70,7 @@ public static int getMaxRecipeMultiplier(@NotNull Recipe recipe, @NotNull IItemH * @return returns the amount of recipes that can be merged successfully into a given output inventory */ public static int limitByOutputMerging(@NotNull Recipe recipe, @NotNull IItemHandlerModifiable outputs, - @NotNull IMultipleTankHandler fluidOutputs, int parallelAmount, + @NotNull MultipleTankHandler fluidOutputs, int parallelAmount, boolean voidItems, boolean voidFluids) { int modifiedItemParallelAmount = Integer.MAX_VALUE; int modifiedFluidParallelAmount = Integer.MAX_VALUE; @@ -103,7 +102,7 @@ public static int limitByOutputMerging(@NotNull Recipe recipe, @NotNull IItemHan if (voidFluids) { modifiedFluidParallelAmount = parallelAmount; } else { - modifiedFluidParallelAmount = limitParallelByFluids(recipe, new OverlayedFluidHandler(fluidOutputs), + modifiedFluidParallelAmount = limitParallelByFluids(recipe, fluidOutputs, modifiedItemParallelAmount); } @@ -120,7 +119,7 @@ public static int limitByOutputMerging(@NotNull Recipe recipe, @NotNull IItemHan * @param recipe the recipe from which we get the input to product ratio * @param multiplier the maximum possible multiplied we can get from the input inventory * see - * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, IMultipleTankHandler, int)} + * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, MultipleTankHandler, int)} * @return the amount of times a {@link Recipe} outputs can be merged into an inventory without * voiding products. */ @@ -166,7 +165,7 @@ public static int limitParallelByItems(@NotNull Recipe recipe, @NotNull Overlaye * @param outputsToAppend the recipe outputs from the recipe we want to append to the recipe we are building * @param multiplier the maximum possible multiplied we can get from the input inventory * see - * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, IMultipleTankHandler, int)} + * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, MultipleTankHandler, int)} * @return the amount of times a {@link Recipe} outputs can be merged into an inventory without * voiding products. */ @@ -253,17 +252,16 @@ public static int limitParallelByItemsIncremental(@NotNull List recip * @param recipe the recipe from which we get the fluid input to product ratio * @param multiplier the maximum possible multiplied we can get from the input tanks * see - * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, IMultipleTankHandler, int)} + * {@link ParallelLogic#getMaxRecipeMultiplier(Recipe, IItemHandlerModifiable, MultipleTankHandler, int)} * @return the amount of times a {@link Recipe} outputs can be merged into a fluid handler without * voiding products. */ public static int limitParallelByFluids(@NotNull Recipe recipe, - @NotNull OverlayedFluidHandler overlayedFluidHandler, int multiplier) { + @NotNull MultipleTankHandler tankHandler, int multiplier) { int minMultiplier = 0; int maxMultiplier = multiplier; while (minMultiplier != maxMultiplier) { - overlayedFluidHandler.reset(); int amountLeft = 0; @@ -275,7 +273,7 @@ public static int limitParallelByFluids(@NotNull Recipe recipe, } else { amountLeft = fluidStack.amount * multiplier; } - int inserted = overlayedFluidHandler.insertFluid(fluidStack, amountLeft); + int inserted = tankHandler.simulateFill(fluidStack, amountLeft); if (inserted > 0) { amountLeft -= inserted; } @@ -476,9 +474,9 @@ protected static int getMaxRatioFluid(@NotNull Map countFluid // take care of voiding public static RecipeBuilder doParallelRecipes(@NotNull Recipe currentRecipe, @NotNull RecipeMap recipeMap, @NotNull IItemHandlerModifiable importInventory, - @NotNull IMultipleTankHandler importFluids, + @NotNull MultipleTankHandler importFluids, @NotNull IItemHandlerModifiable exportInventory, - @NotNull IMultipleTankHandler exportFluids, int parallelAmount, + @NotNull MultipleTankHandler exportFluids, int parallelAmount, long maxVoltage, @NotNull IVoidable voidable) { // First check if we are limited by recipe inputs. This can short circuit a lot of consecutive checking int multiplierByInputs = getMaxRecipeMultiplier(currentRecipe, importInventory, importFluids, parallelAmount); diff --git a/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java b/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java index a6d66d3e62e..42f61345e63 100644 --- a/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java +++ b/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java @@ -192,7 +192,7 @@ protected void addInventorySlotGroup(@NotNull ModularUI.Builder builder, @NotNull IItemHandlerModifiable itemHandler, @NotNull FluidTankList fluidHandler, boolean isOutputs, int yOffset) { int itemInputsCount = itemHandler.getSlots(); - int fluidInputsCount = fluidHandler.getTanks(); + int fluidInputsCount = fluidHandler.size(); boolean invertFluids = false; if (itemInputsCount == 0) { int tmp = itemInputsCount; @@ -205,9 +205,9 @@ protected void addInventorySlotGroup(@NotNull ModularUI.Builder builder, int itemSlotsToDown = inputSlotGrid[1]; int startInputsX = isOutputs ? 106 : 70 - itemSlotsToLeft * 18; int startInputsY = 33 - (int) (itemSlotsToDown / 2.0 * 18) + yOffset; - boolean wasGroup = itemHandler.getSlots() + fluidHandler.getTanks() == 12; + boolean wasGroup = itemHandler.getSlots() + fluidHandler.size() == 12; if (wasGroup) startInputsY -= 9; - else if (itemHandler.getSlots() >= 6 && fluidHandler.getTanks() >= 2 && !isOutputs) startInputsY -= 9; + else if (itemHandler.getSlots() >= 6 && fluidHandler.size() >= 2 && !isOutputs) startInputsY -= 9; for (int i = 0; i < itemSlotsToDown; i++) { for (int j = 0; j < itemSlotsToLeft; j++) { int slotIndex = i * itemSlotsToLeft + j; @@ -256,7 +256,7 @@ protected void addSlot(ModularUI.Builder builder, int x, int y, int slotIndex, I getOverlaysForSlot(isOutputs, false, slotIndex == itemHandler.getSlots() - 1))); } else { builder.widget(new TankWidget(fluidHandler.getTankAt(slotIndex), x, y, 18, 18).setAlwaysShowFull(true) - .setBackgroundTexture(getOverlaysForSlot(isOutputs, true, slotIndex == fluidHandler.getTanks() - 1)) + .setBackgroundTexture(getOverlaysForSlot(isOutputs, true, slotIndex == fluidHandler.size() - 1)) .setContainerClicking(true, !isOutputs)); } } diff --git a/src/main/java/gregtech/api/recipes/ui/impl/DistillationTowerUI.java b/src/main/java/gregtech/api/recipes/ui/impl/DistillationTowerUI.java index e11f636fe6a..227914218ad 100644 --- a/src/main/java/gregtech/api/recipes/ui/impl/DistillationTowerUI.java +++ b/src/main/java/gregtech/api/recipes/ui/impl/DistillationTowerUI.java @@ -67,7 +67,7 @@ protected void addInventorySlotGroup(@NotNull ModularUI.Builder builder, @NotNull IItemHandlerModifiable itemHandler, @NotNull FluidTankList fluidHandler, boolean isOutputs, int yOffset) { int itemInputsCount = itemHandler.getSlots(); - int fluidInputsCount = fluidHandler.getTanks(); + int fluidInputsCount = fluidHandler.size(); boolean invertFluids = false; if (itemInputsCount == 0) { int tmp = itemInputsCount; @@ -80,9 +80,9 @@ protected void addInventorySlotGroup(@NotNull ModularUI.Builder builder, int itemSlotsToDown = inputSlotGrid[1]; int startInputsX = isOutputs ? 104 : 68 - itemSlotsToLeft * 18; int startInputsY = 55 - (int) (itemSlotsToDown / 2.0 * 18) + yOffset; - boolean wasGroupOutput = itemHandler.getSlots() + fluidHandler.getTanks() == 12; + boolean wasGroupOutput = itemHandler.getSlots() + fluidHandler.size() == 12; if (wasGroupOutput && isOutputs) startInputsY -= 9; - if (itemHandler.getSlots() == 6 && fluidHandler.getTanks() == 2 && !isOutputs) startInputsY -= 9; + if (itemHandler.getSlots() == 6 && fluidHandler.size() == 2 && !isOutputs) startInputsY -= 9; if (!isOutputs) { addSlot(builder, 40, startInputsY + (itemSlotsToDown - 1) * 18 - 18, 0, itemHandler, fluidHandler, invertFluids, false); diff --git a/src/main/java/gregtech/api/util/GTTransferUtils.java b/src/main/java/gregtech/api/util/GTTransferUtils.java index d79024f844b..651128764b8 100644 --- a/src/main/java/gregtech/api/util/GTTransferUtils.java +++ b/src/main/java/gregtech/api/util/GTTransferUtils.java @@ -1,6 +1,6 @@ package gregtech.api.util; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidActionResult; @@ -135,26 +135,24 @@ public static boolean addItemsToItemHandler(final IItemHandler handler, } /** - * Simulates the insertion of fluid into a target fluid handler, then optionally performs the insertion. - *
- *
+ * Simulates the insertion of fluid into a target fluid handler, then optionally performs the insertion.
+ *
* Simulating will not modify any of the input parameters. Insertion will either succeed completely, or fail - * without modifying anything. - * This method should be called with {@code simulate} {@code true} first, then {@code simulate} {@code false}, - * only if it returned {@code true}. + * without modifying anything. This method should be called with {@code simulate} {@code true} first, then + * {@code simulate} {@code false}, only if it returned {@code true}. * + * @param fluidStacks the items to insert into {@code fluidHandler}. * @param fluidHandler the target inventory * @param simulate whether to simulate ({@code true}) or actually perform the insertion ({@code false}) - * @param fluidStacks the items to insert into {@code fluidHandler}. * @return {@code true} if the insertion succeeded, {@code false} otherwise. */ - public static boolean addFluidsToFluidHandler(IMultipleTankHandler fluidHandler, - boolean simulate, - List fluidStacks) { + public static boolean addFluidsToFluidHandler(List fluidStacks, + MultipleTankHandler fluidHandler, + boolean simulate) { if (simulate) { - OverlayedFluidHandler overlayedFluidHandler = new OverlayedFluidHandler(fluidHandler); for (FluidStack fluidStack : fluidStacks) { - int inserted = overlayedFluidHandler.insertFluid(fluidStack, fluidStack.amount); + int inserted = fluidHandler.fill(fluidStack, false); if (inserted != fluidStack.amount) { return false; } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 39b4a6a0d65..b6fc5f55f84 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -3,7 +3,7 @@ import gregtech.api.GTValues; import gregtech.api.GregTechAPI; import gregtech.api.block.machines.MachineItemBlock; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.cover.CoverDefinition; import gregtech.api.fluids.GTFluid; import gregtech.api.gui.widgets.ProgressWidget; @@ -431,8 +431,8 @@ public int size() { * @return a list of fluidstack linked with given fluid handler * modifications in list will reflect on fluid handler and wise-versa */ - public static List fluidHandlerToList(IMultipleTankHandler fluidInputs) { - List backedList = fluidInputs.getFluidTanks(); + public static List fluidHandlerToList(MultipleTankHandler fluidInputs) { + 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..5240a8c0390 100644 --- a/src/main/java/gregtech/api/util/OverlayedFluidHandler.java +++ b/src/main/java/gregtech/api/util/OverlayedFluidHandler.java @@ -1,11 +1,12 @@ package gregtech.api.util; -import gregtech.api.capability.IMultipleTankHandler; -import gregtech.api.capability.IMultipleTankHandler.MultiFluidTankEntry; +import gregtech.api.capability.MultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler.Entry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidTankProperties; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,20 +15,20 @@ import java.util.List; /** - * Simulates consecutive fills to {@link IMultipleTankHandler} instance. + * Simulates consecutive fills to {@link MultipleTankHandler} instance. */ +@Deprecated +@ApiStatus.ScheduledForRemoval(inVersion = "2.9") public class OverlayedFluidHandler { private final List overlayedTanks; - public OverlayedFluidHandler(@NotNull IMultipleTankHandler tank) { + public OverlayedFluidHandler(@NotNull MultipleTankHandler tank) { this.overlayedTanks = new ArrayList<>(); - MultiFluidTankEntry[] entries = tank.getFluidTanks().toArray(new MultiFluidTankEntry[0]); - Arrays.sort(entries, IMultipleTankHandler.ENTRY_COMPARATOR); - for (MultiFluidTankEntry fluidTank : entries) { - for (IFluidTankProperties property : fluidTank.getTankProperties()) { - this.overlayedTanks.add(new OverlayedTank(property, fluidTank.allowSameFluidFill())); - } + Entry[] entries = tank.getFluidTanks().toArray(new Entry[0]); + Arrays.sort(entries, MultipleTankHandler.ENTRY_COMPARATOR); + for (Entry fluidTank : entries) { + this.overlayedTanks.add(new OverlayedTank(fluidTank, fluidTank.allowSameFluidFill())); } } diff --git a/src/main/java/gregtech/common/covers/CoverDigitalInterface.java b/src/main/java/gregtech/common/covers/CoverDigitalInterface.java index 0063a113faa..e46930a1de2 100644 --- a/src/main/java/gregtech/common/covers/CoverDigitalInterface.java +++ b/src/main/java/gregtech/common/covers/CoverDigitalInterface.java @@ -321,7 +321,7 @@ public void update() { int maxSlotLimit = Integer.MAX_VALUE; if (this.getCoverableView() instanceof MetaTileEntity metaTileEntity) { maxSlotLimit = this.mode == MODE.ITEM ? metaTileEntity.getImportItems().getSlots() : - metaTileEntity.getImportFluids().getTanks(); + metaTileEntity.getImportFluids().size(); } double x = 0; double y = 1 - rayTraceResult.hitVec.y + rayTraceResult.getBlockPos().getY(); diff --git a/src/main/java/gregtech/common/items/behaviors/TricorderBehavior.java b/src/main/java/gregtech/common/items/behaviors/TricorderBehavior.java index 1045603125a..acc62ae0267 100644 --- a/src/main/java/gregtech/common/items/behaviors/TricorderBehavior.java +++ b/src/main/java/gregtech/common/items/behaviors/TricorderBehavior.java @@ -298,7 +298,7 @@ else if (metaTileEntity instanceof IDataInfoProvider) list.add(new TextComponentTranslation("behavior.tricorder.quantum_controller.connected_items", TextFormatting.RED.toString() + handler.getItemHandlers().getSlots())); list.add(new TextComponentTranslation("behavior.tricorder.quantum_controller.connected_fluids", - TextFormatting.RED.toString() + handler.getFluidTanks().getTanks())); + TextFormatting.RED.toString() + handler.getFluidTanks().size())); } else if (metaTileEntity instanceof IQuantumStoragestorage) { var qcontrollor = storage.getQuantumController(); if (qcontrollor != null) { diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityDistillationTower.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityDistillationTower.java index 2c7eea8410a..96d9ebee784 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityDistillationTower.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityDistillationTower.java @@ -1,7 +1,7 @@ package gregtech.common.metatileentities.multi.electric; import gregtech.api.capability.IDistillationTower; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.DistillationTowerLogicHandler; import gregtech.api.capability.impl.MultiblockRecipeLogic; import gregtech.api.metatileentity.MetaTileEntity; @@ -180,7 +180,7 @@ protected void outputRecipeOutputs() { } @Override - protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMultipleTankHandler exportFluids) { + protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull MultipleTankHandler exportFluids) { // We have already trimmed fluid outputs at this time if (!metaTileEntity.canVoidRecipeFluidOutputs() && !handler.applyFluidToOutputs(recipe.getAllFluidOutputs(), false)) { @@ -191,7 +191,7 @@ protected boolean checkOutputSpaceFluids(@NotNull Recipe recipe, @NotNull IMulti } @Override - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { return handler.getFluidTanks(); } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java index dca07a39e5f..882d9e1acfd 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFluidDrill.java @@ -3,8 +3,8 @@ import gregtech.api.GTValues; import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IEnergyContainer; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.IWorkable; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.EnergyContainerList; import gregtech.api.capability.impl.FluidDrillLogic; import gregtech.api.capability.impl.FluidTankList; @@ -61,8 +61,8 @@ public class MetaTileEntityFluidDrill extends MultiblockWithDisplayBase private final FluidDrillLogic minerLogic; private final int tier; - protected IMultipleTankHandler inputFluidInventory; - protected IMultipleTankHandler outputFluidInventory; + protected MultipleTankHandler inputFluidInventory; + protected MultipleTankHandler outputFluidInventory; protected IEnergyContainer energyContainer; public MetaTileEntityFluidDrill(ResourceLocation metaTileEntityId, int tier) { @@ -287,8 +287,8 @@ public void setWorkingEnabled(boolean isActivationAllowed) { } public boolean fillTanks(FluidStack stack, boolean simulate) { - return GTTransferUtils.addFluidsToFluidHandler(outputFluidInventory, simulate, - Collections.singletonList(stack)); + return GTTransferUtils.addFluidsToFluidHandler(Collections.singletonList(stack), outputFluidInventory, + simulate); } public int getEnergyTier() { diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java index cc2b78fa6ba..98305ada7e0 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityLargeMiner.java @@ -75,7 +75,7 @@ public class MetaTileEntityLargeMiner extends MultiblockWithDisplayBase private final int tier; private IEnergyContainer energyContainer; - protected IMultipleTankHandler inputFluidInventory; + protected MultipleTankHandler inputFluidInventory; protected IItemHandlerModifiable outputInventory; private boolean silkTouch = false; diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java index 4759bb1dec7..40371933cc7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java @@ -1,7 +1,7 @@ package gregtech.common.metatileentities.multi.electric; import gregtech.api.GTValues; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.AbstractRecipeLogic; import gregtech.api.capability.impl.MultiblockRecipeLogic; import gregtech.api.metatileentity.IMachineHatchMultiblock; @@ -387,7 +387,7 @@ public int getParallelLimit() { } @Override - protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) { + protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, MultipleTankHandler fluidInputs) { return super.findRecipe(Math.min(super.getMaxVoltage(), this.machineVoltage), inputs, fluidInputs); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java index 46edc9619e7..66b5811b53d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java @@ -1,8 +1,8 @@ package gregtech.common.metatileentities.multi.electric.generator; import gregtech.api.GTValues; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.IRotorHolder; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.MultiblockFuelRecipeLogic; import gregtech.api.metatileentity.multiblock.FuelMultiblockController; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -16,7 +16,6 @@ import net.minecraft.util.math.MathHelper; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.NotNull; @@ -113,7 +112,7 @@ protected boolean checkPreviousRecipe() { @Override protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, - IMultipleTankHandler fluidInputs) { + MultipleTankHandler fluidInputs) { RecipeMap map = getRecipeMap(); if (map == null || !isRecipeMapValid(map)) { return null; @@ -183,9 +182,7 @@ public void invalidate() { public void updateTanks() { FuelMultiblockController controller = (FuelMultiblockController) this.metaTileEntity; - List tanks = controller.getNotifiedFluidInputList(); - for (IFluidTank tank : controller.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) { - tanks.add((IFluidHandler) tank); - } + List tanks = controller.getNotifiedFluidInputList(); + tanks.addAll(controller.getAbilities(MultiblockAbility.IMPORT_FLUIDS)); } } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/MetaTileEntityLargeCombustionEngine.java b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/MetaTileEntityLargeCombustionEngine.java index 5bdd31eafc8..20e772e3542 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/MetaTileEntityLargeCombustionEngine.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/MetaTileEntityLargeCombustionEngine.java @@ -3,7 +3,7 @@ import gregtech.api.GTValues; import gregtech.api.capability.GregtechCapabilities; import gregtech.api.capability.IEnergyContainer; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.MultiblockFuelRecipeLogic; import gregtech.api.fluids.store.FluidStorageKeys; import gregtech.api.gui.GuiTextures; @@ -364,7 +364,7 @@ protected void updateRecipeProgress() { protected void checkOxygen() { // check oxygen if present to boost production, and if the dynamo hatch supports it if (combustionEngine.isBoostAllowed()) { - IMultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); + MultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); FluidStack boosterStack = isExtreme ? LIQUID_OXYGEN_STACK : OXYGEN_STACK; isOxygenBoosted = boosterStack.isFluidStackIdentical(inputTank.drain(boosterStack, false)); } @@ -379,7 +379,7 @@ protected void drainOxygen() { protected boolean checkLubricant() { // check lubricant and invalidate if it fails - IMultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); + MultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); if (LUBRICANT_STACK.isFluidStackIdentical(inputTank.drain(LUBRICANT_STACK, false))) { return true; } else { @@ -390,7 +390,7 @@ protected boolean checkLubricant() { protected void drainLubricant() { if (totalContinuousRunningTime == 1 || totalContinuousRunningTime % 72 == 0) { - IMultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); + MultipleTankHandler inputTank = combustionEngine.getInputFluidInventory(); inputTank.drain(LUBRICANT_STACK, true); } } 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 8cf7c4f2e6a..70f08d120e5 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityFluidHatch.java @@ -339,10 +339,11 @@ private void setLocked(boolean locked) { fluidTank.onContentsChanged(); } - protected class HatchFluidTank extends NotifiableFluidTank implements IFilteredFluidContainer, IFilter { + protected class HatchFluidTank extends NotifiableFluidTank implements IFilter { public HatchFluidTank(int capacity, MetaTileEntity entityToNotify, boolean isExport) { super(capacity, entityToNotify, isExport); + setFilter(this); } @Override @@ -356,23 +357,12 @@ public int fillInternal(FluidStack resource, boolean doFill) { return accepted; } - @Override - public boolean canFillFluidType(FluidStack fluid) { - return test(fluid); - } - // override for visibility @Override public void onContentsChanged() { super.onContentsChanged(); } - @Nullable - @Override - public IFilter getFilter() { - return this; - } - @Override public boolean test(@NotNull FluidStack fluidStack) { if (!isExportHatch) return true; @@ -382,7 +372,8 @@ public boolean test(@NotNull FluidStack fluidStack) { @Override public int getPriority() { if (!isExportHatch) return IFilter.noPriority(); - return !locked || lockedFluid == null ? IFilter.noPriority() : IFilter.whitelistPriority(1); + return !locked || lockedFluid == null ? IFilter.noPriority() : + IFilter.whitelistPriority(1); } } } 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..b147a909e7d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMultiblockNotifiablePart.java @@ -1,7 +1,7 @@ package gregtech.common.metatileentities.multi.multiblockpart; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.capability.INotifiableHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.NotifiableItemStackHandler; import gregtech.api.metatileentity.multiblock.MultiblockControllerBase; @@ -55,7 +55,7 @@ private List getPartHandlers() { FluidTankList fluidTankList = getFluidHandlers(); if (fluidTankList != null) { for (IFluidTank fluidTank : fluidTankList) { - if (fluidTank instanceof IMultipleTankHandler.MultiFluidTankEntry entry) { + if (fluidTank instanceof MultipleTankHandler.Entry entry) { fluidTank = entry.getDelegate(); } if (fluidTank instanceof INotifiableHandler) { diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityBuffer.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityBuffer.java index 1ecb31c1821..da4811c0dea 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityBuffer.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityBuffer.java @@ -76,7 +76,7 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { int invTier = tier + 2; ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, Math.max(166, 18 + 18 * invTier + 94));// 176, 166 - for (int i = 0; i < this.fluidTankList.getTanks(); i++) { + for (int i = 0; i < this.fluidTankList.size(); i++) { builder.widget(new TankWidget(this.fluidTankList.getTankAt(i), 176 - 8 - 18, 18 + 18 * i, 18, 18) .setAlwaysShowFull(true) .setBackgroundTexture(GuiTextures.FLUID_SLOT) diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java index c4431e902a9..444b9b5fbf9 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java @@ -492,7 +492,7 @@ private void rebuildCache() { @Override public boolean hasFluidTanks() { - return getFluidTanks().getTanks() > 0; + return getFluidTanks().size() > 0; } @Override diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java index 0d675b9b1c9..8e52afeb07d 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumTank.java @@ -1,9 +1,6 @@ package gregtech.common.metatileentities.storage; -import gregtech.api.capability.GregtechTileCapabilities; -import gregtech.api.capability.IActiveOutputSide; -import gregtech.api.capability.IFilter; -import gregtech.api.capability.IFilteredFluidContainer; +import gregtech.api.capability.*; import gregtech.api.capability.impl.FilteredItemHandler; import gregtech.api.capability.impl.FluidHandlerProxy; import gregtech.api.capability.impl.FluidTankList; diff --git a/src/main/java/gregtech/integration/opencomputers/drivers/DriverRecipeMapMultiblockController.java b/src/main/java/gregtech/integration/opencomputers/drivers/DriverRecipeMapMultiblockController.java index 7db4e9bd232..1a81c354dad 100644 --- a/src/main/java/gregtech/integration/opencomputers/drivers/DriverRecipeMapMultiblockController.java +++ b/src/main/java/gregtech/integration/opencomputers/drivers/DriverRecipeMapMultiblockController.java @@ -1,7 +1,7 @@ package gregtech.integration.opencomputers.drivers; import gregtech.api.capability.GregtechTileCapabilities; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.MultiblockRecipeLogic; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; @@ -126,7 +126,7 @@ public Object[] getOutputInventory(final Context context, final Arguments args) } @NotNull - private Object[] getTank(IMultipleTankHandler handler) { + private Object[] getTank(MultipleTankHandler handler) { List> result = new ArrayList<>(); handler.getFluidTanks().forEach(tank -> { Map map = new Object2ObjectOpenHashMap<>(); diff --git a/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java b/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java index a734933b9fe..a5307f4e154 100644 --- a/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java +++ b/src/test/java/gregtech/api/capability/impl/FluidTankListTest.java @@ -1,9 +1,7 @@ package gregtech.api.capability.impl; import gregtech.Bootstrap; -import gregtech.api.capability.IMultipleTankHandler; import gregtech.api.unification.material.Materials; -import gregtech.api.util.OverlayedFluidHandler; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -314,9 +312,6 @@ private static final class FluidHandlerTester { private final FluidTankList tank; - @Nullable - private OverlayedFluidHandler overlayedFluidHandler; - FluidHandlerTester(FluidTankList tank) { this.tank = tank; } @@ -334,19 +329,8 @@ FluidHandlerTester fill(FluidStack fluidStack) { String tankString = this.tank.toString(true); int tankFillSim = this.tank.fill(fluidStack, false); - - if (this.overlayedFluidHandler != null) { - String overlayString = this.overlayedFluidHandler.toString(true); - int ofhSim = this.overlayedFluidHandler.insertFluid(fluidStack, fluidStack.amount); - - if (tankFillSim != ofhSim) { - throw new AssertionError("Result of simulation fill from tank and OFH differ.\n" + - "Tank Simulation: " + tankFillSim + ", OFH simulation: " + ofhSim + "\n" + - "Tank: " + tankString + "\n" + - "OFH: " + overlayString); - } - } int actualFill = this.tank.fill(fluidStack, true); + if (tankFillSim != actualFill) { throw new AssertionError("Simulation fill to tank and actual fill differ.\n" + "Simulated Fill: " + tankFillSim + ", Actual Fill: " + actualFill + "\n" + @@ -360,9 +344,6 @@ FluidHandlerTester drain(Fluid fluid, int amount) { } FluidHandlerTester drain(FluidStack fluidStack) { - if (this.overlayedFluidHandler != null) { - throw new IllegalStateException("Cannot drain stuff in simulation"); - } // make string representation before modifying the state, to produce better error message String tankString = this.tank.toString(true); @@ -378,9 +359,6 @@ FluidHandlerTester drain(FluidStack fluidStack) { } FluidHandlerTester drain(int amount) { - if (this.overlayedFluidHandler != null) { - throw new IllegalStateException("Cannot drain stuff in simulation"); - } // make string representation before modifying the state, to produce better error message String tankString = this.tank.toString(true); @@ -396,20 +374,16 @@ FluidHandlerTester drain(int amount) { } FluidHandlerTester beginSimulation() { - if (this.overlayedFluidHandler != null) { - throw new IllegalStateException("Simulation already begun"); - } - this.overlayedFluidHandler = new OverlayedFluidHandler(this.tank); return this; } FluidHandlerTester expectContents(@NotNull FluidStack... optionalFluidStacks) { - if (optionalFluidStacks.length != this.tank.getTanks()) { + if (optionalFluidStacks.length != this.tank.size()) { throw new IllegalArgumentException("Wrong number of fluids to compare; " + - "expected: " + this.tank.getTanks() + ", provided: " + optionalFluidStacks.length); + "expected: " + this.tank.size() + ", 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) diff --git a/src/test/java/gregtech/api/capability/impl/MultiblockRecipeLogicTest.java b/src/test/java/gregtech/api/capability/impl/MultiblockRecipeLogicTest.java index 47c4287aef1..471605c4f68 100644 --- a/src/test/java/gregtech/api/capability/impl/MultiblockRecipeLogicTest.java +++ b/src/test/java/gregtech/api/capability/impl/MultiblockRecipeLogicTest.java @@ -1,7 +1,7 @@ package gregtech.api.capability.impl; import gregtech.Bootstrap; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.MetaTileEntityHolder; import gregtech.api.metatileentity.multiblock.MultiblockAbility; @@ -216,12 +216,12 @@ protected IItemHandlerModifiable getOutputInventory() { } @Override - protected IMultipleTankHandler getInputTank() { + protected MultipleTankHandler getInputTank() { return importFluidBus.getImportFluids(); } @Override - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { return importFluidBus.getExportFluids(); } }; @@ -463,12 +463,12 @@ protected IItemHandlerModifiable getOutputInventory() { } @Override - protected IMultipleTankHandler getInputTank() { + protected MultipleTankHandler getInputTank() { return importFluidBus.getImportFluids(); } @Override - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { return importFluidBus.getExportFluids(); } @@ -690,12 +690,12 @@ protected IItemHandlerModifiable getOutputInventory() { } @Override - protected IMultipleTankHandler getInputTank() { + protected MultipleTankHandler getInputTank() { return new FluidTankList(false); } @Override - protected IMultipleTankHandler getOutputTank() { + protected MultipleTankHandler getOutputTank() { return new FluidTankList(false); } diff --git a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java index 882d9287e6a..bd8a49db015 100644 --- a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java +++ b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java @@ -1,7 +1,7 @@ package gregtech.api.recipes.logic; import gregtech.Bootstrap; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.MultiblockRecipeLogic; import gregtech.api.metatileentity.MetaTileEntity; @@ -335,7 +335,7 @@ public void findMultipliedRecipe_FluidOnlyMaxParallelTest() { importFluidBus.getImportFluids().fill(Materials.Toluene.getFluid(4000), true); secondImportFluidBus.getImportFluids().fill(Materials.RawGasoline.getFluid(50000), true); - IMultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), + MultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), secondImportFluidBus.getImportFluids().getTankAt(0)); RecipeBuilder parallelRecipe = logic.findMultipliedParallelRecipe(map, recipe, @@ -388,7 +388,7 @@ public void findMultipliedRecipe_FluidOnlyLessThanMaxParallelTest() { importFluidBus.getImportFluids().fill(Materials.Toluene.getFluid(2000), true); secondImportFluidBus.getImportFluids().fill(Materials.RawGasoline.getFluid(50000), true); - IMultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), + MultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), secondImportFluidBus.getImportFluids().getTankAt(0)); RecipeBuilder parallelRecipe = logic.findMultipliedParallelRecipe(map, recipe, diff --git a/src/test/java/gregtech/api/recipes/logic/ParallelLogicTest.java b/src/test/java/gregtech/api/recipes/logic/ParallelLogicTest.java index 0b1de7c397a..256512311a4 100644 --- a/src/test/java/gregtech/api/recipes/logic/ParallelLogicTest.java +++ b/src/test/java/gregtech/api/recipes/logic/ParallelLogicTest.java @@ -2,7 +2,7 @@ import gregtech.Bootstrap; import gregtech.api.GTValues; -import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.MultipleTankHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; @@ -11,7 +11,6 @@ import gregtech.api.recipes.builders.BlastRecipeBuilder; import gregtech.api.unification.material.Materials; import gregtech.api.util.GTHashMaps; -import gregtech.api.util.OverlayedFluidHandler; import gregtech.api.util.OverlayedItemHandler; import gregtech.common.metatileentities.MetaTileEntities; import gregtech.common.metatileentities.electric.SimpleMachineMetaTileEntityResizable; @@ -31,6 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; +@SuppressWarnings("DataFlowIssue") public class ParallelLogicTest { MetaTileEntityItemBus importItemBus = new MetaTileEntityItemBus(gregtechId("item_bus.export.lv"), 1, false); @@ -364,7 +364,7 @@ public void limitParallelByFluids_MaxParallelTest() { importItemBus.getImportItems().insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false); int itemRatio = ParallelLogic.limitParallelByFluids(recipe, - new OverlayedFluidHandler(exportFluidBus.getExportFluids()), parallelLimit); + exportFluidBus.getExportFluids(), parallelLimit); assertThat(itemRatio, is(4)); } @@ -395,7 +395,7 @@ public void limitParallelByFluids_PartialParallelsTest() { exportFluidBus.getExportFluids().fill(Materials.Acetone.getFluid(15800), true); int itemRatio = ParallelLogic.limitParallelByFluids(recipe, - new OverlayedFluidHandler(exportFluidBus.getExportFluids()), parallelLimit); + exportFluidBus.getExportFluids(), parallelLimit); assertThat(itemRatio, is(2)); } @@ -426,7 +426,7 @@ public void limitParallelByFluids_FluidOutputFullTest() { exportFluidBus.getExportFluids().fill(Materials.Acetone.getFluid(16000), true); int itemRatio = ParallelLogic.limitParallelByFluids(recipe, - new OverlayedFluidHandler(exportFluidBus.getExportFluids()), parallelLimit); + exportFluidBus.getExportFluids(), parallelLimit); assertThat(itemRatio, is(0)); } @@ -726,7 +726,7 @@ public void getMaxRatioFluid_DifferentNonConsumedTest() { importFluidBus.getImportFluids().fill(Materials.Water.getFluid(1000), true); secondImportFluidBus.getImportFluids().fill(Materials.Acetone.getFluid(1), true); - IMultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), + MultipleTankHandler tankHandler = new FluidTankList(false, importFluidBus.getImportFluids().getTankAt(0), secondImportFluidBus.getImportFluids().getTankAt(0)); int fluidRatio = ParallelLogic.getMaxRatioFluid(GTHashMaps.fromFluidHandler(tankHandler),