PaperMC/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch
CraftBukkit/Spigot 99be5d2a3c SPIGOT-7375: Fix crash breeding certain entities
By: md_5 <git@md-5.net>
2023-06-08 19:22:25 +10:00

104 lines
4.6 KiB
Diff

--- a/net/minecraft/world/entity/animal/EntityAnimal.java
+++ b/net/minecraft/world/entity/animal/EntityAnimal.java
@@ -30,12 +30,19 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.pathfinder.PathType;
+// CraftBukkit start
+import net.minecraft.world.entity.EntityTameableAnimal;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityEnterLoveModeEvent;
+// CraftBukkit end
+
public abstract class EntityAnimal extends EntityAgeable {
protected static final int PARENT_AGE_AFTER_BREEDING = 6000;
public int inLove;
@Nullable
public UUID loveCause;
+ public ItemStack breedItem; // CraftBukkit - Add breedItem variable
protected EntityAnimal(EntityTypes<? extends EntityAnimal> entitytypes, World world) {
super(entitytypes, world);
@@ -72,6 +79,9 @@
}
+ /* CraftBukkit start
+ // Function disabled as it has no special function anymore after
+ // setSitting is disabled.
@Override
public boolean hurt(DamageSource damagesource, float f) {
if (this.isInvulnerableTo(damagesource)) {
@@ -81,6 +91,7 @@
return super.hurt(damagesource, f);
}
}
+ // CraftBukkit end */
@Override
public float getWalkTargetValue(BlockPosition blockposition, IWorldReader iworldreader) {
@@ -175,10 +186,17 @@
}
public void setInLove(@Nullable EntityHuman entityhuman) {
- this.inLove = 600;
+ // CraftBukkit start
+ EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(entityhuman, this, 600);
+ if (entityEnterLoveModeEvent.isCancelled()) {
+ return;
+ }
+ this.inLove = entityEnterLoveModeEvent.getTicksInLove();
+ // CraftBukkit end
if (entityhuman != null) {
this.loveCause = entityhuman.getUUID();
}
+ this.breedItem = entityhuman.getInventory().getSelected(); // CraftBukkit
this.level().broadcastEntityEvent(this, (byte) 18);
}
@@ -220,12 +238,29 @@
if (entityageable != null) {
entityageable.setBaby(true);
entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
- this.finalizeSpawnChildFromBreeding(worldserver, entityanimal, entityageable);
- worldserver.addFreshEntityWithPassengers(entityageable);
+ // CraftBukkit start - call EntityBreedEvent
+ EntityPlayer breeder = Optional.ofNullable(this.getLoveCause()).or(() -> {
+ return Optional.ofNullable(entityanimal.getLoveCause());
+ }).orElse(null);
+ int experience = this.getRandom().nextInt(7) + 1;
+ org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, entityanimal, breeder, this.breedItem, experience);
+ if (entityBreedEvent.isCancelled()) {
+ return;
+ }
+ experience = entityBreedEvent.getExperience();
+ this.finalizeSpawnChildFromBreeding(worldserver, entityanimal, entityageable, experience);
+ worldserver.addFreshEntityWithPassengers(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING);
+ // CraftBukkit end
}
}
public void finalizeSpawnChildFromBreeding(WorldServer worldserver, EntityAnimal entityanimal, @Nullable EntityAgeable entityageable) {
+ // CraftBukkit start
+ this.finalizeSpawnChildFromBreeding(worldserver, entityanimal, entityageable, this.getRandom().nextInt(7) + 1);
+ }
+
+ public void finalizeSpawnChildFromBreeding(WorldServer worldserver, EntityAnimal entityanimal, @Nullable EntityAgeable entityageable, int experience) {
+ // CraftBukkit end
Optional.ofNullable(this.getLoveCause()).or(() -> {
return Optional.ofNullable(entityanimal.getLoveCause());
}).ifPresent((entityplayer) -> {
@@ -238,7 +273,11 @@
entityanimal.resetLove();
worldserver.broadcastEntityEvent(this, (byte) 18);
if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
- worldserver.addFreshEntity(new EntityExperienceOrb(worldserver, this.getX(), this.getY(), this.getZ(), this.getRandom().nextInt(7) + 1));
+ // CraftBukkit start - use event experience
+ if (experience > 0) {
+ worldserver.addFreshEntity(new EntityExperienceOrb(worldserver, this.getX(), this.getY(), this.getZ(), experience));
+ }
+ // CraftBukkit end
}
}