public BlockMultiPlaceEvent(List<BlockState> states, Block clicked, ItemStack itemInHand, Player thePlayer, boolean canBuild) { super(states.get(0).getBlock(), states.get(0), clicked, itemInHand, thePlayer, canBuild); this.states = ImmutableList.copyOf(states); }
public void repair() { if (getWorld().getBlockAt(getX(), getY(), getZ()).getState().getData() instanceof Bed) return; super.repair(); other.getBlock().setBlockData(other.getBlockData()); } }
/** * 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; }
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()); } }
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())); } } } } } }
if (!TerrainObject.killPlantAbove(state.getBlock())) {
state.setType(type); state.update(true); new PulseTask((GlowBlock) state.getBlock(), true, 1, true).startPulseTask();
/** * 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; }
/** * Sets the given block to a spawner for the given entity type. * * @param pos a point relative to this structure's root point * @param entityType the type of entity the spawner will spawn */ public void createMobSpawner(Vector pos, EntityType entityType) { 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(Material.MOB_SPAWNER); state.update(true); state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState(); if (state instanceof CreatureSpawner) { ((CreatureSpawner) state).setSpawnedType(entityType); } } }
@Override public Block apply(@Nullable BlockState blockState) { return blockState != null ? blockState.getBlock() : null; }
@Override public MCBlock getBlock() { return new BukkitMCBlock(bs.getBlock()); }
@SuppressWarnings("deprecation") public void addPlacedBlock(Block placeBlock, BlockState replacedBlock) { this.placedBlocks.add(placeBlock); if (replacedBlock != null) { if (replacedBlock.getData() instanceof Directional) { this.breakedBlockFace.put(replacedBlock.getBlock(), ((Directional) replacedBlock.getData()).getFacing()); } this.breakedBlockTypes.put(replacedBlock.getBlock(), replacedBlock.getTypeId()); this.breakedBlockData.put(replacedBlock.getBlock(), replacedBlock.getData().getData()); this.breakedBlocks.add(replacedBlock.getBlock()); } }
private int getSignCount(Sign s, BlockFace direction) { int i = 1; BlockState state = s.getBlock().getState(); while ((state = state.getBlock().getRelative(direction).getState()) instanceof Sign) i++; return i; }
public RepairableBed(BlockState state) { super(state); other = state.getBlock().getRelative(((Bed) state.getData()).getFacing()).getState(); }
@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())); }
@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(priority = EventPriority.HIGH) public void onBlockSpread(BlockSpreadEvent e) { Block newBlock = e.getNewState().getBlock(); if (shopUtils.isShop(newBlock.getLocation()) || shopUtils.isShop(newBlock.getRelative(BlockFace.DOWN).getLocation())) { e.setCancelled(true); } }
@EventHandler(ignoreCancelled = true) public void onInventoryOpen(InventoryOpenEvent event) { InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof BlockState) { Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), ((BlockState) holder).getBlock())); } else if (holder instanceof Entity) { if (!(holder instanceof Player)) { Events.fireToCancel(event, new UseEntityEvent(event, create(event.getPlayer()), (Entity) holder)); } } }
@EventHandler(priority = EventPriority.HIGH) public void onMultiBlockPlace(BlockMultiPlaceEvent e) { for (BlockState blockState : e.getReplacedBlockStates()) { Block below = blockState.getBlock().getRelative(BlockFace.DOWN); if (shopUtils.isShop(below.getLocation())) { Shop shop = shopUtils.getShop(below.getLocation()); if (shop.getItem() != null) { shop.getItem().resetForPlayer(e.getPlayer()); } e.setCancelled(true); } } }