Search in sources :

Example 1 with AttributeInstance

use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.

the class ImprovedOfflinePlayerImpl method setMaxHealth.

@Override
public void setMaxHealth(double input) {
    AttributeMap attributes = getAttributes();
    AttributeInstance maxHealth = attributes.getInstance(Attributes.MAX_HEALTH);
    maxHealth.setBaseValue(input);
    setAttributes(attributes);
}
Also used : AttributeMap(net.minecraft.world.entity.ai.attributes.AttributeMap) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 2 with AttributeInstance

use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showMobHealth.

@Override
public void showMobHealth(Player player, LivingEntity mob, double health, double maxHealth) {
    AttributeInstance attr = new AttributeInstance(Attributes.MAX_HEALTH, (a) -> {
    });
    attr.setBaseValue(maxHealth);
    send(player, new ClientboundUpdateAttributesPacket(mob.getEntityId(), Collections.singletonList(attr)));
    FriendlyByteBuf healthData = new FriendlyByteBuf(Unpooled.buffer());
    healthData.writeVarInt(mob.getEntityId());
    // health id
    healthData.writeByte(9);
    // type = float
    healthData.writeVarInt(2);
    healthData.writeFloat((float) health);
    // Mark end of packet
    healthData.writeByte(255);
    send(player, new ClientboundSetEntityDataPacket(healthData));
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 3 with AttributeInstance

use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showMobHealth.

@Override
public void showMobHealth(Player player, LivingEntity mob, double health, double maxHealth) {
    AttributeInstance attr = new AttributeInstance(Attributes.MAX_HEALTH, (a) -> {
    });
    attr.setBaseValue(maxHealth);
    send(player, new ClientboundUpdateAttributesPacket(mob.getEntityId(), Collections.singletonList(attr)));
    FriendlyByteBuf healthData = new FriendlyByteBuf(Unpooled.buffer());
    healthData.writeVarInt(mob.getEntityId());
    // health id
    healthData.writeByte(9);
    // type = float
    healthData.writeVarInt(2);
    healthData.writeFloat((float) health);
    // Mark end of packet
    healthData.writeByte(255);
    send(player, new ClientboundSetEntityDataPacket(healthData));
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 4 with AttributeInstance

use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.

the class ImprovedOfflinePlayerImpl method setMaxHealth.

@Override
public void setMaxHealth(double input) {
    AttributeMap attributes = getAttributes();
    AttributeInstance maxHealth = attributes.getInstance(Attributes.MAX_HEALTH);
    maxHealth.setBaseValue(input);
    setAttributes(attributes);
}
Also used : AttributeMap(net.minecraft.world.entity.ai.attributes.AttributeMap) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 5 with AttributeInstance

use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project MinecraftForge by MinecraftForge.

the class ForgeIngameGui method renderHealth.

public void renderHealth(int width, int height, PoseStack pStack) {
    bind(GUI_ICONS_LOCATION);
    minecraft.getProfiler().push("health");
    RenderSystem.enableBlend();
    Player player = (Player) this.minecraft.getCameraEntity();
    int health = Mth.ceil(player.getHealth());
    boolean highlight = healthBlinkTime > (long) tickCount && (healthBlinkTime - (long) tickCount) / 3L % 2L == 1L;
    if (health < this.lastHealth && player.invulnerableTime > 0) {
        this.lastHealthTime = Util.getMillis();
        this.healthBlinkTime = (long) (this.tickCount + 20);
    } else if (health > this.lastHealth && player.invulnerableTime > 0) {
        this.lastHealthTime = Util.getMillis();
        this.healthBlinkTime = (long) (this.tickCount + 10);
    }
    if (Util.getMillis() - this.lastHealthTime > 1000L) {
        this.lastHealth = health;
        this.displayHealth = health;
        this.lastHealthTime = Util.getMillis();
    }
    this.lastHealth = health;
    int healthLast = this.displayHealth;
    AttributeInstance attrMaxHealth = player.getAttribute(Attributes.MAX_HEALTH);
    float healthMax = Math.max((float) attrMaxHealth.getValue(), Math.max(healthLast, health));
    int absorb = Mth.ceil(player.getAbsorptionAmount());
    int healthRows = Mth.ceil((healthMax + absorb) / 2.0F / 10.0F);
    int rowHeight = Math.max(10 - (healthRows - 2), 3);
    this.random.setSeed((long) (tickCount * 312871));
    int left = width / 2 - 91;
    int top = height - left_height;
    left_height += (healthRows * rowHeight);
    if (rowHeight != 10)
        left_height += 10 - rowHeight;
    int regen = -1;
    if (player.hasEffect(MobEffects.REGENERATION)) {
        regen = this.tickCount % Mth.ceil(healthMax + 5.0F);
    }
    this.renderHearts(pStack, player, left, top, rowHeight, regen, healthMax, health, healthLast, absorb, highlight);
    RenderSystem.disableBlend();
    minecraft.getProfiler().pop();
}
Also used : Player(net.minecraft.world.entity.player.Player) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Aggregations

AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)8 LivingEntity (net.minecraft.world.entity.LivingEntity)3 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)2 AttributeMap (net.minecraft.world.entity.ai.attributes.AttributeMap)2 Multimap (com.google.common.collect.Multimap)1 MyAquaticPetPathNavigation (de.Keyle.MyPet.compat.v1_17_R1.entity.ai.navigation.MyAquaticPetPathNavigation)1 MyAquaticPetPathNavigation (de.Keyle.MyPet.compat.v1_18_R1.entity.ai.navigation.MyAquaticPetPathNavigation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Entity (net.minecraft.world.entity.Entity)1 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)1 Attribute (net.minecraft.world.entity.ai.attributes.Attribute)1 AttributeModifier (net.minecraft.world.entity.ai.attributes.AttributeModifier)1 Operation (net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation)1