Search in sources :

Example 1 with ClientboundSetHealthPacket

use of net.minecraft.network.protocol.game.ClientboundSetHealthPacket in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_HealthScale method bridge$refreshScaledHealth.

@Override
public void bridge$refreshScaledHealth() {
    // We need to use the dirty instances to signify that the player needs to have it updated, instead
    // of modifying the attribute instances themselves, we bypass other potentially detrimental logic
    // that would otherwise break the actual health scaling.
    final Set<AttributeInstance> dirtyInstances = this.shadow$getAttributes().getDirtyAttributes();
    this.bridge$injectScaledHealth(dirtyInstances);
    // Send the new information to the client.
    final FoodData foodData = this.shadow$getFoodData();
    this.connection.send(new ClientboundSetHealthPacket(this.bridge$getInternalScaledHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel()));
    this.connection.send(new ClientboundUpdateAttributesPacket(this.shadow$getId(), dirtyInstances));
    // Reset the dirty instances since they've now been manually updated on the client.
    dirtyInstances.clear();
}
Also used : AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ClientboundSetHealthPacket(net.minecraft.network.protocol.game.ClientboundSetHealthPacket) FoodData(net.minecraft.world.food.FoodData) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket)

Aggregations

ClientboundSetHealthPacket (net.minecraft.network.protocol.game.ClientboundSetHealthPacket)1 ClientboundUpdateAttributesPacket (net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket)1 AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)1 FoodData (net.minecraft.world.food.FoodData)1