use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutDestroyEntities method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutDestroyEntities message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
final int[] entityIds = message.getEntityIds();
buf.writeVarInt(entityIds.length);
for (int entityId : entityIds) {
buf.writeVarInt(entityId);
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutDisplayRecipe method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutDisplayRecipe message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeByte((byte) message.getWindowId());
buf.writeVarInt(message.getRecipeId());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutEffect) {
final MessagePlayOutEffect message1 = (MessagePlayOutEffect) message;
buf.writeInteger(message1.getType());
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getData());
buf.writeBoolean(message1.isBroadcast());
} else if (message instanceof MessagePlayOutRecord) {
final MessagePlayOutRecord message1 = (MessagePlayOutRecord) message;
buf.writeInteger(1010);
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getRecord().map(type -> 2256 + ((LanternRecordType) type).getInternalId()).orElse(0));
buf.writeBoolean(false);
} else {
throw new EncoderException("Unsupported message type: " + message.getClass().getName());
}
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutEntityCollectItem method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutEntityCollectItem message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(message.getCollectedId());
buf.writeVarInt(message.getCollectorId());
buf.writeVarInt(message.getCollectItemCount());
return buf;
}
use of org.lanternpowered.server.network.buffer.ByteBuffer in project LanternServer by LanternPowered.
the class CodecPlayOutEntityEquipment method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutEntityEquipment message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeVarInt(message.getEntityId());
buf.writeVarInt(message.getSlotIndex());
final Object item = message.getItem();
if (item instanceof ItemStack) {
buf.write(Types.ITEM_STACK, (ItemStack) item);
} else if (item instanceof RawItemStack || item == null) {
buf.write(Types.RAW_ITEM_STACK, (RawItemStack) item);
} else {
throw new EncoderException("Invalid item type:" + item.getClass().getName());
}
return buf;
}
Aggregations