Search in sources :

Example 6 with NbtList

use of net.minecraft.nbt.NbtList in project Primeval by devs-immortal.

the class VesselItem method getBundledStacks.

private static Stream<ItemStack> getBundledStacks(ItemStack stack) {
    NbtCompound nbtCompound = stack.getNbt();
    if (nbtCompound == null) {
        return Stream.empty();
    } else {
        NbtList nbtList = nbtCompound.getList("Items", 10);
        Stream<NbtElement> var10000 = nbtList.stream();
        Objects.requireNonNull(NbtCompound.class);
        return var10000.map(NbtCompound.class::cast).map(ItemStack::fromNbt);
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement) ItemStack(net.minecraft.item.ItemStack)

Example 7 with NbtList

use of net.minecraft.nbt.NbtList in project Primeval by devs-immortal.

the class VesselItem method addToBundle.

private static int addToBundle(ItemStack bundle, ItemStack stack) {
    if (!stack.isEmpty() && stack.getItem().canBeNested() && canAddItem(bundle)) {
        NbtCompound nbtCompound = bundle.getOrCreateNbt();
        if (!nbtCompound.contains("Items")) {
            nbtCompound.put("Items", new NbtList());
        }
        int i = getBundleOccupancy(bundle);
        int j = getItemOccupancy(stack);
        int k = Math.min(stack.getCount(), (64 - i) / j);
        if (k == 0) {
            return 0;
        } else {
            NbtList nbtList = nbtCompound.getList("Items", 10);
            Optional<NbtCompound> optional = canMergeStack(stack, nbtList);
            if (optional.isPresent()) {
                NbtCompound nbtCompound2 = optional.get();
                ItemStack itemStack = ItemStack.fromNbt(nbtCompound2);
                itemStack.increment(k);
                itemStack.writeNbt(nbtCompound2);
                nbtList.remove(nbtCompound2);
                nbtList.add(0, nbtCompound2);
            } else {
                ItemStack nbtCompound2 = stack.copy();
                nbtCompound2.setCount(k);
                NbtCompound itemStack = new NbtCompound();
                nbtCompound2.writeNbt(itemStack);
                nbtList.add(0, itemStack);
            }
            return k;
        }
    } else {
        return 0;
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 8 with NbtList

use of net.minecraft.nbt.NbtList in project meteor-rejects by AntiCope.

the class HeadScreen method createHeadStack.

private ItemStack createHeadStack(String uuid, String value, String name) {
    ItemStack head = Items.PLAYER_HEAD.getDefaultStack();
    NbtCompound tag = new NbtCompound();
    NbtCompound skullOwner = new NbtCompound();
    skullOwner.putUuid("Id", UUID.fromString(uuid));
    NbtCompound properties = new NbtCompound();
    NbtList textures = new NbtList();
    NbtCompound Value = new NbtCompound();
    Value.putString("Value", value);
    textures.add(Value);
    properties.put("textures", textures);
    skullOwner.put("Properties", properties);
    tag.put("SkullOwner", skullOwner);
    head.setNbt(tag);
    head.setCustomName(new LiteralText(name));
    return head;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 9 with NbtList

use of net.minecraft.nbt.NbtList in project FabricWaystones by LordDeatHunter.

the class WaystoneStorage method toTag.

public NbtCompound toTag(NbtCompound tag) {
    if (tag == null) {
        tag = new NbtCompound();
    }
    NbtList waystones = new NbtList();
    for (Map.Entry<String, WaystoneValue> waystone : WAYSTONES.entrySet()) {
        String hash = waystone.getKey();
        WaystoneValue entity = waystone.getValue();
        NbtCompound waystoneTag = new NbtCompound();
        waystoneTag.putString("hash", hash);
        waystoneTag.putString("name", entity.getWaystoneName());
        BlockPos pos = entity.way_getPos();
        waystoneTag.putIntArray("position", Arrays.asList(pos.getX(), pos.getY(), pos.getZ()));
        waystoneTag.putString("dimension", entity.getWorldName());
        waystones.add(waystoneTag);
    }
    tag.put("waystones", waystones);
    NbtList globals = new NbtList();
    var globalWaystones = getGlobals();
    for (String globalWaystone : globalWaystones) {
        globals.add(NbtString.of(globalWaystone));
    }
    tag.put("global_waystones", globals);
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) WaystoneValue(wraith.waystones.access.WaystoneValue) BlockPos(net.minecraft.util.math.BlockPos) NbtString(net.minecraft.nbt.NbtString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 10 with NbtList

use of net.minecraft.nbt.NbtList in project FabricWaystones by LordDeatHunter.

the class CompatibilityLayer method writeNbt.

public NbtCompound writeNbt(NbtCompound tag) {
    if (COMPATABILITY_ENABLED)
        return tag;
    if (tag == null)
        tag = new NbtCompound();
    NbtList compatWaystones = new NbtList();
    for (Map.Entry<String, HashSet<String>> player : COMPATABILITY_MAP.entrySet()) {
        NbtCompound playerTag = new NbtCompound();
        playerTag.putString("username", player.getKey());
        NbtList knownWaystones = new NbtList();
        for (String hash : player.getValue()) {
            NbtCompound waystone = new NbtCompound();
            waystone.putString("hash", hash);
            knownWaystones.add(waystone);
        }
        playerTag.put("waystones", knownWaystones);
        compatWaystones.add(playerTag);
    }
    tag.put("waystones_compat", compatWaystones);
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

NbtList (net.minecraft.nbt.NbtList)146 NbtCompound (net.minecraft.nbt.NbtCompound)79 NbtElement (net.minecraft.nbt.NbtElement)45 Identifier (net.minecraft.util.Identifier)37 ItemStack (net.minecraft.item.ItemStack)25 NbtString (net.minecraft.nbt.NbtString)16 LiteralText (net.minecraft.text.LiteralText)12 BlockPos (net.minecraft.util.math.BlockPos)11 Block (net.minecraft.block.Block)9 List (java.util.List)8 Item (net.minecraft.item.Item)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 IOException (java.io.IOException)6 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 Comparator (java.util.Comparator)4 Blocks (net.minecraft.block.Blocks)4 EntityType (net.minecraft.entity.EntityType)4