Java Code Examples for com.sk89q.worldedit.blocks.BaseBlock#getNbtData()

The following examples show how to use com.sk89q.worldedit.blocks.BaseBlock#getNbtData() . 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: ProcessedWEExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
    CompoundTag nbt = block.getNbtData();
    if (nbt != null) {
        if (!limit.MAX_BLOCKSTATES()) {
            WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
            return false;
        } else {
            if (!limit.MAX_CHANGES()) {
                WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
                return false;
            }
            return extent.setBlock(x, y, z, block);
        }
    }
    if (!limit.MAX_CHANGES()) {
        WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
        return false;
    } else {
        return extent.setBlock(x, y, z, block);
    }
}
 
Example 2
Source File: DiskOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) {
    try {
        int index = (HEADER_SIZE) + (getIndex(x, y, z) << 1);
        final int id = block.getId();
        final int data = block.getData();
        int combined = (id << 4) + data;
        mbb.putChar(index, (char) combined);
        CompoundTag tile = block.getNbtData();
        if (tile != null) {
            setTile(x, y, z, tile);
        }
        return true;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 4
Source File: FaweAdapter_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 5
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 6
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 7
Source File: BukkitQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CompoundTag getTileEntity(ChunkSnapshot chunk, int x, int y, int z) {
    if (getAdapter() == null) {
        return null;
    }
    Location loc = new Location(getWorld(), x, y, z);
    BaseBlock block = getAdapter().getBlock(loc);
    return block != null ? block.getNbtData() : null;
}
 
Example 8
Source File: FaweAdapter_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight) {
    World craftWorld = location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte) block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null) {
        try {
            Object nmsWorld = getHandleWorld.invoke(craftWorld);
            Object tileEntity = getTileEntity(nmsWorld, x, y, z);
            if (tileEntity != null) {
                Object tag = fromNative(nativeTag);

                setNBTTagCompound.invoke(tag, "x", newNBTTagInt.newInstance(x));
                setNBTTagCompound.invoke(tag, "y", newNBTTagInt.newInstance(y));
                setNBTTagCompound.invoke(tag, "z", newNBTTagInt.newInstance(z));
                readTagIntoTileEntity.invoke(tileEntity, tag); // Load data
            }
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    return changed;
}
 
Example 9
Source File: FaweChangeSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void add(int x, int y, int z, int combinedFrom, BaseBlock to) {
    try {
        if (to.hasNbtData()) {
            CompoundTag nbt = to.getNbtData();
            MainUtil.setPosition(nbt, x, y, z);
            addTileCreate(nbt);
        }
        int combinedTo = (to.getId() << 4) + to.getData();
        add(x, y, z, combinedFrom, combinedTo);

    } catch (Exception e) {
        MainUtil.handleError(e);
    }
}
 
Example 10
Source File: CPUOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(int index, BaseBlock block) {
    int id = block.getId();
    setId(index, id);
    setData(index, block.getData());
    if (id >= 256) {
        setAdd(index, (id >> 8));
    }
    CompoundTag tile = block.getNbtData();
    if (tile != null) {
        setTile(index, tile);
    }
    return true;
}
 
Example 11
Source File: MemoryOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(int index, BaseBlock block) {
    int id = block.getId();
    setId(index, id);
    if (id >= 256) {
        setAdd(index, (id >> 8));
    }
    setData(index, block.getData());
    CompoundTag tile = block.getNbtData();
    if (tile != null) {
        setTile(index, tile);
    }
    return true;
}
 
Example 12
Source File: ExtentBlockCopy.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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) {
                Vector applyAbsolute = transform.apply(direction.toVector());
                Vector applyOrigin = transform.apply(Vector.ZERO);
                applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
                applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
                applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());

                Direction newDirection = Direction.findClosest(applyAbsolute, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL);

                if (newDirection != null) {
                    Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
                    values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
                }
            }
        }
    }
    return state;
}
 
Example 13
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean clearContainerBlockContents(Vector pos) {
    BaseBlock block = getBlock(pos);
    CompoundTag nbt = block.getNbtData();
    if (nbt != null) {
        if (nbt.containsKey("items")) {
            block.setNbtData(null);
            return setBlock(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), block);
        }
    }
    return false;
}
 
Example 14
Source File: SchematicWriter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run(int x, int y, int z, BaseBlock block) {
    if (this.x == x - 1 && this.y == y && this.z == z) {
        this.x++;
        index++;
    } else {
        index = yarea[this.y = y] + zwidth[this.z = z] + (this.x = x);
    }
    int id = block.getId();
    blocks[index] = (byte) id;
    if (FaweCache.hasData(id)) {
        blockData[index] = (byte) block.getData();
        if (id > 255) {
            if (addBlocks == null) { // Lazily create section
                addBlocks = new byte[((blocks.length + 1) >> 1)];
            }
            addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? addBlocks[index >> 1] & 0xF0 | (id >> 8) & 0xF : addBlocks[index >> 1] & 0xF | ((id >> 8) & 0xF) << 4);
        }
    }
    CompoundTag rawTag = block.getNbtData();
    if (rawTag != null) {
        Map<String, Tag> values = ReflectionUtils.getMap(rawTag.getValue());
        values.put("id", new StringTag(block.getNbtId()));
        values.put("x", new IntTag(x));
        values.put("y", new IntTag(y));
        values.put("z", new IntTag(z));
        tileEntities.add(rawTag);
    }
}