Search in sources :

Example 1 with NbtString

use of net.minecraft.nbt.NbtString in project BleachHack by BleachDrinker420.

the class BookCrash method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    delay = (delay >= getSetting(2).asSlider().getValue() ? 0 : delay + 1);
    if (delay > 0)
        return;
    ItemStack bookObj = new ItemStack(Items.WRITABLE_BOOK);
    NbtList list = new NbtList();
    NbtCompound tag = new NbtCompound();
    String author = "Bleach";
    String title = "\n Bleachhack Owns All \n";
    String size = "";
    int pages = Math.min(getSetting(4).asSlider().getValueInt(), 100);
    int pageChars = 210;
    if (getSetting(3).asMode().getMode() == 2) {
        IntStream chars = new Random().ints(0x80, 0x10FFFF - 0x800).map(i -> i < 0xd800 ? i : i + 0x800);
        size = chars.limit(pageChars * pages).mapToObj(i -> String.valueOf((char) i)).collect(Collectors.joining());
    } else if (getSetting(3).asMode().getMode() == 1) {
        size = repeat(pages * pageChars, String.valueOf(0x10FFFF));
    } else if (getSetting(3).asMode().getMode() == 0) {
        IntStream chars = new Random().ints(0x20, 0x7E);
        size = chars.limit(pageChars * pages).mapToObj(i -> String.valueOf((char) i)).collect(Collectors.joining());
    } else if (getSetting(3).asMode().getMode() == 3) {
        size = "wveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5vr2c43rc434v432tvt4tvybn4n6n57u6u57m6m6678mi68,867,79o,o97o,978iun7yb65453v4tyv34t4t3c2cc423rc334tcvtvt43tv45tvt5t5v43tv5345tv43tv5355vt5t3tv5t533v5t45tv43vt4355t54fwveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5vr2c43rc434v432tvt4tvybn4n6n57u6u57m6m6678mi68,867,79o,o97o,978iun7yb65453v4tyv34t4t3c2cc423rc334tcvtvt43tv45tvt5t5v43tv5345tv43tv5355vt5t3tv5t533v5t45tv43vt4355t54fwveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5";
    }
    if (getSetting(0).asMode().getMode() == 2) {
        String text = "bh ontop";
        Random rand = new Random();
        for (int i = 0; i < getSetting(1).asSlider().getValue(); i++) {
            mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(new BlockPos(rand.nextInt(29999999), rand.nextInt(29999999), rand.nextInt(29999999)), text, text, text, text));
        }
    } else {
        for (int i = 0; i < pages; i++) {
            NbtString tString = NbtString.of(size);
            list.add(tString);
        }
        tag.putString("author", author);
        tag.putString("title", title);
        tag.put("pages", list);
        bookObj.setSubNbt("pages", list);
        bookObj.setNbt(tag);
        for (int i = 0; i < getSetting(1).asSlider().getValue(); i++) {
            if (getSetting(0).asMode().getMode() == 0) {
                Int2ObjectMap<ItemStack> map = new Int2ObjectOpenHashMap<>(1);
                map.put(0, bookObj);
                mc.player.networkHandler.sendPacket(new ClickSlotC2SPacket(0, 0, 0, 0, SlotActionType.PICKUP, bookObj, map));
            } else {
                mc.player.networkHandler.sendPacket(new CreativeInventoryActionC2SPacket(0, bookObj));
            }
        }
    }
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) NbtCompound(net.minecraft.nbt.NbtCompound) UpdateSignC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket) NbtString(net.minecraft.nbt.NbtString) NbtString(net.minecraft.nbt.NbtString) ClickSlotC2SPacket(net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket) Random(java.util.Random) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) IntStream(java.util.stream.IntStream) CreativeInventoryActionC2SPacket(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with NbtString

use of net.minecraft.nbt.NbtString in project meteor-client by MeteorDevelopment.

the class BookBot method writeBook.

private void writeBook(PrimitiveIterator.OfInt chars) {
    ArrayList<String> pages = new ArrayList<>();
    for (int pageI = 0; pageI < (mode.get() == Mode.File ? 100 : this.pages.get()); pageI++) {
        // Check if the stream is empty before creating a new page
        if (!chars.hasNext())
            break;
        StringBuilder page = new StringBuilder();
        for (int lineI = 0; lineI < 13; lineI++) {
            // Check if the stream is empty before creating a new line
            if (!chars.hasNext())
                break;
            double lineWidth = 0;
            StringBuilder line = new StringBuilder();
            while (true) {
                // Check if the stream is empty
                if (!chars.hasNext())
                    break;
                // Get the next character
                int nextChar = chars.nextInt();
                // Ignore newline chars when writing lines, should already be organised
                if (nextChar == '\r' || nextChar == '\n')
                    break;
                // Make sure the character will fit on the line
                double charWidth = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever().getWidth(nextChar, Style.EMPTY);
                if (lineWidth + charWidth > 114)
                    break;
                // Append it to the line
                line.appendCodePoint(nextChar);
                lineWidth += charWidth;
            }
            // Append the line to the page
            page.append(line).append('\n');
        }
        // Append page to the page list
        pages.add(page.toString());
    }
    // Get the title with count
    String title = name.get();
    if (count.get() && bookCount != 0)
        title += " #" + bookCount;
    // Write data to book
    mc.player.getMainHandStack().setSubNbt("title", NbtString.of(title));
    mc.player.getMainHandStack().setSubNbt("author", NbtString.of(mc.player.getGameProfile().getName()));
    // Write pages NBT
    NbtList pageNbt = new NbtList();
    pages.stream().map(NbtString::of).forEach(pageNbt::add);
    if (!pages.isEmpty())
        mc.player.getMainHandStack().setSubNbt("pages", pageNbt);
    // Send book update to server
    mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, Optional.of(title)));
    bookCount++;
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) ArrayList(java.util.ArrayList) NbtList(net.minecraft.nbt.NbtList) NbtString(net.minecraft.nbt.NbtString)

Example 3 with NbtString

use of net.minecraft.nbt.NbtString in project Client by MatHax.

the class BookEditScreenMixin 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();
        pages.stream().map(NbtString::of).forEach(listTag::add);
        NbtCompound tag = new NbtCompound();
        tag.put("pages", listTag);
        tag.putInt("currentPage", currentPage);
        FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bytes);
        try {
            NbtIo.write(tag, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
        } catch (OutOfMemoryError exception) {
            GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), exception.toString());
        }
    }));
    addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Paste"), button -> {
        String clipboard = GLFW.glfwGetClipboardString(mc.getWindow().getHandle());
        if (clipboard == null)
            return;
        byte[] bytes;
        try {
            bytes = Base64.getDecoder().decode(clipboard);
        } catch (IllegalArgumentException ignored) {
            return;
        }
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
        try {
            NbtCompound tag = NbtIo.read(in);
            NbtList listTag = tag.getList("pages", 8).copy();
            pages.clear();
            for (int i = 0; i < listTag.size(); ++i) {
                pages.add(listTag.getString(i));
            }
            if (pages.isEmpty())
                pages.add("");
            currentPage = tag.getInt("currentPage");
            dirty = true;
            updateButtons();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }));
}
Also used : NbtIo(net.minecraft.nbt.NbtIo) LiteralText(net.minecraft.text.LiteralText) DataInputStream(java.io.DataInputStream) Inject(org.spongepowered.asm.mixin.injection.Inject) NbtList(net.minecraft.nbt.NbtList) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) IOException(java.io.IOException) Final(org.spongepowered.asm.mixin.Final) GLFW(org.lwjgl.glfw.GLFW) MatHax.mc(mathax.client.MatHax.mc) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Base64(java.util.Base64) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) Text(net.minecraft.text.Text) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) BookEditScreen(net.minecraft.client.gui.screen.ingame.BookEditScreen) At(org.spongepowered.asm.mixin.injection.At) NbtCompound(net.minecraft.nbt.NbtCompound) DataOutputStream(java.io.DataOutputStream) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) NbtString(net.minecraft.nbt.NbtString) DataInputStream(java.io.DataInputStream) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) NbtList(net.minecraft.nbt.NbtList) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with NbtString

use of net.minecraft.nbt.NbtString in project meteor-client by MeteorDevelopment.

the class BookEditScreenMixin 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();
        pages.stream().map(NbtString::of).forEach(listTag::add);
        NbtCompound tag = new NbtCompound();
        tag.put("pages", listTag);
        tag.putInt("currentPage", currentPage);
        FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bytes);
        try {
            NbtIo.write(tag, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
        } catch (OutOfMemoryError exception) {
            GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), exception.toString());
        }
    }));
    addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Paste"), button -> {
        String clipboard = GLFW.glfwGetClipboardString(mc.getWindow().getHandle());
        if (clipboard == null)
            return;
        byte[] bytes;
        try {
            bytes = Base64.getDecoder().decode(clipboard);
        } catch (IllegalArgumentException ignored) {
            return;
        }
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
        try {
            NbtCompound tag = NbtIo.read(in);
            NbtList listTag = tag.getList("pages", 8).copy();
            pages.clear();
            for (int i = 0; i < listTag.size(); ++i) {
                pages.add(listTag.getString(i));
            }
            if (pages.isEmpty()) {
                pages.add("");
            }
            currentPage = tag.getInt("currentPage");
            dirty = true;
            updateButtons();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }));
}
Also used : NbtIo(net.minecraft.nbt.NbtIo) LiteralText(net.minecraft.text.LiteralText) DataInputStream(java.io.DataInputStream) Inject(org.spongepowered.asm.mixin.injection.Inject) NbtList(net.minecraft.nbt.NbtList) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) IOException(java.io.IOException) Final(org.spongepowered.asm.mixin.Final) GLFW(org.lwjgl.glfw.GLFW) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Base64(java.util.Base64) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) Text(net.minecraft.text.Text) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) BookEditScreen(net.minecraft.client.gui.screen.ingame.BookEditScreen) At(org.spongepowered.asm.mixin.injection.At) MeteorClient.mc(meteordevelopment.meteorclient.MeteorClient.mc) NbtCompound(net.minecraft.nbt.NbtCompound) DataOutputStream(java.io.DataOutputStream) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) NbtString(net.minecraft.nbt.NbtString) DataInputStream(java.io.DataInputStream) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) FastByteArrayOutputStream(it.unimi.dsi.fastutil.io.FastByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) NbtList(net.minecraft.nbt.NbtList) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with NbtString

use of net.minecraft.nbt.NbtString in project Client by MatHax.

the class BookBot method writeBook.

private void writeBook(PrimitiveIterator.OfInt chars) {
    ArrayList<String> pages = new ArrayList<>();
    for (int pageI = 0; pageI < (mode.get() == Mode.File ? 100 : this.pages.get()); pageI++) {
        // Check if the stream is empty before creating a new page
        if (!chars.hasNext())
            break;
        StringBuilder page = new StringBuilder();
        for (int lineI = 0; lineI < 13; lineI++) {
            // Check if the stream is empty before creating a new line
            if (!chars.hasNext())
                break;
            double lineWidth = 0;
            StringBuilder line = new StringBuilder();
            while (true) {
                // Check if the stream is empty
                if (!chars.hasNext())
                    break;
                // Get the next character
                int nextChar = chars.nextInt();
                // Ignore newline chars when writing lines, should already be organised
                if (nextChar == '\r' || nextChar == '\n')
                    break;
                // Make sure the character will fit on the line
                double charWidth = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever().getWidth(nextChar, Style.EMPTY);
                if (lineWidth + charWidth > 114)
                    break;
                // Append it to the line
                line.appendCodePoint(nextChar);
                lineWidth += charWidth;
            }
            // Append the line to the page
            page.append(line).append('\n');
        }
        // Append page to the page list
        pages.add(page.toString());
    }
    // Get the title with count
    String title = name.get();
    if (count.get() && bookCount != 0)
        title += " #" + bookCount;
    // Write data to book
    mc.player.getMainHandStack().setSubNbt("title", NbtString.of(title));
    mc.player.getMainHandStack().setSubNbt("author", NbtString.of(mc.player.getGameProfile().getName()));
    // Write pages NBT
    NbtList pageNbt = new NbtList();
    pages.stream().map(NbtString::of).forEach(pageNbt::add);
    if (!pages.isEmpty())
        mc.player.getMainHandStack().setSubNbt("pages", pageNbt);
    // Send book update to server
    mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, Optional.of(title)));
    bookCount++;
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) ArrayList(java.util.ArrayList) NbtList(net.minecraft.nbt.NbtList) NbtString(net.minecraft.nbt.NbtString)

Aggregations

NbtList (net.minecraft.nbt.NbtList)5 NbtString (net.minecraft.nbt.NbtString)5 NbtCompound (net.minecraft.nbt.NbtCompound)3 FastByteArrayOutputStream (it.unimi.dsi.fastutil.io.FastByteArrayOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Base64 (java.util.Base64)2 List (java.util.List)2 Screen (net.minecraft.client.gui.screen.Screen)2 BookEditScreen (net.minecraft.client.gui.screen.ingame.BookEditScreen)2 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)2 NbtIo (net.minecraft.nbt.NbtIo)2 BookUpdateC2SPacket (net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket)2 LiteralText (net.minecraft.text.LiteralText)2 Text (net.minecraft.text.Text)2 GLFW (org.lwjgl.glfw.GLFW)2 Final (org.spongepowered.asm.mixin.Final)2