mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-13 04:36:53 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
114 lines
5.4 KiB
Diff
114 lines
5.4 KiB
Diff
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
|
|
index ac7a52e77fd2fcbe9f95709b95ba54f8c2a6514b..8a0e65ac8318a467996f48b423db1ac621359fbe 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1100,19 +1100,26 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
|
|
@Override
|
|
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
|
+ // Paper start - Fix silent equipment change
|
|
+ setItemSlot(slot, stack, false);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
|
|
+ // Paper end - Fix silent equipment change
|
|
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 - Fix silent equipment change
|
|
break;
|
|
case HUMANOID_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 - Fix silent equipment change
|
|
break;
|
|
case ANIMAL_ARMOR:
|
|
ItemStack itemstack1 = this.bodyArmorItem;
|
|
|
|
this.bodyArmorItem = stack;
|
|
- this.onEquipItem(slot, itemstack1, stack);
|
|
+ this.onEquipItem(slot, itemstack1, stack, silent); // Paper - Fix silent equipment change
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
index 0cb179bc28cc863b09a079b37b957744f26f3e1d..32670a3cb4b54b66d655197e3fde834d2b2b6d34 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
@@ -258,8 +258,8 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
|
// Paper end - shouldBurnInDay API
|
|
|
|
@Override
|
|
- public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
|
- super.setItemSlot(slot, stack);
|
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) { // Paper - Fix silent equipment change
|
|
+ super.setItemSlot(slot, stack, silent); // Paper - Fix silent equipment change
|
|
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
|
|
index 0000000000000000000000000000000000000000..18e0ae815528f3b2f944febc01df48f346b3a4f6
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java
|
|
@@ -0,0 +1,52 @@
|
|
+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;
|
|
+import java.util.stream.Stream;
|
|
+import org.bukkit.support.environment.Normal;
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.fail;
|
|
+
|
|
+@Normal
|
|
+public class EntitySetItemSlotSilentOverrideTest {
|
|
+
|
|
+ public static Stream<ClassInfo> parameters() {
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return classInfo.stream();
|
|
+ }
|
|
+
|
|
+ @ParameterizedTest
|
|
+ @MethodSource("parameters")
|
|
+ public void checkSetItemSlotSilentOverrides(ClassInfo overridesSetItemSlot) {
|
|
+ final MethodInfoList setItemSlot = overridesSetItemSlot.getDeclaredMethodInfo("setItemSlot");
|
|
+ for (final MethodInfo methodInfo : setItemSlot) {
|
|
+ for (final MethodParameterInfo methodParameterInfo : methodInfo.getParameterInfo()) {
|
|
+ if ("boolean".equals(methodParameterInfo.getTypeDescriptor().toStringWithSimpleNames())) {
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ fail(overridesSetItemSlot.getName() + " needs to override setItemSlot with the boolean silent parameter as well");
|
|
+ }
|
|
+}
|