Search in sources :

Example 91 with NbtList

use of net.minecraft.nbt.NbtList 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 92 with NbtList

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

the class LocateCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("buried_treasure").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.FILLED_MAP) {
            error("You need to hold a treasure map first");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        NbtList nbt1 = (NbtList) tag.get("Decorations");
        if (nbt1 == null) {
            error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?");
            return SINGLE_SUCCESS;
        }
        NbtCompound iconNBT = nbt1.getCompound(0);
        if (iconNBT == null) {
            error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
        BaseText text = new LiteralText("Buried Treasure located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("lodestone").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.COMPASS) {
            error("You need to hold a lodestone compass");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        if (tag == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        NbtCompound nbt1 = tag.getCompound("LodestonePos");
        if (nbt1 == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(nbt1.getDouble("X"), nbt1.getDouble("Y"), nbt1.getDouble("Z"));
        BaseText text = new LiteralText("Lodestone located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("mansion").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.FILLED_MAP) {
            error("You need to hold a woodland explorer map first");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        NbtList nbt1 = (NbtList) tag.get("Decorations");
        if (nbt1 == null) {
            error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?");
            return SINGLE_SUCCESS;
        }
        NbtCompound iconNBT = nbt1.getCompound(0);
        if (iconNBT == null) {
            error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
        BaseText text = new LiteralText("Mansion located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("stronghold").executes(s -> {
        FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
        if (eye.found()) {
            BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
            firstStart = null;
            firstEnd = null;
            secondStart = null;
            secondEnd = null;
            MeteorClient.EVENT_BUS.subscribe(this);
            info("Please throw the first Eye of Ender");
        } else {
            Vec3d coords = findByBlockList(strongholdBlocks);
            if (coords == null) {
                error("No stronghold found nearby. You can use (highlight)Ender Eyes(default) for more success.");
                return SINGLE_SUCCESS;
            }
            BaseText text = new LiteralText("Stronghold located at ");
            text.append(ChatUtils.formatCoords(coords));
            text.append(".");
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("nether_fortress").executes(s -> {
        Vec3d coords = findByBlockList(netherFortressBlocks);
        if (coords == null) {
            error("No nether fortress found.");
            return SINGLE_SUCCESS;
        }
        BaseText text = new LiteralText("Fortress located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("monument").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() == Items.FILLED_MAP) {
            NbtCompound tag = stack.getNbt();
            if (tag != null) {
                NbtList nbt1 = (NbtList) tag.get("Decorations");
                if (nbt1 != null) {
                    NbtCompound iconNBT = nbt1.getCompound(0);
                    if (iconNBT != null) {
                        Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z"));
                        BaseText text = new LiteralText("Monument located at ");
                        text.append(ChatUtils.formatCoords(coords));
                        text.append(".");
                        info(text);
                        return SINGLE_SUCCESS;
                    }
                }
            }
        }
        Vec3d coords = findByBlockList(monumentBlocks);
        if (coords == null) {
            error("No monument found. You can try using a (highlight)Ocean explorer map(default) for more success.");
            return SINGLE_SUCCESS;
        }
        BaseText text = new LiteralText("Monument located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("cancel").executes(s -> {
        cancel();
        return SINGLE_SUCCESS;
    }));
}
Also used : EntityType(net.minecraft.entity.EntityType) LiteralText(net.minecraft.text.LiteralText) Arrays(java.util.Arrays) NbtList(net.minecraft.nbt.NbtList) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) ItemStack(net.minecraft.item.ItemStack) PlaySoundS2CPacket(net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket) BaseText(net.minecraft.text.BaseText) Command(meteordevelopment.meteorclient.systems.commands.Command) Block(net.minecraft.block.Block) SoundEvents(net.minecraft.sound.SoundEvents) Vec3d(net.minecraft.util.math.Vec3d) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) InvUtils(meteordevelopment.meteorclient.utils.player.InvUtils) ChatUtils(meteordevelopment.meteorclient.utils.player.ChatUtils) EntitySpawnS2CPacket(net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket) BaritoneAPI(baritone.api.BaritoneAPI) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) PacketEvent(meteordevelopment.meteorclient.events.packets.PacketEvent) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Blocks(net.minecraft.block.Blocks) CommandSource(net.minecraft.command.CommandSource) NbtCompound(net.minecraft.nbt.NbtCompound) List(java.util.List) MeteorClient(meteordevelopment.meteorclient.MeteorClient) EventHandler(meteordevelopment.orbit.EventHandler) BaseText(net.minecraft.text.BaseText) NbtCompound(net.minecraft.nbt.NbtCompound) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) LiteralText(net.minecraft.text.LiteralText)

Example 93 with NbtList

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

the class Modules method toTag.

@Override
public NbtCompound toTag() {
    NbtCompound tag = new NbtCompound();
    NbtList modulesTag = new NbtList();
    for (Module module : getAll()) {
        NbtCompound moduleTag = module.toTag();
        if (moduleTag != null)
            modulesTag.add(moduleTag);
    }
    tag.put("modules", modulesTag);
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 94 with NbtList

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

the class Modules method fromTag.

@Override
public Modules fromTag(NbtCompound tag) {
    disableAll();
    NbtList modulesTag = tag.getList("modules", 10);
    for (NbtElement moduleTagI : modulesTag) {
        NbtCompound moduleTag = (NbtCompound) moduleTagI;
        Module module = get(moduleTag.getString("name"));
        if (module != null)
            module.fromTag(moduleTag);
    }
    return this;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Example 95 with NbtList

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

the class Friends method toTag.

@Override
public NbtCompound toTag() {
    NbtCompound tag = new NbtCompound();
    NbtList friendsTag = new NbtList();
    for (Friend friend : friends) friendsTag.add(friend.toTag());
    tag.put("friends", friendsTag);
    tag.put("color", color.toTag());
    tag.putBoolean("attack", attack);
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Aggregations

NbtList (net.minecraft.nbt.NbtList)161 NbtCompound (net.minecraft.nbt.NbtCompound)92 NbtElement (net.minecraft.nbt.NbtElement)46 Identifier (net.minecraft.util.Identifier)38 ItemStack (net.minecraft.item.ItemStack)28 NbtString (net.minecraft.nbt.NbtString)17 LiteralText (net.minecraft.text.LiteralText)12 BlockPos (net.minecraft.util.math.BlockPos)11 Block (net.minecraft.block.Block)9 IOException (java.io.IOException)8 List (java.util.List)8 Item (net.minecraft.item.Item)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Items (net.minecraft.item.Items)6 NbtIo (net.minecraft.nbt.NbtIo)6 StatusEffect (net.minecraft.entity.effect.StatusEffect)5 Text (net.minecraft.text.Text)5 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 Blocks (net.minecraft.block.Blocks)4