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

The following examples show how to use cn.nukkit.nbt.tag.CompoundTag#putByte() . 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: NBTIO.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag putItemHelper(Item item, Integer slot) {
    CompoundTag tag = new CompoundTag(null)
            .putShort("id", item.getId())
            .putByte("Count", item.getCount())
            .putShort("Damage", item.getDamage());
    if (slot != null) {
        tag.putByte("Slot", slot);
    }

    if (item.hasCompoundTag()) {
        tag.putCompound("tag", item.getNamedTag());
    }

    return tag;
}
 
Example 2
Source File: Anvil.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static ChunkSection createChunkSection(int y) {
    CompoundTag nbt = new CompoundTag();
    nbt.putByte("Y", y);
    nbt.putByteArray("Blocks", new byte[4096]);
    nbt.putByteArray("Data", new byte[2048]);
    byte[] sl = new byte[2048];
    Arrays.fill(sl, (byte) 0xff);
    nbt.putByteArray("SkyLight", sl);
    nbt.putByteArray("BlockLight", new byte[2048]);
    return new ChunkSection(nbt);
}
 
Example 3
Source File: BlockEntityItemFrame.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntityItemFrame(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("Item")) {
        nbt.putCompound("Item", NBTIO.putItemHelper(new ItemBlock(new BlockAir())));
    }
    if (!nbt.contains("ItemRotation")) {
        nbt.putByte("ItemRotation", 0);
    }
    if (!nbt.contains("ItemDropChance")) {
        nbt.putFloat("ItemDropChance", 1.0f);
    }

    this.level.updateComparatorOutputLevel(this);
}
 
Example 4
Source File: BlockEntitySkull.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntitySkull(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("SkullType")) {
        nbt.putByte("SkullType", 0);
    }
    if (!nbt.contains("Rot")) {
        nbt.putByte("Rot", 0);
    }
    this.namedTag = nbt;
}
 
Example 5
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag putItemHelper(Item item, Integer slot) {
    CompoundTag tag = new CompoundTag(null)
            .putShort("id", item.getId())
            .putByte("Count", item.getCount())
            .putShort("Damage", item.getDamage());
    if (slot != null) {
        tag.putByte("Slot", slot);
    }

    if (item.hasCompoundTag()) {
        tag.putCompound("tag", item.getNamedTag());
    }

    return tag;
}
 
Example 6
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag putItemHelper(Item item, Integer slot) {
    CompoundTag tag = new CompoundTag(null)
            .putShort("id", item.getId())
            .putByte("Count", item.getCount())
            .putShort("Damage", item.getDamage());
    if (slot != null) {
        tag.putByte("Slot", slot);
    }

    if (item.hasCompoundTag()) {
        tag.putCompound("tag", item.getNamedTag());
    }

    return tag;
}
 
Example 7
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public byte[] toFastBinary() {
    CompoundTag nbt = this.getNBT().copy();
    nbt.putInt("xPos", this.x);
    nbt.putInt("zPos", this.z);

    nbt.putIntArray("BiomeColors", this.getBiomeColorArray());
    nbt.putIntArray("HeightMap", this.getHeightMapArray());

    for (cn.nukkit.level.format.ChunkSection section : this.getSections()) {
        if (section instanceof EmptyChunkSection) {
            continue;
        }
        CompoundTag s = new CompoundTag(null);
        s.putByte("Y", section.getY());
        s.putByteArray("Blocks", section.getIdArray());
        s.putByteArray("Data", section.getDataArray());
        s.putByteArray("BlockLight", section.getLightArray());
        s.putByteArray("SkyLight", section.getSkyLightArray());
        nbt.getList("Sections", CompoundTag.class).add(s);
    }

    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);

    List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this);

    if (entries != null) {
        ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks");
        long totalTime = this.provider.getLevel().getCurrentTick();

        for (BlockUpdateEntry entry : entries) {
            CompoundTag entryNBT = new CompoundTag()
                    .putString("i", entry.block.getClass().getSimpleName())
                    .putInt("x", entry.pos.getFloorX())
                    .putInt("y", entry.pos.getFloorY())
                    .putInt("z", entry.pos.getFloorZ())
                    .putInt("t", (int) (entry.delay - totalTime))
                    .putInt("p", entry.priority);
            tileTickTag.add(entryNBT);
        }

        nbt.putList(tileTickTag);
    }

    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 NBTIO.write(chunk, ByteOrder.BIG_ENDIAN);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

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

    nbt.putInt("xPos", this.x);
    nbt.putInt("zPos", this.z);

    ListTag<CompoundTag> sectionList = new ListTag<>("Sections");
    for (cn.nukkit.level.format.ChunkSection section : this.getSections()) {
        if (section instanceof EmptyChunkSection) {
            continue;
        }
        CompoundTag s = new CompoundTag(null);
        s.putByte("Y", (section.getY()));
        s.putByteArray("Blocks", section.getIdArray());
        s.putByteArray("Data", section.getDataArray());
        s.putByteArray("BlockLight", section.getLightArray());
        s.putByteArray("SkyLight", section.getSkyLightArray());
        sectionList.add(s);
    }
    nbt.putList(sectionList);

    nbt.putIntArray("BiomeColors", this.getBiomeColorArray());
    nbt.putIntArray("HeightMap", this.getHeightMapArray());

    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);

    List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this);

    if (entries != null) {
        ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks");
        long totalTime = this.provider.getLevel().getCurrentTick();

        for (BlockUpdateEntry entry : entries) {
            CompoundTag entryNBT = new CompoundTag()
                    .putString("i", entry.block.getClass().getSimpleName())
                    .putInt("x", entry.pos.getFloorX())
                    .putInt("y", entry.pos.getFloorY())
                    .putInt("z", entry.pos.getFloorZ())
                    .putInt("t", (int) (entry.delay - totalTime))
                    .putInt("p", entry.priority);
            tileTickTag.add(entryNBT);
        }

        nbt.putList(tileTickTag);
    }

    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);
    }
}
 
Example 9
Source File: BlockBed.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
private void createBlockEntity(Vector3 pos, int color) {
    CompoundTag nbt = BlockEntity.getDefaultCompound(pos, BlockEntity.BED);
    nbt.putByte("color", color);

    new BlockEntityBed(this.level.getChunk(pos.getFloorX() >> 4, pos.getFloorZ() >> 4), nbt);
}
 
Example 10
Source File: BlockBed.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private void createBlockEntity(Vector3 pos, int color) {
    CompoundTag nbt = BlockEntity.getDefaultCompound(pos, BlockEntity.BED);
    nbt.putByte("color", color);

    BlockEntity.createBlockEntity(BlockEntity.BED, this.level.getChunk(pos.getFloorX() >> 4, pos.getFloorZ() >> 4), nbt);
}
 
Example 11
Source File: BlockBed.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private void createBlockEntity(Vector3 pos, int color) {
    CompoundTag nbt = BlockEntity.getDefaultCompound(pos, BlockEntity.BED);
    nbt.putByte("color", color);

    BlockEntity.createBlockEntity(BlockEntity.BED, this.level.getChunk(pos.getFloorX() >> 4, pos.getFloorZ() >> 4), nbt);
}