Skip to content

fix the blueprint printing command bug for the sign (1.20.1) #8108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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;
Expand All @@ -17,12 +21,14 @@

public class CreateNBTProcessors {
public static void register() {

// Remove commands while preserving the styles.
NBTProcessors.addProcessor(BlockEntityType.SIGN, data -> {
for (int i = 0; i < 4; ++i) {
if (NBTProcessors.textComponentHasClickEvent(data.getString("Text" + (i + 1))))
return null;
}
var front_text = data.getCompound("front_text").getList("messages", Tag.TAG_STRING);
var back_text = data.getCompound("back_text").getList("messages", Tag.TAG_STRING);
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;
});

Expand Down Expand Up @@ -57,6 +63,34 @@ 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;
}

public static CompoundTag clipboardProcessor(CompoundTag data) {
if (!data.contains("Item", Tag.TAG_COMPOUND))
return data;
Expand Down