Skip to content

Commit

Permalink
Fix capacity bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
CodexAdrian committed Jan 11, 2024
1 parent 596d6b9 commit 34695d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 34695d5

Please sign in to comment.