aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
authorTechlone <techlone.mc@gmail.com>2017-06-04 21:30:51 +0500
committerTechlone <techlone.mc@gmail.com>2017-06-04 21:30:51 +0500
commitdbd2f5800886a36dbe4528aabfb2b30f1e7b0908 (patch)
treebb297a5498fe57f75aedf33e4f3f77f8bb89a202 /src/main/java/gregtech/common
parent4f6bdedf963842c74bf1cf59f77ead8ad66b48bc (diff)
parent30de32fb07bdc82ec7dc79fd698ba0a1ab6b06f6 (diff)
downloadGT5-Unofficial-dbd2f5800886a36dbe4528aabfb2b30f1e7b0908.tar.gz
GT5-Unofficial-dbd2f5800886a36dbe4528aabfb2b30f1e7b0908.tar.bz2
GT5-Unofficial-dbd2f5800886a36dbe4528aabfb2b30f1e7b0908.zip
Merge branch 'unstable' of https://github.com/Blood-Asp/GT5-Unofficial into unstable
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/GT_Pollution.java257
-rw-r--r--src/main/java/gregtech/common/GT_Proxy.java124
-rw-r--r--src/main/java/gregtech/common/GT_UndergroundOil.java100
-rw-r--r--src/main/java/gregtech/common/blocks/GT_Material_Casings.java2
-rw-r--r--src/main/java/gregtech/common/blocks/GT_Material_Reinforced.java2
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_PlayerDetector.java4
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_RedstoneReceiverInternal.java8
-rw-r--r--src/main/java/gregtech/common/items/GT_MetaGenerated_Item_03.java6
-rw-r--r--src/main/java/gregtech/common/items/ItemComb.java16
-rw-r--r--src/main/java/gregtech/common/items/armor/ModularArmor_Item.java12
-rw-r--r--src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Steel.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/generators/GT_MetaTileEntity_LightningRod.java13
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java21
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java3
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_SeismicProspector.java3
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java3
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BronzeBlastFurnace.java21
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Charcoal_Pit.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java11
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrill.java5
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java32
26 files changed, 466 insertions, 191 deletions
diff --git a/src/main/java/gregtech/common/GT_Pollution.java b/src/main/java/gregtech/common/GT_Pollution.java
index a950e8a2f2..175ea6ac85 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<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;
- static List<ChunkPosition> 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<ChunkPosition>(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<ChunkPosition> 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(tNPol<tPollution && tNPol*12 < tPollution*10){
- int tDiff = tPollution - tNPol;
- tDiff = tDiff/10;
- tNPol += tDiff;
- tPollution -= tDiff;
- GT_Proxy.chunkData.get(tNPos)[1] = tNPol;
- }
- }else{
- GT_Utility.getUndergroundOil(aWorld,tNPos.chunkPosX<<4,tNPos.chunkPosZ<<4);
+
+ 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());
+ //get pollution
+ int tPollution = chunkData.get(actualPos)[GTPOLLUTION];
+ //remove some
+ 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
+
+ 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...
+ 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<EntityLivingBase> 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<EntityLivingBase> 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<EntityLiving> 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,42 @@ 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){
+ 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);
+ HashMap<ChunkCoordIntPair,int[]> dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId);
+ if(dataMap==null){
+ dataMap=new HashMap<>(1024);
+ dimensionWiseChunkData.put(ch.worldObj.provider.dimensionId,dataMap);
}
- }catch(Exception e){
-
+ 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){
+ return getPollution(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()));
+ }
+
+ public static int getPollution(Chunk ch){
+ if(!GT_Mod.gregtechproxy.mPollution)return 0;
+ HashMap<ChunkCoordIntPair,int[]> dataMap=dimensionWiseChunkData.get(ch.worldObj.provider.dimensionId);
+ if(dataMap==null || dataMap.get(ch.getChunkCoordIntPair())==null) return 0;
+ return dataMap.get(ch.getChunkCoordIntPair())[GTPOLLUTION];
+ }
+
+ //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){
+ //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);
}
}
diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java
index 91033a1f34..b79e6691d3 100644
--- a/src/main/java/gregtech/common/GT_Proxy.java
+++ b/src/main/java/gregtech/common/GT_Proxy.java
@@ -6,6 +6,8 @@ import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.ProgressManager;
import cpw.mods.fml.common.eventhandler.Event.Result;
+import cpw.mods.fml.common.eventhandler.EventBus;
+import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
@@ -55,10 +57,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
+import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraft.world.gen.feature.WorldGenMinable;
+import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
@@ -69,6 +73,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.terraingen.OreGenEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ChunkDataEvent;
+import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
@@ -196,6 +201,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
public boolean mLowGravProcessing = false;
public boolean mAprilFool = false;
public boolean mCropNeedBlock = true;
+ public boolean mAMHInteraction = true;
public GT_Proxy() {
GameRegistry.registerFuelHandler(this);
@@ -580,6 +586,9 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
}
}
} catch (Throwable e) {e.printStackTrace(GT_Log.err);}
+
+ dimensionWiseChunkData.clear();//!!! IMPORTANT for map switching...
+ dimensionWisePollution.clear();//!!! IMPORTANT for map switching...
}
public void onServerStarted() {
@@ -1245,8 +1254,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
}
}
}
- if(aEvent.world.provider.dimensionId==0)
- GT_Pollution.onWorldTick(aEvent.world, (int) (aEvent.world.getTotalWorldTime() % 1200));
+
+ GT_Pollution.onWorldTick(aEvent);
}
}
@@ -1699,48 +1708,91 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
ProgressManager.pop(progressBar);
}
- public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<ChunkPosition, int[]>(5000);
+ public static final HashMap<Integer,HashMap<ChunkCoordIntPair,int []>> dimensionWiseChunkData = new HashMap<>(16);//stores chunk data that is loaded/saved
+ public static final HashMap<Integer,GT_Pollution> dimensionWisePollution = new HashMap<>(16);//stores GT_Polluttors objects
+ public static final byte GTOIL=3,GTOILFLUID=2,GTPOLLUTION=1,GTMETADATA=0,NOT_LOADED=0,LOADED=1;//consts
+ //@Deprecated
+ //public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<>(0);
+
+ private static final byte oilVer=(byte)20;//non zero plz
+
+ //TO get default's fast
+ public static int[] getDefaultChunkDataOnCreation(){
+ return new int[]{NOT_LOADED,0,-1,-1};
+ }
+ public static int[] getDefaultChunkDataOnLoad(){
+ return new int[]{LOADED,0,-1,-1};
+ }
@SubscribeEvent
- public void handleChunkSaveEvent(ChunkDataEvent.Save event)
- {
- ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,event.getChunk().worldObj.provider.dimensionId,event.getChunk().zPosition);
- if(chunkData.containsKey(tPos)){
- int[] tInts = chunkData.get(tPos);
- if(tInts.length>0){event.getData().setInteger("GTOIL", tInts[0]);}
- if(tInts.length>1){event.getData().setInteger("GTPOLLUTION", tInts[1]);}
- if(tInts.length>2){event.getData().setInteger("GTOILFLUID", tInts[2]);}
- }
+ public void handleChunkSaveEvent(ChunkDataEvent.Save event) {//ALWAYS SAVE FROM THE HASH MAP DATA
+ HashMap<ChunkCoordIntPair,int []> chunkData=dimensionWiseChunkData.get(event.world.provider.dimensionId);
+ if(chunkData==null) return;//no dim info stored
+
+ int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair());
+ if(tInts==null) return;//no chunk data stored
+ //assuming len of this array 4
+ if(tInts[3]>=0)event.getData().setInteger("GTOIL", tInts[GTOIL]);
+ else event.getData().removeTag("GTOIL");
+ if(tInts[2]>=0)event.getData().setInteger("GTOILFLUID", tInts[GTOILFLUID]);
+ else event.getData().removeTag("GTOILFLUID");
+ if(tInts[1]>0)event.getData().setInteger("GTPOLLUTION", tInts[GTPOLLUTION]);
+ else event.getData().removeTag("GTPOLLUTION");
+ event.getData().setByte("GTOILVER", oilVer);//version mark
}
@SubscribeEvent
- public void handleChunkLoadEvent(ChunkDataEvent.Load event)
- {
- int tOil = 0;
- int tOilFluid = 0;
- int tPollution = 0;
-
- ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,event.getChunk().worldObj.provider.dimensionId,event.getChunk().zPosition);
- int[] tData = new int[0];
- if(chunkData.containsKey(tPos)){
- tData = chunkData.get(tPos);
- chunkData.remove(tPos);
- if(tData.length>0)
- tOil = tData[0];
- if(tData.length>1)
- tPollution = tData[1];
- if(tData.length>2)
- tOilFluid = tData[2];
+ public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
+ final int worldID=event.world.provider.dimensionId;
+ HashMap<ChunkCoordIntPair, int[]> chunkData = dimensionWiseChunkData.get(worldID);
+ if (chunkData == null){
+ chunkData=new HashMap<>(1024);
+ dimensionWiseChunkData.put(worldID, chunkData);
}
+ if (dimensionWisePollution.get(worldID) == null)
+ dimensionWisePollution.put(worldID, new GT_Pollution(event.world));
+
+ int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair());
+ if (tInts == null) {
+ //NOT LOADED and NOT PROCESSED by pollution algorithms
+ //regular load
+ tInts = getDefaultChunkDataOnLoad();
+
+ if (event.getData().getByte("GTOILVER") == oilVer) {
+ if (event.getData().hasKey("GTOIL"))
+ tInts[GTOIL] = event.getData().getInteger("GTOIL");
+ if (event.getData().hasKey("GTOILFLUID"))
+ tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID");
+ }
+
+ tInts[GTPOLLUTION] = event.getData().getInteger("GTPOLLUTION");//Defaults to 0
+
+ //store in HASH MAP if has useful data
+ if (tInts[GTPOLLUTION] > 0 || tInts[GTOIL] >= 0 || tInts[GTOILFLUID] >= 0)
+ chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts);
+ } else if (tInts[GTMETADATA] == NOT_LOADED) {//was NOT loaded from chunk save game data
+ //NOT LOADED but generated
+ //append load
+ if (event.getData().getByte("GTOILVER") == oilVer) {
+ if (tInts[GTOIL] < 0 && event.getData().hasKey("GTOIL"))//if was not yet initialized
+ tInts[GTOIL] = event.getData().getInteger("GTOIL");
+
+ if (tInts[GTOILFLUID] < 0 && event.getData().hasKey("GTOILFLUID"))//if was not yet initialized
+ tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID");
+ } else {
+ tInts[GTOIL] = -1;
+ tInts[GTOILFLUID] = -1;
+ }
- if(tOil==0&&event.getData().hasKey("GTOIL"))
- tOil = event.getData().getInteger("GTOIL");
- if(tPollution==0&&event.getData().hasKey("GTPOLLUTION"))
- tPollution = event.getData().getInteger("GTPOLLUTION");
- if(tOilFluid==0&&event.getData().hasKey("GTOILFLUID"))
- tOilFluid = event.getData().getInteger("GTOILFLUID");
+ tInts[GTPOLLUTION] += event.getData().getInteger("GTPOLLUTION");//Defaults to 0, add stored pollution to data
+ tInts[GTMETADATA] = LOADED;//mark as = loaded
+ //store in HASHMAP
- chunkData.put(tPos, new int[]{tOil,tPollution,tOilFluid});
+ chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts);
+ }//else if(tInts[0]==1){
+ ////Already loaded chunk data
+ ////DO NOTHING - this chunk data was already loaded and stored in hash map
+ //}
}
public static class OreDictEventContainer {
diff --git a/src/main/java/gregtech/common/GT_UndergroundOil.java b/src/main/java/gregtech/common/GT_UndergroundOil.java
new file mode 100644
index 0000000000..a3e0962100
--- /dev/null
+++ b/src/main/java/gregtech/common/GT_UndergroundOil.java
@@ -0,0 +1,100 @@
+package gregtech.common;
+
+import gregtech.GT_Mod;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.objects.GT_UO_Fluid;
+import gregtech.api.objects.XSTR;
+import gregtech.common.GT_Proxy;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.ChunkPosition;
+import net.minecraft.world.World;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+
+import java.util.HashMap;
+
+import static gregtech.api.util.GT_Utility.getScaleCoordinates;
+import static gregtech.common.GT_Proxy.*;
+
+/**
+ * Created by Tec on 29.04.2017.
+ */
+public class GT_UndergroundOil {
+ public static final short DIVIDER=5000;
+
+ public static FluidStack undergroundOil(IGregTechTileEntity te, float drainSpeedCoefficient){
+ return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),drainSpeedCoefficient);
+ }
+
+ //Returns whole content for information purposes -> when drainSpeedCoeff < 0
+ //Else returns extracted fluidStack if amount > 0, or null otherwise
+ public static FluidStack undergroundOil(Chunk chunk, float drainSpeedCoefficient) {
+ if (GT_Mod.gregtechproxy.mUndergroundOil.CheckBlackList(chunk.worldObj.provider.dimensionId)) return null;
+ World aWorld = chunk.worldObj;
+
+ //Read hash map
+ HashMap<ChunkCoordIntPair, int[]> chunkData = dimensionWiseChunkData.get(aWorld.provider.dimensionId);
+ if(chunkData==null){
+ chunkData=new HashMap<>(1024);
+ dimensionWiseChunkData.put(aWorld.provider.dimensionId,chunkData);
+ }
+
+ int[] tInts = chunkData.get(chunk.getChunkCoordIntPair());
+
+ if(tInts==null) tInts=getDefaultChunkDataOnCreation();//init if null
+ else if(tInts[GTOIL]==0){//FAST stop
+ //can return 0 amount stack for info :D
+ return drainSpeedCoefficient>=0 ? null : new FluidStack(FluidRegistry.getFluid(tInts[GTOILFLUID]),0);
+ }
+
+ //GEN IT TO GET OBJECT...
+ XSTR tRandom = new XSTR(aWorld.getSeed() + aWorld.provider.dimensionId * 2 +
+ (chunk.getChunkCoordIntPair().chunkXPos>>3) +
+ 8267 * (chunk.getChunkCoordIntPair().chunkZPos>>3));
+ GT_UO_Fluid uoFluid = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(aWorld.provider.dimensionId).getRandomFluid(tRandom);
+
+ //Fluid stack holder
+ FluidStack fluidInChunk;
+
+ //Set fluidstack from uoFluid
+ if (uoFluid == null || uoFluid.getFluid()==null){
+ tInts[GTOILFLUID]=Integer.MAX_VALUE;//null fluid pointer... kindof
+ tInts[GTOIL]=0;
+ chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map
+ return null;
+ } else {
+ if(tInts[GTOILFLUID]== uoFluid.getFluid().getID()){//if stored fluid matches uoFluid
+ fluidInChunk = new FluidStack(uoFluid.getFluid(),tInts[GTOIL]);
+ }else{
+ fluidInChunk = new FluidStack(uoFluid.getFluid(), uoFluid.getRandomAmount(tRandom));
+ tRandom=new XSTR();
+ fluidInChunk.amount=(int)((float)fluidInChunk.amount*(0.75f+(tRandom.nextFloat()/2f)));//Randomly change amounts by +/- 25%
+ }
+ tInts[GTOIL]=fluidInChunk.amount;
+ tInts[GTOILFLUID]=fluidInChunk.getFluidID();
+ }
+
+ //do stuff on it if needed
+ if(drainSpeedCoefficient>=0){
+ if(fluidInChunk.amount<DIVIDER){
+ fluidInChunk=null;
+ tInts[GTOIL]=0;//so in next access it will stop way above
+ }else{
+ fluidInChunk.amount = (int)(fluidInChunk.amount*(double)drainSpeedCoefficient/DIVIDER);//give appropriate amount
+ tInts[GTOIL]-=uoFluid.DecreasePerOperationAmount;//diminish amount
+ }
+ }else{//just get info
+ if(fluidInChunk.amount<DIVIDER){
+ fluidInChunk.amount=0;//return informative stack
+ tInts[GTOIL]=0;//so in next access it will stop way above
+ }else{
+ fluidInChunk.amount=fluidInChunk.amount/DIVIDER;//give moderate extraction speed
+ }
+ }
+
+ chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map
+ return fluidInChunk;
+ }
+}
diff --git a/src/main/java/gregtech/common/blocks/GT_Material_Casings.java b/src/main/java/gregtech/common/blocks/GT_Material_Casings.java
index 211fbdd65f..94afcbd894 100644
--- a/src/main/java/gregtech/common/blocks/GT_Material_Casings.java
+++ b/src/main/java/gregtech/common/blocks/GT_Material_Casings.java
@@ -13,6 +13,6 @@ public class GT_Material_Casings
}
public boolean isOpaque() {
- return false;
+ return true;
}
}
diff --git a/src/main/java/gregtech/common/blocks/GT_Material_Reinforced.java b/src/main/java/gregtech/common/blocks/GT_Material_Reinforced.java
index a6cf425caa..4aa9ba6931 100644
--- a/src/main/java/gregtech/common/blocks/GT_Material_Reinforced.java
+++ b/