@Override public Location getFixedSpawnLocation(World world, Random random) { while (true) { int x = random.nextInt(128) - 64; int y = 128 * 3 / 4; int z = random.nextInt(128) - 64; if (world.getBlockAt(x, y, z).isEmpty()) { while (world.getBlockAt(x, y - 1, z).isEmpty() && y > 0) { y--; } return new Location(world, x, y, z); } } }
@Override public boolean canSpawn(World world, int x, int z) { Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN); return !block.isLiquid() && !block.isEmpty() && !noSpawnFloors.contains(block.getType()); }
@Override public void decorate(World world, Random random, Chunk source) { if (random.nextInt(type == Material.STATIONARY_WATER ? 4 : 8) == 0) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random .nextInt(type == Material.STATIONARY_WATER ? 256 : random.nextInt(248) + 8); if (type == Material.STATIONARY_LAVA && (sourceY >= world.getSeaLevel() || random.nextInt(10) > 0)) { return; } while (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() && sourceY > 5) { sourceY--; } if (sourceY >= 5) { new Lake(type).generate(world, random, sourceX, sourceY, sourceZ); } } } }
@Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { Block thisBlock; do { thisBlock = world.getBlockAt(sourceX, sourceY, sourceZ); sourceY--; } while ((thisBlock.isEmpty() || thisBlock.getType() == Material.LEAVES) && sourceY > 0); sourceY++; boolean succeeded = false; for (int i = 0; i < 128; 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); Block block = world.getBlockAt(x, y, z); Material blockTypeBelow = block.getRelative(BlockFace.DOWN).getType(); if (y < 255 && block.getType() == Material.AIR && ( blockTypeBelow == Material.GRASS || blockTypeBelow == Material.DIRT)) { BlockState state = block.getState(); state.setType(Material.LONG_GRASS); state.setData(grassType); state.update(true); succeeded = true; } } return succeeded; } }
int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1); while (sourceY > 0 && (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEAVES)) { sourceY--; int y = sourceY + random.nextInt(4) - random.nextInt(4); if (world.getBlockAt(x, y, z).isEmpty()) { Block blockBelow = world.getBlockAt(x, y - 1, z); for (Material soil : SOIL_TYPES) {
/** * Generates or extends a cactus, if there is space. */ @Override public boolean generate(World world, Random random, int x, int y, int z) { if (world.getBlockAt(x, y, z).isEmpty()) { int height = random.nextInt(random.nextInt(3) + 1) + 1; for (int n = y; n < y + height; n++) { Block block = world.getBlockAt(x, n, z); Material typeBelow = block.getRelative(BlockFace.DOWN).getType(); if ((typeBelow == Material.SAND || typeBelow == Material.CACTUS) && block.getRelative(BlockFace.UP).isEmpty()) { for (BlockFace face : FACES) { if (block.getRelative(face).getType().isSolid()) { return n > y; } } BlockState state = block.getState(); state.setType(Material.CACTUS); state.setData(new MaterialData(Material.CACTUS)); state.update(true); } } } return true; } }
private void placeBoat(GlowPlayer player, ItemStack holding) { Block targetBlock = player.getTargetBlock((Set<Material>) null, 5); if (targetBlock != null && !targetBlock.isEmpty() && targetBlock.getRelative(BlockFace.UP).isEmpty()) { Location location = targetBlock.getRelative(BlockFace.UP).getLocation(); // center boat on cursor location location.add(0.6875f, 0, 0.6875f); location.setYaw(player.getLocation().getYaw()); Boat boat = targetBlock.getWorld().spawn(location, Boat.class); boat.setWoodType(woodType); if (player.getGameMode() != GameMode.CREATIVE) { player.getInventory().removeItem(holding); } } }
@Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { if (!world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() != Material.ENDER_STONE) {
int airBlockCount = 0; for (BlockFace face : SIDES) { if (block.getRelative(face).isEmpty()) { airBlockCount++;
private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ, World world) { for (int x = -2; x <= 2; x++) { for (int z = -2; z <= 2; z++) { if (Math.abs(x) == 2 && Math.abs(z) == 2) { continue; } for (int y = 2; y >= -3; y--) { Block block = world .getBlockAt(sourceX + x, sourceY + y, sourceZ + z); if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) { BlockState state = block.getState(); state.setType(Material.DIRT); DirtType dirtType = DirtType.PODZOL; if (world.getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z) .getType().isOccluding()) { dirtType = DirtType.NORMAL; } state.setData(new Dirt(dirtType)); state.update(true); } else if (!block.isEmpty() && sourceY + y < sourceY) { break; } } } } } }
@Override public boolean generate(World world, Random random, int x, int y, int z) { if (!world.getBlockAt(x, y, z).isEmpty()) { return false; || block.getType() == Material.SAND) { Block caneBlock = block.getRelative(BlockFace.UP); if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP) .isEmpty()) { return n > 0;
protected void jump() { if (location.getBlock().isLiquid()) { // jump out more when you breach the surface of the liquid if (location.getBlock().getRelative(BlockFace.UP).isEmpty()) { velocity.setY(velocity.getY() + 0.3); } // less jumping in liquid velocity.setY(velocity.getY() + 0.04); } else { // jump normally velocity.setY(velocity.getY() + 0.42); } }
@Override public void handle(GlowSession session, PlayerSwingArmMessage message) { GlowPlayer player = session.getPlayer(); EventFactory eventFactory = EventFactory.getInstance(); Block block = player.getTargetBlock((Set<Material>) null, 6); if (block == null || block.isEmpty()) { if (eventFactory.onPlayerInteract( player, Action.LEFT_CLICK_AIR, message.getHandSlot()).useItemInHand() == Result.DENY) { return; } // todo: item interactions with air } if (!eventFactory.callEvent(new PlayerAnimationEvent(player)).isCancelled()) { // play the animation to others player.playAnimation(message.getHand() == 1 ? EntityAnimation.SWING_OFF_HAND : EntityAnimation.SWING_MAIN_HAND); } } }
break; } else if (!target.isEmpty()) { break;