private double getYPosition(Vector direction, Vector position, Block block) { return getPosition(direction.getY(), position.getY(), block.getY()); }
@Override protected String disambiguate(Block subject, String metadataKey) { return subject.getWorld() + "," + subject.getX() + "," + subject.getY() + "," + subject .getZ() + ":" + metadataKey; } }
/** * Checks whether the entity is within the specified distance from the block. * * @param entity the entity * @param block the block * @param x maximum distance on x axis * @param y maximum distance on y axis * @param z maximum distance on z axis * @return Whether the entity is within distance */ private boolean isWithinDistance(Entity entity, Block block, int x, int y, int z) { Location loc = entity.getLocation(); return Math.abs(loc.getX() - block.getX()) <= x && Math.abs(loc.getY() - block.getY()) <= y && Math.abs(loc.getZ() - block.getZ()) <= z; } }
public static boolean isRainy(Block block) { return isRainy(block.getBiome(), block.getX(), block.getY(), block.getZ()); }
public static boolean isCold(Block block) { return isCold(block.getBiome(), block.getX(), block.getY(), block.getZ()); }
public static boolean isSnowy(Block block) { return isSnowy(block.getBiome(), block.getX(), block.getY(), block.getZ()); }
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())); } } } } } }
/** * Creates a bounding box that is effectively the entire given block. * @param block the block */ public BlockBoundingBox(Block block) { minCorner.setX(block.getX()); minCorner.setY(block.getY()); minCorner.setZ(block.getZ()); maxCorner.setX(block.getX() + 1); maxCorner.setY(block.getY() + 0.95); maxCorner.setZ(block.getZ() + 1); }
private void setType(Block block, int type, int data) { World world = block.getWorld(); int x = block.getX(); int y = block.getY(); int z = block.getZ(); GlowChunk chunk = (GlowChunk) world.getChunkAt(block); chunk.setType(x & 0xf, z & 0xf, y, type); chunk.setMetaData(x & 0xf, z & 0xf, y, data); } }
@Override public BlockFace getFace(Block block) { for (BlockFace face : BlockFace.values()) { if (x + face.getModX() == block.getX() && y + face.getModY() == block.getY() && z + face.getModZ() == block.getZ()) { return face; } } return null; }
if (action == Action.LEFT_CLICK_BLOCK) { final Block clickedBlock = event.getClickedBlock(); final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ()); final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
private static String toBlockString(List<Block> blocks) { StringBuilder builder = new StringBuilder(); boolean first = true; for (Block block : blocks) { if (!first) { builder.append("|"); } builder.append(block.getX()).append(",").append(block.getY()).append(",").append(block.getZ()); first = false; } return builder.toString(); }
/** * (convenience method, uses cache). * * @param block * the block * @return the type id */ public Material getType(final Block block) { return getType(block.getX(), block.getY(), block.getZ()); }
@Override public synchronized void setFalse(Block block) { if (block == null) { return; } setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
@Override public synchronized void setTrue(Block block) { if (block == null) { return; } setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
@Override public synchronized boolean isTrue(Block block) { if (block == null) { return false; } return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void placeBlock(BlockPlaceEvent e) { if (isOnPipe(e.getPlayer())) { Block b = e.getBlockPlaced(); getUserConnection(e.getPlayer()) .get(EntityTracker.class) .addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ())); } } }
@EventHandler public void blockFormEvent(BlockFormEvent event) { if (event.getNewState().getType() == Material.SNOW) { WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID()); if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.SNOW_FORMATION)) { double temperature = climateEngine.getTemperature(); if (event.getBlock().getY() < heightMap.getValue(temperature)) { event.setCancelled(true); } } } }
@EventHandler public void blockFormEvent(BlockFormEvent event) { if (event.getNewState().getType() == Material.ICE) { WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID()); if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.ICE_FORMATION)) { if (event.getBlock().getY() < heightMap.getValue(climateEngine.getTemperature())) { event.setCancelled(true); } } } }