Search in sources :

Example 1 with CustomRecipeManager

use of com.minecolonies.coremod.colony.crafting.CustomRecipeManager in project minecolonies by ldtteam.

the class CrafterRecipeListener method apply.

@Override
protected void apply(@NotNull final Map<ResourceLocation, JsonElement> object, @NotNull final IResourceManager resourceManagerIn, @NotNull final IProfiler profilerIn) {
    Log.getLogger().info("Beginning load of custom recipes for colony workers");
    final CustomRecipeManager recipeManager = CustomRecipeManager.getInstance();
    recipeManager.reset();
    for (final Map.Entry<ResourceLocation, JsonElement> entry : object.entrySet()) {
        final ResourceLocation key = entry.getKey();
        try {
            final JsonObject recipeJson = entry.getValue().getAsJsonObject();
            switch(JSONUtils.getAsString(recipeJson, RECIPE_TYPE_PROP, "")) {
                case RECIPE_TYPE_RECIPE:
                case RECIPE_TYPE_RECIPE_MULT_OUT:
                    recipeManager.addRecipe(CustomRecipe.parse(key, recipeJson));
                    break;
                case RECIPE_TYPE_REMOVE:
                    final ResourceLocation toRemove = new ResourceLocation(JSONUtils.getAsString(recipeJson, RECIPE_ID_TO_REMOVE_PROP, ""));
                    recipeManager.removeRecipe(toRemove);
                    break;
            }
        } catch (final JsonParseException e) {
            Log.getLogger().error("Error parsing crafterrecipe " + key.toString(), e);
        }
    }
    final int totalRecipes = recipeManager.getAllRecipes().values().stream().mapToInt(Map::size).sum();
    Log.getLogger().info("Loaded " + totalRecipes + " recipes for " + recipeManager.getAllRecipes().size() + " crafters");
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) Map(java.util.Map)

Example 2 with CustomRecipeManager

use of com.minecolonies.coremod.colony.crafting.CustomRecipeManager in project minecolonies by Minecolonies.

the class CrafterRecipeListener method apply.

@Override
protected void apply(@NotNull final Map<ResourceLocation, JsonElement> object, @NotNull final IResourceManager resourceManagerIn, @NotNull final IProfiler profilerIn) {
    Log.getLogger().info("Beginning load of custom recipes for colony workers");
    final CustomRecipeManager recipeManager = CustomRecipeManager.getInstance();
    recipeManager.reset();
    for (final Map.Entry<ResourceLocation, JsonElement> entry : object.entrySet()) {
        final ResourceLocation key = entry.getKey();
        try {
            final JsonObject recipeJson = entry.getValue().getAsJsonObject();
            switch(JSONUtils.getAsString(recipeJson, RECIPE_TYPE_PROP, "")) {
                case RECIPE_TYPE_RECIPE:
                case RECIPE_TYPE_RECIPE_MULT_OUT:
                    recipeManager.addRecipe(CustomRecipe.parse(key, recipeJson));
                    break;
                case RECIPE_TYPE_REMOVE:
                    final ResourceLocation toRemove = new ResourceLocation(JSONUtils.getAsString(recipeJson, RECIPE_ID_TO_REMOVE_PROP, ""));
                    recipeManager.removeRecipe(toRemove);
                    break;
            }
        } catch (final JsonParseException e) {
            Log.getLogger().error("Error parsing crafterrecipe " + key.toString(), e);
        }
    }
    final int totalRecipes = recipeManager.getAllRecipes().values().stream().mapToInt(Map::size).sum();
    Log.getLogger().info("Loaded " + totalRecipes + " recipes for " + recipeManager.getAllRecipes().size() + " crafters");
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) Map(java.util.Map)

Aggregations

CustomRecipeManager (com.minecolonies.coremod.colony.crafting.CustomRecipeManager)2 Map (java.util.Map)2 ResourceLocation (net.minecraft.util.ResourceLocation)2