diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index d025e53f..059131af 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -60,9 +60,7 @@ public class MinecraftServerMixin { private void bclib_injectRecipes() { RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager(); - if (!BCLib.isClient()) { - accessor.bclib_setRecipesByName(BCLRecipeManager.getMapByName(accessor.bclib_getRecipesByName())); - } + accessor.bclib_setRecipesByName(BCLRecipeManager.getMapByName(accessor.bclib_getRecipesByName())); accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes())); } } diff --git a/src/main/java/ru/bclib/recipes/BCLRecipeManager.java b/src/main/java/ru/bclib/recipes/BCLRecipeManager.java index f1577458..07c6f95c 100644 --- a/src/main/java/ru/bclib/recipes/BCLRecipeManager.java +++ b/src/main/java/ru/bclib/recipes/BCLRecipeManager.java @@ -17,20 +17,13 @@ public class BCLRecipeManager { private static final Map, Map>> RECIPES = Maps.newHashMap(); public static void addRecipe(RecipeType type, Recipe recipe) { - Map> list = RECIPES.get(type); - if (list == null) { - list = Maps.newHashMap(); - RECIPES.put(type, list); - } + Map> list = RECIPES.computeIfAbsent(type, i -> Maps.newHashMap()); list.put(recipe.getId(), recipe); } - @SuppressWarnings("unchecked") public static > T getRecipe(RecipeType type, ResourceLocation id) { - if (RECIPES.containsKey(type)) { - return (T) RECIPES.get(type).get(id); - } - return null; + Map> map = RECIPES.get(type); + return map != null ? (T) map.get(id) : null; } public static Map, Map>> getMap(Map, Map>> recipes) { @@ -42,31 +35,22 @@ public class BCLRecipeManager { result.put(type, typeList); } - for (RecipeType type : RECIPES.keySet()) { - Map> list = RECIPES.get(type); + RECIPES.forEach((type, list) -> { if (list != null) { - Map> typeList = result.get(type); - if (typeList == null) { - typeList = Maps.newHashMap(); - result.put(type, typeList); - } + Map> typeList = result.computeIfAbsent(type, i -> Maps.newHashMap()); for (Entry> entry : list.entrySet()) { ResourceLocation id = entry.getKey(); - if (!typeList.containsKey(id)) typeList.put(id, entry.getValue()); + typeList.computeIfAbsent(id, i -> entry.getValue()); } } - } + }); return result; } public static Map> getMapByName(Map> recipes) { Map> result = CollectionsUtil.getMutable(recipes); - RECIPES.values().forEach(map -> map.forEach((location, recipe) -> { - if (!result.containsKey(location)) { - result.put(location, recipe); - } - })); + RECIPES.values().forEach(map -> map.forEach((location, recipe) -> result.computeIfAbsent(location, i -> recipe))); return result; } diff --git a/src/main/java/ru/bclib/recipes/FurnaceRecipe.java b/src/main/java/ru/bclib/recipes/FurnaceRecipe.java index c3e3c1be..8fd556e1 100644 --- a/src/main/java/ru/bclib/recipes/FurnaceRecipe.java +++ b/src/main/java/ru/bclib/recipes/FurnaceRecipe.java @@ -80,7 +80,7 @@ public class FurnaceRecipe { } SmeltingRecipe recipe = new SmeltingRecipe( - id, + new ResourceLocation(id + "_smelting"), group, Ingredient.of(input), new ItemStack(output, count), @@ -91,7 +91,7 @@ public class FurnaceRecipe { if (blasting) { BlastingRecipe recipe2 = new BlastingRecipe( - id, + new ResourceLocation(id + "_blasting"), group, Ingredient.of(input), new ItemStack(output, count), @@ -103,7 +103,7 @@ public class FurnaceRecipe { if (campfire) { CampfireCookingRecipe recipe2 = new CampfireCookingRecipe( - id, + new ResourceLocation(id + "_campfire"), group, Ingredient.of(input), new ItemStack(output, count), @@ -115,7 +115,7 @@ public class FurnaceRecipe { if (smoker) { SmokingRecipe recipe2 = new SmokingRecipe( - id, + new ResourceLocation(id + "_smoker"), group, Ingredient.of(input), new ItemStack(output, count),