-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide specified item components from clients
- Loading branch information
1 parent
8bcdca0
commit f89d910
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
patches/server/0092-Hide-specified-item-components-from-clients.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: TheFloodDragon <[email protected]> | ||
Date: Sun, 4 Aug 2024 12:43:15 +0800 | ||
Subject: [PATCH] Hide specified item components from clients | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
index 573c380e123473e35c0b72c44b32c8d6ba8e61c6..feacc41ecf7f4028e0a1cce5d2012ced96a26d30 100644 | ||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java | ||
@@ -374,7 +374,7 @@ public class ServerEntity { | ||
ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot); | ||
|
||
if (!itemstack.isEmpty()) { | ||
- list.add(Pair.of(enumitemslot, itemstack.copy())); | ||
+ list.add(Pair.of(enumitemslot, org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack, true))); // Leaf - Hide specified item components | ||
} | ||
} | ||
|
||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
index 855fa46cbaaa22003f46e0e63292ad0824d23c86..60ef9bf2425a8d6d54cd59ae15f3f3780924a977 100644 | ||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
@@ -2858,7 +2858,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl | ||
entity.refreshEntityData(ServerGamePacketListenerImpl.this.player); | ||
// SPIGOT-7136 - Allays | ||
if (entity instanceof Allay) { | ||
- ServerGamePacketListenerImpl.this.send(new ClientboundSetEquipmentPacket(entity.getId(), Arrays.stream(net.minecraft.world.entity.EquipmentSlot.VALUES).map((slot) -> Pair.of(slot, ((LivingEntity) entity).getItemBySlot(slot).copy())).collect(Collectors.toList()), true)); // Paper - sanitize // Gale - JettPack - reduce array allocations | ||
+ ServerGamePacketListenerImpl.this.send(new ClientboundSetEquipmentPacket(entity.getId(), Arrays.stream(net.minecraft.world.entity.EquipmentSlot.VALUES).map((slot) -> Pair.of(slot, org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(((LivingEntity) entity).getItemBySlot(slot), true))).collect(Collectors.toList()), true)); // Paper - sanitize // Gale - JettPack - reduce array allocations // Leaf - Hide specified item components | ||
ServerGamePacketListenerImpl.this.player.containerMenu.sendAllDataToRemote(); | ||
} | ||
} | ||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
index 7c75298c8ea7a828c2d9cd4e7ffd4d09a0113aed..80d2b471e13a70b92cda44b75e86e909bb7727ab 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java | ||
@@ -3472,7 +3472,7 @@ public abstract class LivingEntity extends Entity implements Attackable { | ||
equipmentChanges.forEach((enumitemslot, itemstack) -> { | ||
ItemStack itemstack1 = itemstack.copy(); | ||
|
||
- list.add(Pair.of(enumitemslot, itemstack1)); | ||
+ list.add(Pair.of(enumitemslot, org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack1, true))); // Leaf - Hide specified item components | ||
switch (enumitemslot.getType()) { | ||
case HAND: | ||
this.setLastHandItem(enumitemslot, itemstack1); | ||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/HiddenItemComponents.java b/src/main/java/org/dreeam/leaf/config/modules/misc/HiddenItemComponents.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..01a1454561a1eed291860f1fd92a35a9b83b348d | ||
--- /dev/null | ||
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/HiddenItemComponents.java | ||
@@ -0,0 +1,43 @@ | ||
+package org.dreeam.leaf.config.modules.misc; | ||
+ | ||
+import net.minecraft.core.component.DataComponentType; | ||
+import net.minecraft.core.registries.BuiltInRegistries; | ||
+import net.minecraft.resources.ResourceLocation; | ||
+import org.dreeam.leaf.config.ConfigModules; | ||
+import org.dreeam.leaf.config.EnumConfigCategory; | ||
+import org.dreeam.leaf.config.LeafConfig; | ||
+ | ||
+import java.util.ArrayList; | ||
+import java.util.Collections; | ||
+import java.util.List; | ||
+ | ||
+public class HiddenItemComponents extends ConfigModules { | ||
+ | ||
+ public String getBasePath() { | ||
+ return EnumConfigCategory.MISC.getBaseKeyName(); | ||
+ } | ||
+ | ||
+ public static List<DataComponentType<?>> hiddenItemComponentTypes = Collections.emptyList(); | ||
+ | ||
+ @Override | ||
+ public void onLoaded() { | ||
+ List<String> componentIds = config.getList(getBasePath() + ".hidden-item-components", Collections.emptyList(), """ | ||
+ Controls whether specified component information is sent to other players' clients. | ||
+ This may break resource packs that rely on this information when observing other players. | ||
+ The configuration is very similar to [https://docs.papermc.io/paper/reference/world-configuration#anticheat_obfuscation_items]. | ||
+ But the patch [Paper/server/Hide-unnecessary-itemmeta-from-clients] has been removed. | ||
+ It needs a component type list, incorrect things will not work. | ||
+ You can fill it with ["custom_data"] to hide components of CUSTOM_DATA to avoid some frequent client animations. | ||
+ NOTICE: You must know what you're filling in and how it works! | ||
+ """); | ||
+ List<DataComponentType<?>> types = new ArrayList<>(componentIds.size()); | ||
+ for (String id : componentIds) { | ||
+ // Find and check | ||
+ DataComponentType<?> type = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(id)); | ||
+ if (type != null) types.add(type); | ||
+ else LeafConfig.LOGGER.warn("Unknown component type: {}", id); | ||
+ } | ||
+ hiddenItemComponentTypes = types; | ||
+ } | ||
+ | ||
+} | ||
diff --git a/src/main/java/org/dreeam/leaf/util/item/ItemStackObfuscator.java b/src/main/java/org/dreeam/leaf/util/item/ItemStackObfuscator.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..688a4f84424759c894735b6dc84d91aabf7f9d1d | ||
--- /dev/null | ||
+++ b/src/main/java/org/dreeam/leaf/util/item/ItemStackObfuscator.java | ||
@@ -0,0 +1,25 @@ | ||
+package org.dreeam.leaf.util.item; | ||
+ | ||
+import net.minecraft.core.component.DataComponentType; | ||
+import net.minecraft.world.item.ItemStack; | ||
+import org.dreeam.leaf.config.modules.misc.HiddenItemComponents; | ||
+ | ||
+public class ItemStackObfuscator { | ||
+ | ||
+ // Leaf start - Hide specified item components | ||
+ public static ItemStack stripMeta(final ItemStack itemStack, final boolean copyItemStack) { | ||
+ if (itemStack.isEmpty() || itemStack.getComponentsPatch().isEmpty()) return itemStack; | ||
+ | ||
+ final ItemStack copy = copyItemStack ? itemStack.copy() : itemStack; | ||
+ | ||
+ // Remove specified types | ||
+ for (DataComponentType<?> hiddenType : HiddenItemComponents.hiddenItemComponentTypes) { | ||
+ // Only remove, no others | ||
+ copy.remove(hiddenType); | ||
+ } | ||
+ | ||
+ return copy; | ||
+ } | ||
+ // Leaf end - Hide specified item components | ||
+ | ||
+} |