2023-09-17 01:27:11 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
|
|
|
|
Date: Thu, 31 Aug 2023 17:32:48 +0200
|
|
|
|
Subject: [PATCH] Fix silent equipment change for mobs
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
index d1833dcc92b1570e62a1941bbea6d66ff0b2ee5f..4e8aee81cb9e9fe4a4e5df4e228c0314b3af486b 100644
|
2023-09-17 01:27:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -1047,13 +1047,20 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
2023-09-17 01:27:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper start - Fix silent equipment change
|
2023-09-17 01:27:11 +02:00
|
|
|
+ setItemSlot(slot, stack, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - Fix silent equipment change
|
2023-09-17 01:27:11 +02:00
|
|
|
this.verifyEquippedItem(stack);
|
|
|
|
switch (slot.getType()) {
|
|
|
|
case HAND:
|
|
|
|
- this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
|
2023-09-17 01:27:11 +02:00
|
|
|
break;
|
|
|
|
case ARMOR:
|
|
|
|
- this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
|
2023-09-17 01:27:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
2024-01-21 19:37:09 +01:00
|
|
|
index 40664cc7e3665432a2ab5e552802c3fc3edbdb22..586e3e92ccc275446df6dbbff9bf010a37a9aa8f 100644
|
2023-09-17 01:27:11 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
|
|
@@ -250,8 +250,8 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
2024-01-19 17:54:05 +01:00
|
|
|
// Paper end - shouldBurnInDay API
|
2023-09-17 01:27:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
- public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
|
|
|
- super.setItemSlot(slot, stack);
|
2024-01-13 18:34:33 +01:00
|
|
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) { // Paper - Fix silent equipment change
|
|
|
|
+ super.setItemSlot(slot, stack, silent); // Paper - Fix silent equipment change
|
2023-09-17 01:27:11 +02:00
|
|
|
if (!this.level().isClientSide) {
|
|
|
|
this.reassessWeaponGoal();
|
|
|
|
}
|
|
|
|
diff --git a/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java b/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java
|
|
|
|
new file mode 100644
|
2023-09-25 01:05:05 +02:00
|
|
|
index 0000000000000000000000000000000000000000..81947843d1f2f7dc6f59d7b52f327d60b17d0dcc
|
2023-09-17 01:27:11 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java
|
2023-09-25 01:05:05 +02:00
|
|
|
@@ -0,0 +1,51 @@
|
2023-09-17 01:27:11 +02:00
|
|
|
+package io.papermc.paper.entity;
|
|
|
|
+
|
|
|
|
+import io.github.classgraph.ClassGraph;
|
|
|
|
+import io.github.classgraph.ClassInfo;
|
|
|
|
+import io.github.classgraph.MethodInfo;
|
|
|
|
+import io.github.classgraph.MethodInfoList;
|
|
|
|
+import io.github.classgraph.MethodParameterInfo;
|
|
|
|
+import io.github.classgraph.ScanResult;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
2023-09-24 09:16:58 +02:00
|
|
|
+import java.util.stream.Stream;
|
2023-09-17 01:27:11 +02:00
|
|
|
+import org.bukkit.support.AbstractTestingBase;
|
2023-09-24 09:16:58 +02:00
|
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
2023-09-17 01:27:11 +02:00
|
|
|
+
|
2023-09-24 09:16:58 +02:00
|
|
|
+import static org.junit.jupiter.api.Assertions.fail;
|
2023-09-17 01:27:11 +02:00
|
|
|
+
|
|
|
|
+public class EntitySetItemSlotSilentOverrideTest extends AbstractTestingBase {
|
|
|
|
+
|
2023-09-24 09:16:58 +02:00
|
|
|
+ public static Stream<ClassInfo> parameters() {
|
2023-09-17 01:27:11 +02:00
|
|
|
+ final List<ClassInfo> classInfo = new ArrayList<>();
|
|
|
|
+ try (ScanResult scanResult = new ClassGraph()
|
|
|
|
+ .enableClassInfo()
|
|
|
|
+ .enableMethodInfo()
|
|
|
|
+ .whitelistPackages("net.minecraft")
|
|
|
|
+ .scan()
|
|
|
|
+ ) {
|
|
|
|
+ for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.entity.LivingEntity")) {
|
|
|
|
+ final MethodInfoList setItemSlot = subclass.getDeclaredMethodInfo("setItemSlot");
|
|
|
|
+ if (!setItemSlot.isEmpty()) {
|
|
|
|
+ classInfo.add(subclass);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
2023-09-24 09:16:58 +02:00
|
|
|
+ return classInfo.stream();
|
2023-09-17 01:27:11 +02:00
|
|
|
+ }
|
|
|
|
+
|
2023-09-24 09:16:58 +02:00
|
|
|
+ @ParameterizedTest
|
|
|
|
+ @MethodSource("parameters")
|
|
|
|
+ public void checkSetItemSlotSilentOverrides(ClassInfo overridesSetItemSlot) {
|
|
|
|
+ final MethodInfoList setItemSlot = overridesSetItemSlot.getDeclaredMethodInfo("setItemSlot");
|
2023-09-17 01:27:11 +02:00
|
|
|
+ for (final MethodInfo methodInfo : setItemSlot) {
|
|
|
|
+ for (final MethodParameterInfo methodParameterInfo : methodInfo.getParameterInfo()) {
|
|
|
|
+ if ("boolean".equals(methodParameterInfo.getTypeDescriptor().toStringWithSimpleNames())) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
2023-09-24 09:16:58 +02:00
|
|
|
+ fail(overridesSetItemSlot.getName() + " needs to override setItemSlot with the boolean silent parameter as well");
|
2023-09-17 01:27:11 +02:00
|
|
|
+ }
|
|
|
|
+}
|