pollution smog

This commit is contained in:
Blood-Asp 2017-06-14 23:51:39 +02:00
parent 6b4b32200d
commit 911a807529
5 changed files with 107 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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*/

View file

@ -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);
}
}
}