aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorMaxim <maxim235@gmx.de>2023-01-18 00:01:46 +0100
committerGitHub <noreply@github.com>2023-01-18 00:01:46 +0100
commit921859c68e64e865e4e18ec98be7eecf4e5344e0 (patch)
tree7b187f045eeb76411cc5e05553c2ee0964ff33ac /src/main/java/gregtech/api
parentdd69992906ab5828338ec7ed7d39182e6e9b24c9 (diff)
downloadGT5-Unofficial-921859c68e64e865e4e18ec98be7eecf4e5344e0.tar.gz
GT5-Unofficial-921859c68e64e865e4e18ec98be7eecf4e5344e0.tar.bz2
GT5-Unofficial-921859c68e64e865e4e18ec98be7eecf4e5344e0.zip
Added getter if machine is rain proof (#1662)
* Added getter if machine is rain proof * Extract rain checker to prevent needless computation * Minor refactoring
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java129
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaTileEntity.java9
2 files changed, 79 insertions, 59 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index f2da90cde9..821cfcd8a7 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -268,6 +268,31 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity
return biome.rainfall > 0 && (biome.canSpawnLightningBolt() || biome.getEnableSnow());
}
+ /**
+ * Check if this is exposed to rain
+ *
+ * @return True if exposed to rain, else false
+ */
+ public boolean isRainExposed() {
+ final int precipitationHeightAtSide2 = worldObj.getPrecipitationHeight(xCoord, zCoord - 1);
+ final int precipitationHeightAtSide3 = worldObj.getPrecipitationHeight(xCoord, zCoord + 1);
+ final int precipitationHeightAtSide4 = worldObj.getPrecipitationHeight(xCoord - 1, zCoord);
+ final int precipitationHeightAtSide5 = worldObj.getPrecipitationHeight(xCoord + 1, zCoord);
+ return (getCoverIDAtSide((byte) 1) == 0 && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord)
+ || (getCoverIDAtSide((byte) 2) == 0
+ && precipitationHeightAtSide2 - 1 < yCoord
+ && precipitationHeightAtSide2 > -1)
+ || (getCoverIDAtSide((byte) 3) == 0
+ && precipitationHeightAtSide3 - 1 < yCoord
+ && precipitationHeightAtSide3 > -1)
+ || (getCoverIDAtSide((byte) 4) == 0
+ && precipitationHeightAtSide4 - 1 < yCoord
+ && precipitationHeightAtSide4 > -1)
+ || (getCoverIDAtSide((byte) 5) == 0
+ && precipitationHeightAtSide5 - 1 < yCoord
+ && precipitationHeightAtSide5 > -1);
+ }
+
@Override
public void updateEntity() {
super.updateEntity();
@@ -411,67 +436,53 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity
return;
}
- if (getRandomNumber(1000) == 0 && isRainPossible()) {
- final int precipitationHeightAtSide2 =
- worldObj.getPrecipitationHeight(xCoord, zCoord - 1);
- final int precipitationHeightAtSide3 =
- worldObj.getPrecipitationHeight(xCoord, zCoord + 1);
- final int precipitationHeightAtSide4 =
- worldObj.getPrecipitationHeight(xCoord - 1, zCoord);
- final int precipitationHeightAtSide5 =
- worldObj.getPrecipitationHeight(xCoord + 1, zCoord);
-
- if ((getCoverIDAtSide((byte) 1) == 0
- && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord)
- || (getCoverIDAtSide((byte) 2) == 0
- && precipitationHeightAtSide2 - 1 < yCoord
- && precipitationHeightAtSide2 > -1)
- || (getCoverIDAtSide((byte) 3) == 0
- && precipitationHeightAtSide3 - 1 < yCoord
- && precipitationHeightAtSide3 > -1)
- || (getCoverIDAtSide((byte) 4) == 0
- && precipitationHeightAtSide4 - 1 < yCoord
- && precipitationHeightAtSide4 > -1)
- || (getCoverIDAtSide((byte) 5) == 0
- && precipitationHeightAtSide5 - 1 < yCoord
- && precipitationHeightAtSide5 > -1)) {
- if (GregTech_API.sMachineRainExplosions && worldObj.isRaining()) {
- if (getRandomNumber(10) == 0) {
- try {
- GT_Mod.achievements.issueAchievement(
- this.getWorldObj().getPlayerEntityByName(mOwnerName),
- "badweather");
- } catch (Exception ignored) {
+ if (GregTech_API.sMachineRainExplosions) {
+ if (mMetaTileEntity.willExplodeInRain()) {
+ if (getRandomNumber(1000) == 0 && isRainPossible()) {
+ if (isRainExposed()) {
+ if (worldObj.isRaining()) {
+ if (getRandomNumber(10) == 0) {
+ try {
+ GT_Mod.achievements.issueAchievement(
+ this.getWorldObj()
+ .getPlayerEntityByName(mOwnerName),
+ "badweather");
+ } catch (Exception ignored) {
+ }
+ GT_Log.exp.println("Machine at: " + this.getXCoord() + " | "
+ + this.getYCoord() + " | " + this.getZCoord() + " DIMID: "
+ + this.worldObj.provider.dimensionId
+ + " explosion due to rain!");
+ doEnergyExplosion();
+ } else {
+ GT_Log.exp.println("Machine at: " + this.getXCoord() + " | "
+ + this.getYCoord() + " | " + this.getZCoord() + " DIMID: "
+ + this.worldObj.provider.dimensionId
+ + " set to Fire due to rain!");
+ setOnFire();
+ }
+ }
+ if (!hasValidMetaTileEntity()) {
+ mRunningThroughTick = false;
+ return;
+ }
+ if (GregTech_API.sMachineThunderExplosions
+ && worldObj.isThundering()
+ && getRandomNumber(3) == 0) {
+ try {
+ GT_Mod.achievements.issueAchievement(
+ this.getWorldObj().getPlayerEntityByName(mOwnerName),
+ "badweather");
+ } catch (Exception ignored) {
+ }
+ GT_Log.exp.println(
+ "Machine at: " + this.getXCoord() + " | " + this.getYCoord()
+ + " | " + this.getZCoord() + " DIMID: "
+ + this.worldObj.provider.dimensionId
+ + " explosion due to Thunderstorm!");
+ doEnergyExplosion();
}
- GT_Log.exp.println("Machine at: " + this.getXCoord() + " | "
- + this.getYCoord() + " | " + this.getZCoord() + " DIMID: "
- + this.worldObj.provider.dimensionId + " explosion due to rain!");
- doEnergyExplosion();
- } else {
- GT_Log.exp.println("Machine at: " + this.getXCoord() + " | "
- + this.getYCoord() + " | " + this.getZCoord() + " DIMID: "
- + this.worldObj.provider.dimensionId
- + " set to Fire due to rain!");
- setOnFire();
- }
- }
- if (!hasValidMetaTileEntity()) {
- mRunningThroughTick = false;
- return;
- }
- if (GregTech_API.sMachineThunderExplosions
- && worldObj.isThundering()
- && getRandomNumber(3) == 0) {
- try {
- GT_Mod.achievements.issueAchievement(
- this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather");
- } catch (Exception ignored) {
}
- GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord()
- + " | " + this.getZCoord() + " DIMID: "
- + this.worldObj.provider.dimensionId
- + " explosion due to Thunderstorm!");
- doEnergyExplosion();
}
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
index 21a93307e5..8f1c3f2e48 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
@@ -752,6 +752,15 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac
}
/**
+ * Flag if this MTE will exploding when its raining
+ *
+ * @return True if this will explode in rain, else false
+ */
+ public boolean willExplodeInRain() {
+ return true;
+ }
+
+ /**
* Gets the Output for the comparator on the given Side
*/
@Override