Search in sources :

Example 96 with NbtCompound

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

the class DisplayUtils method setName.

public DisplayUtils setName(NbtString name) {
    NbtCompound display = this.getDisplay();
    display.put(ItemStack.NAME_KEY, name);
    this.nbt.put(ItemStack.DISPLAY_KEY, display);
    return this;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Example 97 with NbtCompound

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

the class EntityMixin method giveDyedArmor.

private void giveDyedArmor(Item item, EquipmentSlot slot, byte slotId) {
    MinecraftClient mc = MinecraftClient.getInstance();
    assert mc.player != null;
    ItemStack stack = item.getDefaultStack();
    NbtCompound display = new NbtCompound();
    int averageColor = getAverageColor(skinPartBuffered);
    if (mc.interactionManager == null) {
        return;
    }
    display.putInt(DyeableItem.COLOR_KEY, averageColor);
    stack.setSubNbt(DyeableItem.DISPLAY_KEY, display);
    skinPartBuffered = new BufferedImage(40, 48, BufferedImage.TYPE_INT_ARGB);
    g = skinPartBuffered.createGraphics();
    mc.player.equipStack(slot, stack);
    mc.interactionManager.clickCreativeStack(stack, slotId);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) MinecraftClient(net.minecraft.client.MinecraftClient) BufferedImage(java.awt.image.BufferedImage)

Example 98 with NbtCompound

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

the class ItemFrameEntityMixin method getPickBlockStack.

@Inject(method = "getPickBlockStack", at = @At(value = "HEAD"), cancellable = true)
public void getPickBlockStack(CallbackInfoReturnable<ItemStack> cir) {
    if (Screen.hasControlDown()) {
        ItemStack stack = this.getAsItemStack();
        NbtCompound entityTag = new NbtCompound();
        this.writeCustomDataToNbt(entityTag);
        entityTag.remove("TileX");
        entityTag.remove("TileY");
        entityTag.remove("TileZ");
        entityTag.remove("Facing");
        stack.setSubNbt(EntityType.ENTITY_TAG_KEY, entityTag);
        stack = new DisplayUtils(stack).addLore("(" + EntityType.ENTITY_TAG_KEY + ")", Configs.Colors.LORE_PICK_BLOCK.getColor()).get();
        cir.setReturnValue(stack);
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) DisplayUtils(fzmm.zailer.me.utils.DisplayUtils) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 99 with NbtCompound

use of net.minecraft.nbt.NbtCompound 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 100 with NbtCompound

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

the class Tooltips method getTooltipData.

@Subscribe
@AllowConcurrentEvents
public void getTooltipData(TooltipDataEvent event) {
    // Shulker Box
    if (hasItems(event.itemStack) && getSetting(3).asToggle().state) {
        NbtCompound compoundTag = event.itemStack.getSubNbt("BlockEntityTag");
        DefaultedList<ItemStack> itemStacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
        Inventories.readNbt(compoundTag, itemStacks);
        event.tooltipData = new ContainerTooltipComponent(itemStacks, getShulkerColor(event.itemStack));
    } else // EChest
    if (event.itemStack.getItem() == Items.ENDER_CHEST && getSetting(4).asToggle().state) {
        event.tooltipData = new ContainerTooltipComponent(EChestMemory.ITEMS, new Color(0, 50, 50));
    }
}
Also used : ContainerTooltipComponent(com.tangykiwi.kiwiclient.util.tooltip.ContainerTooltipComponent) NbtCompound(net.minecraft.nbt.NbtCompound) DyeColor(net.minecraft.util.DyeColor) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

NbtCompound (net.minecraft.nbt.NbtCompound)282 NbtList (net.minecraft.nbt.NbtList)79 ItemStack (net.minecraft.item.ItemStack)58 LiteralText (net.minecraft.text.LiteralText)24 NbtElement (net.minecraft.nbt.NbtElement)23 Identifier (net.minecraft.util.Identifier)23 IOException (java.io.IOException)21 BlockPos (net.minecraft.util.math.BlockPos)19 Inject (org.spongepowered.asm.mixin.injection.Inject)18 NbtString (net.minecraft.nbt.NbtString)16 File (java.io.File)13 List (java.util.List)9 Text (net.minecraft.text.Text)9 Items (net.minecraft.item.Items)8 TranslatableText (net.minecraft.text.TranslatableText)8 BlockState (net.minecraft.block.BlockState)6 Item (net.minecraft.item.Item)6 NbtIo (net.minecraft.nbt.NbtIo)6 PacketByteBuf (net.minecraft.network.PacketByteBuf)6 Vec3d (net.minecraft.util.math.Vec3d)6