fix: recipes

This commit is contained in:
Reider745
2026-01-26 19:19:56 +03:00
parent e2b95d3467
commit d91fc9fd6b
2 changed files with 23 additions and 6 deletions
@@ -71,6 +71,7 @@ public class NativeWorkbench {
return this; return this;
} }
} }
private static long RECIPE_ID = Long.MIN_VALUE;
private static class RecipeRegistryEntry implements IApply { private static class RecipeRegistryEntry implements IApply {
public int resultId; public int resultId;
@@ -139,7 +140,7 @@ public class NativeWorkbench {
} }
if (accepted) { if (accepted) {
RecipeRegistry.registerShapedRecipe(new ShapedRecipe(result, this.pattern, ingredients, new ArrayList<>())); RecipeRegistry.registerShapedRecipe(new ShapedRecipe(String.valueOf(RECIPE_ID++), 1, result, this.pattern, ingredients, new ArrayList<>()));
} }
} else { } else {
final Collection<ItemDescriptor> ingredients = new ArrayList<>(); final Collection<ItemDescriptor> ingredients = new ArrayList<>();
@@ -158,7 +159,7 @@ public class NativeWorkbench {
ingredients.add(new DefaultDescriptor(item)); ingredients.add(new DefaultDescriptor(item));
} }
if (accepted) { if (accepted) {
RecipeRegistry.registerShapelessRecipe(new ShapelessRecipe(result, ingredients)); RecipeRegistry.registerShapelessRecipe(new ShapelessRecipe(String.valueOf(RECIPE_ID++), 10, result, ingredients));
} }
} }
@@ -171,14 +172,28 @@ public class NativeWorkbench {
private static void addShapedRecipe(int resultId, int resultCount, int resultData, NativeItemInstanceExtra resultExtra, private static void addShapedRecipe(int resultId, int resultCount, int resultData, NativeItemInstanceExtra resultExtra,
String[] pattern, int[] ingredients) { String[] pattern, int[] ingredients) {
if (resultId == 0) {
Logger.error("Recipe result id 0");
return;
}
final HashMap<Character, ItemStack> ingredients_ = new HashMap<>(); final HashMap<Character, ItemStack> ingredients_ = new HashMap<>();
for (int i = 0; i < ingredients.length; i += 3) for (int i = 0; i < ingredients.length; i += 3) {
ingredients_.put((char) ingredients[i], new ItemStack(ingredients[i + 1], 1, ingredients[i + 2])); int id = ingredients[i + 1];
if (id == 0) {
Logger.error("Recipe result id 0");
return;
}
ingredients_.put((char) ingredients[i], new ItemStack(id, 1, ingredients[i + 2]));
}
final RecipeRegistryEntry recipe = new RecipeRegistryEntry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_); final RecipeRegistryEntry recipe = new RecipeRegistryEntry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_);
recipe.apply(runtimeItemMapping) if(runtimeItemMapping != null) {
recipe.apply(runtimeItemMapping)
.rebuildPacket(); .rebuildPacket();
} else {
recipes.add(recipe);
}
} }
public static void addShapedRecipe(ItemStack result, String[] pattern, int[] ingredients) { public static void addShapedRecipe(ItemStack result, String[] pattern, int[] ingredients) {
@@ -1,5 +1,6 @@
package com.zhekasmirnov.innercore.api.mod.recipes; package com.zhekasmirnov.innercore.api.mod.recipes;
import com.zhekasmirnov.horizon.runtime.logger.Logger;
import com.zhekasmirnov.innercore.api.NativeItemInstanceExtra; import com.zhekasmirnov.innercore.api.NativeItemInstanceExtra;
import com.zhekasmirnov.innercore.api.commontypes.ItemInstance; import com.zhekasmirnov.innercore.api.commontypes.ItemInstance;
import com.zhekasmirnov.innercore.api.log.ICLog; import com.zhekasmirnov.innercore.api.log.ICLog;
@@ -215,7 +216,8 @@ public class RecipeRegistry {
int count = ScriptableObjectHelper.getIntProperty(item, "count", 1); int count = ScriptableObjectHelper.getIntProperty(item, "count", 1);
int aux = ScriptableObjectHelper.getIntProperty(item, "data", 0); int aux = ScriptableObjectHelper.getIntProperty(item, "data", 0);
if (id == 0) { if (id == 0) {
throw new IllegalArgumentException("recipe id is 0"); Logger.error("delete recipe id is 0");
return;
} }
removeWorkbenchRecipe(id, count, aux); removeWorkbenchRecipe(id, count, aux);