summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityHorse.java
diff options
context:
space:
mode:
authorh31ix <zero_gravity@outlook.com>2013-07-10 11:58:18 -0400
committermbax <matt@phozop.net>2013-07-10 13:45:52 -0400
commitf9d58bf4813495e9122dd3950f6bfb2e90ba4ef6 (patch)
treeaa8dbba4bfc15d7a408feddd58b79ff42b820bb0 /src/main/java/net/minecraft/server/EntityHorse.java
parenta192775f0fc6f6a7431da5af4b0e00deff3f64e6 (diff)
downloadcraftbukkit-f9d58bf4813495e9122dd3950f6bfb2e90ba4ef6.tar
craftbukkit-f9d58bf4813495e9122dd3950f6bfb2e90ba4ef6.tar.gz
craftbukkit-f9d58bf4813495e9122dd3950f6bfb2e90ba4ef6.tar.lz
craftbukkit-f9d58bf4813495e9122dd3950f6bfb2e90ba4ef6.tar.xz
craftbukkit-f9d58bf4813495e9122dd3950f6bfb2e90ba4ef6.zip
Implement Horse API. Adds BUKKIT-4424
API has been added to interface with Horses and to modify their inventories. Horse entities will now be recognized with the type EntityType.HORSE, and will no longer be UNKNOWN. HorseJumpEvent, EntityDamageEvent, and EntityTameEvent are all correctly fired for horses. This commit fixes BUKKIT-4393.
Diffstat (limited to 'src/main/java/net/minecraft/server/EntityHorse.java')
-rw-r--r--src/main/java/net/minecraft/server/EntityHorse.java61
1 files changed, 48 insertions, 13 deletions
diff --git a/src/main/java/net/minecraft/server/EntityHorse.java b/src/main/java/net/minecraft/server/EntityHorse.java
index e18738a3..fb411ed4 100644
--- a/src/main/java/net/minecraft/server/EntityHorse.java
+++ b/src/main/java/net/minecraft/server/EntityHorse.java
@@ -3,10 +3,15 @@ package net.minecraft.server;
import java.util.Iterator;
import java.util.List;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityDamageEvent;
+// CraftBukkit end
+
public class EntityHorse extends EntityAnimal implements IInventoryListener {
private static final IEntitySelector bu = new EntitySelectorHorse();
- private static final IAttribute attributeJumpStrength = (new AttributeRanged("horse.jumpStrength", 0.7D, 0.0D, 2.0D)).a("Jump Strength").a(true);
+ public static final IAttribute attributeJumpStrength = (new AttributeRanged("horse.jumpStrength", 0.7D, 0.0D, 2.0D)).a("Jump Strength").a(true); // CraftBukkit - private -> public
private static final String[] bw = new String[] { null, "textures/entity/horse/armor/horse_armor_iron.png", "textures/entity/horse/armor/horse_armor_gold.png", "textures/entity/horse/armor/horse_armor_diamond.png"};
private static final String[] bx = new String[] { "", "meo", "goo", "dio"};
private static final int[] by = new int[] { 0, 5, 7, 11};
@@ -20,7 +25,7 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
public int bp;
public int bq;
protected boolean br;
- private InventoryHorseChest inventoryChest;
+ public InventoryHorseChest inventoryChest; // CraftBukkit - private -> public
private boolean bH;
protected int bs;
protected float bt;
@@ -34,6 +39,7 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
private int bP;
private String bQ;
private String[] bR = new String[3];
+ public int maxDomestication = 100; // CraftBukkit - store max domestication value
public EntityHorse(World world) {
super(world);
@@ -281,9 +287,26 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
int i = MathHelper.f(f * 0.5F - 3.0F);
if (i > 0) {
- this.damageEntity(DamageSource.FALL, (float) i);
+ // CraftBukkit start
+ EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, this, EntityDamageEvent.DamageCause.FALL, i);
+ if (!event.isCancelled()) {
+ float damage = (float) event.getDamage();
+ if (damage > 0) {
+ this.getBukkitEntity().setLastDamageCause(event);
+ this.damageEntity(DamageSource.FALL, damage);
+ }
+ }
+
if (this.passenger != null) {
- this.passenger.damageEntity(DamageSource.FALL, (float) i);
+ EntityDamageEvent passengerEvent = CraftEventFactory.callEntityDamageEvent(null, this.passenger, EntityDamageEvent.DamageCause.FALL, i);
+ if (!passengerEvent.isCancelled() && this.passenger != null) { // Check again in case of plugin
+ float damage = (float) passengerEvent.getDamage();
+ if (damage > 0) {
+ this.passenger.getBukkitEntity().setLastDamageCause(passengerEvent);
+ this.passenger.damageEntity(DamageSource.FALL, damage);
+ }
+ }
+ // CraftBukkit end
}
int j = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.locY - 0.2D - (double) this.lastYaw), MathHelper.floor(this.locZ));
@@ -299,10 +322,10 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
private int cG() {
int i = this.getType();
- return this.hasChest() && (i == 1 || i == 2) ? 17 : 2;
+ return this.hasChest() /* && (i == 1 || i == 2) */ ? 17 : 2; // CraftBukkit - Remove type check
}
- private void cH() {
+ public void cH() { // CraftBukkit - private -> public
InventoryHorseChest inventoryhorsechest = this.inventoryChest;
this.inventoryChest = new InventoryHorseChest("HorseChest", this.cG());
@@ -467,7 +490,7 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
}
public int cq() {
- return 100;
+ return this.maxDomestication; // CraftBukkit - return stored max domestication instead of 100
}
protected float aZ() {
@@ -928,6 +951,7 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
nbttagcompound.setInt("Temper", this.getTemper());
nbttagcompound.setBoolean("Tame", this.isTame());
nbttagcompound.setString("OwnerName", this.getOwnerName());
+ nbttagcompound.setInt("Bukkit.MaxDomestication", this.maxDomestication); // CraftBukkit
if (this.hasChest()) {
NBTTagList nbttaglist = new NBTTagList();
@@ -968,7 +992,11 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
if (nbttagcompound.hasKey("OwnerName")) {
this.setOwnerName(nbttagcompound.getString("OwnerName"));
}
-
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.MaxDomestication")) {
+ this.maxDomestication = nbttagcompound.getInt("Bukkit.MaxDomestication");
+ }
+ // CraftBukkit end
AttributeInstance attributeinstance = this.aW().a("Speed");
if (attributeinstance != null) {
@@ -1138,18 +1166,25 @@ public class EntityHorse extends EntityAnimal implements IInventoryListener {
public void u(int i) {
if (this.co()) {
+ // CraftBukkit start - fire HorseJumpEvent, use event power
if (i < 0) {
i = 0;
- } else {
- this.bI = true;
- this.cO();
}
+ float power;
if (i >= 90) {
- this.bt = 1.0F;
+ power = 1.0F;
} else {
- this.bt = 0.4F + 0.4F * (float) i / 90.0F;
+ power = 0.4F + 0.4F * (float) i / 90.0F;
+ }
+
+ org.bukkit.event.entity.HorseJumpEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callHorseJumpEvent(this, power);
+ if (!event.isCancelled()) {
+ this.bI = true;
+ this.cO();
+ this.bt = event.getPower();
}
+ // CraftBukkit end
}
}