Search in sources :

Example 1 with EditBookTitleAndAuthorScreen

use of meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen in project meteor-client by MeteorDevelopment.

the class BookScreenMixin method onInit.

@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
    addDrawableChild(new ButtonWidget(4, 4, 120, 20, new LiteralText("Copy"), button -> {
        NbtList listTag = new NbtList();
        for (int i = 0; i < contents.getPageCount(); i++) listTag.add(NbtString.of(contents.getPage(i).getString()));
        NbtCompound tag = new NbtCompound();
        tag.put("pages", listTag);
        tag.putInt("currentPage", pageIndex);
        FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bytes);
        try {
            NbtIo.write(tag, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
    }));
    // Edit title & author
    ItemStack itemStack = mc.player.getMainHandStack();
    Hand hand = Hand.MAIN_HAND;
    if (itemStack.getItem() != Items.WRITTEN_BOOK) {
        itemStack = mc.player.getOffHandStack();
        hand = Hand.OFF_HAND;
    }
    if (itemStack.getItem() != Items.WRITTEN_BOOK)
        return;
    // Fuck you Java
    ItemStack book = itemStack;
    // Honestly
    Hand hand2 = hand;
    addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Edit title & author"), button -> {
        mc.setScreen(new EditBookTitleAndAuthorScreen(GuiThemes.get(), book, hand2));
    }));
}
Also used : NbtIo(net.minecraft.nbt.NbtIo) LiteralText(net.minecraft.text.LiteralText) EditBookTitleAndAuthorScreen(meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen) Inject(org.spongepowered.asm.mixin.injection.Inject) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) BookScreen(net.minecraft.client.gui.screen.ingame.BookScreen) DataOutputStream(java.io.DataOutputStream) Mixin(org.spongepowered.asm.mixin.Mixin) Hand(net.minecraft.util.Hand) At(org.spongepowered.asm.mixin.injection.At) MeteorClient.mc(meteordevelopment.meteorclient.MeteorClient.mc) GuiThemes(meteordevelopment.meteorclient.gui.GuiThemes) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) IOException(java.io.IOException) Items(net.minecraft.item.Items) GLFW(org.lwjgl.glfw.GLFW) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) Base64(java.util.Base64) Screen(net.minecraft.client.gui.screen.Screen) Shadow(org.spongepowered.asm.mixin.Shadow) Text(net.minecraft.text.Text) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) NbtCompound(net.minecraft.nbt.NbtCompound) DataOutputStream(java.io.DataOutputStream) EditBookTitleAndAuthorScreen(meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen) NbtList(net.minecraft.nbt.NbtList) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

FastByteArrayOutputStream (it.unimi.dsi.fastutil.io.FastByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 MeteorClient.mc (meteordevelopment.meteorclient.MeteorClient.mc)1 GuiThemes (meteordevelopment.meteorclient.gui.GuiThemes)1 EditBookTitleAndAuthorScreen (meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen)1 Screen (net.minecraft.client.gui.screen.Screen)1 BookScreen (net.minecraft.client.gui.screen.ingame.BookScreen)1 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)1 ItemStack (net.minecraft.item.ItemStack)1 Items (net.minecraft.item.Items)1 NbtCompound (net.minecraft.nbt.NbtCompound)1 NbtIo (net.minecraft.nbt.NbtIo)1 NbtList (net.minecraft.nbt.NbtList)1 NbtString (net.minecraft.nbt.NbtString)1 LiteralText (net.minecraft.text.LiteralText)1 Text (net.minecraft.text.Text)1 Hand (net.minecraft.util.Hand)1 GLFW (org.lwjgl.glfw.GLFW)1