Search in sources :

Example 1 with BleachHack

use of org.bleachhack.BleachHack in project BleachHack by BleachDrinker420.

the class UpdateScreen method init.

public void init() {
    super.init();
    int wd = Math.min(width / 2 - 30, 175);
    addWindow(new Window(width / 2 - wd, height / 16, width / 2 + wd, height - height / 16, String.format("BleachHack Update [%s -> %s]", BleachHack.VERSION, updateJson.get("name").getAsString()), new ItemStack(Items.MAGENTA_GLAZED_TERRACOTTA)));
    int w = getWindow(0).x2 - getWindow(0).x1;
    int h = getWindow(0).y2 - getWindow(0).y1;
    getWindow(0).addWidget(new WindowTextWidget("A new BleachHack update is available.", true, WindowTextWidget.TextAlign.MIDDLE, 1.5f, w / 2, 18, 0xe0e0e0));
    getWindow(0).addWidget(new WindowBoxWidget(3, 50, w - 3, h - 23));
    ImmutablePairList<String, Boolean> changelog = new ImmutablePairList<>();
    if (updateJson.has("changelog") && updateJson.get("changelog").isJsonArray()) {
        for (JsonElement je : updateJson.get("changelog").getAsJsonArray()) {
            if (je.isJsonPrimitive()) {
                String string = je.getAsString();
                if (string.charAt(0) == '-')
                    string = "\u00a77-\u00a7r" + string.substring(1);
                List<StringVisitable> wrapped = client.textRenderer.getTextHandler().wrapLines(string, w - 32, Style.EMPTY);
                for (int i = 0; i < wrapped.size(); i++) changelog.add(wrapped.get(i).getString(), i == 0);
            }
        }
    } else {
        changelog.add("Could not find changelog.", false);
    }
    changelogWidgets.clear();
    changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(updateJson.get("name").getAsString(), true, WindowTextWidget.TextAlign.MIDDLE, 2.5f, w / 2, 58, 0xe0e0e0)));
    for (int i = 0; i < changelog.size(); i++) {
        if (changelog.get(i).getValue()) {
            changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget("*", true, 10, 87 + i * 10, 0xa0a0a0)));
        }
        changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(changelog.get(i).getKey(), true, 19, 85 + i * 10, 0xe0e0e0)));
    }
    scrollbar = getWindow(0).addWidget(new WindowScrollbarWidget(w - 14, 51, 37 + changelog.size() * 10, h - 75, 0));
    getWindow(0).addWidget(new WindowButtonWidget(3, h - 21, w / 2 - 2, h - 3, "Website", () -> Util.getOperatingSystem().open(URI.create("https://bleachhack.org/"))));
    getWindow(0).addWidget(new WindowButtonWidget(w / 2 + 2, h - 21, w - 3, h - 3, "Update", () -> {
        try {
            JsonObject installerJson = updateJson.get("installer").getAsJsonObject();
            if (installerJson.has("os") && installerJson.get("os").isJsonPrimitive() && !System.getProperty("os.name").startsWith(installerJson.get("os").getAsString())) {
                updateResult = "Updater doesn't support your OS!";
                selectWindow(1);
                return;
            }
            File modpath = new File(FabricLoader.getInstance().getModContainer("bleachhack").get().getOrigin().getPaths().get(0).toUri());
            if (!modpath.isFile()) {
                updateResult = "Invalid mod path!";
                selectWindow(1);
                return;
            }
            String link = installerJson.get("link").getAsString();
            String name = link.replaceFirst("^.*\\/", "");
            File installerFile = new File(System.getProperty("java.io.tmpdir"), name);
            BleachLogger.logger.info("\n> Installer path: " + installerFile + "\n> Installer URL: " + link + "\n> Installer file name: " + name + "\n> Regular File: " + Files.isRegularFile(installerFile.toPath()) + "\n> File Length: " + installerFile.length());
            if (!Files.isRegularFile(installerFile.toPath()) || installerFile.length() <= 1024L) {
                FileUtils.copyURLToFile(new URL(link), installerFile);
            }
            String execCommand = link.endsWith(".jar") ? "java -jar " : "cmd /c start ";
            Runtime.getRuntime().exec(execCommand + installerFile.getAbsolutePath() + " " + modpath + " " + installerJson.get("url").getAsString());
            client.scheduleStop();
        } catch (Exception e) {
            updateResult = "Unknown error!";
            selectWindow(1);
            e.printStackTrace();
        }
    }));
    wd = Math.min(width / 2 - 20, 90);
    addWindow(new Window(width / 2 - wd, height / 2 - 15, width / 2 + wd, height / 2 + 15, "Error updating!", new ItemStack(Items.RED_BANNER), true));
    getWindow(1).addWidget(new WindowTextWidget("", true, WindowTextWidget.TextAlign.MIDDLE, wd, 16, 0xc05050).withRenderEvent((wg, ms, wx, wy) -> ((WindowTextWidget) wg).setText(new LiteralText(updateResult))));
}
Also used : Window(org.bleachhack.gui.window.Window) FabricLoader(net.fabricmc.loader.api.FabricLoader) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) Util(net.minecraft.util.Util) URL(java.net.URL) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Style(net.minecraft.text.Style) StringVisitable(net.minecraft.text.StringVisitable) Window(org.bleachhack.gui.window.Window) BleachLogger(org.bleachhack.util.BleachLogger) ImmutablePairList(org.bleachhack.util.collections.ImmutablePairList) URI(java.net.URI) org.bleachhack.gui.window.widget(org.bleachhack.gui.window.widget) WindowScreen(org.bleachhack.gui.window.WindowScreen) Files(java.nio.file.Files) BleachHack(org.bleachhack.BleachHack) MatrixStack(net.minecraft.client.util.math.MatrixStack) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) Items(net.minecraft.item.Items) File(java.io.File) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) ImmutablePairList(org.bleachhack.util.collections.ImmutablePairList) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) JsonElement(com.google.gson.JsonElement) StringVisitable(net.minecraft.text.StringVisitable) ItemStack(net.minecraft.item.ItemStack) File(java.io.File) LiteralText(net.minecraft.text.LiteralText)

Example 2 with BleachHack

use of org.bleachhack.BleachHack 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)

Aggregations

JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 FabricLoader (net.fabricmc.loader.api.FabricLoader)2 MatrixStack (net.minecraft.client.util.math.MatrixStack)2 ItemStack (net.minecraft.item.ItemStack)2 Items (net.minecraft.item.Items)2 LiteralText (net.minecraft.text.LiteralText)2 Util (net.minecraft.util.Util)2 BleachHack (org.bleachhack.BleachHack)2 Window (org.bleachhack.gui.window.Window)2 WindowScreen (org.bleachhack.gui.window.WindowScreen)2 JsonElement (com.google.gson.JsonElement)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 File (java.io.File)1 URI (java.net.URI)1 URL (java.net.URL)1 BodyHandlers (java.net.http.HttpResponse.BodyHandlers)1 Files (java.nio.file.Files)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1