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