Search in sources :

Example 51 with NbtList

use of net.minecraft.nbt.NbtList in project Interdimensional by QuiltServerTools.

the class PortalLinkingStorage method writeNbt.

public NbtCompound writeNbt(NbtCompound tag) {
    NbtList links = new NbtList();
    portalLinks.keys().asIterator().forEachRemaining(dimKey -> {
        portalLinks.get(dimKey).forEach((blockPos, dimensionalBlockPos) -> {
            NbtCompound link = new NbtCompound();
            link.putString("fromDimID", dimKey.toString());
            link.putLong("fromPos", blockPos.asLong());
            link.put("to", dimensionalBlockPos.toTag(new NbtCompound()));
            links.add(link);
        });
    });
    tag.put("portalLinks", links);
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 52 with NbtList

use of net.minecraft.nbt.NbtList in project Interdimensional by QuiltServerTools.

the class PortalLinkingStorage method fromNbt.

public static PersistentState fromNbt(NbtCompound tag) {
    PortalLinkingStorage cman = new PortalLinkingStorage();
    NbtList links = (NbtList) tag.get("portalLinks");
    for (int i = 0; i < links.size(); i++) {
        NbtCompound link = links.getCompound(i);
        DimensionalBlockPos toTag = DimensionalBlockPos.fromTag(link.getCompound("to"));
        cman.addLink(BlockPos.fromLong(link.getLong("fromPos")), new Identifier(link.getString("fromDimID")), toTag.pos, toTag.dimensionType);
    }
    return cman;
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 53 with NbtList

use of net.minecraft.nbt.NbtList in project meteor-utils by kkllffaa.

the class BetterBookBot method writeBook.

private void writeBook(char[] chars) {
    if (mc.player == null)
        return;
    ArrayList<String> pages = new ArrayList<>();
    int booklenght = 0;
    if (check(chars)) {
        toggle();
        info("complete");
        return;
    }
    for (int pageI = 0; pageI < 100; pageI++) {
        if (check(chars))
            break;
        if (!filltomax.get() && booklenght >= numberofcharacters.get())
            break;
        StringBuilder page = new StringBuilder();
        for (int lineI = 0; lineI < 13; lineI++) {
            if (check(chars))
                break;
            if (!filltomax.get() && booklenght >= numberofcharacters.get())
                break;
            double lineWidth = 0;
            StringBuilder line = new StringBuilder();
            while (true) {
                if (check(chars))
                    break;
                if (!filltomax.get() && booklenght >= numberofcharacters.get())
                    break;
                char next = chars[iterator];
                iterator++;
                booklenght++;
                if (next == '\r') {
                    if (chars.length > iterator && chars[iterator] == '\n')
                        continue;
                    break;
                }
                if (next == '\n')
                    break;
                double charWidth = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever().getWidth(next, Style.EMPTY);
                if (lineWidth + charWidth > 114)
                    break;
                line.appendCodePoint(next);
                lineWidth += charWidth;
            }
            page.append(line).append('\n');
        }
        pages.add(page.toString());
    }
    if (check(chars)) {
        toggle();
        info("complete");
    }
    // Write pages NBT
    NbtList pageNbt = new NbtList();
    pages.stream().map(NbtString::of).forEach(pageNbt::add);
    if (!pages.isEmpty())
        mc.player.getMainHandStack().setSubNbt("pages", pageNbt);
    mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, sign.get() ? Optional.of(name.get() + (count.get() ? " #" + bookCount : "")) : Optional.empty()));
    bookCount++;
    if (showiterator.get()) {
        MutableText message = new LiteralText("");
        message.append(new LiteralText("iterator: ")).append(new LiteralText(String.valueOf(iterator)).setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(iterator))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("COPY")))));
        message.append(new LiteralText("     "));
        message.append(new LiteralText("bookcount: ")).append(new LiteralText(String.valueOf(bookCount)).setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(bookCount))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("COPY")))));
        info(message);
    }
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) ArrayList(java.util.ArrayList) NbtString(net.minecraft.nbt.NbtString) NbtList(net.minecraft.nbt.NbtList)

Example 54 with NbtList

use of net.minecraft.nbt.NbtList in project meteor-utils by kkllffaa.

the class EchestMemoryMixin method save.

@EventHandler
private static void save(GameLeftEvent event) {
    if (mc.player == null)
        return;
    if (getSaveFile() == null)
        return;
    if (ITEMS.stream().allMatch(ItemStack::isEmpty)) {
        getSaveFile().delete();
        return;
    }
    NbtCompound tag = new NbtCompound();
    NbtList list = new NbtList();
    for (ItemStack stack : ITEMS) {
        NbtCompound item = new NbtCompound();
        list.add(stack.writeNbt(item));
    }
    tag.put("items", list);
    try {
        loc.mkdir();
        getSaveFile().getParentFile().mkdir();
        getSaveFile().createNewFile();
        NbtIo.write(tag, getSaveFile());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) EventHandler(meteordevelopment.orbit.EventHandler)

Example 55 with NbtList

use of net.minecraft.nbt.NbtList in project HWG by cybercat-mods.

the class GrenadeLauncherItem method getProjectiles.

private static List<ItemStack> getProjectiles(ItemStack crossbow) {
    List<ItemStack> list = Lists.newArrayList();
    NbtCompound NbtCompound = crossbow.getNbt();
    if (NbtCompound != null && NbtCompound.contains("ChargedProjectiles", 9)) {
        NbtList NbtList = NbtCompound.getList("ChargedProjectiles", 10);
        if (NbtList != null) {
            for (int i = 0; i < NbtList.size(); ++i) {
                NbtCompound NbtCompound2 = NbtList.getCompound(i);
                list.add(ItemStack.fromNbt(NbtCompound2));
            }
        }
    }
    return list;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

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