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
2023-09-22 18:59:52 +02:00
index bb29725ea06128fb2386c50d088316fea01c312c..d28c477171c1b6888a45175075017d960464b5cd 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
2023-09-22 18:59:52 +02:00
@@ -1060,13 +1060,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) {
+ // Paper start
+ setItemSlot(slot, stack, false);
+ }
+
+ @Override
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
+ // Paper end
this.verifyEquippedItem(stack);
switch (slot.getType()) {
case HAND:
- this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack);
+ this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack, silent); // Paper
break;
case ARMOR:
- this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack);
+ this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack, silent); // Paper
}
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
2023-09-22 18:59:52 +02:00
index 8e9469fec42f7b6a132cf173f6f5a95777a29b3b..b319021b22c5dceba6199ed27814b2dcf47b8d50 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
// Paper end
@Override
- public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
- super.setItemSlot(slot, stack);
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) { // Paper
+ super.setItemSlot(slot, stack, silent); // Paper
if (!this.level().isClientSide) {
this.reassessWeaponGoal();
}
2023-09-17 01:53:21 +02:00
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2023-09-24 04:35:16 +02:00
index 87cae8ed22a2428a1dda8f2a4510e45fbc31eab5..ea8a0961190e9aafda4fed6fecd85097c141040a 100644
2023-09-17 01:53:21 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2023-09-24 04:35:16 +02:00
@@ -1870,7 +1870,10 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2023-09-22 22:13:57 +02:00
// Paper end - optimize redstone (Alternate Current)
// Paper start - notify observers even if grow failed
2023-09-17 01:53:21 +02:00
public void checkCapturedTreeStateForObserverNotify(final BlockPos pos, final CraftBlockState craftBlockState) {
- if (craftBlockState.getPosition().getY() == pos.getY() && this.getBlockState(craftBlockState.getPosition()) == craftBlockState.getHandle()) { // notify observers if the block state is the same and the Y level equals the original y level (for mega trees)
+ // notify observers if the block state is the same and the Y level equals the original y level (for mega trees)
+ // blocks at the same Y level with the same state can be assumed to be saplings which trigger observers regardless of if the
+ // tree grew or not
+ if (craftBlockState.getPosition().getY() == pos.getY() && this.getBlockState(craftBlockState.getPosition()) == craftBlockState.getHandle()) {
this.notifyAndUpdatePhysics(craftBlockState.getPosition(), null, craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getHandle(), craftBlockState.getFlag(), 512);
}
}
2023-09-17 01:27:11 +02:00
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
+ }
+}