use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenWindow in project LanternServer by LanternPowered.
the class CodecPlayOutOpenWindow method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutOpenWindow message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeByte((byte) message.getWindowId());
MessagePlayOutOpenWindow.WindowType windowType = message.getWindowType();
String type;
if (windowType == MessagePlayOutOpenWindow.WindowType.HORSE) {
type = "EntityHorse";
} else {
type = "minecraft:" + windowType.name().toLowerCase();
}
buf.writeString(type);
buf.write(Types.TEXT, message.getTitle());
// That logic...
if (windowType == MessagePlayOutOpenWindow.WindowType.ANVIL || windowType == MessagePlayOutOpenWindow.WindowType.CRAFTING_TABLE || windowType == MessagePlayOutOpenWindow.WindowType.ENCHANTING_TABLE) {
buf.writeByte((byte) 0);
} else {
buf.writeByte((byte) message.getSlotCount());
}
if (windowType == MessagePlayOutOpenWindow.WindowType.HORSE) {
buf.writeInteger(message.getEntityId());
}
return buf;
}
Aggregations