From 6b138e1bde2fff4858f8bead823db1b03e450a5c Mon Sep 17 00:00:00 2001 From: OLDREDSTONE Date: Tue, 25 Mar 2025 10:43:48 +0800 Subject: [PATCH 1/4] fix the blueprint printing command bug for the sign --- .../foundation/CreateNBTProcessors.java | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java index 6291c9bd66..980485cd1e 100644 --- a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java @@ -9,52 +9,36 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Items; +import net.minecraft.network.chat.Component; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.registries.ForgeRegistries; - public class CreateNBTProcessors { public static void register() { - + // Remove the first layer of commands while preserving the styles. + // Since recursive commands won't be executed, there's no need to handle them. NBTProcessors.addProcessor(BlockEntityType.SIGN, data -> { + var front_text = data.getCompound("front_text").getList("messages", Tag.TAG_STRING); + var back_text = data.getCompound("back_text").getList("messages", Tag.TAG_STRING); for (int i = 0; i < 4; ++i) { - if (NBTProcessors.textComponentHasClickEvent(data.getString("Text" + (i + 1)))) - return null; + tryRemovingCommand(front_text, i); + tryRemovingCommand(back_text, i); } return data; }); + NBTProcessors.addProcessor(AllBlockEntityTypes.PLACARD.get(), NBTProcessors.itemProcessor("Item")); + } - NBTProcessors.addProcessor(BlockEntityType.LECTERN, data -> { - if (!data.contains("Book", Tag.TAG_COMPOUND)) - return data; - CompoundTag book = data.getCompound("Book"); - - // Writable books can't have click events, so they're safe to keep - ResourceLocation writableBookResource = ForgeRegistries.ITEMS.getKey(Items.WRITABLE_BOOK); - if (writableBookResource != null && book.getString("id").equals(writableBookResource.toString())) - return data; - - if (!book.contains("tag", Tag.TAG_COMPOUND)) - return data; - CompoundTag tag = book.getCompound("tag"); - - if (!tag.contains("pages", Tag.TAG_LIST)) - return data; - ListTag pages = tag.getList("pages", Tag.TAG_STRING); - - for (Tag inbt : pages) { - if (NBTProcessors.textComponentHasClickEvent(inbt.getAsString())) - return null; + private static void tryRemovingCommand(ListTag front_text, int i) { + if(NBTProcessors.textComponentHasClickEvent(front_text.get(i).getAsString())) + { + var text = + Component.Serializer.fromJson(front_text.get(i).getAsString()); + if (text != null) { + text.setStyle(text.getStyle().withClickEvent(null)); + front_text.remove(i); + front_text.add(i,net.minecraft.nbt.StringTag.valueOf(Component.Serializer.toJson(text))); } - return data; - }); - - NBTProcessors.addProcessor(AllBlockEntityTypes.CLIPBOARD.get(), CreateNBTProcessors::clipboardProcessor); - - NBTProcessors.addProcessor(AllBlockEntityTypes.CREATIVE_CRATE.get(), NBTProcessors.itemProcessor("Filter")); - NBTProcessors.addProcessor(AllBlockEntityTypes.PLACARD.get(), NBTProcessors.itemProcessor("Item")); + } } public static CompoundTag clipboardProcessor(CompoundTag data) { From 2930541259fe0f0dcfbfa18bef3215678e271193 Mon Sep 17 00:00:00 2001 From: OLDREDSTONE Date: Tue, 25 Mar 2025 10:43:48 +0800 Subject: [PATCH 2/4] fix the blueprint printing command bug for the sign --- .../foundation/CreateNBTProcessors.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java index 6291c9bd66..2f77c2d750 100644 --- a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -17,11 +18,14 @@ public class CreateNBTProcessors { public static void register() { - + // Remove the first layer of commands while preserving the styles. + // Since recursive commands won't be executed, there's no need to handle them. NBTProcessors.addProcessor(BlockEntityType.SIGN, data -> { + var front_text = data.getCompound("front_text").getList("messages", Tag.TAG_STRING); + var back_text = data.getCompound("back_text").getList("messages", Tag.TAG_STRING); for (int i = 0; i < 4; ++i) { - if (NBTProcessors.textComponentHasClickEvent(data.getString("Text" + (i + 1)))) - return null; + tryRemovingCommand(front_text, i); + tryRemovingCommand(back_text, i); } return data; }); @@ -57,6 +61,19 @@ public static void register() { NBTProcessors.addProcessor(AllBlockEntityTypes.PLACARD.get(), NBTProcessors.itemProcessor("Item")); } + private static void tryRemovingCommand(ListTag front_text, int i) { + if(NBTProcessors.textComponentHasClickEvent(front_text.get(i).getAsString())) + { + var text = + Component.Serializer.fromJson(front_text.get(i).getAsString()); + if (text != null) { + text.setStyle(text.getStyle().withClickEvent(null)); + front_text.remove(i); + front_text.add(i,net.minecraft.nbt.StringTag.valueOf(Component.Serializer.toJson(text))); + } + } + } + public static CompoundTag clipboardProcessor(CompoundTag data) { if (!data.contains("Item", Tag.TAG_COMPOUND)) return data; From bb4e659740f81289a61eabaa6e35892d159620a1 Mon Sep 17 00:00:00 2001 From: OLDREDSTONE Date: Tue, 25 Mar 2025 21:28:07 +0800 Subject: [PATCH 3/4] Removed commands for recursive tags --- .../foundation/CreateNBTProcessors.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java index 2f77c2d750..51c3204454 100644 --- a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java @@ -9,7 +9,10 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.nbt.StringTag; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Component.Serializer; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -23,10 +26,10 @@ public static void register() { NBTProcessors.addProcessor(BlockEntityType.SIGN, data -> { var front_text = data.getCompound("front_text").getList("messages", Tag.TAG_STRING); var back_text = data.getCompound("back_text").getList("messages", Tag.TAG_STRING); - for (int i = 0; i < 4; ++i) { - tryRemovingCommand(front_text, i); - tryRemovingCommand(back_text, i); - } + ListTag front_text2 = removeCommands(front_text); + ListTag back_text2 = removeCommands(back_text); + data.getCompound("front_text").put("messages",front_text2); + data.getCompound("back_text").put("messages",back_text2); return data; }); @@ -61,6 +64,33 @@ public static void register() { NBTProcessors.addProcessor(AllBlockEntityTypes.PLACARD.get(), NBTProcessors.itemProcessor("Item")); } + private static ListTag removeCommands(ListTag inList) { + ListTag result = new ListTag(); + inList.stream() + .map(t-> + { + var component = Serializer.fromJson(t.getAsString()); + if(component != null) { + return StringTag.valueOf(Serializer.toJson( + removeCommand(component) + )); + } + return StringTag.valueOf(""); + } + ) + .forEach(result::add); + return result; + } + + private static MutableComponent removeCommand(MutableComponent textComponent){ + textComponent.setStyle(textComponent.getStyle().withClickEvent(null)); + for(Component component : textComponent.getSiblings()) + { + if(component instanceof MutableComponent textComponent2) + removeCommand(textComponent2); + } + return textComponent; + } private static void tryRemovingCommand(ListTag front_text, int i) { if(NBTProcessors.textComponentHasClickEvent(front_text.get(i).getAsString())) { @@ -69,7 +99,7 @@ private static void tryRemovingCommand(ListTag front_text, int i) { if (text != null) { text.setStyle(text.getStyle().withClickEvent(null)); front_text.remove(i); - front_text.add(i,net.minecraft.nbt.StringTag.valueOf(Component.Serializer.toJson(text))); + front_text.add(i,StringTag.valueOf(Component.Serializer.toJson(text))); } } } From db8e9afa0e3cd704fe456c02d135a2fb1d6224e1 Mon Sep 17 00:00:00 2001 From: OLDREDSTONE Date: Wed, 26 Mar 2025 09:45:59 +0800 Subject: [PATCH 4/4] remove unnecessary codes --- .../create/foundation/CreateNBTProcessors.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java index 51c3204454..faf3e3ce4f 100644 --- a/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/CreateNBTProcessors.java @@ -21,8 +21,7 @@ public class CreateNBTProcessors { public static void register() { - // Remove the first layer of commands while preserving the styles. - // Since recursive commands won't be executed, there's no need to handle them. + // Remove commands while preserving the styles. NBTProcessors.addProcessor(BlockEntityType.SIGN, data -> { var front_text = data.getCompound("front_text").getList("messages", Tag.TAG_STRING); var back_text = data.getCompound("back_text").getList("messages", Tag.TAG_STRING); @@ -91,18 +90,6 @@ private static MutableComponent removeCommand(MutableComponent textComponent){ } return textComponent; } - private static void tryRemovingCommand(ListTag front_text, int i) { - if(NBTProcessors.textComponentHasClickEvent(front_text.get(i).getAsString())) - { - var text = - Component.Serializer.fromJson(front_text.get(i).getAsString()); - if (text != null) { - text.setStyle(text.getStyle().withClickEvent(null)); - front_text.remove(i); - front_text.add(i,StringTag.valueOf(Component.Serializer.toJson(text))); - } - } - } public static CompoundTag clipboardProcessor(CompoundTag data) { if (!data.contains("Item", Tag.TAG_COMPOUND))