2011-01-11 09:25:49 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-02-10 15:32:11 +01:00
|
|
|
// CraftBukkit start
|
2012-03-19 20:12:17 +01:00
|
|
|
import org.bukkit.entity.Ageable;
|
2012-02-06 06:19:23 +01:00
|
|
|
import org.bukkit.entity.EntityType;
|
2012-07-22 08:18:00 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2011-06-27 00:25:01 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
2011-01-11 09:44:39 +01:00
|
|
|
import org.bukkit.event.player.PlayerEggThrowEvent;
|
2012-02-10 15:32:11 +01:00
|
|
|
// CraftBukkit end
|
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) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if (movingobjectposition.entity != null) {
|
|
|
|
movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), 0);
|
2011-01-11 09:25:49 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-03-12 23:55:02 +01:00
|
|
|
// CraftBukkit start
|
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
|
|
|
|
2012-02-06 06:19:23 +01:00
|
|
|
EntityType hatchingType = EntityType.CHICKEN;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (this.shooter instanceof EntityPlayer) {
|
2012-07-22 08:18:00 +02:00
|
|
|
Player player = (this.shooter == null) ? null : (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();
|
2012-02-06 06:19:23 +01:00
|
|
|
hatchingType = event.getHatchingType();
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
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++) {
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.entity.Entity entity = world.getWorld().spawn(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass(), SpawnReason.EGG);
|
2012-03-19 20:12:17 +01:00
|
|
|
if (entity instanceof Ageable) {
|
|
|
|
((Ageable) entity).setBaby();
|
2011-11-24 21:16:43 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|