Skip to content

Commit

Permalink
Fix reservoir hatches that would lose their set fluid if they were em…
Browse files Browse the repository at this point in the history
…pty when the world closed. + bump ver
  • Loading branch information
Zorbatron committed Jul 16, 2024
1 parent 0623e04 commit 8879e7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -76,16 +77,16 @@ 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))
.bindPlayerInventory(entityPlayer.inventory);
}

private Supplier<String> getFluidNameText(InfiniteTank fluidTank) {
return () -> fluidTank.getFluid() != null ? fluidTank.getFluid().getLocalizedName() : "";
return () -> fluidTank.getLockFluid() != null ? fluidTank.getLockFluid().getLocalizedName() : "";
}

private Supplier<String> getFluidAmountText(InfiniteTank fluidTank) {
Expand All @@ -94,6 +95,7 @@ private Supplier<String> 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();
}
Expand Down Expand Up @@ -170,25 +172,27 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List<String> 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);
}

@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);
}
Expand All @@ -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;
Expand Down

1 comment on commit 8879e7e

@D-Alessian
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will fix world hunger

Please sign in to comment.