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