mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 11:27:35 +01:00
Implement entity max health methods. Adds BUKKIT-266
This commit is contained in:
parent
4e1793f363
commit
ced0646351
@ -82,7 +82,7 @@ public class EntityEnderDragon extends EntityLiving implements IComplex {
|
|||||||
float f1;
|
float f1;
|
||||||
|
|
||||||
if (!this.world.isStatic) {
|
if (!this.world.isStatic) {
|
||||||
this.datawatcher.watch(16, Integer.valueOf(this.health));
|
this.datawatcher.watch(16, Integer.valueOf(this.getScaledHealth())); // CraftBukkit - this.health -> this.getScaledHealth()
|
||||||
} else {
|
} else {
|
||||||
f = MathHelper.cos(this.bN * 3.1415927F * 2.0F);
|
f = MathHelper.cos(this.bN * 3.1415927F * 2.0F);
|
||||||
f1 = MathHelper.cos(this.bM * 3.1415927F * 2.0F);
|
f1 = MathHelper.cos(this.bM * 3.1415927F * 2.0F);
|
||||||
@ -307,7 +307,7 @@ public class EntityEnderDragon extends EntityLiving implements IComplex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.bR = null;
|
this.bR = null;
|
||||||
} else if (this.ticksLived % 10 == 0 && this.health < this.getMaxHealth()) {
|
} else if (this.ticksLived % 10 == 0 && this.health < this.maxHealth) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
|
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
|
||||||
this.world.getServer().getPluginManager().callEvent(event);
|
this.world.getServer().getPluginManager().callEvent(event);
|
||||||
|
@ -294,7 +294,8 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
|
|||||||
--this.bN;
|
--this.bN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.world.difficulty == 0 && this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 * 12 == 0) {
|
// CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
||||||
|
if (this.world.difficulty == 0 && this.getHealth() < this.maxHealth && this.ticksLived % 20 * 12 == 0) {
|
||||||
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
|
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
|
||||||
this.heal(1, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
|
this.heal(1, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
|
||||||
}
|
}
|
||||||
@ -1289,7 +1290,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean cd() {
|
public boolean cd() {
|
||||||
return this.getHealth() > 0 && this.getHealth() < this.getMaxHealth();
|
return this.getHealth() > 0 && this.getHealth() < this.maxHealth; // CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
||||||
}
|
}
|
||||||
|
|
||||||
public void a(ItemStack itemstack, int i) {
|
public void a(ItemStack itemstack, int i) {
|
||||||
|
@ -106,8 +106,11 @@ public abstract class EntityLiving extends Entity {
|
|||||||
private int bV = 0;
|
private int bV = 0;
|
||||||
private Entity bW;
|
private Entity bW;
|
||||||
protected int bI = 0;
|
protected int bI = 0;
|
||||||
public int expToDrop = 0; // CraftBukkit
|
// CraftBukkit start
|
||||||
public int maxAirTicks = 300; // CraftBukkit
|
public int expToDrop = 0;
|
||||||
|
public int maxAirTicks = 300;
|
||||||
|
public int maxHealth = this.getMaxHealth();
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
public EntityLiving(World world) {
|
public EntityLiving(World world) {
|
||||||
super(world);
|
super(world);
|
||||||
@ -418,6 +421,14 @@ public abstract class EntityLiving extends Entity {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getScaledHealth() {
|
||||||
|
if (this.maxHealth != this.getMaxHealth() && this.getHealth() > 0) {
|
||||||
|
return this.getHealth() * this.getMaxHealth() / this.maxHealth + 1;
|
||||||
|
} else {
|
||||||
|
return this.getHealth();
|
||||||
|
}
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
protected void aP() {
|
protected void aP() {
|
||||||
@ -626,10 +637,11 @@ public abstract class EntityLiving extends Entity {
|
|||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
this.health += event.getAmount();
|
this.health += event.getAmount();
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
|
||||||
|
|
||||||
if (this.health > this.getMaxHealth()) {
|
// this.getMaxHealth() -> this.maxHealth
|
||||||
this.health = this.getMaxHealth();
|
if (this.health > this.maxHealth) {
|
||||||
|
this.health = this.maxHealth;
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
this.noDamageTicks = this.maxNoDamageTicks / 2;
|
this.noDamageTicks = this.maxNoDamageTicks / 2;
|
||||||
@ -1138,12 +1150,19 @@ public abstract class EntityLiving extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nbttagcompound.set("DropChances", nbttaglist1);
|
nbttagcompound.set("DropChances", nbttaglist1);
|
||||||
|
nbttagcompound.setInt("Bukkit.MaxHealth", this.maxHealth); // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void a(NBTTagCompound nbttagcompound) {
|
public void a(NBTTagCompound nbttagcompound) {
|
||||||
this.health = nbttagcompound.getShort("Health");
|
this.health = nbttagcompound.getShort("Health");
|
||||||
|
// CraftBukkit start
|
||||||
|
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
|
||||||
|
this.maxHealth = nbttagcompound.getInt("Bukkit.MaxHealth");
|
||||||
|
}
|
||||||
|
|
||||||
if (!nbttagcompound.hasKey("Health")) {
|
if (!nbttagcompound.hasKey("Health")) {
|
||||||
this.health = this.getMaxHealth();
|
this.health = this.maxHealth; // this.getMaxHealth() -> this.maxHealth
|
||||||
|
// CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hurtTicks = nbttagcompound.getShort("HurtTime");
|
this.hurtTicks = nbttagcompound.getShort("HurtTime");
|
||||||
@ -1811,7 +1830,7 @@ public abstract class EntityLiving extends Entity {
|
|||||||
if (this.aG() == null) {
|
if (this.aG() == null) {
|
||||||
return 3;
|
return 3;
|
||||||
} else {
|
} else {
|
||||||
int i = (int) ((float) this.health - (float) this.getMaxHealth() * 0.33F);
|
int i = (int) ((float) this.health - (float) this.maxHealth * 0.33F); // this.getMaxHealth() -> this.maxHealth
|
||||||
|
|
||||||
i -= (3 - this.world.difficulty) * 4;
|
i -= (3 - this.world.difficulty) * 4;
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -205,7 +205,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.getHealth() != this.cl || this.cm != this.foodData.a() || this.foodData.e() == 0.0F != this.cn) {
|
if (this.getHealth() != this.cl || this.cm != this.foodData.a() || this.foodData.e() == 0.0F != this.cn) {
|
||||||
this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getHealth(), this.foodData.a(), this.foodData.e()));
|
// CraftBukkit - this.getHealth() -> this.getScaledHealth()
|
||||||
|
this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e()));
|
||||||
this.cl = this.getHealth();
|
this.cl = this.getHealth();
|
||||||
this.cm = this.foodData.a();
|
this.cm = this.foodData.a();
|
||||||
this.cn = this.foodData.e() == 0.0F;
|
this.cn = this.foodData.e() == 0.0F;
|
||||||
@ -773,7 +774,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|||||||
this.newLevel = this.expLevel;
|
this.newLevel = this.expLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.health = 20;
|
this.health = this.maxHealth;
|
||||||
this.fireTicks = 0;
|
this.fireTicks = 0;
|
||||||
this.fallDistance = 0;
|
this.fallDistance = 0;
|
||||||
this.foodData = new FoodMetaData();
|
this.foodData = new FoodMetaData();
|
||||||
|
@ -81,7 +81,7 @@ public class EntityWitch extends EntityMonster implements IRangedEntity {
|
|||||||
|
|
||||||
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
|
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
|
||||||
short1 = 16307;
|
short1 = 16307;
|
||||||
} else if (this.random.nextFloat() < 0.05F && this.health < this.getMaxHealth()) {
|
} else if (this.random.nextFloat() < 0.05F && this.health < this.maxHealth) { // CraftBukkit - this.getMaxHealth -> this.maxHealth
|
||||||
short1 = 16341;
|
short1 = 16341;
|
||||||
} else if (this.random.nextFloat() < 0.25F && this.aG() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.aG().e(this) > 121.0D) {
|
} else if (this.random.nextFloat() < 0.25F && this.aG() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.aG().e(this) > 121.0D) {
|
||||||
short1 = 16274;
|
short1 = 16274;
|
||||||
|
@ -70,7 +70,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
|
|||||||
|
|
||||||
public void c() {
|
public void c() {
|
||||||
if (!this.world.isStatic) {
|
if (!this.world.isStatic) {
|
||||||
this.datawatcher.watch(16, Integer.valueOf(this.health));
|
this.datawatcher.watch(16, Integer.valueOf(this.getScaledHealth())); // CraftBukkit - this.health -> this.getScaledHealth()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.motY *= 0.6000000238418579D;
|
this.motY *= 0.6000000238418579D;
|
||||||
@ -458,7 +458,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean o() {
|
public boolean o() {
|
||||||
return this.b() <= this.getMaxHealth() / 2;
|
return this.b() <= this.maxHealth / 2; // CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumMonsterType getMonsterType() {
|
public EnumMonsterType getMonsterType() {
|
||||||
|
@ -75,7 +75,7 @@ public class MobEffectList {
|
|||||||
|
|
||||||
public void tick(EntityLiving entityliving, int i) {
|
public void tick(EntityLiving entityliving, int i) {
|
||||||
if (this.id == REGENERATION.id) {
|
if (this.id == REGENERATION.id) {
|
||||||
if (entityliving.getHealth() < entityliving.getMaxHealth()) {
|
if (entityliving.getHealth() < entityliving.maxHealth) { // CraftBukkit - .getMaxHealth() -> .maxHealth
|
||||||
entityliving.heal(1, RegainReason.MAGIC_REGEN); // CraftBukkit
|
entityliving.heal(1, RegainReason.MAGIC_REGEN); // CraftBukkit
|
||||||
}
|
}
|
||||||
} else if (this.id == POISON.id) {
|
} else if (this.id == POISON.id) {
|
||||||
|
@ -4,6 +4,7 @@ import net.minecraft.server.EntityComplexPart;
|
|||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.entity.EnderDragon;
|
import org.bukkit.entity.EnderDragon;
|
||||||
import org.bukkit.entity.EnderDragonPart;
|
import org.bukkit.entity.EnderDragonPart;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
public class CraftEnderDragonPart extends CraftComplexPart implements EnderDragonPart {
|
public class CraftEnderDragonPart extends CraftComplexPart implements EnderDragonPart {
|
||||||
public CraftEnderDragonPart(CraftServer server, EntityComplexPart entity) {
|
public CraftEnderDragonPart(CraftServer server, EntityComplexPart entity) {
|
||||||
@ -24,4 +25,32 @@ public class CraftEnderDragonPart extends CraftComplexPart implements EnderDrago
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "CraftEnderDragonPart";
|
return "CraftEnderDragonPart";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void damage(int amount) {
|
||||||
|
getParent().damage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void damage(int amount, Entity source) {
|
||||||
|
getParent().damage(amount, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHealth() {
|
||||||
|
return getParent().getHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHealth(int health) {
|
||||||
|
getParent().setHealth(health);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxHealth() {
|
||||||
|
return getParent().getMaxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxHealth(int health) {
|
||||||
|
getParent().setMaxHealth(health);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetMaxHealth() {
|
||||||
|
getParent().resetMaxHealth();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxHealth() {
|
public int getMaxHealth() {
|
||||||
return getHandle().getMaxHealth();
|
return getHandle().maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxHealth(int amount) {
|
||||||
|
Validate.isTrue(amount > 0, "Max health must be greater than 0");
|
||||||
|
|
||||||
|
getHandle().maxHealth = amount;
|
||||||
|
|
||||||
|
if (getHealth() > amount) {
|
||||||
|
setHealth(amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetMaxHealth() {
|
||||||
|
setMaxHealth(getHandle().getMaxHealth());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -941,4 +941,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxHealth(int amount) {
|
||||||
|
super.setMaxHealth(amount);
|
||||||
|
getHandle().m(); // Update health
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetMaxHealth() {
|
||||||
|
super.resetMaxHealth();
|
||||||
|
getHandle().m(); // Update health
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user