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