From 2a908960a51412eaf14d0888442133ddf8b17258 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:48:53 -0400 Subject: [PATCH 01/22] Switched from LDLib FluidStack to Forge FluidStack --- .../blockentity/MetaMachineBlockEntity.java | 15 ++- .../gtceu/api/capability/ICoverable.java | 4 +- .../api/capability/IPropertyFluidFilter.java | 12 +-- .../IThermalFluidHandlerItemStack.java | 12 +-- .../recipe/FluidRecipeCapability.java | 76 +++++++-------- .../gtceu/api/cover/CoverBehavior.java | 4 +- .../api/cover/filter/FilterHandlers.java | 2 +- .../gtceu/api/cover/filter/FluidFilter.java | 8 +- .../api/cover/filter/SimpleFluidFilter.java | 32 +++---- .../api/cover/filter/TagFluidFilter.java | 7 +- .../api/data/chemical/material/Material.java | 19 ++-- .../properties/FluidPipeProperties.java | 12 +-- .../gtceu/api/gui/misc/IGhostFluidTarget.java | 10 +- .../gtceu/api/gui/misc/ProspectorMode.java | 14 +-- .../widget/ScrollablePhantomFluidWidget.java | 27 +++--- .../gtceu/api/item/GTBucketItem.java | 7 +- .../component/FilteredFluidContainer.java | 14 +-- .../api/item/component/ThermalFluidStats.java | 13 +-- .../api/machine/MachineCoverContainer.java | 4 +- .../gtceu/api/machine/MetaMachine.java | 11 ++- .../api/machine/SimpleGeneratorMachine.java | 6 +- .../api/machine/SimpleTieredMachine.java | 9 +- .../api/machine/WorkableTieredMachine.java | 6 +- .../FancyTankConfigurator.java | 8 +- .../api/machine/steam/SimpleSteamMachine.java | 6 +- .../api/machine/steam/SteamBoilerMachine.java | 30 +++--- .../steam/SteamEnergyRecipeHandler.java | 10 +- .../gtceu/api/misc/FluidRecipeHandler.java | 17 ++-- .../forge/FilteredFluidHandlerItemStack.java | 10 +- .../SimpleThermalFluidHandlerItemStack.java | 2 +- .../forge/ThermalFluidHandlerItemStack.java | 6 +- .../gtceu/api/pipenet/PipeCoverContainer.java | 4 +- .../gtceu/api/recipe/RecipeHelper.java | 3 +- .../content/SerializerFluidIngredient.java | 3 +- .../recipe/ingredient/FluidIngredient.java | 38 ++++---- .../api/recipe/lookup/MapFluidIngredient.java | 3 +- .../gtceu/client/TooltipsHandler.java | 4 +- .../renderer/machine/QuantumTankRenderer.java | 24 +++-- .../gtceu/common/block/FluidPipeBlock.java | 12 +-- .../blockentity/FluidPipeBlockEntity.java | 72 +++++++------- .../gtceu/common/cover/FluidFilterCover.java | 4 +- .../common/cover/FluidRegulatorCover.java | 84 ++++++++-------- .../common/cover/InfiniteWaterCover.java | 17 ++-- .../gtceu/common/cover/PumpCover.java | 95 ++++++++++--------- .../gtceu/common/cover/data/BucketMode.java | 4 +- .../detector/AdvancedFluidDetectorCover.java | 18 ++-- .../cover/detector/FluidDetectorCover.java | 18 ++-- .../voiding/AdvancedFluidVoidingCover.java | 37 ++++---- .../cover/voiding/FluidVoidingCover.java | 13 +-- .../gtceu/common/data/GTItems.java | 39 ++++---- .../gtceu/common/data/GTMachines.java | 72 +++++++------- .../gtceu/common/data/GTRecipeTypes.java | 10 +- .../gtceu/common/item/ItemFluidContainer.java | 8 +- .../common/item/armor/PowerlessJetpack.java | 40 ++++---- .../item/tool/behavior/PlungerBehavior.java | 20 ++-- .../SimpleKineticElectricWorkableMachine.java | 4 +- .../electric/AssemblyLineMachine.java | 3 +- .../electric/FusionReactorMachine.java | 9 +- .../electric/LargeMinerMachine.java | 17 ++-- .../electric/MultiblockTankMachine.java | 10 +- .../electric/research/HPCAMachine.java | 28 +++--- .../LargeCombustionEngineMachine.java | 3 +- .../multiblock/part/CokeOvenHatch.java | 5 +- .../multiblock/part/DualHatchPartMachine.java | 17 ++-- .../part/FluidHatchPartMachine.java | 30 +++--- .../multiblock/part/PumpHatchPartMachine.java | 8 +- .../part/ReservoirHatchPartMachine.java | 23 +++-- .../part/SteamHatchPartMachine.java | 8 +- .../multiblock/part/TankValvePartMachine.java | 9 +- .../multiblock/primitive/CokeOvenMachine.java | 5 +- .../primitive/PrimitivePumpMachine.java | 12 +-- .../primitive/PrimitiveWorkableMachine.java | 6 +- .../multiblock/steam/LargeBoilerMachine.java | 8 +- .../steam/SteamLiquidBoilerMachine.java | 6 +- .../machine/steam/SteamMinerMachine.java | 9 +- .../common/machine/storage/BufferMachine.java | 7 +- .../machine/storage/CreativeTankMachine.java | 29 +++--- .../common/machine/trait/FluidDrillLogic.java | 13 ++- .../trait/customlogic/CannerLogic.java | 11 +-- .../pipelike/fluidpipe/FluidPipeNet.java | 4 +- .../longdistance/LDFluidEndpointMachine.java | 41 ++++---- .../data/recipe/builder/GTRecipeBuilder.java | 2 +- .../generated/DecompositionRecipeHandler.java | 3 +- .../recipe/generated/WireRecipeHandler.java | 6 +- .../gtceu/data/recipe/misc/FuelRecipes.java | 5 +- .../gtceu/data/recipe/misc/GCyMRecipes.java | 10 +- .../data/recipe/misc/MachineRecipeLoader.java | 3 +- .../data/recipe/misc/WoodMachineRecipes.java | 4 +- .../alloyblast/AlloyBlastRecipeProducer.java | 9 +- .../gtceu/integration/GTOreByProduct.java | 15 ++- .../integration/GTOreByProductWidget.java | 19 ++-- .../gtceu/integration/GTOreVeinWidget.java | 12 ++- .../gui/widget/list/AEFluidDisplayWidget.java | 16 ++-- .../widget/slot/AEFluidConfigSlotWidget.java | 51 +++++----- .../ae2/machine/MEInputHatchPartMachine.java | 15 +-- .../ae2/machine/MEOutputHatchPartMachine.java | 37 ++++---- .../machine/MEPatternBufferPartMachine.java | 27 +++--- .../machine/MEStockingHatchPartMachine.java | 20 ++-- .../trait/MEPatternBufferRecipeHandler.java | 2 +- .../gtceu/integration/ae2/utils/AEUtil.java | 8 +- .../jade/provider/RecipeOutputProvider.java | 7 +- .../machine/KineticMachineBuilder.java | 6 +- .../machine/MachineFunctionPresets.java | 6 +- .../machine/SimpleMachineBuilder.java | 6 +- .../kjs/recipe/GTRecipeSchema.java | 2 +- .../recipe/components/GTRecipeComponents.java | 14 +-- .../top/element/FluidStackElement.java | 12 ++- .../top/provider/RecipeOutputProvider.java | 3 +- .../api/machine/trait/ParallelLogicTest.java | 14 +-- .../gtceu/utils/DummyMachineBlockEntity.java | 4 +- .../gtceu/utils/DummyRecipeLogicMachine.java | 4 +- .../com/gregtechceu/gtceu/utils/FluidKey.java | 7 +- .../gtceu/utils/FluidStackHashStrategy.java | 2 +- .../gregtechceu/gtceu/utils/GTHashMaps.java | 24 ++--- .../com/gregtechceu/gtceu/utils/GTMath.java | 4 + .../gtceu/utils/GTTransferUtils.java | 73 +++++++------- .../com/gregtechceu/gtceu/utils/GTUtil.java | 88 +++++++++++++---- .../gtceu/utils/OreDictExprFilter.java | 3 +- .../gtceu/utils/OverlayedFluidHandler.java | 37 ++++---- 119 files changed, 997 insertions(+), 963 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java index fc64c16e70..b73b80b032 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java @@ -17,12 +17,10 @@ import com.gregtechceu.gtceu.client.renderer.GTRendererProvider; import com.gregtechceu.gtceu.common.pipelike.fluidpipe.longdistance.LDFluidEndpointMachine; import com.gregtechceu.gtceu.common.pipelike.item.longdistance.LDItemEndpointMachine; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.client.renderer.IRenderer; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidTransferHelperImpl; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import com.lowdragmc.lowdraglib.side.item.forge.ItemTransferHelperImpl; import com.lowdragmc.lowdraglib.syncdata.managed.MultiManagedStorage; @@ -219,17 +217,16 @@ public static LazyOptional getCapability(MetaMachine machine, @NotNull Ca ILDEndpoint endpoint = fluidEndpointMachine.getLink(); if (endpoint == null) return null; Direction outputFacing = fluidEndpointMachine.getOutputFacing(); - IFluidTransfer transfer = FluidTransferHelper.getFluidTransfer(machine.getLevel(), - endpoint.getPos().relative(outputFacing), outputFacing.getOpposite()); - if (transfer != null) { - return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, LazyOptional.of(() -> FluidTransferHelperImpl - .toFluidHandler(new LDFluidEndpointMachine.FluidHandlerWrapper(transfer)))); + var h = GTUtil.getAdjacentFluidHandler(machine.getLevel(), endpoint.getPos(), outputFacing) + .map(LDFluidEndpointMachine.FluidHandlerWrapper::new); + if (h.isPresent()) { + return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, LazyOptional.of(h::get)); } } var transfer = machine.getFluidTransferCap(side, true); if (transfer != null) { return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, - LazyOptional.of(() -> FluidTransferHelperImpl.toFluidHandler(transfer))); + LazyOptional.of(() -> transfer)); } } else if (cap == ForgeCapabilities.ENERGY) { if (machine instanceof IEnergyStorage energyStorage) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java b/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java index f621ef1d77..5ebc0eddcc 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java @@ -4,10 +4,10 @@ import com.gregtechceu.gtceu.api.blockentity.ITickSubscription; import com.gregtechceu.gtceu.api.cover.CoverBehavior; import com.gregtechceu.gtceu.api.cover.CoverDefinition; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.LDLib; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import net.minecraft.core.BlockPos; @@ -61,7 +61,7 @@ public interface ICoverable extends ITickSubscription, IAppearance { IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCoverCapability); - IFluidTransfer getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability); + IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability); /** * Its an internal method, you should never call it yourself. diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/IPropertyFluidFilter.java b/src/main/java/com/gregtechceu/gtceu/api/capability/IPropertyFluidFilter.java index f8487a52a9..59642e443a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/IPropertyFluidFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/IPropertyFluidFilter.java @@ -6,11 +6,10 @@ import com.gregtechceu.gtceu.utils.FormattingUtil; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.network.chat.Component; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnmodifiableView; @@ -26,7 +25,8 @@ public interface IPropertyFluidFilter extends Predicate { @Override default boolean test(@NotNull FluidStack stack) { Fluid fluid = stack.getFluid(); - if (FluidHelper.getTemperature(stack) < CRYOGENIC_FLUID_THRESHOLD && !isCryoProof()) return false; + FluidType fluidType = fluid.getFluidType(); + if (fluidType.getTemperature() < CRYOGENIC_FLUID_THRESHOLD && !isCryoProof()) return false; if (fluid instanceof IAttributedFluid attributedFluid) { FluidState state = attributedFluid.getState(); @@ -41,7 +41,7 @@ default boolean test(@NotNull FluidStack stack) { // plasma ignores temperature requirements if (state == FluidState.PLASMA) return true; } else { - if (FluidHelper.isLighterThanAir(stack) && !canContain(FluidState.GAS)) { + if (fluidType.isLighterThanAir() && !canContain(FluidState.GAS)) { return false; } if (!canContain(FluidState.LIQUID)) { @@ -49,7 +49,7 @@ default boolean test(@NotNull FluidStack stack) { } } - return FluidHelper.getTemperature(stack) <= getMaxFluidTemperature(); + return fluidType.getTemperature() <= getMaxFluidTemperature(); } /** diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/IThermalFluidHandlerItemStack.java b/src/main/java/com/gregtechceu/gtceu/api/capability/IThermalFluidHandlerItemStack.java index d1d397519f..79fde0ad45 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/IThermalFluidHandlerItemStack.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/IThermalFluidHandlerItemStack.java @@ -4,10 +4,8 @@ import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttributes; import com.gregtechceu.gtceu.api.fluids.attribute.IAttributedFluid; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - -import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; /** * Interface for FluidHandlerItemStacks which handle GT's unique fluid mechanics @@ -26,12 +24,12 @@ public interface IThermalFluidHandlerItemStack { default boolean canFillFluidType(FluidStack stack) { if (stack == null || stack.getFluid() == null) return false; - Fluid fluid = stack.getFluid(); - var temp = FluidHelper.getTemperature(stack); + FluidType fluidType = stack.getFluid().getFluidType(); + var temp = fluidType.getTemperature(); if (temp > getMaxFluidTemperature()) return false; // fluids less than 120K are cryogenic if (temp < 120 && !isCryoProof()) return false; - if (FluidHelper.isLighterThanAir(stack) && !isGasProof()) return false; + if (fluidType.isLighterThanAir() && !isGasProof()) return false; // TODO custom fluid // for (RegistryEntry entry : GTRegistries.REGISTRATE.getAll(Registry.FLUID_REGISTRY)) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java index 9411da91bf..90a937a023 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java @@ -1,5 +1,8 @@ package com.gregtechceu.gtceu.api.capability.recipe; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.misc.lib.TagOrCycleFluidTransfer; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.content.Content; @@ -11,6 +14,7 @@ import com.gregtechceu.gtceu.api.recipe.lookup.MapFluidTagIngredient; import com.gregtechceu.gtceu.api.recipe.modifier.ParallelLogic; import com.gregtechceu.gtceu.api.recipe.ui.GTRecipeTypeUI; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.client.TooltipsHandler; import com.gregtechceu.gtceu.integration.GTRecipeWidget; import com.gregtechceu.gtceu.utils.FluidKey; @@ -19,24 +23,21 @@ import com.gregtechceu.gtceu.utils.OverlayingFluidStorage; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.jei.IngredientIO; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; -import com.lowdragmc.lowdraglib.utils.TagOrCycleFluidTransfer; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.tags.TagKey; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,7 +83,7 @@ public List convertToMapIngredient(Object obj) { Collection fluids = value.getFluids(); for (Fluid fluid : fluids) { ingredients.add(new MapFluidIngredient( - FluidStack.create(fluid, ingredient.getAmount(), ingredient.getNbt()))); + new FluidStack(fluid, ingredient.getAmount(), ingredient.getNbt()))); } } } @@ -153,8 +154,8 @@ public int limitParallel(GTRecipe recipe, IRecipeCapabilityHolder holder, int mu Objects.requireNonNullElseGet(holder.getCapabilitiesProxy().get(IO.OUT, FluidRecipeCapability.CAP), Collections::emptyList) .stream() - .filter(IFluidTransfer.class::isInstance) - .map(IFluidTransfer.class::cast) + .filter(IFluidHandler.class::isInstance) + .map(IFluidHandler.class::cast) .toList())); List recipeOutputs = recipe.getOutputContents(FluidRecipeCapability.CAP) @@ -167,8 +168,8 @@ public int limitParallel(GTRecipe recipe, IRecipeCapabilityHolder holder, int mu while (minMultiplier != maxMultiplier) { overlayedFluidHandler.reset(); - long returnedAmount = 0; - long amountToInsert = 0; + int returnedAmount = 0; + int amountToInsert = 0; for (FluidStack fluidStack : recipeOutputs) { if (fluidStack.getAmount() <= 0) continue; @@ -197,24 +198,24 @@ public int limitParallel(GTRecipe recipe, IRecipeCapabilityHolder holder, int mu @Override public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe, int parallelAmount) { // Find all the fluids in the combined Fluid Input inventories and create oversized FluidStacks - Map fluidStacks = Objects + Map fluidStacks = Objects .requireNonNullElseGet(holder.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP), Collections::>emptyList) .stream() .map(container -> container.getContents().stream().filter(FluidStack.class::isInstance) .map(FluidStack.class::cast).toList()) .flatMap(container -> GTHashMaps.fromFluidCollection(container).entrySet().stream()) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Long::sum, - Object2LongLinkedOpenHashMap::new)); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, Integer::sum, + Object2IntLinkedOpenHashMap::new)); int minMultiplier = Integer.MAX_VALUE; // map the recipe input fluids to account for duplicated fluids, // so their sum is counted against the total of fluids available in the input - Map fluidCountMap = new HashMap<>(); - Map notConsumableMap = new HashMap<>(); + Map fluidCountMap = new HashMap<>(); + Map notConsumableMap = new HashMap<>(); for (Content content : recipe.getInputContents(FluidRecipeCapability.CAP)) { FluidIngredient fluidInput = FluidRecipeCapability.CAP.of(content.content); - long fluidAmount = fluidInput.getAmount(); + int fluidAmount = fluidInput.getAmount(); if (content.chance == 0) { notConsumableMap.computeIfPresent(fluidInput, (k, v) -> v + fluidAmount); @@ -227,23 +228,23 @@ public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe, } // Iterate through the recipe inputs, excluding the not consumable fluids from the fluid inventory map - for (Map.Entry notConsumableFluid : notConsumableMap.entrySet()) { - long needed = notConsumableFluid.getValue(); - long available = 0; + for (Map.Entry notConsumableFluid : notConsumableMap.entrySet()) { + int needed = notConsumableFluid.getValue(); + int available = 0; // For every fluid gathered from the fluid inputs. - for (Map.Entry inputFluid : fluidStacks.entrySet()) { + for (Map.Entry inputFluid : fluidStacks.entrySet()) { // Strip the Non-consumable tags here, as FluidKey compares the tags, which causes finding matching // fluids // in the input tanks to fail, because there is nothing in those hatches with a non-consumable tag if (notConsumableFluid.getKey().test( - FluidStack.create(inputFluid.getKey().fluid, inputFluid.getValue(), inputFluid.getKey().tag))) { + new FluidStack(inputFluid.getKey().fluid, inputFluid.getValue(), inputFluid.getKey().tag))) { available = inputFluid.getValue(); if (available > needed) { inputFluid.setValue(available - needed); needed -= available; break; } else { - inputFluid.setValue(0L); + inputFluid.setValue(0); notConsumableFluid.setValue(needed - available); needed -= available; } @@ -268,13 +269,13 @@ public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe, } // Iterate through the fluid inputs in the recipe - for (Map.Entry fs : fluidCountMap.entrySet()) { - long needed = fs.getValue(); - long available = 0; + for (Map.Entry fs : fluidCountMap.entrySet()) { + int needed = fs.getValue(); + int available = 0; // For every fluid gathered from the fluid inputs. - for (Map.Entry inputFluid : fluidStacks.entrySet()) { + for (Map.Entry inputFluid : fluidStacks.entrySet()) { if (fs.getKey().test( - FluidStack.create(inputFluid.getKey().fluid, inputFluid.getValue(), inputFluid.getKey().tag))) { + new FluidStack(inputFluid.getKey().fluid, inputFluid.getValue(), inputFluid.getKey().tag))) { available += inputFluid.getValue(); } } @@ -301,7 +302,8 @@ public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe, public Object createXEIContainer(List contents) { // cast is safe if you don't pass the wrong thing. // noinspection unchecked - return new TagOrCycleFluidTransfer((List, Long>>, List>>) contents); + return new TagOrCycleFluidTransfer( + (List, Integer>>, List>>) contents); } @NotNull @@ -330,10 +332,10 @@ public void applyWidgetInfo(@NotNull Widget widget, @Nullable Content content, @Nullable Object storage) { if (widget instanceof TankWidget tank) { - if (storage instanceof TagOrCycleFluidTransfer fluidTransfer) { - tank.setFluidTank(fluidTransfer, index); - } else if (storage instanceof IFluidTransfer fluidTransfer) { - tank.setFluidTank(new OverlayingFluidStorage(fluidTransfer, index)); + if (storage instanceof TagOrCycleFluidTransfer fluidHandler) { + tank.setFluidTank(fluidHandler, index); + } else if (storage instanceof IFluidHandlerModifiable fluidHandler) { + tank.setFluidTank(new OverlayingFluidStorage(fluidHandler, index)); } tank.setIngredientIO(io == IO.IN ? IngredientIO.INPUT : IngredientIO.OUTPUT); tank.setAllowClickFilled(!isXEI); @@ -361,17 +363,17 @@ public void applyWidgetInfo(@NotNull Widget widget, } // Maps fluids to Either<(tag with count), FluidStack>s - public static Either, Long>>, List> mapFluid(FluidIngredient ingredient) { - long amount = ingredient.getAmount(); + public static Either, Integer>>, List> mapFluid(FluidIngredient ingredient) { + int amount = ingredient.getAmount(); CompoundTag tag = ingredient.getNbt(); - List, Long>> tags = new ArrayList<>(); + List, Integer>> tags = new ArrayList<>(); List fluids = new ArrayList<>(); for (FluidIngredient.Value value : ingredient.values) { if (value instanceof FluidIngredient.TagValue tagValue) { tags.add(Pair.of(tagValue.getTag(), amount)); } else { - fluids.addAll(value.getFluids().stream().map(fluid -> FluidStack.create(fluid, amount, tag)).toList()); + fluids.addAll(value.getFluids().stream().map(fluid -> new FluidStack(fluid, amount, tag)).toList()); } } if (!tags.isEmpty()) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java b/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java index 29587d813e..ba81026bee 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java @@ -5,10 +5,10 @@ import com.gregtechceu.gtceu.api.gui.factory.CoverUIFactory; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.item.tool.IToolGridHighLight; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.client.renderer.cover.ICoverRenderer; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import com.lowdragmc.lowdraglib.syncdata.IEnhancedManaged; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -217,7 +217,7 @@ public IItemTransfer getItemTransferCap(IItemTransfer defaultValue) { } @Nullable - public IFluidTransfer getFluidTransferCap(IFluidTransfer defaultValue) { + public IFluidHandlerModifiable getFluidTransferCap(IFluidHandlerModifiable defaultValue) { return defaultValue; } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FilterHandlers.java b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FilterHandlers.java index 26bb521c6f..d2ccc7aa08 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FilterHandlers.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FilterHandlers.java @@ -1,9 +1,9 @@ package com.gregtechceu.gtceu.api.cover.filter; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.IEnhancedManaged; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; public interface FilterHandlers { diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FluidFilter.java b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FluidFilter.java index 852533a1ad..bfa7de498e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FluidFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/FluidFilter.java @@ -1,11 +1,11 @@ package com.gregtechceu.gtceu.api.cover.filter; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; +import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.NotImplementedException; @@ -33,7 +33,7 @@ static FluidFilter loadFilter(ItemStack itemStack) { * @return The amount configured for the supplied fluid stack.
* If the stack is not matched by this filter, 0 is returned instead. */ - long testFluidAmount(FluidStack fluidStack); + int testFluidAmount(FluidStack fluidStack); /** * @return Whether this filter supports querying for exact fluid amounts. @@ -54,8 +54,8 @@ public boolean test(FluidStack fluidStack) { } @Override - public long testFluidAmount(FluidStack fluidStack) { - return Long.MAX_VALUE; + public int testFluidAmount(FluidStack fluidStack) { + return Integer.MAX_VALUE; } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java index 80cc6ce02a..124d1096e2 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java @@ -3,16 +3,16 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.widget.ScrollablePhantomFluidWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import lombok.Getter; @@ -41,12 +41,12 @@ public class SimpleFluidFilter implements FluidFilter { protected Consumer onUpdated = filter -> itemWriter.accept(filter); @Getter - protected long maxStackSize = 1L; + protected int maxStackSize = 1; - private FluidStorage[] fluidStorageSlots = new FluidStorage[9]; + private CustomFluidTank[] fluidStorageSlots = new CustomFluidTank[9]; protected SimpleFluidFilter() { - Arrays.fill(matches, FluidStack.empty()); + Arrays.fill(matches, FluidStack.EMPTY); } public static SimpleFluidFilter loadFilter(ItemStack itemStack) { @@ -60,7 +60,7 @@ private static SimpleFluidFilter loadFilter(CompoundTag tag, Consumer 0L) ? 0L : Long.MAX_VALUE; + return (totalFluidAmount > 0) ? 0 : Integer.MAX_VALUE; } return totalFluidAmount; } - public long getTotalConfiguredFluidAmount(FluidStack fluidStack) { - long totalAmount = 0L; + public int getTotalConfiguredFluidAmount(FluidStack fluidStack) { + int totalAmount = 0; for (var candidate : matches) { if (ignoreNbt && candidate.getFluid() == fluidStack.getFluid()) { @@ -167,10 +167,10 @@ public long getTotalConfiguredFluidAmount(FluidStack fluidStack) { return totalAmount; } - public void setMaxStackSize(long maxStackSize) { + public void setMaxStackSize(int maxStackSize) { this.maxStackSize = maxStackSize; - for (FluidStorage slot : fluidStorageSlots) { + for (CustomFluidTank slot : fluidStorageSlots) { if (slot != null) slot.setCapacity(maxStackSize); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/TagFluidFilter.java b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/TagFluidFilter.java index 5273335d99..158599a59c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/TagFluidFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/TagFluidFilter.java @@ -2,11 +2,10 @@ import com.gregtechceu.gtceu.utils.OreDictExprFilter; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; @@ -56,8 +55,8 @@ public boolean test(FluidStack fluidStack) { } @Override - public long testFluidAmount(FluidStack fluidStack) { - return test(fluidStack) ? Long.MAX_VALUE : 0; + public int testFluidAmount(FluidStack fluidStack) { + return test(fluidStack) ? Integer.MAX_VALUE : 0; } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java index 297763b219..a1ee566a56 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java @@ -20,8 +20,6 @@ import com.gregtechceu.gtceu.integration.kjs.helpers.MaterialStackWrapper; import com.gregtechceu.gtceu.utils.FormattingUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -29,6 +27,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -236,10 +235,10 @@ public Fluid getFluid(@NotNull FluidStorageKey key) { /** * @param amount the amount the FluidStack should have * @return a FluidStack with the fluid and amount - * @see #getFluid(FluidStorageKey, long) + * @see #getFluid(FluidStorageKey, int) */ - public FluidStack getFluid(long amount) { - return FluidStack.create(getFluid(), amount); + public FluidStack getFluid(int amount) { + return new FluidStack(getFluid(), amount); } /** @@ -247,13 +246,13 @@ public FluidStack getFluid(long amount) { * @param amount the amount the FluidStack should have * @return a FluidStack with the fluid and amount */ - public FluidStack getFluid(@NotNull FluidStorageKey key, long amount) { - return FluidStack.create(getFluid(key), amount); + public FluidStack getFluid(@NotNull FluidStorageKey key, int amount) { + return new FluidStack(getFluid(key), amount); } /** * @return a {@code TagKey} with the material's name as the tag key - * @see #getFluid(FluidStorageKey, long) + * @see #getFluid(FluidStorageKey, int) */ public TagKey getFluidTag() { return TagUtil.createFluidTag(this.getName()); @@ -314,9 +313,9 @@ public Fluid getHotFluid() { return prop == null ? null : prop.getFluid(); } - public FluidStack getHotFluid(long amount) { + public FluidStack getHotFluid(int amount) { AlloyBlastProperty prop = properties.getProperty(PropertyKey.ALLOY_BLAST); - return prop == null ? null : FluidStack.create(prop.getFluid(), amount); + return prop == null ? null : new FluidStack(prop.getFluid(), amount); } public Item getBucket() { diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java index f7c5c6c5b1..8e3a7cce9a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java @@ -5,7 +5,7 @@ import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttribute; import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttributes; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; +import net.minecraftforge.fluids.FluidType; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; @@ -26,7 +26,7 @@ public class FluidPipeProperties implements IMaterialProperty containmentPredicate = new Object2BooleanOpenHashMap<>(); - public FluidPipeProperties(int maxFluidTemperature, long throughput, boolean gasProof, boolean acidProof, + public FluidPipeProperties(int maxFluidTemperature, int throughput, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof, int channels) { this.maxFluidTemperature = maxFluidTemperature; this.throughput = throughput; @@ -59,7 +59,7 @@ public FluidPipeProperties(int maxFluidTemperature, long throughput, boolean gas /** * Default property constructor. */ - public FluidPipeProperties(int maxFluidTemperature, long throughput, boolean gasProof, boolean acidProof, + public FluidPipeProperties(int maxFluidTemperature, int throughput, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof) { this(maxFluidTemperature, throughput, gasProof, acidProof, cryoProof, plasmaProof, 1); } @@ -103,8 +103,8 @@ public String toString() { '}'; } - public long getPlatformThroughput() { - return getThroughput() * FluidHelper.getBucket() / 1000; + public int getPlatformThroughput() { + return getThroughput() * FluidType.BUCKET_VOLUME / 1000; } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java index e4b16e1181..4501b899b5 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java @@ -3,12 +3,12 @@ import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.ingredient.IGhostIngredientTarget; import com.lowdragmc.lowdraglib.gui.ingredient.Target; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import net.minecraft.client.renderer.Rect2i; import net.minecraft.world.level.material.Fluid; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidStack; import com.google.common.collect.Lists; import dev.emi.emi.api.stack.EmiStack; @@ -17,7 +17,7 @@ import java.util.Collections; import java.util.List; -import static com.lowdragmc.lowdraglib.gui.widget.PhantomFluidWidget.drainFrom; +import static com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget.drainFrom; public interface IGhostFluidTarget extends IGhostIngredientTarget { @@ -62,13 +62,13 @@ public void accept(@NotNull Object ingredient) { default Object convertIngredient(Object ingredient) { if (LDLib.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { - ingredient = FluidStack.create(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getTag()); + ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getTag()); } if (LDLib.isEmiLoaded() && ingredient instanceof EmiStack fluidEmiStack) { Fluid fluid = fluidEmiStack.getKeyOfType(Fluid.class); - ingredient = fluid == null ? FluidStack.empty() : - FluidStack.create(fluid, fluidEmiStack.getAmount(), fluidEmiStack.getNbt()); + ingredient = fluid == null ? FluidStack.EMPTY : + new FluidStack(fluid, (int) fluidEmiStack.getAmount(), fluidEmiStack.getNbt()); } if (LDLib.isJeiLoaded() && ingredient instanceof net.minecraftforge.fluids.FluidStack fluidStack) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java index 64b86ad7d5..d7cc20ea1d 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java @@ -12,13 +12,13 @@ import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.utils.FormattingUtil; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.BlockPos; @@ -34,6 +34,7 @@ import net.minecraft.world.level.material.Fluids; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; @@ -178,11 +179,11 @@ public void scan(FluidInfo[][][] storage, LevelChunk chunk) { @Override public int getItemColor(FluidInfo item) { - var fluidStack = FluidStack.create(item.fluid, item.yield); + var fluidStack = new FluidStack(item.fluid, item.yield); if (fluidStack.getFluid() == Fluids.LAVA) { return 0xFFFF7000; } - return FluidHelper.getColor(fluidStack); + return GTUtil.getFluidColor(fluidStack); } @Override @@ -192,7 +193,7 @@ public IGuiTexture getItemIcon(FluidInfo item) { @Override public String getDescriptionId(FluidInfo item) { - return FluidStack.create(item.fluid, item.yield).getDisplayName().getString(); + return new FluidStack(item.fluid, item.yield).getDisplayName().getString(); } @Override @@ -238,7 +239,8 @@ public void drawSpecialGrid(GuiGraphics graphics, FluidInfo[] items, int x, int float drawnV = (float) ProgressTexture.FillDirection.DOWN_TO_UP.getDrawnV(progress); float drawnWidth = (float) ProgressTexture.FillDirection.DOWN_TO_UP.getDrawnWidth(progress); float drawnHeight = (float) ProgressTexture.FillDirection.DOWN_TO_UP.getDrawnHeight(progress); - DrawerHelper.drawFluidForGui(graphics, FluidStack.create(item.fluid(), item.left), 100, + DrawerHelper.drawFluidForGui(graphics, + FluidHelperImpl.toFluidStack(new FluidStack(item.fluid(), item.left)), 100, (int) (x + drawnU * width), (int) (y + drawnV * height), ((int) (width * drawnWidth)), ((int) (height * drawnHeight))); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java index 8bb0614dbb..43e5d7d634 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java @@ -1,15 +1,14 @@ package com.gregtechceu.gtceu.api.gui.widget; +import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.gui.widget.PhantomFluidWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; @@ -19,9 +18,9 @@ public class ScrollablePhantomFluidWidget extends PhantomFluidWidget { private static final int SCROLL_ACTION_ID = 0x0001_0001; - private static final long MILLIBUCKETS = FluidHelper.getBucket() / 1000; + private static final int MILLIBUCKETS = FluidType.BUCKET_VOLUME / 1000; - public ScrollablePhantomFluidWidget(@Nullable IFluidTransfer fluidTank, int tank, int x, int y, int width, + public ScrollablePhantomFluidWidget(@Nullable IFluidHandlerModifiable fluidTank, int tank, int x, int y, int width, int height, Supplier phantomFluidGetter, Consumer phantomFluidSetter) { super(fluidTank, tank, x, y, width, height, phantomFluidGetter, phantomFluidSetter); @@ -34,12 +33,12 @@ public boolean mouseWheelMove(double mouseX, double mouseY, double wheelDelta) { return false; var delta = getModifiedChangeAmount((wheelDelta > 0) ? 1 : -1) * MILLIBUCKETS; - writeClientAction(SCROLL_ACTION_ID, buf -> buf.writeLong(delta)); + writeClientAction(SCROLL_ACTION_ID, buf -> buf.writeInt(delta)); return true; } - private long getModifiedChangeAmount(int amount) { + private int getModifiedChangeAmount(int amount) { if (GTUtil.isShiftDown()) amount *= 10; @@ -55,15 +54,15 @@ private long getModifiedChangeAmount(int amount) { @Override public void handleClientAction(int id, FriendlyByteBuf buffer) { switch (id) { - case SCROLL_ACTION_ID -> handleScrollAction(buffer.readLong()); + case SCROLL_ACTION_ID -> handleScrollAction(buffer.readInt()); default -> super.handleClientAction(id, buffer); } detectAndSendChanges(); } - private void handleScrollAction(long delta) { - IFluidTransfer fluidTank = getFluidTank(); + private void handleScrollAction(int delta) { + IFluidHandlerModifiable fluidTank = (IFluidHandlerModifiable) getFluidTank(); if (fluidTank == null) return; @@ -74,9 +73,9 @@ private void handleScrollAction(long delta) { if (fluid.isEmpty()) return; - fluid.setAmount(Math.min(Math.max(fluid.getAmount() + delta, 0L), fluidTank.getTankCapacity(tank))); + fluid.setAmount(Math.min(Math.max(fluid.getAmount() + delta, 0), fluidTank.getTankCapacity(tank))); if (fluid.getAmount() <= 0L) { - fluidTank.setFluidInTank(tank, FluidStack.empty()); + fluidTank.setFluidInTank(tank, FluidStack.EMPTY); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/GTBucketItem.java b/src/main/java/com/gregtechceu/gtceu/api/item/GTBucketItem.java index 5378eb802d..7f6406bc3a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/GTBucketItem.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/GTBucketItem.java @@ -4,9 +4,6 @@ import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; import com.gregtechceu.gtceu.api.fluids.GTFluid; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -25,7 +22,9 @@ import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper; @@ -55,7 +54,7 @@ public GTBucketItem(Supplier fluid, Properties properties, Mate public static int color(ItemStack itemStack, int index) { if (itemStack.getItem() instanceof GTBucketItem item) { if (index == 1) { - return FluidHelper.getColor(FluidStack.create(item.getFluid(), FluidHelper.getBucket())); + return IClientFluidTypeExtensions.of(item.getFluid()).getTintColor(); } } return -1; diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/component/FilteredFluidContainer.java b/src/main/java/com/gregtechceu/gtceu/api/item/component/FilteredFluidContainer.java index 2dfd8bbdd4..80370d5248 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/component/FilteredFluidContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/component/FilteredFluidContainer.java @@ -3,9 +3,6 @@ import com.gregtechceu.gtceu.api.item.component.forge.IComponentCapability; import com.gregtechceu.gtceu.api.misc.forge.FilteredFluidHandlerItemStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; - import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -13,6 +10,8 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,12 +49,9 @@ public static FilteredFluidContainer create(int capacity, boolean allowPartialFi public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltipComponents, TooltipFlag isAdvanced) { if (stack.hasTag()) { - FluidStack tank = FluidTransferHelper.getFluidContained(stack); - if (tank != null) { - tooltipComponents - .add(Component.translatable("gtceu.universal.tooltip.fluid_stored", tank.getDisplayName(), - tank.getAmount())); - } + FluidUtil.getFluidContained(stack).ifPresent(tank -> tooltipComponents + .add(Component.translatable("gtceu.universal.tooltip.fluid_stored", tank.getDisplayName(), + tank.getAmount()))); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/component/ThermalFluidStats.java b/src/main/java/com/gregtechceu/gtceu/api/item/component/ThermalFluidStats.java index b2e02d135e..82cec56f9f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/item/component/ThermalFluidStats.java +++ b/src/main/java/com/gregtechceu/gtceu/api/item/component/ThermalFluidStats.java @@ -4,9 +4,6 @@ import com.gregtechceu.gtceu.api.misc.forge.SimpleThermalFluidHandlerItemStack; import com.gregtechceu.gtceu.api.misc.forge.ThermalFluidHandlerItemStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; - import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -14,6 +11,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,12 +69,9 @@ public static ThermalFluidStats create(int capacity, int maxFluidTemperature, bo public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltipComponents, TooltipFlag isAdvanced) { if (stack.hasTag()) { - FluidStack tank = FluidTransferHelper.getFluidContained(stack); - if (tank != null) { - tooltipComponents - .add(Component.translatable("gtceu.universal.tooltip.fluid_stored", tank.getDisplayName(), - tank.getAmount())); - } + FluidUtil.getFluidContained(stack).ifPresent(tank -> tooltipComponents + .add(Component.translatable("gtceu.universal.tooltip.fluid_stored", tank.getDisplayName(), + tank.getAmount()))); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java index 78c122c0eb..c68e259712 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java @@ -5,9 +5,9 @@ import com.gregtechceu.gtceu.api.cover.CoverBehavior; import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import com.lowdragmc.lowdraglib.syncdata.IEnhancedManaged; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -185,7 +185,7 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Override - public IFluidTransfer getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { return machine.getFluidTransferCap(side, useCoverCapability); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java index abdf3fbd3e..97a748259a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java @@ -21,6 +21,7 @@ import com.gregtechceu.gtceu.api.machine.trait.MachineTrait; import com.gregtechceu.gtceu.api.misc.IOFluidTransferList; import com.gregtechceu.gtceu.api.misc.IOItemTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.FluidFilterCover; import com.gregtechceu.gtceu.common.cover.ItemFilterCover; import com.gregtechceu.gtceu.common.item.tool.behavior.ToolModeSwitchBehavior; @@ -28,8 +29,6 @@ import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import com.lowdragmc.lowdraglib.syncdata.IEnhancedManaged; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -63,6 +62,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import com.mojang.datafixers.util.Pair; import lombok.Getter; @@ -689,11 +690,11 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Nullable - public IFluidTransfer getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { var list = getTraits().stream() - .filter(IFluidTransfer.class::isInstance) + .filter(IFluidHandler.class::isInstance) .filter(t -> t.hasCapability(side)) - .map(IFluidTransfer.class::cast) + .map(IFluidHandler.class::cast) .toList(); if (list.isEmpty()) return null; diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleGeneratorMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleGeneratorMachine.java index 895ca0b09a..226b668d9a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleGeneratorMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleGeneratorMachine.java @@ -24,7 +24,7 @@ import com.google.common.collect.Tables; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,13 +50,13 @@ public class SimpleGeneratorMachine extends WorkableTieredMachine private final float hazardStrengthPerOperation; public SimpleGeneratorMachine(IMachineBlockEntity holder, int tier, - float hazardStrengthPerOperation, Int2LongFunction tankScalingFunction, + float hazardStrengthPerOperation, Int2IntFunction tankScalingFunction, Object... args) { super(holder, tier, tankScalingFunction, args); this.hazardStrengthPerOperation = hazardStrengthPerOperation; } - public SimpleGeneratorMachine(IMachineBlockEntity holder, int tier, Int2LongFunction tankScalingFunction, + public SimpleGeneratorMachine(IMachineBlockEntity holder, int tier, Int2IntFunction tankScalingFunction, Object... args) { this(holder, tier, 0.25f, tankScalingFunction, args); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java index aaa2fd32a9..3de80209e5 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java @@ -18,13 +18,13 @@ import com.gregtechceu.gtceu.common.item.IntCircuitBehaviour; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.lang.LangHandler; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -47,7 +47,7 @@ import com.google.common.collect.Tables; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.Nullable; @@ -107,7 +107,7 @@ public class SimpleTieredMachine extends WorkableTieredMachine implements IAutoO @Nullable protected ISubscription exportItemSubs, exportFluidSubs, energySubs; - public SimpleTieredMachine(IMachineBlockEntity holder, int tier, Int2LongFunction tankScalingFunction, + public SimpleTieredMachine(IMachineBlockEntity holder, int tier, Int2IntFunction tankScalingFunction, Object... args) { super(holder, tier, tankScalingFunction, args); this.outputFacingItems = hasFrontFacing() ? getFrontFacing().getOpposite() : Direction.UP; @@ -249,8 +249,7 @@ protected void updateAutoOutputSubscription() { ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(outputFacingItems), outputFacingItems.getOpposite()) != null || (isAutoOutputFluids() && !exportFluids.isEmpty()) && outputFacingFluids != null && - FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(outputFacingFluids), - outputFacingFluids.getOpposite()) != null) { + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/WorkableTieredMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/WorkableTieredMachine.java index 41a8a3f462..3040d5ab01 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/WorkableTieredMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/WorkableTieredMachine.java @@ -15,7 +15,7 @@ import com.google.common.collect.Table; import com.google.common.collect.Tables; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.NotNull; @@ -49,7 +49,7 @@ public abstract class WorkableTieredMachine extends TieredEnergyMachine implemen @Persisted public int activeRecipeType; @Getter - public final Int2LongFunction tankScalingFunction; + public final Int2IntFunction tankScalingFunction; @Nullable @Getter @Setter @@ -79,7 +79,7 @@ public abstract class WorkableTieredMachine extends TieredEnergyMachine implemen protected boolean isMuffled; protected boolean previouslyMuffled = true; - public WorkableTieredMachine(IMachineBlockEntity holder, int tier, Int2LongFunction tankScalingFunction, + public WorkableTieredMachine(IMachineBlockEntity holder, int tier, Int2IntFunction tankScalingFunction, Object... args) { super(holder, tier, args); this.overclockTier = getMaxOverclockTier(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java index f62d27b952..89c20b0b61 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java @@ -2,12 +2,12 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.fancy.IFancyConfigurator; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.FluidStorage; import net.minecraft.network.chat.Component; @@ -21,7 +21,7 @@ @Accessors(chain = true) public class FancyTankConfigurator implements IFancyConfigurator { - private final FluidStorage[] tanks; + private final CustomFluidTank[] tanks; @Getter private final Component title; @@ -30,7 +30,7 @@ public class FancyTankConfigurator implements IFancyConfigurator { @Setter private List tooltips = Collections.emptyList(); - public FancyTankConfigurator(FluidStorage[] tanks, Component title) { + public FancyTankConfigurator(CustomFluidTank[] tanks, Component title) { this.tanks = tanks; this.title = title; } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java index 457c05d430..603f8f7875 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java @@ -22,7 +22,6 @@ import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import com.lowdragmc.lowdraglib.utils.Position; @@ -31,6 +30,7 @@ import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.player.Player; +import net.minecraftforge.fluids.FluidType; import com.google.common.collect.Tables; import lombok.Setter; @@ -73,7 +73,7 @@ public ManagedFieldHolder getFieldHolder() { @Override protected NotifiableFluidTank createSteamTank(Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket(), IO.IN); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME, IO.IN); } protected NotifiableItemStackHandler createImportItemHandler(@SuppressWarnings("unused") Object... args) { @@ -89,7 +89,7 @@ public void onLoad() { super.onLoad(); // Fine, we use it to provide eu cap for recipe, simulating an EU machine. capabilitiesProxy.put(IO.IN, EURecipeCapability.CAP, - List.of(new SteamEnergyRecipeHandler(steamTank, FluidHelper.getBucket() / 1000d))); + List.of(new SteamEnergyRecipeHandler(steamTank, FluidType.BUCKET_VOLUME / 1000d))); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java index 6ab9e00ab7..800d7dfce3 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java @@ -11,6 +11,7 @@ import com.gregtechceu.gtceu.api.machine.feature.IExplosionMachine; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.logic.OCParams; import com.gregtechceu.gtceu.api.recipe.logic.OCResult; @@ -18,15 +19,13 @@ import com.gregtechceu.gtceu.common.item.PortableScannerBehavior; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.utils.FormattingUtil; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.ProgressWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; @@ -48,6 +47,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -102,11 +103,11 @@ public ManagedFieldHolder getFieldHolder() { @Override protected NotifiableFluidTank createSteamTank(Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket(), IO.OUT); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME, IO.OUT); } protected NotifiableFluidTank createWaterTank(@SuppressWarnings("unused") Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket(), IO.IN); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME, IO.IN); } @Override @@ -144,10 +145,8 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { } protected void updateAutoOutputSubscription() { - if (Direction.stream() - .filter(direction -> direction != getFrontFacing() && direction != Direction.DOWN) - .anyMatch(direction -> FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(direction), - direction.getOpposite()) != null)) { + if (Direction.stream().filter(direction -> direction != getFrontFacing() && direction != Direction.DOWN) + .anyMatch(direction -> GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), direction))) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -159,8 +158,7 @@ protected void autoOutput() { if (getOffsetTimer() % 5 == 0) { steamTank.exportToNearby(Direction.stream() .filter(direction -> direction != getFrontFacing() && direction != Direction.DOWN) - .filter(direction -> FluidTransferHelper.getFluidTransfer(getLevel(), - getPos().relative(direction), direction.getOpposite()) != null) + .filter(direction -> GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), direction)) .toArray(Direction[]::new)); updateAutoOutputSubscription(); } @@ -198,13 +196,15 @@ protected void updateCurrentTemperature() { if (getOffsetTimer() % 10 == 0) { if (currentTemperature >= 100) { - long fillAmount = (long) (getBaseSteamOutput() * ((float) currentTemperature / getMaxTemperature()) / + int fillAmount = (int) (getBaseSteamOutput() * ((float) currentTemperature / getMaxTemperature()) / 2); - boolean hasDrainedWater = !waterTank.drainInternal(FluidHelper.getBucket() / 1000, false).isEmpty(); + boolean hasDrainedWater = !waterTank.drainInternal(FluidType.BUCKET_VOLUME / 1000, FluidAction.EXECUTE) + .isEmpty(); var filledSteam = 0L; if (hasDrainedWater) { filledSteam = steamTank.fillInternal( - GTMaterials.Steam.getFluid(fillAmount * FluidHelper.getBucket() / 1000), false); + GTMaterials.Steam.getFluid(fillAmount * FluidType.BUCKET_VOLUME / 1000), + FluidAction.EXECUTE); } if (this.hasNoWater && hasDrainedWater) { doExplosion(2.0f); @@ -229,7 +229,7 @@ protected void updateCurrentTemperature() { } // bypass capability check for special case behavior - steamTank.drainInternal(FluidHelper.getBucket() * 4, false); + steamTank.drainInternal(FluidType.BUCKET_VOLUME * 4, FluidAction.EXECUTE); } } else this.hasNoWater = false; } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java index c1270947d2..79ef9ce6e6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java @@ -9,7 +9,7 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.common.data.GTMaterials; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; @@ -36,7 +36,7 @@ public SteamEnergyRecipeHandler(NotifiableFluidTank steamTank, double conversion public List handleRecipeInner(IO io, GTRecipe recipe, List left, @Nullable String slotName, boolean simulate) { long sum = left.stream().reduce(0L, Long::sum); - long realSum = (long) Math.ceil(sum * conversionRate); + int realSum = (int) Math.ceil(sum * conversionRate); if (realSum > 0) { var steam = io == IO.IN ? FluidIngredient.of(GTMaterials.Steam.getFluidTag(), realSum) : FluidIngredient.of(GTMaterials.Steam.getFluid(realSum)); @@ -58,7 +58,7 @@ public List getContents() { tankContents.add(stack); } } - long sum = tankContents.stream().map(FluidStack::getAmount).reduce(0L, Long::sum); + long sum = tankContents.stream().map(FluidStack::getAmount).reduce(0, Integer::sum); long realSum = (long) Math.ceil(sum * conversionRate); return List.of(realSum); } @@ -72,7 +72,7 @@ public double getTotalContentAmount() { tankContents.add(stack); } } - long sum = tankContents.stream().map(FluidStack::getAmount).reduce(0L, Long::sum); + long sum = tankContents.stream().map(FluidStack::getAmount).reduce(0, Integer::sum); return (long) Math.ceil(sum * conversionRate); } @@ -87,7 +87,7 @@ public long getCapacity() { public long getStored() { FluidStack stack = steamTank.getFluidInTank(0); - if (stack != FluidStack.empty()) { + if (stack != FluidStack.EMPTY) { return stack.getAmount(); } return 0; diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java index b6d7eb1b2c..8966976695 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java @@ -7,11 +7,12 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; +import net.minecraftforge.fluids.FluidStack; + import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -25,13 +26,13 @@ public class FluidRecipeHandler implements IRecipeHandler { public final IO handlerIO; @Persisted @Getter - private final FluidStorage[] storages; + private final CustomFluidTank[] storages; - public FluidRecipeHandler(IO handlerIO, int slots, long capacity) { + public FluidRecipeHandler(IO handlerIO, int slots, int capacity) { this.handlerIO = handlerIO; - this.storages = new FluidStorage[slots]; + this.storages = new CustomFluidTank[slots]; for (int i = 0; i < this.storages.length; i++) { - this.storages[i] = new FluidStorage(capacity); + this.storages[i] = new CustomFluidTank(capacity); } } @@ -44,7 +45,7 @@ public List handleRecipeInner(IO io, GTRecipe recipe, List getContents() { List ingredients = new ArrayList<>(); - for (FluidStorage storage : getStorages()) { + for (CustomFluidTank storage : getStorages()) { FluidStack stack = storage.getFluid(); if (!stack.isEmpty()) { ingredients.add(stack); @@ -56,7 +57,7 @@ public List getContents() { @Override public double getTotalContentAmount() { long amount = 0; - for (FluidStorage storage : getStorages()) { + for (CustomFluidTank storage : getStorages()) { FluidStack stack = storage.getFluid(); if (!stack.isEmpty()) { amount += stack.getAmount(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/FilteredFluidHandlerItemStack.java b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/FilteredFluidHandlerItemStack.java index 68dea83fec..fde82d03cc 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/FilteredFluidHandlerItemStack.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/FilteredFluidHandlerItemStack.java @@ -1,7 +1,5 @@ package com.gregtechceu.gtceu.api.misc.forge; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; - import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack; @@ -12,14 +10,14 @@ public class FilteredFluidHandlerItemStack extends FluidHandlerItemStack { - Predicate filter; + Predicate filter; /** * @param container The container itemStack, data is stored on it directly as NBT. * @param capacity The maximum capacity of this fluid tank. */ public FilteredFluidHandlerItemStack(@NotNull ItemStack container, int capacity, - Predicate filter) { + Predicate filter) { super(container, capacity); this.filter = filter; } @@ -39,13 +37,13 @@ public FilteredFluidHandlerItemStack(@NotNull ItemStack container, int capacity, } private void removeTagWhenEmpty(FluidAction action) { - if (getFluid() == FluidStack.EMPTY && action == FluidAction.EXECUTE) { + if (getFluid() == FluidStack.EMPTY && action.execute()) { this.container.setTag(null); } } @Override public boolean canFillFluidType(FluidStack fluid) { - return filter.test(FluidHelperImpl.toFluidStack(fluid)); + return filter.test(fluid); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/SimpleThermalFluidHandlerItemStack.java b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/SimpleThermalFluidHandlerItemStack.java index a1c1c84650..a256aede09 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/SimpleThermalFluidHandlerItemStack.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/SimpleThermalFluidHandlerItemStack.java @@ -48,7 +48,7 @@ public SimpleThermalFluidHandlerItemStack(@NotNull ItemStack container, int capa } private void removeTagWhenEmpty(FluidAction action) { - if (getFluid() == FluidStack.EMPTY && action == FluidAction.EXECUTE) { + if (getFluid() == FluidStack.EMPTY && action.execute()) { this.container.setTag(null); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/ThermalFluidHandlerItemStack.java b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/ThermalFluidHandlerItemStack.java index 75f64abe46..987090ffe8 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/forge/ThermalFluidHandlerItemStack.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/forge/ThermalFluidHandlerItemStack.java @@ -2,8 +2,6 @@ import com.gregtechceu.gtceu.api.capability.IThermalFluidHandlerItemStack; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; - import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack; @@ -47,14 +45,14 @@ public ThermalFluidHandlerItemStack(@NotNull ItemStack container, int capacity, } private void removeTagWhenEmpty(FluidAction action) { - if (getFluid() == FluidStack.EMPTY && action == FluidAction.EXECUTE) { + if (getFluid() == FluidStack.EMPTY && action.execute()) { this.container.setTag(null); } } @Override public boolean canFillFluidType(FluidStack fluid) { - return IThermalFluidHandlerItemStack.super.canFillFluidType(FluidHelperImpl.toFluidStack(fluid)); + return IThermalFluidHandlerItemStack.super.canFillFluidType(fluid); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java b/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java index 95ceb763f7..814e4dd300 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java @@ -6,11 +6,11 @@ import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.api.machine.TickableSubscription; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.blockentity.FluidPipeBlockEntity; import com.gregtechceu.gtceu.common.blockentity.ItemPipeBlockEntity; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import com.lowdragmc.lowdraglib.syncdata.IEnhancedManaged; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -164,7 +164,7 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Override - public IFluidTransfer getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { if (pipeTile instanceof FluidPipeBlockEntity fluidPipe) { return fluidPipe.getTankList(side); } else { diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeHelper.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeHelper.java index 565abf70d9..83293f25fa 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeHelper.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeHelper.java @@ -11,9 +11,8 @@ import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/content/SerializerFluidIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/content/SerializerFluidIngredient.java index a81680796c..5a2b5379fa 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/content/SerializerFluidIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/content/SerializerFluidIngredient.java @@ -2,9 +2,8 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.fluids.FluidStack; import com.google.gson.JsonElement; import com.mojang.serialization.Codec; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java index 619eaade6d..8ed19da6d6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java @@ -1,8 +1,5 @@ package com.gregtechceu.gtceu.api.recipe.ingredient; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; @@ -14,6 +11,8 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; import net.minecraftforge.common.crafting.CraftingHelper; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import com.google.common.collect.Lists; import com.google.gson.*; @@ -40,32 +39,32 @@ public class FluidIngredient implements Predicate { @Nullable public FluidStack[] stacks; @Getter - private long amount; + private int amount; @Getter private CompoundTag nbt; private boolean changed = true; - public FluidIngredient(Stream empty, long amount, @Nullable CompoundTag nbt) { + public FluidIngredient(Stream empty, int amount, @Nullable CompoundTag nbt) { this.values = empty.toArray(Value[]::new); this.amount = amount; this.nbt = nbt; } - public static FluidIngredient fromValues(Stream stream, long amount, + public static FluidIngredient fromValues(Stream stream, int amount, @Nullable CompoundTag nbt) { FluidIngredient ingredient = new FluidIngredient(stream, amount, nbt); return ingredient.isEmpty() ? EMPTY : ingredient; } public void toNetwork(FriendlyByteBuf buffer) { - buffer.writeCollection(Arrays.asList(this.getStacks()), (buf, stack) -> stack.writeToBuf(buf)); - buffer.writeVarLong(amount); + buffer.writeCollection(Arrays.asList(this.getStacks()), (buf, stack) -> stack.writeToPacket(buf)); + buffer.writeVarInt(amount); buffer.writeNbt(nbt); } public JsonElement toJson() { JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("amount", this.amount * FluidHelper.getBucket() / 1000); + jsonObject.addProperty("amount", this.amount * FluidType.BUCKET_VOLUME / 1000); if (this.nbt != null) { jsonObject.addProperty("nbt", this.nbt.getAsString()); } @@ -137,7 +136,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { int result = Arrays.hashCode(values); - result = 31 * result + Long.hashCode(amount); + result = 31 * result + Integer.hashCode(amount); result = 31 * result + Objects.hashCode(nbt); return result; } @@ -155,7 +154,7 @@ public FluidStack[] getStacks() { if (found.contains(fluid)) continue; found.add(fluid); - fluidStacks.add(FluidStack.create(fluid, this.amount, this.nbt)); + fluidStacks.add(new FluidStack(fluid, this.amount, this.nbt)); } } this.stacks = fluidStacks.toArray(FluidStack[]::new); @@ -164,7 +163,7 @@ public FluidStack[] getStacks() { return this.stacks; } - public void setAmount(long amount) { + public void setAmount(int amount) { this.amount = amount; this.changed = true; } @@ -178,7 +177,7 @@ public static FluidIngredient of() { return EMPTY; } - public static FluidIngredient of(long amount, Fluid... items) { + public static FluidIngredient of(int amount, Fluid... items) { return FluidIngredient.of(Arrays.stream(items), amount, null); } @@ -187,7 +186,7 @@ public static FluidIngredient of(FluidStack... stacks) { stacks.length == 0 ? 0 : stacks[0].getAmount(), stacks.length == 0 ? null : stacks[0].getTag()); } - public static FluidIngredient of(Stream stacks, long amount, CompoundTag nbt) { + public static FluidIngredient of(Stream stacks, int amount, CompoundTag nbt) { return FluidIngredient.fromValues( stacks.filter(stack -> stack != null && !stack.isSame(Fluids.EMPTY)).map(FluidValue::new), amount, nbt); } @@ -197,18 +196,18 @@ public static FluidIngredient of(Stream stacks, long amount, CompoundTag * * @param tag the tag key */ - public static FluidIngredient of(TagKey tag, long amount) { + public static FluidIngredient of(TagKey tag, int amount) { return FluidIngredient.fromValues(Stream.of(new FluidIngredient.TagValue(tag)), amount, null); } - public static FluidIngredient of(TagKey tag, long amount, CompoundTag nbt) { + public static FluidIngredient of(TagKey tag, int amount, CompoundTag nbt) { return FluidIngredient.fromValues(Stream.of(new FluidIngredient.TagValue(tag)), amount, nbt); } public static FluidIngredient fromNetwork(FriendlyByteBuf buffer) { return FluidIngredient.fromValues( - buffer.readList(FluidStack::readFromBuf).stream().map(stack -> new FluidValue(stack.getFluid())), - buffer.readVarLong(), buffer.readNbt()); + buffer.readList(FluidStack::readFromPacket).stream().map(stack -> new FluidValue(stack.getFluid())), + buffer.readVarInt(), buffer.readNbt()); } public static FluidIngredient fromJson(@Nullable JsonElement json) { @@ -223,7 +222,7 @@ public static FluidIngredient fromJson(@Nullable JsonElement json, boolean allow throw new JsonSyntaxException("Expected fluid ingredient to be object"); } JsonObject jsonObject = GsonHelper.convertToJsonObject(json, "ingredient"); - long amount = GsonHelper.getAsLong(jsonObject, "amount", 0); + int amount = GsonHelper.getAsInt(jsonObject, "amount", 0); CompoundTag nbt = jsonObject.has("nbt") ? CraftingHelper.getNBT(jsonObject.get("nbt")) : null; if (GsonHelper.isObjectNode(jsonObject, "value")) { return FluidIngredient.fromValues( @@ -282,6 +281,7 @@ public TagValue(TagKey tag) { public Collection getFluids() { ArrayList list = Lists.newArrayList(); for (Holder holder : BuiltInRegistries.FLUID.getTagOrEmpty(this.tag)) { + list.add(holder.value()); } return list; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/MapFluidIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/MapFluidIngredient.java index 40a0531b6b..6b1803c697 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/MapFluidIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/MapFluidIngredient.java @@ -2,11 +2,10 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/gregtechceu/gtceu/client/TooltipsHandler.java b/src/main/java/com/gregtechceu/gtceu/client/TooltipsHandler.java index 2bda0f14a2..2a025704df 100644 --- a/src/main/java/com/gregtechceu/gtceu/client/TooltipsHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/client/TooltipsHandler.java @@ -12,8 +12,6 @@ import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; - import net.minecraft.ChatFormatting; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; @@ -50,7 +48,7 @@ public static void appendTooltips(ItemStack stack, TooltipFlag flag, List 0) { maxTemperature = Math.max(maxTemperature, - stack.getFluid().getFluidType().getTemperature(forgeStack)); + stack.getFluid().getFluidType().getTemperature(stack)); minTemperature = Math.min(minTemperature, - stack.getFluid().getFluidType().getTemperature(forgeStack)); + stack.getFluid().getFluidType().getTemperature(stack)); } } if (maxTemperature != Integer.MIN_VALUE) { @@ -160,9 +157,8 @@ public void entityInside(BlockState state, Level level, BlockPos pos, Entity ent if (tank.getFluid() != null && tank.getFluid().getAmount() > 0) { // Apply temperature damage for the pipe (single fluid pipes) FluidStack stack = tank.getFluid(); - net.minecraftforge.fluids.FluidStack forgeStack = FluidHelperImpl.toFluidStack(stack); EntityDamageUtil.applyTemperatureDamage(livingEntity, - stack.getFluid().getFluidType().getTemperature(forgeStack), 1.0F, 20); + stack.getFluid().getFluidType().getTemperature(stack), 1.0F, 20); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java index 731c00a2df..44b44dd1a5 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java @@ -12,6 +12,8 @@ import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttribute; import com.gregtechceu.gtceu.api.machine.TickableSubscription; import com.gregtechceu.gtceu.api.machine.feature.IDataInfoProvider; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.PumpCover; import com.gregtechceu.gtceu.common.cover.data.ManualIOMode; import com.gregtechceu.gtceu.common.item.PortableScannerBehavior; @@ -21,13 +23,6 @@ import com.gregtechceu.gtceu.utils.FormattingUtil; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidTransferHelperImpl; - import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -53,6 +48,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; import org.jetbrains.annotations.NotNull; @@ -70,7 +66,7 @@ public class FluidPipeBlockEntity extends PipeBlockEntity tankLists = new EnumMap<>(Direction.class); - private FluidStorage[] fluidTanks; + private CustomFluidTank[] fluidTanks; private long timer = 0L; private final int offset = GTValues.RNG.nextInt(20); @@ -109,8 +105,7 @@ public boolean canAttachTo(Direction side) { if (level.getBlockEntity(getBlockPos().relative(side)) instanceof FluidPipeBlockEntity) { return false; } - return FluidTransferHelper.getFluidTransfer(level, getBlockPos().relative(side), side.getOpposite()) != - null; + return GTUtil.isAdjacentFluidHandler(level, getBlockPos(), side); } return false; } @@ -124,7 +119,7 @@ public LazyOptional getCapability(Capability capability, @Nullable Dir if (tankList == null) return LazyOptional.empty(); return ForgeCapabilities.FLUID_HANDLER.orEmpty(capability, - LazyOptional.of(() -> FluidTransferHelperImpl.toFluidHandler(tankList))); + LazyOptional.of(() -> tankList)); } } else if (capability == GTCapability.CAPABILITY_COVERABLE) { return GTCapability.CAPABILITY_COVERABLE.orEmpty(capability, LazyOptional.of(this::getCoverContainer)); @@ -134,7 +129,7 @@ public LazyOptional getCapability(Capability capability, @Nullable Dir return super.getCapability(capability, facing); } - public long getCapacityPerTank() { + public int getCapacityPerTank() { return getNodeData().getThroughput() * 20; } @@ -150,12 +145,12 @@ public void update() { int tanks = getNodeData().getChannels(); for (int i = 0, j = GTValues.RNG.nextInt(tanks); i < tanks; i++) { int index = (i + j) % tanks; - FluidStorage tank = getFluidTanks()[index]; + CustomFluidTank tank = getFluidTanks()[index]; FluidStack fluid = tank.getFluid(); if (fluid.isEmpty() || fluid.getFluid() == Fluids.EMPTY) continue; if (fluid.getAmount() <= 0) { - tank.setFluid(FluidStack.empty()); + tank.setFluid(FluidStack.EMPTY); continue; } @@ -168,10 +163,10 @@ public void update() { } } - private void distributeFluid(int channel, FluidStorage tank, FluidStack fluid) { + private void distributeFluid(int channel, CustomFluidTank tank, FluidStack fluid) { // Tank, From, Amount to receive List tanks = new ArrayList<>(); - long amount = fluid.getAmount(); + int amount = fluid.getAmount(); FluidStack maxFluid = fluid.copy(); double availableCapacity = 0; @@ -187,12 +182,11 @@ private void distributeFluid(int channel, FluidStorage tank, FluidStack fluid) { BlockEntity neighbor = getNeighbor(facing); if (neighbor == null) continue; - IFluidHandler handler = neighbor.getCapability(ForgeCapabilities.FLUID_HANDLER, facing.getOpposite()) + IFluidHandler fluidHandler = neighbor.getCapability(ForgeCapabilities.FLUID_HANDLER, facing.getOpposite()) .resolve().orElse(null); - IFluidTransfer fluidHandler = handler == null ? null : FluidTransferHelperImpl.toFluidTransfer(handler); if (fluidHandler == null) continue; - IFluidTransfer pipeTank = tank; + IFluidHandlerModifiable pipeTank = tank; CoverBehavior cover = getCoverContainer().getCoverAtSide(facing); // pipeTank should only be determined by the cover attached to the actual pipe @@ -209,12 +203,13 @@ private void distributeFluid(int channel, FluidStorage tank, FluidStack fluid) { } } - FluidStack drainable = pipeTank.drain(maxFluid, true); + FluidStack drainable = pipeTank.drain(maxFluid, IFluidHandler.FluidAction.SIMULATE); if (drainable.isEmpty() || drainable.getAmount() <= 0) { continue; } - long filled = Math.min(fluidHandler.fill(maxFluid, true), drainable.getAmount()); + int filled = Math.min(fluidHandler.fill(maxFluid, IFluidHandler.FluidAction.SIMULATE), + drainable.getAmount()); if (filled > 0) { tanks.add(new FluidTransaction(fluidHandler, pipeTank, filled)); @@ -250,16 +245,16 @@ private void distributeFluid(int channel, FluidStorage tank, FluidStack fluid) { if (toInsert.isEmpty() || toInsert.getFluid() == Fluids.EMPTY) continue; toInsert.setAmount(transaction.amount); - long inserted = transaction.target.fill(toInsert, false); + int inserted = transaction.target.fill(toInsert, IFluidHandler.FluidAction.EXECUTE); if (inserted > 0) { - transaction.pipeTank.drain(inserted, false); + transaction.pipeTank.drain(inserted, IFluidHandler.FluidAction.EXECUTE); } } } private boolean checkForPumpCover(@Nullable CoverBehavior cover) { if (cover instanceof PumpCover coverPump) { - long pipeThroughput = getNodeData().getThroughput() * 20; + int pipeThroughput = getNodeData().getThroughput() * 20; if (coverPump.getCurrentMilliBucketsPerTick() > pipeThroughput) { coverPump.setTransferRate(pipeThroughput); } @@ -272,9 +267,8 @@ public void checkAndDestroy(@NotNull FluidStack stack) { Fluid fluid = stack.getFluid(); FluidPipeProperties prop = getNodeData(); - net.minecraftforge.fluids.FluidStack forgeStack = FluidHelperImpl.toFluidStack(stack); - boolean burning = prop.getMaxFluidTemperature() < fluid.getFluidType().getTemperature(forgeStack); - boolean leaking = !prop.isGasProof() && fluid.getFluidType().getDensity(forgeStack) < 0; + boolean burning = prop.getMaxFluidTemperature() < fluid.getFluidType().getTemperature(stack); + boolean leaking = !prop.isGasProof() && fluid.getFluidType().getDensity(stack) < 0; boolean shattering = !prop.isCryoProof() && fluid.getFluidType().getTemperature() < FluidConstants.CRYOGENIC_FLUID_THRESHOLD; boolean corroding = false; @@ -325,7 +319,7 @@ public void destroyPipe(FluidStack stack, boolean isBurning, boolean isLeaking, new AABB(getPipePos()).inflate(2)); for (LivingEntity entityLivingBase : entities) { EntityDamageUtil.applyTemperatureDamage(entityLivingBase, - stack.getFluid().getFluidType().getTemperature(FluidHelperImpl.toFluidStack(stack)), + stack.getFluid().getFluidType().getTemperature(stack), 2.0F, 10); } } @@ -377,7 +371,7 @@ public void destroyPipe(FluidStack stack, boolean isBurning, boolean isLeaking, new AABB(getPipePos()).inflate(2)); for (LivingEntity entityLivingBase : entities) { EntityDamageUtil.applyTemperatureDamage(entityLivingBase, - stack.getFluid().getFluidType().getTemperature(FluidHelperImpl.toFluidStack(stack)), + stack.getFluid().getFluidType().getTemperature(stack), 2.0F, 10); } } @@ -402,7 +396,7 @@ public void destroyPipe(FluidStack stack, boolean isBurning, boolean isLeaking, new AABB(getPipePos()).inflate(2)); for (LivingEntity entityLivingBase : entities) { EntityDamageUtil.applyTemperatureDamage(entityLivingBase, - stack.getFluid().getFluidType().getTemperature(FluidHelperImpl.toFluidStack(stack)), + stack.getFluid().getFluidType().getTemperature(stack), 2.0F, 10); } } @@ -427,9 +421,9 @@ public FluidStack getContainedFluid(int channel) { } private void createTanksList() { - fluidTanks = new FluidStorage[getNodeData().getChannels()]; + fluidTanks = new CustomFluidTank[getNodeData().getChannels()]; for (int i = 0; i < getNodeData().getChannels(); i++) { - fluidTanks[i] = new FluidStorage(getCapacityPerTank()); + fluidTanks[i] = new CustomFluidTank(getCapacityPerTank()); } pipeTankList = new PipeTankList(this, null, fluidTanks); for (Direction facing : GTUtil.DIRECTIONS) { @@ -451,7 +445,7 @@ public PipeTankList getTankList(Direction facing) { return tankLists.getOrDefault(facing, pipeTankList); } - public FluidStorage[] getFluidTanks() { + public CustomFluidTank[] getFluidTanks() { if (pipeTankList == null || fluidTanks == null) { createTanksList(); } @@ -476,7 +470,7 @@ public void saveCustomPersistedData(CompoundTag tag, boolean forDrop) { if (stack1 == null || stack1.getAmount() <= 0) fluidTag.putBoolean("isNull", true); else - stack1.saveToTag(fluidTag); + stack1.writeToNBT(fluidTag); list.add(fluidTag); } tag.put("Fluids", list); @@ -490,7 +484,7 @@ public void loadCustomPersistedData(CompoundTag nbt) { for (int i = 0; i < list.size(); i++) { CompoundTag tag = list.getCompound(i); if (!tag.getBoolean("isNull")) { - fluidTanks[i].setFluid(FluidStack.loadFromTag(tag)); + fluidTanks[i].setFluid(FluidStack.loadFluidStackFromNBT(tag)); } } } @@ -559,11 +553,11 @@ public static void setNeighboursToFire(Level world, BlockPos selfPos) { private static class FluidTransaction { - public final IFluidTransfer target; - public final IFluidTransfer pipeTank; - public long amount; + public final IFluidHandler target; + public final IFluidHandler pipeTank; + public int amount; - private FluidTransaction(IFluidTransfer target, IFluidTransfer pipeTank, long amount) { + private FluidTransaction(IFluidHandler target, IFluidHandler pipeTank, int amount) { this.target = target; this.pipeTank = pipeTank; this.amount = amount; diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java index 19232c0cf6..9fcf56ee00 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java @@ -9,10 +9,10 @@ import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidUtil; import javax.annotation.ParametersAreNonnullByDefault; @@ -33,7 +33,7 @@ public FluidFilterCover(CoverDefinition definition, ICoverable coverHolder, Dire @Override public boolean canAttach() { - return FluidTransferHelper.getFluidTransfer(coverHolder.getLevel(), coverHolder.getPos(), attachedSide) != null; + return FluidUtil.getFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).isPresent(); } public FluidFilter getFluidFilter() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java index 15d8e249b0..7da5d97d24 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java @@ -5,19 +5,21 @@ import com.gregtechceu.gtceu.api.cover.filter.FluidFilter; import com.gregtechceu.gtceu.api.cover.filter.SimpleFluidFilter; import com.gregtechceu.gtceu.api.gui.widget.EnumSelectorWidget; -import com.gregtechceu.gtceu.api.gui.widget.LongInputWidget; +import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; import com.gregtechceu.gtceu.api.gui.widget.NumberInputWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.data.BucketMode; import com.gregtechceu.gtceu.common.cover.data.TransferMode; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -26,7 +28,7 @@ public class FluidRegulatorCover extends PumpCover { - private static final long MAX_STACK_SIZE = 2_048_000_000; // Capacity of quantum tank IX + private static final int MAX_STACK_SIZE = 2_048_000_000; // Capacity of quantum tank IX @Persisted @DescSynced @@ -40,10 +42,10 @@ public class FluidRegulatorCover extends PumpCover { @Persisted @DescSynced @Getter - protected long globalTransferSizeMillibuckets; - protected long fluidTransferBuffered = 0L; + protected int globalTransferSizeMillibuckets; + protected int fluidTransferBuffered = 0; - private NumberInputWidget transferSizeInput; + private NumberInputWidget transferSizeInput; private EnumSelectorWidget transferBucketModeInput; public FluidRegulatorCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide, int tier) { @@ -55,8 +57,8 @@ public FluidRegulatorCover(CoverDefinition definition, ICoverable coverHolder, D ////////////////////////////////////// @Override - protected long doTransferFluidsInternal(IFluidTransfer source, IFluidTransfer destination, - long platformTransferLimit) { + protected int doTransferFluidsInternal(IFluidHandlerModifiable source, IFluidHandlerModifiable destination, + int platformTransferLimit) { return switch (transferMode) { case TRANSFER_ANY -> transferAny(source, destination, platformTransferLimit); case TRANSFER_EXACT -> transferExact(source, destination, platformTransferLimit); @@ -64,80 +66,82 @@ protected long doTransferFluidsInternal(IFluidTransfer source, IFluidTransfer de }; } - private long transferExact(IFluidTransfer source, IFluidTransfer destination, long platformTransferLimit) { - long fluidLeftToTransfer = platformTransferLimit; + private int transferExact(IFluidHandler source, IFluidHandler destination, int platformTransferLimit) { + int fluidLeftToTransfer = platformTransferLimit; for (int slot = 0; slot < source.getTanks(); slot++) { - if (fluidLeftToTransfer <= 0L) + if (fluidLeftToTransfer <= 0) break; FluidStack sourceFluid = source.getFluidInTank(slot).copy(); - long supplyAmount = getFilteredFluidAmount(sourceFluid) * MILLIBUCKET_SIZE; + int supplyAmount = getFilteredFluidAmount(sourceFluid) * MILLIBUCKET_SIZE; // If the remaining transferrable amount in this operation is not enough to transfer the full stack size, // the remaining amount for this operation will be buffered and added to the next operation's maximum. if (fluidLeftToTransfer + fluidTransferBuffered < supplyAmount) { this.fluidTransferBuffered += fluidLeftToTransfer; - fluidLeftToTransfer = 0L; + fluidLeftToTransfer = 0; break; } - if (sourceFluid.isEmpty() || supplyAmount <= 0L) + if (sourceFluid.isEmpty() || supplyAmount <= 0) continue; sourceFluid.setAmount(supplyAmount); - FluidStack drained = source.drain(sourceFluid, true); + FluidStack drained = source.drain(sourceFluid, FluidAction.SIMULATE); if (drained.isEmpty() || drained.getAmount() < supplyAmount) continue; - long insertableAmount = destination.fill(drained.copy(), true); + int insertableAmount = destination.fill(drained.copy(), FluidAction.SIMULATE); if (insertableAmount <= 0) continue; drained.setAmount(insertableAmount); - drained = source.drain(drained, false); + drained = source.drain(drained, FluidAction.EXECUTE); if (!drained.isEmpty()) { - destination.fill(drained, false); + destination.fill(drained, FluidAction.EXECUTE); fluidLeftToTransfer -= (drained.getAmount() - fluidTransferBuffered); } - fluidTransferBuffered = 0L; + fluidTransferBuffered = 0; } return platformTransferLimit - fluidLeftToTransfer; } - private long keepExact(IFluidTransfer source, IFluidTransfer destination, long platformTransferLimit) { - long fluidLeftToTransfer = platformTransferLimit; + private int keepExact(IFluidHandlerModifiable source, IFluidHandlerModifiable destination, + int platformTransferLimit) { + int fluidLeftToTransfer = platformTransferLimit; - final Map sourceAmounts = enumerateDistinctFluids(source, TransferDirection.EXTRACT); - final Map destinationAmounts = enumerateDistinctFluids(destination, TransferDirection.INSERT); + final Map sourceAmounts = enumerateDistinctFluids(source, TransferDirection.EXTRACT); + final Map destinationAmounts = enumerateDistinctFluids(destination, + TransferDirection.INSERT); for (FluidStack fluidStack : sourceAmounts.keySet()) { - if (fluidLeftToTransfer <= 0L) + if (fluidLeftToTransfer <= 0) break; - long amountToKeep = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; - long amountInDest = destinationAmounts.getOrDefault(fluidStack, 0L); + int amountToKeep = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; + int amountInDest = destinationAmounts.getOrDefault(fluidStack, 0); if (amountInDest >= amountToKeep) continue; FluidStack fluidToMove = fluidStack.copy(); fluidToMove.setAmount(Math.min(fluidLeftToTransfer, amountToKeep - amountInDest)); - if (fluidToMove.getAmount() <= 0L) + if (fluidToMove.getAmount() <= 0) continue; - FluidStack drained = source.drain(fluidToMove, true); - long fillableAmount = destination.fill(drained, true); - if (fillableAmount <= 0L) + FluidStack drained = source.drain(fluidToMove, FluidAction.SIMULATE); + int fillableAmount = destination.fill(drained, FluidAction.SIMULATE); + if (fillableAmount <= 0) continue; fluidToMove.setAmount(Math.min(fluidToMove.getAmount(), fillableAmount)); - drained = source.drain(fluidToMove, false); - long movedAmount = destination.fill(drained, false); + drained = source.drain(fluidToMove, FluidAction.EXECUTE); + int movedAmount = destination.fill(drained, FluidAction.EXECUTE); fluidLeftToTransfer -= movedAmount; } @@ -175,13 +179,13 @@ private void setTransferMode(TransferMode transferMode) { @Override protected void configureFilter() { if (filterHandler.getFilter() instanceof SimpleFluidFilter filter) { - filter.setMaxStackSize(transferMode == TransferMode.TRANSFER_ANY ? 1L : MAX_STACK_SIZE); + filter.setMaxStackSize(transferMode == TransferMode.TRANSFER_ANY ? 1 : MAX_STACK_SIZE); } configureTransferSizeInput(); } - private long getFilteredFluidAmount(FluidStack fluidStack) { + private int getFilteredFluidAmount(FluidStack fluidStack) { if (!filterHandler.isFilterPresent()) return globalTransferSizeMillibuckets; @@ -204,9 +208,9 @@ protected void buildAdditionalUI(WidgetGroup group) { group.addWidget( new EnumSelectorWidget<>(146, 45, 20, 20, TransferMode.values(), transferMode, this::setTransferMode)); - this.transferSizeInput = new LongInputWidget(35, 45, 84, 20, - this::getCurrentBucketModeTransferSize, this::setCurrentBucketModeTransferSize).setMin(0L) - .setMax(Long.MAX_VALUE); + this.transferSizeInput = new IntInputWidget(35, 45, 84, 20, + this::getCurrentBucketModeTransferSize, this::setCurrentBucketModeTransferSize).setMin(0) + .setMax(Integer.MAX_VALUE); configureTransferSizeInput(); group.addWidget(this.transferSizeInput); @@ -215,11 +219,11 @@ protected void buildAdditionalUI(WidgetGroup group) { group.addWidget(this.transferBucketModeInput); } - private long getCurrentBucketModeTransferSize() { + private int getCurrentBucketModeTransferSize() { return this.globalTransferSizeMillibuckets / this.transferBucketMode.multiplier; } - private void setCurrentBucketModeTransferSize(long transferSize) { + private void setCurrentBucketModeTransferSize(int transferSize) { this.globalTransferSizeMillibuckets = Math.min(Math.max(transferSize * this.transferBucketMode.multiplier, 0), MAX_STACK_SIZE); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/InfiniteWaterCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/InfiniteWaterCover.java index 8e4e33db2b..73e47ca738 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/InfiniteWaterCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/InfiniteWaterCover.java @@ -5,13 +5,13 @@ import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.api.machine.TickableSubscription; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; - import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; import javax.annotation.ParametersAreNonnullByDefault; @@ -32,7 +32,7 @@ public InfiniteWaterCover(CoverDefinition definition, ICoverable coverHolder, Di @Override public boolean canAttach() { - return FluidTransferHelper.getFluidTransfer(coverHolder.getLevel(), coverHolder.getPos(), attachedSide) != null; + return FluidUtil.getFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).isPresent(); } @Override @@ -51,10 +51,9 @@ public void onRemoved() { public void update() { if (coverHolder.getOffsetTimer() % 20 == 0) { - var fluidHandler = FluidTransferHelper.getFluidTransfer(coverHolder.getLevel(), coverHolder.getPos(), - attachedSide); - if (fluidHandler != null) - fluidHandler.fill(FluidStack.create(Fluids.WATER, 16 * FluidHelper.getBucket()), false); + FluidUtil.getFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide) + .ifPresent(h -> h.fill(new FluidStack(Fluids.WATER, 16 * FluidType.BUCKET_VOLUME), + IFluidHandler.FluidAction.EXECUTE)); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java index a5e4a21d62..86f889a6e9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java @@ -11,21 +11,20 @@ import com.gregtechceu.gtceu.api.cover.filter.FilterHandlers; import com.gregtechceu.gtceu.api.cover.filter.FluidFilter; import com.gregtechceu.gtceu.api.gui.widget.EnumSelectorWidget; -import com.gregtechceu.gtceu.api.gui.widget.LongInputWidget; +import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; import com.gregtechceu.gtceu.api.gui.widget.NumberInputWidget; import com.gregtechceu.gtceu.api.machine.ConditionalSubscriptionHandler; import com.gregtechceu.gtceu.api.transfer.fluid.FluidTransferDelegate; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +import com.gregtechceu.gtceu.api.transfer.fluid.ModifiableFluidHandlerWrapper; import com.gregtechceu.gtceu.common.cover.data.BucketMode; import com.gregtechceu.gtceu.common.cover.data.ManualIOMode; import com.gregtechceu.gtceu.utils.FluidStackHashStrategy; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.annotation.RequireRerender; @@ -38,8 +37,11 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.capability.IFluidHandler; -import it.unimi.dsi.fastutil.objects.Object2LongOpenCustomHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,15 +64,15 @@ public class PumpCover extends CoverBehavior implements IUICover, IControllable public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(PumpCover.class, CoverBehavior.MANAGED_FIELD_HOLDER); - protected static final long MILLIBUCKET_SIZE = FluidHelper.getBucket() / 1000; + protected static final int MILLIBUCKET_SIZE = FluidType.BUCKET_VOLUME / 1000; public final int tier; - public final long maxMilliBucketsPerTick; + public final int maxMilliBucketsPerTick; @Persisted @DescSynced @Getter - protected long currentMilliBucketsPerTick; + protected int currentMilliBucketsPerTick; @Persisted @DescSynced @Getter @@ -88,13 +90,13 @@ public class PumpCover extends CoverBehavior implements IUICover, IControllable @Persisted @Getter protected boolean isWorkingEnabled = true; - protected long milliBucketsLeftToTransferLastSecond; + protected int milliBucketsLeftToTransferLastSecond; @Persisted @DescSynced protected final FilterHandler filterHandler; protected final ConditionalSubscriptionHandler subscriptionHandler; - private NumberInputWidget transferRateWidget; + private NumberInputWidget transferRateWidget; /* * Transfer rate variables are treated as liters/millibuckets per tick. @@ -105,7 +107,7 @@ public PumpCover(CoverDefinition definition, ICoverable coverHolder, Direction a super(definition, coverHolder, attachedSide); this.tier = tier; - this.maxMilliBucketsPerTick = 64 * (long) Math.pow(4, Math.min(tier - 1, GTValues.IV)); // .5b 2b 8b + this.maxMilliBucketsPerTick = 64 * (int) Math.pow(4, Math.min(tier - 1, GTValues.IV)); // .5b 2b 8b this.currentMilliBucketsPerTick = maxMilliBucketsPerTick; this.milliBucketsLeftToTransferLastSecond = currentMilliBucketsPerTick * 20; @@ -121,13 +123,13 @@ protected boolean isSubscriptionActive() { return isWorkingEnabled() && getAdjacentFluidTransfer() != null; } - protected @Nullable IFluidTransfer getOwnFluidTransfer() { + protected @Nullable IFluidHandlerModifiable getOwnFluidTransfer() { return coverHolder.getFluidTransferCap(attachedSide, false); } - protected @Nullable IFluidTransfer getAdjacentFluidTransfer() { - return FluidTransferHelper.getFluidTransfer(coverHolder.getLevel(), coverHolder.getPos().relative(attachedSide), - attachedSide.getOpposite()); + protected @Nullable IFluidHandler getAdjacentFluidTransfer() { + return GTUtil.getAdjacentFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).resolve() + .orElse(null); } ////////////////////////////////////// @@ -187,7 +189,7 @@ public void setWorkingEnabled(boolean isWorkingAllowed) { // ***** Transfer Logic *****// ////////////////////////////////////// - public void setTransferRate(long milliBucketsPerTick) { + public void setTransferRate(int milliBucketsPerTick) { this.currentMilliBucketsPerTick = Math.min(Math.max(milliBucketsPerTick, 0), maxMilliBucketsPerTick); } @@ -221,7 +223,7 @@ protected void update() { return; if (milliBucketsLeftToTransferLastSecond > 0) { - long platformTransferredFluid = doTransferFluids(milliBucketsLeftToTransferLastSecond * MILLIBUCKET_SIZE); + int platformTransferredFluid = doTransferFluids(milliBucketsLeftToTransferLastSecond * MILLIBUCKET_SIZE); this.milliBucketsLeftToTransferLastSecond -= platformTransferredFluid / MILLIBUCKET_SIZE; } @@ -232,28 +234,30 @@ protected void update() { subscriptionHandler.updateSubscription(); } - private long doTransferFluids(long platformTransferLimit) { - var adjacentFluidTransfer = getAdjacentFluidTransfer(); + private int doTransferFluids(int platformTransferLimit) { + var adjacent = getAdjacentFluidTransfer(); + var adjacentModifiable = adjacent instanceof IFluidHandlerModifiable modifiable ? modifiable : + new ModifiableFluidHandlerWrapper(adjacent); var ownFluidTransfer = getOwnFluidTransfer(); - if (adjacentFluidTransfer != null && ownFluidTransfer != null) { + if (adjacent != null && ownFluidTransfer != null) { return switch (io) { - case IN -> doTransferFluidsInternal(adjacentFluidTransfer, ownFluidTransfer, platformTransferLimit); - case OUT -> doTransferFluidsInternal(ownFluidTransfer, adjacentFluidTransfer, platformTransferLimit); - default -> 0L; + case IN -> doTransferFluidsInternal(adjacentModifiable, ownFluidTransfer, platformTransferLimit); + case OUT -> doTransferFluidsInternal(ownFluidTransfer, adjacentModifiable, platformTransferLimit); + default -> 0; }; } return 0; } - protected long doTransferFluidsInternal(IFluidTransfer source, IFluidTransfer destination, - long platformTransferLimit) { + protected int doTransferFluidsInternal(IFluidHandlerModifiable source, IFluidHandlerModifiable destination, + int platformTransferLimit) { return transferAny(source, destination, platformTransferLimit); } - protected long transferAny(IFluidTransfer source, IFluidTransfer destination, long platformTransferLimit) { - return FluidTransferHelper.transferFluids(source, destination, platformTransferLimit, - filterHandler.getFilter()); + protected int transferAny(IFluidHandlerModifiable source, IFluidHandlerModifiable destination, + int platformTransferLimit) { + return GTUtil.transferFiltered(source, destination, platformTransferLimit, filterHandler.getFilter()); } protected enum TransferDirection { @@ -261,8 +265,9 @@ protected enum TransferDirection { EXTRACT } - protected Map enumerateDistinctFluids(IFluidTransfer fluidTransfer, TransferDirection direction) { - final Map summedFluids = new Object2LongOpenCustomHashMap<>( + protected Map enumerateDistinctFluids(IFluidHandlerModifiable fluidTransfer, + TransferDirection direction) { + final Map summedFluids = new Object2IntOpenCustomHashMap<>( FluidStackHashStrategy.comparingAllButAmount()); for (int tank = 0; tank < fluidTransfer.getTanks(); tank++) { @@ -273,7 +278,7 @@ protected Map enumerateDistinctFluids(IFluidTransfer fluidTran if (fluidStack.isEmpty()) continue; - summedFluids.putIfAbsent(fluidStack, 0L); + summedFluids.putIfAbsent(fluidStack, 0); summedFluids.computeIfPresent(fluidStack, (stack, totalAmount) -> { return totalAmount + stack.getAmount(); }); @@ -282,7 +287,7 @@ protected Map enumerateDistinctFluids(IFluidTransfer fluidTran return summedFluids; } - private static boolean canTransfer(IFluidTransfer fluidTransfer, TransferDirection direction, int tank) { + private static boolean canTransfer(IFluidHandlerModifiable fluidTransfer, TransferDirection direction, int tank) { return switch (direction) { case INSERT -> fluidTransfer.supportsFill(tank); case EXTRACT -> fluidTransfer.supportsDrain(tank); @@ -298,8 +303,8 @@ public Widget createUIWidget() { final var group = new WidgetGroup(0, 0, 176, 137); group.addWidget(new LabelWidget(10, 5, LocalizationUtils.format(getUITitle(), GTValues.VN[tier]))); - transferRateWidget = new LongInputWidget(10, 20, 134, 20, - this::getCurrentBucketModeTransferRate, this::setCurrentBucketModeTransferRate).setMin(0L); + transferRateWidget = new IntInputWidget(10, 20, 134, 20, + this::getCurrentBucketModeTransferRate, this::setCurrentBucketModeTransferRate).setMin(0); setBucketMode(this.bucketMode); // initial input widget config happens here group.addWidget(transferRateWidget); @@ -327,11 +332,11 @@ private List getBucketModeTooltip(BucketMode mode, String langKey) { Component.translatable(langKey).append(Component.translatable("gtceu.gui.content.units.per_tick"))); } - private long getCurrentBucketModeTransferRate() { + private int getCurrentBucketModeTransferRate() { return this.currentMilliBucketsPerTick / this.bucketMode.multiplier; } - private void setCurrentBucketModeTransferRate(long transferRate) { + private void setCurrentBucketModeTransferRate(int transferRate) { this.setTransferRate(transferRate * this.bucketMode.multiplier); } @@ -356,7 +361,7 @@ protected void configureFilter() { @Nullable @Override - public IFluidTransfer getFluidTransferCap(@Nullable IFluidTransfer defaultValue) { + public IFluidHandlerModifiable getFluidTransferCap(@Nullable IFluidHandlerModifiable defaultValue) { if (defaultValue == null) { return null; } @@ -368,30 +373,30 @@ public IFluidTransfer getFluidTransferCap(@Nullable IFluidTransfer defaultValue) private class CoverableFluidTransferWrapper extends FluidTransferDelegate { - public CoverableFluidTransferWrapper(IFluidTransfer delegate) { + public CoverableFluidTransferWrapper(IFluidHandlerModifiable delegate) { super(delegate); } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { if (io == IO.OUT && manualIOMode == ManualIOMode.DISABLED) { return 0; } if (!filterHandler.test(resource) && manualIOMode == ManualIOMode.FILTERED) { return 0; } - return super.fill(tank, resource, simulate, notifyChanges); + return super.fill(resource, action); } @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public FluidStack drain(FluidStack resource, FluidAction action) { if (io == IO.IN && manualIOMode == ManualIOMode.DISABLED) { - return FluidStack.empty(); + return FluidStack.EMPTY; } if (manualIOMode == ManualIOMode.FILTERED && !filterHandler.test(resource)) { - return FluidStack.empty(); + return FluidStack.EMPTY; } - return super.drain(tank, resource, simulate, notifyChanges); + return super.drain(resource, action); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/data/BucketMode.java b/src/main/java/com/gregtechceu/gtceu/common/cover/data/BucketMode.java index 059386b461..1768c4e28f 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/data/BucketMode.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/data/BucketMode.java @@ -17,9 +17,9 @@ public enum BucketMode implements EnumSelectorWidget.SelectableEnum { @Getter public final IGuiTexture icon; - public final long multiplier; + public final int multiplier; - BucketMode(String tooltip, String textureName, long multiplier) { + BucketMode(String tooltip, String textureName, int multiplier) { this.tooltip = tooltip; this.icon = new ResourceTexture(textureName + ".png").scale(16F / 20F); this.multiplier = multiplier; diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java index 7639696228..ddab80cf4d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java @@ -7,7 +7,7 @@ import com.gregtechceu.gtceu.api.cover.filter.FilterHandlers; import com.gregtechceu.gtceu.api.cover.filter.FluidFilter; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.api.gui.widget.LongInputWidget; +import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.utils.GTMath; @@ -17,8 +17,6 @@ import com.lowdragmc.lowdraglib.gui.widget.TextBoxWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -27,6 +25,8 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; @@ -51,7 +51,7 @@ public ManagedFieldHolder getFieldHolder() { @Persisted @Getter - private long minValue, maxValue; + private int minValue, maxValue; @Persisted @DescSynced @@ -82,7 +82,7 @@ protected void update() { return; FluidFilter filter = filterHandler.getFilter(); - IFluidTransfer fluidHandler = getFluidTransfer(); + IFluidHandler fluidHandler = getFluidTransfer(); if (fluidHandler == null) return; @@ -99,11 +99,11 @@ protected void update() { RedstoneUtil.computeRedstoneBetweenValues(storedFluid, maxValue, minValue, this.isInverted())); } - public void setMinValue(long minValue) { + public void setMinValue(int minValue) { this.minValue = GTMath.clamp(minValue, 0, maxValue - 1); } - public void setMaxValue(long maxValue) { + public void setMaxValue(int maxValue) { this.maxValue = Math.max(maxValue, 0); } @@ -122,8 +122,8 @@ public Widget createUIWidget() { group.addWidget(new TextBoxWidget(10, 80, 65, List.of(LocalizationUtils.format("cover.advanced_fluid_detector.max")))); - group.addWidget(new LongInputWidget(80, 50, 176 - 80 - 10, 20, this::getMinValue, this::setMinValue)); - group.addWidget(new LongInputWidget(80, 75, 176 - 80 - 10, 20, this::getMaxValue, this::setMaxValue)); + group.addWidget(new IntInputWidget(80, 50, 176 - 80 - 10, 20, this::getMinValue, this::setMinValue)); + group.addWidget(new IntInputWidget(80, 75, 176 - 80 - 10, 20, this::getMaxValue, this::setMaxValue)); // Invert Redstone Output Toggle: group.addWidget(new ToggleButtonWidget( diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java index de79297413..f1ef48fbbd 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java @@ -4,11 +4,10 @@ import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.utils.RedstoneUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; public class FluidDetectorCover extends DetectorCover { @@ -26,12 +25,12 @@ protected void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) return; - IFluidTransfer fluidHandler = getFluidTransfer(); + IFluidHandler fluidHandler = getFluidTransfer(); if (fluidHandler == null) return; - long storedFluid = 0; - long fluidCapacity = 0; + int storedFluid = 0; + int fluidCapacity = 0; for (int tank = 0; tank < fluidHandler.getTanks(); tank++) { FluidStack content = fluidHandler.getFluidInTank(tank); @@ -47,7 +46,8 @@ protected void update() { setRedstoneSignalOutput(RedstoneUtil.computeRedstoneValue(storedFluid, fluidCapacity, isInverted())); } - protected IFluidTransfer getFluidTransfer() { - return FluidTransferHelper.getFluidTransfer(coverHolder.getLevel(), coverHolder.getPos(), attachedSide); + protected IFluidHandler getFluidTransfer() { + return FluidUtil.getFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).resolve() + .orElse(null); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java index e81047e923..ecfeb526ad 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java @@ -5,20 +5,21 @@ import com.gregtechceu.gtceu.api.cover.filter.FluidFilter; import com.gregtechceu.gtceu.api.cover.filter.SimpleFluidFilter; import com.gregtechceu.gtceu.api.gui.widget.EnumSelectorWidget; -import com.gregtechceu.gtceu.api.gui.widget.LongInputWidget; +import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; import com.gregtechceu.gtceu.api.gui.widget.NumberInputWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.data.BucketMode; import com.gregtechceu.gtceu.common.cover.data.VoidingMode; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -39,13 +40,13 @@ public class AdvancedFluidVoidingCover extends FluidVoidingCover { @Persisted @DescSynced @Getter - protected long globalTransferSizeMillibuckets = 1L; + protected int globalTransferSizeMillibuckets = 1; @Persisted @DescSynced @Getter private BucketMode transferBucketMode = BucketMode.MILLI_BUCKET; - private NumberInputWidget stackSizeInput; + private NumberInputWidget stackSizeInput; private EnumSelectorWidget stackSizeBucketModeInput; public AdvancedFluidVoidingCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) { @@ -58,7 +59,7 @@ public AdvancedFluidVoidingCover(CoverDefinition definition, ICoverable coverHol @Override protected void doVoidFluids() { - IFluidTransfer fluidTransfer = getOwnFluidTransfer(); + IFluidHandlerModifiable fluidTransfer = getOwnFluidTransfer(); if (fluidTransfer == null) { return; } @@ -69,23 +70,23 @@ protected void doVoidFluids() { } } - private void voidOverflow(IFluidTransfer fluidTransfer) { - final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); + private void voidOverflow(IFluidHandlerModifiable fluidTransfer) { + final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); for (FluidStack fluidStack : fluidAmounts.keySet()) { - long presentAmount = fluidAmounts.get(fluidStack); - long targetAmount = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; + int presentAmount = fluidAmounts.get(fluidStack); + int targetAmount = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; if (targetAmount <= 0L || targetAmount > presentAmount) continue; var toDrain = fluidStack.copy(); toDrain.setAmount(presentAmount - targetAmount); - fluidTransfer.drain(toDrain, false); + fluidTransfer.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); } } - private long getFilteredFluidAmount(FluidStack fluidStack) { + private int getFilteredFluidAmount(FluidStack fluidStack) { if (!filterHandler.isFilterPresent()) return globalTransferSizeMillibuckets; @@ -127,9 +128,9 @@ protected void buildAdditionalUI(WidgetGroup group) { group.addWidget( new EnumSelectorWidget<>(146, 20, 20, 20, VoidingMode.values(), voidingMode, this::setVoidingMode)); - this.stackSizeInput = new LongInputWidget(35, 20, 84, 20, - this::getCurrentBucketModeTransferSize, this::setCurrentBucketModeTransferSize).setMin(1L) - .setMax(Long.MAX_VALUE); + this.stackSizeInput = new IntInputWidget(35, 20, 84, 20, + this::getCurrentBucketModeTransferSize, this::setCurrentBucketModeTransferSize).setMin(1) + .setMax(Integer.MAX_VALUE); configureStackSizeInput(); group.addWidget(this.stackSizeInput); @@ -138,18 +139,18 @@ protected void buildAdditionalUI(WidgetGroup group) { group.addWidget(this.stackSizeBucketModeInput); } - private long getCurrentBucketModeTransferSize() { + private int getCurrentBucketModeTransferSize() { return this.globalTransferSizeMillibuckets / this.transferBucketMode.multiplier; } - private void setCurrentBucketModeTransferSize(long transferSize) { + private void setCurrentBucketModeTransferSize(int transferSize) { this.globalTransferSizeMillibuckets = Math.max(transferSize * this.transferBucketMode.multiplier, 0); } @Override protected void configureFilter() { if (filterHandler.getFilter() instanceof SimpleFluidFilter filter) { - filter.setMaxStackSize(voidingMode == VoidingMode.VOID_ANY ? 1L : Long.MAX_VALUE); + filter.setMaxStackSize(voidingMode == VoidingMode.VOID_ANY ? 1 : Integer.MAX_VALUE); } configureStackSizeInput(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java index 26374ffa1b..ac5284672b 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java @@ -4,18 +4,19 @@ import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.PumpCover; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -55,15 +56,15 @@ protected void update() { } protected void doVoidFluids() { - IFluidTransfer fluidTransfer = getOwnFluidTransfer(); + IFluidHandlerModifiable fluidTransfer = getOwnFluidTransfer(); if (fluidTransfer == null) { return; } voidAny(fluidTransfer); } - void voidAny(IFluidTransfer fluidTransfer) { - final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); + void voidAny(IFluidHandlerModifiable fluidTransfer) { + final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); for (FluidStack fluidStack : fluidAmounts.keySet()) { if (!filterHandler.test(fluidStack)) @@ -72,7 +73,7 @@ void voidAny(IFluidTransfer fluidTransfer) { var toDrain = fluidStack.copy(); toDrain.setAmount(fluidAmounts.get(fluidStack)); - fluidTransfer.drain(toDrain, false); + fluidTransfer.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java index 167fa50dd5..e9972a71e9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java @@ -39,12 +39,11 @@ import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.utils.FormattingUtil; +import com.gregtechceu.gtceu.utils.GTUtil; import com.gregtechceu.gtceu.utils.SupplierMemoizer; import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.renderer.item.ItemProperties; @@ -63,6 +62,9 @@ import net.minecraftforge.client.model.generators.ModelFile; import net.minecraftforge.common.Tags; import net.minecraftforge.common.TierSortingRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; import com.google.common.collect.ArrayTable; import com.google.common.collect.ImmutableTable; @@ -492,13 +494,9 @@ public static void generateTools() { public static ItemColor cellColor() { return (itemStack, index) -> { if (index == 1) { - var held = FluidTransferHelper.getFluidContained(itemStack); - if (held != null) { - if (held.getFluid() == Fluids.LAVA) { - return 0xFFFF7000; - } - return FluidHelper.getColor(held); - } + return FluidUtil.getFluidContained(itemStack) + .map(f -> f.getFluid() == Fluids.LAVA ? 0xFFFF7000 : GTUtil.getFluidColor(f)) + .orElse(-1); } return -1; }; @@ -509,11 +507,8 @@ public static ICustomDescriptionId cellName() { @Override public Component getItemName(ItemStack stack) { - var held = FluidTransferHelper.getFluidContained(stack); - Component prefix = Component.translatable("gtceu.fluid.empty"); - if (held != null && !held.isEmpty()) { - prefix = FluidHelper.getDisplayName(held); - } + Component prefix = FluidUtil.getFluidContained(stack).map(FluidStack::getDisplayName) + .orElse(Component.translatable("gtceu.fluid.empty")); return Component.translatable(stack.getDescriptionId(), prefix); } }; @@ -525,7 +520,7 @@ public Component getItemName(ItemStack stack) { .color(() -> GTItems::cellColor) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach( - ThermalFluidStats.create((int) FluidHelper.getBucket(), 1800, true, false, false, false, false), + ThermalFluidStats.create(FluidType.BUCKET_VOLUME, 1800, true, false, false, false, false), new ItemFluidContainer(), cellName())) .register(); public static ItemEntry FLUID_CELL_UNIVERSAL = REGISTRATE @@ -535,7 +530,7 @@ public Component getItemName(ItemStack stack) { .setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket(), 1800, true, false, false, false, true), + ThermalFluidStats.create(FluidType.BUCKET_VOLUME, 1800, true, false, false, false, true), new ItemFluidContainer())) .register(); public static ItemEntry FLUID_CELL_LARGE_STEEL = REGISTRATE @@ -545,7 +540,7 @@ public Component getItemName(ItemStack stack) { .setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket() * 8, + ThermalFluidStats.create(FluidType.BUCKET_VOLUME * 8, GTMaterials.Steel.getProperty(PropertyKey.FLUID_PIPE).getMaxFluidTemperature(), true, false, false, false, true), new ItemFluidContainer())) @@ -558,7 +553,7 @@ public Component getItemName(ItemStack stack) { .setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket() * 32, + ThermalFluidStats.create(FluidType.BUCKET_VOLUME * 32, GTMaterials.Aluminium.getProperty(PropertyKey.FLUID_PIPE).getMaxFluidTemperature(), true, false, false, false, true), new ItemFluidContainer())) @@ -571,7 +566,7 @@ public Component getItemName(ItemStack stack) { .setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket() * 64, + ThermalFluidStats.create(FluidType.BUCKET_VOLUME * 64, GTMaterials.StainlessSteel.getProperty(PropertyKey.FLUID_PIPE).getMaxFluidTemperature(), true, false, false, false, true), new ItemFluidContainer())) @@ -585,7 +580,7 @@ public Component getItemName(ItemStack stack) { .setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket() * 128, + ThermalFluidStats.create(FluidType.BUCKET_VOLUME * 128, GTMaterials.Titanium.getProperty(PropertyKey.FLUID_PIPE).getMaxFluidTemperature(), true, false, false, false, true), new ItemFluidContainer())) @@ -599,7 +594,7 @@ public Component getItemName(ItemStack stack) { .properties(p -> p.stacksTo(32)) .onRegister(compassNodeExist(GTCompassSections.ITEMS, "empty_cell")) .onRegister(attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket() * 512, + ThermalFluidStats.create((int) FluidType.BUCKET_VOLUME * 512, GTMaterials.TungstenSteel.getProperty(PropertyKey.FLUID_PIPE).getMaxFluidTemperature(), true, false, false, false, true), new ItemFluidContainer())) @@ -613,7 +608,7 @@ public Component getItemName(ItemStack stack) { .onRegister(compassNode(GTCompassSections.ITEMS)) .onRegister( attach(cellName(), - ThermalFluidStats.create((int) FluidHelper.getBucket(), 1200, false, true, false, false, + ThermalFluidStats.create(FluidType.BUCKET_VOLUME, 1200, false, true, false, false, true), new ItemFluidContainer())) .onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Glass, GTValues.M / 4)))) diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java index f930262e36..595fa14e9f 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java @@ -65,8 +65,6 @@ import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.Platform; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.utils.BlockInfo; import net.minecraft.ChatFormatting; @@ -81,13 +79,15 @@ import net.minecraft.world.level.block.DoorBlock; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fml.ModLoader; import appeng.api.networking.pathing.ChannelMode; import appeng.core.AEConfig; import com.google.common.math.IntMath; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.jetbrains.annotations.Nullable; @@ -127,17 +127,17 @@ public class GTMachines { public static final int[] MULTI_HATCH_TIERS = GTValues.tiersBetween(EV, GTCEuAPI.isHighTier() ? MAX : UHV); public static final int[] DUAL_HATCH_TIERS = GTValues.tiersBetween(LuV, GTCEuAPI.isHighTier() ? MAX : UHV); - public static final Int2LongFunction defaultTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : + public static final Int2IntFunction defaultTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : tier == GTValues.MV ? 12 : tier == GTValues.HV ? 16 : tier == GTValues.EV ? 32 : 64) * - FluidHelper.getBucket(); - public static final Int2LongFunction hvCappedTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : - tier == GTValues.MV ? 12 : 16) * FluidHelper.getBucket(); - public static final Int2LongFunction largeTankSizeFunction = tier -> (tier <= GTValues.LV ? 32 : - tier == GTValues.MV ? 48 : 64) * FluidHelper.getBucket(); - public static final Int2LongFunction steamGeneratorTankSizeFunction = tier -> Math.min(16 * (1 << (tier - 1)), 64) * - FluidHelper.getBucket(); - public static final Int2LongFunction genericGeneratorTankSizeFunction = tier -> Math.min(4 * (1 << (tier - 1)), - 16) * FluidHelper.getBucket(); + FluidType.BUCKET_VOLUME; + public static final Int2IntFunction hvCappedTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : + tier == GTValues.MV ? 12 : 16) * FluidType.BUCKET_VOLUME; + public static final Int2IntFunction largeTankSizeFunction = tier -> (tier <= GTValues.LV ? 32 : + tier == GTValues.MV ? 48 : 64) * FluidType.BUCKET_VOLUME; + public static final Int2IntFunction steamGeneratorTankSizeFunction = tier -> Math.min(16 * (1 << (tier - 1)), 64) * + FluidType.BUCKET_VOLUME; + public static final Int2IntFunction genericGeneratorTankSizeFunction = tier -> Math.min(4 * (1 << (tier - 1)), + 16) * FluidType.BUCKET_VOLUME; public static Object2IntMap DRUM_CAPACITY = new Object2IntArrayMap<>(); @@ -167,7 +167,7 @@ public class GTMachines { .tooltips(Component.translatable("gtceu.universal.tooltip.produces_fluid", (pressure ? ConfigHolder.INSTANCE.machines.smallBoilers.hpSolidBoilerBaseOutput : ConfigHolder.INSTANCE.machines.smallBoilers.solidBoilerBaseOutput) * - FluidHelper.getBucket() / 20000)) + FluidType.BUCKET_VOLUME / 20000)) .register()); public static final Pair STEAM_LIQUID_BOILER = registerSteamMachines( @@ -180,7 +180,7 @@ public class GTMachines { .tooltips(Component.translatable("gtceu.universal.tooltip.produces_fluid", (pressure ? ConfigHolder.INSTANCE.machines.smallBoilers.hpLiquidBoilerBaseOutput : ConfigHolder.INSTANCE.machines.smallBoilers.liquidBoilerBaseOutput) * - FluidHelper.getBucket() / 20000)) + FluidType.BUCKET_VOLUME / 20000)) .register()); public static final Pair STEAM_SOLAR_BOILER = registerSteamMachines( @@ -193,7 +193,7 @@ public class GTMachines { .tooltips(Component.translatable("gtceu.universal.tooltip.produces_fluid", (pressure ? ConfigHolder.INSTANCE.machines.smallBoilers.hpSolarBoilerBaseOutput : ConfigHolder.INSTANCE.machines.smallBoilers.solarBoilerBaseOutput) * - FluidHelper.getBucket() / 20000)) + FluidType.BUCKET_VOLUME / 20000)) .register()); public static final Pair STEAM_EXTRACTOR = registerSimpleSteamMachines( @@ -266,7 +266,7 @@ public class GTMachines { public static final MachineDefinition[] CHEMICAL_BATH = registerSimpleMachines("chemical_bath", GTRecipeTypes.CHEMICAL_BATH_RECIPES, hvCappedTankSizeFunction); public static final MachineDefinition[] CHEMICAL_REACTOR = registerSimpleMachines("chemical_reactor", - GTRecipeTypes.CHEMICAL_RECIPES, tier -> 16 * FluidHelper.getBucket(), true); + GTRecipeTypes.CHEMICAL_RECIPES, tier -> 16 * FluidType.BUCKET_VOLUME, true); public static final MachineDefinition[] COMPRESSOR = registerSimpleMachines("compressor", GTRecipeTypes.COMPRESSOR_RECIPES); public static final MachineDefinition[] CUTTER = registerSimpleMachines("cutter", GTRecipeTypes.CUTTER_RECIPES); @@ -440,7 +440,7 @@ public class GTMachines { Component.translatable("gtceu.universal.tooltip.energy_storage_capacity", FormattingUtil.formatNumbers(GTValues.V[tier] * 64)), Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity", - FormattingUtil.formatNumbers(16 * FluidHelper.getBucket() * Math.max(1, tier))), + FormattingUtil.formatNumbers(16 * FluidType.BUCKET_VOLUME * Math.max(1, tier))), Component.translatable("gtceu.universal.tooltip.working_area", PumpMachine.BASE_PUMP_RANGE + PumpMachine.EXTRA_PUMP_RANGE * tier, PumpMachine.BASE_PUMP_RANGE + PumpMachine.EXTRA_PUMP_RANGE * tier)) @@ -680,7 +680,7 @@ public static BiConsumer> createTankTooltips(String n @Nullable Material material) { return (stack, list) -> { if (stack.hasTag()) { - FluidStack tank = FluidStack.loadFromTag(stack.getOrCreateTagElement(nbtName)); + FluidStack tank = FluidStack.loadFluidStackFromNBT(stack.getOrCreateTagElement(nbtName)); list.add(1, Component.translatable("gtceu.universal.tooltip.fluid_stored", tank.getDisplayName(), FormattingUtil.formatNumbers(tank.getAmount()))); } @@ -697,7 +697,7 @@ public static BiConsumer> createTankTooltips(String n public static final MachineDefinition[] SUPER_TANK = registerTieredMachines("super_tank", (holder, tier) -> new QuantumTankMachine(holder, tier, - 4000L * FluidHelper.getBucket() * (long) Math.pow(2, tier - 1)), + 4000 * FluidType.BUCKET_VOLUME * (int) Math.pow(2, tier - 1)), (tier, builder) -> builder .langValue("Super Tank " + LVT[tier + 1 - LOW_TIERS[0]]) .blockProp(BlockBehaviour.Properties::dynamicShape) @@ -715,7 +715,7 @@ public static BiConsumer> createTankTooltips(String n public static final MachineDefinition[] QUANTUM_TANK = registerTieredMachines("quantum_tank", (holder, tier) -> new QuantumTankMachine(holder, tier, tier == GTValues.UHV ? Integer.MAX_VALUE : - 4000L * FluidHelper.getBucket() * (long) Math.pow(2, tier - 1)), + 4000 * FluidType.BUCKET_VOLUME * (int) Math.pow(2, tier - 1)), (tier, builder) -> builder .langValue("Quantum Tank " + LVT[tier + 1 - LOW_TIERS[0]]) .blockProp(BlockBehaviour.Properties::dynamicShape) @@ -762,22 +762,22 @@ public static BiConsumer> createTankTooltips(String n public static MachineDefinition TUNGSTENSTEEL_CRATE = registerCrate(GTMaterials.TungstenSteel, 144, "Tungstensteel Crate"); - public static MachineDefinition WOODEN_DRUM = registerDrum(GTMaterials.Wood, (int) (16 * FluidHelper.getBucket()), + public static MachineDefinition WOODEN_DRUM = registerDrum(GTMaterials.Wood, (int) (16 * FluidType.BUCKET_VOLUME), "Wooden Barrel"); - public static MachineDefinition BRONZE_DRUM = registerDrum(GTMaterials.Bronze, (int) (32 * FluidHelper.getBucket()), + public static MachineDefinition BRONZE_DRUM = registerDrum(GTMaterials.Bronze, (int) (32 * FluidType.BUCKET_VOLUME), "Bronze Drum"); - public static MachineDefinition STEEL_DRUM = registerDrum(GTMaterials.Steel, (int) (64 * FluidHelper.getBucket()), + public static MachineDefinition STEEL_DRUM = registerDrum(GTMaterials.Steel, (int) (64 * FluidType.BUCKET_VOLUME), "Steel Drum"); public static MachineDefinition ALUMINIUM_DRUM = registerDrum(GTMaterials.Aluminium, - (int) (128 * FluidHelper.getBucket()), "Aluminium Drum"); + (int) (128 * FluidType.BUCKET_VOLUME), "Aluminium Drum"); public static MachineDefinition STAINLESS_STEEL_DRUM = registerDrum(GTMaterials.StainlessSteel, - (int) (256 * FluidHelper.getBucket()), "Stainless Steel Drum"); - public static MachineDefinition GOLD_DRUM = registerDrum(GTMaterials.Gold, (int) (32 * FluidHelper.getBucket()), + (int) (256 * FluidType.BUCKET_VOLUME), "Stainless Steel Drum"); + public static MachineDefinition GOLD_DRUM = registerDrum(GTMaterials.Gold, (int) (32 * FluidType.BUCKET_VOLUME), "Gold Drum"); public static MachineDefinition TITANIUM_DRUM = registerDrum(GTMaterials.Titanium, - (int) (512 * FluidHelper.getBucket()), "Titanium Drum"); + (int) (512 * FluidType.BUCKET_VOLUME), "Titanium Drum"); public static MachineDefinition TUNGSTENSTEEL_DRUM = registerDrum(GTMaterials.TungstenSteel, - (int) (1024 * FluidHelper.getBucket()), "Tungstensteel Drum"); + (int) (1024 * FluidType.BUCKET_VOLUME), "Tungstensteel Drum"); ////////////////////////////////////// // ********** Part **********// @@ -1083,7 +1083,7 @@ public static BiConsumer> createTankTooltips(String n .overlayTieredHullRenderer("fluid_passthrough_hatch") .tooltips( Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity_mult", tier + 1, - 16 * FluidHelper.getBucket()), + 16 * FluidType.BUCKET_VOLUME), Component.translatable("gtceu.universal.enabled")) .compassNode("fluid_passthrough_hatch") .register(), @@ -2229,7 +2229,7 @@ public static MachineDefinition[] registerTieredMachines(String name, } private static MachineDefinition[] registerFluidHatches(String name, String displayname, String model, - String tooltip, IO io, long initialCapacity, int slots, + String tooltip, IO io, int initialCapacity, int slots, int[] tiers, PartAbility... abilities) { return registerTieredMachines(name, (holder, tier) -> new FluidHatchPartMachine(holder, tier, io, initialCapacity, slots), @@ -2286,7 +2286,7 @@ public static MachineDefinition[] registerTransformerMachines(String langName, i public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeType recipeType, - Int2LongFunction tankScalingFunction, + Int2IntFunction tankScalingFunction, boolean hasPollutionDebuff, int... tiers) { return registerTieredMachines(name, @@ -2315,13 +2315,13 @@ public static MachineDefinition[] registerSimpleMachines(String name, } public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeType recipeType, - Int2LongFunction tankScalingFunction, + Int2IntFunction tankScalingFunction, boolean hasPollutionDebuff) { return registerSimpleMachines(name, recipeType, tankScalingFunction, hasPollutionDebuff, ELECTRIC_TIERS); } public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeType recipeType, - Int2LongFunction tankScalingFunction) { + Int2IntFunction tankScalingFunction) { return registerSimpleMachines(name, recipeType, tankScalingFunction, false); } @@ -2331,7 +2331,7 @@ public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeTy public static MachineDefinition[] registerSimpleGenerator(String name, GTRecipeType recipeType, - Int2LongFunction tankScalingFunction, + Int2IntFunction tankScalingFunction, float hazardStrengthPerOperation, int... tiers) { return registerTieredMachines(name, @@ -2575,7 +2575,7 @@ public static MultiblockMachineDefinition registerLargeCombustionEngine(String n .tooltips( Component.translatable("gtceu.universal.tooltip.base_production_eut", V[tier]), Component.translatable("gtceu.universal.tooltip.uses_per_hour_lubricant", - FluidHelper.getBucket()), + FluidType.BUCKET_VOLUME), tier > EV ? Component.translatable("gtceu.machine.large_combustion_engine.tooltip.boost_extreme", V[tier] * 4) : diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index 84f8f6eae1..b81adaba73 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -9,11 +9,13 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.recipe.*; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.sound.ExistingSoundEntry; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.gregtechceu.gtceu.common.machine.trait.customlogic.CannerLogic; import com.gregtechceu.gtceu.common.machine.trait.customlogic.FormingPressLogic; import com.gregtechceu.gtceu.common.recipe.condition.RPMCondition; @@ -24,10 +26,7 @@ import com.gregtechceu.gtceu.utils.ResearchManager; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; -import com.lowdragmc.lowdraglib.misc.FluidStorage; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.utils.CycleItemStackHandler; import com.lowdragmc.lowdraglib.utils.LocalizationUtils; @@ -39,6 +38,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.ModLoader; import com.simibubi.create.AllBlocks; @@ -434,12 +434,12 @@ public class GTRecipeTypes { var fluidA = BuiltInRegistries.FLUID.get(new ResourceLocation(recipe.data.getString("fluidA"))); var fluidB = BuiltInRegistries.FLUID.get(new ResourceLocation(recipe.data.getString("fluidB"))); if (fluidA != Fluids.EMPTY) { - widgetGroup.addWidget(new TankWidget(new FluidStorage(FluidStack.create(fluidA, 1000)), + widgetGroup.addWidget(new TankWidget(new CustomFluidTank(new FluidStack(fluidA, 1000)), widgetGroup.getSize().width - 30, widgetGroup.getSize().height - 30, false, false) .setBackground(GuiTextures.FLUID_SLOT).setShowAmount(false)); } if (fluidB != Fluids.EMPTY) { - widgetGroup.addWidget(new TankWidget(new FluidStorage(FluidStack.create(fluidB, 1000)), + widgetGroup.addWidget(new TankWidget(new CustomFluidTank(new FluidStack(fluidB, 1000)), widgetGroup.getSize().width - 30 - 20, widgetGroup.getSize().height - 30, false, false) .setBackground(GuiTextures.FLUID_SLOT).setShowAmount(false)); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java b/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java index bccafad419..6fadbaf11c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java @@ -3,10 +3,10 @@ import com.gregtechceu.gtceu.api.item.component.IRecipeRemainder; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidType; /** * @author KilaBash @@ -20,9 +20,9 @@ public ItemStack getRecipeRemained(ItemStack itemStack) { var storage = new ItemStackTransfer(itemStack); var transfer = FluidTransferHelper.getFluidTransfer(storage, 0); if (transfer != null) { - var drained = transfer.drain(FluidHelper.getBucket(), true); - if (drained.getAmount() != FluidHelper.getBucket()) return ItemStack.EMPTY; - transfer.drain(FluidHelper.getBucket(), false); + var drained = transfer.drain(FluidType.BUCKET_VOLUME, true); + if (drained.getAmount() != FluidType.BUCKET_VOLUME) return ItemStack.EMPTY; + transfer.drain(FluidType.BUCKET_VOLUME, false); var copied = storage.getStackInSlot(0); copied.setTag(null); return copied; diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java index 78d2c974cf..3306532c1d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java @@ -17,11 +17,6 @@ import com.gregtechceu.gtceu.utils.input.KeyBind; import com.lowdragmc.lowdraglib.Platform; -import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.NonNullList; @@ -38,6 +33,9 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack; import com.google.common.collect.Table; @@ -67,7 +65,7 @@ public PowerlessJetpack() { @Override public void onArmorTick(Level world, Player player, @NotNull ItemStack stack) { - IFluidTransfer internalTank = FluidTransferHelper.getFluidTransfer(new ItemStackTransfer(stack), 0); + IFluidHandler internalTank = FluidUtil.getFluidHandler(stack).resolve().orElse(null); if (internalTank == null) return; @@ -137,7 +135,7 @@ public ResourceLocation getArmorTexture(ItemStack stack, Entity entity, Equipmen @OnlyIn(Dist.CLIENT) @Override public void drawHUD(@NotNull ItemStack item, GuiGraphics guiGraphics) { - IFluidTransfer tank = FluidTransferHelper.getFluidTransfer(new ItemStackTransfer(item), 0); + IFluidHandler tank = FluidUtil.getFluidHandler(item).resolve().orElse(null); if (tank != null) { if (tank.getFluidInTank(0).getAmount() == 0) return; String formated = String.format("%.1f", @@ -178,11 +176,11 @@ public boolean canUseEnergy(ItemStack stack, int amount) { return false; } - IFluidTransfer fluidHandlerItem = getIFluidHandlerItem(stack); + IFluidHandler fluidHandlerItem = getIFluidHandlerItem(stack); if (fluidHandlerItem == null) return false; - com.lowdragmc.lowdraglib.side.fluid.FluidStack fluidStack = fluidHandlerItem.drain(fuel, false); + FluidStack fluidStack = fluidHandlerItem.drain(fuel, IFluidHandler.FluidAction.EXECUTE); if (fluidStack.isEmpty()) return false; @@ -194,7 +192,7 @@ public void drainEnergy(ItemStack stack, int amount) { if (this.burnTimer == 0) { FluidStack fuel = getFuel(); if (fuel == null) return; - getIFluidHandlerItem(stack).drain(fuel, true); + getIFluidHandlerItem(stack).drain(fuel, IFluidHandler.FluidAction.SIMULATE); burnTimer = currentRecipe.duration; } this.burnTimer--; @@ -205,14 +203,14 @@ public boolean hasEnergy(ItemStack stack) { return burnTimer > 0 || currentRecipe != null; } - private static IFluidTransfer getIFluidHandlerItem(@NotNull ItemStack stack) { - return FluidTransferHelper.getFluidTransfer(new ItemStackTransfer(stack), 0); + private static IFluidHandler getIFluidHandlerItem(@NotNull ItemStack stack) { + return FluidUtil.getFluidHandler(stack).resolve().orElse(null); } public void findNewRecipe(@NotNull ItemStack stack) { - IFluidTransfer internalTank = getIFluidHandlerItem(stack); + IFluidHandler internalTank = getIFluidHandlerItem(stack); if (internalTank != null) { - com.lowdragmc.lowdraglib.side.fluid.FluidStack fluidStack = internalTank.drain(1, false); + FluidStack fluidStack = internalTank.drain(1, IFluidHandler.FluidAction.EXECUTE); if (previousRecipe != null && !fluidStack.isEmpty() && FluidRecipeCapability.CAP.of(previousRecipe.getInputContents(FluidRecipeCapability.CAP).get(0)) .test(fluidStack) && @@ -222,7 +220,7 @@ public void findNewRecipe(@NotNull ItemStack stack) { } else if (!fluidStack.isEmpty()) { Table, List>> table = Tables .newCustomTable(new EnumMap<>(IO.class), IdentityHashMap::new); - FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Long.MAX_VALUE); + FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Integer.MAX_VALUE); handler.getStorages()[0].setFluid(fluidStack); table.put(IO.IN, FluidRecipeCapability.CAP, Collections.singletonList(handler)); table.put(IO.OUT, EURecipeCapability.CAP, Collections.singletonList(new IgnoreEnergyRecipeHandler())); @@ -260,7 +258,7 @@ public FluidStack getFuel() { return fluid.getStacks()[0]; } - return FluidStack.empty(); + return FluidStack.EMPTY; } /* @@ -281,7 +279,7 @@ public static class Behaviour implements IDurabilityBar, IItemComponent, ISubIte private static final Predicate JETPACK_FUEL_FILTER = fluidStack -> { Table, List>> table = Tables .newCustomTable(new EnumMap<>(IO.class), IdentityHashMap::new); - FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Long.MAX_VALUE); + FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Integer.MAX_VALUE); handler.getStorages()[0].setFluid(fluidStack); table.put(IO.IN, FluidRecipeCapability.CAP, Collections.singletonList(handler)); table.put(IO.OUT, EURecipeCapability.CAP, Collections.singletonList(new IgnoreEnergyRecipeHandler())); @@ -306,7 +304,7 @@ public Behaviour(int internalCapacity) { @Override public float getDurabilityForDisplay(@NotNull ItemStack itemStack) { - IFluidTransfer fluidHandlerItem = FluidTransferHelper.getFluidTransfer(new ItemStackTransfer(itemStack), 0); + IFluidHandler fluidHandlerItem = FluidUtil.getFluidHandler(itemStack).resolve().orElse(null); if (fluidHandlerItem == null) return 0; FluidStack fluidStack = fluidHandlerItem.getFluidInTank(0); return fluidStack.isEmpty() ? 0 : @@ -326,7 +324,7 @@ public Pair getDurabilityColorsForDisplay(ItemStack itemStack) @Override public boolean canFillFluidType(net.minecraftforge.fluids.FluidStack fluid) { - return JETPACK_FUEL_FILTER.test(FluidHelperImpl.toFluidStack(fluid)); + return JETPACK_FUEL_FILTER.test(fluid); } })); } @@ -350,9 +348,9 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List items) { ItemStack copy = item.getDefaultInstance(); - IFluidTransfer fluidHandlerItem = FluidTransferHelper.getFluidTransfer(new ItemStackTransfer(copy), 0); + IFluidHandler fluidHandlerItem = FluidUtil.getFluidHandler(copy).resolve().orElse(null); if (fluidHandlerItem != null) { - fluidHandlerItem.fill(GTMaterials.Diesel.getFluid(tankCapacity), true); + fluidHandlerItem.fill(GTMaterials.Diesel.getFluid(tankCapacity), IFluidHandler.FluidAction.SIMULATE); items.add(copy); } else { items.add(copy); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java index 1ea15684a6..22d2ed2ea9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java @@ -7,10 +7,6 @@ import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.misc.forge.VoidFluidHandlerItemStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; @@ -21,6 +17,9 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,23 +47,24 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { return InteractionResult.PASS; } - IFluidTransfer fluidHandler; + IFluidHandler fluidHandler; if (context.getLevel() .getBlockEntity(context.getClickedPos()) instanceof IMachineBlockEntity metaMachineBlockEntity) { fluidHandler = metaMachineBlockEntity.getMetaMachine().getFluidTransferCap(context.getClickedFace(), false); } else { - fluidHandler = FluidTransferHelper.getFluidTransfer(context.getLevel(), context.getClickedPos(), - context.getClickedFace()); + fluidHandler = FluidUtil + .getFluidHandler(context.getLevel(), context.getClickedPos(), context.getClickedFace()).resolve() + .orElse(null); } if (fluidHandler == null) { return InteractionResult.PASS; } - com.lowdragmc.lowdraglib.side.fluid.FluidStack drained = fluidHandler.drain(FluidHelper.getBucket(), true); - if (drained != null && !drained.isEmpty()) { - fluidHandler.drain(FluidHelper.getBucket(), false); + FluidStack drained = fluidHandler.drain(FluidType.BUCKET_VOLUME, IFluidHandler.FluidAction.SIMULATE); + if (!drained.isEmpty()) { + fluidHandler.drain(FluidType.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE); ToolHelper.onActionDone(context.getPlayer(), context.getLevel(), context.getHand()); return InteractionResult.CONSUME; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/kinetic/SimpleKineticElectricWorkableMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/kinetic/SimpleKineticElectricWorkableMachine.java index 346f645009..a1ee08e353 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/kinetic/SimpleKineticElectricWorkableMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/kinetic/SimpleKineticElectricWorkableMachine.java @@ -12,7 +12,7 @@ import net.minecraft.core.Direction; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; import javax.annotation.ParametersAreNonnullByDefault; @@ -34,7 +34,7 @@ public class SimpleKineticElectricWorkableMachine extends SimpleTieredMachine im protected final NotifiableStressTrait stressTrait; public SimpleKineticElectricWorkableMachine(IMachineBlockEntity holder, int tier, - Int2LongFunction tankScalingFunction, Object... args) { + Int2IntFunction tankScalingFunction, Object... args) { super(holder, tier, tankScalingFunction, args); this.stressTrait = createStressTrait(args); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/AssemblyLineMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/AssemblyLineMachine.java index 16fcccbb96..2717f9eedc 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/AssemblyLineMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/AssemblyLineMachine.java @@ -11,11 +11,10 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.config.ConfigHolder; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/FusionReactorMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/FusionReactorMachine.java index 6826b5d5a3..9627ff327c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/FusionReactorMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/FusionReactorMachine.java @@ -21,8 +21,8 @@ import com.gregtechceu.gtceu.api.recipe.logic.OCParams; import com.gregtechceu.gtceu.api.recipe.logic.OCResult; import com.gregtechceu.gtceu.common.block.FusionCasingBlock; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -208,10 +208,9 @@ public boolean onWorking() { if (color == -1) { if (!recipe.getOutputContents(FluidRecipeCapability.CAP).isEmpty()) { - int newColor = 0xFF000000 | - FluidHelper.getColor(FluidRecipeCapability.CAP - .of(recipe.getOutputContents(FluidRecipeCapability.CAP).get(0).getContent()) - .getStacks()[0]); + var stack = FluidRecipeCapability.CAP + .of(recipe.getOutputContents(FluidRecipeCapability.CAP).get(0).getContent()).getStacks()[0]; + int newColor = 0xFF000000 | GTUtil.getFluidColor(stack); if (!Objects.equals(color, newColor)) { color = newColor; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java index 9dd535aea6..43f734257a 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java @@ -15,6 +15,7 @@ import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; import com.gregtechceu.gtceu.api.misc.EnergyContainerList; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.common.item.PortableScannerBehavior; @@ -24,9 +25,6 @@ import com.lowdragmc.lowdraglib.gui.util.ClickData; import com.lowdragmc.lowdraglib.gui.widget.ComponentPanelWidget; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.ChatFormatting; @@ -39,6 +37,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import lombok.Getter; @@ -126,7 +126,7 @@ public void onStructureFormed() { private void initializeAbilities() { List energyContainers = new ArrayList<>(); - List fluidTanks = new ArrayList<>(); + List fluidTanks = new ArrayList<>(); Map ioMap = getMultiblockState().getMatchContext().getOrCreate("ioMap", Long2ObjectMaps::emptyMap); for (IMultiPart part : getParts()) { IO io = ioMap.getOrDefault(part.self().getPos().asLong(), IO.BOTH); @@ -139,7 +139,7 @@ private void initializeAbilities() { handler instanceof IEnergyContainer container) { energyContainers.add(container); } else if (handlerIO == IO.IN && handler.getCapability() == FluidRecipeCapability.CAP && - handler instanceof IFluidTransfer fluidTransfer) { + handler instanceof IFluidHandler fluidTransfer) { fluidTanks.add(fluidTransfer); } } @@ -179,12 +179,13 @@ public boolean drainInput(boolean simulate) { // drain fluid if (inputFluidInventory != null && inputFluidInventory.transfers.length > 0) { FluidStack drillingFluid = DrillingFluid - .getFluid((long) this.drillingFluidConsumePerTick * getRecipeLogic().getOverclockAmount()); + .getFluid(this.drillingFluidConsumePerTick * getRecipeLogic().getOverclockAmount()); FluidStack fluidStack = inputFluidInventory.getFluidInTank(0); - if (fluidStack != FluidStack.empty() && fluidStack.isFluidEqual(DrillingFluid.getFluid(1)) && + if (fluidStack != FluidStack.EMPTY && fluidStack.isFluidEqual(DrillingFluid.getFluid(1)) && fluidStack.getAmount() >= drillingFluid.getAmount()) { if (!simulate) { - GTTransferUtils.drainFluidAccountNotifiableList(inputFluidInventory, drillingFluid, false); + GTTransferUtils.drainFluidAccountNotifiableList(inputFluidInventory, drillingFluid, + IFluidHandler.FluidAction.EXECUTE); } } else { return false; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java index b6f3308ac4..5dfd486534 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java @@ -7,9 +7,12 @@ import com.gregtechceu.gtceu.api.machine.feature.IFancyUIMachine; import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockControllerMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; -import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import com.lowdragmc.lowdraglib.gui.widget.Widget; +import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -21,6 +24,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -83,7 +87,7 @@ public Widget createUIWidget() { } private String getFluidLabel() { - return String.valueOf(tank.getFluidInTank(0).getAmount() / (FluidHelper.getBucket() / 1000)); + return String.valueOf(tank.getFluidInTank(0).getAmount() / (FluidType.BUCKET_VOLUME / 1000)); } ////////////////////////////////////// diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java index 68ceec0eaf..42df960593 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java @@ -17,6 +17,7 @@ import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; import com.gregtechceu.gtceu.api.misc.EnergyContainerList; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; @@ -30,9 +31,6 @@ import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.IManaged; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; @@ -50,6 +48,8 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -73,7 +73,7 @@ public class HPCAMachine extends WorkableElectricMultiblockMachine private IMaintenanceMachine maintenance; private IEnergyContainer energyContainer; - private IFluidTransfer coolantHandler; + private IFluidHandler coolantHandler; @Persisted @DescSynced private final HPCAGridHandler hpcaHandler; @@ -99,7 +99,7 @@ public HPCAMachine(IMachineBlockEntity holder, Object... args) { public void onStructureFormed() { super.onStructureFormed(); List energyContainers = new ArrayList<>(); - List coolantContainers = new ArrayList<>(); + List coolantContainers = new ArrayList<>(); List componentHatches = new ArrayList<>(); Map ioMap = getMultiblockState().getMatchContext().getOrCreate("ioMap", Long2ObjectMaps::emptyMap); for (IMultiPart part : getParts()) { @@ -118,7 +118,7 @@ public void onStructureFormed() { handler instanceof IEnergyContainer container) { energyContainers.add(container); } else if (handler.getCapability() == FluidRecipeCapability.CAP && - handler instanceof IFluidTransfer fluidHandler) { + handler instanceof IFluidHandler fluidHandler) { coolantContainers.add(fluidHandler); } } @@ -444,7 +444,7 @@ public void tick() { * decreasing due to passive coolers. Used when the HPCA is running very hot. * @return The temperature change, can be positive or negative. */ - public double calculateTemperatureChange(IFluidTransfer coolantTank, boolean forceCoolWithActive) { + public double calculateTemperatureChange(IFluidHandler coolantTank, boolean forceCoolWithActive) { // calculate temperature increase int maxCWUt = Math.max(1, getMaxCWUt()); // avoids dividing by 0 and the behavior is no different int maxCoolingDemand = getMaxCoolingDemand(); @@ -456,7 +456,7 @@ public double calculateTemperatureChange(IFluidTransfer coolantTank, boolean for // calculate temperature decrease long maxPassiveCooling = 0; long maxActiveCooling = 0; - long maxCoolantDrain = 0; + int maxCoolantDrain = 0; for (var coolantProvider : coolantProviders) { if (coolantProvider.isActiveCooler()) { @@ -475,7 +475,7 @@ public double calculateTemperatureChange(IFluidTransfer coolantTank, boolean for if (forceCoolWithActive || maxActiveCooling <= temperatureChange) { // try to fully utilize active coolers FluidStack coolantStack = GTTransferUtils.drainFluidAccountNotifiableList(coolantTank, - getCoolantStack(maxCoolantDrain), false); + getCoolantStack(maxCoolantDrain), IFluidHandler.FluidAction.EXECUTE); if (!coolantStack.isEmpty()) { long coolantDrained = coolantStack.getAmount(); if (coolantDrained == maxCoolantDrain) { @@ -490,11 +490,11 @@ public double calculateTemperatureChange(IFluidTransfer coolantTank, boolean for } else if (temperatureChange > 0) { // try to partially utilize active coolers to stabilize to zero double temperatureToDecrease = Math.min(temperatureChange, maxActiveCooling); - long coolantToDrain = Math.max(1, (int) (maxCoolantDrain * (temperatureToDecrease / maxActiveCooling))); + int coolantToDrain = Math.max(1, (int) (maxCoolantDrain * (temperatureToDecrease / maxActiveCooling))); FluidStack coolantStack = GTTransferUtils.drainFluidAccountNotifiableList(coolantTank, - getCoolantStack(coolantToDrain), false); + getCoolantStack(coolantToDrain), IFluidHandler.FluidAction.EXECUTE); if (!coolantStack.isEmpty()) { - long coolantDrained = coolantStack.getAmount(); + int coolantDrained = coolantStack.getAmount(); if (coolantDrained == coolantToDrain) { // successfully stabilized to zero return 0; @@ -512,8 +512,8 @@ public double calculateTemperatureChange(IFluidTransfer coolantTank, boolean for * Get the coolant stack for this HPCA. Eventually this could be made more diverse with different * coolants from different Active Cooler components, but currently it is just a fixed Fluid. */ - public FluidStack getCoolantStack(long amount) { - return FluidStack.create(getCoolant(), amount); + public FluidStack getCoolantStack(int amount) { + return new FluidStack(getCoolant(), amount); } private Fluid getCoolant() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/generator/LargeCombustionEngineMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/generator/LargeCombustionEngineMachine.java index cb903a0813..45771e4f48 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/generator/LargeCombustionEngineMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/generator/LargeCombustionEngineMachine.java @@ -18,13 +18,12 @@ import com.gregtechceu.gtceu.common.data.GTRecipeModifiers; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; +import net.minecraftforge.fluids.FluidStack; import lombok.Getter; import lombok.val; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java index 3d25ef3bd4..99b7383aa5 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java @@ -8,8 +8,8 @@ import com.gregtechceu.gtceu.api.machine.trait.FluidTankProxyTrait; import com.gregtechceu.gtceu.api.machine.trait.ItemHandlerProxyTrait; import com.gregtechceu.gtceu.common.machine.multiblock.primitive.CokeOvenMachine; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -133,8 +133,7 @@ public void onRotated(Direction oldFacing, Direction newFacing) { protected void updateAutoIOSubscription() { if ((!outputInventory.isEmpty() && ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null) || - (!tank.isEmpty() && FluidTransferHelper.getFluidTransfer(getLevel(), - getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null)) { + (!tank.isEmpty() && GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()))) { autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO); } else if (autoIOSubs != null) { autoIOSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java index a7cd048164..1ab94c63bb 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java @@ -4,20 +4,20 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.jei.IngredientIO; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; @@ -27,7 +27,7 @@ @MethodsReturnNonnullByDefault public class DualHatchPartMachine extends ItemBusPartMachine { - public static final long INITIAL_TANK_CAPACITY = 16 * FluidHelper.getBucket(); + public static final int INITIAL_TANK_CAPACITY = 16 * FluidType.BUCKET_VOLUME; protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(DualHatchPartMachine.class, ItemBusPartMachine.MANAGED_FIELD_HOLDER); @@ -49,8 +49,8 @@ public DualHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, Object. // ***** Initialization ******// //////////////////////////////// - public static long getTankCapacity(long initialCapacity, int tier) { - return initialCapacity * (1L << (tier - 6)); + public static int getTankCapacity(int initialCapacity, int tier) { + return initialCapacity * (1 << (tier - 6)); } @Override @@ -58,7 +58,7 @@ public int getInventorySize() { return (int) Math.pow((getTier() - 4), 2); } - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { return new NotifiableFluidTank(this, slots, getTankCapacity(initialCapacity, getTier()), io); } @@ -88,8 +88,7 @@ protected void updateInventorySubscription() { if (level != null) { this.hasItemTransfer = ItemTransferHelper.getItemTransfer( level, getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null; - this.hasFluidTransfer = FluidTransferHelper.getFluidTransfer( - level, getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null; + this.hasFluidTransfer = GTUtil.isAdjacentFluidHandler(level, getPos(), getFrontFacing()); } else { this.hasItemTransfer = false; this.hasFluidTransfer = false; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java index 5bc0db7db2..e6904fdc85 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java @@ -11,13 +11,16 @@ import com.gregtechceu.gtceu.api.machine.multiblock.part.TieredIOPartMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; +import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.item.IntCircuitBehaviour; import com.gregtechceu.gtceu.config.ConfigHolder; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import com.lowdragmc.lowdraglib.gui.widget.Widget; +import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -29,6 +32,8 @@ import net.minecraft.server.TickTask; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.Block; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -47,9 +52,9 @@ public class FluidHatchPartMachine extends TieredIOPartMachine implements IMachi protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(FluidHatchPartMachine.class, TieredIOPartMachine.MANAGED_FIELD_HOLDER); - public static final long INITIAL_TANK_CAPACITY_1X = 8 * FluidHelper.getBucket(); - public static final long INITIAL_TANK_CAPACITY_4X = 2 * FluidHelper.getBucket(); - public static final long INITIAL_TANK_CAPACITY_9X = FluidHelper.getBucket(); + public static final int INITIAL_TANK_CAPACITY_1X = 8 * FluidType.BUCKET_VOLUME; + public static final int INITIAL_TANK_CAPACITY_4X = 2 * FluidType.BUCKET_VOLUME; + public static final int INITIAL_TANK_CAPACITY_9X = FluidType.BUCKET_VOLUME; @Persisted public final NotifiableFluidTank tank; @@ -64,7 +69,7 @@ public class FluidHatchPartMachine extends TieredIOPartMachine implements IMachi // The `Object... args` parameter is necessary in case a superclass needs to pass any args along to createTank(). // We can't use fields here because those won't be available while createTank() is called. - public FluidHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, long initialCapacity, int slots, + public FluidHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, int initialCapacity, int slots, Object... args) { super(holder, tier, io); this.slots = slots; @@ -80,12 +85,12 @@ public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { return new NotifiableFluidTank(this, slots, getTankCapacity(initialCapacity, getTier()), io); } - public static long getTankCapacity(long initialCapacity, int tier) { - return initialCapacity * (1L << Math.min(9, tier)); + public static int getTankCapacity(int initialCapacity, int tier) { + return initialCapacity * (1 << Math.min(9, tier)); } protected NotifiableItemStackHandler createCircuitItemHandler(Object... args) { @@ -140,8 +145,7 @@ public void onRotated(Direction oldFacing, Direction newFacing) { protected void updateTankSubscription() { if (isWorkingEnabled() && ((io == IO.OUT && !tank.isEmpty()) || io == IO.IN) && - FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(getFrontFacing()), - getFrontFacing().getOpposite()) != null) { + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing())) { autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO); } else if (autoIOSubs != null) { autoIOSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java index 5e0aac7a62..0fd1285345 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java @@ -6,16 +6,16 @@ import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.world.entity.player.Player; +import net.minecraftforge.fluids.FluidType; import javax.annotation.ParametersAreNonnullByDefault; @@ -24,11 +24,11 @@ public class PumpHatchPartMachine extends FluidHatchPartMachine { public PumpHatchPartMachine(IMachineBlockEntity holder, Object... args) { - super(holder, 0, IO.OUT, FluidHelper.getBucket(), 1, args); + super(holder, 0, IO.OUT, FluidType.BUCKET_VOLUME, 1, args); } @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { return super.createTank(initialCapacity, slots) .setFilter(fluidStack -> fluidStack.getFluid().is(GTMaterials.Water.getFluidTag())); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ReservoirHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ReservoirHatchPartMachine.java index 910f2ca4b2..4c1fcd1227 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ReservoirHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ReservoirHatchPartMachine.java @@ -4,13 +4,12 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; - -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidStack; import java.util.Collections; @@ -22,7 +21,7 @@ public class ReservoirHatchPartMachine extends FluidHatchPartMachine { protected InfiniteWaterTank waterTank; - public static final long FLUID_AMOUNT = 2_000_000_000L; + public static final int FLUID_AMOUNT = 2_000_000_000; public ReservoirHatchPartMachine(IMachineBlockEntity holder, Object... args) { super(holder, GTValues.EV, IO.IN, FLUID_AMOUNT, 1, args); @@ -33,7 +32,7 @@ public ReservoirHatchPartMachine(IMachineBlockEntity holder, Object... args) { ////////////////////////////////// @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { this.waterTank = new InfiniteWaterTank(initialCapacity); // allow both importing and exporting from the tank return new NotifiableFluidTank(this, Collections.singletonList(waterTank), io, IO.BOTH); @@ -62,20 +61,20 @@ protected void autoIO() { } } - protected static class InfiniteWaterTank extends FluidStorage { + protected static class InfiniteWaterTank extends CustomFluidTank { private static final CompoundTag EMPTY = new CompoundTag(); - private static final FluidStack WATER = FluidStack.create(Fluids.WATER, Long.MAX_VALUE); + private static final FluidStack WATER = new FluidStack(Fluids.WATER, Integer.MAX_VALUE); - public InfiniteWaterTank(long capacity) { + public InfiniteWaterTank(int capacity) { super(capacity); // start with the full amount - setFluid(FluidStack.create(Fluids.WATER, capacity)); + setFluid(new FluidStack(Fluids.WATER, capacity)); } public void refillWater() { // call super since our overrides don't allow any kind of filling - super.fill(0, WATER, false, true); + super.fill(WATER, FluidAction.EXECUTE); } public boolean isFull() { @@ -89,7 +88,7 @@ public boolean supportsFill(int tank) { } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChange) { + public int fill(FluidStack resource, FluidAction action) { // don't allow external filling return 0; } @@ -104,7 +103,7 @@ public CompoundTag serializeNBT() { public void deserializeNBT(CompoundTag nbt) {} @Override - public FluidStorage copy() { + public CustomFluidTank copy() { var storage = new InfiniteWaterTank(capacity); storage.setFluid(fluid.copy()); return storage; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java index 073045b5e0..cc416dd4ec 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java @@ -5,17 +5,17 @@ import com.gregtechceu.gtceu.api.gui.UITemplate; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.world.entity.player.Player; +import net.minecraftforge.fluids.FluidType; import javax.annotation.ParametersAreNonnullByDefault; @@ -28,7 +28,7 @@ @MethodsReturnNonnullByDefault public class SteamHatchPartMachine extends FluidHatchPartMachine { - public static final long INITIAL_TANK_CAPACITY = 64 * FluidHelper.getBucket(); + public static final int INITIAL_TANK_CAPACITY = 64 * FluidType.BUCKET_VOLUME; public static final boolean IS_STEEL = ConfigHolder.INSTANCE.machines.steelSteamMultiblocks; public SteamHatchPartMachine(IMachineBlockEntity holder, Object... args) { @@ -36,7 +36,7 @@ public SteamHatchPartMachine(IMachineBlockEntity holder, Object... args) { } @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { return super.createTank(initialCapacity, slots) .setFilter(fluidStack -> fluidStack.getFluid().is(GTMaterials.Steam.getFluidTag())); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java index 1ab8b25aea..468eaad41d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java @@ -7,15 +7,15 @@ import com.gregtechceu.gtceu.api.machine.multiblock.part.MultiblockPartMachine; import com.gregtechceu.gtceu.api.machine.trait.FluidTankProxyTrait; import com.gregtechceu.gtceu.common.machine.multiblock.electric.MultiblockTankMachine; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.block.Block; +import net.minecraftforge.fluids.capability.IFluidHandler; import org.jetbrains.annotations.Nullable; @@ -90,9 +90,8 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { } @Nullable - private IFluidTransfer getTargetTank() { - return FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(getFrontFacing()), - getFrontFacing().getOpposite()); + private IFluidHandler getTargetTank() { + return GTUtil.getAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()).resolve().orElse(null); } private void autoIO() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java index 197860ddde..7dab6c97da 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java @@ -5,12 +5,15 @@ import com.gregtechceu.gtceu.api.gui.UITemplate; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; -import com.lowdragmc.lowdraglib.gui.widget.*; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import com.lowdragmc.lowdraglib.gui.widget.ProgressWidget; +import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitivePumpMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitivePumpMachine.java index 3a6b2db8ce..567c7a98c0 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitivePumpMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitivePumpMachine.java @@ -11,11 +11,11 @@ import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.world.level.biome.Biome.Precipitation; +import net.minecraftforge.fluids.FluidType; import java.util.List; @@ -28,7 +28,7 @@ public class PrimitivePumpMachine extends MultiblockControllerMachine { protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(PrimitivePumpMachine.class, MultiblockControllerMachine.MANAGED_FIELD_HOLDER); - private long biomeModifier = 0; + private int biomeModifier = 0; private int hatchModifier = 0; private NotifiableFluidTank fluidTank; private TickableSubscription produceWaterSubscription; @@ -56,9 +56,9 @@ private void initializeTank() { if (handler.getHandlerIO() == IO.OUT && handler.getCapability() == FluidRecipeCapability.CAP) { fluidTank = (NotifiableFluidTank) handler; long tankCapacity = fluidTank.getTankCapacity(0); - if (tankCapacity == FluidHelper.getBucket()) { + if (tankCapacity == FluidType.BUCKET_VOLUME) { hatchModifier = 1; - } else if (tankCapacity == FluidHelper.getBucket() * 8) { + } else if (tankCapacity == FluidType.BUCKET_VOLUME * 8) { hatchModifier = 2; } else { hatchModifier = 4; @@ -116,8 +116,8 @@ private Precipitation getBiomePrecipitation() { return getLevel().getBiome(getPos()).value().getPrecipitationAt(getPos()); } - public long getFluidProduction() { - long value = biomeModifier * hatchModifier; + public int getFluidProduction() { + int value = biomeModifier * hatchModifier; if (isRainingInBiome()) { value = value * 3 / 2; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitiveWorkableMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitiveWorkableMachine.java index a100499d95..dd9d4b83f4 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitiveWorkableMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/PrimitiveWorkableMachine.java @@ -10,11 +10,11 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidType; import javax.annotation.ParametersAreNonnullByDefault; @@ -66,12 +66,12 @@ protected NotifiableItemStackHandler createExportItemHandler(Object... args) { protected NotifiableFluidTank createImportFluidHandler(Object... args) { return new NotifiableFluidTank(this, getRecipeType().getMaxInputs(FluidRecipeCapability.CAP), - 32 * FluidHelper.getBucket(), IO.IN); + 32 * FluidType.BUCKET_VOLUME, IO.IN); } protected NotifiableFluidTank createExportFluidHandler(Object... args) { return new NotifiableFluidTank(this, getRecipeType().getMaxOutputs(FluidRecipeCapability.CAP), - 32 * FluidHelper.getBucket(), IO.OUT); + 32 * FluidType.BUCKET_VOLUME, IO.OUT); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/steam/LargeBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/steam/LargeBoilerMachine.java index 1a8413af89..544b7ea9d9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/steam/LargeBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/steam/LargeBoilerMachine.java @@ -21,7 +21,6 @@ import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.util.ClickData; import com.lowdragmc.lowdraglib.gui.widget.ComponentPanelWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -35,6 +34,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -68,7 +68,7 @@ public class LargeBoilerMachine extends WorkableMultiblockMachine implements IEx private boolean hasNoWater; @Nullable protected TickableSubscription temperatureSubs; - private long steamGenerated; + private int steamGenerated; public LargeBoilerMachine(IMachineBlockEntity holder, int maxTemperature, int heatSpeed, Object... args) { super(holder, args); @@ -117,8 +117,8 @@ protected void updateCurrentTemperature() { if (currentTemperature >= 100 && getOffsetTimer() % TICKS_PER_STEAM_GENERATION == 0) { // drain water - var maxDrain = currentTemperature * throttle * TICKS_PER_STEAM_GENERATION * FluidHelper.getBucket() / - (ConfigHolder.INSTANCE.machines.largeBoilers.steamPerWater * 100000L); + var maxDrain = currentTemperature * throttle * TICKS_PER_STEAM_GENERATION * FluidType.BUCKET_VOLUME / + (ConfigHolder.INSTANCE.machines.largeBoilers.steamPerWater * 100000); var drainWater = List.of(FluidIngredient.of(maxDrain, Fluids.WATER)); List> inputTanks = new ArrayList<>(); if (getCapabilitiesProxy().contains(IO.IN, FluidRecipeCapability.CAP)) { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java index 68cf3c0b7c..48f6840a2e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java @@ -6,12 +6,11 @@ import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.steam.SteamBoilerMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -20,6 +19,7 @@ import net.minecraft.util.RandomSource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidType; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; @@ -69,7 +69,7 @@ public ManagedFieldHolder getFieldHolder() { } protected NotifiableFluidTank createFuelTank(Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket(), IO.IN); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME, IO.IN); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java index 9aa6dfd1bf..1ade70c86d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java @@ -21,7 +21,6 @@ import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -37,6 +36,8 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Block; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import lombok.Setter; @@ -73,7 +74,7 @@ public class SteamMinerMachine extends SteamWorkableMachine implements IMiner, I public SteamMinerMachine(IMachineBlockEntity holder, int speed, int maximumRadius, int fortune) { super(holder, false, fortune, speed, maximumRadius); this.inventorySize = 4; - this.energyPerTick = (int) (16 * FluidHelper.getBucket() / 1000); + this.energyPerTick = (int) (16 * FluidType.BUCKET_VOLUME / 1000); this.importItems = createImportItemHandler(); this.exportItems = createExportItemHandler(); } @@ -98,7 +99,7 @@ public SteamMinerLogic getRecipeLogic() { @Override protected NotifiableFluidTank createSteamTank(Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket(), IO.IN); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME, IO.IN); } protected NotifiableItemStackHandler createImportItemHandler(@SuppressWarnings("unused") Object... args) { @@ -222,7 +223,7 @@ public boolean drainInput(boolean simulate) { long resultSteam = steamTank.getFluidInTank(0).getAmount() - energyPerTick; if (!this.isVentingBlocked() && resultSteam >= 0L && resultSteam <= steamTank.getTankCapacity(0)) { if (!simulate) - steamTank.drainInternal(energyPerTick, false); + steamTank.drainInternal(energyPerTick, IFluidHandler.FluidAction.EXECUTE); return true; } return false; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java index bf898c51fa..0b1c6ca18c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java @@ -12,13 +12,13 @@ import com.gregtechceu.gtceu.api.machine.feature.IMachineLife; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; -import com.lowdragmc.lowdraglib.gui.widget.TankWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -191,8 +191,7 @@ protected void updateAutoOutputSubscription() { ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(outputFacingItems), outputFacingItems.getOpposite()) != null || (isAutoOutputFluids() && !tank.isEmpty()) && outputFacingFluids != null && - FluidTransferHelper.getFluidTransfer(getLevel(), getPos().relative(outputFacingFluids), - outputFacingFluids.getOpposite()) != null) { + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java index d7ae641dd9..f711904427 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java @@ -5,20 +5,22 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.api.transfer.fluid.InfiniteFluidTransferProxy; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup; import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; import com.lowdragmc.lowdraglib.gui.texture.TextTexture; import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DropSaved; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import org.jetbrains.annotations.Nullable; @@ -44,7 +46,7 @@ public CreativeTankMachine(IMachineBlockEntity holder) { @Nullable @Override - public IFluidTransfer getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { if (side == null || (useCoverCapability && coverContainer.hasCover(side))) return super.getFluidTransferCap(side, useCoverCapability); @@ -58,8 +60,8 @@ protected NotifiableFluidTank createCacheFluidHandler(Object... args) { @Override protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); - if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && FluidTransferHelper - .getFluidTransfer(getLevel(), getPos().relative(outputFacing), outputFacing.getOpposite()) != null) { + if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -115,16 +117,13 @@ public void updateFluidTick() { cache.getStorages()[0].getFluid().isEmpty() || getLevel().isClientSide || !isWorkingEnabled()) return; - IFluidTransfer transfer = FluidTransferHelper.getFluidTransfer(getLevel(), - getPos().relative(getOutputFacingFluids()), getOutputFacingFluids().getOpposite()); - if (transfer != null) { - FluidStack stack = cache.getStorages()[0].getFluid().copy(); + GTUtil.getAdjacentFluidHandler(getLevel(), getPos(), getOutputFacingFluids()).ifPresent(h -> { + FluidStack stack = cache.getFluidInTank(0).copy(); stack.setAmount(mBPerCycle); - long canInsertAmount = transfer.fill(stack, true); - stack.setAmount(Math.min(mBPerCycle, canInsertAmount)); - - transfer.fill(stack, false); - } + int insertable = h.fill(stack, FluidAction.SIMULATE); + stack.setAmount(Math.min(mBPerCycle, insertable)); + h.fill(stack, FluidAction.EXECUTE); + }); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java index cb878dacbe..cec85a02a8 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java @@ -10,12 +10,11 @@ import com.gregtechceu.gtceu.common.machine.multiblock.electric.FluidDrillMachine; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.SectionPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -74,7 +73,7 @@ private GTRecipe getFluidDrillRecipe() { var recipe = GTRecipeBuilder.ofRaw() .duration(MAX_PROGRESS) .EUt(GTValues.VA[getMachine().getEnergyTier()]) - .outputFluids(FluidStack.create(veinFluid, + .outputFluids(new FluidStack(veinFluid, getFluidToProduce(data.getFluidVeinWorldEntry(getChunkX(), getChunkZ())))) .buildRawRecipe(); if (recipe.matchRecipe(getMachine()).isSuccess() && recipe.matchTickRecipe(getMachine()).isSuccess()) { @@ -84,7 +83,7 @@ private GTRecipe getFluidDrillRecipe() { return null; } - public long getFluidToProduce() { + public int getFluidToProduce() { if (getMachine().getLevel() instanceof ServerLevel serverLevel && veinFluid != null) { var data = BedrockFluidVeinSavedData.getOrCreate(serverLevel); return getFluidToProduce(data.getFluidVeinWorldEntry(getChunkX(), getChunkZ())); @@ -92,7 +91,7 @@ public long getFluidToProduce() { return 0; } - private long getFluidToProduce(FluidVeinWorldEntry entry) { + private int getFluidToProduce(FluidVeinWorldEntry entry) { var definition = entry.getDefinition(); if (definition != null) { int depletedYield = definition.getDepletedYield(); @@ -107,7 +106,7 @@ private long getFluidToProduce(FluidVeinWorldEntry entry) { if (isOverclocked()) { produced = produced * 3 / 2; } - return produced * FluidHelper.getBucket() / 1000; + return produced * FluidType.BUCKET_VOLUME / 1000; } return 0; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/customlogic/CannerLogic.java b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/customlogic/CannerLogic.java index 11f9619939..008a5d88c1 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/customlogic/CannerLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/customlogic/CannerLogic.java @@ -10,7 +10,6 @@ import com.gregtechceu.gtceu.utils.GTStringUtils; import com.lowdragmc.lowdraglib.misc.ItemTransferList; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import net.minecraft.world.item.ItemStack; @@ -39,8 +38,8 @@ public class CannerLogic implements GTRecipeType.ICustomRecipeLogic { .requireNonNullElseGet(holder.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP), ArrayList::new) .stream() - .filter(IFluidTransfer.class::isInstance).map(IFluidTransfer.class::cast) - .toArray(IFluidTransfer[]::new); + .filter(IFluidHandler.class::isInstance).map(IFluidHandler.class::cast) + .toArray(IFluidHandler[]::new); var inputs = new ItemTransferList(itemInputs); for (int i = 0; i < inputs.getSlots(); i++) { @@ -60,21 +59,21 @@ public class CannerLogic implements GTRecipeType.ICustomRecipeLogic { return GTRecipeTypes.CANNER_RECIPES.recipeBuilder(GTStringUtils.itemStackToString(item)) .inputItems(inputStack) .outputItems(fluidHandlerItem.getContainer()) - .outputFluids(com.lowdragmc.lowdraglib.side.fluid.FluidStack.create(fluid.getFluid(), + .outputFluids(new FluidStack(fluid.getFluid(), fluid.getAmount(), fluid.getTag())) .duration(Math.max(16, fluid.getAmount() / 64)).EUt(4) .buildRawRecipe(); } // nothing drained so try filling - for (IFluidTransfer fluidInput : fluidInputs) { + for (IFluidHandler fluidInput : fluidInputs) { var fluidStack1 = fluidInput.getFluidInTank(0); if (fluidStack1.isEmpty()) { continue; } fluidStack1 = fluidStack1.copy(); fluidStack1.setAmount( - fluidHandlerItem.fill(new FluidStack(fluidStack1.getFluid(), (int) fluidStack1.getAmount()), + fluidHandlerItem.fill(new FluidStack(fluidStack1.getFluid(), fluidStack1.getAmount()), IFluidHandler.FluidAction.EXECUTE)); if (fluidStack1.getAmount() > 0) { return GTRecipeTypes.CANNER_RECIPES.recipeBuilder(GTStringUtils.itemStackToString(item)) diff --git a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidPipeNet.java b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidPipeNet.java index 5b9702e48d..6402827d30 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidPipeNet.java +++ b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidPipeNet.java @@ -24,7 +24,7 @@ public FluidPipeNet(LevelPipeNet world) { @Override protected void writeNodeData(FluidPipeProperties nodeData, CompoundTag tagCompound) { tagCompound.putInt("max_temperature", nodeData.getMaxFluidTemperature()); - tagCompound.putLong("throughput", nodeData.getThroughput()); + tagCompound.putInt("throughput", nodeData.getThroughput()); tagCompound.putBoolean("gas_proof", nodeData.isGasProof()); tagCompound.putBoolean("acid_proof", nodeData.isAcidProof()); tagCompound.putBoolean("cryo_proof", nodeData.isCryoProof()); @@ -35,7 +35,7 @@ protected void writeNodeData(FluidPipeProperties nodeData, CompoundTag tagCompou @Override protected FluidPipeProperties readNodeData(CompoundTag tagCompound) { int maxTemperature = tagCompound.getInt("max_temperature"); - long throughput = tagCompound.getLong("throughput"); + int throughput = tagCompound.getInt("throughput"); boolean gasProof = tagCompound.getBoolean("gas_proof"); boolean acidProof = tagCompound.getBoolean("acid_proof"); boolean cryoProof = tagCompound.getBoolean("cryo_proof"); diff --git a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/longdistance/LDFluidEndpointMachine.java b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/longdistance/LDFluidEndpointMachine.java index 485c9763aa..a13c6ec0e5 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/longdistance/LDFluidEndpointMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/longdistance/LDFluidEndpointMachine.java @@ -1,10 +1,11 @@ package com.gregtechceu.gtceu.common.pipelike.fluidpipe.longdistance; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.machine.storage.LongDistanceEndpointMachine; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import org.jetbrains.annotations.NotNull; @@ -14,11 +15,11 @@ public LDFluidEndpointMachine(IMachineBlockEntity holder) { super(holder, LDFluidPipeType.INSTANCE); } - public static class FluidHandlerWrapper implements IFluidTransfer { + public static class FluidHandlerWrapper implements IFluidHandlerModifiable { - private final IFluidTransfer delegate; + private final IFluidHandler delegate; - public FluidHandlerWrapper(IFluidTransfer delegate) { + public FluidHandlerWrapper(IFluidHandler delegate) { this.delegate = delegate; } @@ -35,11 +36,13 @@ public FluidStack getFluidInTank(int tank) { @Override public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { - delegate.setFluidInTank(tank, fluidStack); + if (delegate instanceof IFluidHandlerModifiable modifiable) { + modifiable.setFluidInTank(tank, fluidStack); + } } @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return delegate.getTankCapacity(tank); } @@ -48,20 +51,17 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { return delegate.isFluidValid(tank, stack); } - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return delegate.fill(resource, simulate, notifyChanges); - } - @Override public boolean supportsFill(int tank) { - return delegate.supportsFill(tank); + if (delegate instanceof IFluidHandlerModifiable modifiable) { + return modifiable.supportsFill(tank); + } + return true; } - @NotNull @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return FluidStack.empty(); + public int fill(FluidStack resource, FluidAction action) { + return delegate.fill(resource, action); } @Override @@ -69,15 +69,14 @@ public boolean supportsDrain(int tank) { return false; } - @NotNull @Override - public Object createSnapshot() { - return delegate.createSnapshot(); + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + return FluidStack.EMPTY; } @Override - public void restoreFromSnapshot(Object snapshot) { - delegate.restoreFromSnapshot(snapshot); + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return FluidStack.EMPTY; } } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java index 3292ec89e5..127426551c 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/builder/GTRecipeBuilder.java @@ -24,7 +24,6 @@ import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.utils.ResearchManager; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.utils.NBTToJsonConverter; import net.minecraft.MethodsReturnNonnullByDefault; @@ -41,6 +40,7 @@ import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Blocks; +import net.minecraftforge.fluids.FluidStack; import com.google.gson.JsonArray; import com.google.gson.JsonObject; diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java index b9e4f2bfc4..8bd5a3264e 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/DecompositionRecipeHandler.java @@ -8,10 +8,9 @@ import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java index ca88de6e84..ba6b4084bb 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/generated/WireRecipeHandler.java @@ -142,7 +142,7 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material .EUt(VA[ULV]).duration(100) .inputItems(wirePrefix, material) .outputItems(cablePrefix, material) - .inputFluids(Rubber.getFluid(L * (long) insulationAmount)); + .inputFluids(Rubber.getFluid(L * insulationAmount)); if (voltageTier == EV) { builder.inputItems(foil, PolyvinylChloride, insulationAmount); @@ -167,7 +167,7 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material builder.inputItems(foil, PolyvinylChloride, insulationAmount); } - builder.inputFluids(SiliconeRubber.getFluid(L * (long) insulationAmount / 2)) + builder.inputFluids(SiliconeRubber.getFluid(L * insulationAmount / 2)) .save(provider); // Styrene Butadiene Rubber Recipe (all cables) @@ -187,7 +187,7 @@ public static void generateCableCovering(TagPrefix wirePrefix, Material material builder.inputItems(foil, PolyvinylChloride, insulationAmount); } - builder.inputFluids(StyreneButadieneRubber.getFluid(L * (long) insulationAmount / 4)) + builder.inputFluids(StyreneButadieneRubber.getFluid(L * insulationAmount / 4)) .save(provider); } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/FuelRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/FuelRecipes.java index 6f120c7a9d..5f957bc720 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/FuelRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/FuelRecipes.java @@ -4,13 +4,12 @@ import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.entity.FurnaceBlockEntity; import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.fluids.FluidStack; import java.util.HashSet; import java.util.Set; @@ -46,7 +45,7 @@ public static void init(Consumer provider) { } STEAM_BOILER_RECIPES.recipeBuilder("lava") - .inputFluids(FluidStack.create(Fluids.LAVA, 100)) + .inputFluids(new FluidStack(Fluids.LAVA, 100)) .duration(600 * 12) .save(provider); diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCyMRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCyMRecipes.java index 0ad9b66849..4c34ec0764 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCyMRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/GCyMRecipes.java @@ -12,8 +12,6 @@ import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; - import net.minecraft.data.recipes.FinishedRecipe; import org.jetbrains.annotations.NotNull; @@ -390,10 +388,10 @@ private static void registerBinaryAlloy(@NotNull Material input1, int input1Amou .inputItems(TagPrefix.dust, input1, input1Amount) .inputItems(TagPrefix.dust, input2, input2Amount) .circuitMeta(input1Amount + input2Amount) - .outputFluids(output.getFluid((long) GTValues.L * outputAmount)) + .outputFluids(output.getFluid(GTValues.L * outputAmount)) .duration(duration * 3 / 4) .EUt(16) - .blastFurnaceTemp(FluidHelper.getTemperature(output.getFluid(1))) + .blastFurnaceTemp(output.getFluid().getFluidType().getTemperature()) .save(provider); } @@ -409,10 +407,10 @@ private static void registerTrinaryAlloy(@NotNull Material input1, int input1Amo .inputItems(TagPrefix.dust, input2, input2Amount) .inputItems(TagPrefix.dust, input3, input3Amount) .circuitMeta(input1Amount + input2Amount + input3Amount) - .outputFluids(output.getFluid((long) GTValues.L * outputAmount)) + .outputFluids(output.getFluid(GTValues.L * outputAmount)) .duration(duration * 3 / 4) .EUt(16) - .blastFurnaceTemp(FluidHelper.getTemperature(output.getFluid(1))) + .blastFurnaceTemp(output.getFluid().getFluidType().getTemperature()) .save(provider); } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MachineRecipeLoader.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MachineRecipeLoader.java index 66939e196d..3c46f70cad 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MachineRecipeLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MachineRecipeLoader.java @@ -22,8 +22,6 @@ import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.resources.ResourceLocation; @@ -34,6 +32,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; import net.minecraftforge.common.Tags; +import net.minecraftforge.fluids.FluidStack; import com.tterrag.registrate.util.entry.ItemEntry; diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/WoodMachineRecipes.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/WoodMachineRecipes.java index 6674b5b159..c340d257cc 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/WoodMachineRecipes.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/WoodMachineRecipes.java @@ -14,8 +14,6 @@ import com.gregtechceu.gtceu.data.recipe.VanillaRecipeHelper; import com.gregtechceu.gtceu.data.recipe.WoodTypeEntry; -import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; - import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; @@ -749,7 +747,7 @@ private static void registerGTWoodRecipes(Consumer provider) { GTBlocks.TREATED_WOOD_PLANK.asStack(8), "PPP", "PBP", "PPP", 'P', ItemTags.PLANKS, - 'B', FluidUtil.getFilledBucket(FluidHelperImpl.toFluidStack(Creosote.getFluid(1000)))); + 'B', FluidUtil.getFilledBucket(Creosote.getFluid(1000))); VanillaRecipeHelper.addShapedRecipe(provider, "treated_wood_stick", ChemicalHelper.get(rod, TreatedWood, ConfigHolder.INSTANCE.recipes.nerfWoodCrafting ? 2 : 4), diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/alloyblast/AlloyBlastRecipeProducer.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/alloyblast/AlloyBlastRecipeProducer.java index 43ae5eec28..d24094dbc7 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/alloyblast/AlloyBlastRecipeProducer.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/alloyblast/AlloyBlastRecipeProducer.java @@ -17,10 +17,9 @@ import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -109,7 +108,7 @@ protected int addInputs(@NotNull Material material, @NotNull GTRecipeBuilder bui if (fluidAmount >= 2) return -1; // more than 2 fluids won't fit in the machine fluidAmount++; // assume all fluids have 1000mB/mol, since other quantities should be as an item input - builder.inputFluids(msMat.getFluid(1000L * msAmount)); + builder.inputFluids(msMat.getFluid(1000 * msAmount)); } else return -1; // no fluid or item prop means no valid recipe outputAmount += msAmount; } @@ -129,7 +128,7 @@ protected void buildRecipes(@NotNull BlastProperty property, @NotNull Fluid molt int componentAmount, @NotNull GTRecipeBuilder builder, Consumer provider) { // add the fluid output with the correct amount - builder.outputFluids(FluidStack.create(molten, (long) GTValues.L * outputAmount)); + builder.outputFluids(new FluidStack(molten, GTValues.L * outputAmount)); // apply alloy blast duration reduction: 3/4 int duration = builder.duration * outputAmount * 3 / 4; @@ -179,7 +178,7 @@ protected void addFreezerRecipes(@NotNull Material material, @NotNull Fluid molt Consumer provider) { // build the freezer recipe GTRecipeBuilder freezerBuilder = GTRecipeTypes.VACUUM_RECIPES.recipeBuilder(material.getName()) - .inputFluids(FluidStack.create(molten, GTValues.L)) + .inputFluids(new FluidStack(molten, GTValues.L)) .duration((int) material.getMass() * 3) .notConsumable(GTItems.SHAPE_MOLD_INGOT.asStack()) .outputItems(TagPrefix.ingot, material); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProduct.java b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProduct.java index 811746ad21..bc387f70b4 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProduct.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProduct.java @@ -13,8 +13,6 @@ import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.utils.FormattingUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; import net.minecraft.tags.TagKey; @@ -23,6 +21,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Either; @@ -50,7 +49,7 @@ public static void addOreByProductPrefix(TagPrefix orePrefix) { private final Int2ObjectMap chances = new Int2ObjectOpenHashMap<>(); protected final List, Integer>>, List>> itemInputs = new ArrayList<>(); protected final NonNullList itemOutputs = NonNullList.create(); - protected final List, Long>>, List>> fluidInputs = new ArrayList<>(); + protected final List, Integer>>, List>> fluidInputs = new ArrayList<>(); private boolean hasDirectSmelt = false; private boolean hasChemBath = false; private boolean hasSeparator = false; @@ -193,9 +192,9 @@ public GTOreByProduct(Material material) { addToOutputs(material, TagPrefix.crushedPurified, 1); addToOutputs(byproducts[0], TagPrefix.dust, 1); addChance(3333, 0); - List, Long>> fluidStacks = new ArrayList<>(); - fluidStacks.add(Pair.of(GTMaterials.Water.getFluidTag(), 1000L)); - fluidStacks.add(Pair.of(GTMaterials.DistilledWater.getFluidTag(), 100L)); + List, Integer>> fluidStacks = new ArrayList<>(); + fluidStacks.add(Pair.of(GTMaterials.Water.getFluidTag(), 1000)); + fluidStacks.add(Pair.of(GTMaterials.DistilledWater.getFluidTag(), 100)); fluidInputs.add(Either.left(fluidStacks)); // TC crushed/crushed purified -> centrifuged @@ -233,9 +232,9 @@ public GTOreByProduct(Material material) { addToOutputs(material, TagPrefix.crushedPurified, 1); addToOutputs(byproducts[3], TagPrefix.dust, byproductMultiplier); addChance(7000, 580); - List, Long>> washedFluid = new ArrayList<>(); + List, Integer>> washedFluid = new ArrayList<>(); // noinspection DataFlowIssue - washedFluid.add(Pair.of(washedIn.getFirst().getFluidTag(), (long) washedIn.getSecond())); + washedFluid.add(Pair.of(washedIn.getFirst().getFluidTag(), washedIn.getSecond())); fluidInputs.add(Either.left(washedFluid)); } else { addEmptyOutputs(2); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java index 42419f67c5..54f6c6f11b 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java @@ -2,15 +2,17 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.misc.lib.TagOrCycleFluidTransfer; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.recipe.content.Content; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; -import com.lowdragmc.lowdraglib.gui.widget.*; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; +import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.jei.IngredientIO; -import com.lowdragmc.lowdraglib.misc.FluidStorage; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.utils.TagOrCycleFluidTransfer; import com.lowdragmc.lowdraglib.utils.TagOrCycleItemStackTransfer; import net.minecraft.core.NonNullList; @@ -18,6 +20,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Either; @@ -156,15 +159,17 @@ public void setRecipe(GTOreByProduct recipeWrapper) { itemOutputExists.add(true); } - List, Long>>, List>> fluidInputs = recipeWrapper.fluidInputs; + List, Integer>>, List>> fluidInputs = recipeWrapper.fluidInputs; TagOrCycleFluidTransfer fluidInputsHandler = new TagOrCycleFluidTransfer(fluidInputs); WidgetGroup fluidStackGroup = new WidgetGroup(); for (int i = 0; i < FLUID_LOCATIONS.size(); i += 2) { int slotIndex = i / 2; if (!fluidInputs.get(slotIndex).map(Function.identity(), Function.identity()).isEmpty()) { - fluidStackGroup.addWidget(new TankWidget(new FluidStorage(fluidInputsHandler.getFluidInTank(slotIndex)), + var tank = new TankWidget(new CustomFluidTank(fluidInputsHandler.getFluidInTank(slotIndex)), FLUID_LOCATIONS.get(i), FLUID_LOCATIONS.get(i + 1), false, false) - .setIngredientIO(IngredientIO.INPUT).setBackground(GuiTextures.FLUID_SLOT)); + .setIngredientIO(IngredientIO.INPUT).setBackground(GuiTextures.FLUID_SLOT); + tank.setShowAmount(false); + fluidStackGroup.addWidget(tank); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java index dbb907bce8..7e780055bd 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java @@ -6,17 +6,20 @@ import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.gregtechceu.gtceu.client.ClientProxy; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.TextTexture; -import com.lowdragmc.lowdraglib.gui.widget.*; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; +import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.jei.IngredientIO; -import com.lowdragmc.lowdraglib.misc.FluidStorage; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.utils.LocalizationUtils; import net.minecraft.core.NonNullList; @@ -29,6 +32,7 @@ import net.minecraft.world.level.levelgen.heightproviders.HeightProvider; import net.minecraft.world.level.levelgen.heightproviders.UniformHeight; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import lombok.Getter; @@ -117,7 +121,7 @@ private void setupBaseGui(GTOreDefinition oreDefinition) { private void setupBaseGui(BedrockFluidDefinition fluid) { Fluid storedFluid = fluid.getStoredFluid().get(); TankWidget fluidSlot = new TankWidget( - new FluidStorage(FluidStack.create(storedFluid, 1000)), 51, 18, false, false); + new CustomFluidTank(new FluidStack(storedFluid, 1000)), 51, 18, false, false); fluidSlot.setIngredientIO(IngredientIO.OUTPUT); addWidget(fluidSlot); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java index 279539c278..d8b67c460e 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java @@ -6,8 +6,7 @@ import com.lowdragmc.lowdraglib.Platform; import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; import com.lowdragmc.lowdraglib.gui.widget.Widget; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import com.lowdragmc.lowdraglib.utils.Position; import com.lowdragmc.lowdraglib.utils.Size; @@ -15,6 +14,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.world.item.TooltipFlag; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.GenericStack; @@ -54,8 +55,9 @@ public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mous int stackY = position.y + 1; if (fluid != null) { FluidStack fluidStack = fluid.what() instanceof AEFluidKey key ? - FluidStack.create(key.getFluid(), fluid.amount(), key.getTag()) : FluidStack.empty(); - DrawerHelper.drawFluidForGui(graphics, fluidStack, fluid.amount(), stackX, stackY, 16, 16); + new FluidStack(key.getFluid(), (int) fluid.amount(), key.getTag()) : FluidStack.EMPTY; + DrawerHelper.drawFluidForGui(graphics, FluidHelperImpl.toFluidStack(fluidStack), fluid.amount(), stackX, + stackY, 16, 16); String amountStr = String.format("x%,d", fluid.amount()); drawText(graphics, amountStr, stackX + 20, stackY + 5, 1, 0xFFFFFFFF); } @@ -70,13 +72,13 @@ public void drawInForeground(@NotNull GuiGraphics graphics, int mouseX, int mous GenericStack fluid = this.gridWidget.getAt(this.index); if (fluid != null) { FluidStack fluidStack = fluid.what() instanceof AEFluidKey key ? - FluidStack.create(key.getFluid(), fluid.amount(), key.getTag()) : FluidStack.empty(); + new FluidStack(key.getFluid(), (int) fluid.amount(), key.getTag()) : FluidStack.EMPTY; List tooltips = new ArrayList<>(); tooltips.add(fluidStack.getDisplayName()); - tooltips.add(Component.literal(String.format("%,d ", fluid.amount())).append(FluidHelper.getUnit())); + tooltips.add(Component.literal(String.format("%,d ", fluid.amount())).append("mB")); if (!Platform.isForge()) { tooltips.add(Component.literal( - "§6mB:§r %d mB".formatted(fluidStack.getAmount() * 1000 / FluidHelper.getBucket()))); + "§6mB:§r %d mB".formatted(fluidStack.getAmount() * 1000 / FluidType.BUCKET_VOLUME))); } TooltipsHandler.appendFluidTooltips(fluidStack.getFluid(), fluidStack.getAmount(), tooltips::add, TooltipFlag.NORMAL); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java index 178e9d4297..aad77c9d32 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java @@ -10,10 +10,6 @@ import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidActionResult; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.utils.Position; import com.lowdragmc.lowdraglib.utils.Size; @@ -29,12 +25,17 @@ import net.minecraft.world.level.material.Fluids; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.SoundActions; +import net.minecraftforge.fluids.FluidActionResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.GenericStack; import org.jetbrains.annotations.NotNull; import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawStringFixedCorner; +import static com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl.toFluidStack; /** * @Author GlodBlock @@ -65,7 +66,7 @@ public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mous if (config != null) { var stack = AEUtil.toFluidStack(config); if (!stack.isEmpty()) { - DrawerHelper.drawFluidForGui(graphics, stack, config.amount(), stackX, stackY, 16, 16); + DrawerHelper.drawFluidForGui(graphics, toFluidStack(stack), config.amount(), stackX, stackY, 16, 16); if (!parentWidget.isStocking()) { String amountStr = TextFormattingUtil.formatLongToCompactString(config.amount(), 4) + "mB"; drawStringFixedCorner(graphics, amountStr, stackX + 17, stackY + 17, 16777215, true, 0.5f); @@ -75,7 +76,8 @@ public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mous if (stock != null) { var stack = AEUtil.toFluidStack(stock); if (!stack.isEmpty()) { - DrawerHelper.drawFluidForGui(graphics, stack, stock.amount(), stackX, stackY + 18, 16, 16); + DrawerHelper.drawFluidForGui(graphics, toFluidStack(stack), stock.amount(), stackX, stackY + 18, 16, + 16); String amountStr = TextFormattingUtil.formatLongToCompactString(stock.amount(), 4) + "mB"; drawStringFixedCorner(graphics, amountStr, stackX + 17, stackY + 18 + 17, 16777215, true, 0.5f); } @@ -119,11 +121,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } else if (button == 0) { // Left click to set/select ItemStack hold = this.gui.getModularUIContainer().getCarried(); - FluidStack fluid = FluidTransferHelper.getFluidContained(hold); - - if (fluid != null) { - writeClientAction(UPDATE_ID, fluid::writeToBuf); - } + FluidUtil.getFluidContained(hold).ifPresent(f -> writeClientAction(UPDATE_ID, f::writeToPacket)); if (!parentWidget.isStocking()) { this.parentWidget.enableAmount(this.index); @@ -157,13 +155,13 @@ public void handleClientAction(int id, FriendlyByteBuf buffer) { writeUpdateInfo(REMOVE_ID, buf -> {}); } if (id == UPDATE_ID) { - FluidStack fluid = FluidStack.readFromBuf(buffer); + FluidStack fluid = FluidStack.readFromPacket(buffer); var stack = AEUtil.fromFluidStack(fluid); if (!isStackValidForSlot(stack)) return; slot.setConfig(stack); this.parentWidget.enableAmount(this.index); - if (fluid != FluidStack.empty()) { - writeUpdateInfo(UPDATE_ID, fluid::writeToBuf); + if (fluid != FluidStack.EMPTY) { + writeUpdateInfo(UPDATE_ID, fluid::writeToPacket); } } if (id == AMOUNT_CHANGE_ID) { @@ -193,8 +191,8 @@ public void readUpdateInfo(int id, FriendlyByteBuf buffer) { slot.setConfig(null); } if (id == UPDATE_ID) { - FluidStack fluid = FluidStack.create(BuiltInRegistries.FLUID.get(buffer.readResourceLocation()), - buffer.readVarLong()); + FluidStack fluid = new FluidStack(BuiltInRegistries.FLUID.get(buffer.readResourceLocation()), + buffer.readVarInt()); slot.setConfig(new GenericStack(AEFluidKey.of(fluid.getFluid()), fluid.getAmount())); } if (id == AMOUNT_CHANGE_ID) { @@ -210,7 +208,7 @@ public void readUpdateInfo(int id, FriendlyByteBuf buffer) { currentStack.setCount(newStackSize); gui.getModularUIContainer().setCarried(currentStack); - FluidStack stack = FluidStack.create(key.getFluid(), slot.getStock().amount()); + FluidStack stack = new FluidStack(key.getFluid(), (int) slot.getStock().amount()); if (key.hasTag()) { stack.setTag(key.getTag().copy()); } @@ -233,11 +231,11 @@ public Rect2i getRectangleBox() { @Override public void acceptFluid(FluidStack fluidStack) { if (fluidStack.getRawFluid() != Fluids.EMPTY && fluidStack.getAmount() <= 0L) { - fluidStack.setAmount(1000L); + fluidStack.setAmount(1000); } if (!fluidStack.isEmpty()) { - writeClientAction(UPDATE_ID, fluidStack::writeToBuf); + writeClientAction(UPDATE_ID, fluidStack::writeToPacket); } } @@ -253,8 +251,8 @@ public boolean mouseWheelMove(double mouseX, double mouseY, double wheelDelta) { return false; } FluidStack fluid = slot.getConfig().what() instanceof AEFluidKey fluidKey ? - FluidStack.create(fluidKey.getFluid(), slot.getConfig().amount(), fluidKey.getTag()) : - FluidStack.empty(); + new FluidStack(fluidKey.getFluid(), (int) slot.getConfig().amount(), fluidKey.getTag()) : + FluidStack.EMPTY; long amt; if (isCtrlDown()) { amt = wheelDelta > 0 ? fluid.getAmount() * 2L : fluid.getAmount() / 2L; @@ -276,7 +274,7 @@ private int tryClickContainer(boolean isShiftKeyDown) { if (fluidTank == null) return -1; Player player = gui.entityPlayer; ItemStack currentStack = gui.getModularUIContainer().getCarried(); - var handler = FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()); + var handler = FluidUtil.getFluidHandler(currentStack).resolve().orElse(null); if (handler == null) return -1; int maxAttempts = isShiftKeyDown ? currentStack.getCount() : 1; @@ -284,10 +282,10 @@ private int tryClickContainer(boolean isShiftKeyDown) { boolean performedFill = false; FluidStack initialFluid = fluidTank.getFluid(); for (int i = 0; i < maxAttempts; i++) { - FluidActionResult result = FluidTransferHelper.tryFillContainer(currentStack, fluidTank, - Integer.MAX_VALUE, null, false); + FluidActionResult result = FluidUtil.tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, + false); if (!result.isSuccess()) break; - ItemStack remainingStack = FluidTransferHelper + ItemStack remainingStack = FluidUtil .tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); currentStack.shrink(1); performedFill = true; @@ -297,7 +295,8 @@ private int tryClickContainer(boolean isShiftKeyDown) { } } if (performedFill) { - SoundEvent soundevent = FluidHelper.getFillSound(initialFluid); + SoundEvent soundevent = initialFluid.getFluid().getFluidType().getSound(initialFluid, + SoundActions.BUCKET_FILL); if (soundevent != null) { player.level().playSound(null, player.position().x, player.position().y + 0.5, player.position().z, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java index 46f315bc4a..42bf3c9f5b 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java @@ -22,10 +22,12 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import appeng.api.config.Actionable; import appeng.api.stacks.GenericStack; import appeng.api.storage.MEStorage; +import com.google.common.primitives.Ints; import javax.annotation.ParametersAreNonnullByDefault; @@ -52,7 +54,7 @@ public void onMachineRemoved() { } @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { this.aeFluidHandler = new ExportOnlyAEFluidList(this, slots); return aeFluidHandler; } @@ -83,14 +85,15 @@ protected void syncME() { // Try to clear the wrong fluid GenericStack exceedFluid = aeTank.exceedStack(); if (exceedFluid != null) { - long total = exceedFluid.amount(); - long inserted = networkInv.insert(exceedFluid.what(), exceedFluid.amount(), Actionable.MODULATE, - this.actionSource); + int total = Ints.saturatedCast(exceedFluid.amount()); + int inserted = Ints + .saturatedCast(networkInv.insert(exceedFluid.what(), exceedFluid.amount(), Actionable.MODULATE, + this.actionSource)); if (inserted > 0) { - aeTank.drain(inserted, false); + aeTank.drain(inserted, IFluidHandler.FluidAction.EXECUTE); continue; } else { - aeTank.drain(total, false); + aeTank.drain(total, IFluidHandler.FluidAction.EXECUTE); } } // Fill it diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java index 31464cf294..bb63252834 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java @@ -5,21 +5,22 @@ import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.feature.IMachineLife; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.gregtechceu.gtceu.integration.ae2.gui.widget.list.AEListGridWidget; import com.gregtechceu.gtceu.integration.ae2.utils.KeyStorage; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidStack; import appeng.api.config.Actionable; import appeng.api.stacks.AEFluidKey; +import com.google.common.primitives.Ints; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -45,7 +46,7 @@ public MEOutputHatchPartMachine(IMachineBlockEntity holder, Object... args) { ///////////////////////////////// @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { this.internalBuffer = new KeyStorage(); return new InaccessibleInfiniteTank(this); } @@ -113,7 +114,7 @@ public Widget createUIWidget() { private class InaccessibleInfiniteTank extends NotifiableFluidTank { - FluidStorage storage; + CustomFluidTank storage; public InaccessibleInfiniteTank(MetaMachine holder) { super(holder, List.of(new FluidStorageDelegate()), IO.OUT, IO.NONE); @@ -127,12 +128,12 @@ public int getTanks() { } @Override - public FluidStack getFluidInTank(int tank) { + public @NotNull FluidStack getFluidInTank(int tank) { return storage.getFluid(); } @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return storage.getCapacity(); } @@ -142,15 +143,15 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { } } - private class FluidStorageDelegate extends FluidStorage { + private class FluidStorageDelegate extends CustomFluidTank { public FluidStorageDelegate() { - super(0L); + super(0); } @Override - public long getCapacity() { - return Long.MAX_VALUE; + public int getCapacity() { + return Integer.MAX_VALUE; } @Override @@ -159,12 +160,12 @@ public void setFluid(FluidStack fluid) { } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { var key = AEFluidKey.of(resource.getFluid(), resource.getTag()); - long amount = resource.getAmount(); - long oldValue = internalBuffer.storage.getOrDefault(key, 0); - long changeValue = Math.min(Long.MAX_VALUE - oldValue, amount); - if (changeValue > 0 && !simulate) { + int amount = resource.getAmount(); + int oldValue = Ints.saturatedCast(internalBuffer.storage.getOrDefault(key, 0)); + int changeValue = Math.min(Integer.MAX_VALUE - oldValue, amount); + if (changeValue > 0 && action.execute()) { internalBuffer.storage.put(key, oldValue + changeValue); internalBuffer.onChanged(); } @@ -182,13 +183,13 @@ public boolean supportsDrain(int tank) { } @Override - public FluidStorage copy() { + public CustomFluidTank copy() { // because recipe testing uses copy transfer instead of simulated operations return new FluidStorageDelegate() { @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return super.fill(tank, resource, true, notifyChanges); + public int fill(FluidStack resource, FluidAction action) { + return super.fill(resource, action); } }; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java index 5d82a8ea14..cec9381332 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java @@ -31,8 +31,6 @@ import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.IContentChangeAware; import com.lowdragmc.lowdraglib.syncdata.ITagSerializable; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; @@ -49,6 +47,8 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; import appeng.api.crafting.IPatternDetails; import appeng.api.crafting.PatternDetailsHelper; @@ -65,6 +65,7 @@ import appeng.helpers.patternprovider.PatternContainer; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import com.google.common.primitives.Ints; import lombok.Getter; import lombok.Setter; import org.apache.commons.lang3.ArrayUtils; @@ -160,7 +161,7 @@ public MEPatternBufferPartMachine(IMachineBlockEntity holder, Object... args) { this.circuitInventorySimulated = new NotifiableItemStackHandler(this, 1, IO.IN, IO.NONE) .setFilter(IntCircuitBehaviour::isIntegratedCircuit); this.shareInventory = new NotifiableItemStackHandler(this, 9, IO.IN, IO.NONE); - this.shareTank = new NotifiableFluidTank(this, 9, 8 * FluidHelper.getBucket(), IO.IN, IO.NONE); + this.shareTank = new NotifiableFluidTank(this, 9, 8 * FluidType.BUCKET_VOLUME, IO.IN, IO.NONE); } @Override @@ -450,15 +451,15 @@ private void addItem(AEItemKey key, long amount) { recipeHandler.getItemInputHandler().notifyListeners(); } - private void addFluid(AEFluidKey key, long amount) { + private void addFluid(AEFluidKey key, int amount) { if (amount <= 0L) return; for (FluidStack fluid : fluidInventory) { - if (AEUtil.matches(key, fluid)) { - long free = Long.MAX_VALUE - fluid.getAmount(); + if (key.matches(fluid)) { + int free = Integer.MAX_VALUE - fluid.getAmount(); if (amount <= free) { fluid.grow(amount); } else { - fluid.setAmount(Long.MAX_VALUE); + fluid.setAmount(Integer.MAX_VALUE); fluidInventory.add(AEUtil.toFluidStack(key, amount - free)); } return; @@ -500,12 +501,12 @@ public void refund() { for (FluidStack stack : fluidInventory) { if (stack == null || stack.isEmpty()) continue; - long inserted = StorageHelper.poweredInsert( + int inserted = Ints.saturatedCast(StorageHelper.poweredInsert( energy, networkInv, AEFluidKey.of(stack.getFluid(), stack.getTag()), stack.getAmount(), - actionSource); + actionSource)); if (inserted > 0) { stack.shrink(inserted); if (stack.isEmpty()) { @@ -520,7 +521,7 @@ public void refund() { public void pushPattern(IPatternDetails patternDetails, KeyCounter[] inputHolder) { patternDetails.pushInputsToExternalInventory(inputHolder, (what, amount) -> { if (what instanceof AEFluidKey key) { - addFluid(key, amount); + addFluid(key, Ints.saturatedCast(amount)); } if (what instanceof AEItemKey key) { @@ -579,7 +580,7 @@ public void pushPattern(IPatternDetails patternDetails, KeyCounter[] inputHolder foundStack = stack; } if (!found) continue; - long drained = Math.min(foundStack.getAmount(), fluidStack.getAmount()); + int drained = Math.min(foundStack.getAmount(), fluidStack.getAmount()); if (!simulate) { foundStack.shrink(drained); if (foundStack.isEmpty()) { @@ -608,7 +609,7 @@ public CompoundTag serializeNBT() { ListTag fluidInventoryTag = new ListTag(); for (FluidStack fluidStack : fluidInventory) { - fluidInventoryTag.add(fluidStack.saveToTag(new CompoundTag())); + fluidInventoryTag.add(fluidStack.writeToNBT(new CompoundTag())); } tag.put("fluidInventory", fluidInventoryTag); @@ -635,7 +636,7 @@ public void deserializeNBT(CompoundTag tag) { ListTag fluidInv = tag.getList("fluidInventory", Tag.TAG_COMPOUND); for (int i = 0; i < fluidInv.size(); i++) { CompoundTag tagFluidStack = fluidInv.getCompound(i); - var fluid = FluidStack.loadFromTag(tagFluidStack); + var fluid = FluidStack.loadFluidStackFromNBT(tagFluidStack); if (fluid != null) { if (!fluid.isEmpty()) { fluidInventory.add(fluid); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java index 69fa5e0cb5..27b70b4ac3 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java @@ -14,7 +14,6 @@ import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlotList; import com.gregtechceu.gtceu.integration.ae2.utils.AEUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -27,6 +26,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidStack; import appeng.api.config.Actionable; import appeng.api.networking.IGrid; @@ -82,7 +82,7 @@ public void removedFromController(IMultiController controller) { } @Override - protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) { + protected NotifiableFluidTank createTank(int initialCapacity, int slots, Object... args) { this.aeFluidHandler = new ExportOnlyAEStockingFluidList(this, CONFIG_SIZE); return this.aeFluidHandler; } @@ -304,34 +304,34 @@ public ExportOnlyAEFluidSlot copy() { } @Override - public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { + public FluidStack drain(int maxDrain, FluidAction action) { if (this.stock != null && this.config != null) { // Extract the items from the real net to either validate (simulate) // or extract (modulate) when this is called - if (!isOnline()) return FluidStack.empty(); + if (!isOnline()) return FluidStack.EMPTY; MEStorage aeNetwork = getMainNode().getGrid().getStorageService().getInventory(); - Actionable action = simulate ? Actionable.SIMULATE : Actionable.MODULATE; + Actionable actionable = action.simulate() ? Actionable.SIMULATE : Actionable.MODULATE; var key = config.what(); - long extracted = aeNetwork.extract(key, maxDrain, action, actionSource); + long extracted = aeNetwork.extract(key, maxDrain, actionable, actionSource); if (extracted > 0) { FluidStack resultStack = key instanceof AEFluidKey fluidKey ? - AEUtil.toFluidStack(fluidKey, extracted) : FluidStack.empty(); - if (!simulate) { + AEUtil.toFluidStack(fluidKey, extracted) : FluidStack.EMPTY; + if (action.execute()) { // may as well update the display here this.stock = ExportOnlyAESlot.copy(stock, stock.amount() - extracted); if (this.stock.amount() == 0) { this.stock = null; } - if (notifyChanges && this.onContentsChanged != null) { + if (this.onContentsChanged != null) { this.onContentsChanged.run(); } } return resultStack; } } - return FluidStack.empty(); + return FluidStack.EMPTY; } } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/trait/MEPatternBufferRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/trait/MEPatternBufferRecipeHandler.java index 42e9b407ab..7230bf63ea 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/trait/MEPatternBufferRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/trait/MEPatternBufferRecipeHandler.java @@ -8,7 +8,6 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.integration.ae2.machine.MEPatternBufferPartMachine; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -17,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/AEUtil.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/AEUtil.java index 69bcc72994..0c1d9c80d9 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/AEUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/AEUtil.java @@ -1,12 +1,12 @@ package com.gregtechceu.gtceu.integration.ae2.utils; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.AEItemKey; import appeng.api.stacks.GenericStack; +import com.google.common.primitives.Ints; import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -26,11 +26,11 @@ public static FluidStack toFluidStack(GenericStack stack) { if (key instanceof AEFluidKey fluidKey) { return toFluidStack(fluidKey, stack.amount()); } - return FluidStack.empty(); + return FluidStack.EMPTY; } public static FluidStack toFluidStack(AEFluidKey key, long amount) { - return FluidStack.create(key.getFluid(), amount, key.getTag()); + return key.toStack(Ints.saturatedCast(amount)); } public static ItemStack[] toItemStacks(GenericStack stack) { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jade/provider/RecipeOutputProvider.java b/src/main/java/com/gregtechceu/gtceu/integration/jade/provider/RecipeOutputProvider.java index f2e90a24c5..9f00a0016d 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/jade/provider/RecipeOutputProvider.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/jade/provider/RecipeOutputProvider.java @@ -7,8 +7,6 @@ import com.gregtechceu.gtceu.integration.jade.GTElementHelper; import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -21,6 +19,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; import snownee.jade.api.BlockAccessor; @@ -66,7 +65,7 @@ protected void write(CompoundTag data, RecipeLogic recipeLogic) { for (var stack : RecipeHelper.getOutputFluids(recipe)) { if (stack != null && !stack.isEmpty()) { var fluidTag = new CompoundTag(); - stack.saveToTag(fluidTag); + stack.writeToNBT(fluidTag); fluidTags.add(fluidTag); } } @@ -100,7 +99,7 @@ protected void addTooltip(CompoundTag capData, ITooltip tooltip, Player player, ListTag fluidTags = capData.getList("OutputFluids", Tag.TAG_COMPOUND); for (Tag tag : fluidTags) { if (tag instanceof CompoundTag tCompoundTag) { - var stack = FluidStack.loadFromTag(tCompoundTag); + var stack = FluidStack.loadFluidStackFromNBT(tCompoundTag); if (!stack.isEmpty()) { outputFluids.add(stack); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KineticMachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KineticMachineBuilder.java index bd1c0986b8..bc3ed7535a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KineticMachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KineticMachineBuilder.java @@ -21,7 +21,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import com.tterrag.registrate.util.nullness.NonNullConsumer; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import java.util.Locale; import java.util.function.BiConsumer; @@ -39,7 +39,7 @@ */ public class KineticMachineBuilder extends MachineBuilder { - public transient Int2LongFunction tankScalingFunction; // reflected in MachineFunctionPresets. DO NOT CHANGE! + public transient Int2IntFunction tankScalingFunction; // reflected in MachineFunctionPresets. DO NOT CHANGE! private final Object[] passedArguments; public KineticMachineBuilder(String name, boolean isSource, int tier, Object... args) { @@ -58,7 +58,7 @@ public KineticMachineBuilder isSource(boolean isSource) { @SuppressWarnings("unused") // Accessed via reflection public KineticMachineBuilder tankScalingFunction(Function tankScalingFunction) { - this.tankScalingFunction = tier -> tankScalingFunction.apply(tier).longValue(); + this.tankScalingFunction = tier -> tankScalingFunction.apply(tier).intValue(); this.metaMachine((holder) -> new SimpleKineticElectricWorkableMachine(holder, tier(), this.tankScalingFunction, passedArguments)); return this; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/MachineFunctionPresets.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/MachineFunctionPresets.java index b0be54d34c..33791217ab 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/MachineFunctionPresets.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/MachineFunctionPresets.java @@ -449,11 +449,11 @@ public MachineBuilder tankScalingFunction(Function tankScalin @SuppressWarnings("unchecked") @Nullable - public Function getTankScalingFunction(B builder) { + public Function getTankScalingFunction(B builder) { try { Field field = builderClass.getField("tankScalingFunction"); - return (Function) field.get(builder); + return (Function) field.get(builder); } catch (NoSuchFieldException | IllegalAccessException exception) { return null; } @@ -463,7 +463,7 @@ public MachineBuilder workableTooltip(GTRecipeType recipeType) { for (var builder : builders) { if (builder == null) continue; int tier = builder.tier(); - Function tankScalingFunction = getTankScalingFunction(builder); + Function tankScalingFunction = getTankScalingFunction(builder); builder.tooltips(GTMachines.workableTiered( tier, GTValues.V[tier], GTValues.V[tier] * 64, recipeType, tankScalingFunction != null ? tankScalingFunction.apply(tier) : GTMachines.defaultTankSizeFunction.apply(tier), diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/SimpleMachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/SimpleMachineBuilder.java index f73d0db785..69413481e0 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/SimpleMachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/SimpleMachineBuilder.java @@ -13,7 +13,7 @@ import com.gregtechceu.gtceu.common.data.GTRecipeModifiers; import com.gregtechceu.gtceu.common.registry.GTRegistration; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import java.util.Locale; import java.util.function.BiConsumer; @@ -32,7 +32,7 @@ */ public class SimpleMachineBuilder extends MachineBuilder { - public transient Int2LongFunction tankScalingFunction; // reflected in MachineFunctionPresets. DO NOT CHANGE! + public transient Int2IntFunction tankScalingFunction; // reflected in MachineFunctionPresets. DO NOT CHANGE! public SimpleMachineBuilder(String name, Function machineConstructor) { super(GTRegistration.REGISTRATE, name, MachineDefinition::createDefinition, machineConstructor, @@ -42,7 +42,7 @@ public SimpleMachineBuilder(String name, Function tankScalingFunction) { - this.tankScalingFunction = tier -> tankScalingFunction.apply(tier).longValue(); + this.tankScalingFunction = tier -> tankScalingFunction.apply(tier).intValue(); this.metaMachine((holder) -> new SimpleTieredMachine(holder, tier(), this.tankScalingFunction)); return this; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java index 3c705384e6..d9a92265a1 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTRecipeSchema.java @@ -932,7 +932,7 @@ public JsonElement writeOutputItem(OutputItem value) { @Override public JsonElement writeInputFluid(InputFluid value) { var fluid = ((FluidStackJS) value).getFluidStack(); - return FluidIngredient.of(fluid.getAmount(), fluid.getFluid()).toJson(); + return FluidIngredient.of((int) fluid.getAmount(), fluid.getFluid()).toJson(); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/GTRecipeComponents.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/GTRecipeComponents.java index fc2524b1a2..120060e83a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/GTRecipeComponents.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/GTRecipeComponents.java @@ -10,12 +10,11 @@ import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.GTRecipeCapabilities; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; +import net.minecraftforge.fluids.FluidStack; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -409,7 +408,7 @@ public FluidIngredientJS(FluidIngredient ingredient) { @Override public FluidIngredientJS kjs$copy(long amount) { FluidIngredient ingredient1 = ingredient.copy(); - ingredient1.setAmount(amount); + ingredient1.setAmount((int) amount); return new FluidIngredientJS(ingredient1); } @@ -417,7 +416,7 @@ public FluidIngredientJS(FluidIngredient ingredient) { public boolean matches(FluidLike other) { if (other instanceof FluidStackJS fluidStack) { return ingredient - .test(FluidStack.create(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getNbt())); + .test(new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getNbt())); } return other.matches(this); } @@ -431,7 +430,8 @@ public static FluidIngredientJS of(Object o) { return new FluidIngredientJS(FluidIngredient.fromJson(json)); } else if (o instanceof FluidStackJS fluidStackJS) { return new FluidIngredientJS(FluidIngredient.of( - FluidStack.create(fluidStackJS.getFluid(), fluidStackJS.getAmount(), fluidStackJS.getNbt()))); + new FluidStack(fluidStackJS.getFluid(), (int) fluidStackJS.getAmount(), + fluidStackJS.getNbt()))); } var list = ListJS.of(o); @@ -439,13 +439,13 @@ public static FluidIngredientJS of(Object o) { List stacks = new ArrayList<>(); for (var object : list) { FluidStackJS stackJS = FluidStackJS.of(object); - stacks.add(FluidStack.create(stackJS.getFluid(), stackJS.getAmount(), stackJS.getNbt())); + stacks.add(new FluidStack(stackJS.getFluid(), (int) stackJS.getAmount(), stackJS.getNbt())); } return new FluidIngredientJS(FluidIngredient.of(stacks.toArray(FluidStack[]::new))); } else { FluidStackJS stackJS = FluidStackJS.of(o); return new FluidIngredientJS(FluidIngredient - .of(FluidStack.create(stackJS.getFluid(), stackJS.getAmount(), stackJS.getNbt()))); + .of(new FluidStack(stackJS.getFluid(), (int) stackJS.getAmount(), stackJS.getNbt()))); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/top/element/FluidStackElement.java b/src/main/java/com/gregtechceu/gtceu/integration/top/element/FluidStackElement.java index a4c256cdc6..b1956b8f75 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/top/element/FluidStackElement.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/top/element/FluidStackElement.java @@ -4,13 +4,14 @@ import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; import com.mojang.blaze3d.systems.RenderSystem; import mcjty.theoneprobe.api.IElement; @@ -27,9 +28,9 @@ public FluidStackElement(FluidStack fluidStack, IFluidStyle style) { public FluidStackElement(FriendlyByteBuf buf) { if (buf.readBoolean()) { - this.fluidStack = FluidStack.readFromBuf(buf); + this.fluidStack = FluidStack.readFromPacket(buf); } else { - this.fluidStack = FluidStack.empty(); + this.fluidStack = FluidStack.EMPTY; } this.style = new FluidStyle().width(buf.readInt()).height(buf.readInt()); @@ -43,7 +44,8 @@ public void render(GuiGraphics guiGraphics, int x, int y) { y += 2; int width = style.getWidth() - 4; int height = style.getHeight() - 4; - DrawerHelper.drawFluidForGui(guiGraphics, fluidStack, fluidStack.getAmount(), x, y, width, height); + DrawerHelper.drawFluidForGui(guiGraphics, FluidHelperImpl.toFluidStack(fluidStack), fluidStack.getAmount(), + x, y, width, height); guiGraphics.pose().pushPose(); guiGraphics.pose().scale(0.5F, 0.5F, 1); @@ -71,7 +73,7 @@ public int getHeight() { public void toBytes(FriendlyByteBuf friendlyByteBuf) { if (!fluidStack.isEmpty()) { friendlyByteBuf.writeBoolean(true); - fluidStack.writeToBuf(friendlyByteBuf); + fluidStack.writeToPacket(friendlyByteBuf); } else { friendlyByteBuf.writeBoolean(false); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java b/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java index 7d57c72790..11d33a24fc 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java @@ -7,8 +7,6 @@ import com.gregtechceu.gtceu.integration.top.element.FluidStackElement; import com.gregtechceu.gtceu.integration.top.element.FluidStyle; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -17,6 +15,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.fluids.FluidStack; import mcjty.theoneprobe.api.CompoundText; import mcjty.theoneprobe.api.ElementAlignment; diff --git a/src/main/java/com/gregtechceu/gtceu/test/api/machine/trait/ParallelLogicTest.java b/src/main/java/com/gregtechceu/gtceu/test/api/machine/trait/ParallelLogicTest.java index 53ae186f0b..86fd638bd9 100644 --- a/src/main/java/com/gregtechceu/gtceu/test/api/machine/trait/ParallelLogicTest.java +++ b/src/main/java/com/gregtechceu/gtceu/test/api/machine/trait/ParallelLogicTest.java @@ -11,7 +11,6 @@ import com.gregtechceu.gtceu.common.data.GTRecipeModifiers; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import net.minecraft.core.BlockPos; @@ -20,6 +19,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.fluids.capability.IFluidHandler; public class ParallelLogicTest { @@ -49,8 +49,8 @@ public void getMaxRecipeMultiplier_FluidLimitTest(GameTestHelper helper) { ((IItemTransfer) rlm.getCapabilitiesProxy().get(IO.IN, ItemRecipeCapability.CAP)).insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false); - ((IFluidTransfer) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) - .fill(GTMaterials.Acetone.getFluid(8000), false); + ((IFluidHandler) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) + .fill(GTMaterials.Acetone.getFluid(8000), IFluidHandler.FluidAction.EXECUTE); var paralleled = GTRecipeModifiers.accurateParallel(machine, recipe, parallelLimit, false); @@ -86,8 +86,8 @@ public void getMaxRecipeMultiplier_LimitFailureTest(GameTestHelper helper) { ((IItemTransfer) rlm.getCapabilitiesProxy().get(IO.IN, ItemRecipeCapability.CAP)).insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false); - ((IFluidTransfer) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) - .fill(GTMaterials.Acetone.getFluid(8000), false); + ((IFluidHandler) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) + .fill(GTMaterials.Acetone.getFluid(8000), IFluidHandler.FluidAction.EXECUTE); var paralleled = GTRecipeModifiers.accurateParallel(machine, recipe, parallelLimit, false); @@ -123,8 +123,8 @@ public void getMaxRecipeMultiplier_ItemFailureTest(GameTestHelper helper) { ((IItemTransfer) rlm.getCapabilitiesProxy().get(IO.IN, ItemRecipeCapability.CAP)).insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false); - ((IFluidTransfer) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) - .fill(GTMaterials.Naphtha.getFluid(8000), false); + ((IFluidHandler) rlm.getCapabilitiesProxy().get(IO.IN, FluidRecipeCapability.CAP)) + .fill(GTMaterials.Naphtha.getFluid(8000), IFluidHandler.FluidAction.EXECUTE); var paralleled = GTRecipeModifiers.accurateParallel(machine, recipe, parallelLimit, false); diff --git a/src/main/java/com/gregtechceu/gtceu/utils/DummyMachineBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/utils/DummyMachineBlockEntity.java index cae4a5f400..6f5d7f28e9 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/DummyMachineBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/DummyMachineBlockEntity.java @@ -11,7 +11,7 @@ import com.lowdragmc.lowdraglib.syncdata.managed.MultiManagedStorage; import com.google.common.collect.Table; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; import java.util.List; @@ -26,7 +26,7 @@ public class DummyMachineBlockEntity implements IMachineBlockEntity { @Getter private final MachineDefinition definition; - public DummyMachineBlockEntity(int tier, GTRecipeType type, Int2LongFunction tankScalingFunction, + public DummyMachineBlockEntity(int tier, GTRecipeType type, Int2IntFunction tankScalingFunction, Table, List>> capabilitiesProxy, Object... args) { this.definition = MachineDefinition.createDefinition(GTCEu.id("dummy")); diff --git a/src/main/java/com/gregtechceu/gtceu/utils/DummyRecipeLogicMachine.java b/src/main/java/com/gregtechceu/gtceu/utils/DummyRecipeLogicMachine.java index a7dc991571..f52d413db5 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/DummyRecipeLogicMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/DummyRecipeLogicMachine.java @@ -8,7 +8,7 @@ import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine; import com.google.common.collect.Table; -import it.unimi.dsi.fastutil.ints.Int2LongFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import java.util.List; @@ -17,7 +17,7 @@ */ public class DummyRecipeLogicMachine extends WorkableTieredMachine implements IRecipeLogicMachine { - public DummyRecipeLogicMachine(IMachineBlockEntity be, int tier, Int2LongFunction tankScalingFunction, + public DummyRecipeLogicMachine(IMachineBlockEntity be, int tier, Int2IntFunction tankScalingFunction, Table, List>> capabilitiesProxy, Object... args) { super(be, tier, tankScalingFunction, args); diff --git a/src/main/java/com/gregtechceu/gtceu/utils/FluidKey.java b/src/main/java/com/gregtechceu/gtceu/utils/FluidKey.java index feb0cd4b6a..cd4a13b400 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/FluidKey.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/FluidKey.java @@ -1,9 +1,8 @@ package com.gregtechceu.gtceu.utils; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; import lombok.Getter; @@ -15,7 +14,7 @@ public class FluidKey { public final Fluid fluid; // Don't make this final, so we can clear the NBT if we remove the only key, resulting in an NBT of {}. Thanks Forge public CompoundTag tag; - private final long amount; + private final int amount; public FluidKey(FluidStack fluidStack) { this.fluid = fluidStack.getFluid(); @@ -24,7 +23,7 @@ public FluidKey(FluidStack fluidStack) { } public FluidKey copy() { - return new FluidKey(FluidStack.create(getFluid(), this.amount, tag)); + return new FluidKey(new FluidStack(getFluid(), this.amount, tag)); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/utils/FluidStackHashStrategy.java b/src/main/java/com/gregtechceu/gtceu/utils/FluidStackHashStrategy.java index 0d1c5f93b9..b8933c1ff3 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/FluidStackHashStrategy.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/FluidStackHashStrategy.java @@ -1,6 +1,6 @@ package com.gregtechceu.gtceu.utils; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import net.minecraftforge.fluids.FluidStack; import it.unimi.dsi.fastutil.Hash; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTHashMaps.java b/src/main/java/com/gregtechceu/gtceu/utils/GTHashMaps.java index 0cd85697d8..0bec100f88 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTHashMaps.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTHashMaps.java @@ -1,10 +1,10 @@ package com.gregtechceu.gtceu.utils; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import it.unimi.dsi.fastutil.objects.*; import org.jetbrains.annotations.NotNull; @@ -94,22 +94,22 @@ private static Object2IntMap createItemStackMap(boolean linked) { } /** - * Maps all fluids in the {@link IFluidTransfer} into a {@link FluidKey}, {@link Integer} value as amount + * Maps all fluids in the {@link IFluidHandler} into a {@link FluidKey}, {@link Integer} value as amount * - * @param fluidInputs The combined fluid input inventory handler, in the form of an {@link IFluidTransfer} + * @param fluidInputs The combined fluid input inventory handler, in the form of an {@link IFluidHandler} * @return a {@link Set} of unique {@link FluidKey}s for each fluid in the handler. Will be oversized stacks if * required */ - public static Map fromFluidHandler(IFluidTransfer fluidInputs) { - final Object2LongMap map = new Object2LongLinkedOpenHashMap<>(); + public static Map fromFluidHandler(IFluidHandler fluidInputs) { + final Object2IntMap map = new Object2IntLinkedOpenHashMap<>(); // Create a single stack of the combined count for each item for (int i = 0; i < fluidInputs.getTanks(); i++) { FluidStack fluidStack = fluidInputs.getFluidInTank(i); - if (fluidStack != FluidStack.empty() && fluidStack.getAmount() > 0) { + if (fluidStack != FluidStack.EMPTY && fluidStack.getAmount() > 0) { FluidKey key = new FluidKey(fluidStack); - map.put(key, map.getLong(key) + fluidStack.getAmount()); + map.put(key, map.getInt(key) + fluidStack.getAmount()); } } @@ -120,19 +120,19 @@ public static Map fromFluidHandler(IFluidTransfer fluidInputs) { * Maps all fluids in the {@link FluidStack} {@link Collection} into a {@link FluidKey}, {@link Integer} value as * amount * - * @param fluidInputs The combined fluid input inventory handler, in the form of an {@link IFluidTransfer} + * @param fluidInputs The combined fluid input inventory handler, in the form of an {@link IFluidHandler} * @return a {@link Set} of unique {@link FluidKey}s for each fluid in the handler. Will be oversized stacks if * required */ - public static Map fromFluidCollection(Collection fluidInputs) { - final Object2LongMap map = new Object2LongLinkedOpenHashMap<>(); + public static Map fromFluidCollection(Collection fluidInputs) { + final Object2IntMap map = new Object2IntLinkedOpenHashMap<>(); // Create a single stack of the combined count for each item for (FluidStack fluidStack : fluidInputs) { if (fluidStack != null && fluidStack.getAmount() > 0) { FluidKey key = new FluidKey(fluidStack); - map.put(key, map.getLong(key) + fluidStack.getAmount()); + map.put(key, map.getInt(key) + fluidStack.getAmount()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTMath.java b/src/main/java/com/gregtechceu/gtceu/utils/GTMath.java index 5ad0a09994..13a2d36b2a 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTMath.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTMath.java @@ -14,6 +14,10 @@ public static long clamp(long value, long min, long max) { return Math.max(min, Math.min(max, value)); } + public static int clamp(int value, int min, int max) { + return Math.max(min, Math.min(max, value)); + } + public static int[] split(long value) { IntArrayList result = new IntArrayList(); while (value > 0) { diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java index 2e062380d3..1826660aca 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java @@ -2,15 +2,16 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; import com.lowdragmc.lowdraglib.misc.ItemHandlerHelper; import com.lowdragmc.lowdraglib.misc.ItemTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -22,16 +23,16 @@ public class GTTransferUtils { - public static int transferFluids(@NotNull IFluidTransfer sourceHandler, @NotNull IFluidTransfer destHandler) { + public static int transferFluids(@NotNull IFluidHandler sourceHandler, @NotNull IFluidHandler destHandler) { return transferFluids(sourceHandler, destHandler, Integer.MAX_VALUE, fluidStack -> true); } - public static int transferFluids(@NotNull IFluidTransfer sourceHandler, @NotNull IFluidTransfer destHandler, + public static int transferFluids(@NotNull IFluidHandler sourceHandler, @NotNull IFluidHandler destHandler, int transferLimit) { return transferFluids(sourceHandler, destHandler, transferLimit, fluidStack -> true); } - public static int transferFluids(@NotNull IFluidTransfer sourceHandler, @NotNull IFluidTransfer destHandler, + public static int transferFluids(@NotNull IFluidHandler sourceHandler, @NotNull IFluidHandler destHandler, int transferLimit, @NotNull Predicate fluidFilter) { int fluidLeftToTransfer = transferLimit; @@ -43,17 +44,17 @@ public static int transferFluids(@NotNull IFluidTransfer sourceHandler, @NotNull } currentFluid.setAmount(fluidLeftToTransfer); - FluidStack fluidStack = sourceHandler.drain(currentFluid, true); + FluidStack fluidStack = sourceHandler.drain(currentFluid, FluidAction.SIMULATE); if (fluidStack.isEmpty()) { continue; } - long canInsertAmount = destHandler.fill(fluidStack, true); + int canInsertAmount = destHandler.fill(fluidStack, FluidAction.SIMULATE); if (canInsertAmount > 0) { fluidStack.setAmount(canInsertAmount); - fluidStack = sourceHandler.drain(fluidStack, false); - if (fluidStack != FluidStack.empty() && fluidStack.getAmount() > 0) { - fillFluidAccountNotifiableList(destHandler, fluidStack, false); + fluidStack = sourceHandler.drain(fluidStack, FluidAction.EXECUTE); + if (fluidStack != FluidStack.EMPTY && fluidStack.getAmount() > 0) { + fillFluidAccountNotifiableList(destHandler, fluidStack, FluidAction.EXECUTE); fluidLeftToTransfer -= fluidStack.getAmount(); if (fluidLeftToTransfer == 0) { @@ -65,18 +66,18 @@ public static int transferFluids(@NotNull IFluidTransfer sourceHandler, @NotNull return transferLimit - fluidLeftToTransfer; } - public static boolean transferExactFluidStack(@NotNull IFluidTransfer sourceHandler, - @NotNull IFluidTransfer destHandler, FluidStack fluidStack) { - long amount = fluidStack.getAmount(); - FluidStack sourceFluid = sourceHandler.drain(fluidStack, true); - if (sourceFluid == FluidStack.empty() || sourceFluid.getAmount() != amount) { + public static boolean transferExactFluidStack(@NotNull IFluidHandler sourceHandler, + @NotNull IFluidHandler destHandler, FluidStack fluidStack) { + int amount = fluidStack.getAmount(); + FluidStack sourceFluid = sourceHandler.drain(fluidStack, FluidAction.SIMULATE); + if (sourceFluid == FluidStack.EMPTY || sourceFluid.getAmount() != amount) { return false; } - long canInsertAmount = destHandler.fill(sourceFluid, true); + int canInsertAmount = destHandler.fill(sourceFluid, FluidAction.SIMULATE); if (canInsertAmount == amount) { - sourceFluid = sourceHandler.drain(sourceFluid, false); - if (sourceFluid != FluidStack.empty() && sourceFluid.getAmount() > 0) { - destHandler.fill(sourceFluid, false); + sourceFluid = sourceHandler.drain(sourceFluid, FluidAction.EXECUTE); + if (sourceFluid != FluidStack.EMPTY && sourceFluid.getAmount() > 0) { + destHandler.fill(sourceFluid, FluidAction.EXECUTE); return true; } } @@ -155,7 +156,7 @@ public static boolean addFluidsToFluidHandler(FluidTransferList fluidHandler, if (simulate) { OverlayedFluidHandler overlayedFluidHandler = new OverlayedFluidHandler(fluidHandler); for (FluidStack fluidStack : fluidStacks) { - long inserted = overlayedFluidHandler.insertFluid(fluidStack, fluidStack.getAmount()); + int inserted = overlayedFluidHandler.insertFluid(fluidStack, fluidStack.getAmount()); if (inserted != fluidStack.getAmount()) { return false; } @@ -164,47 +165,47 @@ public static boolean addFluidsToFluidHandler(FluidTransferList fluidHandler, } for (FluidStack fluidStack : fluidStacks) { - fillFluidAccountNotifiableList(fluidHandler, fluidStack, false); + fillFluidAccountNotifiableList(fluidHandler, fluidStack, FluidAction.EXECUTE); } return true; } - public static long fillFluidAccountNotifiableList(IFluidTransfer handler, FluidStack stack, boolean simulate) { + public static int fillFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, FluidAction action) { if (stack.isEmpty()) return 0; - if (handler instanceof FluidTransferList transferList) { + if (handler instanceof FluidTransferList handlerList) { var copied = stack.copy(); - for (var transfer : transferList.transfers) { + for (var transfer : handlerList.transfers) { var candidate = copied.copy(); if (transfer instanceof NotifiableFluidTank notifiable) { - copied.shrink(notifiable.fillInternal(candidate, simulate)); + copied.shrink(notifiable.fillInternal(candidate, action)); } else { - copied.shrink(transfer.fill(candidate, simulate)); + copied.shrink(transfer.fill(candidate, action)); } if (copied.isEmpty()) break; } return stack.getAmount() - copied.getAmount(); } - return handler.fill(stack, simulate); + return handler.fill(stack, action); } - public static FluidStack drainFluidAccountNotifiableList(IFluidTransfer handler, FluidStack stack, - boolean simulate) { - if (stack.isEmpty()) return FluidStack.empty(); - if (handler instanceof FluidTransferList transferList) { + public static FluidStack drainFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, + FluidAction action) { + if (stack.isEmpty()) return FluidStack.EMPTY; + if (handler instanceof FluidTransferList handlerList) { var copied = stack.copy(); - for (var transfer : transferList.transfers) { + for (var transfer : handlerList.transfers) { var candidate = copied.copy(); if (transfer instanceof NotifiableFluidTank notifiable) { - copied.shrink(notifiable.drainInternal(candidate, simulate).getAmount()); + copied.shrink(notifiable.drainInternal(candidate, action).getAmount()); } else { - copied.shrink(transfer.drain(candidate, simulate).getAmount()); + copied.shrink(transfer.drain(candidate, action).getAmount()); } if (copied.isEmpty()) break; } copied.setAmount(stack.getAmount() - copied.getAmount()); return copied; } - return handler.drain(stack, simulate); + return handler.drain(stack, action); } /** diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java index 9f20eec2e2..b3e1d4751d 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java @@ -11,10 +11,6 @@ import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.lowdragmc.lowdraglib.LDLib; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -38,8 +34,14 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.Tags; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.datafixers.util.Pair; @@ -54,6 +56,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; + +import javax.annotation.Nonnull; import static com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey.HAZARD; @@ -342,28 +347,28 @@ public static int getItemBurnTime(Item item) { return ForgeHooks.getBurnTime(item.getDefaultInstance(), RecipeType.SMELTING); } - public static long getPumpBiomeModifier(Holder biome) { + public static int getPumpBiomeModifier(Holder biome) { if (biome.is(BiomeTags.IS_NETHER)) { return -1; } if (biome.is(BiomeTags.IS_DEEP_OCEAN) || biome.is(BiomeTags.IS_OCEAN) || biome.is(BiomeTags.IS_BEACH) || biome.is(BiomeTags.IS_RIVER)) { - return FluidHelper.getBucket(); + return FluidType.BUCKET_VOLUME; } else if (biome.is(Tags.Biomes.IS_SWAMP) || biome.is(Tags.Biomes.IS_WET)) { - return FluidHelper.getBucket() * 4 / 5; + return FluidType.BUCKET_VOLUME * 4 / 5; } else if (biome.is(BiomeTags.IS_JUNGLE)) { - return FluidHelper.getBucket() * 35 / 100; + return FluidType.BUCKET_VOLUME * 35 / 100; } else if (biome.is(Tags.Biomes.IS_SNOWY)) { - return FluidHelper.getBucket() * 3 / 10; + return FluidType.BUCKET_VOLUME * 3 / 10; } else if (biome.is(Tags.Biomes.IS_PLAINS) || biome.is(BiomeTags.IS_FOREST)) { - return FluidHelper.getBucket() / 4; + return FluidType.BUCKET_VOLUME / 4; } else if (biome.is(Tags.Biomes.IS_COLD)) { - return FluidHelper.getBucket() * 175 / 1000; + return FluidType.BUCKET_VOLUME * 175 / 1000; } else if (biome.is(CustomTags.IS_SANDY)) { - return FluidHelper.getBucket() * 170 / 1000; + return FluidType.BUCKET_VOLUME * 170 / 1000; } - return FluidHelper.getBucket() / 10; + return FluidType.BUCKET_VOLUME / 10; } /** @@ -420,13 +425,64 @@ public static FluidStack getFluidFromContainer(Object ingredient) { if (ingredient instanceof FluidStack) { return (FluidStack) ingredient; } else if (ingredient instanceof ItemStack itemStack) { - IFluidTransfer fluidHandler = FluidTransferHelper.getFluidTransfer(itemStack); - if (fluidHandler != null) - return fluidHandler.drain(Integer.MAX_VALUE, false); + return FluidUtil.getFluidHandler(itemStack) + .map(h -> h.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.EXECUTE)).orElse(null); } return null; } + /** + * Gets the FluidHandler from the adjacent block on the side connected to the caller + * @param level Level + * @param pos BlockPos of the machine which is calling + * @param facing Direction to get the FluidHandler from + * @return LazyOpt of the IFluidHandler described above + */ + public static LazyOptional getAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { + return FluidUtil.getFluidHandler(level, pos.relative(facing), facing.getOpposite()); + } + + // Same as above, but returns the presence + public static boolean isAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { + return getAdjacentFluidHandler(level, pos, facing).isPresent(); + } + + public static int getFluidColor(FluidStack fluid) { + return IClientFluidTypeExtensions.of(fluid.getFluid()).getTintColor(fluid); + } + + // TODO: Clean this up to use FluidUtil and move it back to caller + public static int transferFiltered(@Nonnull IFluidHandler sourceHandler, @Nonnull IFluidHandler destHandler, + int transferLimit, @Nonnull Predicate fluidFilter) { + int fluidLeftToTransfer = transferLimit; + for (int i = 0; i < sourceHandler.getTanks(); i++) { + FluidStack currentFluid = sourceHandler.getFluidInTank(i).copy(); + if (currentFluid.isEmpty() || !fluidFilter.test(currentFluid)) { + continue; + } + + currentFluid.setAmount(fluidLeftToTransfer); + var drained = sourceHandler.drain(currentFluid, IFluidHandler.FluidAction.SIMULATE); + if (drained.isEmpty()) { + continue; + } + + var canInsertAmount = destHandler.fill(drained.copy(), IFluidHandler.FluidAction.SIMULATE); + if (canInsertAmount > 0) { + drained.setAmount(canInsertAmount); + drained = sourceHandler.drain(drained, IFluidHandler.FluidAction.EXECUTE); + if (!drained.isEmpty()) { + destHandler.fill(drained, IFluidHandler.FluidAction.EXECUTE); + fluidLeftToTransfer -= drained.getAmount(); + if (fluidLeftToTransfer == 0) { + break; + } + } + } + } + return transferLimit - fluidLeftToTransfer; + } + public static boolean canSeeSunClearly(Level world, BlockPos blockPos) { if (!world.canSeeSky(blockPos.above())) { return false; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/OreDictExprFilter.java b/src/main/java/com/gregtechceu/gtceu/utils/OreDictExprFilter.java index 1c64426af4..797e690f8f 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/OreDictExprFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/OreDictExprFilter.java @@ -1,10 +1,9 @@ package com.gregtechceu.gtceu.utils; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; - import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java b/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java index 1f987e01cc..4db3d80bd1 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java @@ -1,11 +1,10 @@ package com.gregtechceu.gtceu.utils; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; import org.jetbrains.annotations.NotNull; @@ -14,7 +13,7 @@ import java.util.stream.IntStream; /** - * Simulates consecutive fills to {@link IFluidTransfer} instance. + * Simulates consecutive fills to {@link IFluidTank} instances. */ public class OverlayedFluidHandler { @@ -25,7 +24,7 @@ public OverlayedFluidHandler(@NotNull FluidTransferList tank) { FluidStack[] entries = IntStream.range(0, tank.getTanks()).mapToObj(tank::getFluidInTank) .toArray(FluidStack[]::new); for (int i = 0; i < tank.getTanks(); ++i) { - FluidStorage storage = new FluidStorage(tank.getTankCapacity(i)); + CustomFluidTank storage = new CustomFluidTank(tank.getTankCapacity(i)); storage.setFluid(entries[i]); this.overlayedTanks.add(new OverlayedTank(storage, tank.isFluidValid(i, entries[i]))); } @@ -48,11 +47,11 @@ public void reset() { * @param amountToInsert Amount of the fluid to insert * @return Amount of fluid inserted into tanks */ - public long insertFluid(@NotNull FluidStack fluid, long amountToInsert) { + public int insertFluid(@NotNull FluidStack fluid, int amountToInsert) { if (amountToInsert <= 0) { return 0; } - long totalInserted = 0; + int totalInserted = 0; // flag value indicating whether the fluid was stored in 'distinct' slot at least once boolean distinctFillPerformed = false; @@ -60,7 +59,7 @@ public long insertFluid(@NotNull FluidStack fluid, long amountToInsert) { for (OverlayedTank overlayedTank : this.overlayedTanks) { // if the fluid to insert matches the tank, insert the fluid if (!overlayedTank.isEmpty() && overlayedTank.fluid != null && fluid.isFluidEqual(overlayedTank.fluid)) { - long inserted = overlayedTank.tryInsert(fluid, amountToInsert); + int inserted = overlayedTank.tryInsert(fluid, amountToInsert); if (inserted > 0) { totalInserted += inserted; amountToInsert -= inserted; @@ -82,7 +81,7 @@ public long insertFluid(@NotNull FluidStack fluid, long amountToInsert) { if ((!distinctFillPerformed || overlayedTank.allowSameFluidFill) && overlayedTank.isEmpty() && overlayedTank.property.isFluidValid(fluid)) { - long inserted = overlayedTank.tryInsert(fluid, amountToInsert); + int inserted = overlayedTank.tryInsert(fluid, amountToInsert); if (inserted > 0) { totalInserted += inserted; amountToInsert -= inserted; @@ -116,7 +115,7 @@ public String toString(boolean lineBreak) { if (fluid.isEmpty()) { stb.append("None 0 / ").append(overlayedTank.property.getCapacity()); } else { - stb.append(FluidHelper.getDisplayName(fluid)).append(' ').append(fluid.getAmount()) + stb.append(fluid.getDisplayName()).append(' ').append(fluid.getAmount()) .append(" / ").append(overlayedTank.property.getCapacity()); } } @@ -126,19 +125,19 @@ public String toString(boolean lineBreak) { private static class OverlayedTank { - private final IFluidStorage property; + private final IFluidTank property; private final boolean allowSameFluidFill; private FluidStack fluid; - OverlayedTank(@NotNull IFluidStorage property, boolean allowSameFluidFill) { + OverlayedTank(@NotNull IFluidTank property, boolean allowSameFluidFill) { this.property = property; this.allowSameFluidFill = allowSameFluidFill; reset(); } public boolean isEmpty() { - return fluid == FluidStack.empty() || fluid.getAmount() <= 0; + return fluid.isEmpty(); } /** @@ -151,13 +150,13 @@ public boolean isEmpty() { * @param amount Amount of the fluid to insert * @return Amount of fluid inserted into this tank */ - public long tryInsert(@NotNull FluidStack fluid, long amount) { + public int tryInsert(@NotNull FluidStack fluid, int amount) { if (this.fluid.isEmpty()) { this.fluid = fluid.copy(); this.fluid.setAmount(Math.min(this.property.getCapacity(), amount)); return this.fluid.getAmount(); } else { - long maxInsert = Math.min(this.property.getCapacity() - this.fluid.getAmount(), amount); + int maxInsert = Math.min(this.property.getCapacity() - this.fluid.getAmount(), amount); if (maxInsert > 0) { this.fluid.setAmount(this.fluid.getAmount() + maxInsert); return maxInsert; @@ -167,7 +166,7 @@ public long tryInsert(@NotNull FluidStack fluid, long amount) { public void reset() { FluidStack fluid = this.property.getFluid(); - this.fluid = fluid != FluidStack.empty() ? fluid.copy() : FluidStack.empty(); + this.fluid = fluid != FluidStack.EMPTY ? fluid.copy() : FluidStack.EMPTY; } } } From 7feb4146554a3ca01a9f035a4818e0916d98dffe Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:41:13 -0400 Subject: [PATCH 02/22] Required changes to integrate with LDLib Adds classes in /api/misc/lib/ which are Forge FluidStack compatible stand-ins for LDLib's versions Creates a Payload for Forge FluidStacks and registers them with LDLib Adds a mixin for LDLib to allow for FluidStack syncing --- .../gtceu/api/misc/lib/FluidTransferList.java | 197 +++++ .../api/misc/lib/PhantomFluidWidget.java | 269 +++++++ .../api/misc/lib/TagOrCycleFluidTransfer.java | 116 +++ .../gtceu/api/misc/lib/TankWidget.java | 731 ++++++++++++++++++ .../common/data/GTSyncedFieldAccessors.java | 5 + .../core/mixins/ldlib/SyncUtilsMixin.java | 31 + .../gtceu/syncdata/FluidStackLoad.java | 34 + src/main/resources/gtceu.mixins.json | 139 ++-- 8 files changed, 1453 insertions(+), 69 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/ldlib/SyncUtilsMixin.java create mode 100644 src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java new file mode 100644 index 0000000000..9b46d1ff5e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java @@ -0,0 +1,197 @@ +package com.gregtechceu.gtceu.api.misc.lib; + +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; + +import com.lowdragmc.lowdraglib.LDLib; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraftforge.common.util.INBTSerializable; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; + +import lombok.Setter; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +public class FluidTransferList implements IFluidHandlerModifiable, INBTSerializable { + + public final IFluidHandler[] transfers; + + @Setter + protected Predicate filter = fluid -> true; + + public FluidTransferList(IFluidHandler... transfers) { + this.transfers = transfers; + } + + public FluidTransferList(List transfers) { + this.transfers = transfers.toArray(IFluidHandler[]::new); + } + + @Override + public int getTanks() { + return Arrays.stream(transfers).mapToInt(IFluidHandler::getTanks).sum(); + } + + @Override + public @NotNull FluidStack getFluidInTank(int tank) { + int index = 0; + for (IFluidHandler handler : transfers) { + if (tank - index < handler.getTanks()) { + return handler.getFluidInTank(tank - index); + } + index += handler.getTanks(); + } + return FluidStack.EMPTY; + } + + @Override + public void setFluidInTank(int tank, FluidStack stack) { + int index = 0; + for (IFluidHandler handler : transfers) { + if (handler instanceof IFluidHandlerModifiable modifiable) { + if (tank - index < modifiable.getTanks()) { + modifiable.setFluidInTank(tank - index, stack); + return; + } + } + index += handler.getTanks(); + } + } + + @Override + public int getTankCapacity(int tank) { + int index = 0; + for (IFluidHandler handler : transfers) { + if (tank - index < handler.getTanks()) { + return handler.getTankCapacity(tank - index); + } + index += handler.getTanks(); + } + return 0; + } + + @Override + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + if (!filter.test(stack)) return false; + + int index = 0; + for (IFluidHandler handler : transfers) { + if (tank - index < handler.getTanks()) { + return handler.isFluidValid(tank - index, stack); + } + index += handler.getTanks(); + } + return false; + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + if (resource.isEmpty() || !filter.test(resource)) return 0; + var copied = resource.copy(); + for (IFluidHandler handler : transfers) { + var candidate = copied.copy(); + copied.shrink(handler.fill(candidate, action)); + if (copied.isEmpty()) break; + } + return resource.getAmount() - copied.getAmount(); + } + + @Override + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + if (resource.isEmpty() || !filter.test(resource)) return FluidStack.EMPTY; + var copied = resource.copy(); + for (IFluidHandler handler : transfers) { + var candidate = copied.copy(); + copied.shrink(handler.drain(candidate, action).getAmount()); + if (copied.isEmpty()) break; + } + copied.setAmount(resource.getAmount() - copied.getAmount()); + return copied; + } + + @Override + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + if (maxDrain == 0) return FluidStack.EMPTY; + FluidStack totalDrained = null; + for (IFluidHandler handler : transfers) { + if (totalDrained == null || totalDrained.isEmpty()) { + totalDrained = handler.drain(maxDrain, action); + if (totalDrained.isEmpty()) totalDrained = null; + else maxDrain -= totalDrained.getAmount(); + } else { + FluidStack copy = totalDrained.copy(); + copy.setAmount(maxDrain); + FluidStack drain = handler.drain(copy, action); + totalDrained.grow(drain.getAmount()); + maxDrain -= drain.getAmount(); + } + if (maxDrain <= 0) break; + } + return totalDrained == null ? FluidStack.EMPTY : totalDrained; + } + + @Override + public CompoundTag serializeNBT() { + var tag = new CompoundTag(); + var list = new ListTag(); + for (IFluidHandler handler : transfers) { + if (handler instanceof INBTSerializable serializable) { + list.add(serializable.serializeNBT()); + } else { + LDLib.LOGGER.warn("[FluidHandlerList] internal tank doesn't support serialization"); + } + } + tag.put("tanks", list); + tag.putByte("type", list.getElementType()); + return tag; + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + var list = nbt.getList("tanks", nbt.getByte("type")); + for (int i = 0; i < list.size(); i++) { + if (transfers[i] instanceof INBTSerializable serializable) { + serializable.deserializeNBT(list.get(i)); + } else { + LDLib.LOGGER.warn("[FluidHandlerList] internal tank doesn't support serialization"); + } + } + } + + @Override + public boolean supportsFill(int tank) { + for (IFluidHandler handler : transfers) { + if (tank >= handler.getTanks()) { + tank -= handler.getTanks(); + continue; + } + + if (handler instanceof IFluidHandlerModifiable modifiable) { + return modifiable.supportsFill(tank); + } + } + + return true; + } + + @Override + public boolean supportsDrain(int tank) { + for (IFluidHandler handler : transfers) { + if (tank >= handler.getTanks()) { + tank -= handler.getTanks(); + continue; + } + + if (handler instanceof IFluidHandlerModifiable modifiable) { + return modifiable.supportsDrain(tank); + } + } + + return true; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java new file mode 100644 index 0000000000..5ad8c55d94 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java @@ -0,0 +1,269 @@ +package com.gregtechceu.gtceu.api.misc.lib; + +import com.lowdragmc.lowdraglib.LDLib; +import com.lowdragmc.lowdraglib.gui.editor.annotation.ConfigSetter; +import com.lowdragmc.lowdraglib.gui.editor.annotation.LDLRegister; +import com.lowdragmc.lowdraglib.gui.editor.configurator.IConfigurableWidget; +import com.lowdragmc.lowdraglib.gui.ingredient.IGhostIngredientTarget; +import com.lowdragmc.lowdraglib.gui.ingredient.Target; +import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; +import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; +import com.lowdragmc.lowdraglib.utils.Position; +import com.lowdragmc.lowdraglib.utils.Size; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; + +import com.google.common.collect.Lists; +import com.mojang.blaze3d.systems.RenderSystem; +import dev.emi.emi.api.stack.EmiStack; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +@LDLRegister(name = "phantom_fluid_slot", group = "widget.container") +public class PhantomFluidWidget extends TankWidget implements IGhostIngredientTarget, IConfigurableWidget { + + private final Supplier phantomFluidGetter; + private final Consumer phantomFluidSetter; + + @Nullable + @Getter + protected FluidStack lastPhantomStack; + + public PhantomFluidWidget(@Nullable IFluidHandler fluidTank, int tank, int x, int y, int width, int height, + Supplier phantomFluidGetter, Consumer phantomFluidSetter) { + super(fluidTank, tank, x, y, width, height, false, false); + this.phantomFluidGetter = phantomFluidGetter; + this.phantomFluidSetter = phantomFluidSetter; + } + + @ConfigSetter(field = "allowClickFilled") + public PhantomFluidWidget setAllowClickFilled(boolean v) { + // you cant modify it + return this; + } + + @ConfigSetter(field = "allowClickDrained") + public PhantomFluidWidget setAllowClickDrained(boolean v) { + // you cant modify it + return this; + } + + protected void setLastPhantomStack(FluidStack fluid) { + if (fluid != null) { + this.lastPhantomStack = fluid.copy(); + this.lastPhantomStack.setAmount(1); + } else { + this.lastPhantomStack = null; + } + } + + public static FluidStack drainFrom(Object ingredient) { + if (ingredient instanceof Ingredient ing) { + var items = ing.getItems(); + if (items.length > 0) { + ingredient = items[0]; + } + } + if (ingredient instanceof ItemStack itemStack) { + var handler = FluidUtil.getFluidHandler(itemStack); + return handler.map(h -> h.drain(Integer.MAX_VALUE, FluidAction.SIMULATE)).orElse(FluidStack.EMPTY); + // var stack = new ItemStackHandler(NonNullList.of(ItemStack.EMPTY, itemStack)).getStackInSlot(0); + // if(!stack.isEmpty()) { + // var h = stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).resolve(); + // if(h.isPresent()) return h.get().drain(Integer.MAX_VALUE, FluidAction.SIMULATE); + // } + // var handler = FluidTransferHelper.getFluidTransfer(new ItemStackHandler(NonNullList.of(ItemStack.EMPTY, + // itemStack)), 0); + // if (handler != null) { + // return handler.drain(Integer.MAX_VALUE, FluidAction.SIMULATE); + // } + } + return FluidStack.EMPTY; + } + + @Override + @OnlyIn(Dist.CLIENT) + public List getPhantomTargets(Object ingredient) { + if (LDLib.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { + ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), fluidStack.getTag()); + } + if (LDLib.isEmiLoaded() && ingredient instanceof EmiStack fluidEmiStack) { + var fluid = fluidEmiStack.getKeyOfType(Fluid.class); + ingredient = fluid == null ? FluidStack.EMPTY : + new FluidStack(fluid, (int) fluidEmiStack.getAmount(), fluidEmiStack.getNbt()); + } + if (!(ingredient instanceof FluidStack) && drainFrom(ingredient) == null) { + return Collections.emptyList(); + } + + Rect2i rectangle = toRectangleBox(); + return Lists.newArrayList(new Target() { + + @Nonnull + @Override + public Rect2i getArea() { + return rectangle; + } + + @Override + public void accept(@Nonnull Object ingredient) { + FluidStack ingredientStack; + if (LDLib.isReiLoaded() && ingredient instanceof dev.architectury.fluid.FluidStack fluidStack) { + ingredient = new FluidStack(fluidStack.getFluid(), (int) fluidStack.getAmount(), + fluidStack.getTag()); + } + if (LDLib.isEmiLoaded() && ingredient instanceof EmiStack fluidEmiStack) { + var fluid = fluidEmiStack.getKeyOfType(Fluid.class); + ingredient = fluid == null ? FluidStack.EMPTY : + new FluidStack(fluid, (int) fluidEmiStack.getAmount(), fluidEmiStack.getNbt()); + } + if (ingredient instanceof FluidStack fluidStack) + ingredientStack = fluidStack; + else + ingredientStack = drainFrom(ingredient); + + if (ingredientStack != null) { + writeClientAction(2, ingredientStack::writeToPacket); + } + + if (isClientSideWidget) { + if (phantomFluidSetter != null) { + phantomFluidSetter.accept(ingredientStack); + } + } + } + }); + } + + @Override + public void handleClientAction(int id, FriendlyByteBuf buffer) { + if (id == 1) { + handlePhantomClick(); + } else if (id == 2) { + if (phantomFluidSetter != null) { + phantomFluidSetter.accept(FluidStack.readFromPacket(buffer)); + } + } else if (id == 4) { + phantomFluidSetter.accept(FluidStack.EMPTY); + } else if (id == 5) { + phantomFluidSetter.accept(FluidStack.readFromPacket(buffer)); + } + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + FluidStack stack = phantomFluidGetter.get(); + if (stack == null || stack.isEmpty()) { + if (lastPhantomStack != null) { + setLastPhantomStack(null); + writeUpdateInfo(4, buf -> {}); + } + } else if (lastPhantomStack == null || !stack.isFluidEqual(lastPhantomStack)) { + setLastPhantomStack(stack); + writeUpdateInfo(5, stack::writeToPacket); + } + } + + @Override + @OnlyIn(Dist.CLIENT) + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (isMouseOverElement(mouseX, mouseY)) { + if (isClientSideWidget) { + handlePhantomClick(); + } else { + writeClientAction(1, buffer -> {}); + } + return true; + } + return false; + } + + private void handlePhantomClick() { + ItemStack itemStack = gui.getModularUIContainer().getCarried().copy(); + if (!itemStack.isEmpty()) { + itemStack.setCount(1); + var stack = FluidUtil.getFluidHandler(gui.getModularUIContainer().getCarried()) + .map(h -> h.drain(Integer.MAX_VALUE, FluidAction.EXECUTE)).orElse(FluidStack.EMPTY); + if (phantomFluidSetter != null) phantomFluidSetter.accept(stack); + // var handler = FluidUtil.getFluidHandler(gui.getModularUIContainer().getCarried()).resolve(); + // if(handler.isPresent()) { + // FluidStack result = handler.get().drain(Integer.MAX_VALUE, FluidAction.EXECUTE); + // if(phantomFluidSetter != null) phantomFluidSetter.accept(result); + // } + // var handler = FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()); + // if (handler != null) { + // FluidStack resultFluid = handler.drain(Integer.MAX_VALUE, FluidAction.EXECUTE); + // if (phantomFluidSetter != null) { + // phantomFluidSetter.accept(resultFluid); + // } + // } + } else { + if (phantomFluidSetter != null) { + phantomFluidSetter.accept(FluidStack.EMPTY); + } + } + } + + @Override + public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + if (this.lastFluidInTank != null) { + super.drawInBackground(graphics, mouseX, mouseY, partialTicks); + return; + } + Position pos = getPosition(); + Size size = getSize(); + FluidStack stack = phantomFluidGetter.get(); + if (stack != null && !stack.isEmpty()) { + RenderSystem.disableBlend(); + + double progress = stack.getAmount() * 1.0 / Math.max(Math.max(stack.getAmount(), lastTankCapacity), 1); + float drawnU = (float) fillDirection.getDrawnU(progress); + float drawnV = (float) fillDirection.getDrawnV(progress); + float drawnWidth = (float) fillDirection.getDrawnWidth(progress); + float drawnHeight = (float) fillDirection.getDrawnHeight(progress); + int width = size.width - 2; + int height = size.height - 2; + int x = pos.x + 1; + int y = pos.y + 1; + DrawerHelper.drawFluidForGui(graphics, FluidHelperImpl.toFluidStack(stack), stack.getAmount(), + (int) (x + drawnU * width), (int) (y + drawnV * height), ((int) (width * drawnWidth)), + ((int) (height * drawnHeight))); + if (showAmount) { + graphics.pose().pushPose(); + graphics.pose().scale(0.5F, 0.5F, 1); + String s = TextFormattingUtil.formatLongToCompactStringBuckets(stack.getAmount(), 3) + "B"; + Font fontRenderer = Minecraft.getInstance().font; + graphics.drawString(fontRenderer, s, + (int) ((pos.x + (size.width / 3f)) * 2 - fontRenderer.width(s) + 21), + (int) ((pos.y + (size.height / 3f) + 6) * 2), 0xFFFFFF, true); + graphics.pose().popPose(); + } + + RenderSystem.enableBlend(); + RenderSystem.setShaderColor(1, 1, 1, 1); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java new file mode 100644 index 0000000000..dc2a4f83d4 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java @@ -0,0 +1,116 @@ +package com.gregtechceu.gtceu.api.misc.lib; + +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.material.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.util.Pair; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class TagOrCycleFluidTransfer implements IFluidHandlerModifiable { + + @Getter + private List, Integer>>, List>> stacks; + + private List> unwrapped = null; + + public TagOrCycleFluidTransfer(List, Integer>>, List>> stacks) { + updateStacks(stacks); + } + + public void updateStacks(List, Integer>>, List>> stacks) { + this.stacks = new ArrayList<>(stacks); + this.unwrapped = null; + } + + public List> getUnwrapped() { + if (unwrapped == null) { + unwrapped = stacks.stream() + .map(tagOrFluid -> { + if (tagOrFluid == null) { + return null; + } + return tagOrFluid.map( + tagList -> tagList + .stream() + .flatMap(pair -> BuiltInRegistries.FLUID.getTag(pair.getFirst()) + .map(holderSet -> holderSet.stream() + .map(holder -> new FluidStack(holder.value(), + pair.getSecond()))) + .orElseGet(Stream::empty)) + .toList(), + Function.identity()); + }) + .collect(Collectors.toList()); + } + return unwrapped; + } + + @Override + public int getTanks() { + return stacks.size(); + } + + @NotNull + @Override + public FluidStack getFluidInTank(int tank) { + List stackList = getUnwrapped().get(tank); + return stackList == null || stackList.isEmpty() ? FluidStack.EMPTY : + stackList.get(Math.abs((int) (System.currentTimeMillis() / 1000) % stackList.size())); + } + + @Override + public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { + if (tank >= 0 && tank < stacks.size()) { + stacks.set(tank, Either.right(List.of(fluidStack))); + unwrapped = null; + } + } + + @Override + public int getTankCapacity(int tank) { + return getFluidInTank(tank).getAmount(); + } + + @Override + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + return true; + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + return 0; + } + + @Override + public boolean supportsFill(int tank) { + return false; + } + + @NotNull + @Override + public FluidStack drain(FluidStack resource, FluidAction action) { + return FluidStack.EMPTY; + } + + @Override + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return FluidStack.EMPTY; + } + + @Override + public boolean supportsDrain(int tank) { + return false; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java new file mode 100644 index 0000000000..609bbee21c --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java @@ -0,0 +1,731 @@ +package com.gregtechceu.gtceu.api.misc.lib; + +import com.lowdragmc.lowdraglib.LDLib; +import com.lowdragmc.lowdraglib.Platform; +import com.lowdragmc.lowdraglib.gui.editor.annotation.Configurable; +import com.lowdragmc.lowdraglib.gui.editor.annotation.LDLRegister; +import com.lowdragmc.lowdraglib.gui.editor.configurator.ConfiguratorGroup; +import com.lowdragmc.lowdraglib.gui.editor.configurator.IConfigurableWidget; +import com.lowdragmc.lowdraglib.gui.editor.configurator.WrapperConfigurator; +import com.lowdragmc.lowdraglib.gui.ingredient.IRecipeIngredientSlot; +import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; +import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; +import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; +import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; +import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; +import com.lowdragmc.lowdraglib.gui.widget.Widget; +import com.lowdragmc.lowdraglib.jei.ClickableIngredient; +import com.lowdragmc.lowdraglib.jei.IngredientIO; +import com.lowdragmc.lowdraglib.jei.JEIPlugin; +import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; +import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; +import com.lowdragmc.lowdraglib.utils.CycleFluidTransfer; +import com.lowdragmc.lowdraglib.utils.Position; +import com.lowdragmc.lowdraglib.utils.Size; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.Fluids; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.SoundActions; +import net.minecraftforge.fluids.FluidActionResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.templates.FluidTank; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.util.Pair; +import dev.emi.emi.api.stack.EmiIngredient; +import dev.emi.emi.api.stack.EmiStack; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.util.EntryIngredients; +import me.shedaniel.rei.api.common.util.EntryStacks; +import mezz.jei.api.helpers.IPlatformFluidHelper; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +@SuppressWarnings("unused") +@LDLRegister(name = "fluid_slot", group = "widget.container") +@Accessors(chain = true) +public class TankWidget extends Widget implements IRecipeIngredientSlot, IConfigurableWidget { + + public final static ResourceBorderTexture FLUID_SLOT_TEXTURE = new ResourceBorderTexture( + "ldlib:textures/gui/fluid_slot.png", 18, 18, 1, 1); + + @Nullable + @Getter + protected IFluidHandler fluidTank; + @Getter + protected int tank; + @Configurable(name = "ldlib.gui.editor.name.showAmount") + @Setter + protected boolean showAmount; + @Configurable(name = "ldlib.gui.editor.name.allowClickFilled") + @Setter + protected boolean allowClickFilled; + @Configurable(name = "ldlib.gui.editor.name.allowClickDrained") + @Setter + protected boolean allowClickDrained; + @Configurable(name = "ldlib.gui.editor.name.drawHoverOverlay") + @Setter + public boolean drawHoverOverlay = true; + @Configurable(name = "ldlib.gui.editor.name.drawHoverTips") + @Setter + protected boolean drawHoverTips; + @Configurable(name = "ldlib.gui.editor.name.fillDirection") + @Setter + protected ProgressTexture.FillDirection fillDirection = ProgressTexture.FillDirection.ALWAYS_FULL; + @Setter + protected BiConsumer> onAddedTooltips; + @Setter + @Getter + protected IngredientIO ingredientIO = IngredientIO.RENDER_ONLY; + @Setter + @Getter + protected float XEIChance = 1f; + protected FluidStack lastFluidInTank; + protected int lastTankCapacity; + @Setter + protected Runnable changeListener; + @NotNull + protected List>> tooltipCallback = new ArrayList<>(); + + public TankWidget() { + this(null, 0, 0, 18, 18, true, true); + } + + @Override + public void initTemplate() { + setBackground(FLUID_SLOT_TEXTURE); + setFillDirection(ProgressTexture.FillDirection.DOWN_TO_UP); + } + + public TankWidget(IFluidHandler fluidTank, int x, int y, boolean allowClickContainerFilling, + boolean allowClickContainerEmptying) { + this(fluidTank, x, y, 18, 18, allowClickContainerFilling, allowClickContainerEmptying); + } + + public TankWidget(@Nullable IFluidHandler fluidTank, int x, int y, int width, int height, + boolean allowClickContainerFilling, boolean allowClickContainerEmptying) { + super(new Position(x, y), new Size(width, height)); + this.fluidTank = fluidTank; + this.tank = 0; + this.showAmount = true; + this.allowClickFilled = allowClickContainerFilling; + this.allowClickDrained = allowClickContainerEmptying; + this.drawHoverTips = true; + } + + public TankWidget(IFluidHandler fluidTank, int tank, int x, int y, boolean allowClickContainerFilling, + boolean allowClickContainerEmptying) { + this(fluidTank, tank, x, y, 18, 18, allowClickContainerFilling, allowClickContainerEmptying); + } + + public TankWidget(@Nullable IFluidHandler fluidTank, int tank, int x, int y, int width, int height, + boolean allowClickContainerFilling, boolean allowClickContainerEmptying) { + super(new Position(x, y), new Size(width, height)); + this.fluidTank = fluidTank; + this.tank = tank; + this.showAmount = true; + this.allowClickFilled = allowClickContainerFilling; + this.allowClickDrained = allowClickContainerEmptying; + this.drawHoverTips = true; + } + + public TankWidget setFluidTank(IFluidHandler fluidTank) { + this.fluidTank = fluidTank; + this.tank = 0; + if (isClientSideWidget) { + setClientSideWidget(); + } + return this; + } + + public TankWidget setFluidTank(IFluidHandler fluidTank, int tank) { + this.fluidTank = fluidTank; + this.tank = tank; + if (isClientSideWidget) { + setClientSideWidget(); + } + return this; + } + + @Override + public TankWidget setClientSideWidget() { + super.setClientSideWidget(); + if (fluidTank != null) { + this.lastFluidInTank = fluidTank.getFluidInTank(tank).copy(); + } else { + this.lastFluidInTank = null; + } + this.lastTankCapacity = fluidTank != null ? fluidTank.getTankCapacity(tank) : 0; + return this; + } + + public TankWidget setBackground(IGuiTexture background) { + super.setBackground(background); + return this; + } + + @Nullable + @Override + public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { + if (self().isMouseOverElement(mouseX, mouseY)) { + if (lastFluidInTank == null || lastFluidInTank.isEmpty()) return null; + + if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { + return getXEIIngredientsFromCycleTransferClickable(cycleItemStackHandler, tank).get(0); + } else if (this.fluidTank instanceof TagOrCycleFluidTransfer transfer) { + return getXEIIngredientsFromTagOrCycleTransferClickable(transfer, tank).get(0); + } + + if (LDLib.isJeiLoaded()) { + return JEICallWrapper.getPlatformFluidTypeForJEIClickable(lastFluidInTank, getPosition(), getSize()); + } + if (LDLib.isReiLoaded()) { + return EntryStacks.of(dev.architectury.fluid.FluidStack.create(lastFluidInTank.getFluid(), + lastFluidInTank.getAmount(), lastFluidInTank.getOrCreateTag())); + } + if (LDLib.isEmiLoaded()) { + return EmiStack + .of(lastFluidInTank.getFluid(), lastFluidInTank.getOrCreateTag(), lastFluidInTank.getAmount()) + .setChance(XEIChance); + } + } + return null; + } + + @Override + public List getXEIIngredients() { + if (lastFluidInTank == null || lastFluidInTank.isEmpty()) return Collections.emptyList(); + + if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { + return getXEIIngredientsFromCycleTransfer(cycleItemStackHandler, tank); + } else if (this.fluidTank instanceof TagOrCycleFluidTransfer transfer) { + return getXEIIngredientsFromTagOrCycleTransfer(transfer, tank); + } + + if (LDLib.isJeiLoaded()) { + return List.of(JEICallWrapper.getPlatformFluidTypeForJEI(lastFluidInTank)); + } + if (LDLib.isReiLoaded()) { + return List.of(EntryStacks.of(dev.architectury.fluid.FluidStack.create(lastFluidInTank.getFluid(), + lastFluidInTank.getAmount(), lastFluidInTank.getOrCreateTag()))); + } + if (LDLib.isEmiLoaded()) { + return List.of(EmiStack + .of(lastFluidInTank.getFluid(), lastFluidInTank.getOrCreateTag(), lastFluidInTank.getAmount()) + .setChance(XEIChance)); + } + return List.of(lastFluidInTank); + } + + private List getXEIIngredientsFromCycleTransfer(CycleFluidTransfer transfer, int index) { + var stream = transfer.getStackList(index).stream().map(FluidHelper::toRealFluidStack) + .map(FluidStack.class::cast); + if (LDLib.isJeiLoaded()) { + return stream.filter(fluid -> !fluid.isEmpty()).map(JEICallWrapper::getPlatformFluidTypeForJEI).toList(); + } else if (LDLib.isReiLoaded()) { + return REICallWrapper.getReiIngredients(stream); + } else if (LDLib.isEmiLoaded()) { + return EMICallWrapper.getEmiIngredients(stream, getXEIChance()); + } + return Collections.emptyList(); + } + + private List getXEIIngredientsFromCycleTransferClickable(CycleFluidTransfer transfer, int index) { + var stream = transfer.getStackList(index).stream().map(FluidHelper::toRealFluidStack) + .map(FluidStack.class::cast); + if (LDLib.isJeiLoaded()) { + return stream + .filter(fluid -> !fluid.isEmpty()) + .map(fluid -> JEICallWrapper.getPlatformFluidTypeForJEIClickable(fluid, getPosition(), getSize())) + .toList(); + } else if (LDLib.isReiLoaded()) { + return REICallWrapper.getReiIngredients(stream); + } else if (LDLib.isEmiLoaded()) { + return EMICallWrapper.getEmiIngredients(stream, getXEIChance()); + } + return Collections.emptyList(); + } + + private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidTransfer transfer, int index) { + Either, Integer>>, List> either = transfer + .getStacks() + .get(index); + var ref = new Object() { + + List returnValue = Collections.emptyList(); + }; + either.ifLeft(list -> { + if (LDLib.isJeiLoaded()) { + ref.returnValue = list.stream() + .flatMap(pair -> BuiltInRegistries.FLUID + .getTag(pair.getFirst()) + .stream() + .flatMap(HolderSet.ListBacked::stream) + .map(fluid -> JEICallWrapper + .getPlatformFluidTypeForJEI(new FluidStack(fluid.value(), pair.getSecond())))) + .collect(Collectors.toList()); + } else if (LDLib.isReiLoaded()) { + ref.returnValue = REICallWrapper.getReiIngredients(list); + } else if (LDLib.isEmiLoaded()) { + ref.returnValue = EMICallWrapper.getEmiIngredients(list, getXEIChance()); + } + }).ifRight(fluids -> { + var stream = fluids.stream(); + if (LDLib.isJeiLoaded()) { + ref.returnValue = stream.filter(fluid -> !fluid.isEmpty()) + .map(JEICallWrapper::getPlatformFluidTypeForJEI).toList(); + } else if (LDLib.isReiLoaded()) { + ref.returnValue = REICallWrapper.getReiIngredients(stream); + } else if (LDLib.isEmiLoaded()) { + ref.returnValue = EMICallWrapper.getEmiIngredients(stream, getXEIChance()); + } + }); + return ref.returnValue; + } + + private List getXEIIngredientsFromTagOrCycleTransferClickable(TagOrCycleFluidTransfer transfer, int index) { + Either, Integer>>, List> either = transfer + .getStacks() + .get(index); + var ref = new Object() { + + List returnValue = Collections.emptyList(); + }; + either.ifLeft(list -> { + if (LDLib.isJeiLoaded()) { + ref.returnValue = list.stream() + .flatMap(pair -> BuiltInRegistries.FLUID + .getTag(pair.getFirst()) + .stream() + .flatMap(HolderSet.ListBacked::stream) + .map(fluid -> JEICallWrapper.getPlatformFluidTypeForJEIClickable( + new FluidStack(fluid.value(), pair.getSecond()), getPosition(), getSize()))) + .collect(Collectors.toList()); + } else if (LDLib.isReiLoaded()) { + ref.returnValue = REICallWrapper.getReiIngredients(list); + } else if (LDLib.isEmiLoaded()) { + ref.returnValue = EMICallWrapper.getEmiIngredients(list, getXEIChance()); + } + }).ifRight(fluids -> { + var stream = fluids.stream(); + if (LDLib.isJeiLoaded()) { + ref.returnValue = stream + .filter(fluid -> !fluid.isEmpty()) + .map(fluid -> JEICallWrapper.getPlatformFluidTypeForJEIClickable(fluid, getPosition(), + getSize())) + .toList(); + } else if (LDLib.isReiLoaded()) { + ref.returnValue = REICallWrapper.getReiIngredients(stream); + } else if (LDLib.isEmiLoaded()) { + ref.returnValue = EMICallWrapper.getEmiIngredients(stream, getXEIChance()); + } + }); + return ref.returnValue; + } + + @Override + public List getTooltipTexts() { + List tooltips = getToolTips(new ArrayList<>()); + tooltips.addAll(tooltipTexts); + return tooltips; + } + + private List getToolTips(List list) { + if (this.onAddedTooltips != null) { + this.onAddedTooltips.accept(this, list); + } + for (Consumer> callback : this.tooltipCallback) { + callback.accept(list); + } + + return list; + } + + @Override + public void addTooltipCallback(Consumer> callback) { + this.tooltipCallback.add(callback); + } + + @Override + public void clearTooltipCallback() { + this.tooltipCallback.clear(); + } + + @Override + @OnlyIn(Dist.CLIENT) + public void drawInBackground(@Nonnull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + super.drawInBackground(graphics, mouseX, mouseY, partialTicks); + if (isClientSideWidget && fluidTank != null) { + FluidStack fluidStack = fluidTank.getFluidInTank(tank); + int capacity = fluidTank.getTankCapacity(tank); + if (capacity != lastTankCapacity) { + this.lastTankCapacity = capacity; + } + if (!fluidStack.isFluidEqual(lastFluidInTank)) { + this.lastFluidInTank = fluidStack.copy(); + } else if (fluidStack.getAmount() != lastFluidInTank.getAmount()) { + this.lastFluidInTank.setAmount(fluidStack.getAmount()); + } + } + Position pos = getPosition(); + Size size = getSize(); + if (lastFluidInTank != null) { + RenderSystem.disableBlend(); + if (!lastFluidInTank.isEmpty()) { + double progress = lastFluidInTank.getAmount() * 1.0 / + Math.max(Math.max(lastFluidInTank.getAmount(), lastTankCapacity), 1); + float drawnU = (float) fillDirection.getDrawnU(progress); + float drawnV = (float) fillDirection.getDrawnV(progress); + float drawnWidth = (float) fillDirection.getDrawnWidth(progress); + float drawnHeight = (float) fillDirection.getDrawnHeight(progress); + int width = size.width - 2; + int height = size.height - 2; + int x = pos.x + 1; + int y = pos.y + 1; + DrawerHelper.drawFluidForGui(graphics, FluidHelperImpl.toFluidStack(lastFluidInTank), + lastFluidInTank.getAmount(), (int) (x + drawnU * width), (int) (y + drawnV * height), + ((int) (width * drawnWidth)), ((int) (height * drawnHeight))); + } + + if (showAmount && !lastFluidInTank.isEmpty()) { + graphics.pose().pushPose(); + graphics.pose().scale(0.5F, 0.5F, 1); + String s = TextFormattingUtil.formatLongToCompactStringBuckets(lastFluidInTank.getAmount(), 3) + "B"; + Font fontRenderer = Minecraft.getInstance().font; + graphics.drawString(fontRenderer, s, + (int) ((pos.x + (size.width / 3f)) * 2 - fontRenderer.width(s) + 21), + (int) ((pos.y + (size.height / 3f) + 6) * 2), 0xFFFFFF, true); + graphics.pose().popPose(); + } + + RenderSystem.enableBlend(); + RenderSystem.setShaderColor(1, 1, 1, 1); + } + drawOverlay(graphics, mouseX, mouseY, partialTicks); + if (drawHoverOverlay && isMouseOverElement(mouseX, mouseY) && getHoverElement(mouseX, mouseY) == this) { + RenderSystem.colorMask(true, true, true, false); + DrawerHelper.drawSolidRect(graphics, getPosition().x + 1, getPosition().y + 1, getSize().width - 2, + getSize().height - 2, 0x80FFFFFF); + RenderSystem.colorMask(true, true, true, true); + } + } + + @Override + @OnlyIn(Dist.CLIENT) + public void drawInForeground(@Nonnull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + if (drawHoverTips && isMouseOverElement(mouseX, mouseY) && getHoverElement(mouseX, mouseY) == this) { + List tooltips = new ArrayList<>(); + if (lastFluidInTank != null && !lastFluidInTank.isEmpty()) { + tooltips.add(lastFluidInTank.getDisplayName()); + tooltips.add(Component.translatable("ldlib.fluid.amount", lastFluidInTank.getAmount(), lastTankCapacity) + .append(" " + FluidHelper.getUnit())); + if (!Platform.isForge()) { + tooltips.add(Component.literal( + "§6mB:§r %d/%d".formatted(lastFluidInTank.getAmount() * 1000 / FluidType.BUCKET_VOLUME, + lastTankCapacity * 1000 / FluidType.BUCKET_VOLUME)) + .append(" " + "mB")); + } + tooltips.add(Component.translatable("ldlib.fluid.temperature", + lastFluidInTank.getFluid().getFluidType().getTemperature())); + tooltips.add(Component.translatable(lastFluidInTank.getFluid().getFluidType().isLighterThanAir() ? + "ldlib.fluid.state_gas" : "ldlib.fluid.state_liquid")); + } else { + tooltips.add(Component.translatable("ldlib.fluid.empty")); + tooltips.add(Component.translatable("ldlib.fluid.amount", 0, lastTankCapacity) + .append(" " + FluidHelper.getUnit())); + if (!Platform.isForge()) { + tooltips.add(Component + .literal("§6mB:§r %d/%d".formatted(0, lastTankCapacity * 1000 / FluidType.BUCKET_VOLUME)) + .append(" " + "mB")); + } + } + if (gui != null) { + tooltips.addAll(getTooltipTexts()); + gui.getModularUIGui().setHoverTooltip(tooltips, ItemStack.EMPTY, null, null); + } + RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1f); + } else { + super.drawInForeground(graphics, mouseX, mouseY, partialTicks); + } + } + + @Override + public void detectAndSendChanges() { + if (fluidTank != null) { + FluidStack fluidStack = fluidTank.getFluidInTank(tank); + int capacity = fluidTank.getTankCapacity(tank); + if (capacity != lastTankCapacity) { + this.lastTankCapacity = capacity; + writeUpdateInfo(0, buffer -> buffer.writeVarInt(lastTankCapacity)); + } + if (!fluidStack.isFluidEqual(lastFluidInTank)) { + this.lastFluidInTank = fluidStack.copy(); + var tag = fluidStack.writeToNBT(new CompoundTag()); + writeUpdateInfo(2, buffer -> buffer.writeNbt(tag)); + } else if (fluidStack.getAmount() != lastFluidInTank.getAmount()) { + this.lastFluidInTank.setAmount(fluidStack.getAmount()); + writeUpdateInfo(3, buffer -> buffer.writeVarInt(lastFluidInTank.getAmount())); + } else { + super.detectAndSendChanges(); + return; + } + if (changeListener != null) { + changeListener.run(); + } + } + } + + @Override + public void writeInitialData(FriendlyByteBuf buffer) { + buffer.writeBoolean(fluidTank != null); + if (fluidTank != null) { + this.lastTankCapacity = fluidTank.getTankCapacity(tank); + buffer.writeVarInt(lastTankCapacity); + FluidStack fluidStack = fluidTank.getFluidInTank(tank); + this.lastFluidInTank = fluidStack.copy(); + var tag = fluidStack.writeToNBT(new CompoundTag()); + buffer.writeNbt(tag); + } + } + + @Override + public void readInitialData(FriendlyByteBuf buffer) { + if (buffer.readBoolean()) { + this.lastTankCapacity = buffer.readVarInt(); + readUpdateInfo(2, buffer); + } + } + + @Override + @OnlyIn(Dist.CLIENT) + public void readUpdateInfo(int id, FriendlyByteBuf buffer) { + if (id == 0) { + this.lastTankCapacity = buffer.readVarInt(); + } else if (id == 1) { + this.lastFluidInTank = null; + } else if (id == 2) { + this.lastFluidInTank = FluidStack.loadFluidStackFromNBT(buffer.readNbt()); + } else if (id == 3 && lastFluidInTank != null) { + this.lastFluidInTank.setAmount(buffer.readVarInt()); + } else if (id == 4) { + ItemStack currentStack = gui.getModularUIContainer().getCarried(); + int newStackSize = buffer.readVarInt(); + currentStack.setCount(newStackSize); + gui.getModularUIContainer().setCarried(currentStack); + } else { + super.readUpdateInfo(id, buffer); + return; + } + if (changeListener != null) { + changeListener.run(); + } + } + + @Override + public void handleClientAction(int id, FriendlyByteBuf buffer) { + super.handleClientAction(id, buffer); + if (id == 1) { + boolean isShiftKeyDown = buffer.readBoolean(); + int clickResult = tryClickContainer(isShiftKeyDown); + if (clickResult >= 0) { + writeUpdateInfo(4, buf -> buf.writeVarInt(clickResult)); + } + } + } + + private int tryClickContainer(boolean isShiftKeyDown) { + if (fluidTank == null) return -1; + Player player = gui.entityPlayer; + ItemStack currentStack = gui.getModularUIContainer().getCarried(); + var handler = FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()); + if (handler == null) return -1; + int maxAttempts = isShiftKeyDown ? currentStack.getCount() : 1; + FluidStack initialFluid = fluidTank.getFluidInTank(tank); + if (allowClickFilled && initialFluid.getAmount() > 0) { + boolean performedFill = false; + for (int i = 0; i < maxAttempts; i++) { + FluidActionResult result = FluidUtil.tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, + false); + if (!result.isSuccess()) break; + ItemStack remainingStack = FluidUtil + .tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); + currentStack.shrink(1); + performedFill = true; + if (!remainingStack.isEmpty() && !player.addItem(remainingStack)) { + Block.popResource(player.level(), player.getOnPos(), remainingStack); + break; + } + } + if (performedFill) { + SoundEvent soundevent = initialFluid.getFluid().getFluidType().getSound(SoundActions.BUCKET_FILL); + if (soundevent != null) { + player.level().playSound(null, player.position().x, player.position().y + 0.5, player.position().z, + soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); + } + gui.getModularUIContainer().setCarried(currentStack); + return currentStack.getCount(); + } + } + + if (allowClickDrained) { + boolean performedEmptying = false; + for (int i = 0; i < maxAttempts; i++) { + FluidActionResult result = FluidUtil.tryEmptyContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, + false); + if (!result.isSuccess()) break; + ItemStack remainingStack = FluidUtil + .tryEmptyContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); + currentStack.shrink(1); + performedEmptying = true; + if (!remainingStack.isEmpty() && !player.getInventory().add(remainingStack)) { + Block.popResource(player.level(), player.getOnPos(), remainingStack); + break; + } + } + var filledFluid = fluidTank.getFluidInTank(tank); + if (performedEmptying) { + SoundEvent soundevent = filledFluid.getFluid().getFluidType().getSound(SoundActions.BUCKET_EMPTY); + if (soundevent != null) { + player.level().playSound(null, player.position().x, player.position().y + 0.5, player.position().z, + soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); + } + gui.getModularUIContainer().setCarried(currentStack); + return currentStack.getCount(); + } + } + + return -1; + } + + @OnlyIn(Dist.CLIENT) + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if ((allowClickDrained || allowClickFilled) && isMouseOverElement(mouseX, mouseY)) { + if (button == 0) { + if (FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()) != null) { + boolean isShiftKeyDown = isShiftDown(); + writeClientAction(1, writer -> writer.writeBoolean(isShiftKeyDown)); + playButtonClickSound(); + return true; + } + } + } + return false; + } + + @Override + public void buildConfigurator(ConfiguratorGroup father) { + var handler = new FluidTank(5000); + handler.fill(new FluidStack(Fluids.WATER, 3000), IFluidHandler.FluidAction.EXECUTE); + father.addConfigurators(new WrapperConfigurator("ldlib.gui.editor.group.preview", new TankWidget() { + + @Override + public void updateScreen() { + super.updateScreen(); + setHoverTooltips(TankWidget.this.tooltipTexts); + this.backgroundTexture = TankWidget.this.backgroundTexture; + this.hoverTexture = TankWidget.this.hoverTexture; + this.showAmount = TankWidget.this.showAmount; + this.drawHoverTips = TankWidget.this.drawHoverTips; + this.fillDirection = TankWidget.this.fillDirection; + this.overlay = TankWidget.this.overlay; + } + }.setAllowClickDrained(false).setAllowClickFilled(false).setFluidTank(handler))); + + IConfigurableWidget.super.buildConfigurator(father); + } + + /** + * Wrapper for methods that use JEI classes so that classloading doesn't brick itself. + */ + public static final class JEICallWrapper { + + public static Object getPlatformFluidTypeForJEI(FluidStack fluidStack) { + return _getPlatformFluidTypeForJEI(JEIPlugin.jeiHelpers.getPlatformFluidHelper(), fluidStack); + } + + private static Object _getPlatformFluidTypeForJEI(IPlatformFluidHelper helper, FluidStack fluidStack) { + return helper.create(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getOrCreateTag()); + } + + public static Object getPlatformFluidTypeForJEIClickable(FluidStack fluidStack, Position pos, Size size) { + return _getPlatformFluidTypeForJEIClickable(JEIPlugin.jeiHelpers.getPlatformFluidHelper(), fluidStack, pos, + size); + } + + private static Object _getPlatformFluidTypeForJEIClickable(IPlatformFluidHelper helper, + FluidStack fluidStack, Position pos, Size size) { + T ingredient = helper.create(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getOrCreateTag()); + return JEIPlugin.jeiHelpers.getIngredientManager().createTypedIngredient(ingredient) + .map(typedIngredient -> new ClickableIngredient<>(typedIngredient, pos.x, pos.y, size.width, + size.height)) + .orElse(null); + } + } + + public static final class REICallWrapper { + + public static List getReiIngredients(Stream stream) { + return List.of(EntryIngredient.of(stream + .map(fluidStack -> dev.architectury.fluid.FluidStack.create(fluidStack.getFluid(), + fluidStack.getAmount(), fluidStack.getOrCreateTag())) + .map(EntryStacks::of) + .toList())); + } + + public static List getReiIngredients(List, Integer>> list) { + return list.stream() + .map(pair -> EntryIngredients.ofTag(pair.getFirst(), + holder -> EntryStacks + .of(dev.architectury.fluid.FluidStack.create(holder.value(), pair.getSecond())))) + .collect(Collectors.toList()); + } + } + + public static final class EMICallWrapper { + + public static List getEmiIngredients(Stream stream, float xeiChance) { + return List.of(EmiIngredient.of(stream.map(fluidStack -> EmiStack.of(fluidStack.getFluid(), + fluidStack.getOrCreateTag(), fluidStack.getAmount())).toList()).setChance(xeiChance)); + } + + public static List getEmiIngredients(List, Integer>> list, float xeiChance) { + return list.stream() + .map(pair -> EmiIngredient.of(pair.getFirst()).setAmount(pair.getSecond()).setChance(xeiChance)) + .collect(Collectors.toList()); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java index 0deb4a965f..055a26058e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java @@ -3,12 +3,16 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.syncdata.GTRecipePayload; +import com.gregtechceu.gtceu.syncdata.FluidStackLoad; +import com.gregtechceu.gtceu.syncdata.GTRecipeAccessor; import com.gregtechceu.gtceu.syncdata.GTRecipeTypeAccessor; import com.gregtechceu.gtceu.syncdata.MaterialPayload; import com.lowdragmc.lowdraglib.syncdata.IAccessor; import com.lowdragmc.lowdraglib.syncdata.payload.FriendlyBufPayload; +import net.minecraftforge.fluids.FluidStack; + import static com.lowdragmc.lowdraglib.syncdata.TypedPayloadRegistries.*; /** @@ -25,5 +29,6 @@ public static void init() { registerSimple(MaterialPayload.class, MaterialPayload::new, Material.class, 1); registerSimple(GTRecipePayload.class, GTRecipePayload::new, GTRecipe.class, 100); + registerSimple(FluidStackLoad.class, FluidStackLoad::new, FluidStack.class, -1); } } diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/ldlib/SyncUtilsMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/ldlib/SyncUtilsMixin.java new file mode 100644 index 0000000000..be5a3c07bf --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/ldlib/SyncUtilsMixin.java @@ -0,0 +1,31 @@ +package com.gregtechceu.gtceu.core.mixins.ldlib; + +import com.lowdragmc.lowdraglib.syncdata.SyncUtils; + +import net.minecraftforge.fluids.FluidStack; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SyncUtils.class) +public class SyncUtilsMixin { + + @Inject(method = "isChanged", at = @At("HEAD"), cancellable = true, remap = false) + private static void gtceu$isChanged(Object oldValue, Object newValue, CallbackInfoReturnable cir) { + if (oldValue instanceof FluidStack fluidStack) { + if (!(newValue instanceof FluidStack)) { + cir.setReturnValue(true); + } + cir.setReturnValue(!fluidStack.isFluidStackIdentical((FluidStack) newValue)); + } + } + + @Inject(method = "copyWhenNecessary", at = @At("HEAD"), cancellable = true, remap = false) + private static void gtceu$copyWhenNecessary(Object value, CallbackInfoReturnable cir) { + if (value instanceof FluidStack fluidStack) { + cir.setReturnValue(fluidStack.copy()); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java new file mode 100644 index 0000000000..7540b3a0e3 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java @@ -0,0 +1,34 @@ +package com.gregtechceu.gtceu.syncdata; + +import com.lowdragmc.lowdraglib.syncdata.payload.ObjectTypedPayload; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.Nullable; + +public class FluidStackLoad extends ObjectTypedPayload { + + @Override + public void writePayload(FriendlyByteBuf buf) { + payload.writeToPacket(buf); + } + + @Override + public void readPayload(FriendlyByteBuf buf) { + payload = FluidStack.readFromPacket(buf); + } + + @Nullable + @Override + public Tag serializeNBT() { + return payload.writeToNBT(new CompoundTag()); + } + + @Override + public void deserializeNBT(Tag tag) { + payload = FluidStack.loadFluidStackFromNBT((CompoundTag) tag); + } +} diff --git a/src/main/resources/gtceu.mixins.json b/src/main/resources/gtceu.mixins.json index ec71dfef3b..8fe219d4fe 100644 --- a/src/main/resources/gtceu.mixins.json +++ b/src/main/resources/gtceu.mixins.json @@ -1,71 +1,72 @@ { - "required": true, - "minVersion": "0.8", - "refmap": "gtceu.refmap.json", - "package": "com.gregtechceu.gtceu.core.mixins", - "compatibilityLevel": "JAVA_17", - "plugin": "com.gregtechceu.gtceu.core.mixins.GregTechMixinPlugin", - "client": [ - "BlockColorsMixin", - "BlockModelMixin", - "ClientLevelAccessor", - "CompassManagerMixin", - "GuiGraphicsAccessor", - "GuiGraphicsMixin", - "GuiHeartTypeMixin", - "LevelRendererMixin", - "ModelManagerMixin", - "MultiPlayerGameModeMixin", - "rei.FluidEntryRendererMixin" - ], - "mixins": [ - "AbstractRegistrateAccessor", - "BlockBehaviourAccessor", - "BlockMixin", - "BlockPropertiesAccessor", - "ChunkGeneratorMixin", - "ChunkMixin", - "CreeperMixin", - "EntityMixin", - "IFoliagePlacerTypeAccessor", - "IHolderReferenceAccessor", - "IngredientAccessor", - "IntersectionIngredientAccessor", - "InventoryMixin", - "ItemValueAccessor", - "ITrunkPlacerTypeAccessor", - "LevelMixin", - "LivingEntityMixin", - "LootDataManagerMixin", - "LootPoolAccessor", - "OreConfigurationMixin", - "OreVeinifierMixin", - "PartialNBTIngredientAccessor", - "PrimedTntAccessor", - "RecipeManagerAccessor", - "RecipeManagerInvoker", - "RecipeManagerMixin", - "RepairItemRecipeMixin", - "ServerChunkProviderMixin", - "ServerGamePacketListenerImplAccessor", - "ShapedRecipeAccessor", - "SidedRedstoneConnectivityMixin", - "StrictNBTIngredientAccessor", - "TagLoaderMixin", - "TagManagerMixin", - "TagValueAccessor", - "ae2.GenericStackInvAccessor", - "create.RotationPropagatorMixin", - "embeddium.BiomeColorCacheMixin", - "embeddium.VanillaColorAdapterMixin", - "emi.FluidEmiStackMixin", - "jei.FluidHelperMixin", - "rei.InputSlotCrafterMixin", - "rei.RecipeFinderMixin", - "top.ConfigMixin" - ], - "injectors": { - "defaultRequire": 1, - "maxShiftBy": 5 - } + "required": true, + "minVersion": "0.8", + "refmap": "gtceu.refmap.json", + "package": "com.gregtechceu.gtceu.core.mixins", + "compatibilityLevel": "JAVA_17", + "plugin": "com.gregtechceu.gtceu.core.mixins.GregTechMixinPlugin", + "client": [ + "BlockColorsMixin", + "BlockModelMixin", + "ClientLevelAccessor", + "CompassManagerMixin", + "GuiGraphicsAccessor", + "GuiGraphicsMixin", + "GuiHeartTypeMixin", + "LevelRendererMixin", + "ModelManagerMixin", + "MultiPlayerGameModeMixin", + "rei.FluidEntryRendererMixin" + ], + "mixins": [ + "AbstractRegistrateAccessor", + "BlockBehaviourAccessor", + "BlockMixin", + "BlockPropertiesAccessor", + "ChunkGeneratorMixin", + "ChunkMixin", + "CreeperMixin", + "EntityMixin", + "IFoliagePlacerTypeAccessor", + "IHolderReferenceAccessor", + "IngredientAccessor", + "IntersectionIngredientAccessor", + "InventoryMixin", + "ItemValueAccessor", + "ITrunkPlacerTypeAccessor", + "LevelMixin", + "LivingEntityMixin", + "LootDataManagerMixin", + "LootPoolAccessor", + "OreConfigurationMixin", + "OreVeinifierMixin", + "PartialNBTIngredientAccessor", + "PrimedTntAccessor", + "RecipeManagerAccessor", + "RecipeManagerInvoker", + "RecipeManagerMixin", + "RepairItemRecipeMixin", + "ServerChunkProviderMixin", + "ServerGamePacketListenerImplAccessor", + "ShapedRecipeAccessor", + "SidedRedstoneConnectivityMixin", + "StrictNBTIngredientAccessor", + "TagLoaderMixin", + "TagManagerMixin", + "TagValueAccessor", + "ae2.GenericStackInvAccessor", + "create.RotationPropagatorMixin", + "embeddium.BiomeColorCacheMixin", + "embeddium.VanillaColorAdapterMixin", + "emi.FluidEmiStackMixin", + "jei.FluidHelperMixin", + "ldlib.SyncUtilsMixin", + "rei.InputSlotCrafterMixin", + "rei.RecipeFinderMixin", + "top.ConfigMixin" + ], + "injectors": { + "defaultRequire": 1, + "maxShiftBy": 5 + } } From abd92488f3c0669f13797644229211834343bfe9 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:43:30 -0400 Subject: [PATCH 03/22] Adds new IFluidHandler extensions --- .../api/transfer/fluid/CustomFluidTank.java | 70 +++++++++++++++++++ .../fluid/IFluidHandlerModifiable.java | 17 +++++ .../fluid/ModifiableFluidHandlerWrapper.java | 54 ++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CustomFluidTank.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/IFluidHandlerModifiable.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CustomFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CustomFluidTank.java new file mode 100644 index 0000000000..badef8e67f --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CustomFluidTank.java @@ -0,0 +1,70 @@ +package com.gregtechceu.gtceu.api.transfer.fluid; + +import com.lowdragmc.lowdraglib.syncdata.IContentChangeAware; +import com.lowdragmc.lowdraglib.syncdata.ITagSerializable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.templates.FluidTank; + +import lombok.Getter; +import lombok.Setter; + +import java.util.function.Predicate; + +public class CustomFluidTank extends FluidTank + implements IFluidHandlerModifiable, ITagSerializable, IContentChangeAware { + + @Getter + @Setter + protected Runnable onContentsChanged = () -> {}; + + public CustomFluidTank(int capacity) { + this(capacity, e -> true); + } + + public CustomFluidTank(int capacity, Predicate validator) { + super(capacity, validator); + } + + public CustomFluidTank(FluidStack stack) { + super(stack.getAmount()); + setFluid(stack); + } + + @Override + protected void onContentsChanged() { + onContentsChanged.run(); + } + + public CustomFluidTank copy() { + FluidStack copiedStack = this.fluid.copy(); + CustomFluidTank copied = new CustomFluidTank(this.capacity, this.validator); + copied.setFluid(copiedStack); + return copied; + } + + @Override + public void setFluidInTank(int tank, FluidStack stack) { + this.setFluid(stack); + this.onContentsChanged(); + } + + public int fill(int tank, FluidStack resource, FluidAction action) { + return this.fill(resource, action); + } + + public FluidStack drain(int tank, FluidStack resource, FluidAction action) { + return this.drain(resource, action); + } + + @Override + public CompoundTag serializeNBT() { + return writeToNBT(new CompoundTag()); + } + + @Override + public void deserializeNBT(CompoundTag nbt) { + readFromNBT(nbt); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/IFluidHandlerModifiable.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/IFluidHandlerModifiable.java new file mode 100644 index 0000000000..680d38de65 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/IFluidHandlerModifiable.java @@ -0,0 +1,17 @@ +package com.gregtechceu.gtceu.api.transfer.fluid; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; + +public interface IFluidHandlerModifiable extends IFluidHandler { + + void setFluidInTank(int tank, FluidStack stack); + + default boolean supportsFill(int tank) { + return true; + } + + default boolean supportsDrain(int tank) { + return true; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java new file mode 100644 index 0000000000..d91b29aea4 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java @@ -0,0 +1,54 @@ +package com.gregtechceu.gtceu.api.transfer.fluid; + +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; + +import lombok.AllArgsConstructor; +import org.jetbrains.annotations.NotNull; + +@AllArgsConstructor +public class ModifiableFluidHandlerWrapper implements IFluidHandlerModifiable { + + private IFluidHandler handler; + + @Override + public void setFluidInTank(int i, FluidStack fluidStack) { + drain(handler.getFluidInTank(i), FluidAction.EXECUTE); + fill(fluidStack, FluidAction.EXECUTE); + } + + @Override + public int getTanks() { + return handler.getTanks(); + } + + @Override + public @NotNull FluidStack getFluidInTank(int tank) { + return handler.getFluidInTank(tank); + } + + @Override + public int getTankCapacity(int tank) { + return handler.getTankCapacity(tank); + } + + @Override + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + return handler.isFluidValid(tank, stack); + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + return handler.fill(resource, action); + } + + @Override + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + return handler.drain(resource, action); + } + + @Override + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return handler.drain(maxDrain, action); + } +} From 8689ccefd7f55d1be418d93d879a6978c052597a Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:44:50 -0400 Subject: [PATCH 04/22] Switches IFluidTransfer for IFluidHandler Rewrites these classes to use Forge's native IFLuidHandler rather than LDLib's IFluidTransfer --- .../machine/trait/FluidTankProxyTrait.java | 97 +++++------------ .../gtceu/api/misc/IOFluidTransferList.java | 55 ++++------ .../transfer/fluid/FluidTransferDelegate.java | 48 +++------ .../fluid/InfiniteFluidTransferProxy.java | 15 ++- .../api/transfer/fluid/NoOpFluidTransfer.java | 35 ++---- .../pipelike/fluidpipe/PipeTankList.java | 101 +++++------------- .../ae2/slot/ExportOnlyAEFluidSlot.java | 81 +++++++------- .../gtceu/utils/OverlayingFluidStorage.java | 76 +++++++------ 8 files changed, 186 insertions(+), 322 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java index ca26fee864..9d5d7047c3 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java @@ -2,13 +2,14 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.MetaMachine; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import lombok.Setter; @@ -22,7 +23,7 @@ * @implNote FluidTankProxyTrait */ @Accessors(chain = true) -public class FluidTankProxyTrait extends MachineTrait implements IFluidTransfer, ICapabilityTrait { +public class FluidTankProxyTrait extends MachineTrait implements IFluidHandler, ICapabilityTrait { public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(FluidTankProxyTrait.class); @Getter @@ -30,7 +31,7 @@ public class FluidTankProxyTrait extends MachineTrait implements IFluidTransfer, @Setter @Getter @Nullable - public IFluidTransfer proxy; + public IFluidHandler proxy; public FluidTankProxyTrait(MetaMachine machine, IO capabilityIO) { super(machine); @@ -46,11 +47,6 @@ public ManagedFieldHolder getFieldHolder() { // ******* Capability ********// ////////////////////////////////////// - @Override - public void onContentsChanged() { - if (proxy != null) proxy.onContentsChanged(); - } - @Override public int getTanks() { return proxy == null ? 0 : proxy.getTanks(); @@ -59,18 +55,17 @@ public int getTanks() { @NotNull @Override public FluidStack getFluidInTank(int tank) { - return proxy == null ? FluidStack.empty() : proxy.getFluidInTank(tank); + return proxy == null ? FluidStack.EMPTY : proxy.getFluidInTank(tank); } - @Override public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { if (proxy != null) { - proxy.setFluidInTank(tank, fluidStack); + // proxy.setFluidInTank(tank, fluidStack); } } @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return proxy == null ? 0 : proxy.getTankCapacity(tank); } @@ -80,87 +75,47 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (proxy != null && canCapInput()) { - return proxy.fill(tank, resource, simulate, notifyChanges); - } - return 0; - } - - @Override - public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { if (proxy != null && canCapInput()) { - return proxy.fill(resource, simulate, notifyChanges); + return proxy.fill(resource, action); } return 0; } - public long fillInternal(FluidStack resource, boolean simulate) { + public int fillInternal(FluidStack resource, FluidAction action) { if (proxy != null && !resource.isEmpty()) { - return proxy.fill(resource, simulate); + return proxy.fill(resource, action); } return 0; } - @NotNull - @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (proxy != null && canCapOutput()) { - return proxy.drain(tank, resource, simulate, notifyChanges); - } - return FluidStack.empty(); - } - - public FluidStack drainInternal(FluidStack resource, boolean simulate) { + public FluidStack drainInternal(FluidStack resource, FluidAction action) { if (proxy != null && !resource.isEmpty()) { - return proxy.drain(resource, simulate); + return proxy.drain(resource, action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } @NotNull @Override - public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { + public FluidStack drain(int maxDrain, FluidAction action) { if (proxy != null && canCapOutput()) { - return proxy.drain(maxDrain, simulate, notifyChanges); + return proxy.drain(maxDrain, action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } @NotNull @Override - public FluidStack drain(FluidStack resource, boolean simulate, boolean notifyChanges) { + public FluidStack drain(FluidStack resource, FluidAction action) { if (proxy != null && canCapOutput()) { - return proxy.drain(resource, simulate, notifyChanges); + return proxy.drain(resource, action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } - @NotNull - @Override - public Object createSnapshot() { - return proxy == null ? new Object() : proxy.createSnapshot(); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (proxy != null) { - proxy.restoreFromSnapshot(snapshot); - } - } - - public FluidStack drainInternal(long maxDrain, boolean simulate) { - return proxy == null ? FluidStack.empty() : proxy.drain(maxDrain, simulate); - } - - @Override - public boolean supportsFill(int i) { - return canCapInput(); - } - - @Override - public boolean supportsDrain(int i) { - return canCapOutput(); + public FluidStack drainInternal(int maxDrain, FluidAction action) { + return proxy == null ? FluidStack.EMPTY : proxy.drain(maxDrain, action); } public boolean isEmpty() { @@ -182,8 +137,8 @@ public void exportToNearby(Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - FluidTransferHelper.exportToTarget(this, Integer.MAX_VALUE, f -> true, level, pos.relative(facing), - facing.getOpposite()); + GTUtil.getAdjacentFluidHandler(level, pos, facing).ifPresent( + h -> FluidUtil.tryFluidTransfer(h, this, Integer.MAX_VALUE, true)); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java b/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java index a2bee13634..f315509342 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java @@ -1,10 +1,11 @@ package com.gregtechceu.gtceu.api.misc; import com.gregtechceu.gtceu.api.capability.recipe.IO; +import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; -import com.lowdragmc.lowdraglib.misc.FluidTransferList; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -17,54 +18,44 @@ * @date 2023/3/14 * @implNote IOFluidTransferList */ -public class IOFluidTransferList extends FluidTransferList { +public class IOFluidTransferList extends FluidTransferList implements IFluidHandlerModifiable { @Getter private final IO io; - public IOFluidTransferList(List transfers, IO io, Predicate filter) { + public IOFluidTransferList(List transfers, IO io, Predicate filter) { super(transfers); this.io = io; setFilter(filter); } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { if (io != IO.IN && io != IO.BOTH) return 0; - return super.fill(tank, resource, simulate, notifyChanges); + return super.fill(resource, action); } @Override - public long fill(FluidStack resource, boolean simulate, boolean notifyChanged) { - if (io != IO.IN && io != IO.BOTH) return 0; - return super.fill(resource, simulate, notifyChanged); - } - - @Override - public @NotNull FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (io != IO.OUT && io != IO.BOTH) return FluidStack.empty(); - return super.drain(tank, resource, simulate, notifyChanges); - } - - @Override - public @NotNull FluidStack drain(FluidStack resource, boolean simulate, boolean notifyChanged) { - if (io != IO.OUT && io != IO.BOTH) return FluidStack.empty(); - return super.drain(resource, simulate, notifyChanged); - } - - @Override - public @NotNull FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanged) { - if (io != IO.OUT && io != IO.BOTH) return FluidStack.empty(); - return super.drain(maxDrain, simulate, notifyChanged); + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + if (io != IO.OUT && io != IO.BOTH) return FluidStack.EMPTY; + return super.drain(resource, action); } @Override - public boolean supportsFill(int tank) { - return io == IO.IN || io == IO.BOTH; + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + if (io != IO.OUT && io != IO.BOTH) return FluidStack.EMPTY; + return super.drain(maxDrain, action); } @Override - public boolean supportsDrain(int tank) { - return io == IO.OUT || io == IO.BOTH; + public void setFluidInTank(int tank, FluidStack stack) { + int index = 0; + for (IFluidHandler handler : transfers) { + if (handler instanceof IFluidHandlerModifiable modifiable) { + if (tank - index < handler.getTanks()) modifiable.setFluidInTank(tank - index, stack); + return; + } + index += handler.getTanks(); + } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java index 6e23f8461b..256640a857 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java @@ -1,10 +1,9 @@ package com.gregtechceu.gtceu.api.transfer.fluid; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidStack; +import lombok.Setter; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -12,15 +11,12 @@ @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public abstract class FluidTransferDelegate implements IFluidTransfer { +public abstract class FluidTransferDelegate implements IFluidHandlerModifiable { - public IFluidTransfer delegate; + @Setter + public IFluidHandlerModifiable delegate; - public FluidTransferDelegate(IFluidTransfer delegate) { - this.delegate = delegate; - } - - protected void setDelegate(IFluidTransfer delegate) { + public FluidTransferDelegate(IFluidHandlerModifiable delegate) { this.delegate = delegate; } @@ -46,7 +42,7 @@ public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { } @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return delegate.getTankCapacity(tank); } @@ -57,8 +53,8 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { @Override @ApiStatus.Internal - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return delegate.fill(tank, resource, simulate, notifyChanges); + public int fill(FluidStack resource, FluidAction action) { + return delegate.fill(resource, action); } @Override @@ -68,31 +64,17 @@ public boolean supportsFill(int tank) { @Override @ApiStatus.Internal - @NotNull - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return delegate.drain(tank, resource, simulate, notifyChanges); - } - - @Override - public boolean supportsDrain(int tank) { - return delegate.supportsDrain(tank); - } - - @Override - @ApiStatus.Internal - @NotNull - public Object createSnapshot() { - return delegate.createSnapshot(); + public FluidStack drain(FluidStack resource, FluidAction action) { + return delegate.drain(resource, action); } @Override - @ApiStatus.Internal - public void restoreFromSnapshot(Object snapshot) { - delegate.restoreFromSnapshot(snapshot); + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return delegate.drain(maxDrain, action); } @Override - public void onContentsChanged() { - delegate.onContentsChanged(); + public boolean supportsDrain(int tank) { + return delegate.supportsDrain(tank); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java index f8bb48a326..2f52a8f9ec 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java @@ -1,9 +1,7 @@ package com.gregtechceu.gtceu.api.transfer.fluid; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -16,7 +14,7 @@ public class InfiniteFluidTransferProxy extends FluidTransferDelegate { private final boolean infiniteSource; private final boolean infiniteSink; - public InfiniteFluidTransferProxy(IFluidTransfer delegate, boolean infiniteSource, boolean infiniteSink) { + public InfiniteFluidTransferProxy(IFluidHandlerModifiable delegate, boolean infiniteSource, boolean infiniteSink) { super(delegate); this.infiniteSource = infiniteSource; @@ -24,19 +22,18 @@ public InfiniteFluidTransferProxy(IFluidTransfer delegate, boolean infiniteSourc } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { if (infiniteSink) return resource.getAmount(); - return super.fill(tank, resource, simulate, notifyChanges); + return super.fill(resource, action); } - @NotNull @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { if (infiniteSource) return resource.copy(); - return super.drain(tank, resource, simulate, notifyChanges); + return super.drain(resource, action); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java index 877b10966b..c9df2e3ec9 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java @@ -1,9 +1,7 @@ package com.gregtechceu.gtceu.api.transfer.fluid; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; @@ -11,7 +9,7 @@ @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public class NoOpFluidTransfer implements IFluidTransfer { +public class NoOpFluidTransfer implements IFluidHandlerModifiable { public static final NoOpFluidTransfer INSTANCE = new NoOpFluidTransfer(); @@ -25,14 +23,14 @@ public int getTanks() { @NotNull @Override public FluidStack getFluidInTank(int tank) { - return FluidStack.empty(); + return FluidStack.EMPTY; } @Override public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) {} @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return 0; } @@ -42,32 +40,17 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { return 0; } @Override - public boolean supportsFill(int tank) { - return false; + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + return FluidStack.EMPTY; } - @NotNull @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return FluidStack.empty(); - } - - @Override - public boolean supportsDrain(int tank) { - return false; + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return FluidStack.EMPTY; } - - @NotNull - @Override - public Object createSnapshot() { - return new Object(); - } - - @Override - public void restoreFromSnapshot(Object snapshot) {} } diff --git a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeTankList.java b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeTankList.java index 270748eb2c..ef42b1f842 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeTankList.java +++ b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeTankList.java @@ -1,27 +1,25 @@ package com.gregtechceu.gtceu.common.pipelike.fluidpipe; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.blockentity.FluidPipeBlockEntity; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Iterator; @SuppressWarnings("UnstableApiUsage") -public class PipeTankList implements IFluidTransfer, Iterable { +public class PipeTankList implements IFluidHandlerModifiable, Iterable { private final FluidPipeBlockEntity pipe; - private final FluidStorage[] tanks; + private final CustomFluidTank[] tanks; private final Direction facing; - public PipeTankList(FluidPipeBlockEntity pipe, Direction facing, FluidStorage... fluidTanks) { + public PipeTankList(FluidPipeBlockEntity pipe, Direction facing, CustomFluidTank... fluidTanks) { this.tanks = fluidTanks; this.pipe = pipe; this.facing = facing; @@ -58,7 +56,7 @@ public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { } @Override - public long getTankCapacity(int tank) { + public int getTankCapacity(int tank) { return tanks[tank].getCapacity(); } @@ -67,56 +65,26 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { return tanks[tank].isFluidValid(stack); } - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (pipe.isBlocked(facing) || resource == null || resource.getAmount() <= 0) - return 0; - - return fill(resource, simulate, tank); - } - - @Override - public boolean supportsFill(int tank) { - return true; - } - - @NotNull - @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - FluidStorage storage = tanks[tank]; - FluidStack drained = storage.drain(resource, simulate, notifyChanges); - if (!drained.isEmpty()) return drained; - else return FluidStack.empty(); - } - - @Override - public boolean supportsDrain(int tank) { - return true; + private int fullCapacity() { + return tanks.length * pipe.getCapacityPerTank(); } @Override - public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) { + public int fill(FluidStack resource, FluidAction action) { int channel; - if (pipe.isBlocked(facing) || resource == null || resource.getAmount() <= 0 || - (channel = findChannel(resource)) < 0) - return 0; - - return fill(resource, simulate, channel); - } - - private long fullCapacity() { - return tanks.length * pipe.getCapacityPerTank(); + if (pipe.isBlocked(facing) || resource.getAmount() < 0 || (channel = findChannel(resource)) < 0) return 0; + return fill(resource, action, channel); } - private long fill(FluidStack resource, boolean simulate, int channel) { + private int fill(FluidStack resource, FluidAction action, int channel) { if (channel >= tanks.length) return 0; - FluidStorage tank = tanks[channel]; + CustomFluidTank tank = tanks[channel]; FluidStack currentFluid = tank.getFluid(); if (currentFluid.isEmpty() || currentFluid.getAmount() <= 0) { FluidStack newFluid = resource.copy(); newFluid.setAmount(Math.min(pipe.getCapacityPerTank(), newFluid.getAmount())); - if (!simulate) { + if (action.execute()) { tank.setFluid(newFluid); pipe.receivedFrom(facing); pipe.checkAndDestroy(newFluid); @@ -124,9 +92,9 @@ private long fill(FluidStack resource, boolean simulate, int channel) { return newFluid.getAmount(); } if (currentFluid.isFluidEqual(resource)) { - long toAdd = Math.min(tank.getCapacity() - currentFluid.getAmount(), resource.getAmount()); + int toAdd = Math.min(tank.getCapacity() - currentFluid.getAmount(), resource.getAmount()); if (toAdd > 0) { - if (!simulate) { + if (action.execute()) { currentFluid.setAmount(currentFluid.getAmount() + toAdd); pipe.receivedFrom(facing); pipe.checkAndDestroy(currentFluid); @@ -138,41 +106,30 @@ private long fill(FluidStack resource, boolean simulate, int channel) { return 0; } - @NotNull @Override - public FluidStack drain(long maxDrain, boolean doDrain, boolean notifyChanges) { - if (maxDrain <= 0) return FluidStack.empty(); - for (FluidStorage tank : tanks) { - FluidStack drained = tank.drain(maxDrain, doDrain, notifyChanges); + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + if (maxDrain <= 0) return FluidStack.EMPTY; + for (CustomFluidTank tank : tanks) { + FluidStack drained = tank.drain(maxDrain, action); if (!drained.isEmpty()) return drained; } - return FluidStack.empty(); + return FluidStack.EMPTY; } - @NotNull - @Override - public Object createSnapshot() { - return new Object(); - } - - @Override - public void restoreFromSnapshot(Object snapshot) {} - - @Nullable @Override - public FluidStack drain(FluidStack fluidStack, boolean doDrain) { - if (fluidStack.isEmpty() || fluidStack.getAmount() <= 0) return FluidStack.empty(); - fluidStack = fluidStack.copy(); - for (FluidStorage tank : tanks) { - FluidStack drained = tank.drain(fluidStack, doDrain); + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + if (resource.getAmount() <= 0) return FluidStack.EMPTY; + resource = resource.copy(); + for (CustomFluidTank tank : tanks) { + FluidStack drained = tank.drain(resource, action); if (!drained.isEmpty()) return drained; } - return FluidStack.empty(); + return FluidStack.EMPTY; } @Override @NotNull - public Iterator iterator() { + public Iterator iterator() { return Arrays.stream(tanks).iterator(); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java index 400e4897dd..3fc27640e4 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java @@ -1,20 +1,22 @@ package com.gregtechceu.gtceu.integration.ae2.slot; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.GenericStack; -import com.mojang.datafixers.util.Pair; +import com.google.common.primitives.Ints; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public class ExportOnlyAEFluidSlot extends ExportOnlyAESlot implements IFluidStorage { +public class ExportOnlyAEFluidSlot extends ExportOnlyAESlot implements IFluidHandlerModifiable, IFluidTank { public ExportOnlyAEFluidSlot() { super(); @@ -50,15 +52,9 @@ public void setStock(@Nullable GenericStack stack) { @Override public FluidStack getFluid() { if (this.stock != null && this.stock.what() instanceof AEFluidKey fluidKey) { - return FluidStack.create(fluidKey.getFluid(), this.stock.amount(), - fluidKey.getTag()); + return fluidKey.toStack(Ints.saturatedCast(this.stock.amount())); } - return FluidStack.empty(); - } - - @Override - public void setFluid(FluidStack fluid) { - // NO-OP + return FluidStack.EMPTY; } @Override @@ -67,57 +63,70 @@ public boolean isFluidValid(FluidStack stack) { } @Override - public long getFluidAmount() { - return this.stock != null ? this.stock.amount() : 0; + public int getFluidAmount() { + return this.stock != null ? Ints.saturatedCast(this.stock.amount()) : 0; } @Override - public long getCapacity() { + public int getCapacity() { // Its capacity is always 0. return 0; } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + public int getTanks() { return 0; } @Override - public long fill(FluidStack resource, boolean doFill) { + public FluidStack getFluidInTank(int tank) { + return null; + } + + @Override + public void setFluidInTank(int tank, FluidStack stack) {} + + @Override + public int getTankCapacity(int tank) { return 0; } @Override - public boolean supportsFill(int tank) { + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { return false; } @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return this.drain(resource, simulate, notifyChanges); + public int fill(FluidStack resource, FluidAction action) { + return 0; } @Override - public FluidStack drain(FluidStack resource, boolean doDrain, boolean notifyChanges) { + public boolean supportsFill(int tank) { + return false; + } + + @Override + public FluidStack drain(FluidStack resource, FluidAction action) { if (this.getFluid().isFluidEqual(resource)) { - return this.drain(resource.getAmount(), doDrain, notifyChanges); + return this.drain(resource.getAmount(), action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } @Override - public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { + public FluidStack drain(int maxDrain, FluidAction action) { if (this.stock == null || !(this.stock.what() instanceof AEFluidKey fluidKey)) { - return FluidStack.empty(); + return FluidStack.EMPTY; } int drained = (int) Math.min(this.stock.amount(), maxDrain); - FluidStack result = FluidStack.create(fluidKey.getFluid(), drained, fluidKey.getTag()); - if (!simulate) { + FluidStack result = fluidKey.toStack(drained); + if (action.execute()) { this.stock = new GenericStack(this.stock.what(), this.stock.amount() - drained); if (this.stock.amount() == 0) { this.stock = null; } - if (notifyChanges) onContentsChanged(); + onContentsChanged(); } return result; } @@ -127,7 +136,6 @@ public boolean supportsDrain(int tank) { return tank == 0; } - @Override public void onContentsChanged() { if (onContentsChanged != null) { onContentsChanged.run(); @@ -140,19 +148,4 @@ public ExportOnlyAEFluidSlot copy() { this.config == null ? null : ExportOnlyAESlot.copy(this.config), this.stock == null ? null : ExportOnlyAESlot.copy(this.stock)); } - - @Deprecated - @Override - public Object createSnapshot() { - return Pair.of(this.config, this.stock); - } - - @Deprecated - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Pair pair) { - this.config = (GenericStack) pair.getFirst(); - this.stock = (GenericStack) pair.getSecond(); - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java b/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java index 91b136d572..d7a9a83ccd 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java @@ -1,81 +1,87 @@ package com.gregtechceu.gtceu.utils; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidTank; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; @RequiredArgsConstructor -public class OverlayingFluidStorage implements IFluidStorage { +public class OverlayingFluidStorage implements IFluidHandlerModifiable, IFluidTank { - private final IFluidTransfer transfer; + private final IFluidHandlerModifiable transfer; private final int tank; @Override - public void onContentsChanged() { - this.transfer.onContentsChanged(); + public @NotNull FluidStack getFluid() { + return transfer.getFluidInTank(tank); } - @NotNull @Override - public FluidStack getFluid() { - return transfer.getFluidInTank(tank); + public int getFluidAmount() { + return getFluid().getAmount(); } @Override - public void setFluid(FluidStack fluid) { - transfer.setFluidInTank(tank, fluid); + public int getCapacity() { + return transfer.getTankCapacity(tank); } @Override - public long getCapacity() { - return transfer.getTankCapacity(tank); + public int getTankCapacity(int tank) { + return getCapacity(); } @Override - public boolean isFluidValid(FluidStack stack) { - return transfer.isFluidValid(tank, stack); + public @NotNull FluidStack getFluidInTank(int tank) { + return getFluid(); } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (transfer instanceof NotifiableFluidTank notifiable) { - return notifiable.getStorages()[this.tank].fill(resource, simulate, notifyChanges); - } - return transfer.fill(this.tank, resource, simulate, notifyChanges); + public void setFluidInTank(int tank, FluidStack stack) { + transfer.setFluidInTank(tank, stack); } @Override - public boolean supportsFill(int tank) { - return transfer.supportsFill(this.tank); + public int getTanks() { + return 1; } - @NotNull @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (transfer instanceof NotifiableFluidTank notifiable) { - return notifiable.getStorages()[this.tank].drain(resource, simulate, notifyChanges); - } - return transfer.drain(this.tank, resource, simulate, notifyChanges); + public boolean isFluidValid(FluidStack stack) { + return isFluidValid(tank, stack); } @Override - public boolean supportsDrain(int tank) { - return transfer.supportsDrain(this.tank); + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + return transfer.isFluidValid(tank, stack); + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + if (transfer instanceof NotifiableFluidTank notifiable) { + return notifiable.getStorages()[this.tank].fill(resource, action); + } + return transfer.fill(resource, action); } @NotNull @Override - public Object createSnapshot() { - return transfer.createSnapshot(); + public FluidStack drain(FluidStack resource, FluidAction action) { + if (transfer instanceof NotifiableFluidTank notifiable) { + return notifiable.getStorages()[this.tank].drain(resource, action); + } + return transfer.drain(resource, action); } @Override - public void restoreFromSnapshot(Object snapshot) { - transfer.restoreFromSnapshot(snapshot); + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + if (transfer instanceof NotifiableFluidTank notifiable) { + return notifiable.getStorages()[this.tank].drain(maxDrain, action); + } + return transfer.drain(maxDrain, action); } } From 230db70a43c6fbe2343e8da4c17b3ce3359158c1 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:47:08 -0400 Subject: [PATCH 05/22] Changes fluid-related behavior in some classes Switches from hardcoded logic to using Forge's FluidUtil to add cleanliness --- .../machine/trait/NotifiableFluidTank.java | 248 ++++++++---------- .../common/machine/electric/PumpMachine.java | 47 ++-- .../common/machine/storage/DrumMachine.java | 60 +---- .../machine/storage/QuantumTankMachine.java | 85 ++---- .../ae2/slot/ExportOnlyAEFluidList.java | 73 ++---- 5 files changed, 179 insertions(+), 334 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index d94952c8d6..16b8f36518 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -6,17 +6,18 @@ import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +import com.gregtechceu.gtceu.utils.GTUtil; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.core.Direction; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; import lombok.Getter; import lombok.Setter; @@ -32,7 +33,7 @@ * @implNote NotifiableFluidTank */ public class NotifiableFluidTank extends NotifiableRecipeHandlerTrait - implements ICapabilityTrait, IFluidTransfer { + implements ICapabilityTrait, IFluidHandlerModifiable { public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(NotifiableFluidTank.class, NotifiableRecipeHandlerTrait.MANAGED_FIELD_HOLDER); @@ -42,7 +43,7 @@ public class NotifiableFluidTank extends NotifiableRecipeHandlerTrait storages, IO io, IO capabilityIO) { + public NotifiableFluidTank(MetaMachine machine, List storages, IO io, IO capabilityIO) { super(machine); this.handlerIO = io; - this.storages = storages.toArray(FluidStorage[]::new); + this.storages = storages.toArray(CustomFluidTank[]::new); this.capabilityIO = capabilityIO; - for (FluidStorage storage : this.getStorages()) { + for (CustomFluidTank storage : this.storages) { storage.setOnContentsChanged(this::onContentsChanged); } if (io == IO.IN) { @@ -77,11 +78,11 @@ public NotifiableFluidTank(MetaMachine machine, List storages, IO } } - public NotifiableFluidTank(MetaMachine machine, int slots, long capacity, IO io) { + public NotifiableFluidTank(MetaMachine machine, int slots, int capacity, IO io) { this(machine, slots, capacity, io, io); } - public NotifiableFluidTank(MetaMachine machine, List storages, IO io) { + public NotifiableFluidTank(MetaMachine machine, List storages, IO io) { this(machine, storages, io, io); } @@ -98,16 +99,60 @@ public ManagedFieldHolder getFieldHolder() { @Override public List handleRecipeInner(IO io, GTRecipe recipe, List left, @Nullable String slotName, boolean simulate) { - return handleIngredient(io, recipe, left, simulate, this.handlerIO, storages); + return handleRecipe(io, left, simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE); } + // TODO: Propagate FluidAction parameter up the caller chain + public List handleRecipe(IO io, List left, FluidAction action) { + if (io != IO.IN && io != IO.OUT) return left.isEmpty() ? null : left; + + for (var it = left.iterator(); it.hasNext();) { + var ingredient = it.next(); + if (ingredient.isEmpty()) { + it.remove(); + continue; + } + + var fluids = ingredient.getStacks(); + if (fluids.length == 0) { + it.remove(); + continue; + } + + for (CustomFluidTank storage : storages) { + FluidStack stored = storage.getFluid(); + int transferred = 0; + int toTransfer = ingredient.getAmount(); + if (io == IO.IN) { + if (!ingredient.test(stored)) continue; + var copy = stored.copy(); + copy.setAmount(toTransfer); + transferred = storage.drain(copy, action).getAmount(); + } else { // IO.OUT + FluidStack output = fluids[0]; + transferred = storage.fill(output.copy(), action); + // TODO: Check *all* tanks first + if (output.isFluidEqual(stored) && transferred < toTransfer && !allowSameFluids) return left; + } + ingredient.setAmount(toTransfer - transferred); + if (ingredient.getAmount() <= 0) { + it.remove(); + break; + } + } + } + return left.isEmpty() ? null : left; + } + + // TODO: Implement this method directly into the caller, no longer has other uses @Nullable public static List handleIngredient(IO io, GTRecipe recipe, List left, - boolean simulate, IO handlerIO, FluidStorage[] storages) { + boolean simulate, IO handlerIO, CustomFluidTank[] storages) { if (io != handlerIO) return left; - var capabilities = simulate ? Arrays.stream(storages).map(FluidStorage::copy).toArray(FluidStorage[]::new) : + var capabilities = simulate ? + Arrays.stream(storages).map(CustomFluidTank::copy).toArray(CustomFluidTank[]::new) : storages; - for (FluidStorage capability : capabilities) { + for (CustomFluidTank capability : capabilities) { Iterator iterator = left.iterator(); if (io == IO.IN) { while (iterator.hasNext()) { @@ -127,7 +172,9 @@ public static List handleIngredient(IO io, GTRecipe recipe, Lis foundStack = stored; } if (!found) continue; - FluidStack drained = capability.drain(foundStack.copy(fluidStack.getAmount()), false); + var copy = foundStack.copy(); + copy.setAmount(fluidStack.getAmount()); + FluidStack drained = capability.drain(copy, FluidAction.EXECUTE); fluidStack.setAmount(fluidStack.getAmount() - drained.getAmount()); if (fluidStack.getAmount() <= 0) { @@ -147,7 +194,7 @@ public static List handleIngredient(IO io, GTRecipe recipe, Lis continue; } FluidStack output = fluids[0]; - long filled = capability.fill(output.copy(), false); + int filled = capability.fill(output.copy(), FluidAction.EXECUTE); if (!fluidStack.isEmpty()) { fluidStack.setAmount(fluidStack.getAmount() - filled); } @@ -177,14 +224,14 @@ public boolean isLocked() { public void setLocked(boolean locked) { if (this.isLocked() == locked) return; - FluidStack fluidStack = getStorages()[0].getFluid(); + FluidStack fluidStack = storages[0].getFluid(); if (locked && !fluidStack.isEmpty()) { this.lockedFluid.setFluid(fluidStack.copy()); this.lockedFluid.getFluid().setAmount(1); onContentsChanged(); setFilter(stack -> stack.isFluidEqual(this.lockedFluid.getFluid())); } else { - this.lockedFluid.setFluid(FluidStack.empty()); + this.lockedFluid.setFluid(FluidStack.EMPTY); setFilter(stack -> true); onContentsChanged(); } @@ -198,14 +245,14 @@ public void setLocked(boolean locked, FluidStack fluidStack) { onContentsChanged(); setFilter(stack -> stack.isFluidEqual(this.lockedFluid.getFluid())); } else { - this.lockedFluid.setFluid(FluidStack.empty()); + this.lockedFluid.setFluid(FluidStack.EMPTY); setFilter(stack -> true); onContentsChanged(); } } public NotifiableFluidTank setFilter(Predicate filter) { - for (FluidStorage storage : getStorages()) { + for (CustomFluidTank storage : storages) { storage.setValidator(filter); } return this; @@ -217,7 +264,7 @@ public RecipeCapability getCapability() { } public int getTanks() { - return getStorages().length; + return storages.length; } @Override @@ -252,7 +299,7 @@ public double getTotalContentAmount() { public boolean isEmpty() { if (isEmpty == null) { isEmpty = true; - for (FluidStorage storage : getStorages()) { + for (CustomFluidTank storage : storages) { if (!storage.getFluid().isEmpty()) { isEmpty = false; break; @@ -267,9 +314,8 @@ public void exportToNearby(@NotNull Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - FluidTransferHelper.exportToTarget(this, Integer.MAX_VALUE, getMachine().getFluidCapFilter(facing), level, - pos.relative(facing), - facing.getOpposite()); + GTUtil.getAdjacentFluidHandler(level, pos, facing) + .ifPresent(h -> FluidUtil.tryFluidTransfer(h, this, Integer.MAX_VALUE, true)); } } @@ -277,9 +323,8 @@ public void importFromNearby(@NotNull Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - FluidTransferHelper.importToTarget(this, Integer.MAX_VALUE, getMachine().getFluidCapFilter(facing), level, - pos.relative(facing), - facing.getOpposite()); + GTUtil.getAdjacentFluidHandler(level, pos, facing) + .ifPresent(h -> FluidUtil.tryFluidTransfer(this, h, Integer.MAX_VALUE, true)); } } @@ -289,76 +334,35 @@ public void importFromNearby(@NotNull Direction... facings) { @NotNull @Override public FluidStack getFluidInTank(int tank) { - return getStorages()[tank].getFluid(); + return storages[tank].getFluid(); } - @Override public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { - getStorages()[tank].setFluid(fluidStack); + storages[tank].setFluid(fluidStack); } @Override - public long getTankCapacity(int tank) { - return getStorages()[tank].getCapacity(); + public int getTankCapacity(int tank) { + return storages[tank].getCapacity(); } @Override public boolean isFluidValid(int tank, @NotNull FluidStack stack) { - return getStorages()[tank].isFluidValid(stack); - } - - @Override - public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) { - if (resource.isEmpty() || !canCapInput()) return 0; - long filled = 0; - FluidStorage existingStorage = null; - if (!allowSameFluids) { - for (var storage : getStorages()) { - if (!storage.getFluid().isEmpty() && storage.getFluid().isFluidEqual(resource)) { - existingStorage = storage; - break; - } - } - } - if (existingStorage == null) { - for (int i = 0; i < getTanks(); i++) { - if (filled > 0 && !allowSameFluids) { - break; - } - filled += fill(i, resource.copy(resource.getAmount() - filled), simulate, notifyChanges); - if (filled == resource.getAmount()) break; - } - } else { - filled += existingStorage.fill(resource.copy(resource.getAmount() - filled), simulate, notifyChanges); - } - if (notifyChanges && filled > 0 && !simulate) { - onContentsChanged(); - } - return filled; + return storages[tank].isFluidValid(stack); } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (tank >= 0 && tank < getStorages().length && canCapInput()) { - return getStorages()[tank].fill(resource, simulate, notifyChanges); - } - return 0; + public int fill(FluidStack resource, FluidAction action) { + if (!canCapInput()) return 0; + return fillInternal(resource, action); } - @Override - public long fill(FluidStack resource, boolean simulate) { - if (canCapInput()) { - return fillInternal(resource, simulate); - } - return 0; - } - - public long fillInternal(FluidStack resource, boolean simulate) { + public int fillInternal(FluidStack resource, FluidAction action) { if (resource.isEmpty()) return 0; var copied = resource.copy(); - FluidStorage existingStorage = null; + CustomFluidTank existingStorage = null; if (!allowSameFluids) { - for (var storage : getStorages()) { + for (var storage : storages) { if (!storage.getFluid().isEmpty() && storage.getFluid().isFluidEqual(resource)) { existingStorage = storage; break; @@ -366,8 +370,8 @@ public long fillInternal(FluidStack resource, boolean simulate) { } } if (existingStorage == null) { - for (var storage : getStorages()) { - var filled = storage.fill(copied.copy(), simulate); + for (var storage : storages) { + var filled = storage.fill(copied.copy(), action); if (filled > 0) { copied.shrink(filled); if (!allowSameFluids) { @@ -377,60 +381,51 @@ public long fillInternal(FluidStack resource, boolean simulate) { if (copied.isEmpty()) break; } } else { - copied.shrink(existingStorage.fill(copied.copy(), simulate)); + copied.shrink(existingStorage.fill(copied.copy(), action)); } return resource.getAmount() - copied.getAmount(); } @NotNull @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - if (tank >= 0 && tank < getStorages().length && canCapOutput()) { - return getStorages()[tank].drain(resource, simulate, notifyChanges); - } - return FluidStack.empty(); - } - - @NotNull - @Override - public FluidStack drain(FluidStack resource, boolean simulate) { + public FluidStack drain(FluidStack resource, FluidAction action) { if (canCapOutput()) { - return drainInternal(resource, simulate); + return drainInternal(resource, action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } - public FluidStack drainInternal(FluidStack resource, boolean simulate) { + public FluidStack drainInternal(FluidStack resource, FluidAction action) { if (!resource.isEmpty()) { var copied = resource.copy(); - for (var transfer : getStorages()) { + for (var storage : storages) { var candidate = copied.copy(); - copied.shrink(transfer.drain(candidate, simulate).getAmount()); + copied.shrink(storage.drain(candidate, action).getAmount()); if (copied.isEmpty()) break; } copied.setAmount(resource.getAmount() - copied.getAmount()); return copied; } - return FluidStack.empty(); + return FluidStack.EMPTY; } @NotNull @Override - public FluidStack drain(long maxDrain, boolean simulate) { + public FluidStack drain(int maxDrain, FluidAction action) { if (canCapOutput()) { - return drainInternal(maxDrain, simulate); + return drainInternal(maxDrain, action); } - return FluidStack.empty(); + return FluidStack.EMPTY; } - public FluidStack drainInternal(long maxDrain, boolean simulate) { + public FluidStack drainInternal(int maxDrain, FluidAction action) { if (maxDrain == 0) { - return FluidStack.empty(); + return FluidStack.EMPTY; } FluidStack totalDrained = null; - for (var storage : getStorages()) { + for (var storage : storages) { if (totalDrained == null || totalDrained.isEmpty()) { - totalDrained = storage.drain(maxDrain, simulate); + totalDrained = storage.drain(maxDrain, action); if (totalDrained.isEmpty()) { totalDrained = null; } else { @@ -439,23 +434,13 @@ public FluidStack drainInternal(long maxDrain, boolean simulate) { } else { FluidStack copy = totalDrained.copy(); copy.setAmount(maxDrain); - FluidStack drain = storage.drain(copy, simulate); + FluidStack drain = storage.drain(copy, action); totalDrained.grow(drain.getAmount()); maxDrain -= drain.getAmount(); } if (maxDrain <= 0) break; } - return totalDrained == null ? FluidStack.empty() : totalDrained; - } - - @Override - public boolean supportsFill(int i) { - return canCapInput(); - } - - @Override - public boolean supportsDrain(int i) { - return canCapOutput(); + return totalDrained == null ? FluidStack.EMPTY : totalDrained; } @Override @@ -465,19 +450,4 @@ public void onMachineLoad() { setFilter(stack -> stack.isFluidEqual(this.lockedFluid.getFluid())); } } - - @NotNull - @Override - public Object createSnapshot() { - return Arrays.stream(getStorages()).map(IFluidTransfer::createSnapshot).toArray(Object[]::new); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Object[] array && array.length == getStorages().length) { - for (int i = 0; i < array.length; i++) { - getStorages()[i].restoreFromSnapshot(array[i]); - } - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java index 87eb128b87..591882f1ff 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java @@ -12,15 +12,14 @@ import com.gregtechceu.gtceu.api.machine.feature.IMachineLife; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.misc.FluidBlockTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.DropSaved; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; @@ -32,9 +31,14 @@ import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; +import net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper; import lombok.Getter; import lombok.Setter; @@ -59,6 +63,7 @@ public class PumpMachine extends TieredEnergyMachine implements IAutoOutputFluid public static final int BASE_PUMP_RANGE = 32; public static final int EXTRA_PUMP_RANGE = 8; public static final int PUMP_SPEED_BASE = 80; + private final ItemStack ghostBucket = new ItemStack(Items.BUCKET, 1); private final Deque fluidSourceBlocks = new ArrayDeque<>(); private final Deque blocksToCheck = new ArrayDeque<>(); private boolean initializedQueue = false; @@ -89,7 +94,7 @@ public ManagedFieldHolder getFieldHolder() { } protected NotifiableFluidTank createCacheFluidHandler(Object... args) { - return new NotifiableFluidTank(this, 1, 16 * FluidHelper.getBucket() * Math.max(1, getTier()), IO.NONE, IO.OUT); + return new NotifiableFluidTank(this, 1, 16 * FluidType.BUCKET_VOLUME * Math.max(1, getTier()), IO.NONE, IO.OUT); } @Override @@ -195,16 +200,13 @@ public void onMachineRemoved() { } private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) { - var blockHere = getLevel().getBlockState(checkPos); + var state = getLevel().getBlockState(checkPos); boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos); - if (blockHere.getBlock() instanceof LiquidBlock liquidBlock && - liquidBlock.getFluidState(blockHere).isSource()) { - var fluidHandler = new FluidBlockTransfer(liquidBlock, getLevel(), checkPos); - FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, true); - if (!drainStack.isEmpty()) { - this.fluidSourceBlocks.add(checkPos); - } + if (state.getBlock() instanceof LiquidBlock liquid && liquid.getFluidState(state).isSource()) { + var handler = new BucketPickupHandlerWrapper(liquid, getLevel(), checkPos); + FluidStack drained = handler.drain(Integer.MAX_VALUE, FluidAction.SIMULATE); + if (!drained.isEmpty()) this.fluidSourceBlocks.add(checkPos); shouldCheckNeighbours = true; } @@ -225,16 +227,13 @@ private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) { private void tryPumpFirstBlock() { BlockPos fluidBlockPos = fluidSourceBlocks.poll(); if (fluidBlockPos == null) return; - var blockHere = getLevel().getBlockState(fluidBlockPos); - if (blockHere.getBlock() instanceof LiquidBlock liquidBlock && - liquidBlock.getFluidState(blockHere).isSource()) { - var fluidHandler = new FluidBlockTransfer(liquidBlock, getLevel(), fluidBlockPos); - FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, true); - if (!drainStack.isEmpty() && cache.fillInternal(drainStack, true) == drainStack.getAmount()) { - cache.fillInternal(drainStack, false); - fluidHandler.drain(drainStack, false); - getLevel().setBlockAndUpdate(fluidBlockPos, Blocks.AIR.defaultBlockState()); - this.fluidSourceBlocks.remove(fluidBlockPos); + BlockState state = getLevel().getBlockState(fluidBlockPos); + if (state.getBlock() instanceof LiquidBlock liquid && liquid.getFluidState(state).isSource()) { + var handler = new BucketPickupHandlerWrapper(liquid, getLevel(), fluidBlockPos); + FluidStack drained = handler.drain(Integer.MAX_VALUE, FluidAction.SIMULATE); + if (!drained.isEmpty() && cache.fillInternal(drained, FluidAction.SIMULATE) == drained.getAmount()) { + cache.fillInternal(drained, FluidAction.EXECUTE); + handler.drain(drained, FluidAction.EXECUTE); energyContainer.changeEnergy(-GTValues.V[getTier()] * 2); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java index 8d5f55b3a1..1cc8360219 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java @@ -12,12 +12,9 @@ import com.gregtechceu.gtceu.api.machine.feature.IDropSaveMachine; import com.gregtechceu.gtceu.api.machine.feature.IInteractedMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.side.fluid.FluidActionResult; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.DropSaved; @@ -31,16 +28,15 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.TickTask; import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; import lombok.Getter; @@ -74,7 +70,7 @@ public class DrumMachine extends MetaMachine implements IAutoOutputFluid, IDropS @DescSynced @Getter @DropSaved // rename "Fluid" for Item capability - protected FluidStack stored = FluidStack.empty(); + protected FluidStack stored = FluidStack.EMPTY; @Getter protected final Material material; @@ -117,7 +113,7 @@ private void onFluidChanged() { private void updateStoredFluidFromCache() { FluidStack cachedFluid = cache.getFluidInTank(0); - this.stored = cachedFluid.isEmpty() ? FluidStack.empty() : cachedFluid; + this.stored = cachedFluid.isEmpty() ? FluidStack.EMPTY : cachedFluid; } @Override @@ -137,7 +133,7 @@ public void onUnload() { public void loadFromItem(CompoundTag tag) { IDropSaveMachine.super.loadFromItem(tag); if (!tag.contains("Fluid")) { - stored = FluidStack.empty(); + stored = FluidStack.EMPTY; } // "stored" may not be same as cache (due to item's fluid cap). we should update it. cache.getStorages()[0].setFluid(stored.copy()); @@ -181,8 +177,8 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); - if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && FluidTransferHelper - .getFluidTransfer(getLevel(), getPos().relative(outputFacing), outputFacing.getOpposite()) != null) { + if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -205,44 +201,8 @@ public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Play BlockHitResult hit) { var currentStack = player.getMainHandItem(); if (!currentStack.isEmpty()) { - var handler = FluidTransferHelper.getFluidTransfer(player, InteractionHand.MAIN_HAND); - var fluidTank = cache.getStorages()[0]; - if (handler != null && !isRemote()) { - if (cache.getStorages()[0].getFluidAmount() > 0) { - FluidStack initialFluid = fluidTank.getFluid(); - FluidActionResult result = FluidTransferHelper.tryFillContainer(currentStack, fluidTank, - Integer.MAX_VALUE, null, false); - if (result.isSuccess()) { - ItemStack remainingStack = FluidTransferHelper - .tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); - currentStack.shrink(1); - SoundEvent soundevent = FluidHelper.getFillSound(initialFluid); - if (soundevent != null) { - player.level().playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); - } - if (!remainingStack.isEmpty() && !player.addItem(remainingStack)) { - Block.popResource(player.level(), player.getOnPos(), remainingStack); - } - return InteractionResult.SUCCESS; - } - } - - FluidActionResult result = FluidTransferHelper.tryEmptyContainer(currentStack, fluidTank, - Integer.MAX_VALUE, null, false); - if (result.isSuccess()) { - ItemStack remainingStack = FluidTransferHelper - .tryEmptyContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); - currentStack.shrink(1); - SoundEvent soundevent = FluidHelper.getEmptySound(fluidTank.getFluid()); - if (soundevent != null) { - player.level().playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundevent, - SoundSource.BLOCKS, 1.0F, 1.0F); - } - if (!remainingStack.isEmpty() && !player.getInventory().add(remainingStack)) { - Block.popResource(player.level(), player.getOnPos(), remainingStack); - } - } + if (!isRemote()) { + FluidUtil.interactWithFluidHandler(player, hand, cache); return InteractionResult.SUCCESS; } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java index 05d319b7fe..191c05a83b 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java @@ -14,14 +14,15 @@ import com.gregtechceu.gtceu.api.machine.feature.IFancyUIMachine; import com.gregtechceu.gtceu.api.machine.feature.IInteractedMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.lowdragmc.lowdraglib.gui.editor.ColorPattern; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; -import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.side.fluid.FluidActionResult; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; +import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; +import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; +import com.lowdragmc.lowdraglib.gui.widget.Widget; +import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; import com.lowdragmc.lowdraglib.syncdata.ISubscription; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.DropSaved; @@ -34,16 +35,16 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.TickTask; import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; import lombok.Getter; @@ -77,7 +78,7 @@ public class QuantumTankMachine extends TieredMachine implements IAutoOutputFlui @Persisted protected boolean allowInputFromOutputSideFluids; @Getter - private final long maxStoredFluids; + private final int maxStoredFluids; @Getter @Persisted @DropSaved @@ -90,13 +91,13 @@ public class QuantumTankMachine extends TieredMachine implements IAutoOutputFlui @DescSynced @Getter @DropSaved - protected FluidStack stored = FluidStack.empty(); + protected FluidStack stored = FluidStack.EMPTY; @Persisted @Getter @Setter private boolean isVoiding; - public QuantumTankMachine(IMachineBlockEntity holder, int tier, long maxStoredFluids, Object... args) { + public QuantumTankMachine(IMachineBlockEntity holder, int tier, int maxStoredFluids, Object... args) { super(holder, tier); this.outputFacingFluids = getFrontFacing().getOpposite(); this.maxStoredFluids = maxStoredFluids; @@ -116,21 +117,11 @@ protected NotifiableFluidTank createCacheFluidHandler(Object... args) { return new NotifiableFluidTank(this, 1, maxStoredFluids, IO.BOTH) { @Override - public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) { - return handleVoiding(super.fill(resource, simulate, notifyChanges), resource); + public int fill(FluidStack resource, FluidAction action) { + return handleVoiding(super.fill(resource, action), resource); } - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return handleVoiding(super.fill(tank, resource, simulate, notifyChanges), resource); - } - - @Override - public long fill(FluidStack resource, boolean simulate) { - return handleVoiding(super.fill(resource, simulate), resource); - } - - private long handleVoiding(long filled, FluidStack resource) { + private int handleVoiding(int filled, FluidStack resource) { if (filled < resource.getAmount() && isVoiding && isFluidValid(0, resource)) { if (stored.isEmpty() || stored.isFluidEqual(resource)) { return resource.getAmount(); @@ -207,8 +198,8 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); - if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && FluidTransferHelper - .getFluidTransfer(getLevel(), getPos().relative(outputFacing), outputFacing.getOpposite()) != null) { + if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && FluidUtil + .getFluidHandler(getLevel(), getPos().relative(outputFacing), outputFacing.getOpposite()).isPresent()) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -240,44 +231,8 @@ public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Play BlockHitResult hit) { var currentStack = player.getMainHandItem(); if (hit.getDirection() == getFrontFacing() && !currentStack.isEmpty()) { - var handler = FluidTransferHelper.getFluidTransfer(player, InteractionHand.MAIN_HAND); - var fluidTank = cache.getStorages()[0]; - if (handler != null && !isRemote()) { - if (cache.getStorages()[0].getFluidAmount() > 0) { - FluidStack initialFluid = fluidTank.getFluid(); - FluidActionResult result = FluidTransferHelper.tryFillContainer(currentStack, fluidTank, - Integer.MAX_VALUE, null, false); - if (result.isSuccess()) { - ItemStack remainingStack = FluidTransferHelper - .tryFillContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); - currentStack.shrink(1); - SoundEvent soundevent = FluidHelper.getFillSound(initialFluid); - if (soundevent != null) { - player.level().playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); - } - if (!remainingStack.isEmpty() && !player.addItem(remainingStack)) { - Block.popResource(player.level(), player.getOnPos(), remainingStack); - } - return InteractionResult.SUCCESS; - } - } - - FluidActionResult result = FluidTransferHelper.tryEmptyContainer(currentStack, fluidTank, - Integer.MAX_VALUE, null, false); - if (result.isSuccess()) { - ItemStack remainingStack = FluidTransferHelper - .tryEmptyContainer(currentStack, fluidTank, Integer.MAX_VALUE, null, true).getResult(); - currentStack.shrink(1); - SoundEvent soundevent = FluidHelper.getEmptySound(fluidTank.getFluid()); - if (soundevent != null) { - player.level().playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundevent, - SoundSource.BLOCKS, 1.0F, 1.0F); - } - if (!remainingStack.isEmpty() && !player.getInventory().add(remainingStack)) { - Block.popResource(player.level(), player.getOnPos(), remainingStack); - } - } + if (!isRemote()) { + FluidUtil.interactWithFluidHandler(player, hand, cache); return InteractionResult.SUCCESS; } } @@ -346,7 +301,7 @@ public Widget createUIWidget() { group.addWidget(new ImageWidget(4, 4, 82, 55, GuiTextures.DISPLAY)) .addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount")) .addWidget(new LabelWidget(8, 18, - () -> String.valueOf(cache.getFluidInTank(0).getAmount() / (FluidHelper.getBucket() / 1000))) + () -> String.valueOf(cache.getFluidInTank(0).getAmount() / (FluidType.BUCKET_VOLUME / 1000))) .setTextColor(-1).setDropShadow(true)) .addWidget(new TankWidget(cache.getStorages()[0], 68, 23, true, true) .setBackground(GuiTextures.FLUID_SLOT)) diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java index 074bb48e57..d1a522deb4 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java @@ -3,21 +3,16 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; -import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; +import net.minecraftforge.fluids.FluidStack; + import lombok.Getter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.List; import java.util.function.Supplier; public class ExportOnlyAEFluidList extends NotifiableFluidTank implements IConfigurableSlotList { @@ -28,7 +23,6 @@ public class ExportOnlyAEFluidList extends NotifiableFluidTank implements IConfi @Getter @Persisted protected ExportOnlyAEFluidSlot[] inventory; - private FluidStorage[] fluidStorages; public ExportOnlyAEFluidList(MetaMachine machine, int slots) { this(machine, slots, ExportOnlyAEFluidSlot::new); @@ -40,20 +34,12 @@ public ExportOnlyAEFluidList(MetaMachine machine, int slots, Supplier handleRecipeInner(IO io, GTRecipe recipe, List left, - @Nullable String slotName, boolean simulate) { - return handleIngredient(io, recipe, left, simulate, this.handlerIO, getStorages()); + return totalDrained == null ? FluidStack.EMPTY : totalDrained; } @Override @@ -121,29 +101,12 @@ public boolean ownsSlot(ExportOnlyAEFluidSlot testSlot) { return false; } - @Deprecated - @NotNull - @Override - public Object createSnapshot() { - return Arrays.stream(inventory).map(IFluidTransfer::createSnapshot).toArray(Object[]::new); - } - - @Deprecated - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Object[] array && array.length == inventory.length) { - for (int i = 0; i < array.length; i++) { - inventory[i].restoreFromSnapshot(array[i]); - } - } - } - @Override public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } - private static class FluidStorageDelegate extends FluidStorage { + private static class FluidStorageDelegate extends CustomFluidTank { private final ExportOnlyAEFluidSlot fluid; @@ -158,14 +121,13 @@ public FluidStack getFluid() { return this.fluid.getFluid(); } - @NotNull @Override - public FluidStack drain(FluidStack maxDrain, boolean simulate, boolean notifyChanges) { - return fluid.drain(maxDrain, simulate, notifyChanges); + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + return fluid.drain(resource, action); } @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChange) { + public int fill(FluidStack resource, FluidAction action) { return 0; } @@ -175,14 +137,13 @@ public boolean supportsFill(int tank) { } @Override - public FluidStorage copy() { + public CustomFluidTank copy() { // because recipe testing uses copy storage instead of simulated operations return new FluidStorageDelegate(fluid) { - @NotNull @Override - public FluidStack drain(FluidStack maxDrain, boolean simulate, boolean notifyChanges) { - return super.drain(maxDrain, true, notifyChanges); + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + return super.drain(resource, action); } }; } From 376776b00f8c58378ffead24f32117bb79e71064 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 01:15:05 -0400 Subject: [PATCH 06/22] say the line bart --- src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java index b3e1d4751d..94b098276d 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java @@ -433,8 +433,9 @@ public static FluidStack getFluidFromContainer(Object ingredient) { /** * Gets the FluidHandler from the adjacent block on the side connected to the caller - * @param level Level - * @param pos BlockPos of the machine which is calling + * + * @param level Level + * @param pos BlockPos of the machine which is calling * @param facing Direction to get the FluidHandler from * @return LazyOpt of the IFluidHandler described above */ From f421bf73e68c2f2a690d504ffcbed42e5086f546 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:19:33 -0400 Subject: [PATCH 07/22] Changed fluid prop-getters to be stack-aware --- .../com/gregtechceu/gtceu/api/misc/lib/TankWidget.java | 8 +++++--- .../gtceu/common/blockentity/FluidPipeBlockEntity.java | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java index 609bbee21c..a5b43aa5b6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java @@ -460,7 +460,7 @@ public void drawInForeground(@Nonnull GuiGraphics graphics, int mouseX, int mous .append(" " + "mB")); } tooltips.add(Component.translatable("ldlib.fluid.temperature", - lastFluidInTank.getFluid().getFluidType().getTemperature())); + lastFluidInTank.getFluid().getFluidType().getTemperature(lastFluidInTank))); tooltips.add(Component.translatable(lastFluidInTank.getFluid().getFluidType().isLighterThanAir() ? "ldlib.fluid.state_gas" : "ldlib.fluid.state_liquid")); } else { @@ -591,7 +591,8 @@ private int tryClickContainer(boolean isShiftKeyDown) { } } if (performedFill) { - SoundEvent soundevent = initialFluid.getFluid().getFluidType().getSound(SoundActions.BUCKET_FILL); + SoundEvent soundevent = initialFluid.getFluid().getFluidType().getSound(initialFluid, + SoundActions.BUCKET_FILL); if (soundevent != null) { player.level().playSound(null, player.position().x, player.position().y + 0.5, player.position().z, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); @@ -618,7 +619,8 @@ private int tryClickContainer(boolean isShiftKeyDown) { } var filledFluid = fluidTank.getFluidInTank(tank); if (performedEmptying) { - SoundEvent soundevent = filledFluid.getFluid().getFluidType().getSound(SoundActions.BUCKET_EMPTY); + SoundEvent soundevent = filledFluid.getFluid().getFluidType().getSound(filledFluid, + SoundActions.BUCKET_EMPTY); if (soundevent != null) { player.level().playSound(null, player.position().x, player.position().y + 0.5, player.position().z, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); diff --git a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java index 44b44dd1a5..d50602230c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java @@ -270,7 +270,7 @@ public void checkAndDestroy(@NotNull FluidStack stack) { boolean burning = prop.getMaxFluidTemperature() < fluid.getFluidType().getTemperature(stack); boolean leaking = !prop.isGasProof() && fluid.getFluidType().getDensity(stack) < 0; boolean shattering = !prop.isCryoProof() && - fluid.getFluidType().getTemperature() < FluidConstants.CRYOGENIC_FLUID_THRESHOLD; + fluid.getFluidType().getTemperature(stack) < FluidConstants.CRYOGENIC_FLUID_THRESHOLD; boolean corroding = false; boolean melting = false; From 20ec77de022c498819239997d4dcdc6c767e317f Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:01:48 -0400 Subject: [PATCH 08/22] Changed Drum and Tank right-click behavior Now passes the interaction for drums and tanks if the held item isn't a fluidhandler Also cleaned up the CreativeTankMachine to more properly make use of being a subclass Implemented CreativeTankMachine right-click behavior --- .../machine/storage/CreativeTankMachine.java | 124 +++++++++++------- .../common/machine/storage/DrumMachine.java | 6 +- .../machine/storage/QuantumTankMachine.java | 11 +- 3 files changed, 84 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java index f711904427..439afbdd73 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java @@ -4,11 +4,9 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; +import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; -import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; -import com.gregtechceu.gtceu.api.transfer.fluid.InfiniteFluidTransferProxy; -import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup; import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; @@ -18,11 +16,19 @@ import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; -import net.minecraft.core.Direction; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; public class CreativeTankMachine extends QuantumTankMachine { @@ -36,53 +42,66 @@ public class CreativeTankMachine extends QuantumTankMachine { @DropSaved private int ticksPerCycle = 1; - private final InfiniteFluidTransferProxy capabilityTransferProxy; - public CreativeTankMachine(IMachineBlockEntity holder) { super(holder, GTValues.MAX, -1); - - capabilityTransferProxy = new InfiniteFluidTransferProxy(cache, true, true); - } - - @Nullable - @Override - public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { - if (side == null || (useCoverCapability && coverContainer.hasCover(side))) - return super.getFluidTransferCap(side, useCoverCapability); - - return capabilityTransferProxy; } protected NotifiableFluidTank createCacheFluidHandler(Object... args) { - return new NotifiableFluidTank(this, 1, 1000, IO.BOTH, IO.NONE); - } - - @Override - protected void updateAutoOutputSubscription() { - var outputFacing = getOutputFacingFluids(); - if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { - autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); - } else if (autoOutputSubs != null) { - autoOutputSubs.unsubscribe(); - autoOutputSubs = null; - } + return new InfiniteTank(this); } protected void checkAutoOutput() { if (getOffsetTimer() % ticksPerCycle == 0) { if (isAutoOutputFluids() && getOutputFacingFluids() != null) { - updateFluidTick(); + cache.exportToNearby(getOutputFacingFluids()); } updateAutoOutputSubscription(); } } + private void updateStored(FluidStack fluid) { + cache.setFluidInTank(0, new FluidStack(fluid, 1000)); + stored = cache.getFluidInTank(0); + } + + @Override + public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, + BlockHitResult hit) { + var heldItem = player.getItemInHand(hand); + if (hit.getDirection() == getFrontFacing() && !isRemote()) { + // Clear fluid if empty + shift-rclick + if (heldItem.isEmpty() && player.isCrouching() && !stored.isEmpty()) { + updateStored(FluidStack.EMPTY); + return InteractionResult.SUCCESS; + } + + // If no fluid set and held-item has fluid, set fluid + if (stored.isEmpty()) { + FluidUtil.getFluidContained(heldItem).ifPresent(this::updateStored); + return InteractionResult.SUCCESS; + } + + // If held item can take fluid from tank, do it, otherwise set new fluid + var handler = FluidUtil.getFluidHandler(heldItem).resolve().orElse(null); + if (handler != null) { + var copy = stored.copy(); + copy.setAmount(Integer.MAX_VALUE); + int filled = handler.fill(copy, FluidAction.SIMULATE); + if (filled > 0) { + handler.fill(copy, FluidAction.EXECUTE); + player.setItemInHand(hand, handler.getContainer()); + } else updateStored(handler.getFluidInTank(0)); + return InteractionResult.SUCCESS; + } + } + return InteractionResult.PASS; + } + @Override public WidgetGroup createUIWidget() { var group = new WidgetGroup(0, 0, 176, 131); group.addWidget(new PhantomFluidWidget(this.cache.getStorages()[0], 0, 36, 6, 18, 18, - () -> this.cache.getStorages()[0].getFluid(), (fluid) -> this.cache.getStorages()[0].setFluid(fluid)) + this::getStored, this::updateStored) .setShowAmount(false).setBackground(GuiTextures.FLUID_SLOT)); group.addWidget(new LabelWidget(7, 9, "gtceu.creative.tank.fluid")); group.addWidget(new ImageWidget(7, 45, 154, 14, GuiTextures.DISPLAY)); @@ -112,22 +131,33 @@ public WidgetGroup createUIWidget() { return group; } - public void updateFluidTick() { - if (ticksPerCycle == 0 || getOffsetTimer() % ticksPerCycle != 0 || - cache.getStorages()[0].getFluid().isEmpty() || getLevel().isClientSide || !isWorkingEnabled()) - return; - - GTUtil.getAdjacentFluidHandler(getLevel(), getPos(), getOutputFacingFluids()).ifPresent(h -> { - FluidStack stack = cache.getFluidInTank(0).copy(); - stack.setAmount(mBPerCycle); - int insertable = h.fill(stack, FluidAction.SIMULATE); - stack.setAmount(Math.min(mBPerCycle, insertable)); - h.fill(stack, FluidAction.EXECUTE); - }); - } - @Override public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } + + private class InfiniteTank extends NotifiableFluidTank { + + public InfiniteTank(MetaMachine holder) { + super(holder, 1, FluidType.BUCKET_VOLUME, IO.BOTH, IO.BOTH); + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + if (!stored.isEmpty()) return resource.getAmount(); + return 0; + } + + @Override + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + if (!stored.isEmpty()) return new FluidStack(stored, mBPerCycle); + return FluidStack.EMPTY; + } + + @Override + public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { + if (!stored.isEmpty() && stored.isFluidEqual(resource)) return new FluidStack(resource, mBPerCycle); + return FluidStack.EMPTY; + } + } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java index 1cc8360219..708c737327 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java @@ -199,10 +199,8 @@ protected void checkAutoOutput() { @Override public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - var currentStack = player.getMainHandItem(); - if (!currentStack.isEmpty()) { - if (!isRemote()) { - FluidUtil.interactWithFluidHandler(player, hand, cache); + if (!isRemote()) { + if (FluidUtil.interactWithFluidHandler(player, hand, cache)) { return InteractionResult.SUCCESS; } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java index 191c05a83b..f825e57e26 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java @@ -16,6 +16,7 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.utils.GTUtil; import com.lowdragmc.lowdraglib.gui.editor.ColorPattern; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; @@ -198,8 +199,8 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); - if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && FluidUtil - .getFluidHandler(getLevel(), getPos().relative(outputFacing), outputFacing.getOpposite()).isPresent()) { + if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && + GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -229,10 +230,8 @@ public boolean isFacingValid(Direction facing) { @Override public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - var currentStack = player.getMainHandItem(); - if (hit.getDirection() == getFrontFacing() && !currentStack.isEmpty()) { - if (!isRemote()) { - FluidUtil.interactWithFluidHandler(player, hand, cache); + if (hit.getDirection() == getFrontFacing() && !isRemote()) { + if (FluidUtil.interactWithFluidHandler(player, hand, cache)) { return InteractionResult.SUCCESS; } } From 5bbb1af62894f8b6fec6cc327e292f4a9a1cdea3 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:50:54 -0400 Subject: [PATCH 09/22] Implemented Requested Changes Removed any unnecessary BUCKET_VOLUME uses Moved new classes to appropriate packages Renamed Fluid classes to use Handler rather than Transfer --- .../blockentity/MetaMachineBlockEntity.java | 4 +- .../recipe/FluidRecipeCapability.java | 12 ++-- .../properties/FluidPipeProperties.java | 6 -- .../gtceu/api/gui/misc/IGhostFluidTarget.java | 2 +- .../widget}/PhantomFluidWidget.java | 2 +- .../widget/ScrollablePhantomFluidWidget.java | 5 +- .../{misc/lib => gui/widget}/TankWidget.java | 25 ++++--- .../gtceu/api/machine/MetaMachine.java | 4 +- .../api/machine/SimpleTieredMachine.java | 4 +- .../FancyTankConfigurator.java | 2 +- .../api/machine/steam/SimpleSteamMachine.java | 2 +- .../api/machine/steam/SteamBoilerMachine.java | 12 ++-- .../machine/trait/FluidTankProxyTrait.java | 15 ++-- .../machine/trait/NotifiableFluidTank.java | 6 +- ...nsferList.java => IOFluidHandlerList.java} | 10 +-- .../recipe/ingredient/FluidIngredient.java | 3 +- ...elegate.java => FluidHandlerDelegate.java} | 4 +- .../fluid/FluidHandlerList.java} | 40 ++++++----- ...xy.java => InfiniteFluidHandlerProxy.java} | 4 +- .../fluid/ModifiableFluidHandlerWrapper.java | 10 ++- .../fluid/TagOrCycleFluidHandler.java} | 8 +-- .../blockentity/FluidPipeBlockEntity.java | 3 +- .../common/cover/FluidRegulatorCover.java | 7 +- .../gtceu/common/cover/PumpCover.java | 24 +++---- .../voiding/AdvancedFluidVoidingCover.java | 2 +- .../gtceu/common/data/GTRecipeTypes.java | 2 +- .../common/data/GTSyncedFieldAccessors.java | 5 +- .../gtceu/common/item/ItemFluidContainer.java | 22 +++--- .../common/machine/electric/PumpMachine.java | 2 +- .../electric/LargeMinerMachine.java | 8 +-- .../electric/MultiblockTankMachine.java | 5 +- .../electric/research/HPCAMachine.java | 4 +- .../multiblock/part/CokeOvenHatch.java | 4 +- .../multiblock/part/DualHatchPartMachine.java | 6 +- .../part/FluidHatchPartMachine.java | 8 +-- .../multiblock/part/PumpHatchPartMachine.java | 2 +- .../part/SteamHatchPartMachine.java | 2 +- .../multiblock/part/TankValvePartMachine.java | 4 +- .../multiblock/primitive/CokeOvenMachine.java | 2 +- .../steam/SteamLiquidBoilerMachine.java | 2 +- .../machine/steam/SteamMinerMachine.java | 2 +- .../common/machine/storage/BufferMachine.java | 6 +- .../machine/storage/CreativeTankMachine.java | 2 +- .../common/machine/storage/DrumMachine.java | 4 +- .../machine/storage/QuantumTankMachine.java | 11 ++- .../common/machine/trait/FluidDrillLogic.java | 3 +- .../integration/GTOreByProductWidget.java | 6 +- .../gtceu/integration/GTOreVeinWidget.java | 2 +- .../gui/widget/list/AEFluidDisplayWidget.java | 5 +- ...dStackLoad.java => FluidStackPayload.java} | 2 +- .../gtceu/utils/GTTransferUtils.java | 68 +++++++++++++++++-- .../com/gregtechceu/gtceu/utils/GTUtil.java | 53 --------------- .../gtceu/utils/OverlayedFluidHandler.java | 4 +- 53 files changed, 221 insertions(+), 241 deletions(-) rename src/main/java/com/gregtechceu/gtceu/api/{misc/lib => gui/widget}/PhantomFluidWidget.java (99%) rename src/main/java/com/gregtechceu/gtceu/api/{misc/lib => gui/widget}/TankWidget.java (97%) rename src/main/java/com/gregtechceu/gtceu/api/misc/{IOFluidTransferList.java => IOFluidHandlerList.java} (82%) rename src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/{FluidTransferDelegate.java => FluidHandlerDelegate.java} (92%) rename src/main/java/com/gregtechceu/gtceu/api/{misc/lib/FluidTransferList.java => transfer/fluid/FluidHandlerList.java} (82%) rename src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/{InfiniteFluidTransferProxy.java => InfiniteFluidHandlerProxy.java} (82%) rename src/main/java/com/gregtechceu/gtceu/api/{misc/lib/TagOrCycleFluidTransfer.java => transfer/fluid/TagOrCycleFluidHandler.java} (91%) rename src/main/java/com/gregtechceu/gtceu/syncdata/{FluidStackLoad.java => FluidStackPayload.java} (91%) diff --git a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java index b73b80b032..4b1ed0563a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java @@ -17,7 +17,7 @@ import com.gregtechceu.gtceu.client.renderer.GTRendererProvider; import com.gregtechceu.gtceu.common.pipelike.fluidpipe.longdistance.LDFluidEndpointMachine; import com.gregtechceu.gtceu.common.pipelike.item.longdistance.LDItemEndpointMachine; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.client.renderer.IRenderer; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; @@ -217,7 +217,7 @@ public static LazyOptional getCapability(MetaMachine machine, @NotNull Ca ILDEndpoint endpoint = fluidEndpointMachine.getLink(); if (endpoint == null) return null; Direction outputFacing = fluidEndpointMachine.getOutputFacing(); - var h = GTUtil.getAdjacentFluidHandler(machine.getLevel(), endpoint.getPos(), outputFacing) + var h = GTTransferUtils.getAdjacentFluidHandler(machine.getLevel(), endpoint.getPos(), outputFacing) .map(LDFluidEndpointMachine.FluidHandlerWrapper::new); if (h.isPresent()) { return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, LazyOptional.of(h::get)); diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java index 90a937a023..8981ea47bf 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/recipe/FluidRecipeCapability.java @@ -1,8 +1,6 @@ package com.gregtechceu.gtceu.api.capability.recipe; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; -import com.gregtechceu.gtceu.api.misc.lib.TagOrCycleFluidTransfer; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.content.Content; @@ -14,7 +12,9 @@ import com.gregtechceu.gtceu.api.recipe.lookup.MapFluidTagIngredient; import com.gregtechceu.gtceu.api.recipe.modifier.ParallelLogic; import com.gregtechceu.gtceu.api.recipe.ui.GTRecipeTypeUI; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +import com.gregtechceu.gtceu.api.transfer.fluid.TagOrCycleFluidHandler; import com.gregtechceu.gtceu.client.TooltipsHandler; import com.gregtechceu.gtceu.integration.GTRecipeWidget; import com.gregtechceu.gtceu.utils.FluidKey; @@ -150,7 +150,7 @@ public int limitParallel(GTRecipe recipe, IRecipeCapabilityHolder holder, int mu int minMultiplier = 0; int maxMultiplier = multiplier; - OverlayedFluidHandler overlayedFluidHandler = new OverlayedFluidHandler(new FluidTransferList( + OverlayedFluidHandler overlayedFluidHandler = new OverlayedFluidHandler(new FluidHandlerList( Objects.requireNonNullElseGet(holder.getCapabilitiesProxy().get(IO.OUT, FluidRecipeCapability.CAP), Collections::emptyList) .stream() @@ -302,7 +302,7 @@ public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe, public Object createXEIContainer(List contents) { // cast is safe if you don't pass the wrong thing. // noinspection unchecked - return new TagOrCycleFluidTransfer( + return new TagOrCycleFluidHandler( (List, Integer>>, List>>) contents); } @@ -332,7 +332,7 @@ public void applyWidgetInfo(@NotNull Widget widget, @Nullable Content content, @Nullable Object storage) { if (widget instanceof TankWidget tank) { - if (storage instanceof TagOrCycleFluidTransfer fluidHandler) { + if (storage instanceof TagOrCycleFluidHandler fluidHandler) { tank.setFluidTank(fluidHandler, index); } else if (storage instanceof IFluidHandlerModifiable fluidHandler) { tank.setFluidTank(new OverlayingFluidStorage(fluidHandler, index)); diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java index 8e3a7cce9a..04ebcc9691 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java @@ -5,8 +5,6 @@ import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttribute; import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttributes; -import net.minecraftforge.fluids.FluidType; - import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import lombok.Getter; @@ -103,10 +101,6 @@ public String toString() { '}'; } - public int getPlatformThroughput() { - return getThroughput() * FluidType.BUCKET_VOLUME / 1000; - } - @Override public boolean canContain(@NotNull FluidState state) { return switch (state) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java index 4501b899b5..baeaaeb6f0 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java @@ -17,7 +17,7 @@ import java.util.Collections; import java.util.List; -import static com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget.drainFrom; +import static com.gregtechceu.gtceu.api.gui.widget.PhantomFluidWidget.drainFrom; public interface IGhostFluidTarget extends IGhostIngredientTarget { diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java similarity index 99% rename from src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java rename to src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java index 5ad8c55d94..ff507739e1 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/PhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.api.misc.lib; +package com.gregtechceu.gtceu.api.gui.widget; import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.editor.annotation.ConfigSetter; diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java index 43e5d7d634..93f621d2aa 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java @@ -1,6 +1,5 @@ package com.gregtechceu.gtceu.api.gui.widget; -import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.utils.GTUtil; @@ -8,7 +7,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import org.jetbrains.annotations.Nullable; @@ -18,7 +16,6 @@ public class ScrollablePhantomFluidWidget extends PhantomFluidWidget { private static final int SCROLL_ACTION_ID = 0x0001_0001; - private static final int MILLIBUCKETS = FluidType.BUCKET_VOLUME / 1000; public ScrollablePhantomFluidWidget(@Nullable IFluidHandlerModifiable fluidTank, int tank, int x, int y, int width, int height, Supplier phantomFluidGetter, @@ -32,7 +29,7 @@ public boolean mouseWheelMove(double mouseX, double mouseY, double wheelDelta) { if (!isMouseOverElement(mouseX, mouseY)) return false; - var delta = getModifiedChangeAmount((wheelDelta > 0) ? 1 : -1) * MILLIBUCKETS; + var delta = getModifiedChangeAmount((wheelDelta > 0) ? 1 : -1); writeClientAction(SCROLL_ACTION_ID, buf -> buf.writeInt(delta)); return true; diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java similarity index 97% rename from src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java rename to src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java index a5b43aa5b6..9c0bd5cfe7 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java @@ -1,4 +1,6 @@ -package com.gregtechceu.gtceu.api.misc.lib; +package com.gregtechceu.gtceu.api.gui.widget; + +import com.gregtechceu.gtceu.api.transfer.fluid.TagOrCycleFluidHandler; import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.Platform; @@ -45,7 +47,6 @@ import net.minecraftforge.common.SoundActions; import net.minecraftforge.fluids.FluidActionResult; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.templates.FluidTank; @@ -206,7 +207,7 @@ public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { return getXEIIngredientsFromCycleTransferClickable(cycleItemStackHandler, tank).get(0); - } else if (this.fluidTank instanceof TagOrCycleFluidTransfer transfer) { + } else if (this.fluidTank instanceof TagOrCycleFluidHandler transfer) { return getXEIIngredientsFromTagOrCycleTransferClickable(transfer, tank).get(0); } @@ -232,7 +233,7 @@ public List getXEIIngredients() { if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { return getXEIIngredientsFromCycleTransfer(cycleItemStackHandler, tank); - } else if (this.fluidTank instanceof TagOrCycleFluidTransfer transfer) { + } else if (this.fluidTank instanceof TagOrCycleFluidHandler transfer) { return getXEIIngredientsFromTagOrCycleTransfer(transfer, tank); } @@ -280,7 +281,7 @@ private List getXEIIngredientsFromCycleTransferClickable(CycleFluidTrans return Collections.emptyList(); } - private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidTransfer transfer, int index) { + private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidHandler transfer, int index) { Either, Integer>>, List> either = transfer .getStacks() .get(index); @@ -317,7 +318,7 @@ private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidTran return ref.returnValue; } - private List getXEIIngredientsFromTagOrCycleTransferClickable(TagOrCycleFluidTransfer transfer, int index) { + private List getXEIIngredientsFromTagOrCycleTransferClickable(TagOrCycleFluidHandler transfer, int index) { Either, Integer>>, List> either = transfer .getStacks() .get(index); @@ -452,12 +453,11 @@ public void drawInForeground(@Nonnull GuiGraphics graphics, int mouseX, int mous if (lastFluidInTank != null && !lastFluidInTank.isEmpty()) { tooltips.add(lastFluidInTank.getDisplayName()); tooltips.add(Component.translatable("ldlib.fluid.amount", lastFluidInTank.getAmount(), lastTankCapacity) - .append(" " + FluidHelper.getUnit())); + .append(" mB")); if (!Platform.isForge()) { tooltips.add(Component.literal( - "§6mB:§r %d/%d".formatted(lastFluidInTank.getAmount() * 1000 / FluidType.BUCKET_VOLUME, - lastTankCapacity * 1000 / FluidType.BUCKET_VOLUME)) - .append(" " + "mB")); + "§6mB:§r %d/%d mB".formatted(lastFluidInTank.getAmount(), + lastTankCapacity))); } tooltips.add(Component.translatable("ldlib.fluid.temperature", lastFluidInTank.getFluid().getFluidType().getTemperature(lastFluidInTank))); @@ -466,11 +466,10 @@ public void drawInForeground(@Nonnull GuiGraphics graphics, int mouseX, int mous } else { tooltips.add(Component.translatable("ldlib.fluid.empty")); tooltips.add(Component.translatable("ldlib.fluid.amount", 0, lastTankCapacity) - .append(" " + FluidHelper.getUnit())); + .append(" mB")); if (!Platform.isForge()) { tooltips.add(Component - .literal("§6mB:§r %d/%d".formatted(0, lastTankCapacity * 1000 / FluidType.BUCKET_VOLUME)) - .append(" " + "mB")); + .literal("§6mB:§r %d/%d mB".formatted(0, lastTankCapacity))); } } if (gui != null) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java index 97a748259a..4380abd2fb 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java @@ -19,7 +19,7 @@ import com.gregtechceu.gtceu.api.machine.feature.*; import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart; import com.gregtechceu.gtceu.api.machine.trait.MachineTrait; -import com.gregtechceu.gtceu.api.misc.IOFluidTransferList; +import com.gregtechceu.gtceu.api.misc.IOFluidHandlerList; import com.gregtechceu.gtceu.api.misc.IOItemTransferList; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.common.cover.FluidFilterCover; @@ -705,7 +705,7 @@ public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boo io = IO.OUT; } - IOFluidTransferList transferList = new IOFluidTransferList(list, io, getFluidCapFilter(side)); + IOFluidHandlerList transferList = new IOFluidHandlerList(list, io, getFluidCapFilter(side)); if (!useCoverCapability || side == null) return transferList; CoverBehavior cover = getCoverContainer().getCoverAtSide(side); diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java index 3de80209e5..5703c95df8 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/SimpleTieredMachine.java @@ -18,7 +18,7 @@ import com.gregtechceu.gtceu.common.item.IntCircuitBehaviour; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.lang.LangHandler; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; @@ -249,7 +249,7 @@ protected void updateAutoOutputSubscription() { ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(outputFacingItems), outputFacingItems.getOpposite()) != null || (isAutoOutputFluids() && !exportFluids.isEmpty()) && outputFacingFluids != null && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { + GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java index 89c20b0b61..ffde47feb4 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/FancyTankConfigurator.java @@ -2,7 +2,7 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.fancy.IFancyConfigurator; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java index 603f8f7875..18fec5a333 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SimpleSteamMachine.java @@ -89,7 +89,7 @@ public void onLoad() { super.onLoad(); // Fine, we use it to provide eu cap for recipe, simulating an EU machine. capabilitiesProxy.put(IO.IN, EURecipeCapability.CAP, - List.of(new SteamEnergyRecipeHandler(steamTank, FluidType.BUCKET_VOLUME / 1000d))); + List.of(new SteamEnergyRecipeHandler(steamTank, 1d))); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java index 800d7dfce3..4a3a0ef1de 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java @@ -4,6 +4,7 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.UITemplate; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.TickableSubscription; @@ -11,7 +12,6 @@ import com.gregtechceu.gtceu.api.machine.feature.IExplosionMachine; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.logic.OCParams; import com.gregtechceu.gtceu.api.recipe.logic.OCResult; @@ -19,7 +19,7 @@ import com.gregtechceu.gtceu.common.item.PortableScannerBehavior; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.utils.FormattingUtil; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; @@ -146,7 +146,7 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { if (Direction.stream().filter(direction -> direction != getFrontFacing() && direction != Direction.DOWN) - .anyMatch(direction -> GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), direction))) { + .anyMatch(direction -> GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), direction))) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -158,7 +158,7 @@ protected void autoOutput() { if (getOffsetTimer() % 5 == 0) { steamTank.exportToNearby(Direction.stream() .filter(direction -> direction != getFrontFacing() && direction != Direction.DOWN) - .filter(direction -> GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), direction)) + .filter(direction -> GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), direction)) .toArray(Direction[]::new)); updateAutoOutputSubscription(); } @@ -198,12 +198,12 @@ protected void updateCurrentTemperature() { if (currentTemperature >= 100) { int fillAmount = (int) (getBaseSteamOutput() * ((float) currentTemperature / getMaxTemperature()) / 2); - boolean hasDrainedWater = !waterTank.drainInternal(FluidType.BUCKET_VOLUME / 1000, FluidAction.EXECUTE) + boolean hasDrainedWater = !waterTank.drainInternal(1, FluidAction.EXECUTE) .isEmpty(); var filledSteam = 0L; if (hasDrainedWater) { filledSteam = steamTank.fillInternal( - GTMaterials.Steam.getFluid(fillAmount * FluidType.BUCKET_VOLUME / 1000), + GTMaterials.Steam.getFluid(fillAmount), FluidAction.EXECUTE); } if (this.hasNoWater && hasDrainedWater) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java index 9d5d7047c3..5c3840e2ce 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/FluidTankProxyTrait.java @@ -2,20 +2,19 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.MetaMachine; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import net.minecraft.core.Direction; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author KilaBash @@ -23,15 +22,14 @@ * @implNote FluidTankProxyTrait */ @Accessors(chain = true) -public class FluidTankProxyTrait extends MachineTrait implements IFluidHandler, ICapabilityTrait { +public class FluidTankProxyTrait extends MachineTrait implements IFluidHandlerModifiable, ICapabilityTrait { public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(FluidTankProxyTrait.class); @Getter public final IO capabilityIO; @Setter @Getter - @Nullable - public IFluidHandler proxy; + public IFluidHandlerModifiable proxy; public FluidTankProxyTrait(MetaMachine machine, IO capabilityIO) { super(machine); @@ -58,9 +56,10 @@ public FluidStack getFluidInTank(int tank) { return proxy == null ? FluidStack.EMPTY : proxy.getFluidInTank(tank); } + @Override public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { if (proxy != null) { - // proxy.setFluidInTank(tank, fluidStack); + proxy.setFluidInTank(tank, fluidStack); } } @@ -137,7 +136,7 @@ public void exportToNearby(Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - GTUtil.getAdjacentFluidHandler(level, pos, facing).ifPresent( + GTTransferUtils.getAdjacentFluidHandler(level, pos, facing).ifPresent( h -> FluidUtil.tryFluidTransfer(h, this, Integer.MAX_VALUE, true)); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index 16b8f36518..0f27edc77a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -8,7 +8,7 @@ import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; @@ -314,7 +314,7 @@ public void exportToNearby(@NotNull Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - GTUtil.getAdjacentFluidHandler(level, pos, facing) + GTTransferUtils.getAdjacentFluidHandler(level, pos, facing) .ifPresent(h -> FluidUtil.tryFluidTransfer(h, this, Integer.MAX_VALUE, true)); } } @@ -323,7 +323,7 @@ public void importFromNearby(@NotNull Direction... facings) { var level = getMachine().getLevel(); var pos = getMachine().getPos(); for (Direction facing : facings) { - GTUtil.getAdjacentFluidHandler(level, pos, facing) + GTTransferUtils.getAdjacentFluidHandler(level, pos, facing) .ifPresent(h -> FluidUtil.tryFluidTransfer(this, h, Integer.MAX_VALUE, true)); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java b/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidHandlerList.java similarity index 82% rename from src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java rename to src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidHandlerList.java index f315509342..ed69683329 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidTransferList.java +++ b/src/main/java/com/gregtechceu/gtceu/api/misc/IOFluidHandlerList.java @@ -1,7 +1,7 @@ package com.gregtechceu.gtceu.api.misc; import com.gregtechceu.gtceu.api.capability.recipe.IO; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import net.minecraftforge.fluids.FluidStack; @@ -18,13 +18,13 @@ * @date 2023/3/14 * @implNote IOFluidTransferList */ -public class IOFluidTransferList extends FluidTransferList implements IFluidHandlerModifiable { +public class IOFluidHandlerList extends FluidHandlerList implements IFluidHandlerModifiable { @Getter private final IO io; - public IOFluidTransferList(List transfers, IO io, Predicate filter) { - super(transfers); + public IOFluidHandlerList(List handlers, IO io, Predicate filter) { + super(handlers); this.io = io; setFilter(filter); } @@ -50,7 +50,7 @@ public int fill(FluidStack resource, FluidAction action) { @Override public void setFluidInTank(int tank, FluidStack stack) { int index = 0; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (handler instanceof IFluidHandlerModifiable modifiable) { if (tank - index < handler.getTanks()) modifiable.setFluidInTank(tank - index, stack); return; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java index 8ed19da6d6..2d998ab95e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java @@ -12,7 +12,6 @@ import net.minecraft.world.level.material.Fluids; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import com.google.common.collect.Lists; import com.google.gson.*; @@ -64,7 +63,7 @@ public void toNetwork(FriendlyByteBuf buffer) { public JsonElement toJson() { JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("amount", this.amount * FluidType.BUCKET_VOLUME / 1000); + jsonObject.addProperty("amount", this.amount); if (this.nbt != null) { jsonObject.addProperty("nbt", this.nbt.getAsString()); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerDelegate.java similarity index 92% rename from src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java rename to src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerDelegate.java index 256640a857..eefafa1760 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidTransferDelegate.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerDelegate.java @@ -11,12 +11,12 @@ @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public abstract class FluidTransferDelegate implements IFluidHandlerModifiable { +public abstract class FluidHandlerDelegate implements IFluidHandlerModifiable { @Setter public IFluidHandlerModifiable delegate; - public FluidTransferDelegate(IFluidHandlerModifiable delegate) { + public FluidHandlerDelegate(IFluidHandlerModifiable delegate) { this.delegate = delegate; } diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerList.java similarity index 82% rename from src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java rename to src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerList.java index 9b46d1ff5e..34e6e9fef7 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/FluidTransferList.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/FluidHandlerList.java @@ -1,6 +1,4 @@ -package com.gregtechceu.gtceu.api.misc.lib; - -import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +package com.gregtechceu.gtceu.api.transfer.fluid; import com.lowdragmc.lowdraglib.LDLib; @@ -17,30 +15,30 @@ import java.util.List; import java.util.function.Predicate; -public class FluidTransferList implements IFluidHandlerModifiable, INBTSerializable { +public class FluidHandlerList implements IFluidHandlerModifiable, INBTSerializable { - public final IFluidHandler[] transfers; + public final IFluidHandler[] handlers; @Setter protected Predicate filter = fluid -> true; - public FluidTransferList(IFluidHandler... transfers) { - this.transfers = transfers; + public FluidHandlerList(IFluidHandler... handlers) { + this.handlers = handlers; } - public FluidTransferList(List transfers) { - this.transfers = transfers.toArray(IFluidHandler[]::new); + public FluidHandlerList(List handlers) { + this.handlers = handlers.toArray(IFluidHandler[]::new); } @Override public int getTanks() { - return Arrays.stream(transfers).mapToInt(IFluidHandler::getTanks).sum(); + return Arrays.stream(handlers).mapToInt(IFluidHandler::getTanks).sum(); } @Override public @NotNull FluidStack getFluidInTank(int tank) { int index = 0; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (tank - index < handler.getTanks()) { return handler.getFluidInTank(tank - index); } @@ -52,7 +50,7 @@ public int getTanks() { @Override public void setFluidInTank(int tank, FluidStack stack) { int index = 0; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (handler instanceof IFluidHandlerModifiable modifiable) { if (tank - index < modifiable.getTanks()) { modifiable.setFluidInTank(tank - index, stack); @@ -66,7 +64,7 @@ public void setFluidInTank(int tank, FluidStack stack) { @Override public int getTankCapacity(int tank) { int index = 0; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (tank - index < handler.getTanks()) { return handler.getTankCapacity(tank - index); } @@ -80,7 +78,7 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { if (!filter.test(stack)) return false; int index = 0; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (tank - index < handler.getTanks()) { return handler.isFluidValid(tank - index, stack); } @@ -93,7 +91,7 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { public int fill(FluidStack resource, FluidAction action) { if (resource.isEmpty() || !filter.test(resource)) return 0; var copied = resource.copy(); - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { var candidate = copied.copy(); copied.shrink(handler.fill(candidate, action)); if (copied.isEmpty()) break; @@ -105,7 +103,7 @@ public int fill(FluidStack resource, FluidAction action) { public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { if (resource.isEmpty() || !filter.test(resource)) return FluidStack.EMPTY; var copied = resource.copy(); - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { var candidate = copied.copy(); copied.shrink(handler.drain(candidate, action).getAmount()); if (copied.isEmpty()) break; @@ -118,7 +116,7 @@ public int fill(FluidStack resource, FluidAction action) { public @NotNull FluidStack drain(int maxDrain, FluidAction action) { if (maxDrain == 0) return FluidStack.EMPTY; FluidStack totalDrained = null; - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (totalDrained == null || totalDrained.isEmpty()) { totalDrained = handler.drain(maxDrain, action); if (totalDrained.isEmpty()) totalDrained = null; @@ -139,7 +137,7 @@ public int fill(FluidStack resource, FluidAction action) { public CompoundTag serializeNBT() { var tag = new CompoundTag(); var list = new ListTag(); - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (handler instanceof INBTSerializable serializable) { list.add(serializable.serializeNBT()); } else { @@ -155,7 +153,7 @@ public CompoundTag serializeNBT() { public void deserializeNBT(CompoundTag nbt) { var list = nbt.getList("tanks", nbt.getByte("type")); for (int i = 0; i < list.size(); i++) { - if (transfers[i] instanceof INBTSerializable serializable) { + if (handlers[i] instanceof INBTSerializable serializable) { serializable.deserializeNBT(list.get(i)); } else { LDLib.LOGGER.warn("[FluidHandlerList] internal tank doesn't support serialization"); @@ -165,7 +163,7 @@ public void deserializeNBT(CompoundTag nbt) { @Override public boolean supportsFill(int tank) { - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (tank >= handler.getTanks()) { tank -= handler.getTanks(); continue; @@ -181,7 +179,7 @@ public boolean supportsFill(int tank) { @Override public boolean supportsDrain(int tank) { - for (IFluidHandler handler : transfers) { + for (IFluidHandler handler : handlers) { if (tank >= handler.getTanks()) { tank -= handler.getTanks(); continue; diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java similarity index 82% rename from src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java rename to src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java index 2f52a8f9ec..2604ff1841 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidTransferProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java @@ -9,12 +9,12 @@ @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -public class InfiniteFluidTransferProxy extends FluidTransferDelegate { +public class InfiniteFluidHandlerProxy extends FluidHandlerDelegate { private final boolean infiniteSource; private final boolean infiniteSink; - public InfiniteFluidTransferProxy(IFluidHandlerModifiable delegate, boolean infiniteSource, boolean infiniteSink) { + public InfiniteFluidHandlerProxy(IFluidHandlerModifiable delegate, boolean infiniteSource, boolean infiniteSink) { super(delegate); this.infiniteSource = infiniteSource; diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java index d91b29aea4..a8876dcb9c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/ModifiableFluidHandlerWrapper.java @@ -12,9 +12,13 @@ public class ModifiableFluidHandlerWrapper implements IFluidHandlerModifiable { private IFluidHandler handler; @Override - public void setFluidInTank(int i, FluidStack fluidStack) { - drain(handler.getFluidInTank(i), FluidAction.EXECUTE); - fill(fluidStack, FluidAction.EXECUTE); + public void setFluidInTank(int tank, FluidStack fluidStack) { + var fluid = handler.getFluidInTank(tank); + var canDrain = handler.drain(fluid, FluidAction.SIMULATE); + if (!canDrain.isEmpty()) { + drain(canDrain, FluidAction.EXECUTE); + fill(fluidStack, FluidAction.EXECUTE); + } } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/TagOrCycleFluidHandler.java similarity index 91% rename from src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java rename to src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/TagOrCycleFluidHandler.java index dc2a4f83d4..37accfe65b 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/lib/TagOrCycleFluidTransfer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/TagOrCycleFluidHandler.java @@ -1,6 +1,4 @@ -package com.gregtechceu.gtceu.api.misc.lib; - -import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; +package com.gregtechceu.gtceu.api.transfer.fluid; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.tags.TagKey; @@ -18,14 +16,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class TagOrCycleFluidTransfer implements IFluidHandlerModifiable { +public class TagOrCycleFluidHandler implements IFluidHandlerModifiable { @Getter private List, Integer>>, List>> stacks; private List> unwrapped = null; - public TagOrCycleFluidTransfer(List, Integer>>, List>> stacks) { + public TagOrCycleFluidHandler(List, Integer>>, List>> stacks) { updateStacks(stacks); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java index d50602230c..fdd9170080 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java @@ -21,6 +21,7 @@ import com.gregtechceu.gtceu.common.pipelike.fluidpipe.PipeTankList; import com.gregtechceu.gtceu.utils.EntityDamageUtil; import com.gregtechceu.gtceu.utils.FormattingUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.gregtechceu.gtceu.utils.GTUtil; import net.minecraft.ChatFormatting; @@ -105,7 +106,7 @@ public boolean canAttachTo(Direction side) { if (level.getBlockEntity(getBlockPos().relative(side)) instanceof FluidPipeBlockEntity) { return false; } - return GTUtil.isAdjacentFluidHandler(level, getBlockPos(), side); + return GTTransferUtils.hasAdjacentFluidHandler(level, getBlockPos(), side); } return false; } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java index 7da5d97d24..744d952f01 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidRegulatorCover.java @@ -74,7 +74,7 @@ private int transferExact(IFluidHandler source, IFluidHandler destination, int p break; FluidStack sourceFluid = source.getFluidInTank(slot).copy(); - int supplyAmount = getFilteredFluidAmount(sourceFluid) * MILLIBUCKET_SIZE; + int supplyAmount = getFilteredFluidAmount(sourceFluid); // If the remaining transferrable amount in this operation is not enough to transfer the full stack size, // the remaining amount for this operation will be buffered and added to the next operation's maximum. @@ -123,7 +123,7 @@ private int keepExact(IFluidHandlerModifiable source, IFluidHandlerModifiable de if (fluidLeftToTransfer <= 0) break; - int amountToKeep = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; + int amountToKeep = getFilteredFluidAmount(fluidStack); int amountInDest = destinationAmounts.getOrDefault(fluidStack, 0); if (amountInDest >= amountToKeep) continue; @@ -190,8 +190,7 @@ private int getFilteredFluidAmount(FluidStack fluidStack) { return globalTransferSizeMillibuckets; FluidFilter filter = filterHandler.getFilter(); - return (filter.supportsAmounts() ? filter.testFluidAmount(fluidStack) : globalTransferSizeMillibuckets) * - MILLIBUCKET_SIZE; + return (filter.supportsAmounts() ? filter.testFluidAmount(fluidStack) : globalTransferSizeMillibuckets); } /////////////////////////// diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java index 86f889a6e9..1d887232e0 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java @@ -14,13 +14,13 @@ import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; import com.gregtechceu.gtceu.api.gui.widget.NumberInputWidget; import com.gregtechceu.gtceu.api.machine.ConditionalSubscriptionHandler; -import com.gregtechceu.gtceu.api.transfer.fluid.FluidTransferDelegate; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerDelegate; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; import com.gregtechceu.gtceu.api.transfer.fluid.ModifiableFluidHandlerWrapper; import com.gregtechceu.gtceu.common.cover.data.BucketMode; import com.gregtechceu.gtceu.common.cover.data.ManualIOMode; import com.gregtechceu.gtceu.utils.FluidStackHashStrategy; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; @@ -38,7 +38,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.capability.IFluidHandler; import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap; @@ -64,8 +63,6 @@ public class PumpCover extends CoverBehavior implements IUICover, IControllable public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(PumpCover.class, CoverBehavior.MANAGED_FIELD_HOLDER); - protected static final int MILLIBUCKET_SIZE = FluidType.BUCKET_VOLUME / 1000; - public final int tier; public final int maxMilliBucketsPerTick; @@ -128,7 +125,8 @@ protected boolean isSubscriptionActive() { } protected @Nullable IFluidHandler getAdjacentFluidTransfer() { - return GTUtil.getAdjacentFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).resolve() + return GTTransferUtils.getAdjacentFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide) + .resolve() .orElse(null); } @@ -223,8 +221,8 @@ protected void update() { return; if (milliBucketsLeftToTransferLastSecond > 0) { - int platformTransferredFluid = doTransferFluids(milliBucketsLeftToTransferLastSecond * MILLIBUCKET_SIZE); - this.milliBucketsLeftToTransferLastSecond -= platformTransferredFluid / MILLIBUCKET_SIZE; + int platformTransferredFluid = doTransferFluids(milliBucketsLeftToTransferLastSecond); + this.milliBucketsLeftToTransferLastSecond -= platformTransferredFluid; } if (timer % 20 == 0) { @@ -257,7 +255,7 @@ protected int doTransferFluidsInternal(IFluidHandlerModifiable source, IFluidHan protected int transferAny(IFluidHandlerModifiable source, IFluidHandlerModifiable destination, int platformTransferLimit) { - return GTUtil.transferFiltered(source, destination, platformTransferLimit, filterHandler.getFilter()); + return GTTransferUtils.transferFiltered(source, destination, platformTransferLimit, filterHandler.getFilter()); } protected enum TransferDirection { @@ -357,7 +355,7 @@ protected void configureFilter() { // *** CAPABILITY OVERRIDE ***// ///////////////////////////////////// - private CoverableFluidTransferWrapper fluidTransferWrapper; + private CoverableFluidHandlerWrapper fluidTransferWrapper; @Nullable @Override @@ -366,14 +364,14 @@ public IFluidHandlerModifiable getFluidTransferCap(@Nullable IFluidHandlerModifi return null; } if (fluidTransferWrapper == null || fluidTransferWrapper.delegate != defaultValue) { - this.fluidTransferWrapper = new CoverableFluidTransferWrapper(defaultValue); + this.fluidTransferWrapper = new CoverableFluidHandlerWrapper(defaultValue); } return fluidTransferWrapper; } - private class CoverableFluidTransferWrapper extends FluidTransferDelegate { + private class CoverableFluidHandlerWrapper extends FluidHandlerDelegate { - public CoverableFluidTransferWrapper(IFluidHandlerModifiable delegate) { + public CoverableFluidHandlerWrapper(IFluidHandlerModifiable delegate) { super(delegate); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java index ecfeb526ad..029dbdd03e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java @@ -75,7 +75,7 @@ private void voidOverflow(IFluidHandlerModifiable fluidTransfer) { for (FluidStack fluidStack : fluidAmounts.keySet()) { int presentAmount = fluidAmounts.get(fluidStack); - int targetAmount = getFilteredFluidAmount(fluidStack) * MILLIBUCKET_SIZE; + int targetAmount = getFilteredFluidAmount(fluidStack); if (targetAmount <= 0L || targetAmount > presentAmount) continue; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index b81adaba73..b45518ef15 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -9,7 +9,7 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.recipe.*; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java index 055a26058e..fb41594147 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java @@ -1,10 +1,9 @@ package com.gregtechceu.gtceu.common.data; import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import com.gregtechceu.gtceu.syncdata.FluidStackPayload; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.syncdata.GTRecipePayload; -import com.gregtechceu.gtceu.syncdata.FluidStackLoad; -import com.gregtechceu.gtceu.syncdata.GTRecipeAccessor; import com.gregtechceu.gtceu.syncdata.GTRecipeTypeAccessor; import com.gregtechceu.gtceu.syncdata.MaterialPayload; @@ -29,6 +28,6 @@ public static void init() { registerSimple(MaterialPayload.class, MaterialPayload::new, Material.class, 1); registerSimple(GTRecipePayload.class, GTRecipePayload::new, GTRecipe.class, 100); - registerSimple(FluidStackLoad.class, FluidStackLoad::new, FluidStack.class, -1); + registerSimple(FluidStackPayload.class, FluidStackPayload::new, FluidStack.class, -1); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java b/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java index 6fadbaf11c..44da6f5fe3 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/ItemFluidContainer.java @@ -2,11 +2,10 @@ import com.gregtechceu.gtceu.api.item.component.IRecipeRemainder; -import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; - import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidType; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; /** * @author KilaBash @@ -17,16 +16,13 @@ public class ItemFluidContainer implements IRecipeRemainder { @Override public ItemStack getRecipeRemained(ItemStack itemStack) { - var storage = new ItemStackTransfer(itemStack); - var transfer = FluidTransferHelper.getFluidTransfer(storage, 0); - if (transfer != null) { - var drained = transfer.drain(FluidType.BUCKET_VOLUME, true); + return FluidUtil.getFluidHandler(itemStack).map(handler -> { + var drained = handler.drain(FluidType.BUCKET_VOLUME, FluidAction.SIMULATE); if (drained.getAmount() != FluidType.BUCKET_VOLUME) return ItemStack.EMPTY; - transfer.drain(FluidType.BUCKET_VOLUME, false); - var copied = storage.getStackInSlot(0); - copied.setTag(null); - return copied; - } - return storage.getStackInSlot(0); + handler.drain(FluidType.BUCKET_VOLUME, FluidAction.EXECUTE); + var copy = handler.getContainer(); + copy.setTag(null); + return copy; + }).orElse(itemStack); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java index 591882f1ff..11a3ca247c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java @@ -4,6 +4,7 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.UITemplate; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; @@ -12,7 +13,6 @@ import com.gregtechceu.gtceu.api.machine.feature.IMachineLife; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.utils.GTUtil; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java index 43f734257a..aa3633dcbd 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java @@ -15,7 +15,7 @@ import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; import com.gregtechceu.gtceu.api.misc.EnergyContainerList; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.common.item.PortableScannerBehavior; @@ -67,7 +67,7 @@ public class LargeMinerMachine extends WorkableElectricMultiblockMachine @Nullable protected EnergyContainerList energyContainer; @Nullable - protected FluidTransferList inputFluidInventory; + protected FluidHandlerList inputFluidInventory; private final int drillingFluidConsumePerTick; public LargeMinerMachine(IMachineBlockEntity holder, int tier, int speed, int maximumChunkDiameter, int fortune, @@ -145,7 +145,7 @@ private void initializeAbilities() { } } this.energyContainer = new EnergyContainerList(energyContainers); - this.inputFluidInventory = new FluidTransferList(fluidTanks); + this.inputFluidInventory = new FluidHandlerList(fluidTanks); getRecipeLogic().setVoltageTier(GTUtil.getTierByVoltage(this.energyContainer.getInputVoltage())); getRecipeLogic().setOverclockAmount( @@ -177,7 +177,7 @@ public boolean drainInput(boolean simulate) { } // drain fluid - if (inputFluidInventory != null && inputFluidInventory.transfers.length > 0) { + if (inputFluidInventory != null && inputFluidInventory.handlers.length > 0) { FluidStack drillingFluid = DrillingFluid .getFluid(this.drillingFluidConsumePerTick * getRecipeLogic().getOverclockAmount()); FluidStack fluidStack = inputFluidInventory.getFluidInTank(0); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java index 5dfd486534..5130572eac 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/MultiblockTankMachine.java @@ -3,11 +3,11 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.fluids.PropertyFluidFilter; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.feature.IFancyUIMachine; import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockControllerMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; @@ -24,7 +24,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -87,7 +86,7 @@ public Widget createUIWidget() { } private String getFluidLabel() { - return String.valueOf(tank.getFluidInTank(0).getAmount() / (FluidType.BUCKET_VOLUME / 1000)); + return String.valueOf(tank.getFluidInTank(0).getAmount()); } ////////////////////////////////////// diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java index 42df960593..ce93a354b8 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/HPCAMachine.java @@ -17,8 +17,8 @@ import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; import com.gregtechceu.gtceu.api.misc.EnergyContainerList; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.utils.FormattingUtil; @@ -124,7 +124,7 @@ public void onStructureFormed() { } } this.energyContainer = new EnergyContainerList(energyContainers); - this.coolantHandler = new FluidTransferList(coolantContainers); + this.coolantHandler = new FluidHandlerList(coolantContainers); this.hpcaHandler.onStructureForm(componentHatches); if (getLevel() instanceof ServerLevel serverLevel) { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java index 99b7383aa5..51cfa3d317 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/CokeOvenHatch.java @@ -8,7 +8,7 @@ import com.gregtechceu.gtceu.api.machine.trait.FluidTankProxyTrait; import com.gregtechceu.gtceu.api.machine.trait.ItemHandlerProxyTrait; import com.gregtechceu.gtceu.common.machine.multiblock.primitive.CokeOvenMachine; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.side.item.ItemTransferHelper; import com.lowdragmc.lowdraglib.syncdata.ISubscription; @@ -133,7 +133,7 @@ public void onRotated(Direction oldFacing, Direction newFacing) { protected void updateAutoIOSubscription() { if ((!outputInventory.isEmpty() && ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null) || - (!tank.isEmpty() && GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()))) { + (!tank.isEmpty() && GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()))) { autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO); } else if (autoIOSubs != null) { autoIOSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java index 1ab94c63bb..6065f111d5 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java @@ -2,10 +2,10 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; @@ -88,7 +88,7 @@ protected void updateInventorySubscription() { if (level != null) { this.hasItemTransfer = ItemTransferHelper.getItemTransfer( level, getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null; - this.hasFluidTransfer = GTUtil.isAdjacentFluidHandler(level, getPos(), getFrontFacing()); + this.hasFluidTransfer = GTTransferUtils.hasAdjacentFluidHandler(level, getPos(), getFrontFacing()); } else { this.hasItemTransfer = false; this.hasFluidTransfer = false; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java index e6904fdc85..48e9d5a412 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java @@ -3,6 +3,8 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.fancy.ConfiguratorPanel; +import com.gregtechceu.gtceu.api.gui.widget.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.TickableSubscription; @@ -11,11 +13,9 @@ import com.gregtechceu.gtceu.api.machine.multiblock.part.TieredIOPartMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; -import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.item.IntCircuitBehaviour; import com.gregtechceu.gtceu.config.ConfigHolder; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; @@ -145,7 +145,7 @@ public void onRotated(Direction oldFacing, Direction newFacing) { protected void updateTankSubscription() { if (isWorkingEnabled() && ((io == IO.OUT && !tank.isEmpty()) || io == IO.IN) && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing())) { + GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing())) { autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO); } else if (autoIOSubs != null) { autoIOSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java index 0fd1285345..aca80322d3 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/PumpHatchPartMachine.java @@ -3,10 +3,10 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.UITemplate; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java index cc416dd4ec..fb1718e85f 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/SteamHatchPartMachine.java @@ -3,9 +3,9 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.UITemplate; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java index 468eaad41d..e81366ea0d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/TankValvePartMachine.java @@ -7,7 +7,7 @@ import com.gregtechceu.gtceu.api.machine.multiblock.part.MultiblockPartMachine; import com.gregtechceu.gtceu.api.machine.trait.FluidTankProxyTrait; import com.gregtechceu.gtceu.common.machine.multiblock.electric.MultiblockTankMachine; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.syncdata.ISubscription; @@ -91,7 +91,7 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { @Nullable private IFluidHandler getTargetTank() { - return GTUtil.getAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()).resolve().orElse(null); + return GTTransferUtils.getAdjacentFluidHandler(getLevel(), getPos(), getFrontFacing()).resolve().orElse(null); } private void autoIO() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java index 7dab6c97da..bb26ea318e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/primitive/CokeOvenMachine.java @@ -3,9 +3,9 @@ import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.UITemplate; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.feature.IUIMachine; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java index 48f6840a2e..2f94299bc1 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamLiquidBoilerMachine.java @@ -3,10 +3,10 @@ import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability; import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.steam.SteamBoilerMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java index 1ade70c86d..b7cc692f94 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamMinerMachine.java @@ -74,7 +74,7 @@ public class SteamMinerMachine extends SteamWorkableMachine implements IMiner, I public SteamMinerMachine(IMachineBlockEntity holder, int speed, int maximumRadius, int fortune) { super(holder, false, fortune, speed, maximumRadius); this.inventorySize = 4; - this.energyPerTick = (int) (16 * FluidType.BUCKET_VOLUME / 1000); + this.energyPerTick = 16; this.importItems = createImportItemHandler(); this.exportItems = createExportItemHandler(); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java index 0b1c6ca18c..3786607680 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/BufferMachine.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.MetaMachine; @@ -12,8 +13,7 @@ import com.gregtechceu.gtceu.api.machine.feature.IMachineLife; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; @@ -191,7 +191,7 @@ protected void updateAutoOutputSubscription() { ItemTransferHelper.getItemTransfer(getLevel(), getPos().relative(outputFacingItems), outputFacingItems.getOpposite()) != null || (isAutoOutputFluids() && !tank.isEmpty()) && outputFacingFluids != null && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { + GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), outputFacingFluids)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::autoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java index 439afbdd73..d25b412a16 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java @@ -3,10 +3,10 @@ import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.PhantomFluidWidget; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup; import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java index 708c737327..cdb4a9b4f0 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/DrumMachine.java @@ -12,7 +12,7 @@ import com.gregtechceu.gtceu.api.machine.feature.IDropSaveMachine; import com.gregtechceu.gtceu.api.machine.feature.IInteractedMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; import com.lowdragmc.lowdraglib.syncdata.ISubscription; @@ -178,7 +178,7 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { + GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java index f825e57e26..ae31c03d89 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java @@ -3,6 +3,8 @@ import com.gregtechceu.gtceu.api.capability.IControllable; import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.PhantomFluidWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; @@ -14,9 +16,7 @@ import com.gregtechceu.gtceu.api.machine.feature.IFancyUIMachine; import com.gregtechceu.gtceu.api.machine.feature.IInteractedMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.misc.lib.PhantomFluidWidget; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import com.lowdragmc.lowdraglib.gui.editor.ColorPattern; import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture; @@ -44,7 +44,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.FluidUtil; import com.mojang.blaze3d.MethodsReturnNonnullByDefault; @@ -200,7 +199,7 @@ public void onNeighborChanged(Block block, BlockPos fromPos, boolean isMoving) { protected void updateAutoOutputSubscription() { var outputFacing = getOutputFacingFluids(); if ((isAutoOutputFluids() && !cache.isEmpty()) && outputFacing != null && - GTUtil.isAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { + GTTransferUtils.hasAdjacentFluidHandler(getLevel(), getPos(), outputFacing)) { autoOutputSubs = subscribeServerTick(autoOutputSubs, this::checkAutoOutput); } else if (autoOutputSubs != null) { autoOutputSubs.unsubscribe(); @@ -300,7 +299,7 @@ public Widget createUIWidget() { group.addWidget(new ImageWidget(4, 4, 82, 55, GuiTextures.DISPLAY)) .addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount")) .addWidget(new LabelWidget(8, 18, - () -> String.valueOf(cache.getFluidInTank(0).getAmount() / (FluidType.BUCKET_VOLUME / 1000))) + () -> String.valueOf(cache.getFluidInTank(0).getAmount())) .setTextColor(-1).setDropShadow(true)) .addWidget(new TankWidget(cache.getStorages()[0], 68, 23, true, true) .setBackground(GuiTextures.FLUID_SLOT)) diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java index cec85a02a8..488fe27dcb 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/trait/FluidDrillLogic.java @@ -14,7 +14,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.material.Fluid; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -106,7 +105,7 @@ private int getFluidToProduce(FluidVeinWorldEntry entry) { if (isOverclocked()) { produced = produced * 3 / 2; } - return produced * FluidType.BUCKET_VOLUME / 1000; + return produced; } return 0; } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java index 54f6c6f11b..9def851969 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTOreByProductWidget.java @@ -2,10 +2,10 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.api.misc.lib.TagOrCycleFluidTransfer; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.TagOrCycleFluidHandler; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.widget.ImageWidget; @@ -160,7 +160,7 @@ public void setRecipe(GTOreByProduct recipeWrapper) { } List, Integer>>, List>> fluidInputs = recipeWrapper.fluidInputs; - TagOrCycleFluidTransfer fluidInputsHandler = new TagOrCycleFluidTransfer(fluidInputs); + TagOrCycleFluidHandler fluidInputsHandler = new TagOrCycleFluidHandler(fluidInputs); WidgetGroup fluidStackGroup = new WidgetGroup(); for (int i = 0; i < FLUID_LOCATIONS.size(); i += 2) { int slotIndex = i / 2; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java index 7e780055bd..a2ba9751ad 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTOreVeinWidget.java @@ -6,7 +6,7 @@ import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; -import com.gregtechceu.gtceu.api.misc.lib.TankWidget; +import com.gregtechceu.gtceu.api.gui.widget.TankWidget; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; import com.gregtechceu.gtceu.client.ClientProxy; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java index d8b67c460e..57dea56768 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java @@ -15,7 +15,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.TooltipFlag; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidType; import appeng.api.stacks.AEFluidKey; import appeng.api.stacks.GenericStack; @@ -75,10 +74,10 @@ public void drawInForeground(@NotNull GuiGraphics graphics, int mouseX, int mous new FluidStack(key.getFluid(), (int) fluid.amount(), key.getTag()) : FluidStack.EMPTY; List tooltips = new ArrayList<>(); tooltips.add(fluidStack.getDisplayName()); - tooltips.add(Component.literal(String.format("%,d ", fluid.amount())).append("mB")); + tooltips.add(Component.literal(String.format("%,d mB", fluid.amount()))); if (!Platform.isForge()) { tooltips.add(Component.literal( - "§6mB:§r %d mB".formatted(fluidStack.getAmount() * 1000 / FluidType.BUCKET_VOLUME))); + "§6mB:§r %d mB".formatted(fluidStack.getAmount()))); } TooltipsHandler.appendFluidTooltips(fluidStack.getFluid(), fluidStack.getAmount(), tooltips::add, TooltipFlag.NORMAL); diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java similarity index 91% rename from src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java rename to src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java index 7540b3a0e3..062fa409f1 100644 --- a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackLoad.java +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable; -public class FluidStackLoad extends ObjectTypedPayload { +public class FluidStackPayload extends ObjectTypedPayload { @Override public void writePayload(FriendlyByteBuf buf) { diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java index 1826660aca..274fccc70a 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java @@ -2,14 +2,19 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import com.lowdragmc.lowdraglib.misc.ItemHandlerHelper; import com.lowdragmc.lowdraglib.misc.ItemTransferList; import com.lowdragmc.lowdraglib.side.item.IItemTransfer; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; @@ -21,8 +26,27 @@ import java.util.List; import java.util.function.Predicate; +import javax.annotation.Nonnull; + public class GTTransferUtils { + /** + * Gets the FluidHandler from the adjacent block on the side connected to the caller + * + * @param level Level + * @param pos BlockPos of the machine which is calling + * @param facing Direction to get the FluidHandler from + * @return LazyOpt of the IFluidHandler described above + */ + public static LazyOptional getAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { + return FluidUtil.getFluidHandler(level, pos.relative(facing), facing.getOpposite()); + } + + // Same as above, but returns the presence + public static boolean hasAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { + return getAdjacentFluidHandler(level, pos, facing).isPresent(); + } + public static int transferFluids(@NotNull IFluidHandler sourceHandler, @NotNull IFluidHandler destHandler) { return transferFluids(sourceHandler, destHandler, Integer.MAX_VALUE, fluidStack -> true); } @@ -84,6 +108,38 @@ public static boolean transferExactFluidStack(@NotNull IFluidHandler sourceHandl return false; } + // TODO: Clean this up to use FluidUtil and move it back to caller + public static int transferFiltered(@Nonnull IFluidHandler sourceHandler, @Nonnull IFluidHandler destHandler, + int transferLimit, @Nonnull Predicate fluidFilter) { + int fluidLeftToTransfer = transferLimit; + for (int i = 0; i < sourceHandler.getTanks(); i++) { + FluidStack currentFluid = sourceHandler.getFluidInTank(i).copy(); + if (currentFluid.isEmpty() || !fluidFilter.test(currentFluid)) { + continue; + } + + currentFluid.setAmount(fluidLeftToTransfer); + var drained = sourceHandler.drain(currentFluid, FluidAction.SIMULATE); + if (drained.isEmpty()) { + continue; + } + + var canInsertAmount = destHandler.fill(drained.copy(), FluidAction.SIMULATE); + if (canInsertAmount > 0) { + drained.setAmount(canInsertAmount); + drained = sourceHandler.drain(drained, FluidAction.EXECUTE); + if (!drained.isEmpty()) { + destHandler.fill(drained, FluidAction.EXECUTE); + fluidLeftToTransfer -= drained.getAmount(); + if (fluidLeftToTransfer == 0) { + break; + } + } + } + } + return transferLimit - fluidLeftToTransfer; + } + public static void moveInventoryItems(IItemTransfer sourceInventory, IItemTransfer targetInventory) { for (int srcIndex = 0; srcIndex < sourceInventory.getSlots(); srcIndex++) { ItemStack sourceStack = sourceInventory.extractItem(srcIndex, Integer.MAX_VALUE, true); @@ -150,7 +206,7 @@ public static boolean addItemsToItemHandler(final IItemTransfer handler, * @param fluidStacks the items to insert into {@code fluidHandler}. * @return {@code true} if the insertion succeeded, {@code false} otherwise. */ - public static boolean addFluidsToFluidHandler(FluidTransferList fluidHandler, + public static boolean addFluidsToFluidHandler(FluidHandlerList fluidHandler, boolean simulate, List fluidStacks) { if (simulate) { @@ -172,9 +228,9 @@ public static boolean addFluidsToFluidHandler(FluidTransferList fluidHandler, public static int fillFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, FluidAction action) { if (stack.isEmpty()) return 0; - if (handler instanceof FluidTransferList handlerList) { + if (handler instanceof FluidHandlerList handlerList) { var copied = stack.copy(); - for (var transfer : handlerList.transfers) { + for (var transfer : handlerList.handlers) { var candidate = copied.copy(); if (transfer instanceof NotifiableFluidTank notifiable) { copied.shrink(notifiable.fillInternal(candidate, action)); @@ -191,9 +247,9 @@ public static int fillFluidAccountNotifiableList(IFluidHandler handler, FluidSta public static FluidStack drainFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, FluidAction action) { if (stack.isEmpty()) return FluidStack.EMPTY; - if (handler instanceof FluidTransferList handlerList) { + if (handler instanceof FluidHandlerList handlerList) { var copied = stack.copy(); - for (var transfer : handlerList.transfers) { + for (var transfer : handlerList.handlers) { var candidate = copied.copy(); if (transfer instanceof NotifiableFluidTank notifiable) { copied.shrink(notifiable.drainInternal(candidate, action).getAmount()); diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java index 94b098276d..bd81a72673 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java @@ -37,7 +37,6 @@ import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.Tags; -import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.FluidUtil; @@ -56,9 +55,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.function.Predicate; - -import javax.annotation.Nonnull; import static com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey.HAZARD; @@ -431,59 +427,10 @@ public static FluidStack getFluidFromContainer(Object ingredient) { return null; } - /** - * Gets the FluidHandler from the adjacent block on the side connected to the caller - * - * @param level Level - * @param pos BlockPos of the machine which is calling - * @param facing Direction to get the FluidHandler from - * @return LazyOpt of the IFluidHandler described above - */ - public static LazyOptional getAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { - return FluidUtil.getFluidHandler(level, pos.relative(facing), facing.getOpposite()); - } - - // Same as above, but returns the presence - public static boolean isAdjacentFluidHandler(Level level, BlockPos pos, Direction facing) { - return getAdjacentFluidHandler(level, pos, facing).isPresent(); - } - public static int getFluidColor(FluidStack fluid) { return IClientFluidTypeExtensions.of(fluid.getFluid()).getTintColor(fluid); } - // TODO: Clean this up to use FluidUtil and move it back to caller - public static int transferFiltered(@Nonnull IFluidHandler sourceHandler, @Nonnull IFluidHandler destHandler, - int transferLimit, @Nonnull Predicate fluidFilter) { - int fluidLeftToTransfer = transferLimit; - for (int i = 0; i < sourceHandler.getTanks(); i++) { - FluidStack currentFluid = sourceHandler.getFluidInTank(i).copy(); - if (currentFluid.isEmpty() || !fluidFilter.test(currentFluid)) { - continue; - } - - currentFluid.setAmount(fluidLeftToTransfer); - var drained = sourceHandler.drain(currentFluid, IFluidHandler.FluidAction.SIMULATE); - if (drained.isEmpty()) { - continue; - } - - var canInsertAmount = destHandler.fill(drained.copy(), IFluidHandler.FluidAction.SIMULATE); - if (canInsertAmount > 0) { - drained.setAmount(canInsertAmount); - drained = sourceHandler.drain(drained, IFluidHandler.FluidAction.EXECUTE); - if (!drained.isEmpty()) { - destHandler.fill(drained, IFluidHandler.FluidAction.EXECUTE); - fluidLeftToTransfer -= drained.getAmount(); - if (fluidLeftToTransfer == 0) { - break; - } - } - } - } - return transferLimit - fluidLeftToTransfer; - } - public static boolean canSeeSunClearly(Level world, BlockPos blockPos) { if (!world.canSeeSky(blockPos.above())) { return false; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java b/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java index 4db3d80bd1..e590a471a3 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/OverlayedFluidHandler.java @@ -1,7 +1,7 @@ package com.gregtechceu.gtceu.utils; -import com.gregtechceu.gtceu.api.misc.lib.FluidTransferList; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerList; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; @@ -19,7 +19,7 @@ public class OverlayedFluidHandler { private final List overlayedTanks; - public OverlayedFluidHandler(@NotNull FluidTransferList tank) { + public OverlayedFluidHandler(@NotNull FluidHandlerList tank) { this.overlayedTanks = new ArrayList<>(); FluidStack[] entries = IntStream.range(0, tank.getTanks()).mapToObj(tank::getFluidInTank) .toArray(FluidStack[]::new); From 497f58847349f980a3bc36a6098f99bd8cef1c24 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:05:50 -0400 Subject: [PATCH 10/22] Update LDLib overrides Also clean up some lingering references --- .../gtceu/api/gui/misc/IGhostFluidTarget.java | 2 +- .../api/gui/widget/PhantomFluidWidget.java | 22 ------------------- .../gtceu/api/gui/widget/TankWidget.java | 20 ++++------------- .../steam/SteamSolidBoilerMachine.java | 4 ++-- .../pipelike/fluidpipe/PipeNetRoutePath.java | 11 +++++----- 5 files changed, 12 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java index baeaaeb6f0..b208a0f118 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/misc/IGhostFluidTarget.java @@ -72,7 +72,7 @@ default Object convertIngredient(Object ingredient) { } if (LDLib.isJeiLoaded() && ingredient instanceof net.minecraftforge.fluids.FluidStack fluidStack) { - ingredient = FluidStack.create(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getTag()); + ingredient = new FluidStack(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getTag()); } return ingredient; } diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java index ff507739e1..35b5090ff9 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java @@ -89,16 +89,6 @@ public static FluidStack drainFrom(Object ingredient) { if (ingredient instanceof ItemStack itemStack) { var handler = FluidUtil.getFluidHandler(itemStack); return handler.map(h -> h.drain(Integer.MAX_VALUE, FluidAction.SIMULATE)).orElse(FluidStack.EMPTY); - // var stack = new ItemStackHandler(NonNullList.of(ItemStack.EMPTY, itemStack)).getStackInSlot(0); - // if(!stack.isEmpty()) { - // var h = stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).resolve(); - // if(h.isPresent()) return h.get().drain(Integer.MAX_VALUE, FluidAction.SIMULATE); - // } - // var handler = FluidTransferHelper.getFluidTransfer(new ItemStackHandler(NonNullList.of(ItemStack.EMPTY, - // itemStack)), 0); - // if (handler != null) { - // return handler.drain(Integer.MAX_VALUE, FluidAction.SIMULATE); - // } } return FluidStack.EMPTY; } @@ -208,18 +198,6 @@ private void handlePhantomClick() { var stack = FluidUtil.getFluidHandler(gui.getModularUIContainer().getCarried()) .map(h -> h.drain(Integer.MAX_VALUE, FluidAction.EXECUTE)).orElse(FluidStack.EMPTY); if (phantomFluidSetter != null) phantomFluidSetter.accept(stack); - // var handler = FluidUtil.getFluidHandler(gui.getModularUIContainer().getCarried()).resolve(); - // if(handler.isPresent()) { - // FluidStack result = handler.get().drain(Integer.MAX_VALUE, FluidAction.EXECUTE); - // if(phantomFluidSetter != null) phantomFluidSetter.accept(result); - // } - // var handler = FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()); - // if (handler != null) { - // FluidStack resultFluid = handler.drain(Integer.MAX_VALUE, FluidAction.EXECUTE); - // if (phantomFluidSetter != null) { - // phantomFluidSetter.accept(resultFluid); - // } - // } } else { if (phantomFluidSetter != null) { phantomFluidSetter.accept(FluidStack.EMPTY); diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java index 9c0bd5cfe7..d853cf230e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java @@ -19,8 +19,6 @@ import com.lowdragmc.lowdraglib.jei.ClickableIngredient; import com.lowdragmc.lowdraglib.jei.IngredientIO; import com.lowdragmc.lowdraglib.jei.JEIPlugin; -import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import com.lowdragmc.lowdraglib.utils.CycleFluidTransfer; import com.lowdragmc.lowdraglib.utils.Position; @@ -253,7 +251,7 @@ public List getXEIIngredients() { } private List getXEIIngredientsFromCycleTransfer(CycleFluidTransfer transfer, int index) { - var stream = transfer.getStackList(index).stream().map(FluidHelper::toRealFluidStack) + var stream = transfer.getStackList(index).stream().map(FluidHelperImpl::toRealFluidStack) .map(FluidStack.class::cast); if (LDLib.isJeiLoaded()) { return stream.filter(fluid -> !fluid.isEmpty()).map(JEICallWrapper::getPlatformFluidTypeForJEI).toList(); @@ -266,7 +264,7 @@ private List getXEIIngredientsFromCycleTransfer(CycleFluidTransfer trans } private List getXEIIngredientsFromCycleTransferClickable(CycleFluidTransfer transfer, int index) { - var stream = transfer.getStackList(index).stream().map(FluidHelper::toRealFluidStack) + var stream = transfer.getStackList(index).stream().map(FluidHelperImpl::toRealFluidStack) .map(FluidStack.class::cast); if (LDLib.isJeiLoaded()) { return stream @@ -376,16 +374,6 @@ private List getToolTips(List list) { return list; } - @Override - public void addTooltipCallback(Consumer> callback) { - this.tooltipCallback.add(callback); - } - - @Override - public void clearTooltipCallback() { - this.tooltipCallback.clear(); - } - @Override @OnlyIn(Dist.CLIENT) public void drawInBackground(@Nonnull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { @@ -570,7 +558,7 @@ private int tryClickContainer(boolean isShiftKeyDown) { if (fluidTank == null) return -1; Player player = gui.entityPlayer; ItemStack currentStack = gui.getModularUIContainer().getCarried(); - var handler = FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()); + var handler = FluidUtil.getFluidHandler(currentStack).resolve().orElse(null); if (handler == null) return -1; int maxAttempts = isShiftKeyDown ? currentStack.getCount() : 1; FluidStack initialFluid = fluidTank.getFluidInTank(tank); @@ -636,7 +624,7 @@ private int tryClickContainer(boolean isShiftKeyDown) { public boolean mouseClicked(double mouseX, double mouseY, int button) { if ((allowClickDrained || allowClickFilled) && isMouseOverElement(mouseX, mouseY)) { if (button == 0) { - if (FluidTransferHelper.getFluidTransfer(gui.entityPlayer, gui.getModularUIContainer()) != null) { + if (FluidUtil.getFluidHandler(gui.getModularUIContainer().getCarried()).isPresent()) { boolean isShiftKeyDown = isShiftDown(); writeClientAction(1, writer -> writer.writeBoolean(isShiftKeyDown)); playButtonClickSound(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamSolidBoilerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamSolidBoilerMachine.java index 392f3d700c..a5acbd8293 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamSolidBoilerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/steam/SteamSolidBoilerMachine.java @@ -18,7 +18,6 @@ import com.lowdragmc.lowdraglib.gui.texture.ProgressTexture; import com.lowdragmc.lowdraglib.gui.widget.ProgressWidget; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; @@ -26,6 +25,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fluids.FluidUtil; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; @@ -54,7 +54,7 @@ public class SteamSolidBoilerMachine extends SteamBoilerMachine implements IMach public SteamSolidBoilerMachine(IMachineBlockEntity holder, boolean isHighPressure, Object... args) { super(holder, isHighPressure, args); this.fuelHandler = createFuelHandler(args).setFilter(itemStack -> { - if (FluidTransferHelper.getFluidContained(itemStack) != null) { + if (FluidUtil.getFluidContained(itemStack).isPresent()) { return false; } return FUEL_CACHE.computeIfAbsent(itemStack.getItem(), item -> { diff --git a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeNetRoutePath.java b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeNetRoutePath.java index 1777dfdf63..89d94566d4 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeNetRoutePath.java +++ b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/PipeNetRoutePath.java @@ -1,20 +1,19 @@ package com.gregtechceu.gtceu.common.pipelike.fluidpipe; import com.gregtechceu.gtceu.api.pipenet.IRoutePath; - -import com.lowdragmc.lowdraglib.side.fluid.FluidTransferHelper; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import com.gregtechceu.gtceu.utils.GTTransferUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; +import net.minecraftforge.fluids.capability.IFluidHandler; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import oshi.util.tuples.Pair; -public class PipeNetRoutePath implements IRoutePath { +public class PipeNetRoutePath implements IRoutePath { @Getter private final BlockPos pipePos; @@ -43,7 +42,7 @@ public BlockPos getTargetPipePos() { } @Nullable - public IFluidTransfer getHandler(Level world) { - return FluidTransferHelper.getFluidTransfer(world, getTargetPipePos(), targetFacing.getOpposite()); + public IFluidHandler getHandler(Level world) { + return GTTransferUtils.getAdjacentFluidHandler(world, pipePos, targetFacing).resolve().orElse(null); } } From 8db32568483256cbb36c1627a61636bff7a4cdf5 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:53:04 -0400 Subject: [PATCH 11/22] spotless --- .../gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java index fb41594147..0216883d2e 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTSyncedFieldAccessors.java @@ -1,8 +1,8 @@ package com.gregtechceu.gtceu.common.data; import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import com.gregtechceu.gtceu.syncdata.FluidStackPayload; import com.gregtechceu.gtceu.api.recipe.GTRecipe; +import com.gregtechceu.gtceu.syncdata.FluidStackPayload; import com.gregtechceu.gtceu.syncdata.GTRecipePayload; import com.gregtechceu.gtceu.syncdata.GTRecipeTypeAccessor; import com.gregtechceu.gtceu.syncdata.MaterialPayload; From 201cbe954d8456f3e281b0d4ae86c4f5ef8df03b Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:30:31 -0400 Subject: [PATCH 12/22] Error handling for old LDLib tags --- .../gtceu/syncdata/FluidStackPayload.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java index 062fa409f1..1d25d8976c 100644 --- a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java @@ -1,5 +1,8 @@ package com.gregtechceu.gtceu.syncdata; +import com.gregtechceu.gtceu.GTCEu; + +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import com.lowdragmc.lowdraglib.syncdata.payload.ObjectTypedPayload; import net.minecraft.nbt.CompoundTag; @@ -29,6 +32,14 @@ public Tag serializeNBT() { @Override public void deserializeNBT(Tag tag) { - payload = FluidStack.loadFluidStackFromNBT((CompoundTag) tag); + try { + payload = FluidStack.loadFluidStackFromNBT((CompoundTag) tag); + } catch (ClassCastException exception) { + // LDLib FluidStack stores amount as Long tag, which will throw an error + // Loads from tag using LDLib FluidStack, then converts it to a Forge FluidStack + GTCEu.LOGGER.warn("Old FluidStack Tag Detected"); + var stack = com.lowdragmc.lowdraglib.side.fluid.FluidStack.loadFromTag((CompoundTag) tag); + payload = FluidHelperImpl.toFluidStack(stack); + } } } From 5df122e5abcc571b50fa3e3c82ef0dfd4618ab8a Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:17:54 -0400 Subject: [PATCH 13/22] Remove warning --- .../java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java index 1d25d8976c..7fadc9ea22 100644 --- a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java @@ -37,7 +37,6 @@ public void deserializeNBT(Tag tag) { } catch (ClassCastException exception) { // LDLib FluidStack stores amount as Long tag, which will throw an error // Loads from tag using LDLib FluidStack, then converts it to a Forge FluidStack - GTCEu.LOGGER.warn("Old FluidStack Tag Detected"); var stack = com.lowdragmc.lowdraglib.side.fluid.FluidStack.loadFromTag((CompoundTag) tag); payload = FluidHelperImpl.toFluidStack(stack); } From c11ecedf7e94f6e73706aef86b3454bc226883c8 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:15:36 -0400 Subject: [PATCH 14/22] lesspot --- .../java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java index 7fadc9ea22..adeeaab339 100644 --- a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java @@ -1,7 +1,5 @@ package com.gregtechceu.gtceu.syncdata; -import com.gregtechceu.gtceu.GTCEu; - import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import com.lowdragmc.lowdraglib.syncdata.payload.ObjectTypedPayload; From b8b8c0a1724d7509c8cd02c2516e9025e1604b7e Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:41:05 -0400 Subject: [PATCH 15/22] Remove references to Transfer --- .../blockentity/MetaMachineBlockEntity.java | 6 +- .../gtceu/api/capability/ICoverable.java | 2 +- .../gtceu/api/cover/CoverBehavior.java | 2 +- .../gtceu/api/gui/widget/TankWidget.java | 36 ++-- .../api/machine/MachineCoverContainer.java | 4 +- .../gtceu/api/machine/MetaMachine.java | 4 +- .../gtceu/api/pipenet/PipeCoverContainer.java | 2 +- .../api/transfer/fluid/CycleFluidHandler.java | 81 +++++++++ .../fluid/InfiniteFluidHandlerProxy.java | 39 ----- .../api/transfer/fluid/NoOpFluidTransfer.java | 56 ------ .../blockentity/FluidPipeBlockEntity.java | 2 +- .../gtceu/common/cover/PumpCover.java | 44 ++--- .../detector/AdvancedFluidDetectorCover.java | 2 +- .../cover/detector/FluidDetectorCover.java | 6 +- .../voiding/AdvancedFluidVoidingCover.java | 14 +- .../cover/voiding/FluidVoidingCover.java | 12 +- .../item/tool/behavior/PlungerBehavior.java | 2 +- .../electric/LargeMinerMachine.java | 4 +- .../multiblock/part/DualHatchPartMachine.java | 12 +- .../fluidpipe/FluidTransferHandler.java | 161 ------------------ .../gtceu/utils/OverlayingFluidStorage.java | 22 +-- 21 files changed, 168 insertions(+), 345 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CycleFluidHandler.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidTransferHandler.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java index 4b1ed0563a..dbca08e4de 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/api/blockentity/MetaMachineBlockEntity.java @@ -223,10 +223,10 @@ public static LazyOptional getCapability(MetaMachine machine, @NotNull Ca return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, LazyOptional.of(h::get)); } } - var transfer = machine.getFluidTransferCap(side, true); - if (transfer != null) { + var handler = machine.getFluidHandlerCap(side, true); + if (handler != null) { return ForgeCapabilities.FLUID_HANDLER.orEmpty(cap, - LazyOptional.of(() -> transfer)); + LazyOptional.of(() -> handler)); } } else if (cap == ForgeCapabilities.ENERGY) { if (machine instanceof IEnergyStorage energyStorage) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java b/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java index 5ebc0eddcc..bc82c5b680 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java +++ b/src/main/java/com/gregtechceu/gtceu/api/capability/ICoverable.java @@ -61,7 +61,7 @@ public interface ICoverable extends ITickSubscription, IAppearance { IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCoverCapability); - IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability); + IFluidHandlerModifiable getFluidHandlerCap(@Nullable Direction side, boolean useCoverCapability); /** * Its an internal method, you should never call it yourself. diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java b/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java index ba81026bee..f2c252801d 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/CoverBehavior.java @@ -217,7 +217,7 @@ public IItemTransfer getItemTransferCap(IItemTransfer defaultValue) { } @Nullable - public IFluidHandlerModifiable getFluidTransferCap(IFluidHandlerModifiable defaultValue) { + public IFluidHandlerModifiable getFluidHandlerCap(IFluidHandlerModifiable defaultValue) { return defaultValue; } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java index d853cf230e..c36e74fb54 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.api.gui.widget; +import com.gregtechceu.gtceu.api.transfer.fluid.CycleFluidHandler; import com.gregtechceu.gtceu.api.transfer.fluid.TagOrCycleFluidHandler; import com.lowdragmc.lowdraglib.LDLib; @@ -20,7 +21,6 @@ import com.lowdragmc.lowdraglib.jei.IngredientIO; import com.lowdragmc.lowdraglib.jei.JEIPlugin; import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; -import com.lowdragmc.lowdraglib.utils.CycleFluidTransfer; import com.lowdragmc.lowdraglib.utils.Position; import com.lowdragmc.lowdraglib.utils.Size; @@ -203,10 +203,10 @@ public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { if (self().isMouseOverElement(mouseX, mouseY)) { if (lastFluidInTank == null || lastFluidInTank.isEmpty()) return null; - if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { - return getXEIIngredientsFromCycleTransferClickable(cycleItemStackHandler, tank).get(0); - } else if (this.fluidTank instanceof TagOrCycleFluidHandler transfer) { - return getXEIIngredientsFromTagOrCycleTransferClickable(transfer, tank).get(0); + if (this.fluidTank instanceof CycleFluidHandler cycleFluidHandler) { + return getXEIIngredientsFromCycleHandlerClickable(cycleFluidHandler, tank).get(0); + } else if (this.fluidTank instanceof TagOrCycleFluidHandler tagOrCycleFluidHandler) { + return getXEIIngredientsFromTagOrCycleHandlerClickable(tagOrCycleFluidHandler, tank).get(0); } if (LDLib.isJeiLoaded()) { @@ -229,10 +229,10 @@ public Object getXEIIngredientOverMouse(double mouseX, double mouseY) { public List getXEIIngredients() { if (lastFluidInTank == null || lastFluidInTank.isEmpty()) return Collections.emptyList(); - if (this.fluidTank instanceof CycleFluidTransfer cycleItemStackHandler) { - return getXEIIngredientsFromCycleTransfer(cycleItemStackHandler, tank); - } else if (this.fluidTank instanceof TagOrCycleFluidHandler transfer) { - return getXEIIngredientsFromTagOrCycleTransfer(transfer, tank); + if (this.fluidTank instanceof CycleFluidHandler cycleFluidHandler) { + return getXEIIngredientsFromCycleHandler(cycleFluidHandler, tank); + } else if (this.fluidTank instanceof TagOrCycleFluidHandler tagOrCycleFluidHandler) { + return getXEIIngredientsFromTagOrCycleHandler(tagOrCycleFluidHandler, tank); } if (LDLib.isJeiLoaded()) { @@ -250,9 +250,8 @@ public List getXEIIngredients() { return List.of(lastFluidInTank); } - private List getXEIIngredientsFromCycleTransfer(CycleFluidTransfer transfer, int index) { - var stream = transfer.getStackList(index).stream().map(FluidHelperImpl::toRealFluidStack) - .map(FluidStack.class::cast); + private List getXEIIngredientsFromCycleHandler(CycleFluidHandler handler, int index) { + var stream = handler.getStackList(index).stream(); if (LDLib.isJeiLoaded()) { return stream.filter(fluid -> !fluid.isEmpty()).map(JEICallWrapper::getPlatformFluidTypeForJEI).toList(); } else if (LDLib.isReiLoaded()) { @@ -263,9 +262,8 @@ private List getXEIIngredientsFromCycleTransfer(CycleFluidTransfer trans return Collections.emptyList(); } - private List getXEIIngredientsFromCycleTransferClickable(CycleFluidTransfer transfer, int index) { - var stream = transfer.getStackList(index).stream().map(FluidHelperImpl::toRealFluidStack) - .map(FluidStack.class::cast); + private List getXEIIngredientsFromCycleHandlerClickable(CycleFluidHandler handler, int index) { + var stream = handler.getStackList(index).stream(); if (LDLib.isJeiLoaded()) { return stream .filter(fluid -> !fluid.isEmpty()) @@ -279,8 +277,8 @@ private List getXEIIngredientsFromCycleTransferClickable(CycleFluidTrans return Collections.emptyList(); } - private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidHandler transfer, int index) { - Either, Integer>>, List> either = transfer + private List getXEIIngredientsFromTagOrCycleHandler(TagOrCycleFluidHandler handler, int index) { + Either, Integer>>, List> either = handler .getStacks() .get(index); var ref = new Object() { @@ -316,8 +314,8 @@ private List getXEIIngredientsFromTagOrCycleTransfer(TagOrCycleFluidHand return ref.returnValue; } - private List getXEIIngredientsFromTagOrCycleTransferClickable(TagOrCycleFluidHandler transfer, int index) { - Either, Integer>>, List> either = transfer + private List getXEIIngredientsFromTagOrCycleHandlerClickable(TagOrCycleFluidHandler handler, int index) { + Either, Integer>>, List> either = handler .getStacks() .get(index); var ref = new Object() { diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java index c68e259712..7996477324 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java @@ -185,8 +185,8 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Override - public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { - return machine.getFluidTransferCap(side, useCoverCapability); + public IFluidHandlerModifiable getFluidHandlerCap(@Nullable Direction side, boolean useCoverCapability) { + return machine.getFluidHandlerCap(side, useCoverCapability); } @SuppressWarnings("unused") diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java index 4380abd2fb..8df0ce3afa 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java @@ -690,7 +690,7 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Nullable - public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidHandlerCap(@Nullable Direction side, boolean useCoverCapability) { var list = getTraits().stream() .filter(IFluidHandler.class::isInstance) .filter(t -> t.hasCapability(side)) @@ -709,7 +709,7 @@ public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boo if (!useCoverCapability || side == null) return transferList; CoverBehavior cover = getCoverContainer().getCoverAtSide(side); - return cover != null ? cover.getFluidTransferCap(transferList) : transferList; + return cover != null ? cover.getFluidHandlerCap(transferList) : transferList; } ////////////////////////////////////// diff --git a/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java b/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java index 814e4dd300..d39a7d258e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java +++ b/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java @@ -164,7 +164,7 @@ public IItemTransfer getItemTransferCap(@Nullable Direction side, boolean useCov } @Override - public IFluidHandlerModifiable getFluidTransferCap(@Nullable Direction side, boolean useCoverCapability) { + public IFluidHandlerModifiable getFluidHandlerCap(@Nullable Direction side, boolean useCoverCapability) { if (pipeTile instanceof FluidPipeBlockEntity fluidPipe) { return fluidPipe.getTankList(side); } else { diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CycleFluidHandler.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CycleFluidHandler.java new file mode 100644 index 0000000000..abb57b44ff --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/CycleFluidHandler.java @@ -0,0 +1,81 @@ +package com.gregtechceu.gtceu.api.transfer.fluid; + +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class CycleFluidHandler implements IFluidHandlerModifiable { + + private List> stacks; + + public CycleFluidHandler(List> stacks) { + this.updateStacks(stacks); + } + + public void updateStacks(List> stacks) { + this.stacks = stacks; + } + + @Override + public int getTanks() { + return this.stacks.size(); + } + + @NotNull + @Override + public FluidStack getFluidInTank(int tank) { + List stackList = this.stacks.get(tank); + return stackList != null && !stackList.isEmpty() ? + stackList.get(Math.abs((int) (System.currentTimeMillis() / 1000L) % stackList.size())) : + FluidStack.EMPTY; + } + + @Override + public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) { + if (tank >= 0 && tank < this.stacks.size()) { + this.stacks.set(tank, List.of(fluidStack)); + } + } + + @Override + public int getTankCapacity(int tank) { + return this.getFluidInTank(tank).getAmount(); + } + + @Override + public boolean isFluidValid(int tank, @NotNull FluidStack stack) { + return false; + } + + @Override + public int fill(FluidStack resource, FluidAction action) { + return 0; + } + + @Override + public boolean supportsFill(int tank) { + return false; + } + + @NotNull + @Override + public FluidStack drain(FluidStack resource, FluidAction action) { + return FluidStack.EMPTY; + } + + @Override + public @NotNull FluidStack drain(int maxDrain, FluidAction action) { + return FluidStack.EMPTY; + } + + @Override + public boolean supportsDrain(int tank) { + return false; + } + + public List getStackList(int i) { + return this.stacks.get(i); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java deleted file mode 100644 index 2604ff1841..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/InfiniteFluidHandlerProxy.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.gregtechceu.gtceu.api.transfer.fluid; - -import net.minecraft.MethodsReturnNonnullByDefault; -import net.minecraftforge.fluids.FluidStack; - -import org.jetbrains.annotations.NotNull; - -import javax.annotation.ParametersAreNonnullByDefault; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class InfiniteFluidHandlerProxy extends FluidHandlerDelegate { - - private final boolean infiniteSource; - private final boolean infiniteSink; - - public InfiniteFluidHandlerProxy(IFluidHandlerModifiable delegate, boolean infiniteSource, boolean infiniteSink) { - super(delegate); - - this.infiniteSource = infiniteSource; - this.infiniteSink = infiniteSink; - } - - @Override - public int fill(FluidStack resource, FluidAction action) { - if (infiniteSink) - return resource.getAmount(); - - return super.fill(resource, action); - } - - @Override - public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { - if (infiniteSource) - return resource.copy(); - - return super.drain(resource, action); - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java b/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java deleted file mode 100644 index c9df2e3ec9..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/transfer/fluid/NoOpFluidTransfer.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gregtechceu.gtceu.api.transfer.fluid; - -import net.minecraft.MethodsReturnNonnullByDefault; -import net.minecraftforge.fluids.FluidStack; - -import org.jetbrains.annotations.NotNull; - -import javax.annotation.ParametersAreNonnullByDefault; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class NoOpFluidTransfer implements IFluidHandlerModifiable { - - public static final NoOpFluidTransfer INSTANCE = new NoOpFluidTransfer(); - - private NoOpFluidTransfer() {} - - @Override - public int getTanks() { - return 0; - } - - @NotNull - @Override - public FluidStack getFluidInTank(int tank) { - return FluidStack.EMPTY; - } - - @Override - public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) {} - - @Override - public int getTankCapacity(int tank) { - return 0; - } - - @Override - public boolean isFluidValid(int tank, @NotNull FluidStack stack) { - return false; - } - - @Override - public int fill(FluidStack resource, FluidAction action) { - return 0; - } - - @Override - public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { - return FluidStack.EMPTY; - } - - @Override - public @NotNull FluidStack drain(int maxDrain, FluidAction action) { - return FluidStack.EMPTY; - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java index fdd9170080..7863776ce7 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java +++ b/src/main/java/com/gregtechceu/gtceu/common/blockentity/FluidPipeBlockEntity.java @@ -192,7 +192,7 @@ private void distributeFluid(int channel, CustomFluidTank tank, FluidStack fluid // pipeTank should only be determined by the cover attached to the actual pipe if (cover != null) { - pipeTank = cover.getFluidTransferCap(pipeTank); + pipeTank = cover.getFluidHandlerCap(pipeTank); // Shutter covers return null capability when active, so check here to prevent NPE if (pipeTank == null || checkForPumpCover(cover)) continue; } else { diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java index 1d887232e0..d468236ffb 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/PumpCover.java @@ -117,14 +117,14 @@ public PumpCover(CoverDefinition definition, ICoverable coverHolder, Direction a } protected boolean isSubscriptionActive() { - return isWorkingEnabled() && getAdjacentFluidTransfer() != null; + return isWorkingEnabled() && getAdjacentFluidHandler() != null; } - protected @Nullable IFluidHandlerModifiable getOwnFluidTransfer() { - return coverHolder.getFluidTransferCap(attachedSide, false); + protected @Nullable IFluidHandlerModifiable getOwnFluidHandler() { + return coverHolder.getFluidHandlerCap(attachedSide, false); } - protected @Nullable IFluidHandler getAdjacentFluidTransfer() { + protected @Nullable IFluidHandler getAdjacentFluidHandler() { return GTTransferUtils.getAdjacentFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide) .resolve() .orElse(null); @@ -140,7 +140,7 @@ public ManagedFieldHolder getFieldHolder() { @Override public boolean canAttach() { - return getOwnFluidTransfer() != null; + return getOwnFluidHandler() != null; } public void setIo(IO io) { @@ -233,15 +233,15 @@ protected void update() { } private int doTransferFluids(int platformTransferLimit) { - var adjacent = getAdjacentFluidTransfer(); + var adjacent = getAdjacentFluidHandler(); var adjacentModifiable = adjacent instanceof IFluidHandlerModifiable modifiable ? modifiable : new ModifiableFluidHandlerWrapper(adjacent); - var ownFluidTransfer = getOwnFluidTransfer(); + var ownFluidHandler = getOwnFluidHandler(); - if (adjacent != null && ownFluidTransfer != null) { + if (adjacent != null && ownFluidHandler != null) { return switch (io) { - case IN -> doTransferFluidsInternal(adjacentModifiable, ownFluidTransfer, platformTransferLimit); - case OUT -> doTransferFluidsInternal(ownFluidTransfer, adjacentModifiable, platformTransferLimit); + case IN -> doTransferFluidsInternal(adjacentModifiable, ownFluidHandler, platformTransferLimit); + case OUT -> doTransferFluidsInternal(ownFluidHandler, adjacentModifiable, platformTransferLimit); default -> 0; }; } @@ -263,16 +263,16 @@ protected enum TransferDirection { EXTRACT } - protected Map enumerateDistinctFluids(IFluidHandlerModifiable fluidTransfer, + protected Map enumerateDistinctFluids(IFluidHandlerModifiable fluidHandler, TransferDirection direction) { final Map summedFluids = new Object2IntOpenCustomHashMap<>( FluidStackHashStrategy.comparingAllButAmount()); - for (int tank = 0; tank < fluidTransfer.getTanks(); tank++) { - if (!canTransfer(fluidTransfer, direction, tank)) + for (int tank = 0; tank < fluidHandler.getTanks(); tank++) { + if (!canTransfer(fluidHandler, direction, tank)) continue; - FluidStack fluidStack = fluidTransfer.getFluidInTank(tank); + FluidStack fluidStack = fluidHandler.getFluidInTank(tank); if (fluidStack.isEmpty()) continue; @@ -285,10 +285,10 @@ protected Map enumerateDistinctFluids(IFluidHandlerModifiab return summedFluids; } - private static boolean canTransfer(IFluidHandlerModifiable fluidTransfer, TransferDirection direction, int tank) { + private static boolean canTransfer(IFluidHandlerModifiable fluidHandler, TransferDirection direction, int tank) { return switch (direction) { - case INSERT -> fluidTransfer.supportsFill(tank); - case EXTRACT -> fluidTransfer.supportsDrain(tank); + case INSERT -> fluidHandler.supportsFill(tank); + case EXTRACT -> fluidHandler.supportsDrain(tank); }; } @@ -355,18 +355,18 @@ protected void configureFilter() { // *** CAPABILITY OVERRIDE ***// ///////////////////////////////////// - private CoverableFluidHandlerWrapper fluidTransferWrapper; + private CoverableFluidHandlerWrapper fluidHandlerWrapper; @Nullable @Override - public IFluidHandlerModifiable getFluidTransferCap(@Nullable IFluidHandlerModifiable defaultValue) { + public IFluidHandlerModifiable getFluidHandlerCap(@Nullable IFluidHandlerModifiable defaultValue) { if (defaultValue == null) { return null; } - if (fluidTransferWrapper == null || fluidTransferWrapper.delegate != defaultValue) { - this.fluidTransferWrapper = new CoverableFluidHandlerWrapper(defaultValue); + if (fluidHandlerWrapper == null || fluidHandlerWrapper.delegate != defaultValue) { + this.fluidHandlerWrapper = new CoverableFluidHandlerWrapper(defaultValue); } - return fluidTransferWrapper; + return fluidHandlerWrapper; } private class CoverableFluidHandlerWrapper extends FluidHandlerDelegate { diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java index ddab80cf4d..c89b9fdf29 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/AdvancedFluidDetectorCover.java @@ -82,7 +82,7 @@ protected void update() { return; FluidFilter filter = filterHandler.getFilter(); - IFluidHandler fluidHandler = getFluidTransfer(); + IFluidHandler fluidHandler = getFluidHandler(); if (fluidHandler == null) return; diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java index f1ef48fbbd..f3d3ec8f2b 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/detector/FluidDetectorCover.java @@ -17,7 +17,7 @@ public FluidDetectorCover(CoverDefinition definition, ICoverable coverHolder, Di @Override public boolean canAttach() { - return getFluidTransfer() != null; + return getFluidHandler() != null; } @Override @@ -25,7 +25,7 @@ protected void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) return; - IFluidHandler fluidHandler = getFluidTransfer(); + IFluidHandler fluidHandler = getFluidHandler(); if (fluidHandler == null) return; @@ -46,7 +46,7 @@ protected void update() { setRedstoneSignalOutput(RedstoneUtil.computeRedstoneValue(storedFluid, fluidCapacity, isInverted())); } - protected IFluidHandler getFluidTransfer() { + protected IFluidHandler getFluidHandler() { return FluidUtil.getFluidHandler(coverHolder.getLevel(), coverHolder.getPos(), attachedSide).resolve() .orElse(null); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java index 029dbdd03e..6c547b35a4 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/AdvancedFluidVoidingCover.java @@ -59,19 +59,19 @@ public AdvancedFluidVoidingCover(CoverDefinition definition, ICoverable coverHol @Override protected void doVoidFluids() { - IFluidHandlerModifiable fluidTransfer = getOwnFluidTransfer(); - if (fluidTransfer == null) { + IFluidHandlerModifiable fluidHandler = getOwnFluidHandler(); + if (fluidHandler == null) { return; } switch (voidingMode) { - case VOID_ANY -> voidAny(fluidTransfer); - case VOID_OVERFLOW -> voidOverflow(fluidTransfer); + case VOID_ANY -> voidAny(fluidHandler); + case VOID_OVERFLOW -> voidOverflow(fluidHandler); } } - private void voidOverflow(IFluidHandlerModifiable fluidTransfer) { - final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); + private void voidOverflow(IFluidHandlerModifiable fluidHandler) { + final Map fluidAmounts = enumerateDistinctFluids(fluidHandler, TransferDirection.EXTRACT); for (FluidStack fluidStack : fluidAmounts.keySet()) { int presentAmount = fluidAmounts.get(fluidStack); @@ -82,7 +82,7 @@ private void voidOverflow(IFluidHandlerModifiable fluidTransfer) { var toDrain = fluidStack.copy(); toDrain.setAmount(presentAmount - targetAmount); - fluidTransfer.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); + fluidHandler.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java index ac5284672b..13cde836d7 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/voiding/FluidVoidingCover.java @@ -56,15 +56,15 @@ protected void update() { } protected void doVoidFluids() { - IFluidHandlerModifiable fluidTransfer = getOwnFluidTransfer(); - if (fluidTransfer == null) { + IFluidHandlerModifiable fluidHandler = getOwnFluidHandler(); + if (fluidHandler == null) { return; } - voidAny(fluidTransfer); + voidAny(fluidHandler); } - void voidAny(IFluidHandlerModifiable fluidTransfer) { - final Map fluidAmounts = enumerateDistinctFluids(fluidTransfer, TransferDirection.EXTRACT); + void voidAny(IFluidHandlerModifiable fluidHandler) { + final Map fluidAmounts = enumerateDistinctFluids(fluidHandler, TransferDirection.EXTRACT); for (FluidStack fluidStack : fluidAmounts.keySet()) { if (!filterHandler.test(fluidStack)) @@ -73,7 +73,7 @@ void voidAny(IFluidHandlerModifiable fluidTransfer) { var toDrain = fluidStack.copy(); toDrain.setAmount(fluidAmounts.get(fluidStack)); - fluidTransfer.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); + fluidHandler.drain(toDrain, IFluidHandler.FluidAction.EXECUTE); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java index 22d2ed2ea9..48766c72a6 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/tool/behavior/PlungerBehavior.java @@ -51,7 +51,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { if (context.getLevel() .getBlockEntity(context.getClickedPos()) instanceof IMachineBlockEntity metaMachineBlockEntity) { - fluidHandler = metaMachineBlockEntity.getMetaMachine().getFluidTransferCap(context.getClickedFace(), false); + fluidHandler = metaMachineBlockEntity.getMetaMachine().getFluidHandlerCap(context.getClickedFace(), false); } else { fluidHandler = FluidUtil .getFluidHandler(context.getLevel(), context.getClickedPos(), context.getClickedFace()).resolve() diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java index aa3633dcbd..91b252b827 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/LargeMinerMachine.java @@ -139,8 +139,8 @@ private void initializeAbilities() { handler instanceof IEnergyContainer container) { energyContainers.add(container); } else if (handlerIO == IO.IN && handler.getCapability() == FluidRecipeCapability.CAP && - handler instanceof IFluidHandler fluidTransfer) { - fluidTanks.add(fluidTransfer); + handler instanceof IFluidHandler fluidHandler) { + fluidTanks.add(fluidHandler); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java index 6065f111d5..f93ca8dcae 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/DualHatchPartMachine.java @@ -37,7 +37,7 @@ public class DualHatchPartMachine extends ItemBusPartMachine { @Nullable protected ISubscription tankSubs; - private boolean hasFluidTransfer; + private boolean hasFluidHandler; private boolean hasItemTransfer; public DualHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, Object... args) { @@ -88,13 +88,13 @@ protected void updateInventorySubscription() { if (level != null) { this.hasItemTransfer = ItemTransferHelper.getItemTransfer( level, getPos().relative(getFrontFacing()), getFrontFacing().getOpposite()) != null; - this.hasFluidTransfer = GTTransferUtils.hasAdjacentFluidHandler(level, getPos(), getFrontFacing()); + this.hasFluidHandler = GTTransferUtils.hasAdjacentFluidHandler(level, getPos(), getFrontFacing()); } else { this.hasItemTransfer = false; - this.hasFluidTransfer = false; + this.hasFluidHandler = false; } - if (isWorkingEnabled() && (canOutput || io == IO.IN) && (hasItemTransfer || hasFluidTransfer)) { + if (isWorkingEnabled() && (canOutput || io == IO.IN) && (hasItemTransfer || hasFluidHandler)) { autoIOSubs = subscribeServerTick(autoIOSubs, this::autoIO); } else if (autoIOSubs != null) { autoIOSubs.unsubscribe(); @@ -110,14 +110,14 @@ protected void autoIO() { if (hasItemTransfer) { getInventory().exportToNearby(getFrontFacing()); } - if (hasFluidTransfer) { + if (hasFluidHandler) { tank.exportToNearby(getFrontFacing()); } } else if (io == IO.IN) { if (hasItemTransfer) { getInventory().importFromNearby(getFrontFacing()); } - if (hasFluidTransfer) { + if (hasFluidHandler) { tank.importFromNearby(getFrontFacing()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidTransferHandler.java b/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidTransferHandler.java deleted file mode 100644 index 92c507e549..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/common/pipelike/fluidpipe/FluidTransferHandler.java +++ /dev/null @@ -1,161 +0,0 @@ -// package com.gregtechceu.gtceu.common.pipelike.fluidpipe; -// -// import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; -// import com.gregtechceu.gtceu.common.blockentity.FluidPipeBlockEntity; -// import com.gregtechceu.gtceu.common.cover.FluidFilterCover; -// import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -// import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; -// import it.unimi.dsi.fastutil.objects.Object2LongMap; -// import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; -// import lombok.Setter; -// import net.minecraft.core.BlockPos; -// import net.minecraft.core.Direction; -// import net.minecraft.world.level.material.Fluid; -// import org.jetbrains.annotations.NotNull; -// import org.jetbrains.annotations.Nullable; -// import oshi.util.tuples.Pair; -// -// import java.util.*; -// import java.util.function.Predicate; -// -/// ** -// * @author KilaBash -// * @date 2023/3/11 -// * @implNote FluidTransferHandler -// */ -// public class FluidTransferHandler implements IFluidTransfer { -// -// private final FluidPipeNet net; -// private final FluidPipeBlockEntity pipe; -// private final List paths; -// @Nullable -// private final Direction side; -// @Setter -// private Predicate filter = fluid -> true; -// -// public FluidTransferHandler(FluidPipeNet net, FluidPipeBlockEntity pipe, @Nullable Direction side) { -// this.net = Objects.requireNonNull(net); -// this.pipe = Objects.requireNonNull(pipe); -// this.paths = net.getNetData(pipe.getPipePos()); -// this.side = side; -// } -// -// @Override -// public int getTanks() { -// return 1; -// } -// -// @NotNull -// @Override -// public FluidStack getFluidInTank(int tank) { -// return FluidStack.empty(); -// } -// -// @Override -// public long getTankCapacity(int tank) { -// return tank == 0 ? net.getNodeAt(pipe.getPipePos()).data.properties.getPlatformThroughput() - -// net.getThroughputUsed(pipe.getPipePos()) : 0; -// } -// -// @Override -// public boolean isFluidValid(int tank, @NotNull FluidStack stack) { -// return filter.test(stack); -// } -// -// /** -// * check path. how much fluid can be transferred. -// * @return amount -// */ -// private long checkPathAvailable(FluidStack stack, PipeNetRoutePath routePath, Map> -// simulateChannelUsed, Object2LongMap simulateThroughputUsed) { -// if (stack.isEmpty()) return 0; -// var amount = stack.getAmount(); -// for (Pair node : routePath.getPath()) { -// var properties = node.getB().properties; -// var pos = node.getA(); -// if (!properties.acceptFluid(stack)) { -// return 0; -// } -// var channels = net.getChannelUsed(pos); -// var simulateChannels = simulateChannelUsed.getOrDefault(pos, Collections.emptySet()); -// -// if (!channels.contains(stack.getFluid()) && !simulateChannels.contains(stack.getFluid()) -// && (channels.size() + simulateChannels.size()) >= properties.getChannels()) return 0; -// -// var left = properties.getPlatformThroughput() - net.getThroughputUsed(pos) - simulateThroughputUsed.getOrDefault(pos, -// 0); -// amount = Math.min(amount, left); -// if (amount == 0) return 0; -// } -// return amount; -// } -// -// @Override -// public long fill(FluidStack resource, boolean simulate) { -// if (resource.isEmpty() || !filter.test(resource)) return 0; -// var left = resource.copy(); -// Map> simulateChannelUsed = new HashMap<>(); -// Object2LongMap simulateThroughputUsed = new Object2LongOpenHashMap<>(); -// for (PipeNetRoutePath path : paths) { -// if (Objects.equals(pipe.getPipePos(), path.getPipePos()) && (side == path.getFaceToHandler() || side == null)) { -// //Do not insert into source handler -// continue; -// } -// var handler = path.getHandler(pipe.getPipeLevel()); -// if (handler != null) { -// var coverable = GTCapabilityHelper.getCoverable(net.getLevel(), path.getPipePos(), null); -// if (coverable != null) { -// if (coverable.getCoverAtSide(path.getFaceToHandler()) instanceof FluidFilterCover cover && -// !cover.getFluidFilter().test(resource)) { -// return 0; -// } -// } -// var accepted = checkPathAvailable(left, path, simulateChannelUsed, simulateThroughputUsed); -// if (accepted <= 0) continue; -// var copied = left.copy(); -// copied.setAmount(accepted); -// var filled = handler.fill(copied, simulate); -// if (filled > 0) { // occupy capacity + channel -// for (Pair node : path.getPath()) { -// var pos = node.getA(); -// if (simulate) { -// simulateThroughputUsed.put(pos, simulateThroughputUsed.getOrDefault(pos, 0) + filled); -// simulateChannelUsed.computeIfAbsent(pos, p -> new HashSet<>()).add(resource.getFluid()); -// } else { -// net.useThroughput(pos, filled); -// net.useChannel(pos, resource.getFluid()); -// } -// } -// -// } -// left.shrink(filled); -// if (left.isEmpty()) { -// break; -// } -// } -// } -// return resource.getAmount() - left.getAmount(); -// } -// -// @NotNull -// @Override -// public FluidStack drain(FluidStack resource, boolean simulate) { -// return FluidStack.empty(); -// } -// -// @NotNull -// @Override -// public FluidStack drain(long maxDrain, boolean simulate) { -// return FluidStack.empty(); -// } -// -// @Override -// public boolean supportsFill(int i) { -// return true; -// } -// -// @Override -// public boolean supportsDrain(int i) { -// return false; -// } -// } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java b/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java index d7a9a83ccd..b3c9c39219 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/OverlayingFluidStorage.java @@ -12,12 +12,12 @@ @RequiredArgsConstructor public class OverlayingFluidStorage implements IFluidHandlerModifiable, IFluidTank { - private final IFluidHandlerModifiable transfer; + private final IFluidHandlerModifiable handler; private final int tank; @Override public @NotNull FluidStack getFluid() { - return transfer.getFluidInTank(tank); + return handler.getFluidInTank(tank); } @Override @@ -27,7 +27,7 @@ public int getFluidAmount() { @Override public int getCapacity() { - return transfer.getTankCapacity(tank); + return handler.getTankCapacity(tank); } @Override @@ -42,7 +42,7 @@ public int getTankCapacity(int tank) { @Override public void setFluidInTank(int tank, FluidStack stack) { - transfer.setFluidInTank(tank, stack); + handler.setFluidInTank(tank, stack); } @Override @@ -57,31 +57,31 @@ public boolean isFluidValid(FluidStack stack) { @Override public boolean isFluidValid(int tank, @NotNull FluidStack stack) { - return transfer.isFluidValid(tank, stack); + return handler.isFluidValid(tank, stack); } @Override public int fill(FluidStack resource, FluidAction action) { - if (transfer instanceof NotifiableFluidTank notifiable) { + if (handler instanceof NotifiableFluidTank notifiable) { return notifiable.getStorages()[this.tank].fill(resource, action); } - return transfer.fill(resource, action); + return handler.fill(resource, action); } @NotNull @Override public FluidStack drain(FluidStack resource, FluidAction action) { - if (transfer instanceof NotifiableFluidTank notifiable) { + if (handler instanceof NotifiableFluidTank notifiable) { return notifiable.getStorages()[this.tank].drain(resource, action); } - return transfer.drain(resource, action); + return handler.drain(resource, action); } @Override public @NotNull FluidStack drain(int maxDrain, FluidAction action) { - if (transfer instanceof NotifiableFluidTank notifiable) { + if (handler instanceof NotifiableFluidTank notifiable) { return notifiable.getStorages()[this.tank].drain(maxDrain, action); } - return transfer.drain(maxDrain, action); + return handler.drain(maxDrain, action); } } From dc22f65cf7e463ccd91c178b6a1fc85ef6545fe3 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Tue, 15 Oct 2024 04:18:07 -0400 Subject: [PATCH 16/22] Migrate new things and touchups --- .../ingredient/FluidContainerIngredient.java | 41 ++++-------- .../gtceu/common/cover/FluidFilterCover.java | 10 +-- .../common/machine/electric/PumpMachine.java | 8 +-- .../ae2/gui/widget/AEFluidConfigWidget.java | 2 +- .../gui/widget/list/AEFluidDisplayWidget.java | 2 +- .../widget/slot/AEFluidConfigSlotWidget.java | 10 +-- .../gtceu/syncdata/FluidStackPayload.java | 4 +- .../com/gregtechceu/gtceu/utils/GTUtil.java | 2 - .../gtceu/utils/InfiniteFluidTransfer.java | 64 ------------------- 9 files changed, 31 insertions(+), 112 deletions(-) delete mode 100644 src/main/java/com/gregtechceu/gtceu/utils/InfiniteFluidTransfer.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidContainerIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidContainerIngredient.java index ffcc6c3a56..f8fc6fcebd 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidContainerIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidContainerIngredient.java @@ -2,9 +2,6 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.data.tag.TagUtil; -import com.gregtechceu.gtceu.utils.InfiniteFluidTransfer; - -import com.lowdragmc.lowdraglib.side.fluid.*; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; @@ -16,6 +13,10 @@ import net.minecraft.world.level.material.Fluid; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IIngredientSerializer; +import net.minecraftforge.fluids.FluidActionResult; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.fluids.capability.templates.VoidFluidHandler; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -60,7 +61,7 @@ public FluidContainerIngredient(TagKey tag, int amount) { public ItemStack[] getItems() { if (cachedStacks == null) cachedStacks = Arrays.stream(this.fluid.getStacks()) - .map(stack -> stack.getFluid().getBucket().getDefaultInstance()) + .map(FluidUtil::getFilledBucket) .filter(s -> !s.isEmpty()) .toArray(ItemStack[]::new); return this.cachedStacks; @@ -83,8 +84,9 @@ public boolean isEmpty() { public boolean test(@Nullable ItemStack stack) { if (stack == null || stack.isEmpty()) return false; - IFluidTransfer transfer = FluidTransferHelper.getFluidTransfer(stack); - return transfer != null && this.extractFrom(transfer, true); + return FluidUtil.getFluidContained(stack).map(fluid::test).orElse(false) && + FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, fluid.getAmount(), null, false) + .isSuccess(); } @Override @@ -93,33 +95,14 @@ public boolean isSimple() { } public ItemStack getExtractedStack(ItemStack input) { - FluidActionResult result = FluidTransferHelper.tryEmptyContainer(input, - new InfiniteFluidTransfer(1), - (int) this.fluid.getAmount(), - ForgeHooks.getCraftingPlayer(), - true); - if (result.success) { - return result.result; + FluidActionResult result = FluidUtil.tryEmptyContainer(input, VoidFluidHandler.INSTANCE, fluid.getAmount(), + ForgeHooks.getCraftingPlayer(), true); + if (result.isSuccess()) { + return result.getResult(); } return input; } - public boolean extractFrom(IFluidTransfer handler, boolean simulate) { - for (int tank = 0; tank < handler.getTanks(); tank++) { - FluidStack inTank = handler.getFluidInTank(tank); - if (fluid.test(inTank)) { - FluidStack toExtract = inTank.copy(fluid.getAmount()); - FluidStack extractedSim = handler.drain(toExtract, true); - if (extractedSim.getAmount() >= fluid.getAmount()) { - if (!simulate) - handler.drain(toExtract, false); - return true; - } - } - } - return false; - } - @Override @NotNull public IIngredientSerializer getSerializer() { diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java index bb265a7548..bd575f9c85 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/FluidFilterCover.java @@ -5,9 +5,9 @@ import com.gregtechceu.gtceu.api.cover.CoverDefinition; import com.gregtechceu.gtceu.api.cover.IUICover; import com.gregtechceu.gtceu.api.cover.filter.FluidFilter; - import com.gregtechceu.gtceu.api.transfer.fluid.FluidHandlerDelegate; import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable; + import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; @@ -31,7 +31,7 @@ public class FluidFilterCover extends CoverBehavior implements IUICover { protected FluidFilter fluidFilter; - private FilteredFluidTransferWrapper fluidFilterWrapper; + private FilteredFluidHandlerWrapper fluidFilterWrapper; public FluidFilterCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) { super(definition, coverHolder, attachedSide); @@ -56,7 +56,7 @@ public FluidFilter getFluidFilter() { } if (fluidFilterWrapper == null || fluidFilterWrapper.delegate != defaultValue) { - this.fluidFilterWrapper = new FilteredFluidTransferWrapper(defaultValue); + this.fluidFilterWrapper = new FilteredFluidHandlerWrapper(defaultValue); } return fluidFilterWrapper; @@ -70,9 +70,9 @@ public Widget createUIWidget() { return group; } - private class FilteredFluidTransferWrapper extends FluidHandlerDelegate { + private class FilteredFluidHandlerWrapper extends FluidHandlerDelegate { - public FilteredFluidTransferWrapper(IFluidHandlerModifiable delegate) { + public FilteredFluidHandlerWrapper(IFluidHandlerModifiable delegate) { super(delegate); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java index 7974b2575c..06a40d0d37 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/PumpMachine.java @@ -33,18 +33,15 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper; -import net.minecraft.world.level.material.FluidState; -import net.minecraftforge.fluids.FluidType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; @@ -483,7 +480,8 @@ private void pumpCycle() { if (sourceState.state().getBlock() instanceof LiquidBlock liquidBlock && fluidState.isSource()) { var fluidHandler = new BucketPickupHandlerWrapper(liquidBlock, getLevel(), pos); FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, FluidAction.SIMULATE); - if (!drainStack.isEmpty() && cache.fillInternal(drainStack, FluidAction.SIMULATE) == drainStack.getAmount()) { + if (!drainStack.isEmpty() && + cache.fillInternal(drainStack, FluidAction.SIMULATE) == drainStack.getAmount()) { cache.fillInternal(drainStack, FluidAction.EXECUTE); fluidHandler.drain(drainStack, FluidAction.EXECUTE); getLevel().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState()); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java index 4e78833f6f..a97ff4eeca 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java @@ -9,7 +9,7 @@ /** * @Author GlodBlock - * @Description Display {@link com.lowdragmc.lowdraglib.side.fluid.FluidStack} config + * @Description Display {@link net.minecraftforge.fluids.FluidStack} config * @Date 2023/4/21-1:45 */ public class AEFluidConfigWidget extends ConfigWidget { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java index 57dea56768..021edd66cb 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java @@ -29,7 +29,7 @@ /** * @author GlodBlock - * @ Display a certain {@link com.lowdragmc.lowdraglib.side.fluid.FluidStack} element. + * @ Display a certain {@link FluidStack} element. * @date 2023/4/19-0:30 */ public class AEFluidDisplayWidget extends Widget { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java index aad77c9d32..bb6927e275 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java @@ -10,6 +10,7 @@ import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; +import com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl; import com.lowdragmc.lowdraglib.utils.Position; import com.lowdragmc.lowdraglib.utils.Size; @@ -35,11 +36,10 @@ import org.jetbrains.annotations.NotNull; import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawStringFixedCorner; -import static com.lowdragmc.lowdraglib.side.fluid.forge.FluidHelperImpl.toFluidStack; /** * @Author GlodBlock - * @Description A configurable slot for {@link com.lowdragmc.lowdraglib.side.fluid.FluidStack} + * @Description A configurable slot for {@link FluidStack} * @Date 2023/4/21-0:50 */ public class AEFluidConfigSlotWidget extends AEConfigSlotWidget implements IGhostFluidTarget { @@ -66,7 +66,8 @@ public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mous if (config != null) { var stack = AEUtil.toFluidStack(config); if (!stack.isEmpty()) { - DrawerHelper.drawFluidForGui(graphics, toFluidStack(stack), config.amount(), stackX, stackY, 16, 16); + DrawerHelper.drawFluidForGui(graphics, FluidHelperImpl.toFluidStack(stack), config.amount(), stackX, + stackY, 16, 16); if (!parentWidget.isStocking()) { String amountStr = TextFormattingUtil.formatLongToCompactString(config.amount(), 4) + "mB"; drawStringFixedCorner(graphics, amountStr, stackX + 17, stackY + 17, 16777215, true, 0.5f); @@ -76,7 +77,8 @@ public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mous if (stock != null) { var stack = AEUtil.toFluidStack(stock); if (!stack.isEmpty()) { - DrawerHelper.drawFluidForGui(graphics, toFluidStack(stack), stock.amount(), stackX, stackY + 18, 16, + DrawerHelper.drawFluidForGui(graphics, FluidHelperImpl.toFluidStack(stack), stock.amount(), stackX, + stackY + 18, 16, 16); String amountStr = TextFormattingUtil.formatLongToCompactString(stock.amount(), 4) + "mB"; drawStringFixedCorner(graphics, amountStr, stackX + 17, stackY + 18 + 17, 16777215, true, 0.5f); diff --git a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java index adeeaab339..4e6c1ca35b 100644 --- a/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java +++ b/src/main/java/com/gregtechceu/gtceu/syncdata/FluidStackPayload.java @@ -10,6 +10,8 @@ import org.jetbrains.annotations.Nullable; +import static com.lowdragmc.lowdraglib.side.fluid.FluidStack.loadFromTag; + public class FluidStackPayload extends ObjectTypedPayload { @Override @@ -35,7 +37,7 @@ public void deserializeNBT(Tag tag) { } catch (ClassCastException exception) { // LDLib FluidStack stores amount as Long tag, which will throw an error // Loads from tag using LDLib FluidStack, then converts it to a Forge FluidStack - var stack = com.lowdragmc.lowdraglib.side.fluid.FluidStack.loadFromTag((CompoundTag) tag); + var stack = loadFromTag((CompoundTag) tag); payload = FluidHelperImpl.toFluidStack(stack); } } diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java index 860e98961f..401acac5e0 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java @@ -41,8 +41,6 @@ import net.minecraftforge.common.Tags; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fluids.FluidUtil; -import net.minecraftforge.fluids.capability.IFluidHandler; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.datafixers.util.Pair; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/InfiniteFluidTransfer.java b/src/main/java/com/gregtechceu/gtceu/utils/InfiniteFluidTransfer.java deleted file mode 100644 index f61f4508f7..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/utils/InfiniteFluidTransfer.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.gregtechceu.gtceu.utils; - -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.jetbrains.annotations.NotNull; - -@RequiredArgsConstructor -public class InfiniteFluidTransfer implements IFluidTransfer { - - @Getter - private final int tanks; - - @NotNull - @Override - public FluidStack getFluidInTank(int tank) { - return FluidStack.empty(); - } - - @Override - public void setFluidInTank(int tank, @NotNull FluidStack fluidStack) {} - - @Override - public long getTankCapacity(int tank) { - return Long.MAX_VALUE; - } - - @Override - public boolean isFluidValid(int tank, @NotNull FluidStack stack) { - return true; - } - - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return resource.getAmount(); - } - - @Override - public boolean supportsFill(int tank) { - return true; - } - - @NotNull - @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return resource.copy(); - } - - @Override - public boolean supportsDrain(int tank) { - return true; - } - - @NotNull - @Override - public Object createSnapshot() { - return new Object(); - } - - @Override - public void restoreFromSnapshot(Object snapshot) {} -} From ea31506bdf96b080039bddc87574608520ffcc64 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:35:44 -0400 Subject: [PATCH 17/22] Change widget registration priority so that custom UIs still work --- .../gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java | 2 +- .../java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java index 35b5090ff9..ff17f4dda6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/PhantomFluidWidget.java @@ -41,7 +41,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -@LDLRegister(name = "phantom_fluid_slot", group = "widget.container") +@LDLRegister(name = "phantom_fluid_slot", group = "widget.container", priority = 50) public class PhantomFluidWidget extends TankWidget implements IGhostIngredientTarget, IConfigurableWidget { private final Supplier phantomFluidGetter; diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java index c36e74fb54..c71e156a67 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/TankWidget.java @@ -75,7 +75,7 @@ import javax.annotation.Nullable; @SuppressWarnings("unused") -@LDLRegister(name = "fluid_slot", group = "widget.container") +@LDLRegister(name = "fluid_slot", group = "widget.container", priority = 50) @Accessors(chain = true) public class TankWidget extends Widget implements IRecipeIngredientSlot, IConfigurableWidget { From 8f76229d75203e6e87d4b4ce7dc89ab3bcafa2ed Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:05:40 -0400 Subject: [PATCH 18/22] More cleanup --- .../gtceu/api/machine/MetaMachine.java | 6 ++--- .../gtceu/utils/GTTransferUtils.java | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java index 8df0ce3afa..3e4d377025 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java @@ -705,11 +705,11 @@ public IFluidHandlerModifiable getFluidHandlerCap(@Nullable Direction side, bool io = IO.OUT; } - IOFluidHandlerList transferList = new IOFluidHandlerList(list, io, getFluidCapFilter(side)); - if (!useCoverCapability || side == null) return transferList; + IOFluidHandlerList handlerList = new IOFluidHandlerList(list, io, getFluidCapFilter(side)); + if (!useCoverCapability || side == null) return handlerList; CoverBehavior cover = getCoverContainer().getCoverAtSide(side); - return cover != null ? cover.getFluidHandlerCap(transferList) : transferList; + return cover != null ? cover.getFluidHandlerCap(handlerList) : handlerList; } ////////////////////////////////////// diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java index 274fccc70a..25dfd3ee66 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTTransferUtils.java @@ -226,42 +226,42 @@ public static boolean addFluidsToFluidHandler(FluidHandlerList fluidHandler, return true; } - public static int fillFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, FluidAction action) { + public static int fillFluidAccountNotifiableList(IFluidHandler fluidHandler, FluidStack stack, FluidAction action) { if (stack.isEmpty()) return 0; - if (handler instanceof FluidHandlerList handlerList) { + if (fluidHandler instanceof FluidHandlerList handlerList) { var copied = stack.copy(); - for (var transfer : handlerList.handlers) { + for (var handler : handlerList.handlers) { var candidate = copied.copy(); - if (transfer instanceof NotifiableFluidTank notifiable) { + if (handler instanceof NotifiableFluidTank notifiable) { copied.shrink(notifiable.fillInternal(candidate, action)); } else { - copied.shrink(transfer.fill(candidate, action)); + copied.shrink(handler.fill(candidate, action)); } if (copied.isEmpty()) break; } return stack.getAmount() - copied.getAmount(); } - return handler.fill(stack, action); + return fluidHandler.fill(stack, action); } - public static FluidStack drainFluidAccountNotifiableList(IFluidHandler handler, FluidStack stack, + public static FluidStack drainFluidAccountNotifiableList(IFluidHandler fluidHandler, FluidStack stack, FluidAction action) { if (stack.isEmpty()) return FluidStack.EMPTY; - if (handler instanceof FluidHandlerList handlerList) { + if (fluidHandler instanceof FluidHandlerList handlerList) { var copied = stack.copy(); - for (var transfer : handlerList.handlers) { + for (var handler : handlerList.handlers) { var candidate = copied.copy(); - if (transfer instanceof NotifiableFluidTank notifiable) { + if (handler instanceof NotifiableFluidTank notifiable) { copied.shrink(notifiable.drainInternal(candidate, action).getAmount()); } else { - copied.shrink(transfer.drain(candidate, action).getAmount()); + copied.shrink(handler.drain(candidate, action).getAmount()); } if (copied.isEmpty()) break; } copied.setAmount(stack.getAmount() - copied.getAmount()); return copied; } - return handler.drain(stack, action); + return fluidHandler.drain(stack, action); } /** From 7a04aa06e4a75522b050a7994e392c81adac66cc Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:05:57 -0400 Subject: [PATCH 19/22] Rework fluid recipe handling, again --- .../machine/trait/NotifiableFluidTank.java | 38 +++++++------------ .../recipe/ingredient/FluidIngredient.java | 4 ++ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index 0f27edc77a..a3b3aa90a9 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -99,13 +99,10 @@ public ManagedFieldHolder getFieldHolder() { @Override public List handleRecipeInner(IO io, GTRecipe recipe, List left, @Nullable String slotName, boolean simulate) { - return handleRecipe(io, left, simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE); - } - - // TODO: Propagate FluidAction parameter up the caller chain - public List handleRecipe(IO io, List left, FluidAction action) { + if (io != handlerIO) return left; if (io != IO.IN && io != IO.OUT) return left.isEmpty() ? null : left; + FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE; for (var it = left.iterator(); it.hasNext();) { var ingredient = it.next(); if (ingredient.isEmpty()) { @@ -119,26 +116,19 @@ public List handleRecipe(IO io, List left, Flu continue; } - for (CustomFluidTank storage : storages) { - FluidStack stored = storage.getFluid(); - int transferred = 0; - int toTransfer = ingredient.getAmount(); - if (io == IO.IN) { - if (!ingredient.test(stored)) continue; - var copy = stored.copy(); - copy.setAmount(toTransfer); - transferred = storage.drain(copy, action).getAmount(); - } else { // IO.OUT - FluidStack output = fluids[0]; - transferred = storage.fill(output.copy(), action); - // TODO: Check *all* tanks first - if (output.isFluidEqual(stored) && transferred < toTransfer && !allowSameFluids) return left; - } - ingredient.setAmount(toTransfer - transferred); - if (ingredient.getAmount() <= 0) { - it.remove(); - break; + if(io == IO.IN) { + for(FluidStack fluid : fluids) { + FluidStack copy = new FluidStack(fluid, ingredient.getAmount()); + ingredient.shrink(drainInternal(copy, action).getAmount()); + if(ingredient.getAmount() <= 0) { + it.remove(); + break; + } } + } else { // IO.OUT + FluidStack output = fluids[0]; + int filled = fillInternal(output, action); + if(filled >= ingredient.getAmount()) it.remove(); } } return left.isEmpty() ? null : left; diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java index 2d998ab95e..569fac4a45 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/FluidIngredient.java @@ -167,6 +167,10 @@ public void setAmount(int amount) { this.changed = true; } + public void shrink(int amount) { + setAmount(this.amount - amount); + } + public void setNbt(CompoundTag nbt) { this.nbt = nbt; this.changed = true; From e1f8503fb3f6a8311ed11296423d14115e105c82 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Fri, 18 Oct 2024 02:47:20 -0400 Subject: [PATCH 20/22] Rework fluid jetpack to not bother with recipe searching --- .../machine/trait/NotifiableFluidTank.java | 64 ------- .../gtceu/api/misc/FluidRecipeHandler.java | 78 --------- .../gtceu/common/data/GTRecipeTypes.java | 10 +- .../common/item/armor/PowerlessJetpack.java | 157 +++++------------- 4 files changed, 51 insertions(+), 258 deletions(-) delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index a3b3aa90a9..ce391c4646 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -134,70 +134,6 @@ public List handleRecipeInner(IO io, GTRecipe recipe, List handleIngredient(IO io, GTRecipe recipe, List left, - boolean simulate, IO handlerIO, CustomFluidTank[] storages) { - if (io != handlerIO) return left; - var capabilities = simulate ? - Arrays.stream(storages).map(CustomFluidTank::copy).toArray(CustomFluidTank[]::new) : - storages; - for (CustomFluidTank capability : capabilities) { - Iterator iterator = left.iterator(); - if (io == IO.IN) { - while (iterator.hasNext()) { - FluidIngredient fluidStack = iterator.next(); - if (fluidStack.isEmpty()) { - iterator.remove(); - continue; - } - boolean found = false; - FluidStack foundStack = null; - for (int i = 0; i < capability.getTanks(); i++) { - FluidStack stored = capability.getFluidInTank(i); - if (!fluidStack.test(stored)) { - continue; - } - found = true; - foundStack = stored; - } - if (!found) continue; - var copy = foundStack.copy(); - copy.setAmount(fluidStack.getAmount()); - FluidStack drained = capability.drain(copy, FluidAction.EXECUTE); - - fluidStack.setAmount(fluidStack.getAmount() - drained.getAmount()); - if (fluidStack.getAmount() <= 0) { - iterator.remove(); - } - } - } else if (io == IO.OUT) { - while (iterator.hasNext()) { - FluidIngredient fluidStack = iterator.next(); - if (fluidStack.isEmpty()) { - iterator.remove(); - continue; - } - var fluids = fluidStack.getStacks(); - if (fluids.length == 0) { - iterator.remove(); - continue; - } - FluidStack output = fluids[0]; - int filled = capability.fill(output.copy(), FluidAction.EXECUTE); - if (!fluidStack.isEmpty()) { - fluidStack.setAmount(fluidStack.getAmount() - filled); - } - if (fluidStack.getAmount() <= 0) { - iterator.remove(); - } - } - } - if (left.isEmpty()) break; - } - return left.isEmpty() ? null : left; - } - @Override public boolean test(FluidIngredient ingredient) { return !this.isLocked() || ingredient.test(this.lockedFluid.getFluid()); diff --git a/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java deleted file mode 100644 index 8966976695..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/misc/FluidRecipeHandler.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.gregtechceu.gtceu.api.misc; - -import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability; -import com.gregtechceu.gtceu.api.capability.recipe.IO; -import com.gregtechceu.gtceu.api.capability.recipe.IRecipeHandler; -import com.gregtechceu.gtceu.api.capability.recipe.RecipeCapability; -import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; -import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; -import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; - -import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; - -import net.minecraftforge.fluids.FluidStack; - -import lombok.Getter; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class FluidRecipeHandler implements IRecipeHandler { - - @Getter - public final IO handlerIO; - @Persisted - @Getter - private final CustomFluidTank[] storages; - - public FluidRecipeHandler(IO handlerIO, int slots, int capacity) { - this.handlerIO = handlerIO; - this.storages = new CustomFluidTank[slots]; - for (int i = 0; i < this.storages.length; i++) { - this.storages[i] = new CustomFluidTank(capacity); - } - } - - @Override - public List handleRecipeInner(IO io, GTRecipe recipe, List left, - @Nullable String slotName, boolean simulate) { - return NotifiableFluidTank.handleIngredient(io, recipe, left, simulate, this.handlerIO, getStorages()); - } - - @Override - public List getContents() { - List ingredients = new ArrayList<>(); - for (CustomFluidTank storage : getStorages()) { - FluidStack stack = storage.getFluid(); - if (!stack.isEmpty()) { - ingredients.add(stack); - } - } - return Arrays.asList(ingredients.toArray()); - } - - @Override - public double getTotalContentAmount() { - long amount = 0; - for (CustomFluidTank storage : getStorages()) { - FluidStack stack = storage.getFluid(); - if (!stack.isEmpty()) { - amount += stack.getAmount(); - } - } - return amount; - } - - @Override - public int getSize() { - return getStorages().length; - } - - @Override - public RecipeCapability getCapability() { - return FluidRecipeCapability.CAP; - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index 969297d197..f17347d7d2 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -16,6 +16,7 @@ import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.sound.ExistingSoundEntry; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; +import com.gregtechceu.gtceu.common.item.armor.PowerlessJetpack; import com.gregtechceu.gtceu.common.machine.trait.customlogic.CannerLogic; import com.gregtechceu.gtceu.common.machine.trait.customlogic.FormingPressLogic; import com.gregtechceu.gtceu.common.recipe.condition.RPMCondition; @@ -463,7 +464,14 @@ public class GTRecipeTypes { .setMaxIOSize(0, 0, 1, 0).setEUIO(IO.OUT) .setSlotOverlay(false, true, true, GuiTextures.FURNACE_OVERLAY_2) .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW_MULTIPLE, LEFT_TO_RIGHT) - .setSound(GTSoundEntries.COMBUSTION); + .setSound(GTSoundEntries.COMBUSTION) + .onRecipeBuild((builder, provider) -> { + if(builder.input.containsKey(FluidRecipeCapability.CAP)) { + Content input = builder.input.get(FluidRecipeCapability.CAP).get(0); + FluidIngredient ingredient = FluidRecipeCapability.CAP.of(input.getContent()); + PowerlessJetpack.FUELS.put(ingredient, builder.duration); + } + }); public final static GTRecipeType GAS_TURBINE_FUELS = register("gas_turbine", GENERATOR).setMaxIOSize(0, 0, 1, 0) .setEUIO(IO.OUT) diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java index 3306532c1d..db250e0052 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java @@ -1,23 +1,20 @@ package com.gregtechceu.gtceu.common.item.armor; import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.api.capability.recipe.*; import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem; import com.gregtechceu.gtceu.api.item.armor.ArmorUtils; import com.gregtechceu.gtceu.api.item.armor.IArmorLogic; import com.gregtechceu.gtceu.api.item.component.*; import com.gregtechceu.gtceu.api.item.component.forge.IComponentCapability; -import com.gregtechceu.gtceu.api.misc.FluidRecipeHandler; -import com.gregtechceu.gtceu.api.misc.IgnoreEnergyRecipeHandler; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.common.data.GTMaterials; -import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.gregtechceu.gtceu.utils.GradientUtil; import com.gregtechceu.gtceu.utils.input.KeyBind; import com.lowdragmc.lowdraglib.Platform; +import it.unimi.dsi.fastutil.objects.AbstractObject2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; @@ -36,23 +33,23 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack; -import com.google.common.collect.Table; -import com.google.common.collect.Tables; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; -import java.util.function.Predicate; +import java.util.List; public class PowerlessJetpack implements IArmorLogic, IJetpack, IItemHUDProvider { + // Map of FluidIngredient -> burn time + public static final AbstractObject2IntMap FUELS = new Object2IntOpenHashMap<>(); public static final int tankCapacity = 16000; - private GTRecipe previousRecipe = null; - private GTRecipe currentRecipe = null; + private FluidIngredient currentFuel = FluidIngredient.EMPTY; + private FluidIngredient previousFuel = FluidIngredient.EMPTY; private int burnTimer = 0; @OnlyIn(Dist.CLIENT) @@ -65,9 +62,7 @@ public PowerlessJetpack() { @Override public void onArmorTick(Level world, Player player, @NotNull ItemStack stack) { - IFluidHandler internalTank = FluidUtil.getFluidHandler(stack).resolve().orElse(null); - if (internalTank == null) - return; + if(!FluidUtil.getFluidHandler(stack).isPresent()) return; CompoundTag data = stack.getOrCreateTag(); @@ -103,9 +98,7 @@ public void onArmorTick(Level world, Player player, @NotNull ItemStack stack) { if (toggleTimer > 0) toggleTimer--; data.putByte("toggleTimer", toggleTimer); - // This causes a caching issue. currentRecipe is only set to null in findNewRecipe, so the fuel is never updated - // Rewrite in Armor Rework - if (currentRecipe == null) + if(currentFuel.isEmpty()) findNewRecipe(stack); performFlying(player, jetpackEnabled, hoverMode, stack); @@ -171,94 +164,45 @@ public int getEnergyPerUse() { @Override public boolean canUseEnergy(ItemStack stack, int amount) { - FluidStack fuel = getFuel(); - if (fuel == null) { - return false; - } - - IFluidHandler fluidHandlerItem = getIFluidHandlerItem(stack); - if (fluidHandlerItem == null) - return false; - - FluidStack fluidStack = fluidHandlerItem.drain(fuel, IFluidHandler.FluidAction.EXECUTE); - if (fluidStack.isEmpty()) - return false; - - return fluidStack.getAmount() >= fuel.getAmount(); + if(currentFuel.isEmpty()) return false; + if(burnTimer > 0) return true; + var ret = FluidUtil.getFluidHandler(stack) + .map(h -> h.drain(Integer.MAX_VALUE, FluidAction.SIMULATE)) + .map(drained -> drained.getAmount() >= currentFuel.getAmount()) + .orElse(Boolean.FALSE); + if(!ret) currentFuel = FluidIngredient.EMPTY; + return ret; } @Override public void drainEnergy(ItemStack stack, int amount) { - if (this.burnTimer == 0) { - FluidStack fuel = getFuel(); - if (fuel == null) return; - getIFluidHandlerItem(stack).drain(fuel, IFluidHandler.FluidAction.SIMULATE); - burnTimer = currentRecipe.duration; + if (burnTimer == 0) { + FluidUtil.getFluidHandler(stack) + .ifPresent(h -> h.drain(currentFuel.getAmount(), FluidAction.EXECUTE)); + burnTimer = FUELS.getInt(currentFuel); } - this.burnTimer--; + burnTimer -= amount; } @Override public boolean hasEnergy(ItemStack stack) { - return burnTimer > 0 || currentRecipe != null; - } - - private static IFluidHandler getIFluidHandlerItem(@NotNull ItemStack stack) { - return FluidUtil.getFluidHandler(stack).resolve().orElse(null); + return burnTimer > 0 || !currentFuel.isEmpty(); } public void findNewRecipe(@NotNull ItemStack stack) { - IFluidHandler internalTank = getIFluidHandlerItem(stack); - if (internalTank != null) { - FluidStack fluidStack = internalTank.drain(1, IFluidHandler.FluidAction.EXECUTE); - if (previousRecipe != null && !fluidStack.isEmpty() && - FluidRecipeCapability.CAP.of(previousRecipe.getInputContents(FluidRecipeCapability.CAP).get(0)) - .test(fluidStack) && - fluidStack.getAmount() > 0) { - currentRecipe = previousRecipe; + FluidUtil.getFluidContained(stack).ifPresentOrElse( fluid -> { + if(!previousFuel.isEmpty() && previousFuel.test(fluid) && + fluid.getAmount() >= previousFuel.getAmount()) { + currentFuel = previousFuel; return; - } else if (!fluidStack.isEmpty()) { - Table, List>> table = Tables - .newCustomTable(new EnumMap<>(IO.class), IdentityHashMap::new); - FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Integer.MAX_VALUE); - handler.getStorages()[0].setFluid(fluidStack); - table.put(IO.IN, FluidRecipeCapability.CAP, Collections.singletonList(handler)); - table.put(IO.OUT, EURecipeCapability.CAP, Collections.singletonList(new IgnoreEnergyRecipeHandler())); - IRecipeCapabilityHolder holder = new IRecipeCapabilityHolder() { - - @Override - public @NotNull Table, List>> getCapabilitiesProxy() { - return table; - } - }; - Iterator iterator = GTRecipeTypes.COMBUSTION_GENERATOR_FUELS.searchRecipe(holder); - if (iterator.hasNext()) { - GTRecipe nextRecipe = iterator.next(); - if (nextRecipe == null) { - return; - } - previousRecipe = nextRecipe; - currentRecipe = previousRecipe; - return; - } } - } - currentRecipe = null; - } - public void resetRecipe() { - currentRecipe = null; - previousRecipe = null; - } - - public FluidStack getFuel() { - if (currentRecipe != null) { - var recipeInputs = currentRecipe.inputs.get(FluidRecipeCapability.CAP); - FluidIngredient fluid = FluidRecipeCapability.CAP.of(recipeInputs.get(0).content); - return fluid.getStacks()[0]; - } - - return FluidStack.EMPTY; + for(var fuel : FUELS.keySet()) { + if(fuel.test(fluid) && fluid.getAmount() >= fuel.getAmount()) { + previousFuel = currentFuel = fuel; + } + } + }, () -> currentFuel = FluidIngredient.EMPTY); } /* @@ -276,24 +220,6 @@ public FluidStack getFuel() { public static class Behaviour implements IDurabilityBar, IItemComponent, ISubItemHandler, IAddInformation, IInteractionItem, IComponentCapability { - private static final Predicate JETPACK_FUEL_FILTER = fluidStack -> { - Table, List>> table = Tables - .newCustomTable(new EnumMap<>(IO.class), IdentityHashMap::new); - FluidRecipeHandler handler = new FluidRecipeHandler(IO.IN, 1, Integer.MAX_VALUE); - handler.getStorages()[0].setFluid(fluidStack); - table.put(IO.IN, FluidRecipeCapability.CAP, Collections.singletonList(handler)); - table.put(IO.OUT, EURecipeCapability.CAP, Collections.singletonList(new IgnoreEnergyRecipeHandler())); - IRecipeCapabilityHolder holder = new IRecipeCapabilityHolder() { - - @Override - public @NotNull Table, List>> getCapabilitiesProxy() { - return table; - } - }; - Iterator iterator = GTRecipeTypes.COMBUSTION_GENERATOR_FUELS.searchRecipe(holder); - return iterator.hasNext() && iterator.next() != null; - }; - public final int maxCapacity; private final Pair durabilityBarColors; @@ -304,11 +230,9 @@ public Behaviour(int internalCapacity) { @Override public float getDurabilityForDisplay(@NotNull ItemStack itemStack) { - IFluidHandler fluidHandlerItem = FluidUtil.getFluidHandler(itemStack).resolve().orElse(null); - if (fluidHandlerItem == null) return 0; - FluidStack fluidStack = fluidHandlerItem.getFluidInTank(0); - return fluidStack.isEmpty() ? 0 : - (float) fluidStack.getAmount() / (float) fluidHandlerItem.getTankCapacity(0); + return FluidUtil.getFluidContained(itemStack) + .map(stack -> (float) stack.getAmount() / maxCapacity) + .orElse(0f); } @Nullable @@ -323,8 +247,11 @@ public Pair getDurabilityColorsForDisplay(ItemStack itemStack) LazyOptional.of(() -> new FluidHandlerItemStack(itemStack, maxCapacity) { @Override - public boolean canFillFluidType(net.minecraftforge.fluids.FluidStack fluid) { - return JETPACK_FUEL_FILTER.test(fluid); + public boolean canFillFluidType(FluidStack fluid) { + for(var ingredient : FUELS.keySet()) { + if(ingredient.test(fluid)) return true; + } + return false; } })); } From 9cad97250329798062ddb6c9942d9fcda08d04dd Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Fri, 18 Oct 2024 02:50:41 -0400 Subject: [PATCH 21/22] Spotless --- .../machine/trait/NotifiableFluidTank.java | 8 +++--- .../gtceu/common/data/GTRecipeTypes.java | 2 +- .../common/item/armor/PowerlessJetpack.java | 26 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index ce391c4646..7f6da14adc 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -116,11 +116,11 @@ public List handleRecipeInner(IO io, GTRecipe recipe, List handleRecipeInner(IO io, GTRecipe recipe, List= ingredient.getAmount()) it.remove(); + if (filled >= ingredient.getAmount()) it.remove(); } } return left.isEmpty() ? null : left; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index f17347d7d2..9e74ea44d4 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -466,7 +466,7 @@ public class GTRecipeTypes { .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW_MULTIPLE, LEFT_TO_RIGHT) .setSound(GTSoundEntries.COMBUSTION) .onRecipeBuild((builder, provider) -> { - if(builder.input.containsKey(FluidRecipeCapability.CAP)) { + if (builder.input.containsKey(FluidRecipeCapability.CAP)) { Content input = builder.input.get(FluidRecipeCapability.CAP).get(0); FluidIngredient ingredient = FluidRecipeCapability.CAP.of(input.getContent()); PowerlessJetpack.FUELS.put(ingredient, builder.duration); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java index db250e0052..b235375b84 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/armor/PowerlessJetpack.java @@ -13,8 +13,6 @@ import com.lowdragmc.lowdraglib.Platform; -import it.unimi.dsi.fastutil.objects.AbstractObject2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; @@ -36,6 +34,8 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack; +import it.unimi.dsi.fastutil.objects.AbstractObject2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,7 +62,7 @@ public PowerlessJetpack() { @Override public void onArmorTick(Level world, Player player, @NotNull ItemStack stack) { - if(!FluidUtil.getFluidHandler(stack).isPresent()) return; + if (!FluidUtil.getFluidHandler(stack).isPresent()) return; CompoundTag data = stack.getOrCreateTag(); @@ -98,7 +98,7 @@ public void onArmorTick(Level world, Player player, @NotNull ItemStack stack) { if (toggleTimer > 0) toggleTimer--; data.putByte("toggleTimer", toggleTimer); - if(currentFuel.isEmpty()) + if (currentFuel.isEmpty()) findNewRecipe(stack); performFlying(player, jetpackEnabled, hoverMode, stack); @@ -164,13 +164,13 @@ public int getEnergyPerUse() { @Override public boolean canUseEnergy(ItemStack stack, int amount) { - if(currentFuel.isEmpty()) return false; - if(burnTimer > 0) return true; + if (currentFuel.isEmpty()) return false; + if (burnTimer > 0) return true; var ret = FluidUtil.getFluidHandler(stack) .map(h -> h.drain(Integer.MAX_VALUE, FluidAction.SIMULATE)) .map(drained -> drained.getAmount() >= currentFuel.getAmount()) .orElse(Boolean.FALSE); - if(!ret) currentFuel = FluidIngredient.EMPTY; + if (!ret) currentFuel = FluidIngredient.EMPTY; return ret; } @@ -190,15 +190,15 @@ public boolean hasEnergy(ItemStack stack) { } public void findNewRecipe(@NotNull ItemStack stack) { - FluidUtil.getFluidContained(stack).ifPresentOrElse( fluid -> { - if(!previousFuel.isEmpty() && previousFuel.test(fluid) && + FluidUtil.getFluidContained(stack).ifPresentOrElse(fluid -> { + if (!previousFuel.isEmpty() && previousFuel.test(fluid) && fluid.getAmount() >= previousFuel.getAmount()) { currentFuel = previousFuel; return; } - for(var fuel : FUELS.keySet()) { - if(fuel.test(fluid) && fluid.getAmount() >= fuel.getAmount()) { + for (var fuel : FUELS.keySet()) { + if (fuel.test(fluid) && fluid.getAmount() >= fuel.getAmount()) { previousFuel = currentFuel = fuel; } } @@ -248,8 +248,8 @@ public Pair getDurabilityColorsForDisplay(ItemStack itemStack) @Override public boolean canFillFluidType(FluidStack fluid) { - for(var ingredient : FUELS.keySet()) { - if(ingredient.test(fluid)) return true; + for (var ingredient : FUELS.keySet()) { + if (ingredient.test(fluid)) return true; } return false; } From 4b5da08cbae19a8144c9bd1b26dff2a69a4cf1f6 Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Fri, 18 Oct 2024 03:44:49 -0400 Subject: [PATCH 22/22] Change where jetpack fuels get added for KJS compatibility --- .../gtceu/api/recipe/lookup/GTRecipeLookup.java | 9 +++++++++ .../gregtechceu/gtceu/common/data/GTRecipeTypes.java | 10 +--------- .../gtceu/core/mixins/RecipeManagerMixin.java | 2 ++ .../gtceu/integration/kjs/GregTechKubeJSPlugin.java | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java index b3450ee4f2..82f45c7484 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/lookup/GTRecipeLookup.java @@ -5,6 +5,9 @@ import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.api.recipe.content.Content; +import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.gregtechceu.gtceu.common.data.GTRecipeTypes; +import com.gregtechceu.gtceu.common.item.armor.PowerlessJetpack; import com.gregtechceu.gtceu.config.ConfigHolder; import com.lowdragmc.lowdraglib.Platform; @@ -460,6 +463,12 @@ public boolean addRecipe(GTRecipe recipe) { if (recipe == null) { return false; } + // Add combustion fuels to the Powerless Jetpack + if (recipe.getType() == GTRecipeTypes.COMBUSTION_GENERATOR_FUELS) { + Content content = recipe.getInputContents(FluidRecipeCapability.CAP).get(0); + FluidIngredient fluid = FluidRecipeCapability.CAP.of(content.content); + PowerlessJetpack.FUELS.put(fluid, recipe.duration); + } List> items = fromRecipe(recipe); return recurseIngredientTreeAdd(recipe, items, lookup, 0, 0); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index 9e74ea44d4..969297d197 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -16,7 +16,6 @@ import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.sound.ExistingSoundEntry; import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank; -import com.gregtechceu.gtceu.common.item.armor.PowerlessJetpack; import com.gregtechceu.gtceu.common.machine.trait.customlogic.CannerLogic; import com.gregtechceu.gtceu.common.machine.trait.customlogic.FormingPressLogic; import com.gregtechceu.gtceu.common.recipe.condition.RPMCondition; @@ -464,14 +463,7 @@ public class GTRecipeTypes { .setMaxIOSize(0, 0, 1, 0).setEUIO(IO.OUT) .setSlotOverlay(false, true, true, GuiTextures.FURNACE_OVERLAY_2) .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW_MULTIPLE, LEFT_TO_RIGHT) - .setSound(GTSoundEntries.COMBUSTION) - .onRecipeBuild((builder, provider) -> { - if (builder.input.containsKey(FluidRecipeCapability.CAP)) { - Content input = builder.input.get(FluidRecipeCapability.CAP).get(0); - FluidIngredient ingredient = FluidRecipeCapability.CAP.of(input.getContent()); - PowerlessJetpack.FUELS.put(ingredient, builder.duration); - } - }); + .setSound(GTSoundEntries.COMBUSTION); public final static GTRecipeType GAS_TURBINE_FUELS = register("gas_turbine", GENERATOR).setMaxIOSize(0, 0, 1, 0) .setEUIO(IO.OUT) diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/RecipeManagerMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/RecipeManagerMixin.java index 16a62f0d93..93cdf66a8f 100644 --- a/src/main/java/com/gregtechceu/gtceu/core/mixins/RecipeManagerMixin.java +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/RecipeManagerMixin.java @@ -2,6 +2,7 @@ import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.GTRecipeType; +import com.gregtechceu.gtceu.common.item.armor.PowerlessJetpack; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -33,6 +34,7 @@ public abstract class RecipeManagerMixin { at = @At(value = "TAIL")) private void gtceu$cloneVanillaRecipes(Map map, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo ci) { + PowerlessJetpack.FUELS.clear(); for (RecipeType recipeType : BuiltInRegistries.RECIPE_TYPE) { if (recipeType instanceof GTRecipeType gtRecipeType) { gtRecipeType.getLookup().removeAllRecipes(); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java index d88abb592f..3582360ec7 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java @@ -45,6 +45,7 @@ import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.data.*; import com.gregtechceu.gtceu.common.data.machines.GCyMMachines; +import com.gregtechceu.gtceu.common.item.armor.PowerlessJetpack; import com.gregtechceu.gtceu.common.unification.material.MaterialRegistryManager; import com.gregtechceu.gtceu.data.recipe.CraftingComponent; import com.gregtechceu.gtceu.data.recipe.builder.GTRecipeBuilder; @@ -443,6 +444,7 @@ public void injectRuntimeRecipes(RecipesEventJS event, RecipeManager manager, } }))); + PowerlessJetpack.FUELS.clear(); // clone vanilla recipes for stuff like electric furnaces, etc for (RecipeType recipeType : BuiltInRegistries.RECIPE_TYPE) { if (recipeType instanceof GTRecipeType gtRecipeType) {