Java Code Examples for org.bukkit.block.Block#setBlockData()
The following examples show how to use
org.bukkit.block.Block#setBlockData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public boolean setSignFacing(Block block, BlockFace facing) { if (block == null || facing == null) { return false; } BlockState blockState = block.getState(); if (blockState == null) { return false; } BlockData blockData = blockState.getBlockData(); if (blockData == null) { return false; } if(blockData instanceof WallSign) { ((WallSign) blockData).setFacing(facing); } else if(blockData instanceof Sign) { ((Sign) blockData).setRotation(facing); } else { return false; } block.setBlockData(blockData); return true; }
Example 2
Source File: CropGrowthAccelerator.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private boolean grow(Block machine, BlockMenu inv, Block crop) { Ageable ageable = (Ageable) crop.getBlockData(); if (ageable.getAge() < ageable.getMaximumAge()) { for (int slot : getInputSlots()) { if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) { ChargableBlock.addCharge(machine, -getEnergyConsumption()); inv.consumeItem(slot); ageable.setAge(ageable.getAge() + 1); crop.setBlockData(ageable); crop.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, crop.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F); return true; } } } return false; }
Example 3
Source File: InfernalBonemeal.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { Optional<Block> block = e.getClickedBlock(); e.setUseBlock(Result.DENY); if (block.isPresent()) { Block b = block.get(); if (b.getType() == Material.NETHER_WART) { Ageable ageable = (Ageable) b.getBlockData(); if (ageable.getAge() < ageable.getMaximumAge()) { ageable.setAge(ageable.getMaximumAge()); b.setBlockData(ageable); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); if (e.getPlayer().getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(e.getItem(), false); } } } } }; }
Example 4
Source File: ProgrammableAndroid.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
protected void rotate(Block b, int mod) { BlockFace current = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation")); int index = POSSIBLE_ROTATIONS.indexOf(current) + mod; if (index == POSSIBLE_ROTATIONS.size()) { index = 0; } else if (index < 0) { index = POSSIBLE_ROTATIONS.size() - 1; } BlockFace rotation = POSSIBLE_ROTATIONS.get(index); Rotatable rotatatable = (Rotatable) b.getBlockData(); rotatatable.setRotation(rotation); b.setBlockData(rotatatable); BlockStorage.addBlockInfo(b, "rotation", rotation.name()); }
Example 5
Source File: TreeGrowthAccelerator.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private boolean grow(Block machine, Block block, BlockMenu inv, Sapling sapling) { for (int slot : getInputSlots()) { if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) { ChargableBlock.addCharge(machine, -ENERGY_CONSUMPTION); sapling.setStage(sapling.getStage() + 1); block.setBlockData(sapling); inv.consumeItem(slot); block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F); return true; } } return false; }
Example 6
Source File: Crucible.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void placeLiquid(Block block, boolean water) { if (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR || block.getType() == Material.VOID_AIR) { block.setType(water ? Material.WATER : Material.LAVA); } else { if (water && block.getBlockData() instanceof Waterlogged) { Waterlogged wl = (Waterlogged) block.getBlockData(); wl.setWaterlogged(true); block.setBlockData(wl, false); block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F); return; } if (BlockStorage.hasBlockInfo(block)) { BlockStorage.clearBlockInfo(block); } } runPostTask(block, water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, 1); }
Example 7
Source File: WorldChangeTracker.java From GiantTrees with GNU General Public License v3.0 | 6 votes |
public void applyChanges(Location refPoint) { Set<WorldChangeKey> touchedChunks = new HashSet<WorldChangeKey>(); for (WorldChange change : changes.values()) { Location changeLoc = refPoint.clone().add(change.location); Block block = changeLoc.getBlock(); block.setType(change.material); BlockData newBlockData = change.blockDataMutator.apply(block.getBlockData()); block.setBlockData(newBlockData, false); touchedChunks.add(new WorldChangeKey(block.getChunk().getX(), -1, block.getChunk().getZ())); } for (WorldChangeKey chunkKey : touchedChunks) { refPoint.getWorld().refreshChunk(chunkKey.x, chunkKey.z); } }
Example 8
Source File: LumberAxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void stripLog(Block b) { b.getWorld().playSound(b.getLocation(), Sound.ITEM_AXE_STRIP, 1, 1); Axis axis = ((Orientable) b.getBlockData()).getAxis(); b.setType(Material.valueOf("STRIPPED_" + b.getType().name())); Orientable orientable = (Orientable) b.getBlockData(); orientable.setAxis(axis); b.setBlockData(orientable); }
Example 9
Source File: EffToggle.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(final Event e) { if (!flattening) { executeLegacy(e); return; } // 1.13 and newer: use BlockData for (Block b : blocks.getArray(e)) { BlockData data = b.getBlockData(); if (toggle == -1) { if (data instanceof Openable) ((Openable) data).setOpen(false); else if (data instanceof Powerable) ((Powerable) data).setPowered(false); } else if (toggle == 1) { if (data instanceof Openable) ((Openable) data).setOpen(true); else if (data instanceof Powerable) ((Powerable) data).setPowered(true); } else { if (data instanceof Openable) // open = NOT was open ((Openable) data).setOpen(!((Openable) data).isOpen()); else if (data instanceof Powerable) // power = NOT power ((Powerable) data).setPowered(!((Powerable) data).isPowered()); } b.setBlockData(data); } }
Example 10
Source File: v1_13_R2.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockFast(Block block, int blockId, byte data) { BlockState state = block.getState(); if (state.getType().name().endsWith("AIR") && blockId == 0) return; if (state instanceof InventoryHolder) { ((InventoryHolder) state).getInventory().clear(); } XMaterial material = XMaterial.requestOldXMaterial(blockId, (byte) 0); if (material != null && material.parseMaterial() != null) { block.setBlockData(IridiumSkyblock.getInstance().fromLegacy(material.parseMaterial(), data), false); } }
Example 11
Source File: v1_13_R1.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockFast(Block block, int blockId, byte data) { BlockState state = block.getState(); if (state.getType().name().endsWith("AIR") && blockId == 0) return; if (state instanceof InventoryHolder) { ((InventoryHolder) state).getInventory().clear(); } XMaterial material = XMaterial.requestOldXMaterial(blockId, (byte) 0); if (material != null && material.parseMaterial() != null) { block.setBlockData(IridiumSkyblock.getInstance().fromLegacy(material.parseMaterial(), data), false); } }
Example 12
Source File: BlockAdapterBlockData.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void closeDoor(Block block) { if (!(block.getBlockData() instanceof Openable)) { throw new IllegalArgumentException("Block is not Openable"); } Openable data = (Openable) block.getBlockData(); data.setOpen(false); block.setBlockData(data); }
Example 13
Source File: BlockAdapterBlockData.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void setFacing(Block block, BlockFace facing) { BlockData data = block.getBlockData(); if (data instanceof Directional) { ((Directional) data).setFacing(facing); } else if (data instanceof Rotatable) { ((Rotatable) data).setRotation(facing); } else { throw new IllegalArgumentException("Block is not Directional or Rotatable"); } block.setBlockData(data, false); }
Example 14
Source File: BlockAdapterBlockData.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void setAxis(Block block, boolean z) { if (!(block.getBlockData() instanceof Orientable)) { throw new IllegalArgumentException("Block is not Orientable"); } Orientable data = (Orientable) block.getBlockData(); data.setAxis(z ? Axis.Z : Axis.X); block.setBlockData(data, false); }
Example 15
Source File: VersionHelperLatest.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public void toggleDoor(Block b) { if (b.getBlockData() instanceof Openable) { Openable openable = (Openable) b.getBlockData(); openable.setOpen(!openable.isOpen()); b.setBlockData(openable); } }
Example 16
Source File: FarmerAndroid.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override protected void farm(BlockMenu menu, Block block) { if (isFullGrown(block)) { ItemStack drop = getDropFromCrop(block.getType()); if (drop != null && menu.fits(drop, getOutputSlots())) { menu.pushItem(drop, getOutputSlots()); Ageable ageable = (Ageable) block.getBlockData(); ageable.setAge(0); block.setBlockData(ageable); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType()); } } }
Example 17
Source File: v1_15_R1.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockFast(Block block, int blockId, byte data) { BlockState state = block.getState(); if (state.getType().name().endsWith("AIR") && blockId == 0) return; if (state instanceof InventoryHolder) { ((InventoryHolder) state).getInventory().clear(); } XMaterial material = XMaterial.requestOldXMaterial(blockId, (byte) 0); if (material != null && material.parseMaterial() != null) { block.setBlockData(IridiumSkyblock.getInstance().fromLegacy(material.parseMaterial(), data), false); } }
Example 18
Source File: v1_16_R1.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockFast(Block block, int blockId, byte data) { BlockState state = block.getState(); if (state.getType().name().endsWith("AIR") && blockId == 0) return; if (state instanceof InventoryHolder) { ((InventoryHolder) state).getInventory().clear(); } XMaterial material = XMaterial.requestOldXMaterial(blockId, (byte) 0); if (material != null && material.parseMaterial() != null) { block.setBlockData(IridiumSkyblock.getInstance().fromLegacy(material.parseMaterial(), data), false); } }
Example 19
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public void setEndPortalFrameOrientation(Block block, BlockFace blockFace) { EndPortalFrame portalFrame = (EndPortalFrame) block.getBlockData(); portalFrame.setFacing(blockFace); block.setBlockData(portalFrame); }
Example 20
Source File: Schematic.java From ExoticGarden with GNU General Public License v3.0 | 4 votes |
public static void pasteSchematic(Location loc, Tree tree) { Schematic schematic; try { schematic = tree.getSchematic(); } catch (IOException e) { ExoticGarden.instance.getLogger().log(Level.WARNING, "Could not paste Schematic for Tree: " + tree.getFruitID() + "_TREE (" + e.getClass().getSimpleName() + ')', e); return; } BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; short[] blocks = schematic.getBlocks(); byte[] blockData = schematic.getData(); short length = schematic.getLength(); short width = schematic.getWidth(); short height = schematic.getHeight(); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; int blockX = x + loc.getBlockX() - length / 2; int blockY = y + loc.getBlockY(); int blockZ = z + loc.getBlockZ() - width / 2; Block block = new Location(loc.getWorld(), blockX, blockY, blockZ).getBlock(); if ((!block.getType().isSolid() && !block.getType().isInteractable() && !MaterialCollections.getAllUnbreakableBlocks().contains(block.getType())) || block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR || org.bukkit.Tag.SAPLINGS.isTagged(block.getType())) { Material material = parseId(blocks[index], blockData[index]); if (material != null) { if (blocks[index] != 0) { block.setType(material); } if (org.bukkit.Tag.LEAVES.isTagged(material)) { if (ThreadLocalRandom.current().nextInt(100) < 25) { BlockStorage.store(block, tree.getItem()); } } else if (material == Material.PLAYER_HEAD) { Rotatable s = (Rotatable) block.getBlockData(); s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]); block.setBlockData(s); SkullBlock.setFromHash(block, tree.getTexture()); BlockStorage.store(block, tree.getFruit()); } } } } } } }