Search in sources :

Example 1 with RespawnPacket

use of org.dragonet.protocol.packets.RespawnPacket 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 };
}
Also used : SetHealthPacket(org.dragonet.protocol.packets.SetHealthPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) RespawnPacket(org.dragonet.protocol.packets.RespawnPacket)

Aggregations

PEPacket (org.dragonet.protocol.PEPacket)1 RespawnPacket (org.dragonet.protocol.packets.RespawnPacket)1 SetHealthPacket (org.dragonet.protocol.packets.SetHealthPacket)1 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1