Search in sources :

Example 86 with NbtList

use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.

the class LoomScreenMixin method saveFrameBannerPatterns.

@Inject(method = "onInventoryChanged", at = @At("RETURN"))
private void saveFrameBannerPatterns(CallbackInfo ci) {
    if (this.bannerPatterns != null) {
        ItemStack banner = (this.handler).getOutputSlot().getStack();
        NbtList ls = FrameBannerPatternConversions.getNbt(banner);
        frame_bannerPatterns = FrameBannerPatternConversions.makeData(ls);
    } else
        frame_bannerPatterns = Collections.emptyList();
}
Also used : NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 87 with NbtList

use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.

the class LoomScreenMixin method proxyPutPatterns.

/**
 * If the pattern index indicates a Frame pattern, put the Frame
 * pattern in the item NBT instead of a vanilla pattern.
 */
@Redirect(method = "drawBanner", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;put(Ljava/lang/String;Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;", ordinal = 0))
private NbtElement proxyPutPatterns(NbtCompound nbt, String key, NbtElement patterns) {
    frame_singlePattern.clear();
    if (frame_bannerPatternIndex < 0) {
        int frameBannerPatternIdx = -frame_bannerPatternIndex - (1 + BannerPattern.LOOM_APPLICABLE_COUNT);
        FrameBannerPattern pattern = FrameBannerPatternsInternal.get(frameBannerPatternIdx);
        NbtList framePatterns = new NbtList();
        NbtCompound patternNbtElement = new NbtCompound();
        patternNbtElement.putString("Pattern", pattern.getId().toString());
        patternNbtElement.putInt("Color", 0);
        patternNbtElement.putInt("Index", 1);
        framePatterns.add(patternNbtElement);
        // pop dummy vanilla banner pattern
        NbtList vanillaPatterns = (NbtList) patterns;
        assert vanillaPatterns.size() == 2 : vanillaPatterns.size();
        vanillaPatterns.remove(1);
        nbt.put(FrameBannerPatternAccess.NBT_KEY, framePatterns);
        frame_singlePattern.add(new FrameBannerPatternData(pattern, DyeColor.WHITE, 1));
    }
    FrameBannerPatternRenderContext.setFrameBannerPatterns(frame_singlePattern);
    return nbt.put(key, patterns);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) FrameBannerPatternData(net.moddingplayground.frame.impl.bannerpatterns.FrameBannerPatternData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 88 with NbtList

use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.

the class ClientBannerBlockEntityMixin method frame_getBannerPatterns.

@Override
public List<FrameBannerPatternData> frame_getBannerPatterns() {
    if (this.patterns == null) {
        NbtList nbt = ((FrameBannerPatternAccess.Internal) this).frame_getBannerPatternNbt();
        frame_bannerPatterns = FrameBannerPatternConversions.makeData(nbt);
    }
    return Collections.unmodifiableList(frame_bannerPatterns);
}
Also used : NbtList(net.minecraft.nbt.NbtList)

Example 89 with NbtList

use of net.minecraft.nbt.NbtList in project KahzerxMod by otakucraft.

the class SolExtension method createFirework.

private static ItemStack createFirework(FireworkHelper... fireworksConfigs) {
    ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET, 1);
    ItemStack star = new ItemStack(Items.FIREWORK_STAR);
    NbtList explosions = new NbtList();
    for (FireworkHelper config : fireworksConfigs) {
        NbtCompound explosion = star.getOrCreateSubNbt(FireworkRocketItem.EXPLOSION_KEY).copy();
        explosion.putIntArray(FireworkRocketItem.COLORS_KEY, config.getColors());
        explosion.putByte(FireworkRocketItem.TYPE_KEY, (byte) config.getType());
        explosion.putByte(FireworkRocketItem.FLICKER_KEY, (byte) config.getFlicker());
        explosion.putByte(FireworkRocketItem.TRAIL_KEY, (byte) config.getTrail());
        if (config.getFadeColors().length != 0) {
            explosion.putIntArray(FireworkRocketItem.FADE_COLORS_KEY, config.getFadeColors());
        }
        explosions.add(explosion);
    }
    NbtCompound fireworks = firework.getOrCreateSubNbt(FireworkRocketItem.FIREWORKS_KEY);
    fireworks.putByte(FireworkRocketItem.FLIGHT_KEY, (byte) 1);
    fireworks.put(FireworkRocketItem.EXPLOSIONS_KEY, explosions);
    firework.getOrCreateNbt().putBoolean("Sol", true);
    return firework;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 90 with NbtList

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

the class Utils method removeEnchantment.

public static void removeEnchantment(ItemStack itemStack, Enchantment enchantment) {
    NbtCompound nbt = itemStack.getNbt();
    if (nbt == null)
        return;
    if (!nbt.contains("Enchantments", 9))
        return;
    NbtList list = nbt.getList("Enchantments", 10);
    String enchId = Registry.ENCHANTMENT.getId(enchantment).toString();
    for (Iterator<NbtElement> it = list.iterator(); it.hasNext(); ) {
        NbtCompound ench = (NbtCompound) it.next();
        if (ench.getString("id").equals(enchId)) {
            it.remove();
            break;
        }
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Aggregations

NbtList (net.minecraft.nbt.NbtList)174 NbtCompound (net.minecraft.nbt.NbtCompound)102 NbtElement (net.minecraft.nbt.NbtElement)49 Identifier (net.minecraft.util.Identifier)39 ItemStack (net.minecraft.item.ItemStack)30 NbtString (net.minecraft.nbt.NbtString)18 LiteralText (net.minecraft.text.LiteralText)13 BlockPos (net.minecraft.util.math.BlockPos)11 Block (net.minecraft.block.Block)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Item (net.minecraft.item.Item)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 BlockState (net.minecraft.block.BlockState)6 Items (net.minecraft.item.Items)6 NbtIo (net.minecraft.nbt.NbtIo)6 Text (net.minecraft.text.Text)5 Comparator (java.util.Comparator)4 Blocks (net.minecraft.block.Blocks)4