Skip to content

Commit 0d29364

Browse files
committed
Add unsupported config option and internal API to simplify remote item matching
This is important for 1.21.5 servers/clients and non-Vanilla clients that may not be able to match 1.21.5 data hashes anymore
1 parent f0388e2 commit 0d29364

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

paper-server/patches/sources/net/minecraft/server/level/ServerPlayer.java.patch

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Nullable
1111
private Vec3 startingToFallPosition;
1212
@Nullable
13-
@@ -258,6 +_,13 @@
13+
@@ -258,6 +_,20 @@
1414
}
1515
}
1616

@@ -20,6 +20,13 @@
2020
+ ServerPlayer.this.connection.send(new ClientboundContainerSetSlotPacket(ServerPlayer.this.inventoryMenu.containerId, ServerPlayer.this.inventoryMenu.incrementStateId(), net.minecraft.world.inventory.InventoryMenu.SHIELD_SLOT, ServerPlayer.this.inventoryMenu.getSlot(net.minecraft.world.inventory.InventoryMenu.SHIELD_SLOT).getItem().copy()));
2121
+ }
2222
+ // Paper end - Sync offhand slot in menus
23+
+
24+
+ // Paper start - add flag to simplify remote matching logic
25+
+ @Override
26+
+ public ServerPlayer player() {
27+
+ return ServerPlayer.this;
28+
+ }
29+
+ // Paper end - add flag to simplify remote matching logic
2330
+
2431
@Override
2532
public void sendSlotChange(AbstractContainerMenu container, int slot, ItemStack itemStack) {

paper-server/patches/sources/net/minecraft/world/inventory/AbstractContainerMenu.java.patch

+35
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,41 @@
7272
}
7373
}
7474
}
75+
@@ -243,7 +_,7 @@
76+
private void synchronizeSlotToRemote(int slotIndex, ItemStack stack, Supplier<ItemStack> supplier) {
77+
if (!this.suppressRemoteUpdates) {
78+
ItemStack itemStack = this.remoteSlots.get(slotIndex);
79+
- if (!ItemStack.matches(itemStack, stack)) {
80+
+ if (!this.matchesRemote(itemStack, stack)) { // Paper - add flag to simplify remote matching logic
81+
ItemStack itemStack1 = supplier.get();
82+
this.remoteSlots.set(slotIndex, itemStack1);
83+
if (this.synchronizer != null) {
84+
@@ -267,7 +_,7 @@
85+
86+
private void synchronizeCarriedToRemote() {
87+
if (!this.suppressRemoteUpdates) {
88+
- if (!ItemStack.matches(this.getCarried(), this.remoteCarried)) {
89+
+ if (!this.matchesRemote(this.getCarried(), this.remoteCarried)) { // Paper - add flag to simplify remote matching logic
90+
this.remoteCarried = this.getCarried().copy();
91+
if (this.synchronizer != null) {
92+
this.synchronizer.sendCarriedChange(this, this.remoteCarried);
93+
@@ -276,6 +_,16 @@
94+
}
95+
}
96+
97+
+ // Paper start - add flag to simplify remote matching logic
98+
+ private boolean matchesRemote(final ItemStack stack, final ItemStack other) {
99+
+ if (this.synchronizer != null && this.synchronizer.player() != null && this.synchronizer.player().getBukkitEntity().simplifyContainerDesyncCheck()) {
100+
+ // Only check the item type and count
101+
+ return stack == other || (stack.getCount() == other.getCount() && ItemStack.isSameItem(stack, other));
102+
+ }
103+
+ return ItemStack.matches(stack, other);
104+
+ }
105+
+ // Paper end - add flag to simplify remote matching logic
106+
+
107+
public void setRemoteSlot(int slot, ItemStack stack) {
108+
this.remoteSlots.set(slot, stack.copy());
109+
}
75110
@@ -343,6 +_,7 @@
76111
this.resetQuickCraft();
77112
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
--- a/net/minecraft/world/inventory/ContainerSynchronizer.java
22
+++ b/net/minecraft/world/inventory/ContainerSynchronizer.java
3-
@@ -11,4 +_,6 @@
3+
@@ -11,4 +_,12 @@
44
void sendCarriedChange(AbstractContainerMenu containerMenu, ItemStack stack);
55

66
void sendDataChange(AbstractContainerMenu container, int id, int value);
77
+
88
+ default void sendOffHandSlotChange() {} // Paper - Sync offhand slot in menus
9+
+
10+
+ // Paper start - add flag to simplify remote matching logic
11+
+ default [email protected] ServerPlayer player() {
12+
+ return null;
13+
+ }
14+
+ // Paper end - add flag to simplify remote matching logic
915
}

paper-server/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public class UnsupportedSettings extends ConfigurationPart {
186186
public CompressionFormat compressionFormat = CompressionFormat.ZLIB;
187187
@Comment("This setting controls if equipment should be updated when handling certain player actions.")
188188
public boolean updateEquipmentOnPlayerActions = true;
189+
@Comment("Only checks an item's amount and type instead of its full data during inventory desync checks.")
190+
public boolean simplifyRemoteItemMatching = false;
189191

190192
public enum CompressionFormat {
191193
GZIP,

paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.mojang.datafixers.util.Pair;
99
import io.netty.buffer.Unpooled;
1010
import io.papermc.paper.FeatureHooks;
11+
import io.papermc.paper.configuration.GlobalConfiguration;
1112
import io.papermc.paper.entity.LookAnchor;
1213
import io.papermc.paper.entity.PaperPlayerGiveResult;
1314
import io.papermc.paper.entity.PlayerGiveResult;
@@ -224,7 +225,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
224225
private CraftWorldBorder clientWorldBorder = null;
225226
private BorderChangeListener clientWorldBorderListener = this.createWorldBorderListener();
226227
public org.bukkit.event.player.PlayerResourcePackStatusEvent.Status resourcePackStatus; // Paper - more resource pack API
227-
private static final boolean DISABLE_CHANNEL_LIMIT = System.getProperty("paper.disableChannelLimit") != null; // Paper - add a flag to disable the channel limit
228+
private boolean simplifyContainerDesyncCheck = GlobalConfiguration.get().unsupportedSettings.simplifyRemoteItemMatching;
228229
private long lastSaveTime; // Paper - getLastPlayed replacement API
229230

230231
public CraftPlayer(CraftServer server, ServerPlayer entity) {
@@ -3606,4 +3607,20 @@ public int getDeathScreenScore() {
36063607
public void setDeathScreenScore(final int score) {
36073608
getHandle().setScore(score);
36083609
}
3610+
3611+
/**
3612+
* Returns whether container desync checks should skip the full item comparison of remote carried and changed slots
3613+
* and should instead only check their type and amount.
3614+
* <p>
3615+
* This is useful if the client is not able to produce the same item stack (or as of 1.21.5, its data hashes) as the server.
3616+
*
3617+
* @return whether to simplify container desync checks
3618+
*/
3619+
public boolean simplifyContainerDesyncCheck() {
3620+
return simplifyContainerDesyncCheck;
3621+
}
3622+
3623+
public void setSimplifyContainerDesyncCheck(final boolean simplifyContainerDesyncCheck) {
3624+
this.simplifyContainerDesyncCheck = simplifyContainerDesyncCheck;
3625+
}
36093626
}

0 commit comments

Comments
 (0)