2011-01-11 09:25:49 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
import org.bukkit.Location;
|
2011-11-24 21:16:43 +01:00
|
|
|
import org.bukkit.entity.Animals;
|
2011-03-07 17:32:41 +01:00
|
|
|
import org.bukkit.entity.CreatureType;
|
2011-06-18 17:10:31 +02:00
|
|
|
import org.bukkit.entity.Projectile;
|
2011-06-27 00:25:01 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
2011-07-19 22:26:00 +02:00
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
2011-01-12 06:48:19 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2011-07-14 19:46:02 +02:00
|
|
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
2011-01-11 09:44:39 +01:00
|
|
|
import org.bukkit.event.player.PlayerEggThrowEvent;
|
2011-01-11 09:25:49 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public class EntityEgg extends EntityProjectile {
|
2011-01-11 09:25:49 +01:00
|
|
|
|
|
|
|
public EntityEgg(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityEgg(World world, EntityLiving entityliving) {
|
2011-11-20 09:01:14 +01:00
|
|
|
super(world, entityliving);
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public EntityEgg(World world, double d0, double d1, double d2) {
|
2011-11-20 09:01:14 +01:00
|
|
|
super(world, d0, d1, d2);
|
2011-01-14 14:31:10 +01:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected void a(MovingObjectPosition movingobjectposition) {
|
|
|
|
// CraftBukkit start
|
|
|
|
ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
|
|
|
|
this.world.getServer().getPluginManager().callEvent(phe);
|
2011-07-14 19:46:02 +02:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (movingobjectposition.entity != null) {
|
|
|
|
boolean stick;
|
|
|
|
if (movingobjectposition.entity instanceof EntityLiving) {
|
|
|
|
org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
|
|
|
|
Projectile projectile = (Projectile) this.getBukkitEntity();
|
2011-01-12 06:48:19 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0);
|
2011-06-27 00:25:01 +02:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
stick = !projectile.doesBounce();
|
|
|
|
} else {
|
|
|
|
// this function returns if the egg should stick in or not, i.e. !bounce
|
|
|
|
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), event.getDamage());
|
2011-01-11 09:44:39 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
|
|
|
stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), 0);
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
2011-01-11 09:44:39 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (stick) {
|
|
|
|
; // Original code does nothing *yet*
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
boolean hatching = !this.world.isStatic && this.random.nextInt(8) == 0;
|
|
|
|
int numHatching = (this.random.nextInt(32) == 0) ? 4 : 1;
|
|
|
|
if (!hatching) {
|
|
|
|
numHatching = 0;
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
CreatureType hatchingType = CreatureType.CHICKEN;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (this.shooter instanceof EntityPlayer) {
|
|
|
|
org.bukkit.entity.Player player = (this.shooter == null) ? null : (org.bukkit.entity.Player) this.shooter.getBukkitEntity();
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
PlayerEggThrowEvent event = new PlayerEggThrowEvent(player, (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, (byte) numHatching, hatchingType);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-01-11 09:25:49 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
hatching = event.isHatching();
|
|
|
|
numHatching = event.getNumHatches();
|
|
|
|
hatchingType = event.getHatchType();
|
|
|
|
}
|
2011-01-11 09:25:49 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (hatching) {
|
|
|
|
for (int k = 0; k < numHatching; k++) {
|
2011-11-24 21:16:43 +01:00
|
|
|
org.bukkit.entity.Entity entity = world.getWorld().spawn(new Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass(), SpawnReason.EGG);
|
|
|
|
|
|
|
|
if (entity instanceof Animals) {
|
|
|
|
((Animals)entity).setAge(-24000);
|
|
|
|
}
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
for (int j = 0; j < 8; ++j) {
|
|
|
|
this.world.a("snowballpoof", this.locX, this.locY, this.locZ, 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
2011-01-11 09:25:49 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!this.world.isStatic) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.die();
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|