Search in sources :

Example 6 with NbtElement

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

the class PerWorldConfig method save.

private void save(NbtCompound tag, Object obj) {
    for (Field field : obj.getClass().getDeclaredFields()) {
        if (!field.isAnnotationPresent(ConfigSubscriber.class))
            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);
            tag.put(field.getName(), loader.save(field.get(obj)));
        } 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)

Example 7 with NbtElement

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

the class FrameBannerPatternConversions method makeData.

/**
 * Parses the given NBT data into a list of {@link FrameBannerPatternData} objects.
 *
 * @param nbt a nullable {@link NbtList} with Frame banner pattern data
 */
public static List<FrameBannerPatternData> makeData(NbtList nbt) {
    List<FrameBannerPatternData> res = new ArrayList<>();
    if (nbt != null) {
        for (NbtElement t : nbt) {
            NbtCompound patternNbt = (NbtCompound) t;
            FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(new Identifier(patternNbt.getString("Pattern")));
            if (pattern != null) {
                DyeColor color = DyeColor.byId(patternNbt.getInt("Color"));
                int index = patternNbt.getInt("Index");
                res.add(new FrameBannerPatternData(pattern, color, index));
            }
        }
    }
    return res;
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) ArrayList(java.util.ArrayList) NbtElement(net.minecraft.nbt.NbtElement) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor)

Example 8 with NbtElement

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

the class BannerBlockEntityMixin method frame_setBannerPatternNbt.

@Override
public void frame_setBannerPatternNbt(NbtList nbt) {
    frame_bannerPatternsTag = nbt;
    if (frame_bannerPatternsTag != null) {
        // validate NBT data, removing and/or resetting invalid data
        for (Iterator<NbtElement> itr = frame_bannerPatternsTag.iterator(); itr.hasNext(); ) {
            NbtCompound element = (NbtCompound) itr.next();
            Identifier id = Identifier.tryParse(element.getString("Pattern"));
            int colorId = element.getInt("Color");
            int index = element.getInt("Index");
            if (id == null || !FrameBannerPatterns.REGISTRY.getIds().contains(id)) {
                itr.remove();
            } else {
                int rtColorId = DyeColor.byId(colorId).getId();
                if (rtColorId != colorId) {
                    element.putInt("Color", rtColorId);
                }
                if (index < 0) {
                    element.putInt("Index", 0);
                }
            }
        }
        // the Java API requires that this sort be stable
        frame_bannerPatternsTag.sort(comparingInt(t -> ((NbtCompound) t).getInt("Index")));
    }
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) NbtElement(net.minecraft.nbt.NbtElement) Iterator(java.util.Iterator) FrameBannerPatternAccess(net.moddingplayground.frame.impl.bannerpatterns.FrameBannerPatternAccess) Unique(org.spongepowered.asm.mixin.Unique) Inject(org.spongepowered.asm.mixin.injection.Inject) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) BlockEntityType(net.minecraft.block.entity.BlockEntityType) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) ItemStack(net.minecraft.item.ItemStack) NbtCompound(net.minecraft.nbt.NbtCompound) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) FrameBannerPatterns(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPatterns) Mixin(org.spongepowered.asm.mixin.Mixin) DyeColor(net.minecraft.util.DyeColor) Identifier(net.minecraft.util.Identifier) BlockState(net.minecraft.block.BlockState) Comparator(java.util.Comparator) BannerBlockEntity(net.minecraft.block.entity.BannerBlockEntity) At(org.spongepowered.asm.mixin.injection.At) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtElement(net.minecraft.nbt.NbtElement)

Example 9 with NbtElement

use of net.minecraft.nbt.NbtElement in project meteor-client by MeteorDevelopment.

the class Marker method fromTag.

@Override
public Module fromTag(NbtCompound tag) {
    super.fromTag(tag);
    markers.clear();
    NbtList list = tag.getList("markers", 10);
    for (NbtElement tagII : list) {
        NbtCompound tagI = (NbtCompound) tagII;
        String type = tagI.getString("type");
        BaseMarker marker = factory.createMarker(type);
        if (marker != null) {
            NbtCompound markerTag = (NbtCompound) tagI.get("marker");
            if (markerTag != null)
                marker.fromTag(markerTag);
            markers.add(marker);
        }
    }
    return this;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Example 10 with NbtElement

use of net.minecraft.nbt.NbtElement in project meteor-client by MeteorDevelopment.

the class BlockListSetting method load.

@Override
protected List<Block> load(NbtCompound tag) {
    get().clear();
    NbtList valueTag = tag.getList("value", 8);
    for (NbtElement tagI : valueTag) {
        Block block = Registry.BLOCK.get(new Identifier(tagI.asString()));
        if (filter == null || filter.test(block))
            get().add(block);
    }
    return get();
}
Also used : Identifier(net.minecraft.util.Identifier) NbtList(net.minecraft.nbt.NbtList) Block(net.minecraft.block.Block) 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