2023-11-12 00:23:02 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Thu, 15 Dec 2022 00:14:44 -0800
|
|
|
|
Subject: [PATCH] Fix several issues with EntityBreedEvent
|
|
|
|
|
|
|
|
Upstream did not account for different hands when storing
|
|
|
|
the breed item for later use in the event. Also they only
|
|
|
|
stored a reference to the stack, not a copy so if the stack
|
|
|
|
changed after love mode was started, the breed item in the event
|
|
|
|
also changed. Also in several places, the breed item was stored after
|
|
|
|
it was decreased by one to consume the item.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Animal.java b/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
2024-10-24 12:11:32 +02:00
|
|
|
index 775bfac26aaa6db998c2647ec81247b67d0bf784..5677dc97ed83652f261100cf391883cfac7d16fe 100644
|
2023-11-12 00:23:02 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -158,8 +158,9 @@ public abstract class Animal extends AgeableMob {
|
2023-11-12 00:23:02 +01:00
|
|
|
int i = this.getAge();
|
|
|
|
|
|
|
|
if (!this.level().isClientSide && i == 0 && this.canFallInLove()) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ final ItemStack breedCopy = itemstack.copy(); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
this.usePlayerItem(player, hand, itemstack);
|
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, breedCopy); // Paper - Fix EntityBreedEvent copying
|
2024-10-24 12:11:32 +02:00
|
|
|
this.playEatingSound();
|
|
|
|
return InteractionResult.SUCCESS_SERVER;
|
2023-11-12 00:23:02 +01:00
|
|
|
}
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -201,10 +202,18 @@ public abstract class Animal extends AgeableMob {
|
2023-11-12 00:23:02 +01:00
|
|
|
return this.inLove <= 0;
|
|
|
|
}
|
|
|
|
|
2024-01-13 18:34:33 +01:00
|
|
|
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
public void setInLove(@Nullable Player player) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
+ this.setInLove(player, null);
|
|
|
|
+ }
|
|
|
|
+ public void setInLove(@Nullable Player player, @Nullable ItemStack breedItemCopy) {
|
|
|
|
+ if (breedItemCopy != null) this.breedItem = breedItemCopy;
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(player, this, 600);
|
|
|
|
if (entityEnterLoveModeEvent.isCancelled()) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.breedItem = null; // Paper - Fix EntityBreedEvent copying; clear if cancelled
|
2023-11-12 00:23:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.inLove = entityEnterLoveModeEvent.getTicksInLove();
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -212,7 +221,7 @@ public abstract class Animal extends AgeableMob {
|
2023-11-12 00:23:02 +01:00
|
|
|
if (player != null) {
|
|
|
|
this.loveCause = player.getUUID();
|
|
|
|
}
|
|
|
|
- this.breedItem = player.getInventory().getSelected(); // CraftBukkit
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper - Fix EntityBreedEvent copying; set breed item in better place
|
2023-11-12 00:23:02 +01:00
|
|
|
|
|
|
|
this.level().broadcastEntityEvent(this, (byte) 18);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Panda.java b/src/main/java/net/minecraft/world/entity/animal/Panda.java
|
2024-10-24 12:11:32 +02:00
|
|
|
index b654bec0fbe903fac24f3bb99399455bf367c68a..be753557d7ebd6f1e82b1bdb6d60ecc450f72eec 100644
|
2023-11-12 00:23:02 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Panda.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Panda.java
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -653,8 +653,9 @@ public class Panda extends Animal {
|
2023-11-12 00:23:02 +01:00
|
|
|
this.usePlayerItem(player, hand, itemstack);
|
|
|
|
this.ageUp((int) ((float) (-this.getAge() / 20) * 0.1F), true);
|
|
|
|
} else if (!this.level().isClientSide && this.getAge() == 0 && this.canFallInLove()) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ final ItemStack breedCopy = itemstack.copy(); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
this.usePlayerItem(player, hand, itemstack);
|
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, breedCopy); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
} else {
|
2024-10-24 12:11:32 +02:00
|
|
|
Level world = this.level();
|
2024-04-28 03:18:20 +02:00
|
|
|
|
2023-11-12 00:23:02 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java b/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
|
2024-10-24 12:11:32 +02:00
|
|
|
index c99d37a40c63726c11980adccc67d09fd5132885..f3c884ab9c09f04dd01cabf2ee9de3b5b620563d 100644
|
2023-11-12 00:23:02 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -395,7 +395,7 @@ public class Camel extends AbstractHorse {
|
2024-03-09 00:52:00 +01:00
|
|
|
boolean flag1 = this.isTamed() && this.getAge() == 0 && this.canFallInLove();
|
2023-11-12 00:23:02 +01:00
|
|
|
|
2024-03-09 00:52:00 +01:00
|
|
|
if (flag1) {
|
2023-11-12 00:23:02 +01:00
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, item.copy()); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
}
|
|
|
|
|
2024-03-09 00:52:00 +01:00
|
|
|
boolean flag2 = this.isBaby();
|
2023-11-12 00:23:02 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
|
2024-10-24 12:11:32 +02:00
|
|
|
index 74151d69380e4adede40c7d7fc20834553706730..8aed30cdbbfdd42c20dcd4c8773c8a0ee21a980d 100644
|
2023-11-12 00:23:02 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/AbstractHorse.java
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -585,7 +585,7 @@ public abstract class AbstractHorse extends Animal implements ContainerListener,
|
2023-11-12 00:23:02 +01:00
|
|
|
b0 = 5;
|
|
|
|
if (!this.level().isClientSide && this.isTamed() && this.getAge() == 0 && !this.isInLove()) {
|
|
|
|
flag = true;
|
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, item.copy()); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
}
|
|
|
|
} else if (item.is(Items.GOLDEN_APPLE) || item.is(Items.ENCHANTED_GOLDEN_APPLE)) {
|
|
|
|
f = 10.0F;
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -593,7 +593,7 @@ public abstract class AbstractHorse extends Animal implements ContainerListener,
|
2023-11-12 00:23:02 +01:00
|
|
|
b0 = 10;
|
|
|
|
if (!this.level().isClientSide && this.isTamed() && this.getAge() == 0 && !this.isInLove()) {
|
|
|
|
flag = true;
|
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, item.copy()); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/Llama.java b/src/main/java/net/minecraft/world/entity/animal/horse/Llama.java
|
2024-10-24 12:11:32 +02:00
|
|
|
index 4da66867109394c8966e27551d20b4bcdf4bc9be..18bd483fe46de3d9dc129bffbccfba9d4cab9550 100644
|
2023-11-12 00:23:02 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/horse/Llama.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/Llama.java
|
2024-10-24 12:11:32 +02:00
|
|
|
@@ -177,7 +177,7 @@ public class Llama extends AbstractChestedHorse implements VariantHolder<Llama.V
|
2023-11-12 00:23:02 +01:00
|
|
|
f = 10.0F;
|
|
|
|
if (this.isTamed() && this.getAge() == 0 && this.canFallInLove()) {
|
|
|
|
flag = true;
|
|
|
|
- this.setInLove(player);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.setInLove(player, item.copy()); // Paper - Fix EntityBreedEvent copying
|
2023-11-12 00:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|