aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlood-Asp <bloodasphendrik@gmail.com>2017-06-14 23:51:39 +0200
committerBlood-Asp <bloodasphendrik@gmail.com>2017-06-14 23:51:39 +0200
commit911a80752930d6207fc0b850f3ccf8b3da05b0a5 (patch)
tree76ba0e8245b9e871ea730c6ce7355b55cf88f81a
parent6b4b32200dce4e3ca2e2813a106a50cb14be38a8 (diff)
downloadGT5-Unofficial-911a80752930d6207fc0b850f3ccf8b3da05b0a5.tar.gz
GT5-Unofficial-911a80752930d6207fc0b850f3ccf8b3da05b0a5.tar.bz2
GT5-Unofficial-911a80752930d6207fc0b850f3ccf8b3da05b0a5.zip
pollution smog
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_Pollution.java43
-rw-r--r--src/main/java/gregtech/common/GT_Client.java42
-rw-r--r--src/main/java/gregtech/common/GT_Network.java8
-rw-r--r--src/main/java/gregtech/common/GT_Pollution.java8
-rw-r--r--src/main/java/gregtech/common/GT_Proxy.java7
5 files changed, 107 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/net/GT_Packet_Pollution.java b/src/main/java/gregtech/api/net/GT_Packet_Pollution.java
new file mode 100644
index 0000000000..e403cae4e9
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_Pollution.java
@@ -0,0 +1,43 @@
+package gregtech.api.net;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+
+import gregtech.common.GT_Pollution;
+import net.minecraft.world.IBlockAccess;
+
+public class GT_Packet_Pollution extends GT_Packet {
+ private int mPollution;
+
+ public GT_Packet_Pollution() {
+ super(true);
+ }
+
+ public GT_Packet_Pollution(int aPollution) {
+ super(false);
+ mPollution = aPollution;
+ }
+
+ @Override
+ public byte[] encode() {
+ ByteArrayDataOutput tOut = ByteStreams.newDataOutput(4);
+ tOut.writeInt(mPollution);
+ return tOut.toByteArray();
+ }
+
+ @Override
+ public GT_Packet decode(ByteArrayDataInput aData) {
+ return new GT_Packet_Pollution(aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ GT_Pollution.mPlayerPollution = mPollution;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 4;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java
index 494e399762..4e255050b7 100644
--- a/src/main/java/gregtech/common/GT_Client.java
+++ b/src/main/java/gregtech/common/GT_Client.java
@@ -9,6 +9,7 @@ import codechicken.lib.vec.Rotation;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
+import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.Materials;
@@ -30,6 +31,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
+import net.minecraftforge.client.event.EntityViewRenderEvent;
+import net.minecraftforge.event.terraingen.BiomeEvent;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.opengl.GL11;
@@ -140,6 +143,45 @@ public class GT_Client extends GT_Proxy
GL11.glEnd();
GL11.glPopMatrix();
}
+
+ @SubscribeEvent
+ public void manipulateDensity(EntityViewRenderEvent.FogDensity event) {
+ System.out.println("test: "+GT_Pollution.mPlayerPollution);
+ if(GT_Pollution.mPlayerPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){
+ event.density = 0.25f/(GT_Pollution.mPlayerPollution/GT_Mod.gregtechproxy.mPollutionSourRainLimit);
+ event.setCanceled(true);
+ }
+ }
+
+ @SubscribeEvent
+ public void manipulateColor(EntityViewRenderEvent.FogColors event) {
+ if(GT_Pollution.mPlayerPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){
+ event.red = 140f/255f;
+ event.green = 80f/255f;
+ event.blue = 40f/255f;
+ }
+ }
+
+ @SubscribeEvent
+ public void manipulateGrassColor(BiomeEvent.GetGrassColor event) {
+ if(GT_Pollution.mPlayerPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){
+ event.newColor = 0xD2691E;
+ }
+ }
+
+ @SubscribeEvent
+ public void manipulateWaterColor(BiomeEvent.GetWaterColor event) {
+ if(GT_Pollution.mPlayerPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){
+ event.newColor = 0x556B2F;
+ }
+ }
+
+ @SubscribeEvent
+ public void manipulateFoliageColor(BiomeEvent.GetFoliageColor event) {
+ if(GT_Pollution.mPlayerPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){
+ event.newColor = 0xCD853F;
+ }
+ }
public boolean isServerSide() {
return true;
diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java
index 2b19b98dff..ae444429bf 100644
--- a/src/main/java/gregtech/common/GT_Network.java
+++ b/src/main/java/gregtech/common/GT_Network.java
@@ -32,7 +32,7 @@ public class GT_Network
public GT_Network() {
this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", new ChannelHandler[]{this, new HandlerShared()});
- this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores()};
+ this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores(), new GT_Packet_Pollution()};
}
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput)
@@ -47,6 +47,12 @@ public class GT_Network
}
public void sendToPlayer(GT_Packet aPacket, EntityPlayerMP aPlayer) {
+ if(aPacket==null){
+ System.out.println("packet null");return;
+ }
+ if(aPlayer==null){
+ System.out.println("player null");return;
+ }
((FMLEmbeddedChannel) this.mChannel.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
((FMLEmbeddedChannel) this.mChannel.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(aPlayer);
((FMLEmbeddedChannel) this.mChannel.get(Side.SERVER)).writeAndFlush(aPacket);
diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java
index 175ea6ac85..6669bf861a 100644
--- a/src/main/java/gregtech/common/GT_Pollution.java
+++ b/src/main/java/gregtech/common/GT_Pollution.java
@@ -62,6 +62,7 @@ public class GT_Pollution {
private int operationsPerTick=0;//how much chunks should be processed in each cycle
private static final short cycleLen=1200;
private final World aWorld;
+ public static int mPlayerPollution;
public GT_Pollution(World world){
aWorld=world;
@@ -260,6 +261,13 @@ public class GT_Pollution {
if(dataMap==null || dataMap.get(ch.getChunkCoordIntPair())==null) return 0;
return dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION];
}
+
+ public static int getPollution(ChunkCoordIntPair aCh, int aDim){
+ if(!GT_Mod.gregtechproxy.mPollution)return 0;
+ HashMap<ChunkCoordIntPair,int[]> dataMap=dimensionWiseChunkData.get(aDim);
+ if(dataMap==null || dataMap.get(aCh)==null) return 0;
+ return dataMap.get(aCh)[GTPOLLUTION];
+ }
//Add compatibility with old code
@Deprecated /*Don't use it... too weird way of passing position*/
diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java
index a7da28c78e..96b957e01c 100644
--- a/src/main/java/gregtech/common/GT_Proxy.java
+++ b/src/main/java/gregtech/common/GT_Proxy.java
@@ -24,6 +24,7 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.items.GT_MetaGenerated_Item;
import gregtech.api.items.GT_MetaGenerated_Tool;
+import gregtech.api.net.GT_Packet_Pollution;
import gregtech.api.objects.GT_Fluid;
import gregtech.api.objects.GT_FluidStack;
import gregtech.api.objects.GT_UO_DimensionList;
@@ -47,6 +48,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -1325,6 +1327,11 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
aEvent.player.addExhaustion(Math.max(1.0F, tCount / 666.6F));
}
}
+ if (aEvent.player.ticksExisted % 10 == 0) {
+ int tPollution = 0;
+ tPollution = GT_Pollution.getPollution(new ChunkCoordIntPair(aEvent.player.chunkCoordX,aEvent.player.chunkCoordZ), aEvent.player.dimension);
+ if(aEvent.player instanceof EntityPlayerMP)GT_Values.NW.sendToPlayer(new GT_Packet_Pollution(tPollution), (EntityPlayerMP) aEvent.player);
+ }
}
}