fix wrong center chunk coordinates

This commit is contained in:
Techlone 2017-06-08 21:27:24 +05:00
parent 8172e2ef60
commit d7debfd34e

View file

@ -12,17 +12,13 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderEnd;
import net.minecraft.world.gen.ChunkProviderHell;
import java.util.HashSet;
import java.util.Random;
public class GT_Worldgenerator
implements IWorldGenerator {
public class GT_Worldgenerator implements IWorldGenerator {
private static int mEndAsteroidProbability = 300;
private static int mGCAsteroidProbability = 50;
private static int mSize = 100;
@ -54,8 +50,7 @@ public class GT_Worldgenerator
new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, tempDimensionId, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName).run();
}
public static class WorldGenContainer
implements Runnable {
public static class WorldGenContainer implements Runnable {
public final Random mRandom;
public int mX;
public int mZ;
@ -77,29 +72,22 @@ public class GT_Worldgenerator
this.mBiome = aBiome;
}
public boolean surroundingChunksLoaded(int aX, int aZ){
if(!mWorld.checkChunksExist(aX-16, 100, aZ-16, aX-16, 100, aZ-16)) return false;
if(!mWorld.checkChunksExist(aX, 100, aZ-16, aX , 100, aZ-16)) return false;
if(!mWorld.checkChunksExist(aX+16, 100, aZ-16, aX+16, 100, aZ-16)) return false;
if(!mWorld.checkChunksExist(aX+16, 100, aZ , aX+16, 100, aZ )) return false;
if(!mWorld.checkChunksExist(aX+16, 100, aZ+16, aX+16, 100, aZ+16)) return false;
if(!mWorld.checkChunksExist(aX , 100, aZ+16, aX , 100, aZ+16)) return false;
if(!mWorld.checkChunksExist(aX-16, 100, aZ+16, aX-16, 100, aZ+16)) return false;
if(!mWorld.checkChunksExist(aX-16, 100, aZ , aX-16, 100, aZ )) return false;
return true;
//returns a coordinate of a center chunk of 3x3 square; the argument belongs to this square
public int getVeinCenterCoordinate(int c) {
c += c < 0 ? 1 : 3;
return c - c % 3 - 2;
}
public boolean surroundingChunksLoaded(int xCenter, int zCenter) {
return mWorld.checkChunksExist(xCenter - 16, 0, zCenter - 16, xCenter + 16, 0, zCenter + 16);
}
public void run() {
int sX = mX;
int sZ = mZ;
if((this.mX / 16 - 1) % 3 == 1) sX = mX - 16;
if((this.mX / 16 - 1) % 3 == 2) sX = mX + 16;
if((this.mZ / 16 - 1) % 3 == 1) sZ = mZ - 16;
if((this.mZ / 16 - 1) % 3 == 2) sZ = mZ + 16;
if (((sX / 16 - 1) % 3 == 0) && ((sZ / 16 - 1) % 3 == 0) && surroundingChunksLoaded(sX,sZ)) {
ChunkCoordIntPair tPair = new ChunkCoordIntPair(sX, sZ);
if(!mGenerated.contains(tPair)){
mGenerated.add(tPair);
int xCenter = getVeinCenterCoordinate(mX >> 4) << 4;
int zCenter = getVeinCenterCoordinate(mZ >> 4) << 4;
ChunkCoordIntPair centerChunk = new ChunkCoordIntPair(xCenter, zCenter);
if (surroundingChunksLoaded(xCenter, zCenter) && !mGenerated.contains(centerChunk)) {
mGenerated.add(centerChunk);
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
boolean temp = true;
int tRandomWeight;
@ -109,7 +97,7 @@ public class GT_Worldgenerator
tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight;
if (tRandomWeight <= 0) {
try {
if (tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, sX, sZ, this.mChunkGenerator, this.mChunkProvider)) {
if (tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, xCenter, zCenter, this.mChunkGenerator, this.mChunkProvider)) {
temp = false;
}
break;
@ -121,10 +109,9 @@ public class GT_Worldgenerator
}
}
int i = 0;
for (int tX = sX - 16; i < 3; tX += 16) {
for (int tX = xCenter - 16; i < 3; tX += 16) {
int j = 0;
for (int tZ = sZ - 16; j < 3; tZ += 16) {
String tBiome = this.mWorld.getBiomeGenForCoords(tX + 8, tZ + 8).biomeName;
for (int tZ = zCenter - 16; j < 3; tZ += 16) {
try {
for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, tX, tZ, this.mChunkGenerator, this.mChunkProvider);
@ -136,14 +123,13 @@ public class GT_Worldgenerator
}
i++;
}
}
}
//Asteroid Worldgen
int tDimensionType = this.mWorld.provider.dimensionId;
String tDimensionName = this.mWorld.provider.getDimensionName();
Random aRandom = new Random();
if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0))) || ((tDimensionName.equals("Asteroids")) && gcAsteroids && ((mGCAsteroidProbability <= 1) || (aRandom.nextInt(mGCAsteroidProbability) == 0)))) {
short primaryMeta = 0;
short primaryMeta = 0;
short secondaryMeta = 0;
short betweenMeta = 0;
short sporadicMeta = 0;
@ -171,7 +157,7 @@ public class GT_Worldgenerator
}
}
}
if(GT_Values.D1)System.out.println("do asteroid gen: "+this.mX+" "+this.mZ);
if (GT_Values.D1) System.out.println("do asteroid gen: " + this.mX + " " + this.mZ);
int tX = mX + aRandom.nextInt(16);
int tY = 50 + aRandom.nextInt(200 - 50);
int tZ = mZ + aRandom.nextInt(16);
@ -223,12 +209,7 @@ public class GT_Worldgenerator
if (tDimensionType == 1) {
mWorld.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 2);
} else if (tDimensionName.equals("Asteroids")) {
//int asteroidType = aRandom.nextInt(20);
//if (asteroidType == 19) { //Rare Asteroid?
//mWorld.setBlock(eX, eY, eZ, GregTech_API.sBlockGranites, 8, 3);
//} else {
mWorld.setBlock(eX, eY, eZ, GregTech_API.sBlockGranites, 8, 3);
//}
}
}
}
@ -239,10 +220,8 @@ public class GT_Worldgenerator
}
}
}
}
Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ);
if (tChunk != null) {
tChunk.isModified = true;