--- a/net/minecraft/world/entity/animal/EntityAnimal.java +++ b/net/minecraft/world/entity/animal/EntityAnimal.java @@ -29,12 +29,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 entitytypes, World world) { super(entitytypes, world); @@ -71,6 +78,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)) { @@ -80,6 +90,7 @@ return super.hurt(damagesource, f); } } + // CraftBukkit end */ @Override public float getWalkTargetValue(BlockPosition blockposition, IWorldReader iworldreader) { @@ -174,10 +185,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); } @@ -222,6 +240,16 @@ if (entityplayer == null && entityanimal.getLoveCause() != null) { entityplayer = entityanimal.getLoveCause(); } + // CraftBukkit start - call EntityBreedEvent + entityageable.setBaby(true); + entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); + int experience = this.getRandom().nextInt(7) + 1; + org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, entityanimal, entityplayer, this.breedItem, experience); + if (entityBreedEvent.isCancelled()) { + return; + } + experience = entityBreedEvent.getExperience(); + // CraftBukkit end if (entityplayer != null) { entityplayer.awardStat(StatisticList.ANIMALS_BRED); @@ -232,12 +260,14 @@ entityanimal.setAge(6000); this.resetLove(); entityanimal.resetLove(); - entityageable.setBaby(true); - entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); - worldserver.addFreshEntityWithPassengers(entityageable); + worldserver.addFreshEntityWithPassengers(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason 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 } }