PaperMC/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEgg.patch
CraftBukkit/Spigot eed041d629 Update to Minecraft 1.21
By: md_5 <git@md-5.net>
2024-06-14 01:05:00 +10:00

83 lines
3.7 KiB
Diff

--- a/net/minecraft/world/entity/projectile/EntityEgg.java
+++ b/net/minecraft/world/entity/projectile/EntityEgg.java
@@ -12,6 +12,16 @@
import net.minecraft.world.phys.MovingObjectPosition;
import net.minecraft.world.phys.MovingObjectPositionEntity;
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+import net.minecraft.world.entity.Entity;
+import org.bukkit.entity.Ageable;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+// CraftBukkit end
+
public class EntityEgg extends EntityProjectileThrowable {
private static final EntitySize ZERO_SIZED_DIMENSIONS = EntitySize.fixed(0.0F, 0.0F);
@@ -50,30 +60,58 @@
protected void onHit(MovingObjectPosition movingobjectposition) {
super.onHit(movingobjectposition);
if (!this.level().isClientSide) {
- if (this.random.nextInt(8) == 0) {
+ // CraftBukkit start
+ boolean hatching = this.random.nextInt(8) == 0;
+ if (true) {
+ // CraftBukkit end
byte b0 = 1;
if (this.random.nextInt(32) == 0) {
b0 = 4;
}
+ // CraftBukkit start
+ EntityType hatchingType = EntityType.CHICKEN;
+
+ Entity shooter = this.getOwner();
+ if (!hatching) {
+ b0 = 0;
+ }
+ if (shooter instanceof EntityPlayer) {
+ PlayerEggThrowEvent event = new PlayerEggThrowEvent((Player) shooter.getBukkitEntity(), (org.bukkit.entity.Egg) this.getBukkitEntity(), hatching, b0, hatchingType);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ b0 = event.getNumHatches();
+ hatching = event.isHatching();
+ hatchingType = event.getHatchingType();
+ // If hatching is set to false, ensure child count is 0
+ if (!hatching) {
+ b0 = 0;
+ }
+ }
+ // CraftBukkit end
+
for (int i = 0; i < b0; ++i) {
- EntityChicken entitychicken = (EntityChicken) EntityTypes.CHICKEN.create(this.level());
+ 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
if (entitychicken != null) {
- entitychicken.setAge(-24000);
+ // CraftBukkit start
+ if (entitychicken.getBukkitEntity() instanceof Ageable) {
+ ((Ageable) entitychicken.getBukkitEntity()).setBaby();
+ }
+ // CraftBukkit end
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
}
}
}
this.level().broadcastEntityEvent(this, (byte) 3);
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
}
}