@Override public void spawn(LocalWorld world, Random random, boolean villageInChunk, int x, int z) { int y = RandomHelper.numberInRange(random, minAltitude, maxAltitude); world.placeDungeon(random, x, y, z); }
/** * Returns the vein that starts in the chunk. * @param world The world to spawn in. * @param chunkX The x of the chunk. * @param chunkZ The z of the chunk. * @return The vein that starts in the chunk, or null if there is no * starting vein. */ public Vein getVeinStartInChunk(LocalWorld world, int chunkX, int chunkZ) { // Create a random generator that is constant for this chunk and vein Random random = RandomHelper.getRandomForCoords(chunkX, chunkZ, material.hashCode() * (minRadius + maxRadius + 100) + world.getSeed()); if (random.nextDouble() * 100.0 < veinRarity) { int veinX = chunkX * 16 + random.nextInt(16) + 8; int veinY = RandomHelper.numberInRange(random, minAltitude, maxAltitude); int veinZ = chunkZ * 16 + random.nextInt(16) + 8; int veinSize = RandomHelper.numberInRange(random, minRadius, maxRadius); return new Vein(veinX, veinY, veinZ, veinSize); } return null; }
/** * Gets a Random generator with a random seed. However, the same input * will always produce the same output. * * @param x X-coord to start with. * @param y Y-coord to start with. * @param z Z-coord to start with. * @param seed Seed to start with. * @return A random generator with a random seed. */ public static Random getRandomForCoords(int x, int y, int z, long seed) { Random random = getRandomForCoords(x, z, seed); random.setSeed(random.nextInt() * y); return random; }
Random random = RandomHelper.getRandomForCoords(chunkX ^ 2, (chunkZ + 1) * 2, world.getSeed()); CustomStructureGen structureGen = world.getBiome(chunkX * 16 + 15, chunkZ * 16 + 15).getBiomeConfig().structureGen; if (structureGen != null)
@Override public CustomObjectCoordinate makeCustomObjectCoordinate(Random random, int chunkX, int chunkZ) { if (rarity > random.nextDouble() * 100.0) { Rotation rotation = Rotation.getRandomRotation(random); int height = RandomHelper.numberInRange(random, this.spawnElevationMin, this.spawnElevationMax); return new CustomObjectCoordinate(this, rotation, chunkX * 16 + 8 + random.nextInt(16), height, chunkZ * 16 + 8 + random.nextInt(16)); } return null; }
CustomObjectStructure(LocalWorld world, CustomObjectCoordinate start) { CustomObject object = start.getObject(); this.world = world; this.start = start; this.height = object.getStructurePartSpawnHeight(); this.maxBranchDepth = object.getMaxBranchDepth(); random = RandomHelper.getRandomForCoords(start.getX(), start.getY(), start.getZ(), world.getSeed()); // Calculate all branches and add them to a list objectsToSpawn = new LinkedHashMap<ChunkCoordinate, Set<CustomObjectCoordinate>>(); addToSpawnList(start); // Add the object itself addBranches(start, 1); }
@Override public CustomObjectCoordinate makeCustomObjectCoordinate(Random random, int chunkX, int chunkZ) { if (settings.rarity > random.nextDouble() * 100.0) { Rotation rotation = settings.rotateRandomly ? Rotation.getRandomRotation(random) : Rotation.NORTH; int height = RandomHelper.numberInRange(random, settings.minHeight, settings.maxHeight); return new CustomObjectCoordinate( this, rotation, chunkX * 16 + 8 + random.nextInt(16), height, chunkZ * 16 + 8 + random.nextInt(16) ); } return null; }
@Override protected void generateChunk(ChunkCoordinate currentChunk, ChunkBuffer generatingChunkBuffer) { if (this.random.nextInt(100) >= this.worldSettings.ravineRarity) return; double d1 = currentChunk.getBlockX() + this.random.nextInt(ChunkCoordinate.CHUNK_X_SIZE); double d2 = RandomHelper.numberInRange(random, this.worldSettings.ravineMinAltitude, this.worldSettings.ravineMaxAltitude); double d3 = currentChunk.getBlockZ() + this.random.nextInt(ChunkCoordinate.CHUNK_Z_SIZE); int i = 1; for (int j = 0; j < i; j++) { float f1 = this.random.nextFloat() * 3.141593F * 2.0F; float f2 = (this.random.nextFloat() - 0.5F) * 2.0F / 8.0F; float f3 = (this.random.nextFloat() * 2.0F + this.random.nextFloat()) * 2.0F; int size = RandomHelper.numberInRange(random, this.worldSettings.ravineMinLength, this.worldSettings.ravineMaxLength); a(this.random.nextLong(), generatingChunkBuffer, d1, d2, d3, f3, f1, f2, size, this.worldSettings.ravineDepth); } } }
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) { int y = RandomHelper.numberInRange(rand, minAltitude, maxAltitude); for (int i = 0; i < 64; i++) { int j = x + rand.nextInt(8) - rand.nextInt(8); int k = y + rand.nextInt(4) - rand.nextInt(4); int m = z + rand.nextInt(8) - rand.nextInt(8); if ((!world.isEmpty(j, k, m)) || (!sourceBlocks.contains(world.getMaterial(j, k - 1, m)))) continue; plant.spawn(world, j, k, m); } }
public void spawn(LocalWorld world, Random random, ChunkCoordinate chunkCoord, VeinGen gen) { int sizeSquared = size * size; for (int i = 0; i < gen.oreFrequency; i++) { if (random.nextInt(100) < gen.oreRarity) { int oreX = chunkCoord.getBlockXCenter() + random.nextInt(ChunkCoordinate.CHUNK_X_SIZE); int oreY = RandomHelper.numberInRange(random, gen.minAltitude, gen.maxAltitude); int oreZ = chunkCoord.getBlockZCenter() + random.nextInt(ChunkCoordinate.CHUNK_Z_SIZE); if ((oreX - x) * (oreX - x) + (oreY - y) * (oreY - y) + (oreZ - z) * (oreZ - z) < sizeSquared) { spawnOre(world, random, oreX, oreY, oreZ, gen); } } } }
y = RandomHelper.numberInRange(random, this.worldSettings.caveMinAltitude, this.worldSettings.caveMaxAltitude); else y = this.random.nextInt(this.random.nextInt(this.worldSettings.caveMaxAltitude - this.worldSettings.caveMinAltitude + 1) + 1) + this.worldSettings.caveMinAltitude; count += RandomHelper.numberInRange(random, this.worldSettings.caveSystemPocketMinSize, this.worldSettings.caveSystemPocketMaxSize);
@Test public void testConsistency() { // Random number generator with a known seed, so results should always // be the same (required for terrain generation to be reproducible) Random random = new Random(15); assertEquals(6, RandomHelper.numberInRange(random, 0, 10)); assertEquals(0, RandomHelper.numberInRange(random, 0, 10)); assertEquals(0, RandomHelper.numberInRange(random, 0, 10)); assertEquals(7, RandomHelper.numberInRange(random, 0, 10)); }
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) int y = RandomHelper.numberInRange(rand, minAltitude, maxAltitude);
@Test public void testZeroRange() { assertEquals(3, RandomHelper.numberInRange(new Random(), 3, 3)); } }
z -= 8; int y = RandomHelper.numberInRange(rand, minAltitude, maxAltitude);
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) int y = RandomHelper.numberInRange(rand, minAltitude, maxAltitude); int size = RandomHelper.numberInRange(rand, minSize, maxSize);
public void spawnBasement(LocalWorld world, Random random,int x, int z) int y = RandomHelper.numberInRange(random, this.minAltitude, this.maxAltitude);
public void spawnSpike(LocalWorld par1World, Random random, int x, int z, boolean hugeSpike) int y = RandomHelper.numberInRange(random, minAltitude, maxAltitude); while (par1World.isEmpty(x, y, z) && y > 2)
protected boolean spawn(LocalWorld world, Random random, int x, int z) { Rotation rotation = settings.rotateRandomly ? Rotation.getRandomRotation(random) : Rotation.NORTH; int y = 0; if (settings.spawnHeight == SpawnHeightEnum.atMinY) { y = settings.minHeight; } if (settings.spawnHeight == SpawnHeightEnum.randomY) { y = RandomHelper.numberInRange(random, settings.minHeight, settings.maxHeight); } if (settings.spawnHeight == SpawnHeightEnum.highestBlock) { y = world.getHighestBlockYAt(x, z); } if (settings.spawnHeight == SpawnHeightEnum.highestSolidBlock) { y = world.getSolidHeight(x, z); } // Offset by static and random settings values y += this.getOffsetAndVariance(random, settings.spawnHeightOffset, settings.spawnHeightVariance); if (!canSpawnAt(world, rotation, x, y, z)) { return false; } return spawnForced(world, random, rotation, x, y, z); }
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) int y = RandomHelper.numberInRange(rand, minAltitude, maxAltitude);