aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/GT_Pollution.java59
-rw-r--r--src/main/java/gregtech/common/GT_UndergroundOil.java32
-rw-r--r--src/main/java/gregtech/common/render/GT_PollutionRenderer.java4
3 files changed, 80 insertions, 15 deletions
diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java
index 8ad39306f1..afaac41650 100644
--- a/src/main/java/gregtech/common/GT_Pollution.java
+++ b/src/main/java/gregtech/common/GT_Pollution.java
@@ -9,6 +9,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.net.GT_Packet_Pollution;
import gregtech.api.util.GT_ChunkAssociatedData;
import gregtech.api.util.GT_Utility;
+import gregtech.common.render.GT_PollutionRenderer;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
@@ -101,6 +102,7 @@ public class GT_Pollution {
public static void onWorldTick(TickEvent.WorldTickEvent aEvent) {//called from proxy
//return if pollution disabled
if (!GT_Mod.gregtechproxy.mPollution) return;
+ if (aEvent.phase == TickEvent.Phase.START) return;
final GT_Pollution pollutionInstance = dimensionWisePollution.get(aEvent.world.provider.dimensionId);
if (pollutionInstance == null) return;
pollutionInstance.tickPollutionInWorld((int) (aEvent.world.getTotalWorldTime() % cycleLen));
@@ -278,16 +280,32 @@ public class GT_Pollution {
return dimensionWisePollution.computeIfAbsent(world.provider.dimensionId, i -> new GT_Pollution(world));
}
+ /** @see #addPollution(World, int, int, int) */
public static void addPollution(IGregTechTileEntity te, int aPollution) {
- if (!GT_Mod.gregtechproxy.mPollution || aPollution == 0) return;
+ if (!GT_Mod.gregtechproxy.mPollution || aPollution == 0 || te.isClientSide()) return;
mutatePollution(te.getWorld(), te.getXCoord() >> 4, te.getZCoord() >> 4, d -> d.changeAmount(aPollution), null);
}
+ /** @see #addPollution(World, int, int, int) */
public static void addPollution(Chunk ch, int aPollution) {
- if (!GT_Mod.gregtechproxy.mPollution || aPollution == 0) return;
+ if (!GT_Mod.gregtechproxy.mPollution || aPollution == 0 || ch.worldObj.isRemote) return;
mutatePollution(ch.worldObj, ch.xPosition, ch.zPosition, d -> d.changeAmount(aPollution), null);
}
+ /**
+ * Add some pollution to given chunk. Can pass in negative to remove pollution.
+ * Will clamp the final pollution number to 0 if it would be changed into negative.
+ *
+ * @param w world to modify. do nothing if it's a client world
+ * @param chunkX chunk coordinate X, i.e. blockX >> 4
+ * @param chunkZ chunk coordinate Z, i.e. blockZ >> 4
+ * @param aPollution desired delta. Positive means the pollution in chunk would go higher.
+ */
+ public static void addPollution(World w, int chunkX, int chunkZ, int aPollution) {
+ if (!GT_Mod.gregtechproxy.mPollution || aPollution == 0 || w.isRemote) return;
+ mutatePollution(w, chunkX, chunkZ, d -> d.changeAmount(aPollution), null);
+ }
+
private static void mutatePollution(World world, int x, int z, Consumer<ChunkData> mutator, @Nullable Set<ChunkCoordIntPair> chunks) {
ChunkData data = STORAGE.get(world, x, z);
boolean hadPollution = data.getAmount() > 0;
@@ -303,14 +321,36 @@ public class GT_Pollution {
}
}
+ /** @see #getPollution(World, int, int) */
public static int getPollution(IGregTechTileEntity te) {
- return getPollution(te.getWorld().getChunkFromBlockCoords(te.getXCoord(), te.getZCoord()));
+ return getPollution(te.getWorld(), te.getXCoord() >> 4, te.getZCoord() >> 4);
}
+ /** @see #getPollution(World, int, int) */
public static int getPollution(Chunk ch) {
+ return getPollution(ch.worldObj, ch.xPosition, ch.zPosition);
+ }
+
+ /**
+ * Get the pollution in specified chunk
+ * @param w world to look in. can be a client world, but that limits the knowledge to what server side send us
+ * @param chunkX chunk coordinate X, i.e. blockX >> 4
+ * @param chunkZ chunk coordinate Z, i.e. blockZ >> 4
+ * @return pollution amount. may be 0 if pollution is disabled, or if it's a client world and server did not send
+ * us info about this chunk
+ */
+ public static int getPollution(World w, int chunkX, int chunkZ) {
if (!GT_Mod.gregtechproxy.mPollution)
return 0;
- return STORAGE.get(ch).getAmount();
+ if (w.isRemote)
+ // it really should be querying the client side stuff instead
+ return GT_PollutionRenderer.getKnownPollution(chunkX << 4, chunkZ << 4);
+ return STORAGE.get(w, chunkX, chunkZ).getAmount();
+ }
+
+ @Deprecated
+ public static int getPollution(ChunkCoordIntPair aCh, int aDim) {
+ return getPollution(DimensionManager.getWorld(aDim), aCh.chunkXPos, aCh.chunkZPos);
}
public static boolean hasPollution(Chunk ch) {
@@ -319,12 +359,6 @@ public class GT_Pollution {
return STORAGE.isCreated(ch.worldObj, ch.getChunkCoordIntPair()) && STORAGE.get(ch).getAmount() > 0;
}
- public static int getPollution(ChunkCoordIntPair aCh, int aDim) {
- if (!GT_Mod.gregtechproxy.mPollution)
- return 0;
- return STORAGE.get(DimensionManager.getWorld(aDim), aCh.chunkXPos, aCh.chunkZPos).getAmount();
- }
-
//Add compatibility with old code
@Deprecated /*Don't use it... too weird way of passing position*/
public static void addPollution(World aWorld, ChunkPosition aPos, int aPollution) {
@@ -352,7 +386,8 @@ public class GT_Pollution {
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load e) {
// super class loads everything lazily. We force it to load them all.
- STORAGE.loadAll(e.world);
+ if (!e.world.isRemote)
+ STORAGE.loadAll(e.world);
}
}
@@ -369,6 +404,8 @@ public class GT_Pollution {
@Override
protected ChunkData readElement(DataInput input, int version, World world, int chunkX, int chunkZ) throws IOException {
+ if (version != 0)
+ throw new IOException("Region file corrupted");
ChunkData data = new ChunkData(input.readInt());
if (data.getAmount() > 0)
getPollutionManager(world).pollutedChunks.add(new ChunkCoordIntPair(chunkX, chunkZ));
diff --git a/src/main/java/gregtech/common/GT_UndergroundOil.java b/src/main/java/gregtech/common/GT_UndergroundOil.java
index 21b681de4a..b725b4bbb6 100644
--- a/src/main/java/gregtech/common/GT_UndergroundOil.java
+++ b/src/main/java/gregtech/common/GT_UndergroundOil.java
@@ -31,22 +31,46 @@ public class GT_UndergroundOil {
private static final GT_UndergroundOilStore STORAGE = new GT_UndergroundOilStore();
private static final ChunkData NIL_FLUID_STACK = new ChunkData(-1, null, null, false);
+ /**
+ * Effectively just call {@code undergroundOil(te, -1)} for you
+ * @see #undergroundOil(World, int, int, float)
+ */
public static FluidStack undergroundOilReadInformation(IGregTechTileEntity te){
return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),-1);
}
+ /**
+ * Effectively just call {@code undergroundOil(chunk, -1)} for you
+ * @see #undergroundOil(World, int, int, float)
+ */
public static FluidStack undergroundOilReadInformation(Chunk chunk) {
return undergroundOil(chunk,-1);
}
+ /** @see #undergroundOil(World, int, int, float) */
public static FluidStack undergroundOil(IGregTechTileEntity te, float readOrDrainCoefficient){
return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),readOrDrainCoefficient);
}
//Returns whole content for information purposes -> when drainSpeedCoefficient < 0
//Else returns extracted fluidStack if amount > 0, or null otherwise
+ /** @see #undergroundOil(World, int, int, float) */
public static FluidStack undergroundOil(Chunk chunk, float readOrDrainCoefficient) {
- ChunkData chunkData = STORAGE.get(chunk);
+ return undergroundOil(chunk.worldObj, chunk.xPosition, chunk.zPosition, readOrDrainCoefficient);
+ }
+
+ /**
+ * Pump fluid or read info.
+ * @param w a remote World. For a WorldClient it will always tell you null
+ * @param chunkX chunk coordinate X, i.e. blockX >> 4
+ * @param chunkZ chunk coordinate Z, i.e. blockZ >> 4
+ * @param readOrDrainCoefficient how fast to pump. The higher the faster. use negative to read expected current output
+ * @return null if nothing here, or depleted already, or a client side world
+ */
+ public static FluidStack undergroundOil(World w, int chunkX, int chunkZ, float readOrDrainCoefficient) {
+ if (w.isRemote)
+ return null; // troublemakers go away
+ ChunkData chunkData = STORAGE.get(w, chunkX, chunkZ);
if (chunkData.getVein() == null || chunkData.getFluid() == null) // nothing here...
return null;
//do stuff on it if needed
@@ -102,7 +126,7 @@ public class GT_UndergroundOil {
ChunkData chunkData = STORAGE.get(e.getChunk());
Fluid fluid = chunkData.getFluid();
if (fluid != null && fluid.getID() == e.getData().getInteger("GTOILFLUID"))
- chunkData.setAmount(Math.min(0, Math.min(chunkData.getAmount(), e.getData().getInteger("GTOIL"))));
+ chunkData.setAmount(Math.min(chunkData.getAmount(), e.getData().getInteger("GTOIL")));
}
}
@@ -250,7 +274,7 @@ public class GT_UndergroundOil {
public void changeAmount(int delta) {
if (delta != 0)
dirty = true;
- this.amount = Math.max(0, amount - delta);
+ this.amount = Math.max(amount + delta, 0);
}
@Nullable
@@ -272,7 +296,7 @@ public class GT_UndergroundOil {
@Override
public boolean isSameAsDefault() {
- return dirty;
+ return !dirty;
}
}
}
diff --git a/src/main/java/gregtech/common/render/GT_PollutionRenderer.java b/src/main/java/gregtech/common/render/GT_PollutionRenderer.java
index 305eadf145..5128af1c36 100644
--- a/src/main/java/gregtech/common/render/GT_PollutionRenderer.java
+++ b/src/main/java/gregtech/common/render/GT_PollutionRenderer.java
@@ -101,6 +101,10 @@ public class GT_PollutionRenderer {
return color(oColor, pollutionMap.getPollution(x, z)/1000, 300, 500, foliageColor);
}
+ public static int getKnownPollution(int x, int z) {
+ return pollutionMap.getPollution(x, z);
+ }
+
@SubscribeEvent(priority = EventPriority.LOW)
public void manipulateColor(EntityViewRenderEvent.FogColors event) {
if (!DEBUG && Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode)