Search in sources :

Example 56 with NbtList

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

the class FlareGunItem method clearProjectiles.

private static void clearProjectiles(ItemStack crossbow) {
    NbtCompound NbtCompound = crossbow.getNbt();
    if (NbtCompound != null) {
        NbtList NbtList = NbtCompound.getList("ChargedProjectiles", 9);
        NbtList.clear();
        NbtCompound.put("ChargedProjectiles", NbtList);
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 57 with NbtList

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

the class FlareGunItem 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)

Example 58 with NbtList

use of net.minecraft.nbt.NbtList in project alaskanativecraft by Platymemo.

the class AkutaqRecipe method addEffectToAkutaq.

// Can't use SuspiciousStewItem.addEffectToStew because it overwrites the list tag each time
public static void addEffectToAkutaq(@NotNull ItemStack stew, StatusEffect effect, int duration) {
    NbtCompound compoundTag = stew.getOrCreateNbt();
    NbtList listTag = compoundTag.getList("Effects", 10);
    boolean effectExists = false;
    byte effectId = (byte) StatusEffect.getRawId(effect);
    int actualDuration = duration;
    for (int i = 0; i < listTag.size(); ++i) {
        NbtCompound previousEffect = listTag.getCompound(i);
        if (previousEffect.contains("EffectDuration", 3) && effectId == previousEffect.getByte("EffectId")) {
            actualDuration += previousEffect.getInt("EffectDuration");
            previousEffect.putInt("EffectDuration", actualDuration);
            effectExists = true;
        }
    }
    if (!effectExists) {
        NbtCompound newEffect = new NbtCompound();
        newEffect.putByte("EffectId", effectId);
        newEffect.putInt("EffectDuration", actualDuration);
        listTag.add(newEffect);
    }
    compoundTag.put("Effects", listTag);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 59 with NbtList

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

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

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) 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) GuiThemes(mathax.client.gui.GuiThemes) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) IOException(java.io.IOException) Items(net.minecraft.item.Items) GLFW(org.lwjgl.glfw.GLFW) MatHax.mc(mathax.client.MatHax.mc) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) Base64(java.util.Base64) Screen(net.minecraft.client.gui.screen.Screen) EditBookTitleAndAuthorScreen(mathax.client.gui.screens.EditBookTitleAndAuthorScreen) 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(mathax.client.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

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