diff options
| author | Sphyix <masifede2@gmail.com> | 2021-11-21 12:58:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-21 12:58:56 +0100 |
| commit | abeecd2da02c7d38cb1c5b6e2fd5517c6f8a994b (patch) | |
| tree | 64c5960fc9a0e9c7a4bb368adfb6fa6e9b5aa071 /src/main/java/gregtech/common | |
| parent | 01c243ee9f58c3f64fc883f931ad9a81813f894f (diff) | |
| parent | 81f0b4801dfb0bd2d2a863e7a60f27af0daba463 (diff) | |
| download | GT5-Unofficial-abeecd2da02c7d38cb1c5b6e2fd5517c6f8a994b.tar.gz GT5-Unofficial-abeecd2da02c7d38cb1c5b6e2fd5517c6f8a994b.tar.bz2 GT5-Unofficial-abeecd2da02c7d38cb1c5b6e2fd5517c6f8a994b.zip | |
Merge branch 'GTNewHorizons:experimental' into experimental
Diffstat (limited to 'src/main/java/gregtech/common')
69 files changed, 2402 insertions, 1036 deletions
diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java index 55efd20920..b9701bb451 100644 --- a/src/main/java/gregtech/common/GT_Client.java +++ b/src/main/java/gregtech/common/GT_Client.java @@ -152,6 +152,7 @@ public class GT_Client extends GT_Proxy private GT_ClientPreference mPreference; private boolean mFirstTick = false; public static final int ROTATION_MARKER_RESOLUTION = 120; + private int mReloadCount; public GT_Client() { mCapeRenderer = new GT_CapeRenderer(mCapeList); @@ -505,6 +506,12 @@ public class GT_Client extends GT_Proxy @SubscribeEvent public void onClientConnectedToServerEvent(FMLNetworkEvent.ClientConnectedToServerEvent aEvent) { mFirstTick = true; + mReloadCount++; + } + + @Override + public int getReloadCount() { + return mReloadCount; } @SubscribeEvent diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java index c9c57676ad..97e511aba4 100644 --- a/src/main/java/gregtech/common/GT_Network.java +++ b/src/main/java/gregtech/common/GT_Network.java @@ -36,7 +36,7 @@ public class GT_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet> public GT_Network() { this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", 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(), new GT_Packet_Pollution(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI(), new MessageUpdateFluidDisplayItem(), new GT_Packet_ClientPreference(), new GT_Packet_WirelessRedstoneCover()}; + 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(), new MessageSetFlaskCapacity(), new GT_Packet_TileEntityCover(), new GT_Packet_TileEntityCoverGUI(), new MessageUpdateFluidDisplayItem(), new GT_Packet_ClientPreference(), new GT_Packet_WirelessRedstoneCover(), new GT_Packet_TileEntityCoverNew()}; } @Override diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java index 7b1ad90d52..865fa83f7e 100644 --- a/src/main/java/gregtech/common/GT_Pollution.java +++ b/src/main/java/gregtech/common/GT_Pollution.java @@ -7,6 +7,7 @@ import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; 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 net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -20,30 +21,34 @@ import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkPosition; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkDataEvent; import net.minecraftforge.event.world.ChunkWatchEvent; +import net.minecraftforge.event.world.WorldEvent; +import javax.annotation.ParametersAreNonnullByDefault; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; -import static gregtech.common.GT_Proxy.GTPOLLUTION; -import static gregtech.common.GT_Proxy.dimensionWiseChunkData; import static gregtech.common.GT_Proxy.dimensionWisePollution; -import static gregtech.common.GT_Proxy.getDefaultChunkDataOnCreation; public class GT_Pollution { + private static final Storage STORAGE = new Storage(); /** * Pollution dispersion until effects start: * Calculation: ((Limit * 0.01) + 2000) * (4 <- spreading rate) - * + * <p> * SMOG(500k) 466.7 pollution/sec * Poison(750k) 633,3 pollution/sec * Dying Plants(1mio) 800 pollution/sec * Sour Rain(1.5mio) 1133.3 pollution/sec - * + * <p> * Pollution producers (pollution/sec) * Bronze Boiler(20) * Lava Boiler(20) @@ -52,7 +57,7 @@ public class GT_Pollution { * Diesel Generator(40/80/160) * Gas Turbine(20/40/80) * Charcoal Pile(100) - * + * <p> * Large Diesel Engine(320) * Electric Blast Furnace(100) * Implosion Compressor(2000) @@ -60,33 +65,27 @@ public class GT_Pollution { * Large Gas Turbine(160) * Multi Smelter(100) * Pyrolyse Oven(400) - * + * <p> * Machine Explosion(100,000) - * + * <p> * Other Random Shit: lots and lots - * + * <p> * Muffler Hatch Pollution reduction: ** inaccurate ** * LV (0%), MV (30%), HV (52%), EV (66%), IV (76%), LuV (84%), ZPM (89%), UV (92%), MAX (95%) */ private List<ChunkCoordIntPair> pollutionList = new ArrayList<>();//chunks left to process - private HashMap<ChunkCoordIntPair,int[]> 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; + private final List<ChunkCoordIntPair> chunkData = new ArrayList<>();//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 world; public static int mPlayerPollution; private static int POLLUTIONPACKET_MINVALUE = 1000; private static GT_PollutionEventHandler EVENT_HANDLER; - 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 GT_Pollution(World world) { + this.world = world; if (EVENT_HANDLER == null) { EVENT_HANDLER = new GT_PollutionEventHandler(); @@ -94,61 +93,61 @@ public class GT_Pollution { } } - public static void onWorldTick(TickEvent.WorldTickEvent aEvent){//called from proxy + public static void onWorldTick(TickEvent.WorldTickEvent aEvent) {//called from proxy //return if pollution disabled - if(!GT_Mod.gregtechproxy.mPollution) return; + 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)); + if (pollutionInstance == null) return; + pollutionInstance.tickPollutionInWorld((int) (aEvent.world.getTotalWorldTime() % cycleLen)); } - private void tickPollutionInWorld(int aTickID){//called from method above + private void tickPollutionInWorld(int aTickID) {//called from method above //gen data set - if(aTickID==0){ - pollutionList = new ArrayList<>(chunkData.keySet()); + if (aTickID == 0) { + // make a snapshot of what to work on + // counterintuitive as it seems, but this is the fastest way java collections framework offers us. + pollutionList = new ArrayList<>(chunkData); //set operations per tick - if(pollutionList.size()>0) operationsPerTick =(pollutionList.size()/cycleLen); - else operationsPerTick=0;//SANity + if (pollutionList.size() > 0) operationsPerTick = (pollutionList.size() / cycleLen); + else operationsPerTick = 0;//SANity } - for(int chunksProcessed=0;chunksProcessed<=operationsPerTick;chunksProcessed++){ - if(pollutionList.size()==0)break;//no more stuff to do - ChunkCoordIntPair actualPos=pollutionList.remove(pollutionList.size()-1);//faster - //add default data if missing - if(!chunkData.containsKey(actualPos)) chunkData.put(actualPos,getDefaultChunkDataOnCreation()); + for (int chunksProcessed = 0; chunksProcessed <= operationsPerTick; chunksProcessed++) { + if (pollutionList.size() == 0) break;//no more stuff to do + ChunkCoordIntPair actualPos = pollutionList.remove(pollutionList.size() - 1);//faster //get pollution - int tPollution = chunkData.get(actualPos)[GTPOLLUTION]; + ChunkData currentData = STORAGE.get(world, actualPos); + int tPollution = currentData.getAmount(); //remove some - tPollution = (int)(0.9945f*tPollution); + tPollution = (int) (0.9945f * tPollution); //tPollution -= 2000;//This does not really matter... - if(tPollution<=0) tPollution = 0;//SANity check - else if(tPollution>400000){//Spread Pollution + if (tPollution <= 0) tPollution = 0;//SANity check + else if (tPollution > 400000) {//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(neighborPosition,getDefaultChunkDataOnCreation()); - - int neighborPollution = chunkData.get(neighborPosition)[GTPOLLUTION]; - if(neighborPollution*6 < tPollution*5){//METHEMATICS... + 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) { + ChunkData neighbor = STORAGE.get(world, neighborPosition); + int neighborPollution = neighbor.getAmount(); + if (neighborPollution * 6 < tPollution * 5) {//MATHEMATICS... int tDiff = tPollution - neighborPollution; - tDiff = tDiff/20; - neighborPollution = GT_Utility.safeInt((long)neighborPollution+tDiff);//tNPol += tDiff; + tDiff = tDiff / 20; + neighborPollution = GT_Utility.safeInt((long) neighborPollution + tDiff);//tNPol += tDiff; tPollution -= tDiff; - chunkData.get(neighborPosition)[GTPOLLUTION] = neighborPollution; + neighbor.setAmount(neighborPollution); } } //Create Pollution effects //Smog filter TODO - if(tPollution > GT_Mod.gregtechproxy.mPollutionSmogLimit) { + 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<EntityLivingBase> tEntitys = aWorld.getEntitiesWithinAABB(EntityLivingBase.class, chunk); + List<EntityLivingBase> tEntitys = world.getEntitiesWithinAABB(EntityLivingBase.class, chunk); for (EntityLivingBase tEnt : tEntitys) { if (tEnt instanceof EntityPlayerMP && ((EntityPlayerMP) tEnt).capabilities.isCreativeMode) continue; @@ -194,131 +193,211 @@ public class GT_Pollution { int x = (actualPos.chunkXPos << 4) + XSTR_INSTANCE.nextInt(16); int y = 60 + (-f + XSTR_INSTANCE.nextInt(f * 2 + 1)); int z = (actualPos.chunkZPos << 4) + XSTR_INSTANCE.nextInt(16); - damageBlock(aWorld, x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); + damageBlock(world, x, y, z, tPollution > GT_Mod.gregtechproxy.mPollutionSourRainLimit); } } } } } //Write new pollution to Hashmap !!! - chunkData.get(actualPos)[GTPOLLUTION] = tPollution; + currentData.setAmount(tPollution); //Send new value to players nearby if (tPollution > POLLUTIONPACKET_MINVALUE) { - NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(aWorld.provider.dimensionId, (actualPos.chunkXPos << 4), 64, (actualPos.chunkZPos << 4), 256); + NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint(world.provider.dimensionId, (actualPos.chunkXPos << 4), 64, (actualPos.chunkZPos << 4), 256); GT_Values.NW.sendToAllAround(new GT_Packet_Pollution(actualPos, tPollution), point); } } } - private static void damageBlock(World world, int x, int y, int z, boolean sourRain){ - if (world.isRemote) return; + 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); - if (tBlock == Blocks.air || tBlock == Blocks.stone || tBlock == Blocks.sand|| tBlock == Blocks.deadbush)return; - - if (tBlock == Blocks.leaves || tBlock == Blocks.leaves2 || tBlock.getMaterial() == Material.leaves) - world.setBlockToAir(x, y, z); - if (tBlock == Blocks.reeds) { - tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); - world.setBlockToAir(x, y, z); - } - if (tBlock == Blocks.tallgrass) - world.setBlock(x, y, z, Blocks.deadbush); - if (tBlock == Blocks.vine) { - tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); - world.setBlockToAir(x, y, z); - } - if (tBlock == Blocks.waterlily || tBlock == Blocks.wheat || tBlock == Blocks.cactus || + if (tBlock == Blocks.air || tBlock == Blocks.stone || tBlock == Blocks.sand || tBlock == Blocks.deadbush) + return; + + if (tBlock == Blocks.leaves || tBlock == Blocks.leaves2 || tBlock.getMaterial() == Material.leaves) + world.setBlockToAir(x, y, z); + if (tBlock == Blocks.reeds) { + tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); + world.setBlockToAir(x, y, z); + } + if (tBlock == Blocks.tallgrass) + world.setBlock(x, y, z, Blocks.deadbush); + if (tBlock == Blocks.vine) { + tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); + world.setBlockToAir(x, y, z); + } + if (tBlock == Blocks.waterlily || tBlock == Blocks.wheat || tBlock == Blocks.cactus || tBlock.getMaterial() == Material.cactus || tBlock == Blocks.melon_block || tBlock == Blocks.melon_stem) { - tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); - world.setBlockToAir(x, y, z); - } - if (tBlock == Blocks.red_flower || tBlock == Blocks.yellow_flower || tBlock == Blocks.carrots || + tBlock.dropBlockAsItem(world, x, y, z, tMeta, 0); + world.setBlockToAir(x, y, z); + } + if (t |
