REI fix
This commit is contained in:
parent
ec61972724
commit
f2fd7ab55b
3 changed files with 13 additions and 31 deletions
|
@ -60,9 +60,7 @@ public class MinecraftServerMixin {
|
||||||
|
|
||||||
private void bclib_injectRecipes() {
|
private void bclib_injectRecipes() {
|
||||||
RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager();
|
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()));
|
accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,20 +17,13 @@ public class BCLRecipeManager {
|
||||||
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
|
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||||
|
|
||||||
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
||||||
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
|
Map<ResourceLocation, Recipe<?>> list = RECIPES.computeIfAbsent(type, i -> Maps.newHashMap());
|
||||||
if (list == null) {
|
|
||||||
list = Maps.newHashMap();
|
|
||||||
RECIPES.put(type, list);
|
|
||||||
}
|
|
||||||
list.put(recipe.getId(), recipe);
|
list.put(recipe.getId(), recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T extends Recipe<?>> T getRecipe(RecipeType<T> type, ResourceLocation id) {
|
public static <T extends Recipe<?>> T getRecipe(RecipeType<T> type, ResourceLocation id) {
|
||||||
if (RECIPES.containsKey(type)) {
|
Map<ResourceLocation, Recipe<?>> map = RECIPES.get(type);
|
||||||
return (T) RECIPES.get(type).get(id);
|
return map != null ? (T) map.get(id) : null;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> getMap(Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes) {
|
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);
|
result.put(type, typeList);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RecipeType<?> type : RECIPES.keySet()) {
|
RECIPES.forEach((type, list) -> {
|
||||||
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
Map<ResourceLocation, Recipe<?>> typeList = result.get(type);
|
Map<ResourceLocation, Recipe<?>> typeList = result.computeIfAbsent(type, i -> Maps.newHashMap());
|
||||||
if (typeList == null) {
|
|
||||||
typeList = Maps.newHashMap();
|
|
||||||
result.put(type, typeList);
|
|
||||||
}
|
|
||||||
for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) {
|
for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) {
|
||||||
ResourceLocation id = entry.getKey();
|
ResourceLocation id = entry.getKey();
|
||||||
if (!typeList.containsKey(id)) typeList.put(id, entry.getValue());
|
typeList.computeIfAbsent(id, i -> entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<ResourceLocation, Recipe<?>> getMapByName(Map<ResourceLocation, Recipe<?>> recipes) {
|
public static Map<ResourceLocation, Recipe<?>> getMapByName(Map<ResourceLocation, Recipe<?>> recipes) {
|
||||||
Map<ResourceLocation, Recipe<?>> result = CollectionsUtil.getMutable(recipes);
|
Map<ResourceLocation, Recipe<?>> result = CollectionsUtil.getMutable(recipes);
|
||||||
RECIPES.values().forEach(map -> map.forEach((location, recipe) -> {
|
RECIPES.values().forEach(map -> map.forEach((location, recipe) -> result.computeIfAbsent(location, i -> recipe)));
|
||||||
if (!result.containsKey(location)) {
|
|
||||||
result.put(location, recipe);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class FurnaceRecipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
SmeltingRecipe recipe = new SmeltingRecipe(
|
SmeltingRecipe recipe = new SmeltingRecipe(
|
||||||
id,
|
new ResourceLocation(id + "_smelting"),
|
||||||
group,
|
group,
|
||||||
Ingredient.of(input),
|
Ingredient.of(input),
|
||||||
new ItemStack(output, count),
|
new ItemStack(output, count),
|
||||||
|
@ -91,7 +91,7 @@ public class FurnaceRecipe {
|
||||||
|
|
||||||
if (blasting) {
|
if (blasting) {
|
||||||
BlastingRecipe recipe2 = new BlastingRecipe(
|
BlastingRecipe recipe2 = new BlastingRecipe(
|
||||||
id,
|
new ResourceLocation(id + "_blasting"),
|
||||||
group,
|
group,
|
||||||
Ingredient.of(input),
|
Ingredient.of(input),
|
||||||
new ItemStack(output, count),
|
new ItemStack(output, count),
|
||||||
|
@ -103,7 +103,7 @@ public class FurnaceRecipe {
|
||||||
|
|
||||||
if (campfire) {
|
if (campfire) {
|
||||||
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
|
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
|
||||||
id,
|
new ResourceLocation(id + "_campfire"),
|
||||||
group,
|
group,
|
||||||
Ingredient.of(input),
|
Ingredient.of(input),
|
||||||
new ItemStack(output, count),
|
new ItemStack(output, count),
|
||||||
|
@ -115,7 +115,7 @@ public class FurnaceRecipe {
|
||||||
|
|
||||||
if (smoker) {
|
if (smoker) {
|
||||||
SmokingRecipe recipe2 = new SmokingRecipe(
|
SmokingRecipe recipe2 = new SmokingRecipe(
|
||||||
id,
|
new ResourceLocation(id + "_smoker"),
|
||||||
group,
|
group,
|
||||||
Ingredient.of(input),
|
Ingredient.of(input),
|
||||||
new ItemStack(output, count),
|
new ItemStack(output, count),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue