@Override public boolean hasNbtData() { return getNbtData() != null; }
@Override public String getNbtId() { CompoundTag nbtData = getNbtData(); if (nbtData == null) { return ""; } Tag idTag = nbtData.getValue().get("id"); if (idTag instanceof StringTag) { return ((StringTag) idTag).getValue(); } else { return ""; } }
/** * Checks whether the type ID and data value are equal. */ @Override public boolean equals(Object o) { if (!(o instanceof BaseBlock)) { if (!hasNbtData() && o instanceof BlockStateHolder) { return Objects.equals(toImmutableState(), ((BlockStateHolder<?>) o).toImmutableState()); } return false; } final BaseBlock otherBlock = (BaseBlock) o; return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbtData(), otherBlock.getNbtData()); }
@Override public <V> BaseBlock with(Property<V> property, V value) { return this.blockState.with(property, value).toBaseBlock(getNbtData()); }
@Override public int hashCode() { int ret = toImmutableState().hashCode() << 3; if (hasNbtData()) { ret += getNbtData().hashCode(); } return ret; }
BlockVector3 point = BlockVector3.at(x0, y0, z0); BaseBlock block = clipboard.getFullBlock(point); if (block.getNbtData() != null) { Map<String, Tag> values = new HashMap<>(); for (Map.Entry<String, Tag> entry : block.getNbtData().getValue().entrySet()) { values.put(entry.getKey(), entry.getValue());
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight); } catch (Exception e) { if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) { logger.warning("Tried to set a corrupt tile entity at " + position.toString()); logger.warning(((BaseBlock) block).getNbtData().toString()); } e.printStackTrace(); Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight); return true; } } else { Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight); return true; } }
if (block != null) { Map<String, Tag> tags = block.getNbtData().getValue(); BlockVector3 tempCuiTemporaryBlock = BlockVector3.at( ((IntTag) tags.get("x")).getValue(),
@Override public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { BlockPos loc = ForgeAdapter.toBlockPos(pos); if (block == null) { // TODO // player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); } else { // TODO // player.sendBlockChange(loc, BukkitAdapter.adapt(block)); if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { player.connection.sendPacket(new SPacketUpdateTileEntity( new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, NBTConverter.toNative(((BaseBlock) block).getNbtData())) ); } } }
NBTTagCompound nativeTag = NBTConverter.toNative(((BaseBlock) block).getNbtData()); nativeTag.setString("id", ((BaseBlock) block).getNbtId()); TileEntityUtils.setTileEntity(world, position, nativeTag);
/** * Transform NBT data in the given block state and return a new instance * if the NBT data needs to be transformed. * * @param state the existing state * @return a new state or the existing one */ private BaseBlock transformNbtData(BaseBlock state) { CompoundTag tag = state.getNbtData(); if (tag != null) { // Handle blocks which store their rotation in NBT if (tag.containsKey("Rot")) { int rot = tag.asInt("Rot"); Direction direction = MCDirections.fromRotation(rot); if (direction != null) { Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize(); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL); if (newDirection != null) { CompoundTagBuilder builder = tag.createBuilder(); builder.putByte("Rot", (byte) MCDirections.toRotation(newDirection)); return state.toBaseBlock(builder.build()); } } } } return state; }
@Override public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()); if (block == null) { player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); } else { player.sendBlockChange(loc, BukkitAdapter.adapt(block)); if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData()); if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) { adapter.sendFakeOP(player); } } } } } }