org.bukkit.block.data.BlockData Java Examples
The following examples show how to use
org.bukkit.block.data.BlockData.
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: RainbowTickHandler.java From Slimefun4 with GNU General Public License v3.0 | 7 votes |
@Override public void tick(Block b, SlimefunItem item, Config data) { if (b.getType() == Material.AIR) { // The block was broken, setting the Material now would result in a // duplication glitch return; } if (waterlogged) { BlockData blockData = b.getBlockData(); b.setType(material, true); if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) { Waterlogged block = (Waterlogged) b.getBlockData(); block.setWaterlogged(true); b.setBlockData(block); } } else { b.setType(material, false); } }
Example #2
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public BlockFace getSignFacing(Block block) { if (block == null) { return null; } BlockState blockState = block.getState(); if (blockState == null) { return null; } BlockData blockData = blockState.getBlockData(); if (blockData == null) { return null; } if(blockData instanceof WallSign) { return ((WallSign) blockData).getFacing(); } else if(blockData instanceof Sign) { return ((Sign) blockData).getRotation(); } return null; }
Example #3
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 #4
Source File: BlockStateBlock.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void setBlockData(BlockData data) { if (!IS_RUNNING_1_13) { throw new IllegalStateException("not on 1.13"); } if (delayChanges) { Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() { @Override public void run() { state.getBlock().setBlockData(data); } }); } else { state.setBlockData(data); } }
Example #5
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 #6
Source File: BlockStateBlock.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void setBlockData(BlockData data, boolean applyPhysics) { if (!IS_RUNNING_1_13) { throw new IllegalStateException("not on 1.13"); } if (delayChanges) { Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() { @Override public void run() { state.getBlock().setBlockData(data, applyPhysics); } }); } else { // Cannot apply physics to a block state state.setBlockData(data); } }
Example #7
Source File: DuctListener.java From Transport-Pipes with MIT License | 6 votes |
private void setDirectionalBlockFace(Location b, BlockData bd, Player p) { if (bd instanceof Directional) { Vector dir = new Vector(b.getX() + 0.5d, b.getY() + 0.5d, b.getZ() + 0.5d); dir.subtract(p.getEyeLocation().toVector()); double absX = Math.abs(dir.getX()); double absY = Math.abs(dir.getY()); double absZ = Math.abs(dir.getZ()); if (((Directional) bd).getFaces().contains(BlockFace.UP) && ((Directional) bd).getFaces().contains(BlockFace.DOWN)) { if (absX >= absY && absX >= absZ) { ((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST); } else if (absY >= absX && absY >= absZ) { ((Directional) bd).setFacing(dir.getY() > 0 ? BlockFace.DOWN : BlockFace.UP); } else { ((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH); } } else { if (absX >= absZ) { ((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST); } else { ((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH); } } } }
Example #8
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public Block getSignAttachedTo(Block block) { if (block == null) { return null; } BlockState blockState = block.getState(); if (blockState == null) { return null; } org.bukkit.block.data.BlockData blockData = blockState.getBlockData(); if (blockData == null) { return null; } if(blockData instanceof WallSign) { return block.getRelative(((WallSign) blockData).getFacing().getOppositeFace()); } else if(blockData instanceof Sign) { return block.getRelative(BlockFace.DOWN); } return null; }
Example #9
Source File: StructureUtil.java From Civs with GNU General Public License v3.0 | 6 votes |
private static void setGlass(World world, double x, double y, double z, Map<Location, Color> boundingBox, Material mat, Player player) { if (y < 1 || y >= world.getMaxHeight()) { return; } Location location = new Location(world, x, y, z); Block block = location.getBlock(); if (block.getType() != Material.AIR || block.getRelative(BlockFace.DOWN).getType() == Material.GRASS_PATH || block.getRelative(BlockFace.DOWN).getType() == Material.FARMLAND) { return; } Color color = Color.RED; if (mat == Material.BLUE_STAINED_GLASS) { color = Color.BLUE; } else if (mat == Material.LIME_STAINED_GLASS) { color = Color.GREEN; } BlockData blockData = mat.createBlockData(); boundingBox.put(new Location(world, x, y, z), color); player.sendBlockChange(location, blockData); }
Example #10
Source File: FallingBlockDisguise.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
/** * {@inheritDoc} */ public String toString() { if(VersionHelper.require1_13()) { return String.format("%s; material=%s; %s", super.toString(), ((BlockData)materialData).getAsString(), onlyBlockCoordinates ? "block-coordinates" : "all-coordinates"); } else { return String.format("%s; material=%s:%s; %s", super.toString(), material.name().toLowerCase(Locale.ENGLISH).replace('_', '-'), materialData, onlyBlockCoordinates ? "block-coordinates" : "all-coordinates"); } }
Example #11
Source File: SpigotMiscUtils.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<BlockData> getBlockDataList(Material material) { return CraftMagicNumbers.getBlock(material).getStates().a().stream() .map(CraftBlockData::fromData) .collect(Collectors.toList()); }
Example #12
Source File: MinecartDisguise.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
/** * {@inheritDoc} */ public String toString() { if(VersionHelper.require1_13()) { return String.format("%s; displayed-block=%s", super.toString(), ((BlockData)blockData).getAsString()); } else { return String.format("%s; displayed-block=%s:%s", super.toString(), displayedBlock.name().toLowerCase(Locale.ENGLISH).replace('_', '-'), blockData); } }
Example #13
Source File: AreaEffectCloudDisguise.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
/** * @since 5.8.1 */ public String getParameterStringRepresentation() { Class<?> parameterType = getParameterType(particle); if(parameterType.equals(Color.class)) { return Integer.toString(((Color)parameter).asRGB(), 16); } else if(parameterType.equals(ItemStack.class)) { return ((ItemStack)parameter).getType().name().toLowerCase(Locale.ENGLISH).replace('_', '-'); } else if(parameterType.equals(MaterialData.class)) { return ((MaterialData)parameter).getItemType().name().toLowerCase(Locale.ENGLISH).replace('_', '-'); } else if(VersionHelper.require1_13() && parameterType.equals(BlockData.class)) { return ((BlockData)parameter).getAsString(); } return ""; }
Example #14
Source File: DelayedChangeBlock.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void setBlockData(BlockData data, boolean applyPhysics) { if (newState != null) { newState.setBlockData(data); } else { b.setBlockData(data, applyPhysics); } }
Example #15
Source File: WallMatcher.java From Modern-LWC with MIT License | 5 votes |
/** * Try and match a wall block * * @param block * @param matchingFace * @return */ private Block tryMatchBlock(Block block, BlockFace matchingFace) { byte direction = block.getData(); BlockData blockData = block.getBlockData(); // Blocks such as wall signs or banners if (PROTECTABLES_WALL.contains(block.getType()) && blockData instanceof Directional) { if (((Directional) block.getState().getBlockData()).getFacing() == matchingFace) { return block; } } // Levers, buttons else if (PROTECTABLES_LEVERS_ET_AL.contains(block.getType())) { byte EAST = 0x4; byte WEST = 0x3; byte SOUTH = 0x1; byte NORTH = 0x2; if (matchingFace == BlockFace.EAST && (direction & EAST) == EAST) { return block; } else if (matchingFace == BlockFace.WEST && (direction & WEST) == WEST) { return block; } else if (matchingFace == BlockFace.SOUTH && (direction & SOUTH) == SOUTH) { return block; } else if (matchingFace == BlockFace.NORTH && (direction & NORTH) == NORTH) { return block; } } return null; }
Example #16
Source File: Util.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * Fetches the block which the given sign is attached to * * @param b The block which is attached * @return The block the sign is attached to */ @Nullable public static Block getAttached(@NotNull Block b) { final BlockData blockData = b.getBlockData(); if (blockData instanceof Directional) { final Directional directional = (Directional) blockData; return b.getRelative(directional.getFacing().getOppositeFace()); } else { return null; } }
Example #17
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 #18
Source File: BlockStateBlock.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public BlockData getBlockData() { if (!IS_RUNNING_1_13) { throw new IllegalStateException("not on 1.13"); } return state.getBlockData(); }
Example #19
Source File: EndermanDisguise.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
/** * {@inheritDoc} */ public String toString() { if(VersionHelper.require1_13()) { return String.format("%s; carried-block=%s", super.toString(), ((BlockData)blockData).getAsString()); } else { return String.format("%s; carried-block=%s:%s", super.toString(), carriedBlock.name().toLowerCase(Locale.ENGLISH).replace('_', '-'), blockData); } }
Example #20
Source File: PlayerEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private boolean isLavaSource(BlockData blockData) { if (blockData.getMaterial() == Material.LAVA) { Levelled level = (Levelled) blockData; return level.getLevel() == 0; } return false; }
Example #21
Source File: FarmerAndroid.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean isFullGrown(Block block) { BlockData data = block.getBlockData(); if (!(data instanceof Ageable)) { return false; } Ageable ageable = (Ageable) data; return ageable.getAge() >= ageable.getMaximumAge(); }
Example #22
Source File: Draw3d.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
private UnaryOperator<BlockData> orient(Orientation orientation) { return blockData -> { if (blockData instanceof Orientable) { Orientable orientable = (Orientable) blockData; switch (orientation) { case xMajor: orientable.setAxis(Axis.X); case yMajor: orientable.setAxis(Axis.Z); case zMajor: orientable.setAxis(Axis.Y); } } return blockData; }; }
Example #23
Source File: Draw3d.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
private UnaryOperator<BlockData> persist() { return blockData -> { if (blockData instanceof Leaves) { Leaves leaves = (Leaves) blockData; leaves.setPersistent(true); } return blockData; }; }
Example #24
Source File: JungleVinePopulator.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
private static UnaryOperator<BlockData> orient(BlockFace direction) { return blockData -> { if (blockData instanceof MultipleFacing) { MultipleFacing facing = (MultipleFacing) blockData; facing.setFace(BlockFace.NORTH, false); facing.setFace(BlockFace.SOUTH, false); facing.setFace(BlockFace.EAST, false); facing.setFace(BlockFace.WEST, false); facing.setFace(direction, true); } return blockData; }; }
Example #25
Source File: TileEntityBannerRemapper.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
protected void register(List<Entry<Consumer<NBTCompound>>> list, Material banner, int color) { for (BlockData blockdata : MaterialAPI.getBlockDataList(banner)) { list.add(new ArrayMap.Entry<>(MaterialAPI.getBlockDataNetworkId(blockdata), nbt -> { LegacyBanner.transformBanner(nbt); nbt.setTag(CommonNBT.BANNER_BASE, new NBTInt(color)); })); } }
Example #26
Source File: TileEntitySkullRemapper.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
protected void register(List<Entry<Consumer<NBTCompound>>> list, Material skull, int skulltype) { for (BlockData blockdata : MaterialAPI.getBlockDataList(skull)) { byte rotation = getLegacyData(blockdata); list.add(new Entry<>(MaterialAPI.getBlockDataNetworkId(blockdata), nbt -> { nbt.setTag("SkullType", new NBTByte((byte) skulltype)); nbt.setTag("Rot", new NBTByte(rotation)); })); } }
Example #27
Source File: TileEntityBedRemapper.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
protected void register(List<Entry<Consumer<NBTCompound>>> list, Material bed, int color) { for (BlockData blockdata : MaterialAPI.getBlockDataList(bed)) { list.add(new ArrayMap.Entry<>(MaterialAPI.getBlockDataNetworkId(blockdata), nbt -> { nbt.setTag("color", new NBTInt(color)); })); } }
Example #28
Source File: MaterialAPI.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns all possible block data states for this material * @param material block material * @return all possible block data states */ @SuppressWarnings("deprecation") public static List<BlockData> getBlockDataList(Material material) { if (material.isLegacy()) { throw new IllegalArgumentException(MessageFormat.format("Material {0} is legacy", material)); } if (!material.isBlock()) { throw new IllegalArgumentException(MessageFormat.format("Material {0} is not a block", material)); } return ServerPlatform.get().getMiscUtils().getBlockDataList(material); }
Example #29
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 #30
Source File: Duct.java From Transport-Pipes with MIT License | 4 votes |
public BlockData obfuscatedWith() { return obfuscatedWith; }