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; }
break; case DIRT: MaterialData data = blockBelow.getState().getData(); if (data instanceof Dirt) { canPlaceShroom = (((Dirt) data).getType() == DirtType.PODZOL
@Override public void onBlockChanged(GlowBlock block, Material oldType, byte oldData, Material newType, byte newData) { if (newType != Material.AIR) { return; } if (oldType.getData() == Door.class) { Door door = new Door(oldType); door.setData(oldData); if (door.isTopHalf()) { Block b = block.getRelative(BlockFace.DOWN); if (b.getState().getData() instanceof Door) { b.setType(Material.AIR); } } else { Block b = block.getRelative(BlockFace.UP); if (b.getState().getData() instanceof Door) { b.setType(Material.AIR); } } } }
/** * 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; }
MaterialData otherPartData = otherPartState.getData();
@Override public MaterialData getData() { return base.getData(); }
Block sign = world.getBlockAt(signLoc); // Get the block sign.setType(Material.WALL_SIGN); // Set the type to "WALL_SIGN", now it's BlockState is an instance of "Sign" BlockState signState = sign.getState(); // Get the general state if (signState instanceof org.bukkit.block.Sign) { // Make sure the sign block really does have the "Sign" BlockState (this isn't really necessary, more of a double check) org.bukkit.block.Sign signBlock = (org.bukkit.block.Sign) signState; // Note that this is the org.bukkit.block.Sign interface signBlock.setLine(0, "Hello"); // Set the first line signBlock.setLine(1, player.getName()); // Set the second line if (signState.getData() instanceof org.bukkit.material.Sign) { // Now get the "MaterialData" from the BlockState... org.bukkit.material.Sign signMaterialData = (org.bukkit.material.Sign) signState.getData(); // And cast it to org.bukkit.material.Sign signMaterialData.setFacingDirection(BlockFace.WEST); // Use this to change the direction of the sign, in this case WEST (sign is placed + X direction of player) } signBlock.update(); // Update the sign's state }
@SuppressWarnings("deprecation") public void addBreakedBlock(Block bedBlock) { if (bedBlock.getState().getData() instanceof Directional) { this.breakedBlockFace.put(bedBlock, ((Directional) bedBlock.getState().getData()).getFacing()); } this.breakedBlockTypes.put(bedBlock, bedBlock.getTypeId()); this.breakedBlockData.put(bedBlock, bedBlock.getData()); if (bedBlock.getState().getData() instanceof Redstone) { this.breakedBlockPower.put(bedBlock, ((Redstone) bedBlock.getState().getData()).isPowered()); } this.breakedBlocks.add(bedBlock); }
@SuppressWarnings("deprecation") public void addBreakedBlock(Block bedBlock) { if (bedBlock.getState().getData() instanceof Directional) { this.breakedBlockFace.put(bedBlock, ((Directional) bedBlock.getState().getData()).getFacing()); } this.breakedBlockTypes.put(bedBlock, bedBlock.getTypeId()); this.breakedBlockData.put(bedBlock, bedBlock.getData()); if (bedBlock.getState().getData() instanceof Redstone) { this.breakedBlockPower.put(bedBlock, ((Redstone) bedBlock.getState().getData()).isPowered()); } this.breakedBlocks.add(bedBlock); }
@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()); } }
@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 BlockFace getDirection(final Block pistonBlock) { // TODO: Register/store a fetcher thing (DirectionalFromBlock) final MaterialData data = pistonBlock.getState().getData(); if (data instanceof Directional) { Directional directional = (Directional) data; return directional.getFacing(); } return null; }
/** * Opens the door. */ public void open() { BlockState state = block.getState(); ((Door) state.getData()).setOpen(true); state.update(true); }
public RepairableBed(BlockState state) { super(state); other = state.getBlock().getRelative(((Bed) state.getData()).getFacing()).getState(); }
@Override public void run() { if (id != -1 && id != 0 && subId != -1) { org.bukkit.material.Sign sign = (org.bukkit.material.Sign) location.getBlock().getState().getData(); location.getBlock().getRelative(sign.getAttachedFace()).setTypeIdAndData(id, (byte) subId, true); } } });
public RepairableAttachable(BlockState state) { super(state); BlockState attached; if (state.getData() instanceof Attachable) attached = state.getBlock().getRelative(((Attachable) state.getData()).getAttachedFace()).getState(); else attached = state.getBlock().getRelative(BlockFace.DOWN).getState(); x = attached.getX(); y = attached.getY(); z = attached.getZ(); state.getBlock().setType(Material.STONE); }
Block block = ....; BlockState state = block.getState(); PistonBaseMaterial piston = (PistonBaseMaterial)state.getData(); piston.setFacingDirection(BlockFace.NORTH); piston.setFacingDirection(BlockFace.SOUTH); piston.setFacingDirection(BlockFace.WEST); piston.setFacingDirection(BlockFace.EAST); piston.setFacingDirection(BlockFace.UP); piston.setFacingDirection(BlockFace.DOWN); state.setData(piston); state.update();
public void repair() { if (getWorld().getBlockAt(getX(), getY(), getZ()).getState().getData() instanceof Bed) return; super.repair(); other.getBlock().setBlockData(other.getBlockData()); } }
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()); } }