This commit is contained in:
paulevsGitch 2022-01-13 19:16:49 +03:00
parent ec61972724
commit f2fd7ab55b
3 changed files with 13 additions and 31 deletions

View file

@ -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()));
}
}

View file

@ -17,20 +17,13 @@ public class BCLRecipeManager {
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
if (list == null) {
list = Maps.newHashMap();
RECIPES.put(type, list);
}
Map<ResourceLocation, Recipe<?>> list = RECIPES.computeIfAbsent(type, i -> Maps.newHashMap());
list.put(recipe.getId(), recipe);
}
@SuppressWarnings("unchecked")
public static <T extends Recipe<?>> T getRecipe(RecipeType<T> type, ResourceLocation id) {
if (RECIPES.containsKey(type)) {
return (T) RECIPES.get(type).get(id);
}
return null;
Map<ResourceLocation, Recipe<?>> map = RECIPES.get(type);
return map != null ? (T) map.get(id) : null;
}
public static Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> getMap(Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes) {
@ -42,31 +35,22 @@ public class BCLRecipeManager {
result.put(type, typeList);
}
for (RecipeType<?> type : RECIPES.keySet()) {
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
RECIPES.forEach((type, list) -> {
if (list != null) {
Map<ResourceLocation, Recipe<?>> typeList = result.get(type);
if (typeList == null) {
typeList = Maps.newHashMap();
result.put(type, typeList);
}
Map<ResourceLocation, Recipe<?>> typeList = result.computeIfAbsent(type, i -> Maps.newHashMap());
for (Entry<ResourceLocation, Recipe<?>> 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<ResourceLocation, Recipe<?>> getMapByName(Map<ResourceLocation, Recipe<?>> recipes) {
Map<ResourceLocation, Recipe<?>> 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;
}

View file

@ -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),