Rework oil gen

This commit is contained in:
Technus 2016-11-01 19:14:28 +01:00
parent 61dcb99966
commit f52851fe6e
3 changed files with 37 additions and 64 deletions

View file

@ -1527,19 +1527,18 @@ public class GT_Utility {
public static FluidStack undergroundOil(World aWorld, int aX, int aZ,boolean save,int sub) { public static FluidStack undergroundOil(World aWorld, int aX, int aZ,boolean save,int sub) {
ChunkPosition tPos = new ChunkPosition(aX, 1, aZ); ChunkPosition tPos = new ChunkPosition(aX, 1, aZ);
int[] tInts = {0,0}; int[] tInts = {0,0,0};
if(GT_Proxy.chunkData.containsKey(tPos)){ if(GT_Proxy.chunkData.containsKey(tPos)){
tInts = GT_Proxy.chunkData.get(tPos); tInts = GT_Proxy.chunkData.get(tPos);
if(tInts.length>0){ if(tInts.length>0){
int type=tInts[0]>>28; int type=tInts[0]>>28;
int amnt=tInts[0]-(type<<28)-sub; int amnt=tInts[0]-(type<<28)-sub;
if(type==0){//update old thing //IGNORES SAVE - chunk must be updated if(type==0){//update old thing //IGNORES SAVE - chunk must be updated
//here i don't care about type it will be added GT_Proxy.chunkData.remove(tPos);
if(amnt<=0) tInts[0] = 0; return setUndergroundOil(aWorld,aX,aZ,tPos,tInts);
else tInts[0] = amnt;
return setUndergroundOilFromOld(aWorld,aX,aZ,tPos,tInts);//compatibility thing
} }
if(save){//obvious? if(save){//obvious?
//tInts[2]|=0x01;
if(amnt<=0) tInts[0] = type << 28; if(amnt<=0) tInts[0] = type << 28;
else tInts[0] = (type << 28) + amnt; else tInts[0] = (type << 28) + amnt;
GT_Proxy.chunkData.remove(tPos); GT_Proxy.chunkData.remove(tPos);
@ -1567,9 +1566,9 @@ public class GT_Utility {
} }
private static FluidStack setUndergroundOil(World aWorld, int aX, int aZ,ChunkPosition tPos,int[] tInts) { private static FluidStack setUndergroundOil(World aWorld, int aX, int aZ,ChunkPosition tPos,int[] tInts) {
XSTR tRandom = new XSTR((aWorld.getSeed() + (aX / 6) + (7 * (aZ / 6)))); XSTR tRandom = new XSTR(aWorld.getSeed() ^ ((long)(aX / 6) + (long)(7000 * (aZ / 6))));
int type=tRandom.nextInt(5);//type slowly changes int type=tRandom.nextInt(5);//type slowly changes
int amnt = (int) ((float)Math.pow(2+tRandom.nextInt(48)+(new XSTR()).nextFloat(), 5)*0.7); int amnt = (int)(Math.ceil(Math.pow(2D+(double)(tRandom.nextInt(48))+(new XSTR()).nextDouble(), 5D)*0.7D));
//roughly uses 28 bits //roughly uses 28 bits
FluidStack tFluidStack; FluidStack tFluidStack;
switch (type) {//0 is old system switch (type) {//0 is old system
@ -1591,35 +1590,7 @@ public class GT_Utility {
} }
tInts[0]=(type<<28)+amnt;//here since the switch changes type tInts[0]=(type<<28)+amnt;//here since the switch changes type
GT_Proxy.chunkData.put(tPos, tInts); //tInts[2]|=0x01;
return tFluidStack;
}
private static FluidStack setUndergroundOilFromOld(World aWorld, int aX, int aZ,ChunkPosition tPos,int[] tInts) {
//max was 51^5/100 roughly uses 22 bits
FluidStack tFluidStack;
int type=new Random((aWorld.getSeed() + (aX / 6) + (7 * (aZ / 6)))).nextInt(4);//Get old type of fluid
//this gives value from 0 to 3 :D
switch (type) {
case 0:
type=5;//important, 0 is invalid !
tFluidStack = new FluidStack(Materials.NatruralGas.mGas,tInts[0]);
break;
case 1:
tFluidStack = new FluidStack(Materials.OilLight.mFluid,tInts[0]);
break;
case 2:
tFluidStack = new FluidStack(Materials.OilMedium.mFluid,tInts[0]);
break;
case 3:
tFluidStack = new FluidStack(Materials.OilHeavy.mFluid,tInts[0]);
break;
default://unreachable but still here XD
type=4;
tFluidStack = new FluidStack(Materials.Oil.mFluid,tInts[0]);
}
tInts[0]+=type<<28;
GT_Proxy.chunkData.remove(tPos);
GT_Proxy.chunkData.put(tPos, tInts); GT_Proxy.chunkData.put(tPos, tInts);
return tFluidStack; return tFluidStack;
} }

View file

@ -100,6 +100,7 @@ public class GT_Pollution {
int[] tArray = GT_Proxy.chunkData.get(tPos); int[] tArray = GT_Proxy.chunkData.get(tPos);
tArray[1] = tPollution; tArray[1] = tPollution;
GT_Proxy.chunkData.remove(tPos); GT_Proxy.chunkData.remove(tPos);
//tArray[2]|=0x01;
GT_Proxy.chunkData.put(tPos, tArray); GT_Proxy.chunkData.put(tPos, tArray);
//Create Pollution effects //Create Pollution effects
// Smog filter TODO // Smog filter TODO
@ -201,7 +202,7 @@ public class GT_Pollution {
try{ try{
ChunkPosition tPos = new ChunkPosition(aPos.chunkPosX>>4, 1, aPos.chunkPosZ>>4); ChunkPosition tPos = new ChunkPosition(aPos.chunkPosX>>4, 1, aPos.chunkPosZ>>4);
// System.out.println("add pollution x: "+ tPos.chunkPosX +" z: " + tPos.chunkPosZ +" poll: "+aPollution); // System.out.println("add pollution x: "+ tPos.chunkPosX +" z: " + tPos.chunkPosZ +" poll: "+aPollution);
int[] tData = new int[2]; int[] tData = new int[3];
if(GT_Proxy.chunkData.containsKey(tPos)){ if(GT_Proxy.chunkData.containsKey(tPos)){
tData = GT_Proxy.chunkData.get(tPos); tData = GT_Proxy.chunkData.get(tPos);
if(tData.length>1){ if(tData.length>1){
@ -209,6 +210,7 @@ public class GT_Pollution {
} }
}else{ }else{
tData[1]=GT_Utility.safeInt((long)tData[1]+aPollution);//tData[1] += aPollution; tData[1]=GT_Utility.safeInt((long)tData[1]+aPollution);//tData[1] += aPollution;
//tData[2]|=0x01;
GT_Proxy.chunkData.put(tPos, tData); GT_Proxy.chunkData.put(tPos, tData);
} }
}catch(Exception e){} }catch(Exception e){}

View file

@ -1872,14 +1872,18 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<ChunkPosition, int[]>(5000); public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<ChunkPosition, int[]>(5000);
private static final byte oilVer=(byte)0x01;
@SubscribeEvent @SubscribeEvent
public void handleChunkSaveEvent(ChunkDataEvent.Save event) public void handleChunkSaveEvent(ChunkDataEvent.Save event)
{ {//by the laws of logic cannot save an never-loaded chunk data... and if there is no data to save GREAT :D
ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition); ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition);
if(chunkData.containsKey(tPos)){ if(chunkData.containsKey(tPos)){
int[] tInts = chunkData.get(tPos); int[] tInts = chunkData.get(tPos);
if(tInts.length>0){event.getData().setInteger("GTOIL", tInts[0]);} if(tInts.length>0){event.getData().setInteger("GTOIL", tInts[0]);}
if(tInts.length>1){event.getData().setInteger("GTPOLLUTION", tInts[1]);}} if(tInts.length>1){event.getData().setInteger("GTPOLLUTION", tInts[1]);}
}
event.getData().setByte("GTOILVER",oilVer);
} }
@SubscribeEvent @SubscribeEvent
@ -1887,39 +1891,35 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
{ {
int tOil = 0; int tOil = 0;
int tPollution = 0; int tPollution = 0;
//place
ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition); ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition);
int[] tData = new int[2]; boolean notLoaded=true;//was it loaded?
if(chunkData.containsKey(tPos)){
tData = chunkData.get(tPos); int[] tData = new int[]{0,0,0};//initialize with defaults
if(chunkData.containsKey(tPos)){//i have the data loaded...
tData = chunkData.get(tPos);//if the array had 3 ints...
if(tData[2]>0x01)notLoaded=false;
chunkData.remove(tPos); chunkData.remove(tPos);
} }//if doesn't contain stuff the array will still be 2 long
if(event.getData().hasKey("GTOIL")){ if(event.getData().hasKey("GTPOLLUTION") && notLoaded){
if(tData.length>2){ tPollution=GT_Utility.safeInt((long)tData[1]+(long)event.getData().getInteger("GTPOLLUTION"));
tOil = tData[0];
}else{
tOil += event.getData().getInteger("GTOIL");
}
}else{ }else{
if(tData[0]!=0){ tPollution=tData[1];
tOil = tData[0];
}
} }
if(event.getData().hasKey("GTPOLLUTION")){ if(!event.getData().hasKey("GTOILVER") || event.getData().getByte("GTOILVER")!=oilVer) {
if(tData.length>2){ chunkData.put(tPos, new int[]{ 0,tPollution,0x02});//anything without type is ok, 0 doesn't have fluid type
tPollution = tData[1]; return;
}else{ }
tPollution += event.getData().getInteger("GTPOLLUTION");
} if(event.getData().hasKey("GTOIL") && notLoaded){
tOil=event.getData().getInteger("GTOIL");
}else{ }else{
if(tData[1]!=0){ tOil=tData[0];
tPollution = tData[1];
}
} }
chunkData.put(tPos, new int[]{ tOil,tPollution,-1}); chunkData.put(tPos, new int[]{ tOil,tPollution,0x02});
} }
public static class OreDictEventContainer { public static class OreDictEventContainer {