Search in sources :

Example 16 with MutableText

use of net.minecraft.text.MutableText in project Client by MatHax.

the class ClientConnectionMixin method disconnect.

@Inject(method = "disconnect", at = @At("HEAD"))
private void disconnect(Text disconnectReason, CallbackInfo info) {
    if (Modules.get().get(HighwayBuilder.class).isActive()) {
        MutableText text = new LiteralText(String.format("\n\n%s[%sHighway Builder%s] Statistics:", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)).append("\n");
        text.append(Modules.get().get(HighwayBuilder.class).getStatsText());
        ((MutableText) disconnectReason).append(text);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) HighwayBuilder(mathax.client.systems.modules.world.HighwayBuilder) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with MutableText

use of net.minecraft.text.MutableText in project Client by MatHax.

the class BookBot method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
    // Check if there is a book to write
    if (!writableBook.found()) {
        toggle();
        return;
    }
    // Move the book into hand
    if (!writableBook.isMainHand()) {
        InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
        return;
    }
    // If somehow it failed, just dont do anything until it tries again
    FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
    if (!finalBook.isMainHand())
        return;
    // Check delay
    if (delayTimer > 0) {
        delayTimer--;
        return;
    }
    // Reset delay
    delayTimer = delay.get();
    if (mode.get() == Mode.Random) {
        int origin = onlyAscii.get() ? 0x21 : 0x0800;
        int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
        writeBook(// Generate a random load of ints to use as random characters
        random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
    } else if (mode.get() == Mode.File) {
        // Ignore if somehow the file got deleted
        if ((file == null || !file.exists()) && mode.get() == Mode.File) {
            info("No file selected, please select a file in the GUI.");
            toggle();
            return;
        }
        // Handle the file being empty
        if (file.length() == 0) {
            MutableText message = new LiteralText("");
            message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
            message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
            info(message);
            toggle();
            return;
        }
        // Read each line of the file and construct a string with the needed line breaks
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            StringBuilder file = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                file.append(line).append('\n');
            }
            reader.close();
            // Write the file string to a book
            writeBook(file.toString().chars().iterator());
        } catch (IOException ignored) {
            error("Failed to read the file.");
        }
    }
}
Also used : MutableText(net.minecraft.text.MutableText) ClickEvent(net.minecraft.text.ClickEvent) FindItemResult(mathax.client.utils.player.FindItemResult) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) LiteralText(net.minecraft.text.LiteralText) EventHandler(mathax.client.eventbus.EventHandler)

Example 18 with MutableText

use of net.minecraft.text.MutableText in project Client by MatHax.

the class SoundLocator method printSound.

private void printSound(SoundInstance sound) {
    WeightedSoundSet soundSet = mc.getSoundManager().get(sound.getId());
    MutableText text = soundSet.getSubtitle().copy();
    text.append(String.format("%s at ", Formatting.GRAY));
    Vec3d pos = new Vec3d(sound.getX(), sound.getY(), sound.getZ());
    text.append(ChatUtils.formatCoords(pos));
    text.append(String.format("%s.", Formatting.GRAY));
    info(text);
}
Also used : MutableText(net.minecraft.text.MutableText) WeightedSoundSet(net.minecraft.client.sound.WeightedSoundSet) Vec3d(net.minecraft.util.math.Vec3d)

Example 19 with MutableText

use of net.minecraft.text.MutableText in project Client by MatHax.

the class BindsCommand method getTooltip.

private MutableText getTooltip(Module module) {
    MutableText tooltip = new LiteralText(module.description).formatted(Formatting.BLUE, Formatting.BOLD).append("\n\n");
    tooltip.append(new LiteralText(module.description).formatted(Formatting.WHITE));
    return tooltip;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Example 20 with MutableText

use of net.minecraft.text.MutableText in project factions by ickerio.

the class MapCommand method show.

public static int show(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    ServerWorld world = player.getWorld();
    ChunkPos chunkPos = world.getChunk(player.getBlockPos()).getPos();
    String dimension = world.getRegistryKey().getValue().toString();
    Member member = Member.get(player.getUuid());
    Faction faction = member == null ? null : member.getFaction();
    // Print the header of the faction map.
    new Message("---------------[").format(Formatting.GRAY).add(new Message(" F MAP ").format(Formatting.AQUA)).add(new Message("]---------------").format(Formatting.GRAY)).send(player, false);
    Map<String, Formatting> factions = new HashMap<>();
    // Create and fill an array with the faction map.
    MutableText[] rows = new MutableText[11];
    for (int z = -5; z <= 5; z++) {
        MutableText row = new LiteralText("");
        for (int x = -6; x <= 6; x++) {
            Claim claim = Claim.get(chunkPos.x + x, chunkPos.z + z, dimension);
            if (x == 0 && z == 0) {
                row.append(new LiteralText(" ■").formatted(Formatting.YELLOW));
            } else if (claim == null) {
                row.append(new LiteralText(" ■").formatted(Formatting.GRAY));
            } else if (faction != null && claim.getFaction().name.equals(faction.name)) {
                row.append(new LiteralText(" ■").formatted(Formatting.GREEN));
            } else {
                Faction owner = claim.getFaction();
                factions.put(owner.name, owner.color);
                row.append(new LiteralText(" ■").formatted(owner.color).styled((style) -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(owner.name)))));
            }
        }
        rows[z + 5] = row;
    }
    // Attach the legend to the rows and send them to the player.
    player.sendMessage(rows[0].append(new LiteralText("  ■").formatted(Formatting.GRAY)).append(" Wilderness"), false);
    player.sendMessage(rows[1].append(new LiteralText("  ■").formatted(Formatting.GREEN)).append(" Your faction"), false);
    player.sendMessage(rows[2].append(new LiteralText("  ■").formatted(Formatting.YELLOW)).append(" Your position"), false);
    int i = 3;
    for (Map.Entry<String, Formatting> entry : factions.entrySet()) {
        if (i >= rows.length)
            break;
        player.sendMessage(rows[i].append(new LiteralText("  ■").formatted(entry.getValue())).append(" " + entry.getKey()), false);
        i++;
    }
    // Send remaining rows.
    for (; i < rows.length; i++) {
        player.sendMessage(rows[i], false);
    }
    // Print the footer of the faction map.
    new Message("---------------------------------------").format(Formatting.GRAY).send(player, false);
    return 1;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandContext(com.mojang.brigadier.context.CommandContext) Faction(io.icker.factions.database.Faction) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkPos(net.minecraft.util.math.ChunkPos) HoverEvent(net.minecraft.text.HoverEvent) Formatting(net.minecraft.util.Formatting) Claim(io.icker.factions.database.Claim) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) MutableText(net.minecraft.text.MutableText) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Message(io.icker.factions.util.Message) Member(io.icker.factions.database.Member) HoverEvent(net.minecraft.text.HoverEvent) Message(io.icker.factions.util.Message) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkPos(net.minecraft.util.math.ChunkPos) Member(io.icker.factions.database.Member) Claim(io.icker.factions.database.Claim) Faction(io.icker.factions.database.Faction) LiteralText(net.minecraft.text.LiteralText)

Aggregations

MutableText (net.minecraft.text.MutableText)40 LiteralText (net.minecraft.text.LiteralText)34 HoverEvent (net.minecraft.text.HoverEvent)8 ClickEvent (net.minecraft.text.ClickEvent)7 Text (net.minecraft.text.Text)7 Formatting (net.minecraft.util.Formatting)6 List (java.util.List)5 TranslatableText (net.minecraft.text.TranslatableText)5 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 CommandSource (net.minecraft.command.CommandSource)3 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)2 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2