Search in sources :

Example 1 with BiomeConfig

use of com.almuradev.almura.feature.biome.BiomeConfig in project Almura by AlmuraDev.

the class ClientboundBiomeInformationPacket method writeTo.

@Override
public void writeTo(final ChannelBuf buf) {
    final int size = this.biomes.size();
    buf.writeInteger(size);
    if (size > 0) {
        for (final BiomeConfig biomeConfig : this.biomes.values()) {
            ByteBufOutputStream byteBufOutputStream = null;
            ObjectOutputStream objectOutputStream = null;
            try {
                final ByteBuf objBuf = Unpooled.buffer();
                byteBufOutputStream = new ByteBufOutputStream(objBuf);
                objectOutputStream = new ObjectOutputStream(byteBufOutputStream);
                objectOutputStream.writeObject(biomeConfig);
                buf.writeInteger(objBuf.array().length);
                buf.writeBytes(objBuf.array());
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (byteBufOutputStream != null) {
                    try {
                        byteBufOutputStream.close();
                    } catch (IOException ignored) {
                    }
                }
                if (objectOutputStream != null) {
                    try {
                        objectOutputStream.close();
                    } catch (IOException ignored) {
                    }
                }
            }
        }
    }
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) BiomeConfig(com.almuradev.almura.feature.biome.BiomeConfig) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with BiomeConfig

use of com.almuradev.almura.feature.biome.BiomeConfig in project Almura by AlmuraDev.

the class ClientboundBiomeInformationPacket method readFrom.

@Override
public void readFrom(final ChannelBuf buf) {
    final int size = buf.readInteger();
    this.biomes = new HashMap<>(size);
    if (size > 0) {
        for (int i = 0; i < size; i++) {
            final int length = buf.readInteger();
            ByteBufInputStream byteBufInputStream = null;
            ObjectInputStream objectInputStream = null;
            try {
                final ByteBuf buffer = Unpooled.buffer(length);
                buffer.writeBytes(buf.readBytes(length));
                byteBufInputStream = new ByteBufInputStream(buffer, length);
                objectInputStream = new ObjectInputStream(byteBufInputStream);
                final BiomeConfig biomeConfig = (BiomeConfig) objectInputStream.readObject();
                this.biomes.put(biomeConfig.getServerBiomeId(), biomeConfig);
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (byteBufInputStream != null) {
                    try {
                        byteBufInputStream.close();
                    } catch (IOException ignored) {
                    }
                }
                if (objectInputStream != null) {
                    try {
                        objectInputStream.close();
                    } catch (IOException ignored) {
                    }
                }
            }
        }
    }
}
Also used : BiomeConfig(com.almuradev.almura.feature.biome.BiomeConfig) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

BiomeConfig (com.almuradev.almura.feature.biome.BiomeConfig)2 ByteBuf (io.netty.buffer.ByteBuf)2 IOException (java.io.IOException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1