Java Code Examples for cn.nukkit.nbt.tag.CompoundTag#remove()

The following examples show how to use cn.nukkit.nbt.tag.CompoundTag#remove() . 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: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
Example 2
Source File: BlockEntityFlowerPot.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public BlockEntityFlowerPot(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("item")) {
        nbt.putShort("item", 0);
    }

    if (!nbt.contains("data")) {
        if (nbt.contains("mData")) {
            nbt.putInt("data", nbt.getInt("mData"));
            nbt.remove("mData");
        } else {
            nbt.putInt("data", 0);
        }
    }

    this.namedTag = nbt;
}
 
Example 3
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
Example 4
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
Example 5
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public Item clearCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return this;
    }
    CompoundTag tag = this.getNamedTag();

    if (tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag) {
        tag.remove("BlockEntityTag");
        this.setNamedTag(tag);
    }

    return this;
}
 
Example 6
Source File: ItemArmor.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void clearCustomColor(){
    if(!this.hasCompoundTag()) return;
    CompoundTag tag = this.getNamedTag();
    if(tag.contains("customColor")){
        tag.remove("customColor");
    }
    this.setCompoundTag(tag);
}
 
Example 7
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Item clearCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return this;
    }
    CompoundTag tag = this.getNamedTag();

    if (tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag) {
        tag.remove("BlockEntityTag");
        this.setNamedTag(tag);
    }

    return this;
}
 
Example 8
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Item clearCustomBlockData() {
    if (!this.hasCompoundTag()) {
        return this;
    }
    CompoundTag tag = this.getNamedTag();

    if (tag.contains("BlockEntityTag") && tag.get("BlockEntityTag") instanceof CompoundTag) {
        tag.remove("BlockEntityTag");
        this.setNamedTag(tag);
    }

    return this;
}
 
Example 9
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public byte[] toBinary() {
    CompoundTag nbt = this.getNBT().copy();
    nbt.remove("BiomeColors");

    nbt.putInt("xPos", this.getX());
    nbt.putInt("zPos", this.getZ());

    if (this.isGenerated()) {
        nbt.putByteArray("Blocks", this.getBlockIdArray());
        nbt.putByteArray("Data", this.getBlockDataArray());
        nbt.putByteArray("SkyLight", this.getBlockSkyLightArray());
        nbt.putByteArray("BlockLight", this.getBlockLightArray());
        nbt.putByteArray("Biomes", this.getBiomeIdArray());

        int[] heightInts = new int[256];
        byte[] heightBytes = this.getHeightMapArray();
        for (int i = 0; i < heightInts.length; i++) {
            heightInts[i] = heightBytes[i] & 0xFF;
        }
        nbt.putIntArray("HeightMap", heightInts);
    }


    ArrayList<CompoundTag> entities = new ArrayList<>();
    for (Entity entity : this.getEntities().values()) {
        if (!(entity instanceof Player) && !entity.closed) {
            entity.saveNBT();
            entities.add(entity.namedTag);
        }
    }
    ListTag<CompoundTag> entityListTag = new ListTag<>("Entities");
    entityListTag.setAll(entities);
    nbt.putList(entityListTag);

    ArrayList<CompoundTag> tiles = new ArrayList<>();
    for (BlockEntity blockEntity : this.getBlockEntities().values()) {
        blockEntity.saveNBT();
        tiles.add(blockEntity.namedTag);
    }
    ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities");
    tileListTag.setAll(tiles);
    nbt.putList(tileListTag);

    BinaryStream extraData = new BinaryStream();
    Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray();
    extraData.putInt(extraDataArray.size());
    for (Integer key : extraDataArray.keySet()) {
        extraData.putInt(key);
        extraData.putShort(extraDataArray.get(key));
    }

    nbt.putByteArray("ExtraData", extraData.getBuffer());

    CompoundTag chunk = new CompoundTag("");
    chunk.putCompound("Level", nbt);

    try {
        return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}