Search in sources :

Example 1 with MessagePlayInOutFinishUsingItem

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem in project LanternServer by LanternPowered.

the class CodecPlayOutEntityStatus method encode.

@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
    final int entityId;
    final int action;
    if (message instanceof MessagePlayOutSetReducedDebug) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = ((MessagePlayOutSetReducedDebug) message).isReduced() ? 22 : 23;
    } else if (message instanceof MessagePlayOutSetOpLevel) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = 24 + Math.max(0, Math.min(4, ((MessagePlayOutSetOpLevel) message).getOpLevel()));
    } else if (message instanceof MessagePlayOutEntityStatus) {
        entityId = ((MessagePlayOutEntityStatus) message).getEntityId();
        action = ((MessagePlayOutEntityStatus) message).getStatus();
    } else if (message instanceof MessagePlayInOutFinishUsingItem) {
        entityId = context.getChannel().attr(CodecPlayOutPlayerJoinGame.PLAYER_ENTITY_ID).get();
        action = 9;
    } else {
        throw new CodecException("Unsupported message type: " + message.getClass().getName());
    }
    return context.byteBufAlloc().buffer(LENGTH).writeInteger(entityId).writeByte((byte) action);
}
Also used : MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) MessagePlayOutEntityStatus(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus) MessagePlayOutSetReducedDebug(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetReducedDebug) CodecException(io.netty.handler.codec.CodecException) MessagePlayOutSetOpLevel(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetOpLevel)

Example 2 with MessagePlayInOutFinishUsingItem

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem in project LanternServer by LanternPowered.

the class CodecPlayInPlayerDigging method decode.

@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    int action = buf.readByte();
    Vector3i position = buf.read(Types.VECTOR_3_I);
    int face = buf.readByte();
    switch(action) {
        case 0:
        case 1:
        case 2:
            return new MessagePlayInPlayerDigging(MessagePlayInPlayerDigging.Action.values()[action], position, fromFace(face));
        case 3:
        case 4:
            return new MessagePlayInDropHeldItem(action == 3);
        case 5:
            return new MessagePlayInOutFinishUsingItem();
        case 6:
            return new MessagePlayInSwapHandItems();
        default:
            throw new DecoderException("Unknown player digging message action: " + action);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) MessagePlayInOutFinishUsingItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem) Vector3i(com.flowpowered.math.vector.Vector3i) MessagePlayInPlayerDigging(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerDigging) MessagePlayInSwapHandItems(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInSwapHandItems) MessagePlayInDropHeldItem(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInDropHeldItem)

Aggregations

MessagePlayInOutFinishUsingItem (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 CodecException (io.netty.handler.codec.CodecException)1 DecoderException (io.netty.handler.codec.DecoderException)1 MessagePlayInDropHeldItem (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInDropHeldItem)1 MessagePlayInPlayerDigging (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInPlayerDigging)1 MessagePlayInSwapHandItems (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInSwapHandItems)1 MessagePlayOutEntityStatus (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus)1 MessagePlayOutSetOpLevel (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetOpLevel)1 MessagePlayOutSetReducedDebug (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetReducedDebug)1