diff --git a/gradle.properties b/gradle.properties index 1ddcef22b16..6ac47fb4b2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,14 +12,14 @@ minecraft_range=[1.18.2,1.19) # Fabric Version Information # check these on https://fabricmc.net/versions.html -fabric_version=0.87.0+1.20.1 +fabric_version=0.90.4+1.20.1 loader_version=0.14.21 # https://parchmentmc.org/docs/getting-started parchment_version=2023.03.12 # Build Dependencies -mantle_version=1.9.254 -port_lib_version = 2.1.1141 +mantle_version=1.9.255 +port_lib_version = 2.1.1152 mantle_range=[1.9.19,) milk_lib_version=1.2.58 dripstone_fluid_lib_version=3.0.1 diff --git a/src/main/java/slimeknights/tconstruct/common/data/AdvancementsProvider.java b/src/main/java/slimeknights/tconstruct/common/data/AdvancementsProvider.java index faf6faa2cf8..baf9f45a2c4 100644 --- a/src/main/java/slimeknights/tconstruct/common/data/AdvancementsProvider.java +++ b/src/main/java/slimeknights/tconstruct/common/data/AdvancementsProvider.java @@ -3,8 +3,11 @@ import com.google.common.collect.Sets; import com.google.gson.JsonObject; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementRewards; import net.minecraft.advancements.CriterionTriggerInstance; @@ -36,7 +39,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.material.Fluid; import slimeknights.mantle.data.GenericDataProvider; -import slimeknights.mantle.transfer.fluid.FluidTank; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.TinkerTags; import slimeknights.tconstruct.common.json.ConfigEnabledCondition; @@ -387,7 +389,7 @@ protected void generate() { /** Gets a tank filled with the given fluid */ private static FluidTank getTankWith(Fluid fluid, long capacity) { FluidTank tank = new FluidTank(capacity); - tank.fill(new FluidStack(fluid, capacity), false); + TransferUtil.insert(tank, FluidVariant.of(fluid), capacity); return tank; } diff --git a/src/main/java/slimeknights/tconstruct/library/client/model/ModelProperties.java b/src/main/java/slimeknights/tconstruct/library/client/model/ModelProperties.java index 2cc896dc746..7d241da666e 100644 --- a/src/main/java/slimeknights/tconstruct/library/client/model/ModelProperties.java +++ b/src/main/java/slimeknights/tconstruct/library/client/model/ModelProperties.java @@ -1,7 +1,7 @@ package slimeknights.tconstruct.library.client.model; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import slimeknights.mantle.client.model.ModelProperty; -import slimeknights.mantle.transfer.fluid.FluidTank; public class ModelProperties { public static final ModelProperty FLUID_TANK = new ModelProperty<>(); diff --git a/src/main/java/slimeknights/tconstruct/library/client/model/block/TankModel.java b/src/main/java/slimeknights/tconstruct/library/client/model/block/TankModel.java index 2132b20c3e1..aa415dbaa1a 100644 --- a/src/main/java/slimeknights/tconstruct/library/client/model/block/TankModel.java +++ b/src/main/java/slimeknights/tconstruct/library/client/model/block/TankModel.java @@ -10,6 +10,7 @@ import io.github.fabricators_of_create.porting_lib.models.geometry.IGeometryLoader; import io.github.fabricators_of_create.porting_lib.models.geometry.IUnbakedGeometry; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j2; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; @@ -43,7 +44,6 @@ import slimeknights.mantle.client.model.util.ColoredBlockModel; import slimeknights.mantle.client.model.util.ExtraTextureConfiguration; import slimeknights.mantle.client.model.util.SimpleBlockModel; -import slimeknights.mantle.transfer.fluid.FluidTank; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.config.Config; import slimeknights.tconstruct.library.client.model.ModelProperties; diff --git a/src/main/java/slimeknights/tconstruct/library/fluid/FluidTankBase.java b/src/main/java/slimeknights/tconstruct/library/fluid/FluidTankBase.java index c7183e32946..17282b7a29f 100644 --- a/src/main/java/slimeknights/tconstruct/library/fluid/FluidTankBase.java +++ b/src/main/java/slimeknights/tconstruct/library/fluid/FluidTankBase.java @@ -1,8 +1,8 @@ package slimeknights.tconstruct.library.fluid; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import net.minecraft.world.level.Level; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.fluid.FluidTank; import slimeknights.tconstruct.common.network.TinkerNetwork; import slimeknights.tconstruct.smeltery.network.FluidUpdatePacket; diff --git a/src/main/java/slimeknights/tconstruct/library/recipe/RandomItem.java b/src/main/java/slimeknights/tconstruct/library/recipe/RandomItem.java index 244732af389..7aca5468448 100644 --- a/src/main/java/slimeknights/tconstruct/library/recipe/RandomItem.java +++ b/src/main/java/slimeknights/tconstruct/library/recipe/RandomItem.java @@ -3,13 +3,13 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import io.netty.handler.codec.DecoderException; import lombok.RequiredArgsConstructor; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.util.GsonHelper; import net.minecraft.world.item.ItemStack; import slimeknights.mantle.recipe.helper.ItemOutput; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import java.util.Random; diff --git a/src/main/java/slimeknights/tconstruct/library/recipe/material/MaterialRecipe.java b/src/main/java/slimeknights/tconstruct/library/recipe/material/MaterialRecipe.java index 5c66198b8bc..246481eb8c9 100644 --- a/src/main/java/slimeknights/tconstruct/library/recipe/material/MaterialRecipe.java +++ b/src/main/java/slimeknights/tconstruct/library/recipe/material/MaterialRecipe.java @@ -1,5 +1,6 @@ package slimeknights.tconstruct.library.recipe.material; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import lombok.Getter; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; @@ -11,7 +12,6 @@ import slimeknights.mantle.recipe.ICustomOutputRecipe; import slimeknights.mantle.recipe.container.ISingleStackContainer; import slimeknights.mantle.recipe.helper.ItemOutput; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.library.materials.MaterialRegistry; import slimeknights.tconstruct.library.materials.definition.MaterialId; import slimeknights.tconstruct.library.materials.definition.MaterialVariant; diff --git a/src/main/java/slimeknights/tconstruct/library/recipe/melting/DamageableMeltingRecipe.java b/src/main/java/slimeknights/tconstruct/library/recipe/melting/DamageableMeltingRecipe.java index d7ed9fdc7de..29511c40e49 100644 --- a/src/main/java/slimeknights/tconstruct/library/recipe/melting/DamageableMeltingRecipe.java +++ b/src/main/java/slimeknights/tconstruct/library/recipe/melting/DamageableMeltingRecipe.java @@ -2,6 +2,9 @@ import com.google.gson.JsonObject; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; @@ -57,7 +60,7 @@ public FluidStack getOutput(IMeltingContainer inv) { } @Override - public void handleByproducts(IMeltingContainer inv, IFluidHandler handler) { + public void handleByproducts(IMeltingContainer inv, SlottedStorage handler) { ItemStack input = inv.getStack(); int maxDamage = input.getMaxDamage(); if (maxDamage <= 0) { @@ -67,7 +70,7 @@ public void handleByproducts(IMeltingContainer inv, IFluidHandler handler) { int itemDamage = input.getDamageValue(); for (int i = 0; i < byproducts.size(); i++) { FluidStack fluidStack = byproducts.get(i); - handler.fill(scaleOutput(fluidStack, itemDamage, maxDamage, i < byproductSizes.length ? byproductSizes[i] : unitSize), false); + TransferUtil.insertFluid(handler, scaleOutput(fluidStack, itemDamage, maxDamage, i < byproductSizes.length ? byproductSizes[i] : unitSize)); } } } diff --git a/src/main/java/slimeknights/tconstruct/library/recipe/melting/IMeltingRecipe.java b/src/main/java/slimeknights/tconstruct/library/recipe/melting/IMeltingRecipe.java index 543c31f7c73..f98f53063dd 100644 --- a/src/main/java/slimeknights/tconstruct/library/recipe/melting/IMeltingRecipe.java +++ b/src/main/java/slimeknights/tconstruct/library/recipe/melting/IMeltingRecipe.java @@ -1,6 +1,8 @@ package slimeknights.tconstruct.library.recipe.melting; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; import slimeknights.mantle.recipe.ICustomOutputRecipe; @@ -39,7 +41,7 @@ public interface IMeltingRecipe extends ICustomOutputRecipe { * @param inv Input inventory * @param handler Fluid handler to fill with the byproduct */ - default void handleByproducts(IMeltingContainer inv, IFluidHandler handler) {} + default void handleByproducts(IMeltingContainer inv, SlottedStorage handler) {} /* Recipe data */ diff --git a/src/main/java/slimeknights/tconstruct/library/recipe/melting/MeltingRecipe.java b/src/main/java/slimeknights/tconstruct/library/recipe/melting/MeltingRecipe.java index c468841f103..d4e0828624d 100644 --- a/src/main/java/slimeknights/tconstruct/library/recipe/melting/MeltingRecipe.java +++ b/src/main/java/slimeknights/tconstruct/library/recipe/melting/MeltingRecipe.java @@ -4,8 +4,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import lombok.Getter; import lombok.RequiredArgsConstructor; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -85,10 +88,10 @@ public OreRateType getOreType() { } @Override - public void handleByproducts(IMeltingContainer inv, IFluidHandler handler) { + public void handleByproducts(IMeltingContainer inv, SlottedStorage handler) { // fill byproducts until we run out of space or byproducts for (FluidStack fluidStack : byproducts) { - handler.fill(fluidStack.copy(), false); + TransferUtil.insertFluid(handler, fluidStack.copy()); } } diff --git a/src/main/java/slimeknights/tconstruct/library/tools/capability/ToolInventoryCapability.java b/src/main/java/slimeknights/tconstruct/library/tools/capability/ToolInventoryCapability.java index c213abd7474..d64253d63ce 100644 --- a/src/main/java/slimeknights/tconstruct/library/tools/capability/ToolInventoryCapability.java +++ b/src/main/java/slimeknights/tconstruct/library/tools/capability/ToolInventoryCapability.java @@ -11,7 +11,6 @@ import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage; -import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; @@ -23,9 +22,6 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import slimeknights.mantle.transfer.item.IItemHandler; -import slimeknights.mantle.transfer.item.IItemHandlerModifiable; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.TinkerTags; import slimeknights.tconstruct.library.modifiers.ModifierEntry; @@ -177,9 +173,9 @@ public static boolean isBlacklisted(ItemStack stack) { } @Override - public boolean isItemValid(int slot, ItemVariant stack) { + public boolean isItemValid(int slot, ItemVariant stack, int count) { // no nesting item handlers - if (!stack.isBlank() && isBlacklisted(stack.toStack())) { + if (!stack.isBlank() && isBlacklisted(stack.toStack(count))) { return false; } IToolStackView tool = this.tool.get(); diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/DuctBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/DuctBlockEntity.java index 597fd302ea9..a2661e7f655 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/DuctBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/DuctBlockEntity.java @@ -2,10 +2,11 @@ import io.github.fabricators_of_create.porting_lib.block.CustomUpdateTagHandlingBlockEntity; -import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; import net.minecraft.core.BlockPos; @@ -19,8 +20,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.transfer.item.IItemHandler; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.smeltery.TinkerSmeltery; import slimeknights.tconstruct.smeltery.block.entity.component.SmelteryInputOutputBlockEntity.SmelteryFluidIO; @@ -74,8 +73,8 @@ public Storage getItemStorage(@org.jetbrains.annotations.Nullable D } @Override - protected LazyOptional makeWrapper(LazyOptional capability) { - return LazyOptional.of(() -> new DuctTankWrapper(capability.orElse(emptyInstance), itemHandler)); + protected Storage makeWrapper(SlottedStorage capability) { + return new DuctTankWrapper(capability, itemHandler); } /** Updates the fluid in model data */ diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/SmelteryInputOutputBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/SmelteryInputOutputBlockEntity.java index a0f39aee25f..d48a507ae21 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/SmelteryInputOutputBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/SmelteryInputOutputBlockEntity.java @@ -3,10 +3,19 @@ import io.github.fabricators_of_create.porting_lib.common.util.NonNullConsumer; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; +import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; @@ -16,13 +25,6 @@ import slimeknights.mantle.client.model.data.IModelData; import slimeknights.mantle.client.model.data.ModelDataMap; import slimeknights.mantle.client.model.data.SinglePropertyData; -import slimeknights.mantle.inventory.EmptyItemHandler; -import slimeknights.mantle.transfer.TransferUtil; -import slimeknights.mantle.transfer.fluid.EmptyFluidHandler; -import slimeknights.mantle.transfer.fluid.FluidTransferable; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.transfer.item.IItemHandler; -import slimeknights.mantle.transfer.item.ItemTransferable; import slimeknights.mantle.util.RetexturedHelper; import slimeknights.mantle.util.WeakConsumerWrapper; import slimeknights.tconstruct.smeltery.TinkerSmeltery; @@ -40,13 +42,13 @@ */ public abstract class SmelteryInputOutputBlockEntity extends SmelteryComponentBlockEntity implements IRetexturedBlockEntity { /** Capability this TE watches */ - private final Class capability; + private final BlockApiLookup, @org.jetbrains.annotations.Nullable Direction> capability; /** Empty capability for in case the valid capability becomes invalid without invalidating */ - protected final T emptyInstance; + protected final Storage emptyInstance = Storage.empty(); /** Listener to attach to consumed capabilities */ protected final NonNullConsumer> listener = new WeakConsumerWrapper<>(this, (te, cap) -> te.clearHandler()); @Nullable - private LazyOptional capabilityHolder = null; + private Storage capabilityHolder = null; /* Retexturing */ @Getter @@ -55,16 +57,14 @@ public abstract class SmelteryInputOutputBlockEntity extends SmelteryComponen @Getter private Block texture = Blocks.AIR; - protected SmelteryInputOutputBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, Class capability, T emptyInstance) { + protected SmelteryInputOutputBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, BlockApiLookup, @org.jetbrains.annotations.Nullable Direction> capability) { super(type, pos, state); this.capability = capability; - this.emptyInstance = emptyInstance; } /** Clears all cached capabilities */ private void clearHandler() { if (capabilityHolder != null) { - capabilityHolder.invalidate(); capabilityHolder = null; } } @@ -94,35 +94,27 @@ protected void setMaster(@Nullable BlockPos master, @Nullable Block block) { /** * Gets the capability to store in this IO block. Capability parent should have the proper listeners attached - * @param parent Parent tile entity + * @param level Parent level + * @param pos Parent pos * @return Capability from parent, or empty if absent */ - protected LazyOptional getCapability(BlockEntity parent) { - LazyOptional handler = (LazyOptional) TransferUtil.getHandler(parent, null, capability); // TODO: PORT this shouldnt need to be casted? - if (handler.isPresent()) { - handler.addListener(listener); - - return LazyOptional.of(() -> handler.orElse(emptyInstance)); - } - return LazyOptional.empty(); + protected Storage getCapability(Level level, BlockPos pos) { + return capability.find(level, pos, null); } /** * Fetches the capability handlers if missing */ - protected LazyOptional getCachedCapability() { + protected Storage getCachedCapability() { if (capabilityHolder == null) { if (validateMaster()) { BlockPos master = getMasterPos(); if (master != null && this.level != null) { - BlockEntity te = level.getBlockEntity(master); - if (te != null) { - capabilityHolder = getCapability(te); - return capabilityHolder; - } + capabilityHolder = getCapability(level, master); + return capabilityHolder; } } - capabilityHolder = LazyOptional.empty(); + capabilityHolder = null; } return capabilityHolder; } @@ -190,27 +182,27 @@ public IModelData getRenderAttachmentData() { } /** Fluid implementation of smeltery IO */ - public static abstract class SmelteryFluidIO extends SmelteryInputOutputBlockEntity implements FluidTransferable { + public static abstract class SmelteryFluidIO extends SmelteryInputOutputBlockEntity implements SidedStorageBlockEntity { protected SmelteryFluidIO(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state, IFluidHandler.class, EmptyFluidHandler.INSTANCE); + super(type, pos, state, FluidStorage.SIDED); } /** Wraps the given capability */ - protected LazyOptional makeWrapper(LazyOptional capability) { - return LazyOptional.of(() -> capability.orElse(emptyInstance)); + protected Storage makeWrapper(SlottedStorage capability) { + return capability; } @Override - protected LazyOptional getCapability(BlockEntity parent) { + protected Storage getCapability(Level level, BlockPos pos) { // fluid capability is not exposed directly in the smeltery + BlockEntity parent = level.getBlockEntity(pos); if (parent instanceof ISmelteryTankHandler) { - LazyOptional capability = ((ISmelteryTankHandler) parent).getFluidCapability(); - if (capability.isPresent()) { - capability.addListener(listener); + SlottedStorage capability = ((ISmelteryTankHandler) parent).getFluidCapability(); + if (capability != null) { return makeWrapper(capability); } } - return LazyOptional.empty(); + return null; } @Override @@ -225,24 +217,24 @@ public IModelData getRetexturedModelData() { @Nullable @Override - public LazyOptional getFluidHandler(@Nullable Direction direction) { + public Storage getFluidStorage(@Nullable Direction direction) { return getCachedCapability(); } } /** Item implementation of smeltery IO */ - public static class ChuteBlockEntity extends SmelteryInputOutputBlockEntity implements ItemTransferable { + public static class ChuteBlockEntity extends SmelteryInputOutputBlockEntity implements SidedStorageBlockEntity { public ChuteBlockEntity(BlockPos pos, BlockState state) { this(TinkerSmeltery.chute.get(), pos, state); } protected ChuteBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state, IItemHandler.class, EmptyItemHandler.INSTANCE); + super(type, pos, state, ItemStorage.SIDED); } @Nullable @Override - public LazyOptional getItemHandler(@Nullable Direction direction) { + public Storage getItemStorage(@Nullable Direction direction) { return getCachedCapability(); } } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/TankBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/TankBlockEntity.java index 9e0c378fcbc..c4e0a8f34d4 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/TankBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/component/TankBlockEntity.java @@ -1,11 +1,15 @@ package slimeknights.tconstruct.smeltery.block.entity.component; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; import lombok.Setter; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -16,8 +20,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import slimeknights.mantle.client.model.data.SinglePropertyData; -import slimeknights.mantle.transfer.fluid.FluidTank; -import slimeknights.mantle.transfer.fluid.FluidTransferable; import slimeknights.mantle.transfer.fluid.IFluidHandler; import slimeknights.tconstruct.library.client.model.ModelProperties; import slimeknights.tconstruct.library.fluid.FluidTankAnimated; @@ -30,7 +32,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class TankBlockEntity extends SmelteryComponentBlockEntity implements ITankBlockEntity, FluidTransferable, RenderAttachmentBlockEntity { +public class TankBlockEntity extends SmelteryComponentBlockEntity implements ITankBlockEntity, SidedStorageBlockEntity, RenderAttachmentBlockEntity { /** Max capacity for the tank */ public static final long DEFAULT_CAPACITY = FluidConstants.BUCKET * 4; @@ -61,8 +63,6 @@ public static long getCapacity(Item item) { /** Internal fluid tank instance */ @Getter protected final FluidTankAnimated tank; - /** Capability holder for the tank */ - private final LazyOptional holder; /** Tank data for the model */ private final SinglePropertyData modelData; /** Last comparator strength to reduce block updates */ @@ -85,7 +85,6 @@ public TankBlockEntity(BlockPos pos, BlockState state, ITankBlock block) { protected TankBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, ITankBlock block) { super(type, pos, state); tank = new FluidTankAnimated(block.getCapacity(), this); - holder = LazyOptional.of(() -> tank); modelData = new SinglePropertyData<>(ModelProperties.FLUID_TANK, tank); } @@ -96,14 +95,8 @@ protected TankBlockEntity(BlockEntityType type, BlockPos pos, BlockState stat @Override @Nonnull - public LazyOptional getFluidHandler(@Nullable Direction direction) { - return holder.cast(); - } - - @Override - public void invalidateCaps() { - super.invalidateCaps(); - holder.invalidate(); + public Storage getFluidStorage(@Nullable Direction direction) { + return tank; } @Nonnull diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/AlloyerBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/AlloyerBlockEntity.java index ed83a7ae81e..c65e97a016e 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/AlloyerBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/AlloyerBlockEntity.java @@ -3,6 +3,9 @@ import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; import lombok.Setter; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -15,7 +18,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import slimeknights.mantle.block.entity.NameableBlockEntity; -import slimeknights.mantle.transfer.fluid.FluidTransferable; import slimeknights.mantle.transfer.fluid.IFluidHandler; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.TinkerTags; @@ -38,7 +40,7 @@ /** * Dedicated alloying block */ -public class AlloyerBlockEntity extends NameableBlockEntity implements ITankBlockEntity, FluidTransferable { +public class AlloyerBlockEntity extends NameableBlockEntity implements ITankBlockEntity, SidedStorageBlockEntity { /** Max capacity for the tank */ private static final long TANK_CAPACITY = TankType.INGOT_TANK.getCapacity(); /** Name of the container */ @@ -49,8 +51,6 @@ public class AlloyerBlockEntity extends NameableBlockEntity implements ITankBloc /** Tank for this mixer */ @Getter protected final FluidTankAnimated tank = new FluidTankAnimated(TANK_CAPACITY, this); - /* Capability for return */ - private final LazyOptional tankHolder = LazyOptional.of(() -> tank); // modules /** Logic for a mixer alloying */ @@ -83,14 +83,8 @@ protected AlloyerBlockEntity(BlockEntityType type, BlockPos pos, BlockState s @Nonnull @Override - public LazyOptional getFluidHandler(@org.jetbrains.annotations.Nullable Direction direction) { - return tankHolder.cast(); - } - - // @Override - public void invalidateCaps() { -// super.invalidateCaps(); - this.tankHolder.invalidate(); + public Storage getFluidStorage(@org.jetbrains.annotations.Nullable Direction direction) { + return tank; } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/HeatingStructureBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/HeatingStructureBlockEntity.java index ac334aa041e..4477c5856db 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/HeatingStructureBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/HeatingStructureBlockEntity.java @@ -6,7 +6,9 @@ import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; @@ -100,8 +102,8 @@ public abstract class HeatingStructureBlockEntity extends NameableBlockEntity im @Getter protected final SmelteryTank tank = new SmelteryTank<>(this); /** Capability to pass to drains for fluid handling */ - @Getter - private LazyOptional fluidCapability = LazyOptional.empty(); + @Nullable @Getter + private SlottedStorage fluidCapability; /** Inventory handling melting items */ @Getter @@ -318,8 +320,8 @@ protected void checkStructure() { new StructureUpdatePacket(worldPosition, newStructure.getMinPos(), newStructure.getMaxPos(), newStructure.getTanks()), level, worldPosition); // update tank capability, do first for update listeners on the drain blocks - if (!fluidCapability.isPresent()) { - fluidCapability = LazyOptional.of(() -> tank); + if (fluidCapability == null) { + fluidCapability = tank; } // set master positions @@ -327,9 +329,8 @@ protected void checkStructure() { setStructure(newStructure); } else { // remove tank capability - if (fluidCapability.isPresent()) { - fluidCapability.invalidate(); - fluidCapability = LazyOptional.empty(); + if (fluidCapability != null) { + fluidCapability = null; } // clear positions @@ -565,7 +566,7 @@ public void load(CompoundTag nbt) { if (nbt.contains(TAG_STRUCTURE, Tag.TAG_COMPOUND)) { setStructure(multiblock.readFromTag(nbt.getCompound(TAG_STRUCTURE))); if (structure != null) { - fluidCapability = LazyOptional.of(() -> tank); + fluidCapability = tank; } } // only exists to be sent server to client in update packets diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/MelterBlockEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/MelterBlockEntity.java index 77397891cda..c0422d31fce 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/MelterBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/controller/MelterBlockEntity.java @@ -1,10 +1,11 @@ package slimeknights.tconstruct.smeltery.block.entity.controller; import io.github.fabricators_of_create.porting_lib.block.ChunkUnloadListeningBlockEntity; -import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import lombok.Getter; import lombok.Setter; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.base.SidedStorageBlockEntity; @@ -22,10 +23,6 @@ import net.minecraft.world.level.block.state.BlockState; import slimeknights.mantle.block.entity.NameableBlockEntity; import slimeknights.mantle.client.model.data.SinglePropertyData; -import slimeknights.mantle.transfer.fluid.FluidTank; -import slimeknights.mantle.transfer.fluid.FluidTransferable; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.transfer.item.IItemHandler; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.TinkerTags; import slimeknights.tconstruct.common.config.Config; @@ -44,7 +41,7 @@ import javax.annotation.Nullable; import java.util.Collections; -public class MelterBlockEntity extends NameableBlockEntity implements ITankBlockEntity, FluidTransferable, SidedStorageBlockEntity, ChunkUnloadListeningBlockEntity, RenderAttachmentBlockEntity { +public class MelterBlockEntity extends NameableBlockEntity implements ITankBlockEntity, SidedStorageBlockEntity, ChunkUnloadListeningBlockEntity, RenderAttachmentBlockEntity { /** Max capacity for the tank */ private static final long TANK_CAPACITY = FluidValues.INGOT * 12; @@ -59,8 +56,6 @@ public class MelterBlockEntity extends NameableBlockEntity implements ITankBlock /** Internal fluid tank output */ @Getter protected final FluidTankAnimated tank = new FluidTankAnimated(TANK_CAPACITY, this); - /** Capability holder for the tank */ - private final LazyOptional tankHolder = LazyOptional.of(() -> tank); /** Tank data for the model */ @Getter private final SinglePropertyData modelData = new SinglePropertyData<>(ModelProperties.FLUID_TANK, tank); @@ -115,8 +110,8 @@ public AbstractContainerMenu createMenu(int id, Inventory inv, Player playerEnti @Nullable @Override - public LazyOptional getFluidHandler(@Nullable Direction direction) { - return tankHolder; + public Storage getFluidStorage(@Nullable Direction direction) { + return tank; } @Nullable @@ -135,12 +130,6 @@ public void setRemoved() { public void onChunkUnloaded() { invalidateCaps(); } - -// @Override - public void invalidateCaps() { -// super.invalidateCaps(); - this.tankHolder.invalidate(); - } /* * Melting diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/inventory/DuctTankWrapper.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/inventory/DuctTankWrapper.java index dcbc11a0288..2821601980d 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/inventory/DuctTankWrapper.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/inventory/DuctTankWrapper.java @@ -1,62 +1,53 @@ package slimeknights.tconstruct.smeltery.block.entity.inventory; -import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; import lombok.AllArgsConstructor; -import slimeknights.mantle.transfer.fluid.IFluidHandler; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; + +import java.util.Iterator; @AllArgsConstructor -public class DuctTankWrapper implements IFluidHandler { - private final IFluidHandler parent; +public class DuctTankWrapper implements SlottedStorage { + private final SlottedStorage parent; private final DuctItemHandler itemHandler; /* Properties */ @Override - public int getTanks() { - return parent.getTanks(); + public int getSlotCount() { + return parent.getSlotCount(); } @Override - public FluidStack getFluidInTank(int tank) { - return parent.getFluidInTank(tank); + public SingleSlotStorage getSlot(int tank) { + return parent.getSlot(tank); } @Override - public long getTankCapacity(int tank) { - return parent.getTankCapacity(tank); - } - - @Override - public boolean isFluidValid(int tank, FluidStack stack) { - return itemHandler.getFluid().isFluidEqual(stack); + public Iterator> iterator() { + return parent.iterator(); } /* Interactions */ @Override - public long fill(FluidStack resource, boolean sim) { - if (resource.isEmpty() || !itemHandler.getFluid().isFluidEqual(resource)) { + public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { + if ((maxAmount <= 0 || resource.isBlank()) || !itemHandler.getFluid().isFluidEqual(resource)) { return 0; } - return parent.fill(resource, sim); + return parent.insert(resource, maxAmount, transaction); } @Override - public FluidStack drain(long maxDrain, boolean sim) { - FluidStack fluid = itemHandler.getFluid(); - if (fluid.isEmpty()) { - return FluidStack.EMPTY; - } - return parent.drain(new FluidStack(fluid, maxDrain), sim); - } - - @Override - public FluidStack drain(FluidStack resource, boolean sim) { - if (resource.isEmpty() || !itemHandler.getFluid().isFluidEqual(resource)) { - return FluidStack.EMPTY; + public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { + if ((maxAmount <= 0 || resource.isBlank()) || !itemHandler.getFluid().isFluidEqual(resource)) { + return 0; } - return parent.drain(resource, sim); + return parent.extract(resource, maxAmount, transaction); } } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/ByproductMeltingModuleInventory.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/ByproductMeltingModuleInventory.java index cb79984e1fa..bfdfdb2fd70 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/ByproductMeltingModuleInventory.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/ByproductMeltingModuleInventory.java @@ -1,16 +1,18 @@ package slimeknights.tconstruct.smeltery.block.entity.module; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import slimeknights.mantle.block.entity.MantleBlockEntity; import slimeknights.mantle.transfer.fluid.IFluidHandler; import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer.IOreRate; import slimeknights.tconstruct.library.recipe.melting.IMeltingRecipe; public class ByproductMeltingModuleInventory extends MeltingModuleInventory { - public ByproductMeltingModuleInventory(MantleBlockEntity parent, IFluidHandler fluidHandler, IOreRate oreRate, int size) { + public ByproductMeltingModuleInventory(MantleBlockEntity parent, SlottedStorage fluidHandler, IOreRate oreRate, int size) { super(parent, fluidHandler, oreRate, size); } - public ByproductMeltingModuleInventory(MantleBlockEntity parent, IFluidHandler fluidHandler, IOreRate oreRate) { + public ByproductMeltingModuleInventory(MantleBlockEntity parent, SlottedStorage fluidHandler, IOreRate oreRate) { super(parent, fluidHandler, oreRate); } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/EntityMeltingModule.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/EntityMeltingModule.java index a96f4330a87..1ea44049c56 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/EntityMeltingModule.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/EntityMeltingModule.java @@ -1,7 +1,11 @@ package slimeknights.tconstruct.smeltery.block.entity.module; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import lombok.RequiredArgsConstructor; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; @@ -34,7 +38,7 @@ @RequiredArgsConstructor public class EntityMeltingModule { private final MantleBlockEntity parent; - private final IFluidHandler tank; + private final SlottedStorage tank; /** Supplier that returns true if the tank has space */ private final BooleanSupplier canMeltEntities; /** Function that tries to insert an item into the inventory */ @@ -144,7 +148,10 @@ else if (canMelt != Boolean.FALSE && !type.is(EntityTypes.MELTING_HIDE) && entit // if the entity is successfully damaged, fill the tank with fluid if (entity.hurt(entity.fireImmune() ? TinkerDamageTypes.getSource(entity.level().registryAccess(), TinkerDamageTypes.SMELTERY_MAGIC) : TinkerDamageTypes.getSource(entity.level().registryAccess(), TinkerDamageTypes.SMELTERY_DAMAGE), damage)) { // its fine if we don't fill it all, leftover fluid is just lost - tank.fill(fluid, false); + try (Transaction tx = TransferUtil.getTransaction()) { + tank.insert(fluid.getType(), fluid.getAmount(), tx); + tx.commit(); + } melted = true; } } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/FuelModule.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/FuelModule.java index f8842ae5f71..59a22e599bc 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/FuelModule.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/FuelModule.java @@ -1,6 +1,7 @@ package slimeknights.tconstruct.smeltery.block.entity.module; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import io.github.fabricators_of_create.porting_lib.common.util.NonNullConsumer; import io.github.fabricators_of_create.porting_lib.common.util.NonNullFunction; @@ -9,6 +10,14 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import net.fabricmc.fabric.api.registry.FuelRegistry; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -20,10 +29,6 @@ import net.minecraft.world.level.material.Fluid; import org.jetbrains.annotations.Nullable; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.TransferUtil; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.transfer.item.IItemHandler; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.mantle.util.WeakConsumerWrapper; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.library.recipe.fuel.MeltingFuel; @@ -47,8 +52,8 @@ public class FuelModule implements ContainerData { public static final int SOLID_TEMPERATURE = 800; /** Listener to attach to stored capability */ - private final NonNullConsumer> fluidListener = new WeakConsumerWrapper<>(this, (self, cap) -> self.reset()); - private final NonNullConsumer> itemListener = new WeakConsumerWrapper<>(this, (self, cap) -> self.reset()); + private final NonNullConsumer> fluidListener = new WeakConsumerWrapper<>(this, (self, cap) -> self.reset()); + private final NonNullConsumer> itemListener = new WeakConsumerWrapper<>(this, (self, cap) -> self.reset()); /** Parent TE */ private final MantleBlockEntity parent; @@ -60,18 +65,18 @@ public class FuelModule implements ContainerData { private MeltingFuel lastRecipe; /** Last fluid handler where fluid was extracted */ @Nullable - private LazyOptional fluidHandler; + private Storage fluidHandler; /** Last item handler where items were extracted */ @Nullable - private LazyOptional itemHandler; + private Storage itemHandler; /** Position of the last fluid handler */ private BlockPos lastPos = NULL_POS; /** Client fuel display */ - private List> tankDisplayHandlers; + private List> tankDisplayHandlers; /** Listener to attach to display capabilities */ - private final NonNullConsumer> displayListener = new WeakConsumerWrapper<>(this, (self, cap) -> { + private final NonNullConsumer> displayListener = new WeakConsumerWrapper<>(this, (self, cap) -> { if (self.tankDisplayHandlers != null) { self.tankDisplayHandlers.remove(cap); } @@ -145,22 +150,21 @@ public void decreaseFuel(int amount) { /* Fuel updating */ /* Cache of objects, since they are otherwise created possibly several times */ - private final NonNullFunction trySolidFuelConsume = handler -> trySolidFuel(handler, true); - private final NonNullFunction trySolidFuelNoConsume = handler -> trySolidFuel(handler, false); - private final NonNullFunction tryLiquidFuelConsume = handler -> tryLiquidFuel(handler, true); - private final NonNullFunction tryLiquidFuelNoConsume = handler -> tryLiquidFuel(handler, false); + private final NonNullFunction,Integer> trySolidFuelConsume = handler -> trySolidFuel(handler, true); + private final NonNullFunction,Integer> trySolidFuelNoConsume = handler -> trySolidFuel(handler, false); + private final NonNullFunction,Integer> tryLiquidFuelConsume = handler -> tryLiquidFuel(handler, true); + private final NonNullFunction,Integer> tryLiquidFuelNoConsume = handler -> tryLiquidFuel(handler, false); /** * Tries to consume fuel from the given fluid handler * @param handler Handler to consume fuel from * @return Temperature of the consumed fuel, 0 if none found */ - private int trySolidFuel(IItemHandler handler, boolean consume) { - for (int i = 0; i < handler.getSlots(); i++) { - ItemStack stack = handler.getStackInSlot(i); + private int trySolidFuel(Storage handler, boolean consume) { + for (StorageView view : handler) { int time = 0; - if (FuelRegistry.INSTANCE.get(stack.getItem()) != null) - time = FuelRegistry.INSTANCE.get(stack.getItem()/*, TinkerRecipeTypes.FUEL.get()*/) / 4; + if (FuelRegistry.INSTANCE.get(view.getResource().getItem()) != null) + time = FuelRegistry.INSTANCE.get(view.getResource().getItem()/*, TinkerRecipeTypes.FUEL.get()*/) / 4; if (time > 0) { if (consume) { ItemStack extracted = handler.extractItem(i, 1, false); @@ -200,7 +204,7 @@ private int trySolidFuel(IItemHandler handler, boolean consume) { * @param consume If true, fuel is consumed * @return Mapper function for solid fuel */ - private NonNullFunction trySolidFuel(boolean consume) { + private NonNullFunction,Integer> trySolidFuel(boolean consume) { return consume ? trySolidFuelConsume : trySolidFuelNoConsume; } @@ -209,16 +213,19 @@ private NonNullFunction trySolidFuel(boolean consume) { * @param handler Handler to consume fuel from * @return Temperature of the consumed fuel, 0 if none found */ - private int tryLiquidFuel(IFluidHandler handler, boolean consume) { - FluidStack fluid = handler.getFluidInTank(0); + private int tryLiquidFuel(Storage handler, boolean consume) { + FluidStack fluid = TransferUtil.getFirstFluid(handler); MeltingFuel recipe = findRecipe(fluid.getFluid()); if (recipe != null) { long amount = recipe.getAmount(fluid.getFluid()); if (fluid.getAmount() >= amount) { if (consume) { - FluidStack drained = handler.drain(new FluidStack(fluid, amount), false); - if (drained.getAmount() != amount) { - TConstruct.LOG.error("Invalid amount of fuel drained from tank"); + try (Transaction tx = TransferUtil.getTransaction()) { + long drained = handler.extract(fluid.getType(), amount, tx); + tx.commit(); + if (drained != amount) { + TConstruct.LOG.error("Invalid amount of fuel drained from tank"); + } } fuel += recipe.getDuration(); fuelQuality = recipe.getDuration(); @@ -238,7 +245,7 @@ private int tryLiquidFuel(IFluidHandler handler, boolean consume) { * @param consume If true, fuel is consumed * @return Mapper function for liquid fuel */ - private NonNullFunction tryLiquidFuel(boolean consume) { + private NonNullFunction,Integer> tryLiquidFuel(boolean consume) { return consume ? tryLiquidFuelConsume : tryLiquidFuelNoConsume; } @@ -249,29 +256,28 @@ private NonNullFunction tryLiquidFuel(boolean consume) { */ private int tryFindFuel(BlockPos pos, boolean consume) { BlockEntity te = getLevel().getBlockEntity(pos); - if (te != null) { - // if we find a valid cap, try to consume fuel from it - LazyOptional capability = TransferUtil.getFluidHandler(te); - Optional temperature = capability.map(tryLiquidFuel(consume)); + // if we find a valid cap, try to consume fuel from it + Storage storage = FluidStorage.SIDED.find(getLevel(), pos, null); + Optional temperature = Optional.ofNullable(storage).map(tryLiquidFuel(consume)); + if (temperature.isPresent()) { + itemHandler = null; + fluidHandler = storage; + tankDisplayHandlers = null; +// storage.addListener(fluidListener); + throw new RuntimeException("Add listener"); + lastPos = pos; + return temperature.get(); + } else { + // if we find a valid item cap, consume fuel from that + LazyOptional itemCap = TransferUtil.getItemHandler(te); + temperature = itemCap.map(trySolidFuel(consume)); if (temperature.isPresent()) { - itemHandler = null; - fluidHandler = capability; + fluidHandler = null; tankDisplayHandlers = null; - capability.addListener(fluidListener); + itemHandler = itemCap; + itemCap.addListener(itemListener); lastPos = pos; return temperature.get(); - } else { - // if we find a valid item cap, consume fuel from that - LazyOptional itemCap = TransferUtil.getItemHandler(te); - temperature = itemCap.map(trySolidFuel(consume)); - if (temperature.isPresent()) { - fluidHandler = null; - tankDisplayHandlers = null; - itemHandler = itemCap; - itemCap.addListener(itemListener); - lastPos = pos; - return temperature.get(); - } } } @@ -286,9 +292,9 @@ public int findFuel(boolean consume) { // if we have a handler, try to use that if possible Optional handlerTemp = Optional.empty(); if (fluidHandler != null) { - handlerTemp = fluidHandler.map(tryLiquidFuel(consume)); + handlerTemp = Optional.of(fluidHandler).map(tryLiquidFuel(consume)); } else if (itemHandler != null) { - handlerTemp = itemHandler.map(trySolidFuel(consume)); + handlerTemp = Optional.of(itemHandler).map(trySolidFuel(consume)); // if no handler, try to find one at the last position } else if (lastPos != NULL_POS) { int posTemp = tryFindFuel(lastPos, consume); @@ -439,26 +445,22 @@ public FuelInfo getFuelInfo() { // fetch primary fuel handler if (fluidHandler == null && itemHandler == null) { BlockEntity te = getLevel().getBlockEntity(mainTank); - if (te != null) { - LazyOptional fluidCap = TransferUtil.getFluidHandler(te); - if (fluidCap.isPresent()) { - fluidHandler = fluidCap; - fluidHandler.addListener(fluidListener); - } else { - LazyOptional itemCap = TransferUtil.getItemHandler(te); - if (itemCap.isPresent()) { - itemHandler = itemCap; - itemHandler.addListener(itemListener); - } + Storage fluidCap = FluidStorage.SIDED.find(getLevel(), mainTank, null); + if (fluidCap != null) { + fluidHandler = fluidCap; +// fluidHandler.addListener(fluidListener); + throw new RuntimeException("Add listener"); + } else { + Storage itemCap = ItemStorage.SIDED.find(getLevel(), mainTank, null); + if (itemCap != null) { + itemHandler = itemCap; +// itemHandler.addListener(itemListener); + throw new RuntimeException("Add listener"); } } } - // ensure all handlers are set - if (fluidHandler == null) fluidHandler = LazyOptional.empty(); - if (itemHandler == null) itemHandler = LazyOptional.empty(); - // if its an item, stop here - if (itemHandler.isPresent()) { + if (itemHandler != null) { return FuelInfo.ITEM; } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModule.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModule.java index a8f92deac7c..8e75bcb7c48 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModule.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModule.java @@ -1,5 +1,6 @@ package slimeknights.tconstruct.smeltery.block.entity.module; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import lombok.Getter; import lombok.RequiredArgsConstructor; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage; @@ -8,7 +9,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.common.network.InventorySlotSyncPacket; import slimeknights.tconstruct.common.network.TinkerNetwork; import slimeknights.tconstruct.library.recipe.TinkerRecipeTypes; diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModuleInventory.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModuleInventory.java index 6125f863ff4..c4a99ab1058 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModuleInventory.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/MeltingModuleInventory.java @@ -1,19 +1,21 @@ package slimeknights.tconstruct.smeltery.block.entity.module; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.transfer.item.SlottedStackStorage; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.inventory.ContainerData; import net.minecraft.world.item.ItemStack; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer.IOreRate; import slimeknights.tconstruct.library.recipe.melting.IMeltingRecipe; @@ -35,7 +37,7 @@ public class MeltingModuleInventory implements SlottedStackStorage, TransactionC /** Parent tile entity */ private final MantleBlockEntity parent; /** Fluid handler for outputs */ - protected final IFluidHandler fluidHandler; + protected final SlottedStorage fluidHandler; /** Array of modules containing each slot */ private MeltingModule[] modules; /** If true, module cannot be resized */ @@ -50,7 +52,7 @@ public class MeltingModuleInventory implements SlottedStackStorage, TransactionC * @param oreRate Ore rate * @param size Size */ - public MeltingModuleInventory(MantleBlockEntity parent, IFluidHandler fluidHandler, IOreRate oreRate, int size) { + public MeltingModuleInventory(MantleBlockEntity parent, SlottedStorage fluidHandler, IOreRate oreRate, int size) { this.parent = parent; this.fluidHandler = fluidHandler; this.modules = new MeltingModule[size]; @@ -64,7 +66,7 @@ public MeltingModuleInventory(MantleBlockEntity parent, IFluidHandler fluidHandl * @param fluidHandler Tank for output * @param oreRate Ore rate */ - public MeltingModuleInventory(MantleBlockEntity parent, IFluidHandler fluidHandler, IOreRate oreRate) { + public MeltingModuleInventory(MantleBlockEntity parent, SlottedStorage fluidHandler, IOreRate oreRate) { this(parent, fluidHandler, oreRate, 0); } @@ -90,7 +92,7 @@ public int getSlotLimit(int slot) { } @Override - public boolean isItemValid(int slot, ItemVariant stack) { + public boolean isItemValid(int slot, ItemVariant stack, int count) { return true; } @@ -273,8 +275,11 @@ public boolean canHeat(int temperature) { */ protected boolean tryFillTank(int index, IMeltingRecipe recipe) { FluidStack fluid = recipe.getOutput(getModule(index)); - if (fluidHandler.fill(fluid.copy(), true) == fluid.getAmount()) { - fluidHandler.fill(fluid, false); + if (StorageUtil.simulateInsert(fluidHandler, fluid.getType(), fluid.getAmount(), null) == fluid.getAmount()) { + try (Transaction tx = TransferUtil.getTransaction()) { + fluidHandler.insert(fluid.getType(), fluid.getAmount(), tx); + tx.commit(); + } return true; } return false; diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/MixerAlloyTank.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/MixerAlloyTank.java index 1c50b88c1c5..5f2a7e404d5 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/MixerAlloyTank.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/MixerAlloyTank.java @@ -1,22 +1,23 @@ package slimeknights.tconstruct.smeltery.block.entity.module.alloying; -import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; -import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import io.github.fabricators_of_create.porting_lib.common.util.NonNullConsumer; +import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.TransferUtil; -import slimeknights.mantle.transfer.fluid.EmptyFluidHandler; -import slimeknights.mantle.transfer.fluid.IFluidHandler; -import slimeknights.mantle.util.WeakConsumerWrapper; import slimeknights.tconstruct.common.TinkerTags; import slimeknights.tconstruct.library.recipe.alloying.IMutableAlloyTank; +import slimeknights.tconstruct.smeltery.block.entity.tank.EmptyFluidStorage; import javax.annotation.Nullable; import java.util.EnumMap; @@ -31,7 +32,7 @@ public class MixerAlloyTank implements IMutableAlloyTank { /** Handler parent */ private final MantleBlockEntity parent; /** Tank for outputs */ - private final IFluidHandler outputTank; + private final SlottedStorage outputTank; /** Current temperature. Provided as a getter and setter as there are a few contexts with different source for temperature */ @Getter @@ -40,12 +41,12 @@ public class MixerAlloyTank implements IMutableAlloyTank { // side tank cache /** Cache of tanks for each of the sides */ - private final Map> inputs = new EnumMap<>(Direction.class); + private final Map> inputs = new EnumMap<>(Direction.class); /** Map of invalidation listeners for each side */ - private final Map>> listeners = new EnumMap<>(Direction.class); + private final Map>> listeners = new EnumMap<>(Direction.class); /** Map of tank index to tank on the side */ @Nullable - private IFluidHandler[] indexedList = null; + private SlottedStorage[] indexedList = null; // state /** If true, tanks are marked for refresh later */ @@ -60,17 +61,17 @@ public int getTanks() { } /** Gets the map of index to direction */ - private IFluidHandler[] indexTanks() { + private SlottedStorage[] indexTanks() { // convert map into indexed list of fluid handlers, will be cleared next time a side updates if (indexedList == null) { - indexedList = new IFluidHandler[currentTanks]; + indexedList = new SlottedStorage[currentTanks]; if (currentTanks > 0) { int nextTank = 0; for (Direction direction : Direction.values()) { if (direction != Direction.DOWN) { - LazyOptional handler = inputs.getOrDefault(direction, LazyOptional.empty()); - if (handler.isPresent()) { - indexedList[nextTank] = handler.orElse(EmptyFluidHandler.INSTANCE); + SlottedStorage handler = inputs.getOrDefault(direction, null); + if (handler != null) { + indexedList[nextTank] = handler; nextTank++; } } @@ -81,11 +82,11 @@ private IFluidHandler[] indexTanks() { } /** Gets the fluid handler for the given tank index */ - public IFluidHandler getFluidHandler(int tank) { + public SlottedStorage getFluidHandler(int tank) { checkTanks(); // invalid index, nothing if (tank >= currentTanks || tank < 0) { - return EmptyFluidHandler.INSTANCE; + return EmptyFluidStorage.INSTANCE; } return indexTanks()[tank]; } @@ -98,7 +99,7 @@ public FluidStack getFluidInTank(int tank) { return FluidStack.EMPTY; } // get the first fluid from the proper tank, we do not support multiple fluids on a side - return indexTanks()[tank].getFluidInTank(0); + return new FluidStack(indexTanks()[tank].getSlot(0)); } @Override @@ -108,18 +109,18 @@ public FluidStack drain(int tank, FluidStack fluidStack) { if (tank >= currentTanks || tank < 0) { return FluidStack.EMPTY; } - return indexTanks()[tank].drain(fluidStack, false); + return new FluidStack(fluidStack.getType(), TransferUtil.extractFluid(indexTanks()[tank], fluidStack)); } @Override public boolean canFit(FluidStack fluid, int removed) { checkTanks(); - return outputTank.fill(fluid, true) == fluid.getAmount(); + return StorageUtil.simulateInsert(outputTank, fluid.getType(), fluid.getAmount(), null) == fluid.getAmount(); } @Override public long fill(FluidStack fluidStack) { - return outputTank.fill(fluidStack, false); + return TransferUtil.insertFluid(outputTank, fluidStack); } /** @@ -140,18 +141,18 @@ private void checkTanks() { // limit by blocks as that gives the modpack more control, say they want to allow only scorched tanks if (world.getBlockState(target).is(TinkerTags.Blocks.ALLOYER_TANKS)) { // if we found a tank, increment the number of tanks - LazyOptional capability = TransferUtil.getFluidHandler(world, target, direction.getOpposite()); - if (capability.isPresent()) { + Storage capability = FluidStorage.SIDED.find(world, target, direction.getOpposite()); + if (capability != null && capability instanceof SlottedStorage storage) { // attach a listener so we know when the side invalidates - capability.addListener(listeners.computeIfAbsent(direction, dir -> new WeakConsumerWrapper<>(this, (self, handler) -> { - if (handler == self.inputs.get(dir)) { - refresh(dir, false); - } - }))); - inputs.put(direction, capability); +// capability.addListener(listeners.computeIfAbsent(direction, dir -> new WeakConsumerWrapper<>(this, (self, handler) -> { +// if (handler == self.inputs.get(dir)) { TODO: PORT replacement? +// refresh(dir, false); +// } +// }))); + inputs.put(direction, storage); currentTanks++; } else { - inputs.put(direction, LazyOptional.empty()); + inputs.put(direction, null); } } } @@ -169,7 +170,7 @@ public void refresh(Direction direction, boolean checkInput) { if (direction == Direction.DOWN) { return; } - if (!checkInput || (inputs.containsKey(direction) && inputs.get(direction).isPresent())) { + if (!checkInput || (inputs.containsKey(direction) && inputs.get(direction) != null)) { currentTanks--; } inputs.remove(direction); diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/SmelteryAlloyTank.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/SmelteryAlloyTank.java index ba7495a4944..0807c8a64aa 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/SmelteryAlloyTank.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/module/alloying/SmelteryAlloyTank.java @@ -1,6 +1,7 @@ package slimeknights.tconstruct.smeltery.block.entity.module.alloying; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -22,7 +23,7 @@ public class SmelteryAlloyTank implements IMutableAlloyTank { @Override public int getTanks() { - return handler.getTanks(); + return handler.getSlotCount(); } @Override @@ -38,11 +39,11 @@ public boolean canFit(FluidStack fluid, int removed) { @Override public FluidStack drain(int tank, FluidStack fluidStack) { - return handler.drain(fluidStack, false); + return new FluidStack(fluidStack.getType(), TransferUtil.extractFluid(handler, fluidStack)); } @Override public long fill(FluidStack fluidStack) { - return handler.fill(fluidStack, false); + return TransferUtil.insertFluid(handler, fluidStack); } } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/EmptyFluidStorage.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/EmptyFluidStorage.java new file mode 100644 index 00000000000..a760efad882 --- /dev/null +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/EmptyFluidStorage.java @@ -0,0 +1,40 @@ +package slimeknights.tconstruct.smeltery.block.entity.tank; + +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; + +public class EmptyFluidStorage implements SingleSlotStorage { + + public static final EmptyFluidStorage INSTANCE = new EmptyFluidStorage(); + + @Override + public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { + return 0; + } + + @Override + public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { + return 0; + } + + @Override + public boolean isResourceBlank() { + return true; + } + + @Override + public FluidVariant getResource() { + return FluidVariant.blank(); + } + + @Override + public long getAmount() { + return 0; + } + + @Override + public long getCapacity() { + return 0; + } +} diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/ISmelteryTankHandler.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/ISmelteryTankHandler.java index 53e3f5fb218..f0f24693d1c 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/ISmelteryTankHandler.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/ISmelteryTankHandler.java @@ -2,6 +2,9 @@ import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import slimeknights.mantle.transfer.fluid.IFluidHandler; import java.util.List; @@ -23,7 +26,7 @@ public interface ISmelteryTankHandler { * Gets the fluid capability for this smeltery. Provided here as the smeltery itself does not expose this * @return Fluid capability */ - LazyOptional getFluidCapability(); + SlottedStorage getFluidCapability(); /** * Called when the tank adds or removes a fluid to notify listeners diff --git a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/SmelteryTank.java b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/SmelteryTank.java index 38cda52c423..89c92abeac1 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/SmelteryTank.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/block/entity/tank/SmelteryTank.java @@ -2,30 +2,39 @@ import com.google.common.collect.Lists; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; +import lombok.AllArgsConstructor; import lombok.Getter; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.level.Level; import slimeknights.mantle.block.entity.MantleBlockEntity; -import slimeknights.mantle.transfer.fluid.IFluidHandler; import slimeknights.tconstruct.common.network.TinkerNetwork; import slimeknights.tconstruct.smeltery.block.entity.tank.ISmelteryTankHandler.FluidChange; import slimeknights.tconstruct.smeltery.network.SmelteryTankUpdatePacket; import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; /** * Fluid handler implementation for the smeltery */ -public class SmelteryTank implements IFluidHandler { +@SuppressWarnings("UnstableApiUsage") +public class SmelteryTank extends SnapshotParticipant implements SlottedStorage { private final T parent; /** Fluids actually contained in the tank */ @Getter - private final List fluids; + private List fluids; /** Maximum capacity of the smeltery */ private long capacity; /** Current amount of fluid in the tank */ @@ -84,20 +93,19 @@ public long getRemainingSpace() { /* Fluids */ @Override - public boolean isFluidValid(int tank, FluidStack stack) { - return true; - } - - @Override - public int getTanks() { + public int getSlotCount() { if (contained < capacity) { return fluids.size() + 1; } return fluids.size(); } - @Nonnull @Override + public SingleSlotStorage getSlot(int slot) { + return new FluidStackSlot(getFluidInTank(slot), slot); + } + + @Nonnull public FluidStack getFluidInTank(int tank) { if (tank < 0 || tank >= fluids.size()) { return FluidStack.EMPTY; @@ -105,7 +113,6 @@ public FluidStack getFluidInTank(int tank) { return fluids.get(tank); } - @Override public long getTankCapacity(int tank) { if (tank < 0) { return 0; @@ -136,23 +143,20 @@ public void moveFluidToBottom(int index) { /* Filling and draining */ @Override - public long fill(FluidStack resource, boolean sim) { + public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { // if full or nothing being filled, do nothing - if (contained >= capacity || resource.isEmpty()) { + if (contained >= capacity || maxAmount <= 0 || resource.isBlank()) { return 0; } // determine how much we can fill - long usable = Math.min(capacity - contained, resource.getAmount()); + long usable = Math.min(capacity - contained, maxAmount); // could be negative if the smeltery size changes then you try filling it if (usable <= 0) { return 0; } - // done here if just simulating - if (sim) { - return usable; - } + updateSnapshots(transaction); // add contained fluid amount contained += usable; @@ -162,85 +166,62 @@ public long fill(FluidStack resource, boolean sim) { if (fluid.isFluidEqual(resource)) { // yup. add it fluid.grow(usable); - parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); + }); return usable; } } // not present yet, add it - resource = resource.copy(); - resource.setAmount(usable); - fluids.add(resource); - parent.notifyFluidsChanged(FluidChange.ADDED, resource); + var fluid = new FluidStack(resource, usable); + fluids.add(fluid); + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.ADDED, fluid); + }); return usable; } - @Nonnull @Override - public FluidStack drain(long maxDrain, boolean sim) { - if (fluids.isEmpty()) { - return FluidStack.EMPTY; - } - - // simply drain the first one - FluidStack fluid = fluids.get(0); - long drainable = Math.min(maxDrain, fluid.getAmount()); - - // copy contained fluid to return for accuracy - FluidStack ret = fluid.copy(); - ret.setAmount(drainable); - - // remove the fluid from the tank - if (!sim) { - fluid.shrink(drainable); - contained -= drainable; - // if now empty, remove from the list - if (fluid.getAmount() <= 0) { - fluids.remove(fluid); - parent.notifyFluidsChanged(FluidChange.REMOVED, fluid); - } else { - parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); - } - } - - // return drained fluid - return ret; - } - - @Nonnull - @Override - public FluidStack drain(FluidStack toDrain, boolean sim) { + public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { // search for the resource ListIterator iter = fluids.listIterator(); while (iter.hasNext()) { FluidStack fluid = iter.next(); - if (fluid.isFluidEqual(toDrain)) { + if (fluid.isFluidEqual(resource)) { // if found, determine how much we can drain - long drainable = Math.min(toDrain.getAmount(), fluid.getAmount()); + long drainable = Math.min(maxAmount, fluid.getAmount()); // copy contained fluid to return for accuracy FluidStack ret = fluid.copy(); ret.setAmount(drainable); // update tank if executing - if (!sim) { - fluid.shrink(drainable); - contained -= drainable; - // if now empty, remove from the list - if (fluid.getAmount() <= 0) { - iter.remove(); - parent.notifyFluidsChanged(FluidChange.REMOVED, fluid); - } else { - parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); - } + updateSnapshots(transaction); + fluid.shrink(drainable); + contained -= drainable; + // if now empty, remove from the list + if (fluid.getAmount() <= 0) { + iter.remove(); + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.REMOVED, fluid); + }); + } else { + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); + }); } - return ret; + return drainable; } } // nothing drained - return FluidStack.EMPTY; + return 0; } /* Saving and loading */ @@ -291,4 +272,136 @@ public void read(CompoundTag tag) { } capacity = tag.getLong(TAG_CAPACITY); } + + @Override + public Iterator> iterator() { + return (Iterator) getSlots().iterator(); + } + + @Override + protected FluidSnapshot createSnapshot() { + List cachedFluids = new ArrayList<>(); + for (int i = 0; i < fluids.size(); i++) { + cachedFluids.add(i, fluids.get(i).copy()); + } + return new FluidSnapshot(this.contained, cachedFluids); + } + + @Override + protected void readSnapshot(FluidSnapshot snapshot) { + this.fluids = snapshot.fluids(); + this.contained = snapshot.contained(); + } + + @SuppressWarnings("UnstableApiUsage") + @AllArgsConstructor + public class FluidStackSlot extends SnapshotParticipant implements SingleSlotStorage { + + private FluidStack fluid; + private final int slot; + + @Override + public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { + // if full or nothing being filled, do nothing + if (contained >= capacity || maxAmount <= 0 || resource.isBlank()) { + return 0; + } + + // determine how much we can fill + long usable = Math.min(capacity - contained, maxAmount); + // could be negative if the smeltery size changes then you try filling it + if (usable <= 0) { + return 0; + } + + updateSnapshots(transaction); + + // add contained fluid amount + contained += usable; + + // check if we already have the given liquid + if (fluid.isFluidEqual(resource)) { + // yup. add it + fluid.grow(usable); + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); + }); + return usable; + } + + // not present yet, add it + var fluid = new FluidStack(resource, usable); + fluids.add(fluid); + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) + parent.notifyFluidsChanged(FluidChange.ADDED, fluid); + }); + return usable; + } + + @Override + public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { + if (fluid.isFluidEqual(resource)) { + // if found, determine how much we can drain + long drainable = Math.min(maxAmount, fluid.getAmount()); + + // copy contained fluid to return for accuracy + FluidStack ret = fluid.copy(); + ret.setAmount(drainable); + + // update tank if executing + updateSnapshots(transaction); + fluid.shrink(drainable); + contained -= drainable; + // if now empty, remove from the list + transaction.addCloseCallback((tx, result) -> { + if (result.wasCommitted()) { + if (fluid.getAmount() <= 0) { + SmelteryTank.this.fluids.remove(slot); + parent.notifyFluidsChanged(FluidChange.REMOVED, fluid); + } else { + parent.notifyFluidsChanged(FluidChange.CHANGED, fluid); + } + } + }); + + + return drainable; + } + return 0; + } + + @Override + public boolean isResourceBlank() { + return this.fluid.getType().isBlank(); + } + + @Override + public FluidVariant getResource() { + return this.fluid.getType(); + } + + @Override + public long getAmount() { + return this.fluid.getAmount(); + } + + @Override + public long getCapacity() { + return SmelteryTank.this.getTankCapacity(this.slot); + } + + @Override + protected FluidSnapshot createSnapshot() { + return SmelteryTank.this.createSnapshot(); + } + + @Override + protected void readSnapshot(FluidSnapshot snapshot) { + SmelteryTank.this.readSnapshot(snapshot); + } + } + + public record FluidSnapshot(long contained, List fluids) {} } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/client/screen/module/GuiTankModule.java b/src/main/java/slimeknights/tconstruct/smeltery/client/screen/module/GuiTankModule.java index 79ebb8cd071..e66fc2455c5 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/client/screen/module/GuiTankModule.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/client/screen/module/GuiTankModule.java @@ -1,9 +1,10 @@ package slimeknights.tconstruct.smeltery.client.screen.module; -import com.mojang.blaze3d.vertex.PoseStack; import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; import lombok.Getter; import net.fabricmc.fabric.api.client.screen.v1.Screens; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; @@ -12,7 +13,6 @@ import net.minecraft.resources.ResourceLocation; import slimeknights.mantle.Mantle; import slimeknights.mantle.fluid.tooltip.FluidTooltipHandler; -import slimeknights.mantle.transfer.fluid.IFluidHandler; import slimeknights.tconstruct.library.client.GuiUtil; import javax.annotation.Nullable; @@ -29,12 +29,12 @@ public class GuiTankModule { private static final int TANK_INDEX = 0; private final AbstractContainerScreen screen; - private final IFluidHandler tank; + private final SlottedStorage tank; @Getter private final int x, y, width, height; private final BiConsumer> formatter; - public GuiTankModule(AbstractContainerScreen screen, IFluidHandler tank, int x, int y, int width, int height, ResourceLocation tooltipId) { + public GuiTankModule(AbstractContainerScreen screen, SlottedStorage tank, int x, int y, int width, int height, ResourceLocation tooltipId) { this.screen = screen; this.tank = tank; this.x = x; @@ -59,11 +59,11 @@ private boolean isHovered(int checkX, int checkY) { * @return Fluid height */ private long getFluidHeight() { - long capacity = tank.getTankCapacity(TANK_INDEX); + long capacity = tank.getSlot(TANK_INDEX).getCapacity(); if (capacity == 0) { return height; } - return height * tank.getFluidInTank(TANK_INDEX).getAmount() / capacity; + return height * tank.getSlot(TANK_INDEX).getAmount() / capacity; } /** @@ -71,7 +71,7 @@ private long getFluidHeight() { * @param graphics Gui graphics instance */ public void draw(GuiGraphics graphics) { - GuiUtil.renderFluidTank(graphics.pose(), screen, tank.getFluidInTank(TANK_INDEX), tank.getTankCapacity(TANK_INDEX), x, y, width, height, 100); + GuiUtil.renderFluidTank(graphics.pose(), screen, new FluidStack(tank.getSlot(TANK_INDEX)), tank.getSlot(TANK_INDEX).getCapacity(), x, y, width, height, 100); } /** @@ -107,9 +107,9 @@ public void renderTooltip(GuiGraphics graphics, int mouseX, int mouseY) { int checkY = mouseY - screen.topPos; if (isHovered(checkX, checkY)) { - FluidStack fluid = tank.getFluidInTank(TANK_INDEX); + FluidStack fluid = new FluidStack(tank.getSlot(TANK_INDEX)); long amount = fluid.getAmount(); - long capacity = tank.getTankCapacity(TANK_INDEX); + long capacity = tank.getSlot(TANK_INDEX).getCapacity(); // if hovering over the fluid, display with name final List tooltip; @@ -151,7 +151,7 @@ public void renderTooltip(GuiGraphics graphics, int mouseX, int mouseY) { @Nullable public FluidStack getIngreientUnderMouse(int checkX, int checkY) { if (isHovered(checkX, checkY) && checkY > (y + height) - getFluidHeight()) { - return tank.getFluidInTank(TANK_INDEX); + return new FluidStack(tank.getSlot(TANK_INDEX)); } return null; } diff --git a/src/main/java/slimeknights/tconstruct/smeltery/item/TankItem.java b/src/main/java/slimeknights/tconstruct/smeltery/item/TankItem.java index 73d48a1448b..e73969da5d4 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/item/TankItem.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/item/TankItem.java @@ -1,6 +1,7 @@ package slimeknights.tconstruct.smeltery.item; import io.github.fabricators_of_create.porting_lib.item.CustomMaxCountItem; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; @@ -14,12 +15,9 @@ import slimeknights.mantle.client.TooltipKey; import slimeknights.mantle.fluid.tooltip.FluidTooltipHandler; import slimeknights.mantle.item.BlockTooltipItem; -import slimeknights.mantle.transfer.fluid.FluidTank; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.library.recipe.FluidValues; import slimeknights.tconstruct.library.utils.NBTTags; -import slimeknights.tconstruct.smeltery.TinkerSmeltery; -import slimeknights.tconstruct.smeltery.block.component.SearedTankBlock; import slimeknights.tconstruct.smeltery.block.entity.component.TankBlockEntity; import javax.annotation.Nullable; @@ -35,6 +33,7 @@ public class TankItem extends BlockTooltipItem implements CustomMaxCountItem { public TankItem(Block blockIn, Properties builder, boolean limitStackSize) { super(blockIn, builder); this.limitStackSize = limitStackSize; + FluidStorage.ITEM.registerForItems((itemStack, context) -> new TankItemFluidHandler(context), this); } /** Checks if the tank item is filled */ @@ -88,21 +87,6 @@ public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List { - return null; // TODO transfer - }); - } - } - /** * Sets the tank to the given stack * @param stack Stack diff --git a/src/main/java/slimeknights/tconstruct/smeltery/item/TankItemFluidHandler.java b/src/main/java/slimeknights/tconstruct/smeltery/item/TankItemFluidHandler.java index f1b7785e87e..bdf8429d08e 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/item/TankItemFluidHandler.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/item/TankItemFluidHandler.java @@ -1,33 +1,34 @@ package slimeknights.tconstruct.smeltery.item; -import io.github.fabricators_of_create.porting_lib.fluids.FluidStack; -import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import lombok.Getter; import lombok.RequiredArgsConstructor; +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.world.item.ItemStack; -import slimeknights.mantle.transfer.fluid.FluidTank; -import slimeknights.mantle.transfer.fluid.IFluidHandlerItem; import slimeknights.tconstruct.smeltery.block.entity.component.TankBlockEntity; -import javax.annotation.Nonnull; - /** * Handler that works with a tank item to adjust its tank in NBT */ @RequiredArgsConstructor -public class TankItemFluidHandler implements IFluidHandlerItem { - private final LazyOptional holder = LazyOptional.of(() -> this); +public class TankItemFluidHandler implements SingleSlotStorage { @Getter - private final ItemStack container; + private final ContainerItemContext container; /** Gets the tank on the stack */ private FluidTank getTank() { - return TankItem.getFluidTank(container); + return TankItem.getFluidTank(container.getItemVariant().toStack()); } /** Updates the container from the given tank */ - private void updateContainer(FluidTank tank) { - TankItem.setTank(container, tank); + private void updateContainer(FluidTank tank, TransactionContext tx) { + ItemStack newStack = container.getItemVariant().toStack(); + TankItem.setTank(newStack, tank); + container.exchange(ItemVariant.of(newStack), 1, tx); } // @Override @@ -36,55 +37,42 @@ private void updateContainer(FluidTank tank) { // } @Override - public int getTanks() { - return 1; - } - - @Nonnull - @Override - public FluidStack getFluidInTank(int tank) { - return getTank().getFluidInTank(tank); - } - - @Override - public long getTankCapacity(int tank) { - return TankBlockEntity.getCapacity(container.getItem()); - } - - @Override - public boolean isFluidValid(int tank, FluidStack stack) { - return true; + public long getCapacity() { + return TankBlockEntity.getCapacity(container.getItemVariant().getItem()); } @Override - public long fill(FluidStack resource, boolean sim) { + public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { FluidTank tank = getTank(); - long didFill = tank.fill(resource, sim); - if (didFill > 0 && !sim) { - updateContainer(tank); + long didFill = tank.insert(resource, maxAmount, transaction); + if (didFill > 0) { + updateContainer(tank, transaction); } return didFill; } - @Nonnull @Override - public FluidStack drain(FluidStack resource, boolean sim) { + public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { FluidTank tank = getTank(); - FluidStack didDrain = tank.drain(resource, sim); - if (!didDrain.isEmpty() && !sim) { - updateContainer(tank); + long didDrain = tank.extract(resource, maxAmount, transaction); + if (!(didDrain <= 0)) { + updateContainer(tank, transaction); } return didDrain; } - @Nonnull @Override - public FluidStack drain(long maxDrain, boolean sim) { - FluidTank tank = getTank(); - FluidStack didDrain = tank.drain(maxDrain, sim); - if (!didDrain.isEmpty() && !sim) { - updateContainer(tank); - } - return didDrain; + public boolean isResourceBlank() { + return getResource().isBlank(); + } + + @Override + public FluidVariant getResource() { + return getTank().getResource(); + } + + @Override + public long getAmount() { + return getTank().getAmount(); } } diff --git a/src/main/java/slimeknights/tconstruct/tables/block/ChestBlock.java b/src/main/java/slimeknights/tconstruct/tables/block/ChestBlock.java index 52ba3aae273..13dab0945dc 100644 --- a/src/main/java/slimeknights/tconstruct/tables/block/ChestBlock.java +++ b/src/main/java/slimeknights/tconstruct/tables/block/ChestBlock.java @@ -1,6 +1,5 @@ package slimeknights.tconstruct.tables.block; -import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.minecraft.core.BlockPos; @@ -23,8 +22,6 @@ import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import slimeknights.mantle.transfer.item.IItemHandler; -import slimeknights.mantle.transfer.item.IItemHandlerModifiable; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.tables.block.entity.chest.AbstractChestBlockEntity; import slimeknights.tconstruct.tables.block.entity.inventory.IChestItemHandler; diff --git a/src/main/java/slimeknights/tconstruct/tables/block/entity/table/CraftingStationBlockEntity.java b/src/main/java/slimeknights/tconstruct/tables/block/entity/table/CraftingStationBlockEntity.java index bc12f3cca72..ef5e323809e 100644 --- a/src/main/java/slimeknights/tconstruct/tables/block/entity/table/CraftingStationBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/tables/block/entity/table/CraftingStationBlockEntity.java @@ -1,6 +1,7 @@ package slimeknights.tconstruct.tables.block.entity.table; import io.github.fabricators_of_create.porting_lib.event.common.ItemCraftedCallback; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; import net.minecraft.core.BlockPos; @@ -16,7 +17,6 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.network.TinkerNetwork; import slimeknights.tconstruct.shared.inventory.ConfigurableInvWrapperCapability; diff --git a/src/main/java/slimeknights/tconstruct/tables/block/entity/table/TinkerStationBlockEntity.java b/src/main/java/slimeknights/tconstruct/tables/block/entity/table/TinkerStationBlockEntity.java index c25c66b431b..0e3605816d3 100644 --- a/src/main/java/slimeknights/tconstruct/tables/block/entity/table/TinkerStationBlockEntity.java +++ b/src/main/java/slimeknights/tconstruct/tables/block/entity/table/TinkerStationBlockEntity.java @@ -1,6 +1,7 @@ package slimeknights.tconstruct.tables.block.entity.table; import io.github.fabricators_of_create.porting_lib.event.common.ItemCraftedCallback; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import lombok.Getter; import net.minecraft.core.BlockPos; @@ -13,7 +14,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.level.block.state.BlockState; -import slimeknights.mantle.transfer.item.ItemHandlerHelper; import org.apache.commons.lang3.StringUtils; import slimeknights.tconstruct.TConstruct; import slimeknights.tconstruct.common.SoundUtils; diff --git a/src/main/java/slimeknights/tconstruct/tools/menu/ToolContainerMenu.java b/src/main/java/slimeknights/tconstruct/tools/menu/ToolContainerMenu.java index ee2d0299944..1869be6128a 100644 --- a/src/main/java/slimeknights/tconstruct/tools/menu/ToolContainerMenu.java +++ b/src/main/java/slimeknights/tconstruct/tools/menu/ToolContainerMenu.java @@ -4,8 +4,6 @@ import io.github.fabricators_of_create.porting_lib.transfer.item.SlottedStackStorage; import lombok.Getter; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; -import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; -import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; @@ -15,8 +13,6 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import slimeknights.mantle.inventory.SmartItemHandlerSlot; -import slimeknights.mantle.transfer.item.IItemHandler; -import slimeknights.mantle.transfer.item.IItemHandlerModifiable; import slimeknights.tconstruct.library.tools.capability.ToolInventoryCapability; import slimeknights.tconstruct.library.tools.helper.ModifierUtil; import slimeknights.tconstruct.tools.TinkerTools;