craftbukkit/src/main/java/net/minecraft/server/EntityEgg.java

69 lines
2.3 KiB
Java
Raw Normal View History

2011-01-11 03:25:49 -05:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.entity.Ageable;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
2011-01-11 03:44:39 -05:00
import org.bukkit.event.player.PlayerEggThrowEvent;
// CraftBukkit end
2011-01-11 03:25:49 -05:00
2011-11-20 00:01:14 -08:00
public class EntityEgg extends EntityProjectile {
2011-01-11 03:25:49 -05:00
public EntityEgg(World world) {
super(world);
}
public EntityEgg(World world, EntityLiving entityliving) {
2011-11-20 00:01:14 -08:00
super(world, entityliving);
2011-01-11 03:25:49 -05:00
}
2011-01-29 22:50:29 +01:00
public EntityEgg(World world, double d0, double d1, double d2) {
2011-11-20 00:01:14 -08:00
super(world, d0, d1, d2);
2011-01-14 13:31:10 +00:00
}
2011-11-20 00:01:14 -08:00
protected void a(MovingObjectPosition movingobjectposition) {
2012-07-29 02:33:13 -05:00
if (movingobjectposition.entity != null) {
2012-11-06 06:05:28 -06:00
movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0);
2011-01-11 03:25:49 -05:00
}
2011-01-29 22:50:29 +01:00
// CraftBukkit start
2011-11-20 00:01:14 -08: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 03:25:49 -05:00
}
2011-01-29 22:50:29 +01:00
EntityType hatchingType = EntityType.CHICKEN;
2011-01-29 22:50:29 +01:00
2012-11-06 06:05:28 -06:00
Entity shooter = this.getShooter();
if (shooter instanceof EntityPlayer) {
Player player = (shooter == null) ? null : (Player) shooter.getBukkitEntity();
2011-01-29 22:50:29 +01:00
2011-11-20 00:01:14 -08: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 03:25:49 -05:00
2011-11-20 00:01:14 -08:00
hatching = event.isHatching();
numHatching = event.getNumHatches();
hatchingType = event.getHatchingType();
2011-11-20 00:01:14 -08:00
}
2011-01-11 03:25:49 -05:00
2011-11-20 00:01:14 -08:00
if (hatching) {
for (int k = 0; k < numHatching; k++) {
2012-09-14 00:03:47 -05: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(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG);
if (entity instanceof Ageable) {
((Ageable) entity).setBaby();
}
2011-01-11 03:25:49 -05:00
}
}
2011-11-20 00:01:14 -08:00
// CraftBukkit end
2011-01-29 22:50:29 +01:00
2011-11-20 00:01:14 -08:00
for (int j = 0; j < 8; ++j) {
this.world.addParticle("snowballpoof", this.locX, this.locY, this.locZ, 0.0D, 0.0D, 0.0D);
2011-11-20 00:01:14 -08:00
}
2011-01-11 03:25:49 -05:00
2011-11-20 00:01:14 -08:00
if (!this.world.isStatic) {
this.die();
2011-01-11 03:25:49 -05:00
}
}
}