use of org.dragonet.protocol.packets.SetHealthPacket in project DragonProxy by DragonetMC.
the class PCUpdateHealthPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) {
// Always round up
int newHealth = (int) Math.ceil(packet.getHealth());
SetHealthPacket h = new SetHealthPacket(newHealth);
CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
peSelfPlayer.attributes.put(PEEntityAttribute.HEALTH, PEEntityAttribute.findAttribute(PEEntityAttribute.HEALTH).setValue(newHealth));
if (peSelfPlayer.foodPacketCount == 0) {
peSelfPlayer.attributes.put(PEEntityAttribute.FOOD, PEEntityAttribute.findAttribute(PEEntityAttribute.FOOD).setValue(packet.getFood()));
}
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.rtid = peSelfPlayer.proxyEid;
pk.entries = peSelfPlayer.attributes.values();
if (newHealth <= 0)
return new PEPacket[] { h, pk, new RespawnPacket() };
return new PEPacket[] { h, pk };
}
Aggregations