Skip to content

Commit

Permalink
allow quantum tanks to lock their fluids
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 committed Dec 1, 2021
1 parent 07149b6 commit f380783
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GuiTextures {
public static final TextureArea BUTTON_FILTER_NBT = TextureArea.fullImage("textures/gui/widget/button_filter_nbt.png");
public static final TextureArea BUTTON_FLUID_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_fluid_output.png");
public static final TextureArea BUTTON_ITEM_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_item_output.png");
public static final TextureArea BUTTON_LOCK = TextureArea.fullImage("textures/gui/widget/button_lock.png");
public static final TextureArea BUTTON_LEFT = TextureArea.fullImage("textures/gui/widget/left.png");
public static final TextureArea BUTTON_OVERCLOCK = TextureArea.fullImage("textures/gui/widget/button_overclock.png");
public static final TextureArea BUTTON_PUBLIC_PRIVATE = TextureArea.fullImage("textures/gui/widget/button_public_private.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import codechicken.lib.vec.Matrix4;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IActiveOutputSide;
import gregtech.api.capability.impl.FilteredFluidHandler;
import gregtech.api.capability.impl.FluidHandlerProxy;
import gregtech.api.capability.impl.FluidTankList;
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.ModularUI.Builder;
import gregtech.api.gui.widgets.*;
import gregtech.api.metatileentity.ITieredMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
Expand Down Expand Up @@ -44,6 +44,7 @@

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Predicate;

import static gregtech.api.capability.GregtechDataCodes.UPDATE_AUTO_OUTPUT_FLUIDS;
import static gregtech.api.capability.GregtechDataCodes.UPDATE_OUTPUT_FACING;
Expand All @@ -61,11 +62,16 @@ public class MetaTileEntityQuantumTank extends MetaTileEntity implements ITiered
private boolean allowInputFromOutputSide = false;
protected IFluidHandler outputFluidInventory;

private boolean locked;
private FluidStack lockedFluid;

public MetaTileEntityQuantumTank(ResourceLocation metaTileEntityId, int tier, int maxFluidCapacity) {
super(metaTileEntityId);
this.tier = tier;
this.maxFluidCapacity = maxFluidCapacity;
this.containerInventory = new ItemStackHandler(2);
this.locked = false;
this.lockedFluid = null;
initializeInventory();
}

Expand All @@ -77,13 +83,17 @@ public int getTier() {
@Override
protected void initializeInventory() {
super.initializeInventory();
this.fluidTank = new FluidTank(maxFluidCapacity);
this.fluidTank = new FilteredFluidHandler(maxFluidCapacity).setFillPredicate(fillPredicate());
this.fluidInventory = fluidTank;
this.importFluids = new FluidTankList(false, fluidTank);
this.exportFluids = new FluidTankList(false, fluidTank);
this.outputFluidInventory = new FluidHandlerProxy(new FluidTankList(false), exportFluids);
}

protected Predicate<FluidStack> fillPredicate() {
return fluidStack -> lockedFluid == null || fluidStack.isFluidEqual(lockedFluid);
}

@Override
public int getActualComparatorValue() {
FluidTank fluidTank = this.fluidTank;
Expand Down Expand Up @@ -113,6 +123,12 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
data.setTag("FluidInventory", fluidTank.writeToNBT(new NBTTagCompound()));
data.setBoolean("AutoOutputFluids", autoOutputFluids);
data.setInteger("OutputFacing", getOutputFacing().getIndex());
data.setBoolean("locked", locked);
if (this.lockedFluid != null)
this.lockedFluid.writeToNBT(data);
else
data.setString("Empty", "");

return data;
}

Expand All @@ -123,6 +139,11 @@ public void readFromNBT(NBTTagCompound data) {
this.fluidTank.readFromNBT(data.getCompoundTag("FluidInventory"));
this.autoOutputFluids = data.getBoolean("AutoOutputFluids");
this.outputFacing = EnumFacing.VALUES[data.getInteger("OutputFacing")];
this.locked = data.getBoolean("locked");
if (!data.hasKey("Empty"))
this.lockedFluid = FluidStack.loadFluidStackFromNBT(data);
else
this.lockedFluid = null;
}

@Override
Expand Down Expand Up @@ -196,34 +217,29 @@ public void addInformation(ItemStack stack, @Nullable World player, List<String>

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
Builder builder = ModularUI.defaultBuilder();
int leftButtonStartX = 7;
builder.image(7, 16, 81, 55, GuiTextures.DISPLAY);
TankWidget tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18)
.setHideTooltip(true).setAlwaysShowFull(true);
builder.widget(tankWidget);
builder.label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF);
builder.dynamicLabel(11, 30, tankWidget::getFormattedFluidAmount, 0xFFFFFF);
builder.dynamicLabel(11, 40, tankWidget::getFluidLocalizedName, 0xFFFFFF);
return builder.label(6, 6, getMetaFullName())
TankWidget tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18).setHideTooltip(true).setAlwaysShowFull(true);
return ModularUI.defaultBuilder()
.image(7, 16, 81, 55, GuiTextures.DISPLAY)
.widget(tankWidget)
.label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF)
.dynamicLabel(11, 30, tankWidget::getFormattedFluidAmount, 0xFFFFFF)
.dynamicLabel(11, 40, tankWidget::getFluidLocalizedName, 0xFFFFFF)
.label(6, 6, getMetaFullName())
.widget(new FluidContainerSlotWidget(containerInventory, 0, 90, 17, false)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.IN_SLOT_OVERLAY))
.widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON))
.widget(new SlotWidget(containerInventory, 1, 90, 54, true, false)
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY)).widget(new ToggleButtonWidget(leftButtonStartX, 53, 18, 18,
.setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY))
.widget(new ToggleButtonWidget(7, 53, 18, 18,
GuiTextures.BUTTON_FLUID_OUTPUT, this::isAutoOutputFluids, this::setAutoOutputFluids)
.setTooltipText("gregtech.gui.fluid_auto_output.tooltip"))
.widget(new ToggleButtonWidget(25, 53, 18, 18,
GuiTextures.BUTTON_LOCK, this::isLocked, this::setLocked)
.setTooltipText("gregtech.gui.fluid_lock.tooltip"))
.bindPlayerInventory(entityPlayer.inventory)
.build(getHolder(), entityPlayer);
}

@Override
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeByte(getOutputFacing().getIndex());
buf.writeBoolean(autoOutputFluids);
}

public EnumFacing getOutputFacing() {
return outputFacing == null ? frontFacing.getOpposite() : outputFacing;
}
Expand Down Expand Up @@ -273,11 +289,20 @@ public boolean isValidFrontFacing(EnumFacing facing) {
return super.isValidFrontFacing(facing) && facing != outputFacing;
}

@Override
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeByte(getOutputFacing().getIndex());
buf.writeBoolean(autoOutputFluids);
buf.writeBoolean(locked);
}

@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
this.outputFacing = EnumFacing.VALUES[buf.readByte()];
this.autoOutputFluids = buf.readBoolean();
this.locked = buf.readBoolean();
}

public void setOutputFacing(EnumFacing outputFacing) {
Expand Down Expand Up @@ -354,4 +379,16 @@ public void setAutoOutputFluids(boolean autoOutputFluids) {
markDirty();
}
}

private boolean isLocked() {
return locked;
}

private void setLocked(boolean locked) {
this.locked = locked;
if (!getWorld().isRemote) {
if (locked) this.lockedFluid = this.fluidTank.getFluid();
else this.lockedFluid = null;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3883,6 +3883,8 @@ gregtech.gui.fluid_auto_output.tooltip.enabled=Fluid Auto-Output Enabled
gregtech.gui.fluid_auto_output.tooltip.disabled=Fluid Auto-Output Disabled
gregtech.gui.item_auto_output.tooltip.enabled=Item Auto-Output Enabled
gregtech.gui.item_auto_output.tooltip.disabled=Item Auto-Output Disabled
gregtech.gui.fluid_lock.tooltip.enabled=Fluid Locking Enabled
gregtech.gui.fluid_lock.tooltip.disabled=Fluid Locking Disabled
gregtech.gui.silktouch.enabled=Silk Touch Enabled: Click to Disable./n§7Switching requires an idle machine.
gregtech.gui.silktouch.disabled=Silk Touch Disabled: Click to Enable./n§7Switching requires an idle machine.
gregtech.gui.chunkmode.enabled=Chunk Mode Enabled: Click to Disable./n§7Switching requires an idle machine.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f380783

Please sign in to comment.