Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reservoir hatch issues #2349

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void update() {
super.update();
if (!getWorld().isRemote) {
fillContainerFromInternalTank(fluidTank);
fillInternalTankFromFluidContainer(fluidTank);
if (getOffsetTimer() % 20 == 0) {
fluidTank.refillWater();
}
Expand Down Expand Up @@ -129,7 +128,7 @@ public ModularUI.Builder createTankUI(IFluidTank fluidTank, String title, Entity

// Add input/output-specific widgets
tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18)
.setAlwaysShowFull(true).setDrawHoveringText(false).setContainerClicking(true, true);
.setAlwaysShowFull(true).setDrawHoveringText(false).setContainerClicking(true, false);

builder.image(7, 16, 81, 55, GuiTextures.DISPLAY)
.widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON))
Expand Down Expand Up @@ -180,47 +179,39 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List<String> t

private static class InfiniteWaterTank extends NotifiableFluidTank {

private final FluidStack BIG_WATER = new FluidStack(FluidRegistry.WATER, FLUID_AMOUNT);

public InfiniteWaterTank(int capacity, MetaTileEntity entityToNotify) {
super(capacity, entityToNotify, false);
setFluid(BIG_WATER);
// start with the full amount
setFluid(new FluidStack(FluidRegistry.WATER, FLUID_AMOUNT));
// don't allow external callers to fill this tank
setCanFill(false);
}

private void refillWater() {
if (BIG_WATER.amount != FLUID_AMOUNT) {
BIG_WATER.amount = FLUID_AMOUNT;
onContentsChanged();
int fillAmount = Math.max(0, FLUID_AMOUNT - getFluidAmount());
if (fillAmount > 0) {
// call super since our overrides don't allow any kind of filling
super.fillInternal(new FluidStack(FluidRegistry.WATER, fillAmount), true);
}
}

@Override
public FluidStack drainInternal(int maxDrain, boolean doDrain) {
return new FluidStack(BIG_WATER, maxDrain);
}

@Nullable
@Override
public FluidStack drainInternal(FluidStack resource, boolean doDrain) {
return new FluidStack(BIG_WATER, resource.amount);
public boolean canDrainFluidType(@Nullable FluidStack fluid) {
return fluid != null && fluid.getFluid() == FluidRegistry.WATER;
}

// don't allow external filling
@Override
public int fillInternal(FluidStack resource, boolean doFill) {
return resource.amount;
}

@Override
public boolean canDrainFluidType(@Nullable FluidStack fluid) {
return fluid != null && fluid.getFluid() == BIG_WATER.getFluid();
return 0;
}

@Override
public boolean canFillFluidType(FluidStack fluid) {
return fluid.getFluid() == BIG_WATER.getFluid();
return false;
}

// serialization is unnecessary here, it should always have the same amount of fluid
// serialization is unnecessary here, we can always recreate it completely full since it would refill anyway
@Override
public FluidTank readFromNBT(NBTTagCompound nbt) {
return this;
Expand Down