From 82458fed2e4c065091f38340ceb05e98f28fc459 Mon Sep 17 00:00:00 2001 From: Technus Date: Mon, 1 May 2017 08:18:30 +0200 Subject: Cherry-Pick c12e474 https://github.com/GTNewHorizons/GT5-Unofficial/commit/c12e474c23ca02fb3479312850f6ae07e623d8b9 --- src/main/java/gregtech/common/GT_Pollution.java | 250 ++++++++++++++---------- 1 file changed, 150 insertions(+), 100 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Pollution.java') diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index a950e8a2f2..4ab0c97d79 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -1,6 +1,8 @@ package gregtech.common; +import cpw.mods.fml.common.gameevent.TickEvent; import gregtech.GT_Mod; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.XSTR; import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; @@ -10,12 +12,17 @@ import net.minecraft.init.Blocks; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkPosition; import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.event.world.WorldEvent; -import java.util.ArrayList; -import java.util.List; +import java.util.*; + +import static gregtech.common.GT_Proxy.*; + +//import net.minecraft.entity.EntityLiving; public class GT_Pollution { /** @@ -49,95 +56,131 @@ public class GT_Pollution { * Muffler Hatch Pollution reduction: * LV (0%), MV (30%), HV (52%), EV (66%), IV (76%), LuV (84%), ZPM (89%), UV (92%), MAX (95%) */ + private static XSTR tRan = new XSTR(); + private List pollutionList = new ArrayList<>();//chunks left to process + private HashMap chunkData;//link to chunk data that is saved/loaded + private int operationsPerTick=0;//how much chunks should be processed in each cycle + private static final short cycleLen=1200; + private final World aWorld; - static List tList = null; - static int loops = 1; - static XSTR tRan = new XSTR(); + public GT_Pollution(World world){ + aWorld=world; + chunkData=dimensionWiseChunkData.get(aWorld.provider.dimensionId); + if(chunkData==null){ + chunkData=new HashMap<>(1024); + dimensionWiseChunkData.put(world.provider.dimensionId,chunkData); + } + dimensionWisePollution.put(aWorld.provider.dimensionId,this); + } - public static void onWorldTick(World aWorld, int aTick){ - if(!GT_Mod.gregtechproxy.mPollution)return; - if(aTick == 0 || (tList==null && GT_Proxy.chunkData!=null)){ - tList = new ArrayList(GT_Proxy.chunkData.keySet()); - loops = (tList.size()/1200) + 1; -// System.out.println("new Pollution loop"+aTick); + public static void onWorldTick(TickEvent.WorldTickEvent aEvent){//called from proxy + //return if pollution disabled + if(!GT_Mod.gregtechproxy.mPollution) return; + final GT_Pollution pollutionInstance = dimensionWisePollution.get(aEvent.world.provider.dimensionId); + if(pollutionInstance==null)return; + pollutionInstance.tickPollutionInWorld((int)(aEvent.world.getTotalWorldTime()%cycleLen)); + } + + private void tickPollutionInWorld(int aTickID){//called from method above + //gen data set + if(aTickID==0){ + pollutionList = new ArrayList<>(chunkData.keySet()); + //set operations per tick + if(pollutionList.size()>0) operationsPerTick =(pollutionList.size()/cycleLen); + else operationsPerTick=0;//SANity } - if(tList!=null && tList.size() > 0){ - int i = 0; - for(; i < loops ; i++){ - if(tList.size()>0){ - ChunkPosition tPos = tList.get(0); - tList.remove(0); - if(tPos!=null && GT_Proxy.chunkData.containsKey(tPos)){ - int tPollution = GT_Proxy.chunkData.get(tPos)[1]; -// System.out.println("process: "+tPos.chunkPosY+" "+tPos.chunkPosX+" "+tPos.chunkPosZ+" "+tPollution); - //Reduce pollution in chunk - tPollution = (int)(0.99f*tPollution); - tPollution -= 2000; - if(tPollution<=0){tPollution = 0;} - //Spread Pollution - if(tPollution>50000){ - List tNeighbor = new ArrayList(); - tNeighbor.add(new ChunkPosition(tPos.chunkPosX+1, tPos.chunkPosY, tPos.chunkPosZ)); - tNeighbor.add(new ChunkPosition(tPos.chunkPosX-1, tPos.chunkPosY, tPos.chunkPosZ)); - tNeighbor.add(new ChunkPosition(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ+1)); - tNeighbor.add(new ChunkPosition(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ-1)); - for(ChunkPosition tNPos : tNeighbor){ - if(GT_Proxy.chunkData.containsKey(tNPos)){ - int tNPol = GT_Proxy.chunkData.get(tNPos)[1]; - if(tNPol400000){//Spread Pollution + + ChunkCoordIntPair[] tNeighbors = new ChunkCoordIntPair[4];//array is faster + tNeighbors[0]=(new ChunkCoordIntPair(actualPos.chunkXPos+1,actualPos.chunkZPos)); + tNeighbors[1]=(new ChunkCoordIntPair(actualPos.chunkXPos-1,actualPos.chunkZPos)); + tNeighbors[2]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos+1)); + tNeighbors[3]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos-1)); + for(ChunkCoordIntPair neighborPosition : tNeighbors){ + if(!chunkData.containsKey(neighborPosition)) chunkData.put(actualPos,getDefaultChunkDataOnCreation()); + + int neighborPollution = chunkData.get(neighborPosition)[GTPOLLUTION]; + if(neighborPollution*6 < tPollution*5){//METHEMATICS... + int tDiff = tPollution - neighborPollution; + tDiff = tDiff/20; + neighborPollution = GT_Utility.safeInt((long)neighborPollution+tDiff);//tNPol += tDiff; + tPollution -= tDiff; + chunkData.get(neighborPosition)[GTPOLLUTION] = neighborPollution; } - }} - int[] tArray = GT_Proxy.chunkData.get(tPos); - tArray[1] = tPollution; - GT_Proxy.chunkData.remove(tPos); - GT_Proxy.chunkData.put(tPos, tArray); + } + + //Create Pollution effects -// Smog filter TODO - if(tPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit){ - AxisAlignedBB chunk = AxisAlignedBB.getBoundingBox(tPos.chunkPosX<<4, 0, tPos.chunkPosZ<<4, (tPos.chunkPosX<<4)+16, 256, (tPos.chunkPosZ<<4)+16); - List tEntitys = aWorld.getEntitiesWithinAABB(EntityLivingBase.class, chunk); - for(EntityLivingBase tEnt : tEntitys){ - if(!GT_Utility.isWearingFullGasHazmat(tEnt) && tRan.nextInt(tPollution/2000) > 40){ - int ran = tRan.nextInt(3); - if(ran==0)tEnt.addPotionEffect(new PotionEffect(Potion.weakness.id, Math.min(tPollution/2500,1000), tPollution/400000)); - if(ran==1)tEnt.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, Math.min(tPollution/2500,1000), tPollution/400000)); - if(ran==2)tEnt.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, Math.min(tPollution/2500,1000), tPollution/400000)); + //Smog filter TODO + if(tPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit) { + AxisAlignedBB chunk = AxisAlignedBB.getBoundingBox(actualPos.chunkXPos << 4, 0, actualPos.chunkZPos << 4, (actualPos.chunkXPos << 4) + 16, 256, (actualPos.chunkZPos << 4) + 16); + List tEntitys = aWorld.getEntitiesWithinAABB(EntityLivingBase.class, chunk); + for (EntityLivingBase tEnt : tEntitys) { + if (!GT_Utility.isWearingFullGasHazmat(tEnt)) { + switch (tRan.nextInt(3)) { + default: + tEnt.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, Math.min(tPollution / 1000, 1000), tPollution / 400000)); + case 1: + tEnt.addPotionEffect(new PotionEffect(Potion.weakness.id, Math.min(tPollution / 1000, 1000), tPollution / 400000)); + case 2: + tEnt.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, Math.min(tPollution / 1000, 1000), tPollution / 400000)); + } } -} -// Poison effects - if(tPollution > GT_Mod.gregtechproxy.mPollutionPoisonLimit){ - for(EntityLivingBase tEnt : tEntitys){ - if(!GT_Utility.isWearingFullGasHazmat(tEnt) && tRan.nextInt(tPollution/2000) > 20){ - int ran = tRan.nextInt(3); - if(ran==0)tEnt.addPotionEffect(new PotionEffect(Potion.poison.id, Math.min(tPollution/2500,1000), tPollution/500000)); - if(ran==1)tEnt.addPotionEffect(new PotionEffect(Potion.confusion.id, Math.min(tPollution/2500,1000), 1)); - if(ran==2)tEnt.addPotionEffect(new PotionEffect(Potion.blindness.id, Math.min(tPollution/2500,1000), 1)); -} - } -// killing plants - if(tPollution > GT_Mod.gregtechproxy.mPollutionVegetationLimit){ - int f = 20; - for(;f<(tPollution/25000);f++){ - int x =tPos.chunkPosX<<4+(tRan.nextInt(16));; - int y =60 +(-f+tRan.nextInt(f*2+1)); - int z =tPos.chunkPosZ<<4+(tRan.nextInt(16)); - damageBlock(x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); - }}}} + } + + + // Poison effects + if (tPollution > GT_Mod.gregtechproxy.mPollutionPoisonLimit) { + //AxisAlignedBB chunk = AxisAlignedBB.getBoundingBox(tPos.chunkPosX*16, 0, tPos.chunkPosZ*16, tPos.chunkPosX*16+16, 256, tPos.chunkPosZ*16+16); + //List tEntitys = aWorld.getEntitiesWithinAABB(EntityLiving.class, chunk); + for (EntityLivingBase tEnt : tEntitys) { + if (!GT_Utility.isWearingFullGasHazmat(tEnt)) { + switch (tRan.nextInt(4)) { + default: + tEnt.addPotionEffect(new PotionEffect(Potion.hunger.id, tPollution / 500000)); + case 1: + tEnt.addPotionEffect(new PotionEffect(Potion.confusion.id, Math.min(tPollution / 2000, 1000), 1)); + case 2: + tEnt.addPotionEffect(new PotionEffect(Potion.poison.id, Math.min(tPollution / 4000, 1000), tPollution / 500000)); + case 3: + tEnt.addPotionEffect(new PotionEffect(Potion.blindness.id, Math.min(tPollution / 2000, 1000), 1)); + } + } + } + + + // killing plants + if (tPollution > GT_Mod.gregtechproxy.mPollutionVegetationLimit) { + int f = 20; + for (; f < (tPollution / 25000); f++) { + int x = (actualPos.chunkXPos << 4) + tRan.nextInt(16); + int y = 60 + (-f + tRan.nextInt(f * 2 + 1)); + int z = (actualPos.chunkZPos << 4) + tRan.nextInt(16); + damageBlock(aWorld, x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); + } + } + } } } - }} + //Write new pollution to Hashmap !!! + chunkData.get(actualPos)[GTPOLLUTION] = tPollution; + } } - public static void damageBlock(int x, int y, int z, boolean sourRain){ - World world = DimensionManager.getWorld(0); + private static void damageBlock(World world, int x, int y, int z, boolean sourRain){ if (world.isRemote) return; Block tBlock = world.getBlock(x, y, z); int tMeta = world.getBlockMetadata(x, y, z); @@ -187,24 +230,31 @@ public class GT_Pollution { } } - //Add aWorld to Save Pollution - public static void addPollution(World aWorld, ChunkPosition aPos, int aPollution){ + public static void addPollution(IGregTechTileEntity te, int aPollution){ + System.out.println(te.getWorld().provider.dimensionId+" "+te.getXCoord()+" "+te.getZCoord()); + addPollution(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()), aPollution); + } + + public static void addPollution(Chunk ch, int aPollution){ if(!GT_Mod.gregtechproxy.mPollution)return; - try{ - ChunkPosition tPos = new ChunkPosition(GT_Utility.getScaleCoordinates(aPos.chunkPosX,16), aWorld.provider.dimensionId, GT_Utility.getScaleCoordinates(aPos.chunkPosZ,16)); // OLD in coordinate -1 -1 chunk 0 0 -// System.out.println("add pollution dim: "+aWorld.provider.dimensionId+" x: "+ tPos.chunkPosX +" z: " + tPos.chunkPosZ +" poll: "+aPollution); - int[] tData = new int[3]; - if(GT_Proxy.chunkData.containsKey(tPos)){ - tData = GT_Proxy.chunkData.get(tPos); - if(tData.length>1){ - tData[1] += aPollution; - } - }else{ - tData[1] += aPollution; - GT_Proxy.chunkData.put(tPos, tData); - } - }catch(Exception e){ - + HashMap dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId); + if(dataMap==null){ + dataMap=new HashMap<>(1024); + dimensionWiseChunkData.put(ch.worldObj.provider.dimensionId,dataMap); } + if(dataMap.get(ch.getChunkCoordIntPair())==null) + dataMap.put(ch.getChunkCoordIntPair(),getDefaultChunkDataOnCreation()); + dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION]+=aPollution; + } + + public static int getPollution(IGregTechTileEntity te){ + return getPollution(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord())); + } + + public static int getPollution(Chunk ch){ + if(!GT_Mod.gregtechproxy.mPollution)return 0; + HashMap dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId); + if(dataMap==null || dataMap.get(ch.getChunkCoordIntPair())==null) return 0; + return dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION]; } -} +} \ No newline at end of file -- cgit From 28694dac932c64c331011b6aa24a0d1c500d9473 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 9 May 2017 06:39:35 +0200 Subject: Fix that so pollution is not negative. --- src/main/java/gregtech/common/GT_Pollution.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Pollution.java') diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 4ab0c97d79..23dd3ad028 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -242,9 +242,13 @@ public class GT_Pollution { dataMap=new HashMap<>(1024); dimensionWiseChunkData.put(ch.worldObj.provider.dimensionId,dataMap); } - if(dataMap.get(ch.getChunkCoordIntPair())==null) - dataMap.put(ch.getChunkCoordIntPair(),getDefaultChunkDataOnCreation()); - dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION]+=aPollution; + int[] dataArr=dataMap.get(ch.getChunkCoordIntPair()); + if(dataArr==null){ + dataArr=getDefaultChunkDataOnCreation(); + dataMap.put(ch.getChunkCoordIntPair(),dataArr); + } + dataArr[GTPOLLUTION]+=aPollution; + if(dataArr[GTPOLLUTION]<0)dataArr[GTPOLLUTION]=0; } public static int getPollution(IGregTechTileEntity te){ -- cgit From 8b1e6d55bef436f82bc4ac8bc21244db68eb5452 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 9 May 2017 08:02:52 +0200 Subject: 7bd71fe --- src/main/java/gregtech/common/GT_Pollution.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common/GT_Pollution.java') diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 23dd3ad028..95228ee9f6 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -261,4 +261,10 @@ public class GT_Pollution { if(dataMap==null || dataMap.get(ch.getChunkCoordIntPair())==null) return 0; return dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION]; } -} \ No newline at end of file + + //Add compatibility with old code + @Deprecated + public static void addPollution(World aWorld, ChunkPosition aPos, int aPollution){ + addPollution(aWorld.getChunkFromChunkCoords(aPos.chunkPosX,aPos.chunkPosZ),aPollution); + } +} -- cgit From 0a928887eda8a9a3961d9b409e8ed7b2b1336995 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 9 May 2017 08:08:47 +0200 Subject: Cleanup and some commentary --- src/main/java/gregtech/common/GT_Pollution.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Pollution.java') diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 95228ee9f6..78040bdb36 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -231,7 +231,6 @@ public class GT_Pollution { } public static void addPollution(IGregTechTileEntity te, int aPollution){ - System.out.println(te.getWorld().provider.dimensionId+" "+te.getXCoord()+" "+te.getZCoord()); addPollution(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()), aPollution); } @@ -263,8 +262,10 @@ public class GT_Pollution { } //Add compatibility with old code - @Deprecated + @Deprecated /*Don't use it... too weird way of passing position*/ public static void addPollution(World aWorld, ChunkPosition aPos, int aPollution){ - addPollution(aWorld.getChunkFromChunkCoords(aPos.chunkPosX,aPos.chunkPosZ),aPollution); + //The abuse of ChunkPosition to store block position and dim... + //is just bad expacially when that is both used to store ChunkPos and BlockPos depeending on context + addPollution(aWorld.getChunkFromBlockCoords(aPos.chunkPosX,aPos.chunkPosZ),aPollution); } } -- cgit From 9a3fa2e42c2f6dcc6c6d0983f60a02591652c4ea Mon Sep 17 00:00:00 2001 From: Blood-Asp Date: Sat, 3 Jun 2017 13:42:41 +0200 Subject: Fix Pollution bug --- src/main/java/gregtech/common/GT_Pollution.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common/GT_Pollution.java') diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 78040bdb36..175ea6ac85 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -110,7 +110,7 @@ public class GT_Pollution { tNeighbors[2]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos+1)); tNeighbors[3]=(new ChunkCoordIntPair(actualPos.chunkXPos,actualPos.chunkZPos-1)); for(ChunkCoordIntPair neighborPosition : tNeighbors){ - if(!chunkData.containsKey(neighborPosition)) chunkData.put(actualPos,getDefaultChunkDataOnCreation()); + if(!chunkData.containsKey(neighborPosition)) chunkData.put(neighborPosition,getDefaultChunkDataOnCreation()); int neighborPollution = chunkData.get(neighborPosition)[GTPOLLUTION]; if(neighborPollution*6 < tPollution*5){//METHEMATICS... -- cgit From 911a80752930d6207fc0b850f3ccf8b3da05b0a5 Mon Sep 17 00:00:00 2001 From: Blood-Asp Date: Wed, 14 Jun 2017 23:51:39 +0200 Subject: pollution smog --- .../java/gregtech/api/net/GT_Packet_Pollution.java | 43 ++++++++++++++++++++++ src/main/java/gregtech/common/GT_Client.java | 42 +++++++++++++++++++++ src/main/java/gregtech/common/GT_Network.java | 8 +++- src/main/java/gregtech/common/GT_Pollution.java | 8 ++++ src/main/java/gregtech/common/GT_Proxy.java | 7 ++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/main/java/gregtech/api/net/GT_Packet_Pollution.java (limited to 'src/main/java/gregtech/common/GT_Pollution.java') 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 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 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); + } } } -- cgit