/** * Convenience method for getting the faced Block. * * @return The faced Block */ public Block getToBlock() { if (to == null) { to = block.getRelative(face); } return to; }
private boolean isNearWater(Block block) { for (BlockFace face : SIDES) { switch (block.getRelative(face).getType()) { case WATER: case STATIONARY_WATER: return true; default: break; } } return false; }
/** * Get an immutable list of the blocks which will be moved by the * extending. * * @return Immutable list of the moved blocks. */ public List<Block> getBlocks() { if (blocks == null) { ArrayList<Block> tmp = new ArrayList<Block>(); for (int i = 0; i < this.getLength(); i++) { tmp.add(block.getRelative(getDirection(), i + 1)); } blocks = Collections.unmodifiableList(tmp); } return blocks; }
@Override public boolean canSpawn(World world, int x, int z) { Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN); return block.getType() == Material.ENDER_STONE; }
private boolean hasDownSupport(Block block) { Block down = block.getRelative(BlockFace.DOWN); return down.getType() == Material.CHORUS_PLANT || down.getType() == Material.ENDER_STONE; } }
@Override public boolean canSpawn(World world, int x, int z) { Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN); return block.getType() == Material.NETHERRACK; }
/** * Gets the location where the possible moving block might be if the * retracting piston is sticky. * * @return The possible location of the possibly moving block. */ public Location getRetractLocation() { return getBlock().getRelative(getDirection(), 2).getLocation(); }
/** * Generates up to 64 flowers around the given point. */ @Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { boolean succeeded = false; 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); Block block = world.getBlockAt(x, y, z); if (y < 255 && block.getType() == Material.AIR && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) { block.setType(type); block.setData((byte) data); succeeded = true; } } return succeeded; } }
@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()); }
/** * Removes the grass, shrub, flower or mushroom directly above the given block, if present. Does * not drop an item. * * @param block the block to update * @return true if a plant was removed; false if none was present */ static boolean killPlantAbove(Block block) { Block blockAbove = block.getRelative(BlockFace.UP); Material mat = blockAbove.getType(); if (PLANT_TYPES.contains(mat)) { if (mat == Material.DOUBLE_PLANT) { MaterialData dataAbove = blockAbove.getState().getData(); if (dataAbove instanceof DoublePlant && ((DoublePlant) dataAbove).getSpecies() == DoublePlantSpecies.PLANT_APEX) { blockAbove.getRelative(BlockFace.UP) .setType(Material.AIR); } } blockAbove.setType(Material.AIR); return true; } return false; }
private boolean isPistonExtended(Block block) { // TODO: check direction of piston_extension to make sure that the extension is attached to // piston Block pistonHead = block .getRelative(((PistonBaseMaterial) block.getState().getData()).getFacing()); return pistonHead.getType() == Material.PISTON_EXTENSION; }
/** * 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; } }
@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; } }
@Override public void setOnGround(boolean onGround) { float fallDistance = getFallDistance(); if (onGround && fallDistance > 3f) { float damage = fallDistance - 3f; damage = Math.round(damage); if (damage > 0f) { Material standingType = location.getBlock().getRelative(BlockFace.DOWN).getType(); // todo: only when bouncing if (standingType == Material.SLIME_BLOCK) { damage = 0f; } if (standingType == Material.HAY_BLOCK) { damage *= 0.2f; } damage(damage, DamageCause.FALL); } } super.setOnGround(onGround); }
private void addCocoa(int sourceX, int sourceY, int sourceZ, World world, Random random) { if (height > 5 && random.nextInt(5) == 0) { for (int y = 0; y < 2; y++) { for (BlockFace cocoaFace : COCOA_FACES) { // rotate the 4 trunk faces if (random.nextInt(COCOA_FACES.length - y) == 0) { // higher it is, more chances there is CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)]; Block block = delegate .getBlockState(world, sourceX, sourceY + height - 5 + y, sourceZ) .getBlock().getRelative(cocoaFace); delegate.setTypeAndData(world, block.getX(), block.getY(), block.getZ(), Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace())); } } } } } }
|| block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) { return; int airBlockCount = 0; for (BlockFace face : SIDES) { Block neighbor = block.getRelative(face); if (neighbor.getType() == Material.NETHERRACK) { netherrackBlockCount++;
private boolean canHoldPainting(Location where) { Block block = where.getBlock(); if (block.getType().isSolid()) { return false; } Block behind = block.getRelative(getAttachedFace()); return behind.getType().isSolid(); }
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); } } }
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 pulse() { super.pulse(); if (ticksLived % (20 * 5) == 0) { if (location.getBlock().getRelative(getAttachedFace()).getType() == Material.AIR) { if (EventFactory.getInstance() .callEvent(new HangingBreakEvent(this, RemoveCause.PHYSICS)) .isCancelled()) { return; } world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME)); if (!isEmpty()) { world.dropItemNaturally(location, getItem().clone()); } remove(); } } }