Search in sources :

Example 1 with DirectoryCache

use of net.minecraft.data.DirectoryCache in project iChunUtil by iChun.

the class LootTableGen method act.

@Override
public void act(DirectoryCache cache) {
    Map<ResourceLocation, LootTable> map = Maps.newHashMap();
    TriConsumer<LootParameterSet, ResourceLocation, LootTable.Builder> consumer = (set, key, builder) -> {
        if (map.put(key, builder.setParameterSet(set).build()) != null)
            throw new IllegalStateException("Duplicate loot table " + key);
    };
    for (Data data : sets) {
        data.accept((key, builder) -> consumer.accept(data.lootSet(), key, builder));
    }
    map.forEach((key, table) -> {
        Path target = this.gen.getOutputFolder().resolve("data/" + key.getNamespace() + "/loot_tables/" + key.getPath() + ".json");
        try {
            IDataProvider.save(GSON, cache, LootTableManager.toJson(table), target);
            iChunUtil.LOGGER.info("Saved loot table {}", target);
        } catch (IOException ioexception) {
            iChunUtil.LOGGER.error("Couldn't save loot table {}", target, ioexception);
        }
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) IDataProvider(net.minecraft.data.IDataProvider) java.util(java.util) TriConsumer(org.apache.logging.log4j.util.TriConsumer) EntityLootTables(net.minecraft.data.loot.EntityLootTables) DirectoryCache(net.minecraft.data.DirectoryCache) net.minecraft.loot(net.minecraft.loot) IOException(java.io.IOException) me.ichun.mods.ichunutil.common.iChunUtil(me.ichun.mods.ichunutil.common.iChunUtil) EntityClassification(net.minecraft.entity.EntityClassification) Maps(com.google.common.collect.Maps) BlockLootTables(net.minecraft.data.loot.BlockLootTables) Sets(com.google.common.collect.Sets) GsonBuilder(com.google.gson.GsonBuilder) Consumer(java.util.function.Consumer) Block(net.minecraft.block.Block) Gson(com.google.gson.Gson) ResourceLocation(net.minecraft.util.ResourceLocation) BiConsumer(java.util.function.BiConsumer) DataGenerator(net.minecraft.data.DataGenerator) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) Path(java.nio.file.Path) ResourceLocation(net.minecraft.util.ResourceLocation) GsonBuilder(com.google.gson.GsonBuilder) IOException(java.io.IOException)

Example 2 with DirectoryCache

use of net.minecraft.data.DirectoryCache in project some-assembly-required by ochotonida.

the class Advancements method act.

@Override
public void act(DirectoryCache cache) {
    Set<ResourceLocation> set = Sets.newHashSet();
    Consumer<Advancement> consumer = (advancement) -> {
        if (!set.add(advancement.getId())) {
            throw new IllegalStateException("Duplicate advancement " + advancement.getId());
        } else {
            Path path1 = getPath(PATH, advancement);
            try {
                IDataProvider.save((new GsonBuilder()).setPrettyPrinting().create(), cache, advancement.copy().serialize(), path1);
            } catch (IOException ioexception) {
                SomeAssemblyRequired.LOGGER.error("Couldn't save advancement {}", path1, ioexception);
            }
        }
    };
    new SomeAssemblyRequiredAdvancements().accept(consumer);
}
Also used : IDataProvider(net.minecraft.data.IDataProvider) HusbandryAdvancements(net.minecraft.data.advancements.HusbandryAdvancements) GsonBuilder(com.google.gson.GsonBuilder) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FrameType(net.minecraft.advancements.FrameType) ItemStack(net.minecraft.item.ItemStack) CriterionInstance(net.minecraft.advancements.criterion.CriterionInstance) DataGenerator(net.minecraft.data.DataGenerator) ModTags(someassemblyrequired.common.init.ModTags) Path(java.nio.file.Path) InventoryChangeTrigger(net.minecraft.advancements.criterion.InventoryChangeTrigger) Advancement(net.minecraft.advancements.Advancement) DirectoryCache(net.minecraft.data.DirectoryCache) Set(java.util.Set) IOException(java.io.IOException) ModAdvancementTriggers(someassemblyrequired.common.init.ModAdvancementTriggers) SomeAssemblyRequired(someassemblyrequired.SomeAssemblyRequired) Sets(com.google.common.collect.Sets) ItemPredicate(net.minecraft.advancements.criterion.ItemPredicate) Consumer(java.util.function.Consumer) AdvancementProvider(net.minecraft.data.AdvancementProvider) Util(someassemblyrequired.common.util.Util) ResourceLocation(net.minecraft.util.ResourceLocation) SandwichBuilder(someassemblyrequired.common.util.SandwichBuilder) ModItems(someassemblyrequired.common.init.ModItems) ModBlocks(someassemblyrequired.common.init.ModBlocks) Path(java.nio.file.Path) GsonBuilder(com.google.gson.GsonBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Advancement(net.minecraft.advancements.Advancement)

Example 3 with DirectoryCache

use of net.minecraft.data.DirectoryCache in project bioplethora by AquexTheSeal.

the class BioAdvancementProvider method run.

@Override
public void run(DirectoryCache cache) {
    Path path = this.datagen.getOutputFolder();
    Set<ResourceLocation> set = Sets.newHashSet();
    Consumer<Advancement> consumer = (advancement) -> {
        if (!set.add(advancement.getId())) {
            throw new IllegalStateException("Duplicate advancement " + advancement.getId());
        } else {
            Path path1 = getPath(path, advancement);
            try {
                IDataProvider.save(GSON, cache, advancement.deconstruct().serializeToJson(), path1);
            } catch (IOException e) {
                Bioplethora.LOGGER.error("Couldn't save advancement {}", path1, e);
            }
        }
    };
    this.register(consumer);
}
Also used : Path(java.nio.file.Path) IDataProvider(net.minecraft.data.IDataProvider) Bioplethora(io.github.bioplethora.Bioplethora) BioplethoraItems(io.github.bioplethora.registry.BioplethoraItems) Advancement(net.minecraft.advancements.Advancement) DirectoryCache(net.minecraft.data.DirectoryCache) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) GsonBuilder(com.google.gson.GsonBuilder) Registry(net.minecraft.util.registry.Registry) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FrameType(net.minecraft.advancements.FrameType) Consumer(java.util.function.Consumer) BioplethoraEntities(io.github.bioplethora.registry.BioplethoraEntities) IItemProvider(net.minecraft.util.IItemProvider) RegistryKey(net.minecraft.util.RegistryKey) Validate(org.apache.commons.lang3.Validate) Gson(com.google.gson.Gson) AdvancementProvider(net.minecraft.data.AdvancementProvider) net.minecraft.advancements.criterion(net.minecraft.advancements.criterion) ResourceLocation(net.minecraft.util.ResourceLocation) DataGenerator(net.minecraft.data.DataGenerator) Path(java.nio.file.Path) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Advancement(net.minecraft.advancements.Advancement)

Example 4 with DirectoryCache

use of net.minecraft.data.DirectoryCache in project ChaosAwakens by ChaosAwakens.

the class CAAdvancementProvider method run.

@Override
public void run(DirectoryCache cache) {
    Path path = this.generator.getOutputFolder();
    Set<ResourceLocation> set = Sets.newHashSet();
    Consumer<Advancement> consumer = (advancement) -> {
        if (!set.add(advancement.getId())) {
            throw new IllegalStateException("Duplicate advancement " + advancement.getId());
        } else {
            Path path1 = getPath(path, advancement);
            try {
                IDataProvider.save(GSON, cache, advancement.deconstruct().serializeToJson(), path1);
            } catch (IOException e) {
                ChaosAwakens.LOGGER.error("Couldn't save advancement {}", path1, e);
            }
        }
    };
    this.register(consumer);
}
Also used : Path(java.nio.file.Path) IDataProvider(net.minecraft.data.IDataProvider) CAEntityTypes(io.github.chaosawakens.common.registry.CAEntityTypes) CABlocks(io.github.chaosawakens.common.registry.CABlocks) GsonBuilder(com.google.gson.GsonBuilder) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FrameType(net.minecraft.advancements.FrameType) RegistryKey(net.minecraft.util.RegistryKey) Gson(com.google.gson.Gson) net.minecraft.advancements.criterion(net.minecraft.advancements.criterion) DataGenerator(net.minecraft.data.DataGenerator) Path(java.nio.file.Path) CADimensions(io.github.chaosawakens.common.registry.CADimensions) Advancement(net.minecraft.advancements.Advancement) DirectoryCache(net.minecraft.data.DirectoryCache) Set(java.util.Set) CAItems(io.github.chaosawakens.common.registry.CAItems) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) IRequirementsStrategy(net.minecraft.advancements.IRequirementsStrategy) Blocks(net.minecraft.block.Blocks) Registry(net.minecraft.util.registry.Registry) ChaosAwakens(io.github.chaosawakens.ChaosAwakens) Consumer(java.util.function.Consumer) IItemProvider(net.minecraft.util.IItemProvider) Validate(org.apache.commons.lang3.Validate) AdvancementProvider(net.minecraft.data.AdvancementProvider) ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Advancement(net.minecraft.advancements.Advancement)

Example 5 with DirectoryCache

use of net.minecraft.data.DirectoryCache in project AntimatterAPI by GregTech-Intergalactical.

the class AntimatterAdvancementProvider method act.

@Override
public void act(@Nonnull DirectoryCache cache) {
    Path folder = this.gen.getOutputFolder();
    Set<ResourceLocation> locs = new ObjectOpenHashSet<>();
    Consumer<Advancement> consumer = a -> {
        if (!locs.add(a.getId()))
            throw new IllegalStateException("Duplicate advancement " + a.getId());
        else {
            Path path = getPath(folder, a);
            try {
                IDataProvider.save(Ref.GSON, cache, a.copy().serialize(), path);
            } catch (IOException e) {
                LOGGER.error("Couldn't save advancement {}", path, e);
            }
        }
    };
    advancements.forEach(a -> a.accept(consumer));
}
Also used : Path(java.nio.file.Path) IDataProvider(net.minecraft.data.IDataProvider) DynamicResourcePack(muramasa.antimatter.datagen.resources.DynamicResourcePack) java.util(java.util) Advancement(net.minecraft.advancements.Advancement) DirectoryCache(net.minecraft.data.DirectoryCache) IOException(java.io.IOException) IAntimatterProvider(muramasa.antimatter.datagen.IAntimatterProvider) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) FrameType(net.minecraft.advancements.FrameType) Consumer(java.util.function.Consumer) IItemProvider(net.minecraft.util.IItemProvider) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) Logger(org.apache.logging.log4j.Logger) ResourceLocation(net.minecraft.util.ResourceLocation) Ref(muramasa.antimatter.Ref) DataGenerator(net.minecraft.data.DataGenerator) LogManager(org.apache.logging.log4j.LogManager) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) Advancement(net.minecraft.advancements.Advancement)

Aggregations

IOException (java.io.IOException)5 Path (java.nio.file.Path)5 Consumer (java.util.function.Consumer)5 DataGenerator (net.minecraft.data.DataGenerator)5 DirectoryCache (net.minecraft.data.DirectoryCache)5 IDataProvider (net.minecraft.data.IDataProvider)5 ResourceLocation (net.minecraft.util.ResourceLocation)5 Sets (com.google.common.collect.Sets)4 GsonBuilder (com.google.gson.GsonBuilder)4 Advancement (net.minecraft.advancements.Advancement)4 FrameType (net.minecraft.advancements.FrameType)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 Gson (com.google.gson.Gson)3 Set (java.util.Set)3 AdvancementProvider (net.minecraft.data.AdvancementProvider)3 IItemProvider (net.minecraft.util.IItemProvider)3 java.util (java.util)2 Nonnull (javax.annotation.Nonnull)2 net.minecraft.advancements.criterion (net.minecraft.advancements.criterion)2 RegistryKey (net.minecraft.util.RegistryKey)2