summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityMobs.java
diff options
context:
space:
mode:
authorAndrew Ardill <andrew.ardill@gmail.com>2011-01-12 16:48:19 +1100
committerErik Broes <erikbroes@grum.nl>2011-01-16 14:14:30 +0100
commitceaf94d5bb761b54249d22de08226167319099be (patch)
tree0feb93042e96e0a5b3f74717e3b71ddb75a91069 /src/main/java/net/minecraft/server/EntityMobs.java
parent807de6ee22f665196adc48498a27223317973958 (diff)
downloadcraftbukkit-ceaf94d5bb761b54249d22de08226167319099be.tar
craftbukkit-ceaf94d5bb761b54249d22de08226167319099be.tar.gz
craftbukkit-ceaf94d5bb761b54249d22de08226167319099be.tar.lz
craftbukkit-ceaf94d5bb761b54249d22de08226167319099be.tar.xz
craftbukkit-ceaf94d5bb761b54249d22de08226167319099be.zip
Implementation of the EntityDamage*Events.
Many files were added to enable the correct hooking of these events, and a new event EntityDamageByProjectileEvent. EntityDamageByProjectileEvent adds the ability to get the projectile entity (such as an egg) and also set if the projectile 'bounces'. Only two projectiles currently respond to bouncing, Arrow and Fish - were if the fish bounces it means the fish is not hooked. Bouncing is independent of any damage caused via the event. In addition, the changes to EntityDamageEvent that enable setting post-event damage were implemented in all hooks. Finally, a bug in CraftArrow was fixed, where the constructor was not declared public.
Diffstat (limited to 'src/main/java/net/minecraft/server/EntityMobs.java')
-rw-r--r--src/main/java/net/minecraft/server/EntityMobs.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/EntityMobs.java b/src/main/java/net/minecraft/server/EntityMobs.java
new file mode 100644
index 00000000..633339a0
--- /dev/null
+++ b/src/main/java/net/minecraft/server/EntityMobs.java
@@ -0,0 +1,111 @@
+package net.minecraft.server;
+
+import java.util.Random;
+
+//CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftEntity;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.event.entity.EntityDamageByBlockEvent;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+//CraftBukkit end
+
+public class EntityMobs extends EntityCreature implements IMobs {
+
+ protected int c;
+
+ public EntityMobs(World world) {
+ super(world);
+ c = 2;
+ aZ = 20;
+ }
+
+ public void o() {
+ float f = b(1.0F);
+
+ if (f > 0.5F) {
+ bw += 2;
+ }
+ super.o();
+ }
+
+ public void b_() {
+ super.b_();
+ if (l.k == 0) {
+ q();
+ }
+ }
+
+ protected Entity l() {
+ EntityPlayer entityplayer = l.a(((Entity) (this)), 16D);
+
+ if (entityplayer != null && i(((Entity) (entityplayer)))) {
+ return ((Entity) (entityplayer));
+ } else {
+ return null;
+ }
+ }
+
+ public boolean a(Entity entity, int i) {
+ if (super.a(entity, i)) {
+ if (j == entity || k == entity) {
+ return true;
+ }
+ if (entity != this) {
+ d = entity;
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected void a(Entity entity, float f) {
+ if ((double) f < 2.5D && entity.z.e > z.b && entity.z.b < z.e) {
+ bf = 20;
+ // CraftBukkit start
+ if(entity instanceof EntityLiving) {
+ CraftServer server = ((WorldServer) l).getServer();
+ CraftEntity damagee = new CraftLivingEntity(server, (EntityLiving) entity);
+ CraftEntity damager = new CraftLivingEntity(server, this);
+
+ EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, c);
+ server.getPluginManager().callEvent(edbee);
+
+ if (!edbee.isCancelled()){
+ entity.a(((Entity) (null)), edbee.getDamage());
+ }
+ } else {
+ entity.a(((Entity) (this)), c);
+ }
+ // CraftBukkit end
+ }
+ }
+
+ protected float a(int i, int j, int k) {
+ return 0.5F - l.l(i, j, k);
+ }
+
+ public void a(NBTTagCompound nbttagcompound) {
+ super.a(nbttagcompound);
+ }
+
+ public void b(NBTTagCompound nbttagcompound) {
+ super.b(nbttagcompound);
+ }
+
+ public boolean b() {
+ int i = MathHelper.b(p);
+ int j = MathHelper.b(z.b);
+ int k = MathHelper.b(r);
+
+ if (l.a(EnumSkyBlock.a, i, j, k) > W.nextInt(32)) {
+ return false;
+ } else {
+ int i1 = l.j(i, j, k);
+
+ return i1 <= W.nextInt(8) && super.b();
+ }
+ }
+}