@Override public Location getFixedSpawnLocation(World world, Random random) { int spawnX = random.nextInt(256) - 128; int spawnZ = random.nextInt(256) - 128; for (int tries = 0; tries < 1000 && !canSpawn(world, spawnX, spawnZ); ++tries) { spawnX += random.nextInt(128) - 64; spawnZ += random.nextInt(128) - 64; } return new Location(world, spawnX, world.getHighestBlockYAt(spawnX, spawnZ), spawnZ); } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); for (int i = 0; i < 10; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); new Cactus().generate(world, random, x, y, z); } } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int maxY = world.getHighestBlockYAt(sourceX, sourceZ); if (maxY <= 0) { return; } int sourceY = random.nextInt(maxY << 1); for (int j = 0; j < 20; j++) { int x = sourceX + random.nextInt(4) - random.nextInt(4); int z = sourceZ + random.nextInt(4) - random.nextInt(4); new SugarCane().generate(world, random, x, sourceY, z); } } }
@Override public void populate(World world, Random random, Chunk chunk) { int sourceX = chunk.getX() << 4; int sourceZ = chunk.getZ() << 4; for (int i = 0; i < random.nextInt(3); i++) { int x = sourceX + random.nextInt(16); int z = sourceZ + random.nextInt(16); int y = world.getHighestBlockYAt(x, z); new StoneBoulder().generate(world, random, x, y, z); } } }
@Override public void decorate(World world, Random random, Chunk source) { if (random.nextInt(5) == 0) { int x = (source.getX() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16); int y = world.getHighestBlockYAt(x, z); new ObsidianPillar().generate(world, random, x, y, z); } } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) + 32); DoublePlantSpecies species = getRandomDoublePlant(random, doublePlants); new DoubleTallPlant(species).generate(world, random, sourceX, sourceY, sourceZ); }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) + 32); // the flower can change on each decoration pass FlowerType flower = getRandomFlower(random, flowers); if (flower != null) { new Flower(flower).generate(world, random, sourceX, sourceY, sourceZ); } }
@Override public void populateOnGround(World world, Random random, Chunk chunk) { int sourceX = chunk.getX() << 4; int sourceZ = chunk.getZ() << 4; int amount = random.nextInt(5) - doublePlantLoweringAmount; int i = 0; while (i < amount) { for (int j = 0; j < 5; j++, i++) { int x = sourceX + random.nextInt(16); int z = sourceZ + random.nextInt(16); int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32); DoublePlantSpecies species = DOUBLE_PLANTS[random.nextInt(DOUBLE_PLANTS.length)]; if (new DoubleTallPlant(species).generate(world, random, x, y, z)) { i++; break; } } } super.populateOnGround(world, random, chunk); } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int topBlock = world.getHighestBlockYAt(sourceX, sourceZ); if (topBlock == 0) { // Nothing to do if this column is empty return; } int sourceY = random.nextInt(Math.abs(topBlock << 1)); // the grass species can change on each decoration pass GrassSpecies species = GrassSpecies.NORMAL; if (fernDensity > 0 && random.nextFloat() < fernDensity) { species = GrassSpecies.FERN_LIKE; } new TallGrass(new LongGrass(species)).generate(world, random, sourceX, sourceY, sourceZ); } }
private double spread(World world, List<Player> list, Location[] locations, boolean teams) { double distance = 0.0D; int i = 0; Map<Team, Location> hashmap = Maps.newHashMap(); for (int j = 0; j < list.size(); ++j) { Player player = list.get(j); Location location; if (teams) { Team team = player.getScoreboard().getPlayerTeam(player); if (!hashmap.containsKey(team)) { hashmap.put(team, locations[i++]); } location = hashmap.get(team); } else { location = locations[i++]; } player.teleport(new Location(world, Math.floor(location.getX()) + 0.5D, world.getHighestBlockYAt((int) location.getX(), (int) location.getZ()), Math.floor(location.getZ()) + 0.5D)); double value = Double.MAX_VALUE; for (int k = 0; k < locations.length; ++k) { if (location != locations[k]) { double d = location.distanceSquared(locations[k]); value = Math.min(d, value); } } distance += value; } distance /= list.size(); return distance; }
@Override public void populateOnGround(World world, Random random, Chunk chunk) { super.populateOnGround(world, random, chunk); int sourceX = chunk.getX() << 4; int sourceZ = chunk.getZ() << 4; for (int i = 0; i < 100; i++) { int x = sourceX + random.nextInt(16); int z = sourceZ + random.nextInt(16); int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32); double noise = (noiseGen.noise(x, z, 0.5D, 2.0D) + 1.0D) / 2.0D; noise = noise < 0 ? 0 : noise > 0.9999D ? 0.9999D : noise; FlowerType flower = FLOWERS[(int) (noise * FLOWERS.length)]; new Flower(flower).generate(world, random, x, y, z); } } }
@Override public void populate(World world, Random random, Chunk source) { if (random.nextInt(32) == 0) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.PUMPKIN); // random facing state.setData(new Pumpkin(FACES[random.nextInt(FACES.length)])); state.update(true); } } } } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); while (world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.AIR && sourceY > 0) { sourceY--; } for (int j = 0; j < 10; j++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (y >= 0 && y <= 255 && world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.STATIONARY_WATER) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.WATER_LILY); state.setData(new MaterialData(Material.WATER_LILY)); state.update(true); } } } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); Block sourceBlock = world .getBlockAt(sourceX, world.getHighestBlockYAt(sourceX, sourceZ), sourceZ); BiFunction<Random, BlockStateDelegate, ? extends GenericTree> ctor = getRandomTree(random, trees); if (ctor != null) { BlockStateDelegate delegate = new BlockStateDelegate(); GenericTree tree; try { tree = ctor.apply(random, delegate); } catch (Exception ex) { tree = new GenericTree(random, delegate); } if (tree.generate(sourceBlock.getLocation())) { delegate.updateBlockStates(); } } }
@Override public void decorate(World world, Random random, Chunk source) { if (random.nextInt(1000) == 0) { int x = (source.getX() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16); int y = world.getHighestBlockYAt(x, z); GlowDesertWell well = new GlowDesertWell(new Location(world, x, y, z)); BlockStateDelegate delegate = new BlockStateDelegate(); if (well.generate(world, random, new StructureBoundingBox(new Vector(x - 15, 1, z - 15), new Vector(x + 15, 511, z + 15)), delegate)) { delegate.updateBlockStates(); } } } }
@Override public void populateOnGround(World world, Random random, Chunk chunk) { int sourceX = chunk.getX() << 4; int sourceZ = chunk.getZ() << 4; for (int i = 0; i < 7; i++) { int x = sourceX + random.nextInt(16); int z = sourceZ + random.nextInt(16); int y = world.getHighestBlockYAt(x, z); Block sourceBlock = world.getBlockAt(x, y, z); BlockStateDelegate delegate = new BlockStateDelegate(); JungleBush bush = new JungleBush(random, delegate); if (bush.generate(sourceBlock.getLocation())) { delegate.updateBlockStates(); } } super.populateOnGround(world, random, chunk); melonDecorator.populate(world, random, chunk); } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = world.getHighestBlockYAt(sourceX, sourceZ) - 1; while ( world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.STATIONARY_WATER || world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.WATER && sourceY > 1) { sourceY--; } Material material = world.getBlockAt(sourceX, sourceY, sourceZ).getType(); if (material == Material.STATIONARY_WATER || material == Material.WATER) { new BlockPatch(type, horizRadius, vertRadius, overridables) .generate(world, random, sourceX, sourceY, sourceZ); } } }
/** * Tests if the specified location is valid for a natural spawn position * * @param world The world we're testing on * @param x X-coordinate of the block to test * @param z Z-coordinate of the block to test * @return true if the location is valid, otherwise false */ public boolean canSpawn(World world, int x, int z) { Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z); switch (world.getEnvironment()) { case NETHER: return true; case THE_END: return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA; case NORMAL: default: return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL; } }
/** * Find a a Location obove or below the specified Location, which is on ground. * * <p>The returned Location will be at the center of the block, X and Y wise. * * @param spawn The Location a safe spawn position should be found at. * @return The location to spawn the player at. */ private static Location findSafeSpawnLocation(Location spawn) { World world = spawn.getWorld(); int blockX = spawn.getBlockX(); int blockY = spawn.getBlockY(); int blockZ = spawn.getBlockZ(); int highestY = world.getHighestBlockYAt(blockX, blockZ); int y = blockY; boolean wasPreviousSafe = false; for (; y <= highestY; y++) { Material type = world.getBlockAt(blockX, y, blockZ).getType(); boolean safe = Material.AIR.equals(type); if (wasPreviousSafe && safe) { y--; break; } wasPreviousSafe = safe; } return new Location(world, blockX + 0.5, y, blockZ + 0.5); }
protected void adjustHorizPos(World world) { if (horizPos >= 0) { return; } int sumY = 0; int blockCount = 0; for (int x = boundingBox.getMin().getBlockX(); x <= boundingBox.getMax().getBlockX(); x++) { for (int z = boundingBox.getMin().getBlockZ(); z <= boundingBox.getMax().getBlockZ(); z++) { int y = world.getHighestBlockYAt(x, z); Material type = world.getBlockAt(x, y - 1, z).getType(); while ((type == Material.LEAVES || type == Material.LEAVES_2 || type == Material.LOG || type == Material.LOG_2) && y > 1) { y--; type = world.getBlockAt(x, y - 1, z).getType(); } sumY += Math.max(world.getSeaLevel(), y + 1); blockCount++; } } horizPos = sumY / blockCount; boundingBox.offset(new Vector(0, horizPos - boundingBox.getMin().getBlockY(), 0)); }