Search in sources :

Example 36 with MutableText

use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.

the class CmdEnchant method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    if (!mc.interactionManager.getCurrentGameMode().isCreative()) {
        BleachLogger.error("Not In Creative Mode!");
        return;
    }
    if (args.length == 0) {
        throw new CmdSyntaxException();
    }
    if (args[0].equalsIgnoreCase("list")) {
        MutableText text = new LiteralText("");
        int i = 0;
        for (String[] s : enchantments.keySet()) {
            int color = i % 2 == 0 ? BleachLogger.INFO_COLOR : Formatting.AQUA.getColorValue();
            text.append(new LiteralText("\u00a77[\u00a7r" + String.join("\u00a77/\u00a7r", s) + "\u00a77] ").setStyle(Style.EMPTY.withColor(color)));
            i++;
        }
        BleachLogger.info(text);
        return;
    }
    int level = args.length == 1 ? 1 : Integer.parseInt(args[1]);
    ItemStack item = mc.player.getInventory().getMainHandStack();
    if (args[0].equalsIgnoreCase("all")) {
        for (Enchantment e : Registry.ENCHANTMENT) {
            enchant(item, e, level);
        }
        return;
    }
    int i = NumberUtils.toInt(args[0], -1);
    if (i != -1) {
        enchant(item, Enchantment.byRawId(i), level);
    } else {
        enchant(item, enchantments.entrySet().stream().filter(e -> ArrayUtils.contains(e.getKey(), args[0])).map(Entry::getValue).findFirst().orElse(null), level);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) LiteralText(net.minecraft.text.LiteralText)

Example 37 with MutableText

use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.

the class CmdFriends method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    if (args.length == 0 || args.length > 2) {
        throw new CmdSyntaxException();
    }
    if (args[0].equalsIgnoreCase("add")) {
        if (args.length < 2) {
            throw new CmdSyntaxException("No username selected");
        }
        BleachHack.friendMang.add(args[1]);
        BleachLogger.info("Added \"" + args[1] + "\" to the friend list");
    } else if (args[0].equalsIgnoreCase("remove")) {
        if (args.length < 2) {
            throw new CmdSyntaxException("No username selected");
        }
        BleachHack.friendMang.remove(args[1].toLowerCase(Locale.ENGLISH));
        BleachLogger.info("Removed \"" + args[1] + "\" from the friend list");
    } else if (args[0].equalsIgnoreCase("list")) {
        if (BleachHack.friendMang.getFriends().isEmpty()) {
            BleachLogger.info("You don't have any friends :(");
        } else {
            int len = BleachHack.friendMang.getFriends().stream().min((f1, f2) -> f2.length() - f1.length()).get().length() + 3;
            MutableText text = new LiteralText("Friends:");
            for (String f : BleachHack.friendMang.getFriends()) {
                String spaces = StringUtils.repeat(' ', len - f.length());
                text.append(new LiteralText("\n> " + f + spaces).styled(style -> style.withColor(BleachLogger.INFO_COLOR))).append(new LiteralText("\u00a7c[Del]").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Remove " + f + " from your friendlist"))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, getPrefix() + "friends remove " + f)))).append("   ").append(new LiteralText("\u00a73[NameMC]").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Open NameMC page of " + f))).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + f))));
            }
            BleachLogger.info(text);
        }
    } else if (args[0].equalsIgnoreCase("clear")) {
        BleachHack.friendMang.getFriends().clear();
        BleachLogger.info("Cleared Friend list");
    } else {
        throw new CmdSyntaxException();
    }
    BleachFileHelper.SCHEDULE_SAVE_FRIENDS.set(true);
}
Also used : LiteralText(net.minecraft.text.LiteralText) CommandCategory(org.bleachhack.command.CommandCategory) BleachHack(org.bleachhack.BleachHack) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) Locale(java.util.Locale) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Command(org.bleachhack.command.Command) BleachLogger(org.bleachhack.util.BleachLogger) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) HoverEvent(net.minecraft.text.HoverEvent) StringUtils(org.apache.commons.lang3.StringUtils) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 38 with MutableText

use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.

the class BleachTitleScreen method init.

@Override
public void init() {
    super.init();
    addWindow(new Window(width / 8, height / 8, width - width / 8, height - height / 8 + 2, "BleachHack", new ItemStack(Items.MUSIC_DISC_CAT)));
    int w = getWindow(0).x2 - getWindow(0).x1;
    int h = getWindow(0).y2 - getWindow(0).y1;
    int maxY = MathHelper.clamp(h / 4 + 119, 0, h - 22);
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 - 100, h / 4 + 38, w / 2 + 100, h / 4 + 58, I18n.translate("menu.singleplayer"), () -> client.setScreen(new SelectWorldScreen(client.currentScreen))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 - 100, h / 4 + 62, w / 2 + 100, h / 4 + 82, I18n.translate("menu.multiplayer"), () -> client.setScreen(new MultiplayerScreen(client.currentScreen))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 - 100, h / 4 + 86, w / 2 + 100, h / 4 + 106, I18n.translate("menu.online"), () -> client.setScreen(new RealmsMainScreen(this))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 - 124, h / 4 + 86, w / 2 - 104, h / 4 + 106, "MC", () -> {
        customTitleScreen = !customTitleScreen;
        BleachFileHelper.saveMiscSetting("customTitleScreen", new JsonPrimitive(false));
        client.setScreen(new TitleScreen(false));
    }));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 - 100, maxY, w / 2 - 2, maxY + 20, I18n.translate("menu.options"), () -> client.setScreen(new OptionsScreen(client.currentScreen, client.options))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 + 2, maxY, w / 2 + 100, maxY + 20, I18n.translate("menu.quit"), () -> client.scheduleStop()));
    // Main Text
    getWindow(0).addWidget(new WindowTextWidget(LiteralText.EMPTY, true, WindowTextWidget.TextAlign.MIDDLE, 3f, w / 2, h / 4 - 25, 0).withRenderEvent((widget, ms, wx, wy) -> {
        MutableText bhText = new LiteralText("");
        int i = 0;
        for (char c : "BleachHack".toCharArray()) {
            int fi = i++;
            bhText.append(new LiteralText(String.valueOf(c)).styled(s -> s.withColor(TextColor.fromRgb(UI.getRainbowFromSettings(fi)))));
        }
        ((WindowTextWidget) widget).setText(bhText);
    }));
    // Version Text
    getWindow(0).addWidget(new WindowTextWidget(BleachHack.VERSION, true, WindowTextWidget.TextAlign.MIDDLE, 1.5f, w / 2, h / 4 - 6, 0xffc050));
    // Splash
    getWindow(0).addWidget(new WindowTextWidget(LiteralText.EMPTY, true, WindowTextWidget.TextAlign.MIDDLE, 2f, -20f, w / 2 + 80, h / 4 + 6, 0xffff00).withRenderEvent((widget, ms, wx, wy) -> {
        if (splash != null) {
            WindowTextWidget windgetText = (WindowTextWidget) widget;
            windgetText.setText(new LiteralText(splash));
            windgetText.color = (windgetText.color & 0x00ffffff) | ((splashTicks * 17) << 24);
            float scale = 1.8F - MathHelper.abs(MathHelper.sin(Util.getMeasuringTimeMs() % 1000L / 1000.0F * 6.2831855F) * 0.1F);
            scale = scale * 66.0F / (textRenderer.getWidth(splash) + 32);
            windgetText.setScale(scale);
        }
    }));
    // Update Text
    JsonObject updateJson = BleachHack.getUpdateJson();
    if (updateJson != null && updateJson.has("version") && updateJson.get("version").getAsInt() > BleachHack.INTVERSION) {
        getWindow(0).addWidget(new WindowTextWidget("\u00a76\u00a7nUpdate\u00a76", true, 4, h - 12, 0xffffff).withClickEvent((widget, mx, my, wx, wy) -> client.setScreen(new UpdateScreen(client.currentScreen, updateJson))));
    }
}
Also used : Window(org.bleachhack.gui.window.Window) FabricLoader(net.fabricmc.loader.api.FabricLoader) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) SelectWorldScreen(net.minecraft.client.gui.screen.world.SelectWorldScreen) BodyHandlers(java.net.http.HttpResponse.BodyHandlers) Util(net.minecraft.util.Util) TranslatableText(net.minecraft.text.TranslatableText) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) Random(java.util.Random) ParticleManager(org.bleachhack.gui.effect.ParticleManager) WindowTextWidget(org.bleachhack.gui.window.widget.WindowTextWidget) ItemStack(net.minecraft.item.ItemStack) Window(org.bleachhack.gui.window.Window) MutableText(net.minecraft.text.MutableText) SharedConstants(net.minecraft.SharedConstants) JsonPrimitive(com.google.gson.JsonPrimitive) WindowScreen(org.bleachhack.gui.window.WindowScreen) I18n(net.minecraft.client.resource.language.I18n) UI(org.bleachhack.module.mods.UI) BleachHack(org.bleachhack.BleachHack) MatrixStack(net.minecraft.client.util.math.MatrixStack) Items(net.minecraft.item.Items) TextColor(net.minecraft.text.TextColor) WindowButtonWidget(org.bleachhack.gui.window.widget.WindowButtonWidget) OptionsScreen(net.minecraft.client.gui.screen.option.OptionsScreen) BleachOnlineMang(org.bleachhack.util.io.BleachOnlineMang) TitleScreen(net.minecraft.client.gui.screen.TitleScreen) List(java.util.List) MultiplayerScreen(net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen) MathHelper(net.minecraft.util.math.MathHelper) RealmsMainScreen(net.minecraft.client.realms.gui.screen.RealmsMainScreen) MutableText(net.minecraft.text.MutableText) JsonPrimitive(com.google.gson.JsonPrimitive) OptionsScreen(net.minecraft.client.gui.screen.option.OptionsScreen) WindowTextWidget(org.bleachhack.gui.window.widget.WindowTextWidget) JsonObject(com.google.gson.JsonObject) WindowButtonWidget(org.bleachhack.gui.window.widget.WindowButtonWidget) TitleScreen(net.minecraft.client.gui.screen.TitleScreen) MultiplayerScreen(net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen) RealmsMainScreen(net.minecraft.client.realms.gui.screen.RealmsMainScreen) ItemStack(net.minecraft.item.ItemStack) SelectWorldScreen(net.minecraft.client.gui.screen.world.SelectWorldScreen) LiteralText(net.minecraft.text.LiteralText)

Example 39 with MutableText

use of net.minecraft.text.MutableText in project mc-discord-bridge by Selicre.

the class DiscordBotImpl method onUserUpdateActivities.

@Override
public void onUserUpdateActivities(@Nonnull UserUpdateActivitiesEvent event) {
    String streamLink = null;
    for (Activity activity : event.getMember().getActivities()) {
        if (activity.getType() == Activity.ActivityType.STREAMING && Activity.isValidStreamingUrl(activity.getUrl())) {
            streamLink = activity.getUrl();
            break;
        }
    }
    UUID uuid = playerLookup.getPlayerProfileId(event.getUser());
    if (uuid != null) {
        boolean wasLive = livePlayers.contains(uuid);
        ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
        if (streamLink != null && !wasLive) {
            livePlayers.add(uuid);
            if (player != null) {
                MutableText message = new LiteralText("").append(discordUserToMinecraft(event.getUser(), getGuild(), false)).append(" is now streaming to ").append(new LiteralText(streamLink).setStyle(Style.EMPTY.withUnderline(true).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, streamLink))));
                if (config.hideChatFromStreamers) {
                    message.append(" - Chat has been disabled.");
                }
                broadcastNoMirror(message);
            }
        } else if (streamLink == null && wasLive) {
            livePlayers.remove(uuid);
            if (player != null) {
                broadcastNoMirror(new LiteralText("").append(discordUserToMinecraft(event.getUser(), getGuild(), false)).append(" is no longer streaming. Chat has been reenabled."));
            }
        }
    }
}
Also used : MutableText(net.minecraft.text.MutableText) ClickEvent(net.minecraft.text.ClickEvent) Activity(net.dv8tion.jda.api.entities.Activity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) LiteralText(net.minecraft.text.LiteralText)

Example 40 with MutableText

use of net.minecraft.text.MutableText in project SeedMapper by xpple.

the class TextUtil method formatList.

public static MutableText formatList(List<MutableText> list) {
    MutableText output = new LiteralText("");
    AtomicInteger count = new AtomicInteger(0);
    list.forEach(text -> {
        int index = count.getAndIncrement();
        output.append(text).append(base(index == list.size() - 1 ? "" : index == list.size() - 2 ? " and " : ", "));
    });
    return output;
}
Also used : MutableText(net.minecraft.text.MutableText) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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