Search in sources :

Example 96 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipIndexDataMessage method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    packetBuffer.writeInt(indexedData.size());
    packetBuffer.writeInt(shipsToLoad.size());
    packetBuffer.writeInt(shipsToUnload.size());
    for (ShipData data : indexedData) {
        // Write index data to the byte buffer.
        try {
            byte[] dataBytes = serializer.writeValueAsBytes(data);
            int bytesSize = dataBytes.length;
            packetBuffer.writeInt(bytesSize);
            packetBuffer.writeBytes(dataBytes);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
    for (UUID toLoad : shipsToLoad) {
        packetBuffer.writeUniqueId(toLoad);
    }
    for (UUID toUnload : shipsToUnload) {
        packetBuffer.writeUniqueId(toUnload);
    }
    packetBuffer.writeInt(dimensionID);
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 97 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipTransformUpdateMessage method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    packetBuffer.writeInt(shipTransforms.size());
    for (Map.Entry<UUID, Tuple<ShipTransform, AxisAlignedBB>> data : shipTransforms.entrySet()) {
        // Write index data to the byte buffer.
        try {
            // Write the UUID
            {
                byte[] dataBytes = serializer.writeValueAsBytes(data.getKey());
                int bytesSize = dataBytes.length;
                packetBuffer.writeInt(bytesSize);
                packetBuffer.writeBytes(dataBytes);
            }
            // Write the ship transform
            {
                byte[] dataBytes = serializer.writeValueAsBytes(data.getValue().getFirst());
                int bytesSize = dataBytes.length;
                packetBuffer.writeInt(bytesSize);
                packetBuffer.writeBytes(dataBytes);
            }
            // Write the ship aabb
            {
                byte[] dataBytes = serializer.writeValueAsBytes(data.getValue().getSecond());
                int bytesSize = dataBytes.length;
                packetBuffer.writeInt(bytesSize);
                packetBuffer.writeBytes(dataBytes);
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
    packetBuffer.writeInt(dimensionID);
}
Also used : JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PacketBuffer(net.minecraft.network.PacketBuffer) Tuple(net.minecraft.util.Tuple)

Example 98 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityMountable method readSpawnData.

@Override
public void readSpawnData(ByteBuf additionalData) {
    PacketBuffer packetBuffer = new PacketBuffer(additionalData);
    mountPos = new Vec3d(packetBuffer.readDouble(), packetBuffer.readDouble(), packetBuffer.readDouble());
    mountPosSpace = CoordinateSpaceType.values()[packetBuffer.readInt()];
    if (packetBuffer.readBoolean()) {
        referencePos = packetBuffer.readBlockPos();
    } else {
        referencePos = null;
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer) Vec3d(net.minecraft.util.math.Vec3d)

Example 99 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityMountable method writeSpawnData.

@Override
public void writeSpawnData(ByteBuf buffer) {
    PacketBuffer packetBuffer = new PacketBuffer(buffer);
    Vec3d mountPosLocal = mountPos;
    packetBuffer.writeDouble(mountPosLocal.x);
    packetBuffer.writeDouble(mountPosLocal.y);
    packetBuffer.writeDouble(mountPosLocal.z);
    packetBuffer.writeInt(mountPosSpace.ordinal());
    packetBuffer.writeBoolean(referencePos != null);
    if (referencePos != null) {
        packetBuffer.writeBlockPos(referencePos);
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer) Vec3d(net.minecraft.util.math.Vec3d)

Example 100 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MessagePlayerStoppedPiloting method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer packetBuf = new PacketBuffer(buf);
    packetBuf.writeBoolean(posToStopPiloting != null);
    packetBuf.writeBoolean(shipIDToStopPiloting != null);
    if (posToStopPiloting != null) {
        packetBuf.writeInt(posToStopPiloting.getX());
        packetBuf.writeInt(posToStopPiloting.getY());
        packetBuf.writeInt(posToStopPiloting.getZ());
    }
    if (shipIDToStopPiloting != null) {
        packetBuf.writeUniqueId(shipIDToStopPiloting);
    }
// use absolute coordinates instead of writeBlockPos in case we ever add compatibility with cubic chunks
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketBuffer (net.minecraft.network.PacketBuffer)105 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)20 IOException (java.io.IOException)14 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)14 ByteBuf (io.netty.buffer.ByteBuf)11 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)7 BlockPos (net.minecraft.util.math.BlockPos)7 HashMap (java.util.HashMap)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)4 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)3 Test (org.junit.Test)3 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 PacketCustomTileData (gregtech.api.net.PacketCustomTileData)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 AbstractData (hellfirepvp.fracture.common.data.AbstractData)2