Search in sources :

Example 1 with HashCache

use of net.minecraft.data.HashCache in project MinecraftForge by MinecraftForge.

the class GlobalLootModifierProvider method run.

@Override
public void run(HashCache cache) throws IOException {
    start();
    Path forgePath = gen.getOutputFolder().resolve("data/forge/loot_modifiers/global_loot_modifiers.json");
    String modPath = "data/" + modid + "/loot_modifiers/";
    List<ResourceLocation> entries = new ArrayList<>();
    toSerialize.forEach(LamdbaExceptionUtils.rethrowBiConsumer((name, pair) -> {
        entries.add(new ResourceLocation(modid, name));
        Path modifierPath = gen.getOutputFolder().resolve(modPath + name + ".json");
        JsonObject json = pair.getB();
        json.addProperty("type", pair.getA().getRegistryName().toString());
        DataProvider.save(GSON, cache, json, modifierPath);
    }));
    JsonObject forgeJson = new JsonObject();
    forgeJson.addProperty("replace", this.replace);
    forgeJson.add("entries", GSON.toJsonTree(entries.stream().map(ResourceLocation::toString).collect(Collectors.toList())));
    DataProvider.save(GSON, cache, forgeJson, forgePath);
}
Also used : Path(java.nio.file.Path) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) IGlobalLootModifier(net.minecraftforge.common.loot.IGlobalLootModifier) HashCache(net.minecraft.data.HashCache) LamdbaExceptionUtils(cpw.mods.modlauncher.api.LamdbaExceptionUtils) Tuple(net.minecraft.util.Tuple) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) GlobalLootModifierSerializer(net.minecraftforge.common.loot.GlobalLootModifierSerializer) ArrayList(java.util.ArrayList) List(java.util.List) Gson(com.google.gson.Gson) Map(java.util.Map) DataGenerator(net.minecraft.data.DataGenerator) DataProvider(net.minecraft.data.DataProvider) Path(java.nio.file.Path) LootModifier(net.minecraftforge.common.loot.LootModifier) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonObject (com.google.gson.JsonObject)1 LamdbaExceptionUtils (cpw.mods.modlauncher.api.LamdbaExceptionUtils)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 DataGenerator (net.minecraft.data.DataGenerator)1 DataProvider (net.minecraft.data.DataProvider)1 HashCache (net.minecraft.data.HashCache)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Tuple (net.minecraft.util.Tuple)1 GlobalLootModifierSerializer (net.minecraftforge.common.loot.GlobalLootModifierSerializer)1 IGlobalLootModifier (net.minecraftforge.common.loot.IGlobalLootModifier)1 LootModifier (net.minecraftforge.common.loot.LootModifier)1