Skip to content

Commit

Permalink
Concatenate sign lines to allow for multiline search
Browse files Browse the repository at this point in the history
  • Loading branch information
xpple committed Jan 7, 2025
1 parent 00a34cc commit 686eb6c
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minecraft.world.level.block.state.BlockState;

import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.mojang.brigadier.arguments.StringArgumentType.*;
import static net.earthcomputer.clientcommands.command.arguments.RegexArgument.*;
Expand Down Expand Up @@ -55,15 +57,12 @@ public boolean test(HolderLookup.Provider holderLookupProvider, BlockGetter bloc
return false;
}

SignText frontText = sign.getFrontText();
SignText backText = sign.getBackText();
for (int i = 0; i < SignText.LINES; i++) {
String line = frontText.getMessage(i, Minecraft.getInstance().isTextFilteringEnabled()).getString();
if (linePredicate.test(line)) {
return true;
}
line = backText.getMessage(i, Minecraft.getInstance().isTextFilteringEnabled()).getString();
if (linePredicate.test(line)) {
boolean textFilteringEnabled = Minecraft.getInstance().isTextFilteringEnabled();
for (SignText text : new SignText[]{sign.getFrontText(), sign.getBackText()}) {
String string = IntStream.range(0, SignText.LINES)
.mapToObj(i -> text.getMessage(i, textFilteringEnabled).getString())
.collect(Collectors.joining("\n"));
if (linePredicate.test(string)) {
return true;
}
}
Expand All @@ -77,5 +76,4 @@ public boolean canEverMatch(BlockState state) {
}
};
}

}

0 comments on commit 686eb6c

Please sign in to comment.