Search in sources :

Example 1 with NbtElement

use of net.minecraft.nbt.NbtElement in project Polymorph by TheIllusiveC4.

the class AbstractStackRecipeData method readNbt.

@Override
public void readNbt(NbtCompound pCompound) {
    if (pCompound.contains("SelectedRecipe")) {
        this.loadedRecipe = new Identifier(pCompound.getString("SelectedRecipe"));
    }
    if (pCompound.contains("RecipeDataSet")) {
        Set<RecipePair> dataset = this.getRecipesList();
        dataset.clear();
        NbtList list = pCompound.getList("RecipeDataSet", NbtType.COMPOUND);
        for (NbtElement inbt : list) {
            NbtCompound tag = (NbtCompound) inbt;
            Identifier id = Identifier.tryParse(tag.getString("Id"));
            ItemStack stack = ItemStack.fromNbt(tag.getCompound("ItemStack"));
            dataset.add(new RecipePairImpl(id, stack));
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair) NbtCompound(net.minecraft.nbt.NbtCompound) RecipePairImpl(top.theillusivec4.polymorph.common.impl.RecipePairImpl) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement) ItemStack(net.minecraft.item.ItemStack)

Example 2 with NbtElement

use of net.minecraft.nbt.NbtElement 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 3 with NbtElement

use of net.minecraft.nbt.NbtElement in project bewitchment by MoriyaShiine.

the class DemonEntity method readCustomDataFromNbt.

@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
    super.readCustomDataFromNbt(nbt);
    dataTracker.set(MALE, nbt.getBoolean("Male"));
    if (nbt.contains("Offers")) {
        offers.clear();
        NbtList offersList = nbt.getList("Offers", NbtType.COMPOUND);
        for (NbtElement offerTag : offersList) {
            offers.add(new DemonTradeOffer((NbtCompound) offerTag));
        }
    }
    tradeResetTimer = nbt.getInt("TradeResetTimer");
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Example 4 with NbtElement

use of net.minecraft.nbt.NbtElement in project EdenClient by HahaOO7.

the class ChestShopLoader method load.

public ChestShopMap load(NbtList tag) {
    ChestShopMap map = new ChestShopMap();
    for (NbtElement element : tag) {
        ChestShopEntry entry = new ChestShopEntry((NbtCompound) element);
        ChestShopSet set = map.computeIfAbsent(entry.getChunkPos(), k -> new ChestShopSet());
        set.add(entry);
    }
    return map;
}
Also used : NbtElement(net.minecraft.nbt.NbtElement)

Example 5 with NbtElement

use of net.minecraft.nbt.NbtElement in project EdenClient by HahaOO7.

the class PerWorldConfig method load.

private void load(NbtCompound tag, Object obj) {
    for (Field field : obj.getClass().getDeclaredFields()) {
        var annotation = field.getDeclaredAnnotation(ConfigSubscriber.class);
        if (annotation == null)
            continue;
        Class<?> c = getClass(field);
        ConfigLoader<NbtElement, ?> loader = getLoader(c);
        if (loader == null) {
            System.err.println("Error loading config: No loader found for class: " + c.getCanonicalName());
            continue;
        }
        try {
            field.setAccessible(true);
            String fieldName = field.getName();
            NbtElement nbt = tag.contains(fieldName) ? tag.get(fieldName) : loader.parse(annotation.value());
            Object value;
            try {
                value = loader.load(nbt);
            } catch (ClassCastException e) {
                System.err.println("Error while loading " + field.getName() + " in class " + obj.getClass().getSimpleName());
                value = loader.load(loader.parse(annotation.value()));
            }
            field.set(obj, value);
        } catch (IllegalAccessException e) {
            System.err.println("Error loading config: Can't access field: " + c.getCanonicalName() + "." + field.getName());
        }
    }
}
Also used : Field(java.lang.reflect.Field) NbtElement(net.minecraft.nbt.NbtElement)

Aggregations

NbtElement (net.minecraft.nbt.NbtElement)51 NbtList (net.minecraft.nbt.NbtList)44 NbtCompound (net.minecraft.nbt.NbtCompound)22 Identifier (net.minecraft.util.Identifier)20 ItemStack (net.minecraft.item.ItemStack)6 Field (java.lang.reflect.Field)2 Block (net.minecraft.block.Block)2 Enchantment (net.minecraft.enchantment.Enchantment)2 StatusEffect (net.minecraft.entity.effect.StatusEffect)2 Item (net.minecraft.item.Item)2 SoundEvent (net.minecraft.sound.SoundEvent)2 DyeColor (net.minecraft.util.DyeColor)2 RecipePair (top.theillusivec4.polymorph.api.common.base.RecipePair)2 RecipePairImpl (top.theillusivec4.polymorph.common.impl.RecipePairImpl)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Module (mathax.client.systems.modules.Module)1 Module (meteordevelopment.meteorclient.systems.modules.Module)1