Search in sources :

Example 1 with MessagePlayOutEntityStatus

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus 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 MessagePlayOutEntityStatus

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

the class IronGolemEntityProcotol method update.

@Override
protected void update(EntityProtocolUpdateContext context) {
    super.update(context);
    final boolean holdsPoppy = getEntity().get(LanternKeys.HOLDS_POPPY).orElse(false);
    if (holdsPoppy) {
        this.lastHoldPoppyTime -= getTickRate();
        if (this.lastHoldPoppyTime <= 0) {
            context.sendToAll(() -> new MessagePlayOutEntityStatus(getRootEntityId(), POPPY_ADD_STATUS));
            this.lastHoldPoppyTime = POPPY_RESEND_DELAY;
        }
    } else if (this.lastHoldPoppyTime >= 0) {
        context.sendToAll(() -> new MessagePlayOutEntityStatus(getRootEntityId(), POPPY_REMOVE_STATUS));
        this.lastHoldPoppyTime = -1;
    }
}
Also used : MessagePlayOutEntityStatus(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus)

Aggregations

MessagePlayOutEntityStatus (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityStatus)2 CodecException (io.netty.handler.codec.CodecException)1 MessagePlayInOutFinishUsingItem (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutFinishUsingItem)1 MessagePlayOutSetOpLevel (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetOpLevel)1 MessagePlayOutSetReducedDebug (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetReducedDebug)1