aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
authorくぁーりぃ <39122497+Quarri6343@users.noreply.github.com>2022-08-30 05:04:31 +0900
committerGitHub <noreply@github.com>2022-08-29 22:04:31 +0200
commit4927a8885381ca48479be71e7cdb37aae9cbf5fd (patch)
tree7664056ac3ec23574942e9a265e6ca37067b8963 /src/main/java/gregtech/common
parentce1bd5b2138093a61e9b17989ffea7c126a00c12 (diff)
downloadGT5-Unofficial-4927a8885381ca48479be71e7cdb37aae9cbf5fd.tar.gz
GT5-Unofficial-4927a8885381ca48479be71e7cdb37aae9cbf5fd.tar.bz2
GT5-Unofficial-4927a8885381ca48479be71e7cdb37aae9cbf5fd.zip
Digitalize Super Tank (#1318)
* add new GUI * make gui interactable * make later three buttons actually function * add auto output feature * do localization * apply spotless * spotless pt.2
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java146
1 files changed, 121 insertions, 25 deletions
diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java
index 6b2a9caf4b..7ccd1e62c3 100644
--- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java
+++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java
@@ -1,33 +1,36 @@
package gregtech.common.tileentities.storage;
-import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_QTANK;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_QTANK_GLOW;
+import static gregtech.api.enums.Textures.BlockIcons.*;
+import gregtech.api.gui.GT_Container_DigitalTank;
+import gregtech.api.gui.GT_GUIContainer_DigitalTank;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
+import net.minecraftforge.fluids.IFluidHandler;
public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntity_BasicTank {
- protected boolean mVoidOverflow = false;
+ public boolean mOutputFluid = false, mVoidFluidPart = false, mVoidFluidFull = false, mLockFluid = false;
+ public String lockedFluidName = null;
private boolean voidBreak;
+ public boolean mAllowInputFromOutputSide = false;
public GT_MetaTileEntity_DigitalTankBase(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 3, new String[] {
- "Stores " + GT_Utility.formatNumbers(commonSizeCompute(aTier)) + "L of fluid",
- "Use a screwdriver to enable",
- "voiding fluid on overflow",
- "Can keep its contents when harvested",
- "Sneak when harvesting to void its contents"
+ StatCollector.translateToLocalFormatted(
+ "GT5U.machines.digitaltank.tooltip", GT_Utility.formatNumbers(commonSizeCompute(aTier))),
+ StatCollector.translateToLocal("GT5U.machines.digitaltank.tooltip1"),
+ StatCollector.translateToLocal("GT5U.machines.digitaltank.tooltip2")
});
}
@@ -77,7 +80,13 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
if (mFluid != null && mFluid.amount > 0) {
aNBT.setTag("mFluid", mFluid.writeToNBT(new NBTTagCompound()));
}
- aNBT.setBoolean("mVoidOverflow", mVoidOverflow);
+ aNBT.setBoolean("mOutputFluid", this.mOutputFluid);
+ aNBT.setBoolean("mVoidOverflow", this.mVoidFluidPart);
+ aNBT.setBoolean("mVoidFluidFull", this.mVoidFluidFull);
+ aNBT.setBoolean("mLockFluid", mLockFluid);
+ if (lockedFluidName != null && lockedFluidName.length() != 0)
+ aNBT.setString("lockedFluidName", lockedFluidName);
+ else aNBT.removeTag("lockedFluidName");
}
super.setItemNBT(aNBT);
}
@@ -85,13 +94,43 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
- aNBT.setBoolean("mVoidOverflow", mVoidOverflow);
+ aNBT.setBoolean("mOutputFluid", this.mOutputFluid);
+ aNBT.setBoolean("mVoidOverflow", this.mVoidFluidPart);
+ aNBT.setBoolean("mVoidFluidFull", this.mVoidFluidFull);
+ aNBT.setBoolean("mLockFluid", mLockFluid);
+ if (lockedFluidName != null && lockedFluidName.length() != 0)
+ aNBT.setString("lockedFluidName", lockedFluidName);
+ else aNBT.removeTag("lockedFluidName");
+ aNBT.setBoolean("mAllowInputFromOutputSide", mAllowInputFromOutputSide);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
- mVoidOverflow = aNBT.getBoolean("mVoidOverflow");
+ mOutputFluid = aNBT.getBoolean("mOutputFluid");
+ mVoidFluidPart = aNBT.getBoolean("mVoidOverflow");
+ mVoidFluidFull = aNBT.getBoolean("mVoidFluidFull");
+ mLockFluid = aNBT.getBoolean("mLockFluid");
+ lockedFluidName = aNBT.getString("lockedFluidName");
+ lockedFluidName = lockedFluidName.length() == 0 ? null : lockedFluidName;
+ mAllowInputFromOutputSide = aNBT.getBoolean("mAllowInputFromOutputSide");
+ }
+
+ @Override
+ public boolean isFluidInputAllowed(FluidStack aFluid) {
+ return !mLockFluid || lockedFluidName == null || lockedFluidName.equals(aFluid.getUnlocalizedName());
+ }
+
+ @Override
+ public boolean isFluidChangingAllowed() {
+ return !mLockFluid || lockedFluidName == null;
+ }
+
+ @Override
+ public void onEmptyingContainerWhenEmpty() {
+ if (this.lockedFluidName == null && this.mFluid != null) {
+ this.lockedFluidName = this.mFluid.getUnlocalizedName();
+ }
}
@Override
@@ -137,7 +176,11 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
byte aColorIndex,
boolean aActive,
boolean aRedstone) {
- if (aSide != ForgeDirection.UP.ordinal()) return new ITexture[] {MACHINE_CASINGS[mTier][aColorIndex + 1]};
+ if (aSide != ForgeDirection.UP.ordinal()) {
+ if (aSide == aBaseMetaTileEntity.getFrontFacing()) {
+ return new ITexture[] {MACHINE_CASINGS[mTier][aColorIndex + 1], TextureFactory.of(OVERLAY_PIPE)};
+ } else return new ITexture[] {MACHINE_CASINGS[mTier][aColorIndex + 1]};
+ }
return new ITexture[] {
MACHINE_CASINGS[mTier][aColorIndex + 1],
TextureFactory.of(OVERLAY_QTANK),
@@ -159,11 +202,11 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
@Override
public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- mVoidOverflow = !mVoidOverflow;
- GT_Utility.sendChatToPlayer(
- aPlayer,
- StatCollector.translateToLocal(
- mVoidOverflow ? "GT5U.machines.voidoveflow.enabled" : "GT5U.machines.voidoveflow.disabled"));
+ if (aSide == getBaseMetaTileEntity().getFrontFacing()) {
+ mAllowInputFromOutputSide = !mAllowInputFromOutputSide;
+ GT_Utility.sendChatToPlayer(
+ aPlayer, mAllowInputFromOutputSide ? GT_Utility.getTrans("095") : GT_Utility.getTrans("096"));
+ }
}
@Override
@@ -185,11 +228,27 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
}
@Override
+ public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
+ return new GT_Container_DigitalTank(aPlayerInventory, aBaseMetaTileEntity);
+ }
+
+ @Override
+ public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
+ return new GT_GUIContainer_DigitalTank(aPlayerInventory, aBaseMetaTileEntity, getLocalName());
+ }
+
+ @Override
public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide()) {
if (isFluidChangingAllowed() && getFillableStack() != null && getFillableStack().amount <= 0)
setFillableStack(null);
+ if (mVoidFluidFull && getFillableStack() != null) {
+ mVoidFluidPart = false;
+ mLockFluid = false;
+ setFillableStack(null);
+ }
+
if (mOpenerCount > 0) updateFluidDisplayItem();
if (doesEmptyContainers()) {
@@ -197,9 +256,8 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
if (tFluid != null && isFluidInputAllowed(tFluid)) {
if (getFillableStack() == null) {
if (isFluidInputAllowed(tFluid)) {
- if ((tFluid.amount <= getRealCapacity()) || mVoidOverflow) {
+ if ((tFluid.amount <= getRealCapacity()) || mVoidFluidPart) {
tFluid = tFluid.copy();
- tFluid.amount = Math.min(tFluid.amount, getRealCapacity());
if (aBaseMetaTileEntity.addStackToSlot(
getOutputSlot(),
GT_Utility.getContainerForFilledItem(mInventory[getInputSlot()], true),
@@ -213,7 +271,8 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
} else {
if (tFluid.isFluidEqual(getFillableStack())) {
if ((((long) tFluid.amount + getFillableStack().amount) <= (long) getRealCapacity())
- || mVoidOverflow) {
+ || mVoidFluidPart
+ || mVoidFluidFull) {
if (aBaseMetaTileEntity.addStackToSlot(
getOutputSlot(),
GT_Utility.getContainerForFilledItem(mInventory[getInputSlot()], true),
@@ -264,12 +323,29 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
if (getFillableStack() == null) setFillableStack(fillableStack);
getBaseMetaTileEntity().markDirty();
}
- return mVoidOverflow ? aFluid.amount : amount;
+ return (mVoidFluidPart || mVoidFluidFull) ? aFluid.amount : amount;
}
@Override
- public final byte getUpdateData() {
- return 0x00;
+ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ super.onPostTick(aBaseMetaTileEntity, aTick);
+ if (aBaseMetaTileEntity.isServerSide()) {
+ if (mOutputFluid && getDrainableStack() != null && (aTick % 20 == 0)) {
+ IFluidHandler tTank = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing());
+ if (tTank != null) {
+ FluidStack tDrained = drain(commonSizeCompute(mTier) / 100, false);
+ if (tDrained != null) {
+ int tFilledAmount = tTank.fill(
+ ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tDrained, false);
+ if (tFilledAmount > 0)
+ tTank.fill(
+ ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()),
+ drain(tFilledAmount, true),
+ true);
+ }
+ }
+ }
+ }
}
@Override
@@ -278,6 +354,26 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
}
@Override
+ public boolean isInputFacing(byte aSide) {
+ return mAllowInputFromOutputSide || aSide != getBaseMetaTileEntity().getFrontFacing();
+ }
+
+ @Override
+ public boolean isOutputFacing(byte aSide) {
+ return false;
+ }
+
+ @Override
+ public boolean isLiquidInput(byte aSide) {
+ return mAllowInputFromOutputSide || aSide != getBaseMetaTileEntity().getFrontFacing();
+ }
+
+ @Override
+ public boolean isLiquidOutput(byte aSide) {
+ return aSide != getBaseMetaTileEntity().getFrontFacing();
+ }
+
+ @Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@@ -289,7 +385,7 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit
@Override
public int getCapacity() {
- return mVoidOverflow ? Integer.MAX_VALUE : getRealCapacity();
+ return (mVoidFluidPart || mVoidFluidFull) ? Integer.MAX_VALUE : getRealCapacity();
}
public int getRealCapacity() {