mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-21 16:09:19 +00:00
Remove stream in RecipeManager getRecipeFor
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
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 8cca2ac616a2c80268c96b9f95e33f834a0fc8fd..c2c0e88962ea010ece20f9710dfcd83b7b61bf91 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.readUnsignedByte();
|
||||
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 63f6a2437da9363786b55af0a7cbc5373232d35b..f4c85b78eafb27331ab7c3e45c8493b271583241 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket.java
|
||||
@@ -21,14 +21,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.readByte();
|
||||
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 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 906c4e90997fbcdaf7af2a5077a7a50e25d7107f..adfb515461fbf5c49f603fc5ecd6053f2e0d3371 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2917,7 +2917,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 3503423ee0d4ed13f7ebdb8272c8266a827ff4c1..341fad1609308fad6adf5b5f9ad289d57ac4ddd6 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -3404,7 +3404,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
ItemStack itemstack1 = itemstack;
|
||||
ItemStack itemstack2 = this.getItemBySlot(enumitemslot);
|
||||
|
||||
- if (this.equipmentHasChanged(itemstack1, itemstack2)) {
|
||||
+ if (this.equipmentHasChanged(org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack1, true), org.dreeam.leaf.util.item.ItemStackObfuscator.stripMeta(itemstack2, 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(itemstack1);
|
||||
@@ -3488,7 +3488,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 ecfa807e78c16a24099d40becd0c7916f239aed1..f1b4adeeb4dad5178a5e52870f420beaa8e13034 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
||||
@@ -295,7 +295,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);
|
||||
@@ -314,7 +314,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);
|
||||
@@ -342,7 +342,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..c51c12efe6fdc360d8d6e0ea41ecaaaa6969fa7b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/HiddenItemComponents.java
|
||||
@@ -0,0 +1,45 @@
|
||||
+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.List;
|
||||
+
|
||||
+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<>(), """
|
||||
+ 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!
|
||||
+ """);
|
||||
+
|
||||
+ List<DataComponentType<?>> types = new ArrayList<>(list.size());
|
||||
+
|
||||
+ for (String id : list) {
|
||||
+ // 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..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;
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user