Refine search
@Override public boolean generate(World world, Random random, int x, int y, int z) { if (!world.getBlockAt(x, y, z).isEmpty()) { return false; Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN); boolean adjacentWater = false; for (BlockFace face : FACES) { Material blockType = block.getRelative(face).getType(); if (blockType == Material.STATIONARY_WATER || blockType == Material.WATER) { adjacentWater = true; return false; for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) { block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN); if (block.getType() == Material.SUGAR_CANE_BLOCK || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState() .getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) { Block caneBlock = block.getRelative(BlockFace.UP); BlockState state = caneBlock.getState(); state.setType(Material.SUGAR_CANE_BLOCK); state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK)); state.update(true);
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())); } } } } } }
/** * Checks whether this tree can grow on top of the given block. * @param soil the block we're growing on * @return true if this tree can grow on the type of block below it; false otherwise */ public boolean canPlaceOn(BlockState soil) { return soil.getType() == Material.GRASS || soil.getType() == Material.DIRT || soil.getType() == Material.SOIL; }
@Override public void populate(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.getSeaLevel() << 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.MELON_BLOCK); state.setData(new MaterialData(Material.MELON_BLOCK)); state.update(true); } } } }
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; } } } } } }
int y = sourceY + random.nextInt(4) - random.nextInt(4); Block block = world.getBlockAt(x, y, z); Block blockBelow = world.getBlockAt(x, y - 1, z); if (y < 255 && block.getType() == Material.AIR) { boolean canPlaceShroom; switch (blockBelow.getType()) { case MYCEL: canPlaceShroom = true; break; case GRASS: canPlaceShroom = (block.getLightLevel() < 13); break; case DIRT: MaterialData data = blockBelow.getState().getData(); if (data instanceof Dirt) { canPlaceShroom = (((Dirt) data).getType() == DirtType.PODZOL BlockState state = block.getState(); state.setType(type); state.setData(new MaterialData(type)); state.update(true);
/** * Populates a container with random items. * * @param random the PRNG to use * @param state the block state for a container block * @param maxStacks the maximum number of slots to fill * @return true if successful (currently always true) */ public boolean fillContainer(Random random, BlockState state, int maxStacks) { if (state.getBlock().getState() instanceof InventoryHolder) { Inventory inventory = ((InventoryHolder) state.getBlock().getState()).getInventory(); int size = inventory.getSize(); for (int i = 0; i < maxStacks; i++) { RandomAmountItem item = getRandomItem(random); if (item != null) { for (ItemStack stack : item.getItemStacks(random)) { // slot can be overriden hence maxStacks can be less than what's expected inventory.setItem(random.nextInt(size), stack); } } } } else { throw new IllegalArgumentException("Bad container type"); } return true; }
} else if (!builder.getBlockState(new Vector(x, y - 1, z)).getType() .isSolid()) { } else if (state.getType().isSolid()) { int x = random.nextInt((radiusX << 1) - 1) + 1; int z = random.nextInt((radiusZ << 1) - 1) + 1; if (builder.getBlockState(new Vector(x, 1, z)).getType() == Material.AIR) { BlockFace face = null; int solidBlocksCount = 0; if (builder.getBlockState(new Vector(x - 1, 1, z)).getType() == Material.COBBLESTONE) { solidBlocksCount++; face = BlockFace.EAST; if (builder.getBlockState(new Vector(x + 1, 1, z)).getType() == Material.COBBLESTONE) { solidBlocksCount++; face = BlockFace.WEST; if (builder.getBlockState(new Vector(x, 1, z - 1)).getType() == Material.COBBLESTONE) { solidBlocksCount++; face = BlockFace.SOUTH; if (builder.getBlockState(new Vector(x, 1, z + 1)).getType() == Material.COBBLESTONE) { solidBlocksCount++;
@Override public boolean generate(World world, Random random, int blockX, int blockY, int blockZ) { Location l = new Location(world, blockX, blockY, blockZ); while ((l.getBlock().getType() == Material.AIR || l.getBlock().getType() == Material.LEAVES) && blockY > 0) { l.subtract(0, 1, 0); if (!canPlaceOn(l.getBlock().getRelative(BlockFace.DOWN).getState())) { return false; for (int z = blockZ - radius; z <= blockZ + radius; z++) { if ((Math.abs(x - l.getBlockX()) != radius || Math.abs(z - l.getBlockZ()) != radius || random.nextBoolean()) && !delegate.getBlockState(world, x, y, z).getType().isSolid()) { delegate .setTypeAndRawData(world, x, y, z, Material.LEAVES, leavesType);
@EventHandler(priority = EventPriority.HIGH) public void onStructureGrow(StructureGrowEvent e) { for (BlockState state : e.getBlocks()) { Block newBlock = state.getBlock(); if (shopUtils.isShop(newBlock.getLocation()) || shopUtils.isShop(newBlock.getRelative(BlockFace.DOWN).getLocation())) { e.setCancelled(true); } } }
@EventHandler(ignoreCancelled = true) public void onEntityBlockForm(EntityBlockFormEvent event) { if (event.getEntity() instanceof Player) { // should just be frostwalker...other uses of EntityBlockForm are in BlockListener Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getEntity()), event.getBlock().getLocation(), event.getNewState().getType())); } }
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; }
@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); } } } }
@EventHandler(ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { Cause cause = create(event.getBlock()); Block dispenserBlock = event.getBlock(); ItemStack item = event.getItem(); MaterialData materialData = dispenserBlock.getState().getData(); Events.fireToCancel(event, new UseItemEvent(event, cause, dispenserBlock.getWorld(), item)); // Simulate right click event as players have it if (materialData instanceof Dispenser) { Dispenser dispenser = (Dispenser) materialData; Block placed = dispenserBlock.getRelative(dispenser.getFacing()); Block clicked = placed.getRelative(dispenser.getFacing()); handleBlockRightClick(event, cause, item, clicked, dispenser.getFacing().getOppositeFace(), placed); } }
@EventHandler(ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (event instanceof BlockMultiPlaceEvent) return; BlockState previousState = event.getBlockReplacedState(); // Some blocks, like tall grass and fire, get replaced if (previousState.getType() != Material.AIR) { Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType())); } if (!event.isCancelled()) { ItemStack itemStack = new ItemStack(event.getBlockPlaced().getType(), 1); Events.fireToCancel(event, new UseItemEvent(event, create(event.getPlayer()), event.getPlayer().getWorld(), itemStack)); } if (!event.isCancelled()) { Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock())); } if (event.isCancelled()) { playDenyEffect(event.getPlayer(), event.getBlockPlaced().getLocation().add(0.5, 0.5, 0.5)); } }
public void repair() { if (getWorld().getBlockAt(getX(), getY(), getZ()).getState().getData() instanceof Door) return; Block b = getWorld().getBlockAt(x,y,z); if (b.getType() == Material.AIR) b.setType(Material.STONE); super.repair(); other.getBlock().setBlockData(other.getBlockData()); } }
/** * Revert the temp fire at the location if any is there. * * @param location The Location */ public static void revertTempFire(final Location location) { if (!TEMP_FIRE.containsKey(location)) { return; } final Information info = TEMP_FIRE.get(location); if (info.getLocation().getBlock().getType() != Material.FIRE && info.getLocation().getBlock().getType() != Material.AIR) { if (info.getState().getType() == Material.RED_ROSE || info.getState().getType() == Material.YELLOW_FLOWER) { final ItemStack itemStack = new ItemStack(info.getState().getData().getItemType(), 1, info.getState().getRawData()); info.getState().getBlock().getWorld().dropItemNaturally(info.getLocation(), itemStack); } } else { info.getBlock().setType(info.getState().getType()); info.getBlock().setData(info.getState().getRawData()); } TEMP_FIRE.remove(location); }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); if (!shouldIncreaseBeTakenIntoAccountNoPermissions(player)) { return; } Block block = event.getBlock(); MultipleAchievements category = MultipleAchievements.PLACES; String blockName = block.getType().name().toLowerCase(); if (!player.hasPermission(category.toPermName() + '.' + blockName)) { return; } Set<String> foundAchievements = findAchievementsByCategoryAndName( category, blockName + ':' + block.getState().getData().toItemStack(0).getDurability()); foundAchievements.addAll(findAchievementsByCategoryAndName(category, blockName)); foundAchievements.forEach(achievement -> updateStatisticAndAwardAchievementsIfAvailable(player, category, achievement, 1)); } }
@EventHandler(ignoreCancelled = true) public void onBlockMultiPlace(BlockMultiPlaceEvent event) { List<Block> blocks = new ArrayList<>(); for (BlockState bs : event.getReplacedBlockStates()) { blocks.add(bs.getBlock()); } Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock().getWorld(), blocks, event.getBlock().getType())); }
/** * Sets the given block to a container and fills it with random items. * * @param pos a point relative to this structure's root point * @param random the PRNG to use * @param content the distribution to draw items from * @param container the container to place * @param maxStacks the maximum number of slots to fill * @return true if the container was placed and filled; false if {@code pos} is outside the * builder's bounding box or {@link RandomItemsContent#fillContainer(Random, BlockState, * int)} fails */ public boolean createRandomItemsContainer(Vector pos, Random random, RandomItemsContent content, DirectionalContainer container, int maxStacks) { Vector vec = translate(pos); if (boundingBox.isVectorInside(vec)) { BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()) .getState(); delegate.backupBlockState(state.getBlock()); state.setType(container.getItemType()); state.setData(container); state.update(true); return content.fillContainer(random, state, maxStacks); } return false; }