Search in sources :

Example 1 with MessagePlayOutUnlockRecipes

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;
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) MessagePlayOutUnlockRecipes(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutUnlockRecipes) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

EncoderException (io.netty.handler.codec.EncoderException)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1 MessagePlayOutUnlockRecipes (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutUnlockRecipes)1