2021-03-16 09:00:00 +11:00
|
|
|
--- a/net/minecraft/world/entity/animal/EntityAnimal.java
|
|
|
|
+++ b/net/minecraft/world/entity/animal/EntityAnimal.java
|
2024-06-22 18:46:41 +10:00
|
|
|
@@ -29,12 +29,20 @@
|
2022-06-08 02:00:00 +10:00
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2021-03-16 09:00:00 +11:00
|
|
|
import net.minecraft.world.level.pathfinder.PathType;
|
2021-03-09 08:47:33 +11:00
|
|
|
|
2020-06-26 11:12:25 +10:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
2023-06-24 17:15:05 +10:00
|
|
|
+import org.bukkit.event.entity.EntityBreedEvent;
|
2024-06-22 18:46:41 +10:00
|
|
|
+import org.bukkit.event.entity.EntityDamageEvent;
|
2020-06-26 11:12:25 +10:00
|
|
|
+import org.bukkit.event.entity.EntityEnterLoveModeEvent;
|
|
|
|
+// CraftBukkit end
|
2021-03-09 08:47:33 +11:00
|
|
|
+
|
2020-06-26 11:12:25 +10:00
|
|
|
public abstract class EntityAnimal extends EntityAgeable {
|
2019-06-21 20:00:00 +10:00
|
|
|
|
2022-06-08 02:00:00 +10:00
|
|
|
protected static final int PARENT_AGE_AFTER_BREEDING = 6000;
|
2021-06-11 15:00:00 +10:00
|
|
|
public int inLove;
|
2021-11-22 09:00:00 +11:00
|
|
|
@Nullable
|
2021-06-11 15:00:00 +10:00
|
|
|
public UUID loveCause;
|
2016-06-18 22:00:39 -07:00
|
|
|
+ public ItemStack breedItem; // CraftBukkit - Add breedItem variable
|
|
|
|
|
2019-04-23 12:00:00 +10:00
|
|
|
protected EntityAnimal(EntityTypes<? extends EntityAnimal> entitytypes, World world) {
|
2018-07-15 10:00:00 +10:00
|
|
|
super(entitytypes, world);
|
2024-06-22 18:46:41 +10:00
|
|
|
@@ -72,9 +80,15 @@
|
2024-04-24 01:15:00 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- protected void actuallyHurt(DamageSource damagesource, float f) {
|
|
|
|
+ // CraftBukkit start - void -> boolean
|
2024-06-22 18:46:41 +10:00
|
|
|
+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) {
|
|
|
|
+ boolean damageResult = super.actuallyHurt(damagesource, f, event);
|
|
|
|
+ if (!damageResult) {
|
|
|
|
+ return false;
|
2024-04-24 01:15:00 +10:00
|
|
|
+ }
|
|
|
|
this.resetLove();
|
|
|
|
- super.actuallyHurt(damagesource, f);
|
2024-06-22 18:46:41 +10:00
|
|
|
+ return true;
|
2024-04-24 01:15:00 +10:00
|
|
|
+ // CraftBukkit end
|
2014-12-09 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2024-04-24 01:15:00 +10:00
|
|
|
@Override
|
2024-06-22 18:46:41 +10:00
|
|
|
@@ -162,10 +176,17 @@
|
2020-06-26 11:12:25 +10:00
|
|
|
}
|
|
|
|
|
2021-11-22 09:00:00 +11:00
|
|
|
public void setInLove(@Nullable EntityHuman entityhuman) {
|
2021-06-11 15:00:00 +10:00
|
|
|
- this.inLove = 600;
|
2020-06-26 11:12:25 +10:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(entityhuman, this, 600);
|
|
|
|
+ if (entityEnterLoveModeEvent.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2021-06-11 15:00:00 +10:00
|
|
|
+ this.inLove = entityEnterLoveModeEvent.getTicksInLove();
|
2020-06-26 11:12:25 +10:00
|
|
|
+ // CraftBukkit end
|
2017-05-14 12:00:00 +10:00
|
|
|
if (entityhuman != null) {
|
2021-11-22 09:00:00 +11:00
|
|
|
this.loveCause = entityhuman.getUUID();
|
2017-05-14 12:00:00 +10:00
|
|
|
}
|
2021-11-22 09:00:00 +11:00
|
|
|
+ this.breedItem = entityhuman.getInventory().getSelected(); // CraftBukkit
|
2017-05-14 12:00:00 +10:00
|
|
|
|
2023-06-08 01:30:00 +10:00
|
|
|
this.level().broadcastEntityEvent(this, (byte) 18);
|
2016-06-18 22:00:39 -07:00
|
|
|
}
|
2024-06-22 18:46:41 +10:00
|
|
|
@@ -207,12 +228,29 @@
|
2023-06-08 19:22:25 +10:00
|
|
|
if (entityageable != null) {
|
2023-06-08 01:30:00 +10:00
|
|
|
entityageable.setBaby(true);
|
|
|
|
entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
|
2023-06-08 19:22:25 +10:00
|
|
|
- this.finalizeSpawnChildFromBreeding(worldserver, entityanimal, entityageable);
|
2021-11-22 09:00:00 +11:00
|
|
|
- worldserver.addFreshEntityWithPassengers(entityageable);
|
2023-06-08 19:22:25 +10:00
|
|
|
+ // 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;
|
2023-06-24 17:15:05 +10:00
|
|
|
+ EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, entityanimal, breeder, this.breedItem, experience);
|
2023-06-08 19:22:25 +10:00
|
|
|
+ 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
|
2023-06-08 01:30:00 +10:00
|
|
|
}
|
|
|
|
}
|
2020-06-25 10:00:00 +10:00
|
|
|
|
2023-06-08 01:30:00 +10:00
|
|
|
public void finalizeSpawnChildFromBreeding(WorldServer worldserver, EntityAnimal entityanimal, @Nullable EntityAgeable entityageable) {
|
2023-06-08 19:22:25 +10:00
|
|
|
+ // 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(() -> {
|
2023-06-08 01:30:00 +10:00
|
|
|
return Optional.ofNullable(entityanimal.getLoveCause());
|
2023-06-08 19:22:25 +10:00
|
|
|
}).ifPresent((entityplayer) -> {
|
2024-06-22 18:46:41 +10:00
|
|
|
@@ -225,7 +263,11 @@
|
2023-06-08 01:30:00 +10:00
|
|
|
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
|
2020-06-25 10:00:00 +10:00
|
|
|
}
|
2023-06-08 01:30:00 +10:00
|
|
|
|
|
|
|
}
|