Search in sources :

Example 1 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class StartGamePacket method encode.

@Override
public void encode() {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeInt(this.seed);
        writer.writeByte(this.dimension);
        writer.writeInt(this.generator);
        writer.writeInt(this.gamemode);
        writer.writeLong(this.eid);
        writer.writeInt(this.spawnX);
        writer.writeInt(this.spawnY);
        writer.writeInt(this.spawnZ);
        writer.writeFloat(this.x);
        writer.writeFloat(this.y + 1.62f);
        writer.writeFloat(this.z);
        writer.writeByte((byte) 0);
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class UpdateBlockPacket method encode.

@Override
public void encode() {
    setShouldSendImmidate(true);
    try {
        setChannel(NetworkChannel.CHANNEL_BLOCKS);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        if (this.records == null) {
            writer.writeInt(0);
        } else {
            writer.writeInt(this.records.length);
            for (UpdateBlockRecord rec : this.records) {
                writer.writeInt(rec.x);
                writer.writeInt(rec.z);
                writer.writeByte(rec.y);
                writer.writeByte(rec.block);
                writer.writeByte((byte) (rec.flags << 4 | rec.meta));
            }
        }
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class WindowDataPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_PRIORITY);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeByte(this.windowID);
        writer.writeShort(this.property);
        writer.writeShort(this.value);
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 4 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class WindowItemsPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_PRIORITY);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeByte(this.windowID);
        writer.writeShort((short) (this.slots.length & 0xFFFF));
        for (PEInventorySlot slot : this.slots) {
            PEInventorySlot.writeSlot(writer, slot);
        }
        if (windowID == PEWindowConstantID.PLAYER_INVENTORY && this.hotbar.length > 0) {
            writer.writeShort((short) (this.hotbar.length & 0xFFFF));
            for (int slot : this.hotbar) {
                writer.writeInt(slot);
            }
        } else {
            writer.writeShort((short) 0);
        }
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PEInventorySlot(org.dragonet.inventory.PEInventorySlot)

Example 5 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class WindowOpenPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_PRIORITY);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeByte(this.windowID);
        writer.writeByte(this.type);
        writer.writeShort(this.slots);
        writer.writeInt(this.x);
        writer.writeInt(this.y);
        writer.writeInt(this.z);
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)39 IOException (java.io.IOException)39 PEBinaryWriter (org.dragonet.utilities.io.PEBinaryWriter)39 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Deflater (java.util.zip.Deflater)1 Enchantment (org.bukkit.enchantments.Enchantment)1 FurnaceRecipe (org.bukkit.inventory.FurnaceRecipe)1 ItemStack (org.bukkit.inventory.ItemStack)1 Recipe (org.bukkit.inventory.Recipe)1 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)1 ShapelessRecipe (org.bukkit.inventory.ShapelessRecipe)1 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)1