aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2021-04-03 16:48:30 +0200
committerGitHub <noreply@github.com>2021-04-03 16:48:30 +0200
commite04ad467cd52d2a0cba6f3d298f80ea25113741f (patch)
tree54a80d50221c2b72b3182827a21dff5b94c04876 /src
parenta08f2915bf68c370b9cd6356da0a637e15f37dae (diff)
downloadGT5-Unofficial-e04ad467cd52d2a0cba6f3d298f80ea25113741f.tar.gz
GT5-Unofficial-e04ad467cd52d2a0cba6f3d298f80ea25113741f.tar.bz2
GT5-Unofficial-e04ad467cd52d2a0cba6f3d298f80ea25113741f.zip
Polished GT_MetaTileEntity_Boiler (#492)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java185
1 files changed, 128 insertions, 57 deletions
diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java
index a65c9dde69..9c52df7986 100644
--- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java
+++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java
@@ -44,6 +44,7 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
super(aName, aTier, 4, aDescription, aTextures);
}
+ @Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
ITexture[] tmp = mTextures[aSide >= 2 ? aSide != aFacing ? 2 : ((byte) (aActive ? 4 : 3)) : aSide][aColorIndex + 1];
if (aSide != aFacing && tmp.length == 2) {
@@ -52,49 +53,59 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
return tmp;
}
+ @Override
public boolean isElectric() {
return false;
}
+ @Override
public boolean isPneumatic() {
return false;
}
+ @Override
public boolean isSteampowered() {
return false;
}
+ @Override
public boolean isSimpleMachine() {
return false;
}
+ @Override
public boolean isFacingValid(byte aFacing) {
return aFacing > 1;
}
+ @Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
+ @Override
public boolean isValidSlot(int aIndex) {
return true;
}
+ @Override
public int getProgresstime() {
return this.mTemperature;
}
+ @Override
public int maxProgresstime() {
return 500;
}
+ @Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
if (aBaseMetaTileEntity.isClientSide()) {
return true;
}
if (aPlayer != null) {
if (GT_Utility.areStacksEqual(aPlayer.getCurrentEquippedItem(), new ItemStack(Items.water_bucket, 1))) {
- fill(Materials.Water.getFluid(1000 * aPlayer.getCurrentEquippedItem().stackSize), true);
+ fill(Materials.Water.getFluid(1000L * (long) aPlayer.getCurrentEquippedItem().stackSize), true);
aPlayer.getCurrentEquippedItem().func_150996_a(Items.bucket);
} else {
aBaseMetaTileEntity.openGUI(aPlayer);
@@ -103,38 +114,47 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
return true;
}
+ @Override
public boolean doesFillContainers() {
return true;
}
+ @Override
public boolean doesEmptyContainers() {
return true;
}
+ @Override
public boolean canTankBeFilled() {
return true;
}
+ @Override
public boolean canTankBeEmptied() {
return true;
}
+ @Override
public boolean displaysItemStack() {
return false;
}
+ @Override
public boolean displaysStackSize() {
return false;
}
+ @Override
public boolean isFluidInputAllowed(FluidStack aFluid) {
return GT_ModHandler.isWater(aFluid);
}
+ @Override
public FluidStack getDrainableStack() {
return this.mSteam;
}
+ @Override
public FluidStack setDrainableStack(FluidStack aFluid) {
this.mSteam = aFluid;
return this.mSteam;
@@ -145,24 +165,27 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
return true;
}
+ @Override
public boolean allowCoverOnSide(byte aSide, GT_ItemStack aCover) {
return GregTech_API.getCoverBehavior(aCover.toStack()).isSimpleCover();
}
+ @Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setInteger("mLossTimer", this.mLossTimer);
aNBT.setInteger("mTemperature", this.mTemperature);
aNBT.setInteger("mProcessingEnergy", this.mProcessingEnergy);
aNBT.setInteger("mExcessWater", this.mExcessWater);
- if (this.mSteam != null) {
- try {
- aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound()));
- } catch (Throwable ignored) {
- }
+ if (this.mSteam == null) {
+ return;
}
+ try {
+ aNBT.setTag("mSteam", this.mSteam.writeToNBT(new NBTTagCompound()));
+ } catch (Throwable ignored) {}
}
+ @Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
this.mLossTimer = aNBT.getInteger("mLossTimer");
@@ -189,73 +212,118 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
}
}
+ @Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
- if ((aBaseMetaTileEntity.isServerSide()) && (aTick > 20L)) {
- if (this.mTemperature <= 20) {
- this.mTemperature = 20;
- this.mLossTimer = 0;
- } else if (++this.mLossTimer > getCooldownInterval()) {
- // only loss temperature if hot
- this.mTemperature -= 1;
- this.mLossTimer = 0;
- }
- for (int i = 1; (this.mSteam != null) && (i < 6); i++) {
- if (i != aBaseMetaTileEntity.getFrontFacing()) {
- IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide((byte) i);
- if (tTileEntity != null) {
- FluidStack tDrained = aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false);
- if (tDrained != null) {
- int tFilledAmount = tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), tDrained, false);
- if (tFilledAmount > 0) {
- tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), true);
- }
- }
- }
- }
- }
- if (aTick % 10L == 0L) {
- if (this.mTemperature > 100) {
- if ((!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) {
- this.mHadNoWater = true;
- } else {
- if (this.mHadNoWater) {
- GT_Log.exp.println("Boiler "+this.mName+" had no Water!");
- aBaseMetaTileEntity.doExplosion(2048L);
- return;
- }
- produceSteam(getProductionPerSecond() / 2);
- }
- } else {
- this.mHadNoWater = false;
- }
- }
- if ((this.mSteam != null) &&
- (this.mSteam.amount > getCapacity())) {
- sendSound((byte) 1);
- this.mSteam.amount = getCapacity() * 3 / 4;
- }
- if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()))
- updateFuel(aBaseMetaTileEntity, aTick);
- if ((this.mTemperature < getMaxTemperature()) && (this.mProcessingEnergy > 0) && (aTick % 12L == 0L)) {
- this.mProcessingEnergy -= getEnergyConsumption();
- this.mTemperature += 1;
- }
- aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0);
+ pollute(aTick);
+
+ if (isNotAllowedToWork(aBaseMetaTileEntity, aTick))
+ return;
+
+ calculateCooldown();
+ pushSteamToInventories(aBaseMetaTileEntity);
+
+ if (canNotCreateSteam(aBaseMetaTileEntity, aTick)) {
+ pollute(aTick);
+ return;
}
+
+ ventSteamIfTankIsFull();
+ updateFuelTimed(aBaseMetaTileEntity, aTick);
+ calculateHeatUp(aBaseMetaTileEntity, aTick);
+ }
+
+ private boolean isNotAllowedToWork(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ return (!aBaseMetaTileEntity.isServerSide()) || (aTick <= 20L);
+ }
+
+ private void pollute(long aTick) {
if (this.mProcessingEnergy > 0 && (aTick % 20L == 0L)) {
GT_Pollution.addPollution(getBaseMetaTileEntity(), getPollution());
}
}
+ private void calculateHeatUp(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ if ((this.mTemperature < getMaxTemperature()) && (this.mProcessingEnergy > 0) && (aTick % 12L == 0L)) {
+ this.mProcessingEnergy -= getEnergyConsumption();
+ this.mTemperature += 1;
+ }
+ aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0);
+ }
+
+ private void updateFuelTimed(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ if ((this.mProcessingEnergy <= 0) && (aBaseMetaTileEntity.isAllowedToWork()))
+ updateFuel(aBaseMetaTileEntity, aTick);
+ }
+
+ private void ventSteamIfTankIsFull() {
+ if ((this.mSteam != null) && (this.mSteam.amount > getCapacity())) {
+ sendSound((byte) 1);
+ this.mSteam.amount = getCapacity() * 3 / 4;
+ }
+ }
+
+ private boolean canNotCreateSteam(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ if (aTick % 10L != 0L) {
+ return false;
+ }
+
+ if (this.mTemperature > 100) {
+ if ((!GT_ModHandler.isWater(this.mFluid)) || (this.mFluid.amount <= 0)) {
+ this.mHadNoWater = true;
+ } else {
+ if (this.mHadNoWater) {
+ GT_Log.exp.println("Boiler "+this.mName+" had no Water!");
+ aBaseMetaTileEntity.doExplosion(2048L);
+ return true;
+ }
+ produceSteam(getProductionPerSecond() / 2);
+ }
+ } else {
+ this.mHadNoWater = false;
+ }
+ return false;
+ }
+
+ private void pushSteamToInventories(IGregTechTileEntity aBaseMetaTileEntity) {
+ for (int i = 1; (this.mSteam != null) && (i < 6); i++) {
+ if (i == aBaseMetaTileEntity.getFrontFacing())
+ continue;
+ IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide((byte) i);
+ if (tTileEntity == null)
+ continue;
+ FluidStack tDrained = aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), Math.max(1, this.mSteam.amount / 2), false);
+ if (tDrained == null)
+ continue;
+ int tFilledAmount = tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), tDrained, false);
+ if (tFilledAmount <= 0)
+ continue;
+ tTileEntity.fill(ForgeDirection.getOrientation(i).getOpposite(), aBaseMetaTileEntity.drain(ForgeDirection.getOrientation(i), tFilledAmount, true), true);
+ }
+ }
+
+ private void calculateCooldown() {
+ if (this.mTemperature <= 20) {
+ this.mTemperature = 20;
+ this.mLossTimer = 0;
+ } else if (++this.mLossTimer > getCooldownInterval()) {
+ // only loss temperature if hot
+ this.mTemperature -= 1;
+ this.mLossTimer = 0;
+ }
+ }
+
+ @Override
public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation;
}
+ @Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation;
}
+ @Override
public void doSound(byte aIndex, double aX, double aY, double aZ) {
if (aIndex == 1) {
GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(4), 2, 1.0F, aX, aY, aZ);
@@ -273,12 +341,15 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa
);
}
}
+
+ @Override
public int getTankPressure() {
return 100;
}
protected abstract int getPollution();
+ @Override
public int getCapacity() {
return 16000;
}