From 34695d51f5ad5a2e9654e4b46a651e64f89fc071 Mon Sep 17 00:00:00 2001 From: CodexAdrian <83074853+CodexAdrian@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:19:40 -0500 Subject: [PATCH] Fix capacity bugs --- .../blockentities/FlowHiveBlockEntity.java | 3 ++- .../HoneyGeneratorBlockEntity.java | 5 +++-- .../common/util/FluidUtils.java | 22 +------------------ 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/FlowHiveBlockEntity.java b/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/FlowHiveBlockEntity.java index 6b2770f0..b2098556 100644 --- a/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/FlowHiveBlockEntity.java +++ b/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/FlowHiveBlockEntity.java @@ -6,6 +6,7 @@ import com.teamresourceful.resourcefulbees.common.lib.constants.NBTConstants; import com.teamresourceful.resourcefulbees.common.recipes.FlowHiveRecipe; import com.teamresourceful.resourcefulbees.common.registries.minecraft.ModBlockEntityTypes; +import earth.terrarium.botarium.common.fluid.FluidConstants; import earth.terrarium.botarium.common.fluid.base.BotariumFluidBlock; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import earth.terrarium.botarium.common.fluid.impl.ExtractOnlyFluidContainer; @@ -101,7 +102,7 @@ public void setChanged() { @Override public WrappedBlockFluidContainer getFluidContainer() { if (tank == null) { - tank = new WrappedBlockFluidContainer(this, new ExtractOnlyFluidContainer(i -> 16000, 1, (amount, fluid) -> true)); + tank = new WrappedBlockFluidContainer(this, new ExtractOnlyFluidContainer(i -> FluidConstants.fromMillibuckets(16000), 1, (amount, fluid) -> true)); } return this.tank; } diff --git a/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/HoneyGeneratorBlockEntity.java b/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/HoneyGeneratorBlockEntity.java index 8c91370b..d9c327ed 100644 --- a/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/HoneyGeneratorBlockEntity.java +++ b/common/src/main/java/com/teamresourceful/resourcefulbees/common/blockentities/HoneyGeneratorBlockEntity.java @@ -20,6 +20,7 @@ import earth.terrarium.botarium.common.energy.base.BotariumEnergyBlock; import earth.terrarium.botarium.common.energy.impl.ExtractOnlyEnergyContainer; import earth.terrarium.botarium.common.energy.impl.WrappedBlockEnergyContainer; +import earth.terrarium.botarium.common.fluid.FluidConstants; import earth.terrarium.botarium.common.fluid.base.BotariumFluidBlock; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import earth.terrarium.botarium.common.fluid.impl.InsertOnlyFluidContainer; @@ -49,7 +50,7 @@ public class HoneyGeneratorBlockEntity extends GUISyncedBlockEntity implements I public static final int ENERGY_TRANSFER_AMOUNT = HoneyGenConfig.energyTransferAmount; public static final int MAX_ENERGY_CAPACITY = HoneyGenConfig.maxEnergyCapacity; - public static final int MAX_TANK_STORAGE = HoneyGenConfig.maxTankCapacity; + public static final int MAX_TANK_STORAGE = (int) FluidConstants.fromMillibuckets(HoneyGenConfig.maxTankCapacity); private FluidContainer fluidContainer; private WrappedBlockFluidContainer wrappedFluidContainer; @@ -257,7 +258,7 @@ private static class FluidContainer extends InsertOnlyFluidContainer { private int capacity; public FluidContainer() { - super(i -> HoneyGenConfig.maxTankCapacity, 1, (i, holder) -> holder.getFluid().is(ModFluidTags.HONEY)); + super(i -> MAX_TANK_STORAGE, 1, (i, holder) -> holder.getFluid().is(ModFluidTags.HONEY)); } @Override diff --git a/common/src/main/java/com/teamresourceful/resourcefulbees/common/util/FluidUtils.java b/common/src/main/java/com/teamresourceful/resourcefulbees/common/util/FluidUtils.java index 6291b3ec..a595add0 100644 --- a/common/src/main/java/com/teamresourceful/resourcefulbees/common/util/FluidUtils.java +++ b/common/src/main/java/com/teamresourceful/resourcefulbees/common/util/FluidUtils.java @@ -12,8 +12,6 @@ import earth.terrarium.botarium.common.fluid.base.FluidContainer; import earth.terrarium.botarium.common.fluid.base.FluidHolder; import net.minecraft.core.BlockPos; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -61,7 +59,7 @@ public static void fillBottle(FluidContainer tank, Player player, InteractionHan } public static void emptyBottle(FluidContainer tank, Player player, InteractionHand hand) { - FluidHolder holder = FluidHolder.of(getHoneyFluidFromBottle(player.getItemInHand(hand)), BeeConstants.HONEY_PER_BOTTLE_BUCKETS, null); + FluidHolder holder = FluidHolder.of(getHoneyFluidFromBottle(player.getItemInHand(hand)), FluidConstants.fromMillibuckets(BeeConstants.HONEY_PER_BOTTLE), null); if (holder.isEmpty()) return; long inserted = exactInsert(tank, holder); @@ -117,22 +115,4 @@ public static void checkBottleAndCapability(FluidContainer tank, BlockEntity ent provider.openMenu(serverPlayer); } } - - public static void writeToBuffer(FluidHolder holder, FriendlyByteBuf buffer) { - if (holder.isEmpty()) { - buffer.writeBoolean(false); - } else { - buffer.writeBoolean(true); - buffer.writeVarInt(BuiltInRegistries.FLUID.getId(holder.getFluid())); - buffer.writeVarLong(holder.getFluidAmount()); - buffer.writeNbt(holder.getCompound()); - } - } - - public static FluidHolder readFromBuffer(FriendlyByteBuf buffer) { - if (!buffer.readBoolean()) return FluidHolder.empty(); - Fluid fluid = BuiltInRegistries.FLUID.byId(buffer.readVarInt()); - long amount = buffer.readVarLong(); - return FluidHolder.of(fluid, amount, buffer.readNbt()); - } }