use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutUnlockRecipes in project LanternServer by LanternPowered.
the class CodecPlayOutUnlockRecipes method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutUnlockRecipes message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutUnlockRecipes.Remove) {
buf.writeVarInt((short) 2);
} else if (message instanceof MessagePlayOutUnlockRecipes.Add) {
buf.writeVarInt((short) 1);
} else if (message instanceof MessagePlayOutUnlockRecipes.Init) {
buf.writeVarInt((short) 0);
} else {
throw new EncoderException();
}
buf.writeBoolean(message.hasOpenCraftingBook());
buf.writeBoolean(message.hasCraftingFilter());
IntList recipeIds = message.getRecipeIds();
buf.writeVarInt(recipeIds.size());
recipeIds.forEach(buf::writeVarInt);
if (message instanceof MessagePlayOutUnlockRecipes.Init) {
recipeIds = ((MessagePlayOutUnlockRecipes.Init) message).getRecipeIdsToBeDisplayed();
buf.writeVarInt(recipeIds.size());
recipeIds.forEach(buf::writeVarInt);
}
return buf;
}
Aggregations