@@ -36,26 +36,44 @@ protected void onHit(final HitResult result) {
3636 super .onHit (result );
3737 if (!this .level ().isClientSide ) {
3838 boolean hatching = this .random .nextInt (8 ) == 0 ;
39- byte b0 = 1 ;
39+ int hatches = 1 ;
4040 if (this .random .nextInt (32 ) == 0 ) {
41- b0 = 4 ;
41+ hatches = 4 ;
4242 }
4343 if (!hatching ) {
44- b0 = 0 ;
44+ hatches = 0 ;
4545 }
4646 org .bukkit .entity .EntityType hatchingType = org .bukkit .entity .EntityType .CHICKEN ;
4747 Entity shooter = this .getOwner ();
4848 if (shooter instanceof ServerPlayer ) {
49- PlayerEggThrowEvent event = new PlayerEggThrowEvent (((ServerPlayerEntityBridge ) shooter ).bridge$getBukkitEntity (), (Egg ) this .getBukkitEntity (), hatching , b0 , hatchingType );
49+ PlayerEggThrowEvent event = new PlayerEggThrowEvent (((ServerPlayerEntityBridge ) shooter ).bridge$getBukkitEntity (), (Egg ) this .getBukkitEntity (), hatching , ( byte ) hatches , hatchingType );
5050 Bukkit .getPluginManager ().callEvent (event );
51- b0 = event .getNumHatches ();
51+ hatches = event .getNumHatches ();
5252 hatching = event .isHatching ();
5353 hatchingType = event .getHatchingType ();
5454 }
55- if (hatching ) {
56- for (int i = 0 ; i < b0 ; ++i ) {
55+ if (hatching && hatchingType == org .bukkit .entity .EntityType .CHICKEN ) {
56+ for (int i = 0 ; i < hatches ; ++i ) {
57+ // Preserve an explicit Chicken local and the vanilla-like hatch path for mod compatibility.
58+ // - Meadow / Let's Do keeps relying on a Chicken local-store shape (#1149).
59+ // - VanillaBackport captures locals around addFreshEntity(Chicken) on this path (#2112).
60+ Chicken chicken = net .minecraft .world .entity .EntityType .CHICKEN .create (this .level ());
61+ if (chicken != null ) {
62+ Blackhole .consume (chicken );
63+ chicken .setAge (-24000 );
64+ chicken .moveTo (this .getX (), this .getY (), this .getZ (), this .getYRot (), 0.0F );
65+ if (!chicken .fudgePositionAfterSizeChange (ZERO_SIZED_DIMENSIONS )) {
66+ break ;
67+ }
68+ ((WorldBridge ) this .level ()).bridge$pushAddEntityReason (CreatureSpawnEvent .SpawnReason .EGG );
69+ this .level ().addFreshEntity (chicken );
70+ }
71+ }
72+ } else if (hatching ) {
73+ for (int i = 0 ; i < hatches ; ++i ) {
5774 // TrickOrTreatMod compat https://github.com/IzzelAliz/Arclight/issues/1178
5875 // https://github.com/MehVahdJukaar/TrickOrTreatMod/blob/020bc478b8f8de6bfec2191a9e667f423f45d7db/common/src/main/java/net/mehvahdjukaar/hauntedharvest/mixins/ThrownEggEntityMixin.java
76+ // Keep the non-chicken fallback on EntityType#create(Level) for existing compat expectations.
5977 var entityType = ((EntityTypeBridge ) (Object ) hatchingType ).bridge$getHandle ();
6078 var entity = entityType .create (this .level ());
6179 // Let's do: Meadow mixin compatibility https://github.com/IzzelAliz/Arclight/issues/1149
0 commit comments