Search in sources :

Example 46 with NbtList

use of net.minecraft.nbt.NbtList in project FZMM-Mod by Zailer43.

the class DisplayUtils method addLore.

public DisplayUtils addLore(Text lore) {
    NbtList oldLore = this.getLore();
    oldLore.add(FzmmUtils.textToNbtString(lore, true));
    this.setLore(oldLore);
    return this;
}
Also used : NbtList(net.minecraft.nbt.NbtList)

Example 47 with NbtList

use of net.minecraft.nbt.NbtList in project KiwiClient by TangyKiwi.

the class Tooltips method appendTooltip.

@Subscribe
@AllowConcurrentEvents
public void appendTooltip(ItemStackTooltipEvent event) {
    // Stew
    if (getSetting(0).asToggle().state) {
        if (event.itemStack.getItem() == Items.SUSPICIOUS_STEW) {
            NbtCompound tag = event.itemStack.getNbt();
            if (tag != null) {
                NbtList effects = tag.getList("Effects", 10);
                if (effects != null) {
                    for (int i = 0; i < effects.size(); i++) {
                        NbtCompound effectTag = effects.getCompound(i);
                        byte effectId = effectTag.getByte("EffectId");
                        int effectDuration = effectTag.contains("EffectDuration") ? effectTag.getInt("EffectDuration") : 160;
                        StatusEffectInstance effect = new StatusEffectInstance(StatusEffect.byRawId(effectId), effectDuration, 0);
                        event.list.add(1, getStatusText(effect));
                    }
                }
            }
        } else if (event.itemStack.getItem().isFood()) {
            FoodComponent food = event.itemStack.getItem().getFoodComponent();
            if (food != null) {
                food.getStatusEffects().forEach((e) -> {
                    StatusEffectInstance effect = e.getFirst();
                    event.list.add(1, getStatusText(effect));
                });
            }
        }
    }
    // Bees
    if (getSetting(1).asToggle().state) {
        if (event.itemStack.getItem() == Items.BEEHIVE || event.itemStack.getItem() == Items.BEE_NEST) {
            NbtCompound tag = event.itemStack.getNbt();
            if (tag != null) {
                NbtCompound blockStateTag = tag.getCompound("BlockStateTag");
                if (blockStateTag != null) {
                    int level = blockStateTag.getInt("honey_level");
                    event.list.add(1, new LiteralText(String.format("%sHoney Level: %s%d%s", Formatting.GRAY, Formatting.YELLOW, level, Formatting.GRAY)));
                }
                NbtCompound blockEntityTag = tag.getCompound("BlockEntityTag");
                if (blockEntityTag != null) {
                    NbtList beesTag = blockEntityTag.getList("Bees", 10);
                    event.list.add(1, new LiteralText(String.format("%sBees: %s%d%s", Formatting.GRAY, Formatting.YELLOW, beesTag.size(), Formatting.GRAY)));
                }
            }
        }
    }
// Fish handled in EntityBucketItemMixin
}
Also used : LiteralText(net.minecraft.text.LiteralText) NbtList(net.minecraft.nbt.NbtList) EChestMemory(com.tangykiwi.kiwiclient.util.tooltip.EChestMemory) TranslatableText(net.minecraft.text.TranslatableText) Module(com.tangykiwi.kiwiclient.modules.Module) DefaultedList(net.minecraft.util.collection.DefaultedList) Block(net.minecraft.block.Block) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Inventories(net.minecraft.inventory.Inventories) MutableText(net.minecraft.text.MutableText) ToggleSetting(com.tangykiwi.kiwiclient.modules.settings.ToggleSetting) Subscribe(com.google.common.eventbus.Subscribe) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) ItemStackTooltipEvent(com.tangykiwi.kiwiclient.event.ItemStackTooltipEvent) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Category(com.tangykiwi.kiwiclient.modules.Category) ContainerTooltipComponent(com.tangykiwi.kiwiclient.util.tooltip.ContainerTooltipComponent) net.minecraft.item(net.minecraft.item) Blocks(net.minecraft.block.Blocks) java.awt(java.awt) TooltipDataEvent(com.tangykiwi.kiwiclient.event.TooltipDataEvent) NbtCompound(net.minecraft.nbt.NbtCompound) StatusEffect(net.minecraft.entity.effect.StatusEffect) Formatting(net.minecraft.util.Formatting) List(java.util.List) StatusEffectUtil(net.minecraft.entity.effect.StatusEffectUtil) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) DyeColor(net.minecraft.util.DyeColor) Text(net.minecraft.text.Text) Comparator(java.util.Comparator) NbtCompound(net.minecraft.nbt.NbtCompound) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) NbtList(net.minecraft.nbt.NbtList) LiteralText(net.minecraft.text.LiteralText) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 48 with NbtList

use of net.minecraft.nbt.NbtList in project KiwiClient by TangyKiwi.

the class Utils method addEnchantment.

public static void addEnchantment(ItemStack itemStack, Enchantment enchantment, int level) {
    NbtCompound tag = itemStack.getOrCreateNbt();
    NbtList listTag;
    if (!tag.contains("Enchantments", 9)) {
        listTag = new NbtList();
        tag.put("Enchantments", listTag);
    } else {
        listTag = tag.getList("Enchantments", 10);
    }
    String enchId = Registry.ENCHANTMENT.getId(enchantment).toString();
    for (NbtElement _t : listTag) {
        NbtCompound t = (NbtCompound) _t;
        if (t.getString("id").equals(enchId)) {
            t.putShort("lvl", (short) level);
            return;
        }
    }
    NbtCompound enchTag = new NbtCompound();
    enchTag.putString("id", enchId);
    enchTag.putShort("lvl", (short) level);
    listTag.add(enchTag);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Example 49 with NbtList

use of net.minecraft.nbt.NbtList in project Capybara-Fabricated by ZestyBlaze.

the class CapybaraEntity method writeCustomDataToNbt.

@Override
public void writeCustomDataToNbt(NbtCompound nbt) {
    super.writeCustomDataToNbt(nbt);
    if (inventory != null) {
        final NbtList inv = new NbtList();
        for (int i = 0; i < this.inventory.size(); i++) {
            inv.add(inventory.getStack(i).writeNbt(new NbtCompound()));
        }
        nbt.put("Inventory", inv);
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 50 with NbtList

use of net.minecraft.nbt.NbtList in project Capybara-Fabricated by ZestyBlaze.

the class CapybaraEntity method readCustomDataFromNbt.

@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
    super.readCustomDataFromNbt(nbt);
    if (nbt.contains("Inventory")) {
        final NbtList inv = nbt.getList("Inventory", 10);
        inventory = new SimpleInventory(inv.size());
        for (int i = 0; i < inv.size(); i++) {
            inventory.setStack(i, ItemStack.fromNbt(inv.getCompound(i)));
        }
        dataTracker.set(CHESTS, inv.size() > 27 ? 2 : 1);
    }
}
Also used : NbtList(net.minecraft.nbt.NbtList) SimpleInventory(net.minecraft.inventory.SimpleInventory)

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