mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
SPIGOT-1319: Add EntityBreedEvent
This commit is contained in:
parent
63839165bc
commit
9af379fc47
@ -1,6 +1,14 @@
|
||||
--- a/net/minecraft/server/EntityAnimal.java
|
||||
+++ b/net/minecraft/server/EntityAnimal.java
|
||||
@@ -40,6 +40,9 @@
|
||||
@@ -7,6 +7,7 @@
|
||||
protected Block bA;
|
||||
private int bx;
|
||||
private EntityHuman by;
|
||||
+ public ItemStack breedItem; // CraftBukkit - Add breedItem variable
|
||||
|
||||
public EntityAnimal(World world) {
|
||||
super(world);
|
||||
@@ -40,6 +41,9 @@
|
||||
|
||||
}
|
||||
|
||||
@ -10,7 +18,7 @@
|
||||
public boolean damageEntity(DamageSource damagesource, float f) {
|
||||
if (this.isInvulnerable(damagesource)) {
|
||||
return false;
|
||||
@@ -48,6 +51,7 @@
|
||||
@@ -48,6 +52,7 @@
|
||||
return super.damageEntity(damagesource, f);
|
||||
}
|
||||
}
|
||||
@ -18,3 +26,11 @@
|
||||
|
||||
public float a(BlockPosition blockposition) {
|
||||
return this.world.getType(blockposition.down()).getBlock() == Blocks.GRASS ? 10.0F : this.world.n(blockposition) - 0.5F;
|
||||
@@ -120,6 +125,7 @@
|
||||
public void c(EntityHuman entityhuman) {
|
||||
this.bx = 600;
|
||||
this.by = entityhuman;
|
||||
+ this.breedItem = entityhuman.inventory.getItemInHand(); // CraftBukkit
|
||||
this.world.broadcastEntityEffect(this, (byte) 18);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/server/PathfinderGoalBreed.java
|
||||
+++ b/net/minecraft/server/PathfinderGoalBreed.java
|
||||
@@ -69,6 +69,11 @@
|
||||
@@ -69,11 +69,23 @@
|
||||
EntityAgeable entityageable = this.animal.createChild(this.partner);
|
||||
|
||||
if (entityageable != null) {
|
||||
@ -12,7 +12,19 @@
|
||||
EntityHuman entityhuman = this.animal.getBreedCause();
|
||||
|
||||
if (entityhuman == null && this.partner.getBreedCause() != null) {
|
||||
@@ -88,7 +93,7 @@
|
||||
entityhuman = this.partner.getBreedCause();
|
||||
}
|
||||
+ // CraftBukkit start - call EntityBreedEvent
|
||||
+ int experience = this.animal.getRandom().nextInt(7) + 1;
|
||||
+ org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, animal, partner, entityhuman, this.animal.breedItem, experience);
|
||||
+ if (entityBreedEvent.isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
if (entityhuman != null) {
|
||||
entityhuman.b(StatisticList.C);
|
||||
@@ -88,7 +100,7 @@
|
||||
this.partner.resetLove();
|
||||
entityageable.setAgeRaw(-24000);
|
||||
entityageable.setPositionRotation(this.animal.locX, this.animal.locY, this.animal.locZ, 0.0F, 0.0F);
|
||||
@ -21,3 +33,12 @@
|
||||
Random random = this.animal.getRandom();
|
||||
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
@@ -103,7 +115,7 @@
|
||||
}
|
||||
|
||||
if (this.a.getGameRules().getBoolean("doMobLoot")) {
|
||||
- this.a.addEntity(new EntityExperienceOrb(this.a, this.animal.locX, this.animal.locY, this.animal.locZ, random.nextInt(7) + 1));
|
||||
+ this.a.addEntity(new EntityExperienceOrb(this.a, this.animal.locX, this.animal.locY, this.animal.locZ, entityBreedEvent.getExperience())); // CraftBukkit - use event experience
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
--- a/net/minecraft/server/PathfinderGoalMakeLove.java
|
||||
+++ b/net/minecraft/server/PathfinderGoalMakeLove.java
|
||||
@@ -87,7 +87,7 @@
|
||||
@@ -80,6 +80,11 @@
|
||||
|
||||
private void i() {
|
||||
EntityVillager entityvillager = this.b.b((EntityAgeable) this.c);
|
||||
+ // CraftBukkit start - call EntityBreedEvent
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityvillager, this.b, this.c, null, null, 0).isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
this.c.setAgeRaw(6000);
|
||||
this.b.setAgeRaw(6000);
|
||||
@@ -87,7 +92,7 @@
|
||||
this.b.s(false);
|
||||
entityvillager.setAgeRaw(-24000);
|
||||
entityvillager.setPositionRotation(this.b.locX, this.b.locY, this.b.locZ, 0.0F, 0.0F);
|
||||
|
@ -1011,4 +1011,13 @@ public class CraftEventFactory {
|
||||
cloud.world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static EntityBreedEvent callEntityBreedEvent(EntityLiving child, EntityLiving mother, EntityLiving father, EntityLiving breeder, ItemStack bredWith, int experience) {
|
||||
org.bukkit.entity.LivingEntity breederEntity = (LivingEntity)(breeder == null ? null : breeder.getBukkitEntity());
|
||||
CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone();
|
||||
|
||||
EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience);
|
||||
child.world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user