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);
}
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);
}
}
Aggregations