Java Code Examples for cn.nukkit.utils.BinaryStream#putByte()

The following examples show how to use cn.nukkit.utils.BinaryStream#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: Chunk.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public byte[] toFastBinary() {
    BinaryStream stream = new BinaryStream(new byte[65536]);
    stream.put(Binary.writeInt(this.x));
    stream.put(Binary.writeInt(this.z));
    stream.put(this.getBlockIdArray());
    stream.put(this.getBlockDataArray());
    stream.put(this.getBlockSkyLightArray());
    stream.put(this.getBlockLightArray());
    for (int height : this.getHeightMapArray()) {
        stream.putByte((byte) height);
    }
    for (int color : this.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
    return stream.getBuffer();
}
 
Example 2
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public byte[] toFastBinary() {
    BinaryStream stream = new BinaryStream(new byte[65536]);
    stream.put(Binary.writeInt(this.getX()));
    stream.put(Binary.writeInt(this.getZ()));
    stream.put(this.getBlockIdArray());
    stream.put(this.getBlockDataArray());
    stream.put(this.getBlockSkyLightArray());
    stream.put(this.getBlockLightArray());
    stream.put(this.getHeightMapArray());
    for (int color : this.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
    return stream.getBuffer();
}
 
Example 3
Source File: CraftingDataPacket.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private static int writeEnchantList(EnchantmentList list, BinaryStream stream) {
    stream.putByte((byte) list.getSize());
    for (int i = 0; i < list.getSize(); ++i) {
        EnchantmentEntry entry = list.getSlot(i);
        stream.putUnsignedVarInt(entry.getCost());
        stream.putUnsignedVarInt(entry.getEnchantments().length);
        for (Enchantment enchantment : entry.getEnchantments()) {
            stream.putUnsignedVarInt(enchantment.getId());
            stream.putUnsignedVarInt(enchantment.getLevel());
        }
        stream.putString(entry.getRandomName());
    }
    return CraftingDataPacket.ENTRY_ENCHANT_LIST;
}
 
Example 4
Source File: EmptyChunkSection.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeTo(BinaryStream stream) {
    stream.putByte((byte) 8);
    stream.putByte((byte) 2);
    EMPTY_STORAGE.writeTo(stream);
    EMPTY_STORAGE.writeTo(stream);
}
 
Example 5
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte[] toFastBinary() {
    BinaryStream stream = new BinaryStream(new byte[65536]);
    stream.put(Binary.writeInt(this.getX()));
    stream.put(Binary.writeInt(this.getZ()));
    stream.put(this.getBlockIdArray());
    stream.put(this.getBlockDataArray());
    stream.put(this.getBlockSkyLightArray());
    stream.put(this.getBlockLightArray());
    stream.put(this.getHeightMapArray());
    stream.put(this.getBiomeIdArray());
    stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
    return stream.getBuffer();
}
 
Example 6
Source File: PalettedBlockStorage.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void writeTo(BinaryStream stream) {
    stream.putByte((byte) getPaletteHeader(bitArray.getVersion(), true));

    for (int word : bitArray.getWords()) {
        stream.putLInt(word);
    }

    stream.putVarInt(palette.size());
    palette.forEach((IntConsumer) stream::putVarInt);
}
 
Example 7
Source File: CraftingDataPacket.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private static int writeEnchantList(EnchantmentList list, BinaryStream stream) {
    stream.putByte((byte) list.getSize());
    for (int i = 0; i < list.getSize(); ++i) {
        EnchantmentEntry entry = list.getSlot(i);
        stream.putUnsignedVarInt(entry.getCost());
        stream.putUnsignedVarInt(entry.getEnchantments().length);
        for (Enchantment enchantment : entry.getEnchantments()) {
            stream.putUnsignedVarInt(enchantment.getId());
            stream.putUnsignedVarInt(enchantment.getLevel());
        }
        stream.putString(entry.getRandomName());
    }
    return CraftingDataPacket.ENTRY_ENCHANT_LIST;
}
 
Example 8
Source File: McRegion.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
    BaseFullChunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
        throw new ChunkException("Invalid Chunk Sent");
    }

    long timestamp = chunk.getChanges();

    BinaryStream stream = new BinaryStream();
    stream.putByte((byte) 0); // subchunk version

    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    stream.put(chunk.getHeightMapArray());
    stream.put(chunk.getBiomeIdArray());

    Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
    stream.putLInt(extra.size());
    if (!extra.isEmpty()) {
        for (Integer key : extra.values()) {
            stream.putLInt(key);
            stream.putLShort(extra.get(key));
        }
    }

    if (!chunk.getBlockEntities().isEmpty()) {
        List<CompoundTag> tagList = new ArrayList<>();

        for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
            if (blockEntity instanceof BlockEntitySpawnable) {
                tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
            }
        }

        try {
            stream.put(NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    return null;
}