2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/entity/projectile/EntityEgg.java
|
|
|
|
+++ b/net/minecraft/world/entity/projectile/EntityEgg.java
|
2024-06-13 17:05:00 +02:00
|
|
|
@@ -12,6 +12,16 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.phys.MovingObjectPositionEntity;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.server.level.EntityPlayer;
|
|
|
|
+import net.minecraft.world.entity.Entity;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.entity.Ageable;
|
|
|
|
+import org.bukkit.entity.EntityType;
|
|
|
|
+import org.bukkit.entity.Player;
|
2024-02-21 10:55:34 +01:00
|
|
|
+import org.bukkit.event.entity.EntityRemoveEvent;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.event.player.PlayerEggThrowEvent;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
2019-04-23 04:00:00 +02:00
|
|
|
public class EntityEgg extends EntityProjectileThrowable {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2024-06-13 17:05:00 +02:00
|
|
|
private static final EntitySize ZERO_SIZED_DIMENSIONS = EntitySize.fixed(0.0F, 0.0F);
|
|
|
|
@@ -50,30 +60,58 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
protected void onHit(MovingObjectPosition movingobjectposition) {
|
|
|
|
super.onHit(movingobjectposition);
|
2023-06-07 17:30:00 +02:00
|
|
|
if (!this.level().isClientSide) {
|
2016-11-17 02:41:03 +01:00
|
|
|
- if (this.random.nextInt(8) == 0) {
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ boolean hatching = this.random.nextInt(8) == 0;
|
2016-11-17 02:41:03 +01:00
|
|
|
+ if (true) {
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // CraftBukkit end
|
2016-11-17 02:41:03 +01:00
|
|
|
byte b0 = 1;
|
|
|
|
|
|
|
|
if (this.random.nextInt(32) == 0) {
|
|
|
|
b0 = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ EntityType hatchingType = EntityType.CHICKEN;
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
+ Entity shooter = this.getOwner();
|
2023-06-24 09:15:05 +02:00
|
|
|
+ if (!hatching) {
|
|
|
|
+ b0 = 0;
|
|
|
|
+ }
|
2016-11-17 02:41:03 +01:00
|
|
|
+ if (shooter instanceof EntityPlayer) {
|
|
|
|
+ PlayerEggThrowEvent event = new PlayerEggThrowEvent((Player) shooter.getBukkitEntity(), (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
|
2023-06-07 17:30:00 +02:00
|
|
|
+ this.level().getCraftServer().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();
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // If hatching is set to false, ensure child count is 0
|
|
|
|
+ if (!hatching) {
|
|
|
|
+ b0 = 0;
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
|
|
|
for (int i = 0; i < b0; ++i) {
|
|
|
|
- EntityChicken entitychicken = (EntityChicken) EntityTypes.CHICKEN.create(this.level());
|
2023-11-19 07:03:35 +01:00
|
|
|
+ Entity entitychicken = this.level().getWorld().makeEntity(new org.bukkit.Location(this.level().getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F), hatchingType.getEntityClass()); // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2023-06-24 09:15:05 +02:00
|
|
|
if (entitychicken != null) {
|
2022-12-07 17:00:00 +01:00
|
|
|
- entitychicken.setAge(-24000);
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (entitychicken.getBukkitEntity() instanceof Ageable) {
|
|
|
|
+ ((Ageable) entitychicken.getBukkitEntity()).setBaby();
|
2016-11-17 02:41:03 +01:00
|
|
|
+ }
|
2023-06-24 09:15:05 +02:00
|
|
|
+ // CraftBukkit end
|
2024-06-13 17:05:00 +02:00
|
|
|
entitychicken.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
|
|
|
|
if (!entitychicken.fudgePositionAfterSizeChange(EntityEgg.ZERO_SIZED_DIMENSIONS)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.level().addFreshEntity(entitychicken);
|
|
|
|
+ this.level().addFreshEntity(entitychicken, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // CraftBukkit
|
2022-12-07 17:00:00 +01:00
|
|
|
}
|
2016-11-17 02:41:03 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-21 10:55:34 +01:00
|
|
|
|
|
|
|
this.level().broadcastEntityEvent(this, (byte) 3);
|
|
|
|
- this.discard();
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|