mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Reimplement Hide specified item components (#210)
* [Reimplement] Hide specified item components * try to fix drag problem in creative mode * correct my name * cleanup * Update 0103-Hide-specified-item-components.patch * Move to gameplay
This commit is contained in:
@@ -1,233 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: TheFloodDragon <1610105206@qq.com>
|
||||
Date: Sun, 4 Aug 2024 19:36:11 +0800
|
||||
Subject: [PATCH] Hide specified item components to clients
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
index 8d5939e03a065197af125d95a10134abbccd07ec..0acd7a54dea269b172fb909dd28ac82f6691c319 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
@@ -23,17 +23,17 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
|
||||
this.items = NonNullList.withSize(contents.size(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < contents.size(); i++) {
|
||||
- this.items.set(i, contents.get(i).copy());
|
||||
+ this.items.set(i, org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(contents.get(i), true)); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
- this.carriedItem = cursorStack.copy();
|
||||
+ this.carriedItem = org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(cursorStack, true); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
private ClientboundContainerSetContentPacket(RegistryFriendlyByteBuf buf) {
|
||||
this.containerId = buf.readContainerId();
|
||||
this.stateId = buf.readVarInt();
|
||||
- this.items = ItemStack.OPTIONAL_LIST_STREAM_CODEC.decode(buf);
|
||||
- this.carriedItem = ItemStack.OPTIONAL_STREAM_CODEC.decode(buf);
|
||||
+ this.items = ItemStack.OPTIONAL_LIST_STREAM_CODEC.decode(buf).stream().map(item -> org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(item, false)).toList(); // Leaf - Hide specified item components
|
||||
+ this.carriedItem = org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(ItemStack.OPTIONAL_STREAM_CODEC.decode(buf), false); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
// Paper start - Handle large packets disconnecting client
|
||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
index 97b6605ba56584a44cfc4361af7389e876496ef2..b60827b281fe03b855c42099df437080a535c714 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
@@ -19,14 +19,14 @@ public class ClientboundContainerSetSlotPacket implements Packet<ClientGamePacke
|
||||
this.containerId = syncId;
|
||||
this.stateId = revision;
|
||||
this.slot = slot;
|
||||
- this.itemStack = stack.copy();
|
||||
+ this.itemStack = org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(stack, true); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
private ClientboundContainerSetSlotPacket(RegistryFriendlyByteBuf buf) {
|
||||
this.containerId = buf.readContainerId();
|
||||
this.stateId = buf.readVarInt();
|
||||
this.slot = buf.readShort();
|
||||
- this.itemStack = ItemStack.OPTIONAL_STREAM_CODEC.decode(buf);
|
||||
+ this.itemStack = org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(ItemStack.OPTIONAL_STREAM_CODEC.decode(buf), false); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
private void write(RegistryFriendlyByteBuf buf) {
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
index a7a44fa556a41512d6a76626618afceccd139c64..709d9997f25369a9a0ac5af94cfe391604081ea1 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
@@ -413,7 +413,7 @@ public class ServerEntity {
|
||||
ItemStack itemstack = entityliving.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 4ecefd90defffeac792d4cb2375ee2d68513b170..0684a8e9e0d91c1724d1e066daa71030bba70904 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2979,7 +2979,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
||||
entity.refreshEntityData(ServerGamePacketListenerImpl.this.player);
|
||||
// SPIGOT-7136 - Allays
|
||||
if (entity instanceof Allay || entity instanceof net.minecraft.world.entity.animal.horse.AbstractHorse) { // Paper - Fix horse armor desync
|
||||
- ServerGamePacketListenerImpl.this.send(new ClientboundSetEquipmentPacket(entity.getId(), Arrays.stream(net.minecraft.world.entity.EquipmentSlot.VALUES_ARRAY).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_ARRAY).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(); // Paper - fix slot desync - always refresh player inventory
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index b816d4509f5d1154fdbe462a0534a17c0d238281..004cecfe99d279a51c21d610833bbea62c8ff25f 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -3552,7 +3552,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
ItemStack itemstack2 = itemstack1; final ItemStack oldEquipment = itemstack2; // Paper - PlayerArmorChangeEvent - obfhelper
|
||||
|
||||
itemstack = this.getItemBySlot(enumitemslot); final ItemStack newEquipment = itemstack;// Paper - PlayerArmorChangeEvent - obfhelper
|
||||
- if (this.equipmentHasChanged(itemstack2, itemstack)) {
|
||||
+ if (this.equipmentHasChanged(org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack2, true), org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack, true))) { // Leaf - Hide specified item components
|
||||
// Paper start - PlayerArmorChangeEvent
|
||||
if (this instanceof ServerPlayer && enumitemslot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
|
||||
final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(oldEquipment);
|
||||
@@ -3629,7 +3629,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/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index bfc90524bd739ed1d91fe9912e38093b3c28928f..71f8946a77f755a4b5ada4313ca154caca070556 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -323,7 +323,7 @@ public abstract class AbstractContainerMenu {
|
||||
private void triggerSlotListeners(int slot, ItemStack stack, Supplier<ItemStack> copySupplier) {
|
||||
ItemStack itemstack1 = (ItemStack) this.lastSlots.get(slot);
|
||||
|
||||
- if (!ItemStack.matches(itemstack1, stack)) {
|
||||
+ if (!ItemStack.matches(org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack1, true), org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(stack, true))) { // Leaf - Hide specified item components
|
||||
ItemStack itemstack2 = (ItemStack) copySupplier.get();
|
||||
|
||||
this.lastSlots.set(slot, itemstack2);
|
||||
@@ -342,7 +342,7 @@ public abstract class AbstractContainerMenu {
|
||||
if (!this.suppressRemoteUpdates) {
|
||||
ItemStack itemstack1 = (ItemStack) this.remoteSlots.get(slot);
|
||||
|
||||
- if (!ItemStack.matches(itemstack1, stack)) {
|
||||
+ if (!ItemStack.matches(org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack1, true), org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(stack, true))) { // Leaf - Hide specified item components
|
||||
ItemStack itemstack2 = (ItemStack) copySupplier.get();
|
||||
|
||||
this.remoteSlots.set(slot, itemstack2);
|
||||
@@ -370,7 +370,7 @@ public abstract class AbstractContainerMenu {
|
||||
|
||||
private void synchronizeCarriedToRemote() {
|
||||
if (!this.suppressRemoteUpdates) {
|
||||
- if (!ItemStack.matches(this.getCarried(), this.remoteCarried)) {
|
||||
+ if (!ItemStack.matches(org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(this.getCarried(), true), org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(this.remoteCarried, true))) { // Leaf - Hide specified item components
|
||||
this.remoteCarried = this.getCarried().copy();
|
||||
if (this.synchronizer != null) {
|
||||
this.synchronizer.sendCarriedChange(this, this.remoteCarried);
|
||||
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..81f28d84ad9043d9e5f3e86dbb231d10cf6c8520
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/HiddenItemComponents.java
|
||||
@@ -0,0 +1,60 @@
|
||||
+package org.dreeam.leaf.config.modules.misc;
|
||||
+
|
||||
+import net.minecraft.core.Holder;
|
||||
+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.List;
|
||||
+import java.util.Optional;
|
||||
+
|
||||
+public class HiddenItemComponents extends ConfigModules {
|
||||
+
|
||||
+ public String getBasePath() {
|
||||
+ return EnumConfigCategory.MISC.getBaseKeyName();
|
||||
+ }
|
||||
+
|
||||
+ public static List<DataComponentType<?>> hiddenItemComponentTypes = List.of();
|
||||
+
|
||||
+ @Override
|
||||
+ public void onLoaded() {
|
||||
+ List<String> list = config.getList(getBasePath() + ".hidden-item-components", new ArrayList<>(), config.pickStringRegionBased("""
|
||||
+ Controls whether specified component information is sent to clients.
|
||||
+ This may break resource packs and mods that rely on this information.
|
||||
+ It needs a component type list, incorrect things will not work.
|
||||
+ You can fill it with ["custom_data"] to hide components of CUSTOM_DATA.
|
||||
+ Also, it can avoid some frequent client animations.
|
||||
+ NOTICE: You must know what you're filling in and how it works! It will handle all itemStacks!""",
|
||||
+ """
|
||||
+ 控制哪些物品组件信息会被发送至客户端.
|
||||
+ 可能会导致依赖物品组件的资源包/模组无法正常工作.
|
||||
+ 该配置项接受一个物品组件列表, 格式不正确将不会启用.
|
||||
+ 可以填入 ["custom_data"] 来隐藏自定义数据物品组件 CUSTOM_DATA.
|
||||
+ 也可以避免一些客户端动画效果.
|
||||
+ 注意: 你必须知道你填进去的是什么, 有什么用, 该项配置会处理所有的ItemStack!"""));
|
||||
+
|
||||
+ List<DataComponentType<?>> types = new ArrayList<>(list.size());
|
||||
+
|
||||
+ for (String id : list) {
|
||||
+ // Find and check
|
||||
+ Optional<Holder.Reference<DataComponentType<?>>> optional = BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(id));
|
||||
+
|
||||
+ if (optional.isEmpty()) continue;
|
||||
+
|
||||
+ DataComponentType<?> type = optional.get().value();
|
||||
+
|
||||
+ 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..55cc252829bff893e6b0f564f3399f06267f7b8e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/util/item/ItemStackObfuscator.java
|
||||
@@ -0,0 +1,29 @@
|
||||
+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;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class ItemStackObfuscator {
|
||||
+
|
||||
+ 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;
|
||||
+
|
||||
+ // Get the types which need to hide
|
||||
+ List<DataComponentType<?>> hiddenTypes = HiddenItemComponents.hiddenItemComponentTypes;
|
||||
+
|
||||
+ if (hiddenTypes.isEmpty()) return copy;
|
||||
+
|
||||
+ // Remove specified types
|
||||
+ for (DataComponentType<?> type : hiddenTypes) {
|
||||
+ // Only remove, no others
|
||||
+ copy.remove(type);
|
||||
+ }
|
||||
+
|
||||
+ return copy;
|
||||
+ }
|
||||
+}
|
||||
201
patches/server/0103-Hide-specified-item-components.patch
Normal file
201
patches/server/0103-Hide-specified-item-components.patch
Normal file
@@ -0,0 +1,201 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: TheFloodDragon <1610105206@qq.com>
|
||||
Date: Tue, 4 Feb 2025 21:11:29 +0800
|
||||
Subject: [PATCH] Hide specified item components
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
index 8d5939e03a065197af125d95a10134abbccd07ec..8125e0680a274ad867d5bf8541b63475d03bbf0e 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
||||
@@ -54,8 +54,8 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
|
||||
private void write(RegistryFriendlyByteBuf buf) {
|
||||
buf.writeContainerId(this.containerId);
|
||||
buf.writeVarInt(this.stateId);
|
||||
- ItemStack.OPTIONAL_LIST_STREAM_CODEC.encode(buf, this.items);
|
||||
- ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, this.carriedItem);
|
||||
+ ItemStack.OPTIONAL_LIST_STREAM_CODEC.encode(buf, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.items, true)); // Leaf - Hide specified item components
|
||||
+ ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.carriedItem, true)); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
index 97b6605ba56584a44cfc4361af7389e876496ef2..08fdafbf6d0249adc502e661216f1fcdeee647d2 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
@@ -33,7 +33,7 @@ public class ClientboundContainerSetSlotPacket implements Packet<ClientGamePacke
|
||||
buf.writeContainerId(this.containerId);
|
||||
buf.writeVarInt(this.stateId);
|
||||
buf.writeShort(this.slot);
|
||||
- ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, this.itemStack);
|
||||
+ ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, org.dreeam.leaf.util.item.ItemStackStripper.strip(this.itemStack, true)); // Leaf - Hide specified item components
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
index bfc90524bd739ed1d91fe9912e38093b3c28928f..c1f644abcb374addb8ad6a914e670da4f033199b 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -370,7 +370,7 @@ public abstract class AbstractContainerMenu {
|
||||
|
||||
private void synchronizeCarriedToRemote() {
|
||||
if (!this.suppressRemoteUpdates) {
|
||||
- if (!ItemStack.matches(this.getCarried(), this.remoteCarried)) {
|
||||
+ if (!org.dreeam.leaf.util.item.ItemStackStripper.matchesStripped(this.getCarried(), this.remoteCarried)) { // Leaf - Hide specified item components - Avoid some frequent client animations
|
||||
this.remoteCarried = this.getCarried().copy();
|
||||
if (this.synchronizer != null) {
|
||||
this.synchronizer.sendCarriedChange(this, this.remoteCarried);
|
||||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/HideItemComponent.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/HideItemComponent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4e647eb06d0c59f5deb99054c9ca2315abb1c8b1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/HideItemComponent.java
|
||||
@@ -0,0 +1,62 @@
|
||||
+package org.dreeam.leaf.config.modules.gameplay;
|
||||
+
|
||||
+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.List;
|
||||
+
|
||||
+/**
|
||||
+ * HideItemComponent
|
||||
+ *
|
||||
+ * @author TheFloodDragon
|
||||
+ * @since 2025/2/4 18:30
|
||||
+ */
|
||||
+public class HideItemComponent extends ConfigModules {
|
||||
+
|
||||
+ public String getBasePath() {
|
||||
+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".hide-item-component";
|
||||
+ }
|
||||
+
|
||||
+ public static boolean enabled = false;
|
||||
+ public static List<DataComponentType<?>> hiddenTypes = List.of();
|
||||
+
|
||||
+ @Override
|
||||
+ public void onLoaded() {
|
||||
+ config.addCommentRegionBased(getBasePath(), """
|
||||
+ Controls whether specified component information would be sent to clients.
|
||||
+ It may break resource packs and mods that rely on the information.
|
||||
+ Also, it can avoid some frequent client animations.
|
||||
+ Attention: This is not same as Paper's item-obfuscation, we only hide specified component information from player's inventory.""",
|
||||
+ """
|
||||
+ 控制哪些物品组件信息会被发送至客户端.
|
||||
+ 可能会导致依赖物品组件的资源包/模组无法正常工作.
|
||||
+ 可以避免一些客户端动画效果.
|
||||
+ 注意: 此项与 Paper 的 item-obfuscation 不同, 我们只从玩家背包中隐藏物品指定的组件信息.""");
|
||||
+ List<String> list = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
|
||||
+ Which type of components will be hidden from clients.
|
||||
+ It needs a component type list, incorrect things will not work.""",
|
||||
+ """
|
||||
+ 被隐藏的物品组件类型列表.
|
||||
+ 该配置项接受一个物品组件列表, 格式不正确将不会启用."""));
|
||||
+ enabled = config.getBoolean(getBasePath() + ".enabled", enabled, config.pickStringRegionBased(
|
||||
+ "If enabled, specified item component information from player's inventory will be hided.",
|
||||
+ "启用后, 玩家背包内物品的指定组件信息会被隐藏."
|
||||
+ ));
|
||||
+
|
||||
+ final List<DataComponentType<?>> types = new ArrayList<>(list.size());
|
||||
+
|
||||
+ for (String componentType : list) {
|
||||
+ BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(componentType)).ifPresentOrElse(
|
||||
+ optional -> types.add(optional.value()),
|
||||
+ () -> LeafConfig.LOGGER.warn("Unknown component type: {}", componentType)
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ hiddenTypes = types;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/util/item/ItemStackStripper.java b/src/main/java/org/dreeam/leaf/util/item/ItemStackStripper.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..9e70d46e367b3f0b3287f59d11b32ca72b177f55
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/util/item/ItemStackStripper.java
|
||||
@@ -0,0 +1,80 @@
|
||||
+package org.dreeam.leaf.util.item;
|
||||
+
|
||||
+import net.minecraft.core.component.DataComponentMap;
|
||||
+import net.minecraft.core.component.DataComponentType;
|
||||
+import net.minecraft.world.item.ItemStack;
|
||||
+import org.dreeam.leaf.config.modules.gameplay.HideItemComponent;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+import java.util.Objects;
|
||||
+
|
||||
+/**
|
||||
+ * ItemStackStripper
|
||||
+ *
|
||||
+ * @author TheFloodDragon
|
||||
+ * @since 2025/2/4 19:04
|
||||
+ */
|
||||
+public class ItemStackStripper {
|
||||
+
|
||||
+ public static ItemStack strip(final ItemStack itemStack, final boolean copy) {
|
||||
+ if (!HideItemComponent.enabled || itemStack.isEmpty() || itemStack.getComponentsPatch().isEmpty())
|
||||
+ return itemStack;
|
||||
+
|
||||
+ final ItemStack copied = copy ? itemStack.copy() : itemStack;
|
||||
+
|
||||
+ // Remove specified types
|
||||
+ for (DataComponentType<?> type : HideItemComponent.hiddenTypes) {
|
||||
+ // Only remove, no others
|
||||
+ copied.remove(type);
|
||||
+ }
|
||||
+
|
||||
+ return copied;
|
||||
+ }
|
||||
+
|
||||
+ public static List<ItemStack> strip(final List<ItemStack> itemStacks, final boolean copy) {
|
||||
+ if (!HideItemComponent.enabled) return itemStacks;
|
||||
+
|
||||
+ final List<ItemStack> copiedItems = new ArrayList<>();
|
||||
+
|
||||
+ for (ItemStack itemStack : itemStacks) {
|
||||
+ if (itemStack.isEmpty() || itemStack.getComponentsPatch().isEmpty()) {
|
||||
+ copiedItems.add(itemStack);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ final ItemStack copied = copy ? itemStack.copy() : itemStack;
|
||||
+
|
||||
+ // Remove specified types
|
||||
+ for (DataComponentType<?> type : HideItemComponent.hiddenTypes) {
|
||||
+ // Only remove, no others
|
||||
+ copied.remove(type);
|
||||
+ }
|
||||
+
|
||||
+ copiedItems.add(copied);
|
||||
+ }
|
||||
+
|
||||
+ return copiedItems;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Check if two ItemStacks are the same after stripping components
|
||||
+ */
|
||||
+ public static boolean matchesStripped(ItemStack left, ItemStack right) {
|
||||
+ if (HideItemComponent.enabled) {
|
||||
+ return left == right || (
|
||||
+ left.is(right.getItem()) && left.getCount() == right.getCount() &&
|
||||
+ (left.isEmpty() && right.isEmpty() || Objects.equals(strip(left.getComponents()), strip(right.getComponents())))
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ return ItemStack.matches(left, right);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @return a new DataComponentMap with all hidden components removed
|
||||
+ */
|
||||
+ private static DataComponentMap strip(final DataComponentMap map) {
|
||||
+ return map.filter(c -> !HideItemComponent.hiddenTypes.contains(c));
|
||||
+ }
|
||||
+}
|
||||
@@ -24,7 +24,7 @@ index eb547af300d8ecea19b3e02e5ebe6139330c9d62..1e4729be4a245a811fd15ea1c02179b3
|
||||
if (this.goalSelector.inactiveTick(this.activatedPriority, true) && !isThrottled) { // Pufferfish - pass activated priroity // Pufferfish - throttle inactive goal selector ticking
|
||||
this.goalSelector.tick();
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
index fd373d98f836c057c30c4fbd5d7618cc4e757b78..50f080e91c0701b635b918ff15e07052052afb47 100644
|
||||
index bd4a96e2b4b539bafe13605e80706311c15263a7..8c578e207d9406df84d267e39f526450da5e5a97 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
@@ -321,7 +321,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
|
||||
@@ -9,7 +9,7 @@ Original license: MIT
|
||||
Original project: https://github.com/PurpurMC/Purpur
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
index 709d9997f25369a9a0ac5af94cfe391604081ea1..bea671ae16a90e9cb9d2f312eed3c816da05b23c 100644
|
||||
index a7a44fa556a41512d6a76626618afceccd139c64..41802175e4b621fc330abec67274c547851646b3 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
@@ -243,6 +243,8 @@ public class ServerEntity {
|
||||
|
||||
@@ -224,7 +224,7 @@ index 4f91107f9ae42f96c060c310596db9aa869a8dbc..f9889f593ed144ee8f1f5bd380e631c6
|
||||
public boolean visible = true;
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
index bea671ae16a90e9cb9d2f312eed3c816da05b23c..36026f9f4cad3930cd45918012bf54498f2de973 100644
|
||||
index 41802175e4b621fc330abec67274c547851646b3..b909263394101b52b97cf92739e05521683b9458 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
||||
@@ -119,7 +119,13 @@ public class ServerEntity {
|
||||
@@ -314,7 +314,7 @@ index 9a7a76599a44dfd51d5e9e9a0e892994528c7680..4a92789d77313e165ab1252cd469e34a
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 0684a8e9e0d91c1724d1e066daa71030bba70904..dd6174a4b695bdaa2229a21c9680e757c6869755 100644
|
||||
index 4ecefd90defffeac792d4cb2375ee2d68513b170..94f8140eda0dacf5e32aa55851b75ff9ebb7639d 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -1833,7 +1833,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
||||
|
||||
@@ -12,7 +12,7 @@ As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
|
||||
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 004cecfe99d279a51c21d610833bbea62c8ff25f..2b8cc1cfeda50721c063429a7d31623dc93089ea 100644
|
||||
index b816d4509f5d1154fdbe462a0534a17c0d238281..5588202b7bdf77e8cdc7fcdfccd68afebb13ab15 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -2866,6 +2866,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
|
||||
@@ -317,7 +317,7 @@ index ceee6345530c3bf91cce988af2da12f0798d8f4b..1289fecee1f05abfce09672ec406caf7
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 2b8cc1cfeda50721c063429a7d31623dc93089ea..ac19c28135debebf0e1055d47571dc068f10e30e 100644
|
||||
index 5588202b7bdf77e8cdc7fcdfccd68afebb13ab15..8371532ea5fed9a781b864955013dcd35f442a53 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -160,7 +160,7 @@ import org.bukkit.event.entity.EntityTeleportEvent;
|
||||
|
||||
Reference in New Issue
Block a user