use of net.minecraft.text.OrderedText in project EdenClient by HahaOO7.
the class AntiSpam method onChat.
private void onChat(AddChatMessageCallback.ChatAddEvent event) {
if (!enabled)
return;
List<ChatHudLine<OrderedText>> chatLines = event.getChatLines();
var chatText = event.getChatText();
if (chatText == null)
return;
if (chatLines.isEmpty())
return;
class JustGiveMeTheStringVisitor implements CharacterVisitor {
final StringBuilder sb = new StringBuilder();
@Override
public boolean accept(int index, Style style, int codePoint) {
sb.appendCodePoint(codePoint);
return true;
}
@Override
public String toString() {
return sb.toString();
}
}
ChatHud chat = MC.inGameHud.getChatHud();
int maxTextLength = MathHelper.floor(chat.getWidth() / chat.getChatScale());
List<OrderedText> newLines = ChatMessages.breakRenderedChatMessageLines(chatText, maxTextLength, MC.textRenderer);
int spamCounter = 1;
int matchingLines = 0;
for (int i = chatLines.size() - 1; i >= 0; i--) {
JustGiveMeTheStringVisitor oldLineVS = new JustGiveMeTheStringVisitor();
chatLines.get(i).getText().accept(oldLineVS);
String oldLine = oldLineVS.toString();
if (matchingLines <= newLines.size() - 1) {
JustGiveMeTheStringVisitor newLineVS = new JustGiveMeTheStringVisitor();
newLines.get(matchingLines).accept(newLineVS);
String newLine = newLineVS.toString();
if (matchingLines < newLines.size() - 1) {
if (oldLine.equals(newLine))
matchingLines++;
else
matchingLines = 0;
continue;
}
if (!oldLine.startsWith(newLine)) {
matchingLines = 0;
continue;
}
if (i > 0 && matchingLines == newLines.size() - 1) {
JustGiveMeTheStringVisitor nextOldLineVS = new JustGiveMeTheStringVisitor();
chatLines.get(i - 1).getText().accept(nextOldLineVS);
String nextOldLine = nextOldLineVS.toString();
String twoLines = oldLine + nextOldLine;
String addedText = twoLines.substring(newLine.length());
if (addedText.startsWith(" [x") && addedText.endsWith("]")) {
String oldSpamCounter = addedText.substring(3, addedText.length() - 1);
if (MathUtils.isInteger(oldSpamCounter)) {
spamCounter += Integer.parseInt(oldSpamCounter);
matchingLines++;
continue;
}
}
}
if (oldLine.length() == newLine.length())
spamCounter++;
else {
String addedText = oldLine.substring(newLine.length());
if (!addedText.startsWith(" [x") || !addedText.endsWith("]")) {
matchingLines = 0;
continue;
}
String oldSpamCounter = addedText.substring(3, addedText.length() - 1);
if (!MathUtils.isInteger(oldSpamCounter)) {
matchingLines = 0;
continue;
}
spamCounter += Integer.parseInt(oldSpamCounter);
}
}
if (i + matchingLines >= i) {
chatLines.subList(i, i + matchingLines + 1).clear();
}
matchingLines = 0;
}
if (spamCounter > 1) {
chatText = new LiteralText("").append(chatText).append(new LiteralText(" [x" + spamCounter + "]"));
}
event.setChatText(chatText);
}
use of net.minecraft.text.OrderedText in project AdvancedChatBox by DarkKronicle.
the class ChatSuggestorGui method showUsages.
private void showUsages(Formatting formatting) {
CommandContextBuilder<CommandSource> commandContextBuilder = this.suggestor.getParse().getContext();
SuggestionContext<CommandSource> suggestionContext = commandContextBuilder.findSuggestionContext(this.textField.getCursor());
Map<CommandNode<CommandSource>, String> map = this.client.player.networkHandler.getCommandDispatcher().getSmartUsage(suggestionContext.parent, this.client.player.networkHandler.getCommandSource());
List<OrderedText> list = new ArrayList<>();
int i = 0;
Style style = Style.EMPTY.withColor(formatting);
for (Map.Entry<CommandNode<CommandSource>, String> commandNodeStringEntry : map.entrySet()) {
if (!(commandNodeStringEntry.getKey() instanceof LiteralCommandNode)) {
list.add(OrderedText.styledForwardsVisitedString(commandNodeStringEntry.getValue(), style));
i = Math.max(i, this.textRenderer.getWidth(commandNodeStringEntry.getValue()));
}
}
if (!list.isEmpty()) {
this.messages.addAll(list);
this.x = MathHelper.clamp(this.textField.getCharacterX(suggestionContext.startPos), 0, this.textField.getCharacterX(0) + this.textField.getInnerWidth() - i);
this.width = i;
}
}
use of net.minecraft.text.OrderedText in project Moonfix by Kingdom-of-Moon.
the class SignBlockEntityRendererMixin method renderModel.
// sign scaling
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;II)V", shift = At.Shift.BEFORE), method = "render(Lnet/minecraft/block/entity/SignBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", locals = LocalCapture.CAPTURE_FAILHARD)
private void renderModel(SignBlockEntity signBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci, BlockState blockState, float g, SignType signType, SignBlockEntityRenderer.SignModel signModel, SpriteIdentifier h, VertexConsumer vertexConsumer) {
if (!(boolean) Config.SIGN_SCALE.value)
return;
// text len
float max = 90;
OrderedText[] texts = signBlockEntity.updateSign(MinecraftClient.getInstance().shouldFilterText(), Text::asOrderedText);
for (OrderedText text : texts) max = Math.max(this.textRenderer.getWidth(text), max);
max = (max + 6) / 96f;
if (max <= 1.01f)
return;
// stick
boolean wasStickVisible = signModel.stick.visible;
signModel.stick.visible = false;
// scale
matrixStack.push();
matrixStack.scale(max, 1.01f, 1.01f);
// render
signModel.root.render(matrixStack, vertexConsumer, i, j);
matrixStack.pop();
signModel.stick.visible = wasStickVisible;
}
Aggregations