oregen lag fix

This commit is contained in:
Dragon2488 2016-09-22 22:00:27 +07:00
parent dda2aa95a2
commit 5509d94044
11 changed files with 418 additions and 182 deletions

View file

@ -0,0 +1,255 @@
package gregtech.api.objects;
/**
* A subclass of java.util.random that implements the Xorshift random number
* generator
*
* - it is 30% faster than the generator from Java's library - it produces
* random sequences of higher quality than java.util.Random - this class also
* provides a clone() function
*
* Usage: XSRandom rand = new XSRandom(); //Instantiation x = rand.nextInt();
* //pull a random number
*
* To use the class in legacy code, you may also instantiate an XSRandom object
* and assign it to a java.util.Random object: java.util.Random rand = new
* XSRandom();
*
* for an explanation of the algorithm, see
* http://demesos.blogspot.com/2011/09/pseudo-random-number-generators.html
*
* @author Wilfried Elmenreich University of Klagenfurt/Lakeside Labs
* http://www.elmenreich.tk
*
* This code is released under the GNU Lesser General Public License Version 3
* http://www.gnu.org/licenses/lgpl-3.0.txt
*/
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
* XSTR - Xorshift ThermiteRandom
* Modified by Bogdan-G
* 03.06.2016
* version 0.0.4
*/
public class XSTR extends Random {
private static final long serialVersionUID = 6208727693524452904L;
private long seed;
private long last;
private static final long GAMMA = 0x9e3779b97f4a7c15L;
private static final int PROBE_INCREMENT = 0x9e3779b9;
private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
/*
MODIFIED BY: Robotia
Modification: Implemented Random class seed generator
*/
/**
* Creates a new pseudo random number generator. The seed is initialized to
* the current time, as if by
* <code>setSeed(System.currentTimeMillis());</code>.
*/
public XSTR() {
this(seedUniquifier() ^ System.nanoTime());
}
private static final AtomicLong seedUniquifier
= new AtomicLong(8682522807148012L);
private static long seedUniquifier() {
// L'Ecuyer, "Tables of Linear Congruential Generators of
// Different Sizes and Good Lattice Structure", 1999
for (;;) {
long current = seedUniquifier.get();
long next = current * 181783497276652981L;
if (seedUniquifier.compareAndSet(current, next)) {
return next;
}
}
}
/**
* Creates a new pseudo random number generator, starting with the specified
* seed, using <code>setSeed(seed);</code>.
*
* @param seed the initial seed
*/
public XSTR(long seed) {
this.seed = seed;
}
public boolean nextBoolean() {
return next(1) != 0;
}
public double nextDouble() {
return (((long)(next(26)) << 27) + next(27)) * DOUBLE_UNIT;
}
/**
* Returns the current state of the seed, can be used to clone the object
*
* @return the current seed
*/
public synchronized long getSeed() {
return seed;
}
/**
* Sets the seed for this pseudo random number generator. As described
* above, two instances of the same random class, starting with the same
* seed, produce the same results, if the same methods are called.
*
* @param seed the new seed
*/
public synchronized void setSeed(long seed) {
this.seed = seed;
}
/**
* @return Returns an XSRandom object with the same state as the original
*/
@Override
public XSTR clone() {
return new XSTR(getSeed());
}
/**
* Implementation of George Marsaglia's elegant Xorshift random generator
* 30% faster and better quality than the built-in java.util.random see also
* see http://www.javamex.com/tutorials/random_numbers/xorshift.shtml
*
* @param nbits
* @return
*/
public int next(int nbits) {
long x = seed;
x ^= (x << 21);
x ^= (x >>> 35);
x ^= (x << 4);
seed = x;
x &= ((1L << nbits) - 1);
return (int) x;
}
boolean haveNextNextGaussian = false;
double nextNextGaussian = 0;
synchronized public double nextGaussian() {
// See Knuth, ACP, Section 3.4.1 Algorithm C.
if (haveNextNextGaussian) {
haveNextNextGaussian = false;
return nextNextGaussian;
} else {
double v1, v2, s;
do {
v1 = 2 * nextDouble() - 1; // between -1 and 1
v2 = 2 * nextDouble() - 1; // between -1 and 1
s = v1 * v1 + v2 * v2;
} while (s >= 1 || s == 0);
double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
nextNextGaussian = v2 * multiplier;
haveNextNextGaussian = true;
return v1 * multiplier;
}
}
/**
* Returns a pseudorandom, uniformly distributed {@code int} value between 0
* (inclusive) and the specified value (exclusive), drawn from this random
* number generator's sequence. The general contract of {@code nextInt} is
* that one {@code int} value in the specified range is pseudorandomly
* generated and returned. All {@code bound} possible {@code int} values are
* produced with (approximately) equal probability. The method
* {@code nextInt(int bound)} is implemented by class {@code Random} as if
* by:
* <pre> {@code
* public int nextInt(int bound) {
* if (bound <= 0)
* throw new IllegalArgumentException("bound must be positive");
*
* if ((bound & -bound) == bound) // i.e., bound is a power of 2
* return (int)((bound * (long)next(31)) >> 31);
*
* int bits, val;
* do {
* bits = next(31);
* val = bits % bound;
* } while (bits - val + (bound-1) < 0);
* return val;
* }}</pre>
*
* <p>The hedge "approx
* imately" is used in the foregoing description only because the next
* method is only approximately an unbiased source of independently chosen
* bits. If it were a perfect source of randomly chosen bits, then the
* algorithm shown would choose {@code int} values from the stated range
* with perfect uniformity.
* <p>
* The algorithm is slightly tricky. It rejects values that would result in
* an uneven distribution (due to the fact that 2^31 is not divisible by n).
* The probability of a value being rejected depends on n. The worst case is
* n=2^30+1, for which the probability of a reject is 1/2, and the expected
* number of iterations before the loop terminates is 2.
* <p>
* The algorithm treats the case where n is a power of two specially: it
* returns the correct number of high-order bits from the underlying
* pseudo-random number generator. In the absence of special treatment, the
* correct number of <i>low-order</i> bits would be returned. Linear
* congruential pseudo-random number generators such as the one implemented
* by this class are known to have short periods in the sequence of values
* of their low-order bits. Thus, this special case greatly increases the
* length of the sequence of values returned by successive calls to this
* method if n is a small power of two.
*
* @param bound the upper bound (exclusive). Must be positive.
* @return the next pseudorandom, uniformly distributed {@code int} value
* between zero (inclusive) and {@code bound} (exclusive) from this random
* number generator's sequence
* @throws IllegalArgumentException if bound is not positive
* @since 1.2
*/
public int nextInt(int bound) {
//if (bound <= 0) {
//throw new RuntimeException("BadBound");
//}
/*int r = next(31);
int m = bound - 1;
if ((bound & m) == 0) // i.e., bound is a power of 2
{
r = (int) ((bound * (long) r) >> 31);
} else {
for (int u = r;
u - (r = u % bound) + m < 0;
u = next(31))
;
}
return r;*/
//speedup, new nextInt ~+40%
last = seed ^ (seed << 21);
last ^= (last >>> 35);
last ^= (last << 4);
seed = last;
int out = (int) last % bound;
return (out < 0) ? -out : out;
}
public int nextInt() {
return next(32);
}
public float nextFloat() {
return next(24) * FLOAT_UNIT;
}
public long nextLong() {
// it's okay that the bottom word remains signed.
return ((long)(next(32)) << 32) + next(32);
}
public void nextBytes(byte[] bytes_arr) {
for (int iba = 0, lenba = bytes_arr.length; iba < lenba; )
for (int rndba = nextInt(),
nba = Math.min(lenba - iba, Integer.SIZE/Byte.SIZE);
nba-- > 0; rndba >>= Byte.SIZE)
bytes_arr[iba++] = (byte)rndba;
}
}

View file

@ -7,16 +7,13 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator; import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
public abstract class GT_Worldgen { public abstract class GT_Worldgen {
public final String mWorldGenName; public final String mWorldGenName;
public final boolean mEnabled; public final boolean mEnabled;
private final Map<String, Boolean> mDimensionMap = new HashMap<String, Boolean>();
public GT_Worldgen(String aName, List aList, boolean aDefault) { public GT_Worldgen(String aName, List aList, boolean aDefault) {
mWorldGenName = aName; mWorldGenName = aName;
@ -51,30 +48,32 @@ public abstract class GT_Worldgen {
} }
public boolean isDimensionAllowed(World aWorld, int aDimensionType, boolean nether, boolean overworld, boolean end) { public boolean isDimensionAllowed(World aWorld, int aDimensionType, boolean nether, boolean overworld, boolean end) {
String aDimName = aWorld.getProviderName(); /*String aDimName = aWorld.getProviderName();
Boolean tAllowed = mDimensionMap.get(aDimName); Boolean tAllowed = mDimensionMap.get(aDimName);
if (tAllowed == null) { if (tAllowed == null) {
boolean tValue = GregTech_API.sWorldgenFile.get("worldgen.dimensions." + mWorldGenName, aDimName, ((aDimensionType == -1) && nether) || ((aDimensionType == 0) && overworld) || ((aDimensionType == 1) && end)); boolean tValue = GregTech_API.sWorldgenFile.get("worldgen.dimensions." + mWorldGenName, aDimName, ((aDimensionType == -1) && nether) || ((aDimensionType == 0) && overworld) || ((aDimensionType == 1) && end));
mDimensionMap.put(aDimName, tValue); mDimensionMap.put(aDimName, tValue);
return tValue; return tValue;
} }
return tAllowed; return tAllowed;*/
return (aDimensionType == 0 && overworld) || (aDimensionType == -1 && nether) || (aDimensionType == 1 & end);
} }
public boolean isDimensionAllowed(World aWorld, int aDimensionType, int exceptedDimension) { public boolean isDimensionAllowed(World aWorld, int aDimensionType, int exceptedDimension) {
String aDimName = aWorld.getProviderName(); /*String aDimName = aWorld.getProviderName();
Boolean tAllowed = mDimensionMap.get(aDimName); Boolean tAllowed = mDimensionMap.get(aDimName);
if (tAllowed == null) { if (tAllowed == null) {
boolean tValue = GregTech_API.sWorldgenFile.get("worldgen.dimensions." + mWorldGenName, aDimName, aDimensionType == exceptedDimension); boolean tValue = GregTech_API.sWorldgenFile.get("worldgen.dimensions." + mWorldGenName, aDimName, aDimensionType == exceptedDimension);
mDimensionMap.put(aDimName, tValue); mDimensionMap.put(aDimName, tValue);
return tValue; return tValue;
} }
return tAllowed; return tAllowed;*/
return aDimensionType == 0 || aDimensionType == -1 || aDimensionType == 1 || aDimensionType == exceptedDimension;
} }
public boolean isGenerationAllowed(World aWorld, BlockPos blockPos) { public boolean isGenerationAllowed(World aWorld, BlockPos blockPos) {
IBlockState blockState = aWorld.getBlockState(blockPos); IBlockState blockState = aWorld.getBlockState(blockPos);
return blockState.getBlock().isReplaceableOreGen(blockState, aWorld, blockPos, GT_Worldgen_Ore_Normal.ANY); return GT_Worldgen_Constants.ANY.apply(blockState);
} }
} }

View file

@ -18,7 +18,7 @@ import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Random; import java.util.Random;
public class GT_Worldgen_Ore_Normal { public class GT_Worldgen_Constants {
public static Predicate<IBlockState> STONES = input -> public static Predicate<IBlockState> STONES = input ->

View file

@ -1,9 +1,8 @@
package gregtech.common; package gregtech.common;
import gregtech.api.world.GT_Worldgen_Ore_Normal; import gregtech.api.world.GT_Worldgen_Constants;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -65,7 +64,7 @@ public class GT_MinableOreGenerator
BlockPos block = new BlockPos(var38, var41, var44); BlockPos block = new BlockPos(var38, var41, var44);
IBlockState blockState = par1World.getBlockState(block); IBlockState blockState = par1World.getBlockState(block);
if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && ((this.allowVoid && par1World.isAirBlock(block)) || if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && ((this.allowVoid && par1World.isAirBlock(block)) ||
(block != null && (blockState.getBlock().isReplaceableOreGen(blockState, par1World, pos, GT_Worldgen_Ore_Normal.ANY))))) { (block != null && (blockState.getBlock().isReplaceableOreGen(blockState, par1World, pos, GT_Worldgen_Constants.ANY))))) {
par1World.setBlockState(block, this.minableBlockId.getStateFromMeta(minableBlockMeta)); par1World.setBlockState(block, this.minableBlockId.getStateFromMeta(minableBlockMeta));
} }
} }

View file

@ -10,6 +10,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator; import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import org.apache.commons.lang3.time.StopWatch;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
@ -60,12 +61,15 @@ public class GT_Worldgen_GT_Ore_Layer
@Override @Override
public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) { public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) {
if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) { //if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) {
return false; //Not the correct biome for ore mix // return false; //Not the correct biome for ore mix
} //}
if (!isDimensionAllowed(aWorld, aDimensionType, mNether, mOverworld, mEnd)) { if (!isDimensionAllowed(aWorld, aDimensionType, mNether, mOverworld, mEnd)) {
return false; return false;
} }
//StopWatch watch = new StopWatch();
//watch.start();
int tMinY = this.mMinY + aRandom.nextInt(this.mMaxY - this.mMinY - 5); int tMinY = this.mMinY + aRandom.nextInt(this.mMaxY - this.mMinY - 5);
int cX = aChunkX - aRandom.nextInt(this.mSize); int cX = aChunkX - aRandom.nextInt(this.mSize);
@ -108,9 +112,10 @@ public class GT_Worldgen_GT_Ore_Layer
} }
} }
} }
if (GT_Values.D1) { //watch.stop();
System.out.println("Generated Orevein: " + this.mWorldGenName); //if (GT_Values.D1) {
} //System.out.println("Generated Orevein: " + watch.getTime() + " ms " + this.mWorldGenName + " X: " + (aChunkX * 16) + " Z: " + (aChunkZ * 16));
//}
return true; return true;
} }
} }

View file

@ -36,9 +36,9 @@ public class GT_Worldgen_GT_Ore_SmallPieces
@Override @Override
public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) { public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) {
if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) { //if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) {
return false; //Not the correct biome for ore mix // return false; //Not the correct biome for ore mix
} //}
if (!isDimensionAllowed(aWorld, aDimensionType, mNether, mOverworld, mEnd)) { if (!isDimensionAllowed(aWorld, aDimensionType, mNether, mOverworld, mEnd)) {
return false; return false;
} }

View file

@ -2,7 +2,7 @@ package gregtech.common;
import gregtech.api.GregTech_API; import gregtech.api.GregTech_API;
import gregtech.api.world.GT_Worldgen_Ore; import gregtech.api.world.GT_Worldgen_Ore;
import gregtech.api.world.GT_Worldgen_Ore_Normal; import gregtech.api.world.GT_Worldgen_Constants;
import gregtech.common.blocks.GT_Block_Ores_Abstract; import gregtech.common.blocks.GT_Block_Ores_Abstract;
import gregtech.common.blocks.GT_TileEntity_Ores; import gregtech.common.blocks.GT_TileEntity_Ores;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -71,7 +71,7 @@ public class GT_Worldgen_Stone
((GT_TileEntity_Ores)tTileEntity).overrideOreBlockMaterial(this.mBlock, (byte) this.mBlockMeta); ((GT_TileEntity_Ores)tTileEntity).overrideOreBlockMaterial(this.mBlock, (byte) this.mBlockMeta);
} }
} else if ((this.mAllowToGenerateinVoid && aWorld.isAirBlock(randPos)) || } else if ((this.mAllowToGenerateinVoid && aWorld.isAirBlock(randPos)) ||
(tTargetedBlock != null && tTargetedBlock.getBlock().isReplaceableOreGen(tTargetedBlock, aWorld, randPos, GT_Worldgen_Ore_Normal.ANY))) { (tTargetedBlock != null && tTargetedBlock.getBlock().isReplaceableOreGen(tTargetedBlock, aWorld, randPos, GT_Worldgen_Constants.ANY))) {
aWorld.setBlockState(randPos, this.mBlock.getStateFromMeta(mBlockMeta)); aWorld.setBlockState(randPos, this.mBlock.getStateFromMeta(mBlockMeta));
} }
} }

View file

@ -1,5 +1,6 @@
package gregtech.common; package gregtech.common;
import gregtech.api.objects.XSTR;
import net.minecraft.init.Biomes; import net.minecraft.init.Biomes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -44,160 +45,143 @@ public class GT_Worldgenerator implements IWorldGenerator {
@Override @Override
public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) { public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) {
if(aRandom.nextInt(3) == 0) { Random xstrRandom = new XSTR(aRandom.nextLong() ^ System.nanoTime());
Biome biome = aWorld.getBiomeGenForCoords(new BlockPos(aX * 16 + 8, 16, aZ * 16 + 8)); Biome biome = aWorld.getBiomeGenForCoords(new BlockPos(aX * 16, 64, aZ * 16));
new WorldGenContainer(aRandom, aX * 16, aZ * 16,
(aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 : generateInternal(xstrRandom, aX * 16, aZ * 16,
(aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0, getDimensionType(aChunkGenerator, biome),
aWorld, aChunkGenerator, aChunkProvider, biome.getBiomeName()).run(); aWorld, aChunkGenerator, aChunkProvider,
} biome.getBiomeName());
} }
public static class WorldGenContainer private int getDimensionType(IChunkGenerator aChunkGenerator, Biome biome) {
implements Runnable { return (aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 :
public final Random mRandom; (aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0;
public final int mX; }
public final int mZ;
public final int mDimensionType;
public final World mWorld;
public final IChunkGenerator mChunkGenerator;
public final IChunkProvider mChunkProvider;
public final String mBiome;
public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) {
this.mRandom = aRandom;
this.mX = aX;
this.mZ = aZ;
this.mDimensionType = aDimensionType;
this.mWorld = aWorld;
this.mChunkGenerator = aChunkGenerator;
this.mChunkProvider = aChunkProvider;
this.mBiome = aBiome;
}
public void run() { private void generateInternal(Random mRandom, int mX, int mZ, int mDimensionType, World mWorld, IChunkGenerator mChunkGenerator, IChunkProvider mChunkProvider, String mBiome) {
if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) { if ((Math.abs(mX / 16) % 3 == 1) && (Math.abs(mZ / 16) % 3 == 1)) {
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
boolean temp = true; boolean temp = true;
int tRandomWeight; int tRandomWeight;
for (int i = 0; (i < 256) && (temp); i++) { for (int i = 0; (i < 256) && (temp); i++) {
tRandomWeight = this.mRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight); tRandomWeight = mRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight);
for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) {
tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight; tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight;
if (tRandomWeight <= 0) { if (tRandomWeight <= 0) {
try {
if (tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX, this.mZ, this.mChunkGenerator, this.mChunkProvider)) {
temp = false;
}
break;
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
}
}
}
}
int i = 0;
for (int tX = this.mX - 16; i < 3; tX += 16) {
int j = 0;
for (int tZ = this.mZ - 16; j < 3; tZ += 16) {
String tBiome = this.mWorld.getBiomeGenForCoords(new BlockPos(tX + 8, 0, tZ + 8)).getBiomeName();
if (tBiome == null) {
tBiome = Biomes.PLAINS.getBiomeName();
}
for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
try { try {
tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, tX, tZ, this.mChunkGenerator, this.mChunkProvider); if (tWorldGen.executeWorldgen(mWorld, mRandom, mBiome, mDimensionType, mX, mZ, mChunkGenerator, mChunkProvider)) {
temp = false;
}
break;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(GT_Log.err); e.printStackTrace(GT_Log.err);
} }
} }
j++;
} }
i++;
} }
} }
//Asteroid Worldgen int i = 0;
int tDimensionType = this.mWorld.provider.getDimension(); for (int tX = mX - 16; i < 3; tX += 16) {
Random aRandom = new Random(); int j = 0;
if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0)))) { for (int tZ = mZ - 16; j < 3; tZ += 16) {
short primaryMeta = 0; String tBiome = mWorld.getBiomeGenForCoords(new BlockPos(tX + 8, 0, tZ + 8)).getBiomeName();
short secondaryMeta = 0; if (tBiome == null) {
short betweenMeta = 0; tBiome = Biomes.PLAINS.getBiomeName();
short sporadicMeta = 0; }
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
boolean temp = true; try {
int tRandomWeight; tWorldGen.executeWorldgen(mWorld, mRandom, mBiome, mDimensionType, tX, tZ, mChunkGenerator, mChunkProvider);
for (int i = 0; (i < 256) && (temp); i++) { } catch (Throwable e) {
tRandomWeight = aRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight); e.printStackTrace(GT_Log.err);
for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { }
tRandomWeight -= tWorldGen.mWeight; }
if (tRandomWeight <= 0) { j++;
try { }
if (tWorldGen.mEndAsteroid && tDimensionType == 1) { i++;
primaryMeta = tWorldGen.mPrimaryMeta; }
secondaryMeta = tWorldGen.mSecondaryMeta; }
betweenMeta = tWorldGen.mBetweenMeta; //Asteroid Worldgen
sporadicMeta = tWorldGen.mSporadicMeta; int tDimensionType = mWorld.provider.getDimension();
temp = false; Random aRandom = new Random();
break; if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0)))) {
} short primaryMeta = 0;
} catch (Throwable e) { short secondaryMeta = 0;
e.printStackTrace(GT_Log.err); short betweenMeta = 0;
short sporadicMeta = 0;
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
boolean temp = true;
int tRandomWeight;
for (int i = 0; (i < 256) && (temp); i++) {
tRandomWeight = aRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight);
for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) {
tRandomWeight -= tWorldGen.mWeight;
if (tRandomWeight <= 0) {
try {
if (tWorldGen.mEndAsteroid && tDimensionType == 1) {
primaryMeta = tWorldGen.mPrimaryMeta;
secondaryMeta = tWorldGen.mSecondaryMeta;
betweenMeta = tWorldGen.mBetweenMeta;
sporadicMeta = tWorldGen.mSporadicMeta;
temp = false;
break;
} }
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
} }
} }
} }
} }
int tX = mX + aRandom.nextInt(16); }
int tY = 50 + aRandom.nextInt(200 - 50); int tX = mX + aRandom.nextInt(16);
int tZ = mZ + aRandom.nextInt(16); int tY = 50 + aRandom.nextInt(200 - 50);
if (tDimensionType == 1) { int tZ = mZ + aRandom.nextInt(16);
mSize = aRandom.nextInt(endMaxSize - endMinSize); if (tDimensionType == 1) {
} mSize = aRandom.nextInt(endMaxSize - endMinSize);
if ((mWorld.isAirBlock(new BlockPos(tX, tY, tZ)))) { }
float var6 = aRandom.nextFloat() * 3.141593F; if ((mWorld.isAirBlock(new BlockPos(tX, tY, tZ)))) {
double var7 = tX + 8 + MathHelper.sin(var6) * mSize / 8.0F; float var6 = aRandom.nextFloat() * 3.141593F;
double var9 = tX + 8 - MathHelper.sin(var6) * mSize / 8.0F; double var7 = tX + 8 + MathHelper.sin(var6) * mSize / 8.0F;
double var11 = tZ + 8 + MathHelper.cos(var6) * mSize / 8.0F; double var9 = tX + 8 - MathHelper.sin(var6) * mSize / 8.0F;
double var13 = tZ + 8 - MathHelper.cos(var6) * mSize / 8.0F; double var11 = tZ + 8 + MathHelper.cos(var6) * mSize / 8.0F;
double var15 = tY + aRandom.nextInt(3) - 2; double var13 = tZ + 8 - MathHelper.cos(var6) * mSize / 8.0F;
double var17 = tY + aRandom.nextInt(3) - 2; double var15 = tY + aRandom.nextInt(3) - 2;
for (int var19 = 0; var19 <= mSize; var19++) { double var17 = tY + aRandom.nextInt(3) - 2;
double var20 = var7 + (var9 - var7) * var19 / mSize; for (int var19 = 0; var19 <= mSize; var19++) {
double var22 = var15 + (var17 - var15) * var19 / mSize; double var20 = var7 + (var9 - var7) * var19 / mSize;
double var24 = var11 + (var13 - var11) * var19 / mSize; double var22 = var15 + (var17 - var15) * var19 / mSize;
double var26 = aRandom.nextDouble() * mSize / 16.0D; double var24 = var11 + (var13 - var11) * var19 / mSize;
double var28 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D; double var26 = aRandom.nextDouble() * mSize / 16.0D;
double var30 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D; double var28 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D;
int tMinX = MathHelper.floor_double(var20 - var28 / 2.0D); double var30 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D;
int tMinY = MathHelper.floor_double(var22 - var30 / 2.0D); int tMinX = MathHelper.floor_double(var20 - var28 / 2.0D);
int tMinZ = MathHelper.floor_double(var24 - var28 / 2.0D); int tMinY = MathHelper.floor_double(var22 - var30 / 2.0D);
int tMaxX = MathHelper.floor_double(var20 + var28 / 2.0D); int tMinZ = MathHelper.floor_double(var24 - var28 / 2.0D);
int tMaxY = MathHelper.floor_double(var22 + var30 / 2.0D); int tMaxX = MathHelper.floor_double(var20 + var28 / 2.0D);
int tMaxZ = MathHelper.floor_double(var24 + var28 / 2.0D); int tMaxY = MathHelper.floor_double(var22 + var30 / 2.0D);
for (int eX = tMinX; eX <= tMaxX; eX++) { int tMaxZ = MathHelper.floor_double(var24 + var28 / 2.0D);
double var39 = (eX + 0.5D - var20) / (var28 / 2.0D); for (int eX = tMinX; eX <= tMaxX; eX++) {
if (var39 * var39 < 1.0D) { double var39 = (eX + 0.5D - var20) / (var28 / 2.0D);
for (int eY = tMinY; eY <= tMaxY; eY++) { if (var39 * var39 < 1.0D) {
double var42 = (eY + 0.5D - var22) / (var30 / 2.0D); for (int eY = tMinY; eY <= tMaxY; eY++) {
if (var39 * var39 + var42 * var42 < 1.0D) { double var42 = (eY + 0.5D - var22) / (var30 / 2.0D);
for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { if (var39 * var39 + var42 * var42 < 1.0D) {
double var45 = (eZ + 0.5D - var24) / (var28 / 2.0D); for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) {
BlockPos randPos = new BlockPos(eX, eY, eZ); double var45 = (eZ + 0.5D - var24) / (var28 / 2.0D);
if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && mWorld.isAirBlock(randPos)) { BlockPos randPos = new BlockPos(eX, eY, eZ);
int ranOre = aRandom.nextInt(50); if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && mWorld.isAirBlock(randPos)) {
if (ranOre < 3) { int ranOre = aRandom.nextInt(50);
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, primaryMeta , true); if (ranOre < 3) {
} else if (ranOre < 6) { GT_TileEntity_Ores.setOreBlock(mWorld, randPos, primaryMeta, true);
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, secondaryMeta , true); } else if (ranOre < 6) {
} else if (ranOre < 8) { GT_TileEntity_Ores.setOreBlock(mWorld, randPos, secondaryMeta, true);
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, betweenMeta , true); } else if (ranOre < 8) {
} else if (ranOre < 10) { GT_TileEntity_Ores.setOreBlock(mWorld, randPos, betweenMeta, true);
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, sporadicMeta , true); } else if (ranOre < 10) {
} else { GT_TileEntity_Ores.setOreBlock(mWorld, randPos, sporadicMeta, true);
mWorld.setBlockState(randPos, Blocks.END_STONE.getDefaultState()); } else {
} mWorld.setBlockState(randPos, Blocks.END_STONE.getDefaultState());
} }
} }
} }
@ -206,10 +190,8 @@ public class GT_Worldgenerator implements IWorldGenerator {
} }
} }
} }
} }
Chunk tChunk = this.mWorld.getChunkFromBlockCoords(new BlockPos(this.mX, 0, this.mZ));
if (tChunk != null) tChunk.setModified(true);
} }
} }
} }

View file

@ -51,7 +51,7 @@ public class GT_TickHandler_Ores {
@SubscribeEvent @SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent player) { public void onPlayerTick(TickEvent.PlayerTickEvent player) {
if(player.side.isServer()) { /*if(player.side.isServer()) {
EntityPlayer entityPlayer = player.player; EntityPlayer entityPlayer = player.player;
World world = entityPlayer.worldObj; World world = entityPlayer.worldObj;
if (world.getWorldTime() % 10 == 0) { if (world.getWorldTime() % 10 == 0) {
@ -71,7 +71,7 @@ public class GT_TickHandler_Ores {
GT_Values.NW.sendTo(packet_ores, (EntityPlayerMP) entityPlayer); GT_Values.NW.sendTo(packet_ores, (EntityPlayerMP) entityPlayer);
} }
} }
} }*/
} }

View file

@ -2,7 +2,6 @@ package gregtech.common.blocks;
import gregtech.GT_Mod; import gregtech.GT_Mod;
import gregtech.api.GregTech_API; import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.Materials; import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.OrePrefixes;
import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.ITexture;
@ -10,16 +9,14 @@ import gregtech.api.interfaces.tileentity.ITexturedTileEntity;
import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_Utility;
import gregtech.api.world.GT_Worldgen_Ore_Normal; import gregtech.api.world.GT_Worldgen_Constants;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
@ -88,7 +85,6 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
} else if(tBlock == GregTech_API.sBlockStones && BlockMeta == 8) { } else if(tBlock == GregTech_API.sBlockStones && BlockMeta == 8) {
aMetaData += 6000; aMetaData += 6000;
} }
aWorld.setBlockState(blockPos, tOreBlock.getStateFromMeta(getHarvestData((short) aMetaData)), 0); aWorld.setBlockState(blockPos, tOreBlock.getStateFromMeta(getHarvestData((short) aMetaData)), 0);
TileEntity tTileEntity = aWorld.getTileEntity(blockPos); TileEntity tTileEntity = aWorld.getTileEntity(blockPos);
if ((tTileEntity instanceof GT_TileEntity_Ores)) { if ((tTileEntity instanceof GT_TileEntity_Ores)) {
@ -142,7 +138,7 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
} else { } else {
this.mMetaData = ((short) (this.mMetaData + 3000)); this.mMetaData = ((short) (this.mMetaData + 3000));
} }
} else if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), GT_Worldgen_Ore_Normal.ANY)) { } else if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), GT_Worldgen_Constants.ANY)) {
if (aOverridingStoneBlock == GregTech_API.sBlockStones) { if (aOverridingStoneBlock == GregTech_API.sBlockStones) {
if (aOverridingStoneMeta < 8) { if (aOverridingStoneMeta < 8) {
this.mMetaData = ((short) (this.mMetaData + 5000)); this.mMetaData = ((short) (this.mMetaData + 5000));
@ -156,17 +152,17 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit
this.worldObj.setBlockState(getPos(), getBlockType().getStateFromMeta(getHarvestData(this.mMetaData)), 0); this.worldObj.setBlockState(getPos(), getBlockType().getStateFromMeta(getHarvestData(this.mMetaData)), 0);
} }
@Override //@Override
public void invalidate() { //public void invalidate() {
super.invalidate(); //super.invalidate();
GT_TickHandler_Ores.unloadChunkOre(this); //GT_TickHandler_Ores.unloadChunkOre(this);
} //}
@Override //@Override
public void validate() { //public void validate() {
super.validate(); //super.validate();
GT_TickHandler_Ores.loadChunkOre(this); //GT_TickHandler_Ores.loadChunkOre(this);
} //}
public void convertOreBlock(World aWorld, int aX, int aY, int aZ) { public void convertOreBlock(World aWorld, int aX, int aY, int aZ) {
short aMeta = ((short) (int) (this.mMetaData % 1000 + (this.mMetaData / 16000 * 16000))); short aMeta = ((short) (int) (this.mMetaData % 1000 + (this.mMetaData / 16000 * 16000)));

View file

@ -143,7 +143,7 @@ public class GT_Loader_Item_Block_And_Fluid
GregTech_API.sBlockOresUb2 = new GT_Block_Ores_UB2(); GregTech_API.sBlockOresUb2 = new GT_Block_Ores_UB2();
GregTech_API.sBlockOresUb3 = new GT_Block_Ores_UB3(); GregTech_API.sBlockOresUb3 = new GT_Block_Ores_UB3();
} }
new GT_TickHandler_Ores(); //new GT_TickHandler_Ores();
GregTech_API.sBlockMetal1 = new GT_Block_Metal("gt.blockmetal1", new Materials[]{ GregTech_API.sBlockMetal1 = new GT_Block_Metal("gt.blockmetal1", new Materials[]{
Materials.Adamantium, Materials.Adamantium,
Materials.Aluminium, Materials.Aluminium,