summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server
diff options
context:
space:
mode:
authorsunkid <sunkid@iminurnetz.com>2011-06-18 08:10:31 -0700
committerEvilSeph <evilseph@unaligned.org>2011-06-18 22:21:02 -0400
commit155874eec9cc307814dd658acba4e27a121ca9a5 (patch)
treeb5537efc7e8768ec2fd286fe8affa971c5f85fe6 /src/main/java/net/minecraft/server
parent546e1306d88978fcad3ddcfadaa2df6945a106d8 (diff)
downloadcraftbukkit-155874eec9cc307814dd658acba4e27a121ca9a5.tar
craftbukkit-155874eec9cc307814dd658acba4e27a121ca9a5.tar.gz
craftbukkit-155874eec9cc307814dd658acba4e27a121ca9a5.tar.lz
craftbukkit-155874eec9cc307814dd658acba4e27a121ca9a5.tar.xz
craftbukkit-155874eec9cc307814dd658acba4e27a121ca9a5.zip
Implemented the concept of a projectile.
Diffstat (limited to 'src/main/java/net/minecraft/server')
-rw-r--r--src/main/java/net/minecraft/server/Entity.java9
-rw-r--r--src/main/java/net/minecraft/server/EntityArrow.java18
-rw-r--r--src/main/java/net/minecraft/server/EntityEgg.java21
-rw-r--r--src/main/java/net/minecraft/server/EntityFireball.java30
-rw-r--r--src/main/java/net/minecraft/server/EntityFish.java17
-rw-r--r--src/main/java/net/minecraft/server/EntitySnowball.java21
-rw-r--r--src/main/java/net/minecraft/server/EntityTrackerEntry.java11
7 files changed, 76 insertions, 51 deletions
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index cf5bca41..5d4f1dca 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -10,6 +10,7 @@ import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.entity.CraftVehicle;
import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Projectile;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
@@ -21,6 +22,7 @@ import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
+import org.bukkit.event.entity.ProjectileHitEvent;
// CraftBukkit end
public abstract class Entity {
@@ -142,6 +144,13 @@ public abstract class Entity {
}
public void die() {
+ // CraftBukkit start
+ if (this.getBukkitEntity() instanceof Projectile && !(this instanceof EntityFish)) {
+ ProjectileHitEvent event = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
+ CraftServer server = ((WorldServer) this.world).getServer();
+ server.getPluginManager().callEvent(event);
+ }
+ // CraftBukkit end
this.dead = true;
}
diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java
index 8d0294b5..b3417858 100644
--- a/src/main/java/net/minecraft/server/EntityArrow.java
+++ b/src/main/java/net/minecraft/server/EntityArrow.java
@@ -4,6 +4,8 @@ import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -165,25 +167,25 @@ public class EntityArrow extends Entity {
// CraftBukkit start
boolean stick;
if (entity instanceof EntityLiving) {
- CraftServer server = ((WorldServer) this.world).getServer();
+ CraftServer server = this.world.getServer();
// TODO decide if we should create DamageCause.ARROW, DamageCause.PROJECTILE
// or leave as DamageCause.ENTITY_ATTACK
- org.bukkit.entity.Entity shooter = (this.shooter == null) ? null : this.shooter.getBukkitEntity();
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
- org.bukkit.entity.Entity projectile = this.getBukkitEntity();
+ Projectile projectile = (Projectile) this.getBukkitEntity();
// TODO deal with arrows being fired from a non-entity
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 4;
- EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
+ EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
+ this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle();
+
+ if (event.isCancelled()) {
+ stick = !event.getBounce();
+ } else {
// this function returns if the arrow should stick in or not, i.e. !bounce
stick = movingobjectposition.entity.damageEntity(this.shooter, event.getDamage());
- } else {
- // event was cancelled, get if the arrow should bounce or not
- stick = !event.getBounce();
}
} else {
stick = movingobjectposition.entity.damageEntity(this.shooter, 4);
diff --git a/src/main/java/net/minecraft/server/EntityEgg.java b/src/main/java/net/minecraft/server/EntityEgg.java
index 50d3c9b2..10b03af0 100644
--- a/src/main/java/net/minecraft/server/EntityEgg.java
+++ b/src/main/java/net/minecraft/server/EntityEgg.java
@@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Player;
+import org.bukkit.entity.Projectile;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
@@ -21,7 +22,7 @@ public class EntityEgg extends Entity {
private int e = 0;
private boolean f = false;
public int a = 0;
- private EntityLiving thrower;
+ public EntityLiving thrower; // CraftBukkit private -> public
private int h;
private int i = 0;
@@ -155,23 +156,21 @@ public class EntityEgg extends Entity {
if (movingobjectposition.entity != null) {
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving) {
- CraftServer server = ((WorldServer) this.world).getServer();
- org.bukkit.entity.Entity shooter = (this.thrower == null) ? null : this.thrower.getBukkitEntity();
+ CraftServer server = this.world.getServer();
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
- org.bukkit.entity.Entity projectile = this.getBukkitEntity();
+ Projectile projectile = (Projectile) this.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 0;
// TODO @see EntityArrow#162
- EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
+ EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
- // this function returns if the egg should stick or not, i.e. !bounce
- stick = movingobjectposition.entity.damageEntity(this.thrower, event.getDamage());
- } else {
- // event was cancelled, get if the egg should bounce or not
+ if (event.isCancelled()) {
stick = !event.getBounce();
+ } else {
+ // this function returns if the egg should stick in or not, i.e. !bounce
+ stick = movingobjectposition.entity.damageEntity(this.thrower, event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(this.thrower, 0);
@@ -191,7 +190,7 @@ public class EntityEgg extends Entity {
CreatureType hatchingType = CreatureType.CHICKEN;
if (this.thrower instanceof EntityPlayer) {
- CraftServer server = ((WorldServer) this.world).getServer();
+ CraftServer server = this.world.getServer();
Player player = (this.thrower == null) ? null : (Player) this.thrower.getBukkitEntity();
PlayerEggThrowEvent event = new PlayerEggThrowEvent(player, (Egg) this.getBukkitEntity(), hatching, (byte) numHatching, hatchingType);
diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java
index 0973c990..b5ee72e3 100644
--- a/src/main/java/net/minecraft/server/EntityFireball.java
+++ b/src/main/java/net/minecraft/server/EntityFireball.java
@@ -6,6 +6,8 @@ import java.util.List;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Explosive;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -45,6 +47,11 @@ public class EntityFireball extends Entity {
this.setPosition(this.locX, this.locY, this.locZ);
this.height = 0.0F;
this.motX = this.motY = this.motZ = 0.0D;
+ // CraftBukkit start (added setDirection method)
+ setDirection(d0, d1, d2);
+ }
+
+ public void setDirection(double d0, double d1, double d2) {
d0 += this.random.nextGaussian() * 0.4D;
d1 += this.random.nextGaussian() * 0.4D;
d2 += this.random.nextGaussian() * 0.4D;
@@ -127,23 +134,23 @@ public class EntityFireball extends Entity {
if (movingobjectposition.entity != null) {
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving) {
- CraftServer server = ((WorldServer) this.world).getServer();
- org.bukkit.entity.Entity shooter = (this.shooter == null) ? null : this.shooter.getBukkitEntity();
+ CraftServer server = this.world.getServer();
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
- org.bukkit.entity.Entity projectile = this.getBukkitEntity();
+ Projectile projectile = (Projectile) this.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 0;
// TODO @see EntityArrow#162
- EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
+ EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
- // this function returns if the fireball should stick or not, i.e. !bounce
- stick = movingobjectposition.entity.damageEntity(this.shooter, event.getDamage());
- } else {
- // event was cancelled, get if the fireball should bounce or not
+ this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle();
+
+ if (event.isCancelled()) {
stick = !event.getBounce();
+ } else {
+ // this function returns if the fireball should stick in or not, i.e. !bounce
+ stick = movingobjectposition.entity.damageEntity(this.shooter, event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(this.shooter, 0);
@@ -153,7 +160,7 @@ public class EntityFireball extends Entity {
}
}
- CraftServer server = ((WorldServer) this.world).getServer();
+ CraftServer server = this.world.getServer();
ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) CraftEntity.getEntity(server, this));
@@ -161,12 +168,11 @@ public class EntityFireball extends Entity {
if (!event.isCancelled()) {
// give 'this' instead of (Entity) null so we know what causes the damage
this.world.createExplosion(this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire());
- this.die();
}
// CraftBukkit end
}
- // this.die() // # CraftBukkit
+ this.die();
}
this.locX += this.motX;
diff --git a/src/main/java/net/minecraft/server/EntityFish.java b/src/main/java/net/minecraft/server/EntityFish.java
index 9b6d2a19..a004cbd6 100644
--- a/src/main/java/net/minecraft/server/EntityFish.java
+++ b/src/main/java/net/minecraft/server/EntityFish.java
@@ -4,6 +4,7 @@ import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -193,23 +194,21 @@ public class EntityFish extends Entity {
// TODO add EntityDamagedByProjectileEvent : fishing hook?
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving) {
- CraftServer server = ((WorldServer) this.world).getServer();
- org.bukkit.entity.Entity shooter = (this.owner == null) ? null : this.owner.getBukkitEntity();
+ CraftServer server = this.world.getServer();
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
- org.bukkit.entity.Entity projectile = this.getBukkitEntity();
+ Projectile projectile = (Projectile) this.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 0;
// TODO @see EntityArrow#162
- EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
+ EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
- // this function returns if the fish should stick or not, i.e. !bounce
- stick = movingobjectposition.entity.damageEntity(this.owner, event.getDamage());
- } else {
- // event was cancelled, get if the fish should bounce or not
+ if (event.isCancelled()) {
stick = !event.getBounce();
+ } else {
+ // this function returns if the fish should stick in or not, i.e. !bounce
+ stick = movingobjectposition.entity.damageEntity(this.owner, event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(this.owner, 0);
diff --git a/src/main/java/net/minecraft/server/EntitySnowball.java b/src/main/java/net/minecraft/server/EntitySnowball.java
index 96613630..1957ed93 100644
--- a/src/main/java/net/minecraft/server/EntitySnowball.java
+++ b/src/main/java/net/minecraft/server/EntitySnowball.java
@@ -4,6 +4,8 @@ import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -17,7 +19,7 @@ public class EntitySnowball extends Entity {
private int e = 0;
private boolean f = false;
public int a = 0;
- private EntityLiving shooter;
+ public EntityLiving shooter; // CraftBukkit private -> public
private int h;
private int i = 0;
@@ -151,23 +153,22 @@ public class EntitySnowball extends Entity {
if (movingobjectposition.entity != null) {
boolean stick;
if (movingobjectposition.entity instanceof EntityLiving) {
- CraftServer server = ((WorldServer) this.world).getServer();
- org.bukkit.entity.Entity shooter = (this.shooter == null) ? null : this.shooter.getBukkitEntity();
+ CraftServer server = this.world.getServer();
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
- org.bukkit.entity.Entity projectile = this.getBukkitEntity();
+ Projectile projectile = (Projectile) this.getBukkitEntity();
DamageCause damageCause = EntityDamageEvent.DamageCause.ENTITY_ATTACK;
int damage = 0;
// TODO @see EntityArrow#162
- EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(shooter, damagee, projectile, damageCause, damage);
+ EntityDamageByProjectileEvent event = new EntityDamageByProjectileEvent(damagee, projectile, damageCause, damage);
server.getPluginManager().callEvent(event);
+ this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle();
- if (!event.isCancelled()) {
- // this function returns if the snowball should stick or not, i.e. !bounce
- stick = movingobjectposition.entity.damageEntity(this.shooter, event.getDamage());
- } else {
- // event was cancelled, get if the snowball should bounce or not
+ if (event.isCancelled()) {
stick = !event.getBounce();
+ } else {
+ // this function returns if the snowball should stick in or not, i.e. !bounce
+ stick = movingobjectposition.entity.damageEntity(this.shooter, event.getDamage());
}
} else {
stick = movingobjectposition.entity.damageEntity(this.shooter, 0);
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
index 8263af85..a980738f 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
@@ -248,7 +248,16 @@ public class EntityTrackerEntry {
return new Packet23VehicleSpawn(this.tracker, 61);
} else if (this.tracker instanceof EntityFireball) {
EntityFireball entityfireball = (EntityFireball) this.tracker;
- Packet23VehicleSpawn packet23vehiclespawn = new Packet23VehicleSpawn(this.tracker, 63, ((EntityFireball) this.tracker).shooter.id);
+ // CraftBukkit start - added check for null shooter
+ // Packet23VehicleSpawn packet23vehiclespawn = new Packet23VehicleSpawn(this.tracker, 63, ((EntityFireball) this.tracker).shooter.id);
+
+ Packet23VehicleSpawn packet23vehiclespawn;
+ if (((EntityFireball) this.tracker).shooter != null) {
+ packet23vehiclespawn = new Packet23VehicleSpawn(this.tracker, 63, ((EntityFireball) this.tracker).shooter.id);
+ } else {
+ packet23vehiclespawn = new Packet23VehicleSpawn(this.tracker, 63, 1);
+ }
+ // CraftBukkit end
packet23vehiclespawn.e = (int) (entityfireball.c * 8000.0D);
packet23vehiclespawn.f = (int) (entityfireball.d * 8000.0D);