Paper/nms-patches/EntityEgg.patch

63 lines
2.6 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityEgg.java
+++ b/net/minecraft/server/EntityEgg.java
@@ -1,5 +1,12 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.entity.Ageable;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public class EntityEgg extends EntityProjectileThrowable {
2019-04-23 04:00:00 +02:00
public EntityEgg(EntityTypes<? extends EntityEgg> entitytypes, World world) {
@@ -21,20 +28,40 @@
}
2016-11-17 02:41:03 +01:00
if (!this.world.isClientSide) {
- if (this.random.nextInt(8) == 0) {
+ boolean hatching = this.random.nextInt(8) == 0; // CraftBukkit
+ if (true) {
byte b0 = 1;
if (this.random.nextInt(32) == 0) {
b0 = 4;
}
- for (int i = 0; i < b0; ++i) {
2019-04-23 04:00:00 +02:00
- EntityChicken entitychicken = (EntityChicken) EntityTypes.CHICKEN.a(this.world);
2016-11-17 02:41:03 +01:00
+ // CraftBukkit start
+ if (!hatching) {
+ b0 = 0;
+ }
+ EntityType hatchingType = EntityType.CHICKEN;
2015-02-26 23:41:06 +01:00
+
2016-11-17 02:41:03 +01:00
+ Entity shooter = this.getShooter();
+ if (shooter instanceof EntityPlayer) {
+ PlayerEggThrowEvent event = new PlayerEggThrowEvent((Player) shooter.getBukkitEntity(), (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
+ this.world.getServer().getPluginManager().callEvent(event);
2015-02-26 23:41:06 +01:00
+
2016-11-17 02:41:03 +01:00
+ b0 = event.getNumHatches();
+ hatching = event.isHatching();
+ hatchingType = event.getHatchingType();
+ }
2016-11-17 02:41:03 +01:00
- entitychicken.setAgeRaw(-24000);
- entitychicken.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, 0.0F);
- this.world.addEntity(entitychicken);
+ if (hatching) {
+ for (int i = 0; i < b0; ++i) {
+ Entity entity = world.getWorld().createEntity(new org.bukkit.Location(world.getWorld(), this.locX, this.locY, this.locZ, this.yaw, 0.0F), hatchingType.getEntityClass());
+ if (entity.getBukkitEntity() instanceof Ageable) {
+ ((Ageable) entity.getBukkitEntity()).setBaby();
+ }
+ world.getWorld().addEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG);
+ }
}
+ // CraftBukkit end
}
2016-11-17 02:41:03 +01:00
this.world.broadcastEntityEffect(this, (byte) 3);