Search in sources :

Example 71 with Identifier

use of net.minecraft.util.Identifier in project frame-fabric by moddingplayground.

the class AbstractLootTableGenerator method accept.

@SuppressWarnings("ConstantConditions")
@Override
public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {
    this.generate();
    Set<Identifier> set = Sets.newHashSet();
    Registry<T> registry = this.getRegistry();
    Iterable<T> objects = registry.stream().filter(obj -> registry.getId(obj).getNamespace().equals(this.modId))::iterator;
    for (T obj : objects) {
        Identifier id = ((ObjectLootTableAccess) obj).access_getLootTableId();
        this.testObject(id, obj);
        if (id != LootTables.EMPTY && set.add(id)) {
            LootTable.Builder builder = this.map.remove(id);
            if (builder == null) {
                throw new IllegalStateException(String.format("Missing loottable '%s' for '%s'", id, registry.getId(obj)));
            }
            biConsumer.accept(id, builder);
        }
    }
    this.map.forEach(biConsumer);
}
Also used : LootTable(net.minecraft.loot.LootTable) LootPoolEntry(net.minecraft.loot.entry.LootPoolEntry) UniformLootNumberProvider(net.minecraft.loot.provider.number.UniformLootNumberProvider) Function(java.util.function.Function) BoundedIntUnaryOperator(net.minecraft.loot.operator.BoundedIntUnaryOperator) Block(net.minecraft.block.Block) BinomialLootNumberProvider(net.minecraft.loot.provider.number.BinomialLootNumberProvider) BiConsumer(java.util.function.BiConsumer) ObjectLootTableAccess(net.moddingplayground.frame.impl.toymaker.ObjectLootTableAccess) StatePredicate(net.minecraft.predicate.StatePredicate) BlockStatePropertyLootCondition(net.minecraft.loot.condition.BlockStatePropertyLootCondition) LootCondition(net.minecraft.loot.condition.LootCondition) LootTables(net.minecraft.loot.LootTables) Property(net.minecraft.state.property.Property) AbstractGenerator(net.moddingplayground.frame.api.toymaker.v0.generator.AbstractGenerator) Set(java.util.Set) ConstantLootNumberProvider(net.minecraft.loot.provider.number.ConstantLootNumberProvider) ItemEntry(net.minecraft.loot.entry.ItemEntry) Sets(com.google.common.collect.Sets) Registry(net.minecraft.util.registry.Registry) RandomChanceLootCondition(net.minecraft.loot.condition.RandomChanceLootCondition) LootPool(net.minecraft.loot.LootPool) SetCountLootFunction(net.minecraft.loot.function.SetCountLootFunction) ItemConvertible(net.minecraft.item.ItemConvertible) Identifier(net.minecraft.util.Identifier) ConditionalLootFunction(net.minecraft.loot.function.ConditionalLootFunction) LootNumberProvider(net.minecraft.loot.provider.number.LootNumberProvider) LootTable(net.minecraft.loot.LootTable) ObjectLootTableAccess(net.moddingplayground.frame.impl.toymaker.ObjectLootTableAccess) Identifier(net.minecraft.util.Identifier)

Example 72 with Identifier

use of net.minecraft.util.Identifier 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 73 with Identifier

use of net.minecraft.util.Identifier 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 74 with Identifier

use of net.minecraft.util.Identifier in project frame-fabric by moddingplayground.

the class FrameBlocksTest method register.

private static Block register(String id, Block block) {
    Identifier identifier = new Identifier("frame-blocks-test", id);
    Registry.register(Registry.ITEM, identifier, new BlockItem(block, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS)));
    return Registry.register(Registry.BLOCK, identifier, block);
}
Also used : Identifier(net.minecraft.util.Identifier) FabricItemSettings(net.fabricmc.fabric.api.item.v1.FabricItemSettings) BlockItem(net.minecraft.item.BlockItem)

Example 75 with Identifier

use of net.minecraft.util.Identifier in project frame-fabric by moddingplayground.

the class BannerItemMixin method frame_addBannerPatternLine.

@Unique
private static void frame_addBannerPatternLine(NbtCompound nbt, List<Text> lines) {
    Identifier id = Identifier.tryParse(nbt.getString("Pattern"));
    DyeColor color = DyeColor.byId(nbt.getInt("Color"));
    if (id != null) {
        FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(id);
        if (pattern != null)
            pattern.addPatternLine(lines, color);
    }
}
Also used : Identifier(net.minecraft.util.Identifier) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor) Unique(org.spongepowered.asm.mixin.Unique)

Aggregations

Identifier (net.minecraft.util.Identifier)343 NbtList (net.minecraft.nbt.NbtList)36 ItemStack (net.minecraft.item.ItemStack)31 Item (net.minecraft.item.Item)28 NbtCompound (net.minecraft.nbt.NbtCompound)22 NbtElement (net.minecraft.nbt.NbtElement)22 Inject (org.spongepowered.asm.mixin.injection.Inject)22 IOException (java.io.IOException)18 Block (net.minecraft.block.Block)18 MinecraftClient (net.minecraft.client.MinecraftClient)15 BlockItem (net.minecraft.item.BlockItem)15 BlockPos (net.minecraft.util.math.BlockPos)15 Map (java.util.Map)12 BlockState (net.minecraft.block.BlockState)12 ArrayList (java.util.ArrayList)11 VertexConsumer (net.minecraft.client.render.VertexConsumer)11 ResourceManager (net.minecraft.resource.ResourceManager)11 SoundEvent (net.minecraft.sound.SoundEvent)11 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 LiteralText (net.minecraft.text.LiteralText)10