Archiviert
13
0

Implement entity max health methods. Adds BUKKIT-266

Dieser Commit ist enthalten in:
feildmaster 2012-12-23 05:49:03 -06:00
Ursprung 4e1793f363
Commit ced0646351
10 geänderte Dateien mit 92 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -82,7 +82,7 @@ public class EntityEnderDragon extends EntityLiving implements IComplex {
float f1;
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 {
f = MathHelper.cos(this.bN * 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;
} 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
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
this.world.getServer().getPluginManager().callEvent(event);

Datei anzeigen

@ -294,7 +294,8 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
--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.
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() {
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) {

Datei anzeigen

@ -106,8 +106,11 @@ public abstract class EntityLiving extends Entity {
private int bV = 0;
private Entity bW;
protected int bI = 0;
public int expToDrop = 0; // CraftBukkit
public int maxAirTicks = 300; // CraftBukkit
// CraftBukkit start
public int expToDrop = 0;
public int maxAirTicks = 300;
public int maxHealth = this.getMaxHealth();
// CraftBukkit end
public EntityLiving(World world) {
super(world);
@ -418,6 +421,14 @@ public abstract class EntityLiving extends Entity {
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
protected void aP() {
@ -626,10 +637,11 @@ public abstract class EntityLiving extends Entity {
if (!event.isCancelled()) {
this.health += event.getAmount();
}
// CraftBukkit end
if (this.health > this.getMaxHealth()) {
this.health = this.getMaxHealth();
// this.getMaxHealth() -> this.maxHealth
if (this.health > this.maxHealth) {
this.health = this.maxHealth;
// CraftBukkit end
}
this.noDamageTicks = this.maxNoDamageTicks / 2;
@ -1138,12 +1150,19 @@ public abstract class EntityLiving extends Entity {
}
nbttagcompound.set("DropChances", nbttaglist1);
nbttagcompound.setInt("Bukkit.MaxHealth", this.maxHealth); // CraftBukkit
}
public void a(NBTTagCompound nbttagcompound) {
this.health = nbttagcompound.getShort("Health");
// CraftBukkit start
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
this.maxHealth = nbttagcompound.getInt("Bukkit.MaxHealth");
}
if (!nbttagcompound.hasKey("Health")) {
this.health = this.getMaxHealth();
this.health = this.maxHealth; // this.getMaxHealth() -> this.maxHealth
// CraftBukkit
}
this.hurtTicks = nbttagcompound.getShort("HurtTime");
@ -1811,7 +1830,7 @@ public abstract class EntityLiving extends Entity {
if (this.aG() == null) {
return 3;
} 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;
if (i < 0) {

Datei anzeigen

@ -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) {
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.cm = this.foodData.a();
this.cn = this.foodData.e() == 0.0F;
@ -773,7 +774,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
this.newLevel = this.expLevel;
}
this.health = 20;
this.health = this.maxHealth;
this.fireTicks = 0;
this.fallDistance = 0;
this.foodData = new FoodMetaData();

Datei anzeigen

@ -81,7 +81,7 @@ public class EntityWitch extends EntityMonster implements IRangedEntity {
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
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;
} else if (this.random.nextFloat() < 0.25F && this.aG() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.aG().e(this) > 121.0D) {
short1 = 16274;

Datei anzeigen

@ -70,7 +70,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
public void c() {
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;
@ -458,7 +458,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
}
public boolean o() {
return this.b() <= this.getMaxHealth() / 2;
return this.b() <= this.maxHealth / 2; // CraftBukkit - this.getMaxHealth() -> this.maxHealth
}
public EnumMonsterType getMonsterType() {

Datei anzeigen

@ -75,7 +75,7 @@ public class MobEffectList {
public void tick(EntityLiving entityliving, int i) {
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
}
} else if (this.id == POISON.id) {

Datei anzeigen

@ -4,6 +4,7 @@ import net.minecraft.server.EntityComplexPart;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.EnderDragonPart;
import org.bukkit.entity.Entity;
public class CraftEnderDragonPart extends CraftComplexPart implements EnderDragonPart {
public CraftEnderDragonPart(CraftServer server, EntityComplexPart entity) {
@ -24,4 +25,32 @@ public class CraftEnderDragonPart extends CraftComplexPart implements EnderDrago
public String toString() {
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();
}
}

Datei anzeigen

@ -75,7 +75,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
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

Datei anzeigen

@ -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
}
}