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) {
ChunkPosition tPos = new ChunkPosition(aX, 1, aZ);
int[] tInts = {0,0};
int[] tInts = {0,0,0};
if(GT_Proxy.chunkData.containsKey(tPos)){
tInts = GT_Proxy.chunkData.get(tPos);
if(tInts.length>0){
int type=tInts[0]>>28;
int amnt=tInts[0]-(type<<28)-sub;
if(type==0){//update old thing //IGNORES SAVE - chunk must be updated
//here i don't care about type it will be added
if(amnt<=0) tInts[0] = 0;
else tInts[0] = amnt;
return setUndergroundOilFromOld(aWorld,aX,aZ,tPos,tInts);//compatibility thing
GT_Proxy.chunkData.remove(tPos);
return setUndergroundOil(aWorld,aX,aZ,tPos,tInts);
}
if(save){//obvious?
//tInts[2]|=0x01;
if(amnt<=0) tInts[0] = type << 28;
else tInts[0] = (type << 28) + amnt;
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) {
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 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
FluidStack tFluidStack;
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
GT_Proxy.chunkData.put(tPos, tInts);
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);
//tInts[2]|=0x01;
GT_Proxy.chunkData.put(tPos, tInts);
return tFluidStack;
}

View file

@ -100,6 +100,7 @@ public class GT_Pollution {
int[] tArray = GT_Proxy.chunkData.get(tPos);
tArray[1] = tPollution;
GT_Proxy.chunkData.remove(tPos);
//tArray[2]|=0x01;
GT_Proxy.chunkData.put(tPos, tArray);
//Create Pollution effects
// Smog filter TODO
@ -201,7 +202,7 @@ public class GT_Pollution {
try{
ChunkPosition tPos = new ChunkPosition(aPos.chunkPosX>>4, 1, aPos.chunkPosZ>>4);
// 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)){
tData = GT_Proxy.chunkData.get(tPos);
if(tData.length>1){
@ -209,6 +210,7 @@ public class GT_Pollution {
}
}else{
tData[1]=GT_Utility.safeInt((long)tData[1]+aPollution);//tData[1] += aPollution;
//tData[2]|=0x01;
GT_Proxy.chunkData.put(tPos, tData);
}
}catch(Exception e){}

View file

@ -1397,7 +1397,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
@SubscribeEvent
public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) {
if(aEvent.world.provider.dimensionId == 0)
mTicksUntilNextCraftSound--;
mTicksUntilNextCraftSound--;
if (aEvent.side.isServer()) {
if (this.mUniverse == null) {
this.mUniverse = aEvent.world;
@ -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);
private static final byte oilVer=(byte)0x01;
@SubscribeEvent
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);
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>1){event.getData().setInteger("GTPOLLUTION", tInts[1]);}
}
event.getData().setByte("GTOILVER",oilVer);
}
@SubscribeEvent
@ -1887,39 +1891,35 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
{
int tOil = 0;
int tPollution = 0;
//place
ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition);
int[] tData = new int[2];
if(chunkData.containsKey(tPos)){
tData = chunkData.get(tPos);
boolean notLoaded=true;//was it loaded?
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);
}
}//if doesn't contain stuff the array will still be 2 long
if(event.getData().hasKey("GTOIL")){
if(tData.length>2){
tOil = tData[0];
}else{
tOil += event.getData().getInteger("GTOIL");
}
if(event.getData().hasKey("GTPOLLUTION") && notLoaded){
tPollution=GT_Utility.safeInt((long)tData[1]+(long)event.getData().getInteger("GTPOLLUTION"));
}else{
if(tData[0]!=0){
tOil = tData[0];
}
tPollution=tData[1];
}
if(event.getData().hasKey("GTPOLLUTION")){
if(tData.length>2){
tPollution = tData[1];
}else{
tPollution += event.getData().getInteger("GTPOLLUTION");
}
if(!event.getData().hasKey("GTOILVER") || event.getData().getByte("GTOILVER")!=oilVer) {
chunkData.put(tPos, new int[]{ 0,tPollution,0x02});//anything without type is ok, 0 doesn't have fluid type
return;
}
if(event.getData().hasKey("GTOIL") && notLoaded){
tOil=event.getData().getInteger("GTOIL");
}else{
if(tData[1]!=0){
tPollution = tData[1];
}
tOil=tData[0];
}
chunkData.put(tPos, new int[]{ tOil,tPollution,-1});
chunkData.put(tPos, new int[]{ tOil,tPollution,0x02});
}
public static class OreDictEventContainer {