From 8879e7e8b872c9ecd077b5e126405af12c83dd18 Mon Sep 17 00:00:00 2001 From: Zorbatron Date: Mon, 15 Jul 2024 23:56:57 -0400 Subject: [PATCH] Fix reservoir hatches that would lose their set fluid if they were empty when the world closed. + bump ver --- gradle.properties | 2 +- .../MetaTileEntityCreativeReservoirHatch.java | 40 +++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 471d5e7e..972851f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ modGroup = com.zorbatron.zbgt # Version of your mod. # This field can be left empty if you want your mod's version to be determined by the latest git tag instead. -modVersion = 0.3.1 +modVersion = 0.3.2 # Whether to use the old jar naming structure (modid-mcversion-version) instead of the new version (modid-version) includeMCVersionJar = false diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeReservoirHatch.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeReservoirHatch.java index 0cf09bcd..2169d525 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeReservoirHatch.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeReservoirHatch.java @@ -58,15 +58,16 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { @Override protected ModularUI createUI(EntityPlayer entityPlayer) { - return createTankUI(fluidTank, getMetaFullName(), entityPlayer).build(getHolder(), entityPlayer); + return createTankUI(getMetaFullName(), entityPlayer).build(getHolder(), entityPlayer); } - public ModularUI.Builder createTankUI(InfiniteTank fluidTank, String title, EntityPlayer entityPlayer) { + public ModularUI.Builder createTankUI(String title, EntityPlayer entityPlayer) { // Create base builder/widget references ModularUI.Builder builder = ModularUI.defaultBuilder(); - PhantomFluidWidget tankWidget = new PhantomFluidWidget(69, 52, 18, 18, this.fluidTank::getFluid, this::setFluid) - .showTip(false).setBackgroundTexture(null); + PhantomFluidWidget tankWidget = new PhantomFluidWidget(69, 52, 18, 18, this.fluidTank::getLockFluid, + this::setFluid) + .showTip(false).setBackgroundTexture(null); builder.image(7, 16, 81, 55, GuiTextures.DISPLAY) .widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON)) @@ -76,8 +77,8 @@ public ModularUI.Builder createTankUI(InfiniteTank fluidTank, String title, Enti // Add general widgets return builder.label(6, 6, title) .label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF) - .widget(new SimpleTextWidget(11, 30, "", 0xFFFFFF, getFluidAmountText(fluidTank)).setCenter(false)) - .widget(new SimpleTextWidget(11, 40, "", 0xFFFFFF, getFluidNameText(fluidTank)).setCenter(false)) + .widget(new SimpleTextWidget(11, 30, "", 0xFFFFFF, getFluidAmountText(this.fluidTank)).setCenter(false)) + .widget(new SimpleTextWidget(11, 40, "", 0xFFFFFF, getFluidNameText(this.fluidTank)).setCenter(false)) .widget(tankWidget) .widget(new FluidContainerSlotWidget(importItems, 0, 90, 16, false) .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.IN_SLOT_OVERLAY)) @@ -85,7 +86,7 @@ public ModularUI.Builder createTankUI(InfiniteTank fluidTank, String title, Enti } private Supplier getFluidNameText(InfiniteTank fluidTank) { - return () -> fluidTank.getFluid() != null ? fluidTank.getFluid().getLocalizedName() : ""; + return () -> fluidTank.getLockFluid() != null ? fluidTank.getLockFluid().getLocalizedName() : ""; } private Supplier getFluidAmountText(InfiniteTank fluidTank) { @@ -94,6 +95,7 @@ private Supplier getFluidAmountText(InfiniteTank fluidTank) { private void setFluid(@Nullable FluidStack fluid) { if (fluid != null) { + this.fluidTank.lockFluid = new FluidStack(fluid.copy(), 1); this.fluidTank.setFluid(new FluidStack(fluid.copy(), FLUID_AMOUNT)); this.fluidTank.onContentsChanged(); } @@ -170,8 +172,8 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { - if (fluidTank != null) { - data.setTag("FluidInventory", fluidTank.writeToNBT(new NBTTagCompound())); + if (fluidTank.getLockFluid() != null) { + data.setTag("FluidInventory", fluidTank.getLockFluid().writeToNBT(new NBTTagCompound())); } return super.writeToNBT(data); } @@ -179,16 +181,18 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) { @Override public void readFromNBT(NBTTagCompound data) { if (data.hasKey("FluidInventory")) { - setFluid(FluidStack.loadFluidStackFromNBT(data.getCompoundTag("FluidInventory"))); + fluidTank.setLockFluid(FluidStack.loadFluidStackFromNBT(data.getCompoundTag("FluidInventory"))); } super.readFromNBT(data); } private static class InfiniteTank extends NotifiableFluidTank { + @Nullable + private FluidStack lockFluid; + public InfiniteTank(int capacity, MetaTileEntity entityToNotify) { super(capacity, entityToNotify, false); - // setFluid(new FluidStack(FluidRegistry.WATER, FLUID_AMOUNT)); setFluid(null); setCanFill(false); } @@ -197,12 +201,22 @@ public void refill() { int fillAmount = Math.max(0, FLUID_AMOUNT - getFluidAmount()); if (fillAmount > 0) { // call super since our overrides don't allow any kind of filling - if (fluid != null) { - super.fillInternal(new FluidStack(fluid, fillAmount), true); + if (lockFluid != null) { + super.fillInternal(new FluidStack(lockFluid, fillAmount), true); } } } + public void setLockFluid(@Nullable FluidStack fluid) { + if (fluid != null) { + lockFluid = new FluidStack(fluid.copy(), 1); + } + } + + public @Nullable FluidStack getLockFluid() { + return lockFluid; + } + @Override public boolean canDrainFluidType(@Nullable FluidStack fluid) { return true;