1using System.Globalization;
8 public static List<CraftingRecipe>
m_recipes = [];
10 public static string fName =
"CraftingRecipesManager";
20 XElement source =
null;
22 modEntity.
LoadCr(ref source);
26 foreach (
Block block
in blocks) {
31 "CraftingRecipesManagerInitialize",
33 loader.CraftingRecipesManagerInitialize(
m_recipes, ref sort);
42 int y = r1.
Ingredients.Count(s => !
string.IsNullOrEmpty(s));
43 int x = r2.
Ingredients.Count(s => !
string.IsNullOrEmpty(s));
44 return Comparer<int>.Default.Compare(x, y);
51 "CraftingRecipesManagerInitialized",
53 loader.CraftingRecipesManagerInitialized();
61 if (item.Attribute(
"Result") !=
null) {
62 foreach (XElement xElement
in item.Elements()) {
69 "OnCraftingRecipeDecode",
71 modLoader.OnCraftingRecipeDecode(
m_recipes, item, out flag);
89 if (desc.StartsWith(
'[')
94 craftingRecipe.ResultValue =
DecodeResult(attributeValue);
97 if (!
string.IsNullOrEmpty(attributeValue2)) {
98 craftingRecipe.RemainsValue =
DecodeResult(attributeValue2);
103 craftingRecipe.Description = desc;
106 Dictionary<char, string> dictionary =
new();
107 foreach (XAttribute item2
in from a
in item.Attributes()
108 where a.Name.LocalName.Length == 1 &&
char.IsLower(a.Name.LocalName[0])
112 throw new InvalidOperationException($
"Block with craftingId \"{item2.Value}\" not found.");
115 && (data.Value < 0 || data.Value > 262143)) {
116 throw new InvalidOperationException($
"Data in recipe ingredient \"{item2.Value}\" must be between 0 and 0x3FFFF.");
118 dictionary.Add(item2.Name.LocalName[0], item2.Value);
120 string[] array = item.Value.Trim().Split([
"\n"], StringSplitOptions.None);
121 for (
int i = 0; i < array.Length; i++) {
122 int num = array[i].IndexOf(
'"');
123 int num2 = array[i].LastIndexOf(
'"');
127 throw new InvalidOperationException(
"Invalid recipe line.");
129 string text = array[i].Substring(num + 1, num2 - num - 1);
130 for (
int j = 0; j < text.Length; j++) {
132 if (
char.IsLower(c)) {
133 string text2 = dictionary[c];
134 craftingRecipe.Ingredients[j + i * horizontalLen] = text2;
138 return craftingRecipe;
142 if (ingredients.All(
string.IsNullOrEmpty)) {
147 for (
int i = 0; i < blocks.Length; i++) {
149 if (adHocCraftingRecipe !=
null
151 craftingRecipe = adHocCraftingRecipe;
155 if (craftingRecipe ==
null) {
158 craftingRecipe = recipe;
163 if (craftingRecipe !=
null) {
165 craftingRecipe = !(heatLevel > 0f)
170 craftingRecipe = !(craftingRecipe.RequiredHeatLevel > 0f)
175 return craftingRecipe;
184 result2 = modLoader.DecodeResult(result, out flag2);
191 if (!
string.IsNullOrEmpty(result)) {
192 string[] array = result.Split([
':'], StringSplitOptions.None);
194 return Terrain.
MakeBlockValue(blockIndex, 0, array.Length == 2 ?
int.Parse(array[1], CultureInfo.InvariantCulture) : 0);
199 public static void DecodeIngredient(
string ingredient, out
string craftingId, out
int? data) {
201 string craftingId_R =
string.Empty;
206 modLoader.DecodeIngredient(ingredient, out craftingId_R, out data_R, out flag2);
211 craftingId = craftingId_R;
215 string[] array = ingredient.Split([
':'], StringSplitOptions.None);
216 craftingId = array[0];
217 data = array.Length >= 2 ?
new int?(
int.Parse(array[1], CultureInfo.InvariantCulture)) :
null;
220 public static bool MatchRecipe(
string[] requiredIngredients,
string[] actualIngredients) {
226 result = modLoader.MatchRecipe(requiredIngredients, actualIngredients, out flag2);
233 if (actualIngredients.Length > 9) {
236 string[] array =
new string[9];
237 for (
int i = 0; i < 2; i++) {
239 for (
int j = -4; j <= 2; j++) {
240 for (
int k = -4; k <= 2; k++) {
245 for (
int l = 0; l < 9; l++) {
246 if (l == actualIngredients.Length
261 public static bool TransformRecipe(
string[] transformedIngredients,
string[] ingredients,
int shiftX,
int shiftY,
bool flip) {
262 for (
int i = 0; i < 9; i++) {
263 transformedIngredients[i] =
null;
265 for (
int j = 0; j < 3; j++) {
266 for (
int k = 0; k < 3; k++) {
267 int num = (flip ? 3 - k - 1 : k) + shiftX;
268 int num2 = j + shiftY;
269 string text = ingredients[k + j * 3];
274 transformedIngredients[num + num2 * 3] = text;
276 else if (!
string.IsNullOrEmpty(text)) {
285 if (requiredIngredient ==
null) {
286 return actualIngredient ==
null;
288 if (actualIngredient ==
null) {
294 if (!data2.HasValue) {
295 throw new InvalidOperationException(
"Actual ingredient data not specified.");
297 if (craftingId == craftingId2) {
298 if (!data.HasValue) {
301 return data.Value == data2.Value;
static void Error(object message)
virtual IEnumerable< CraftingRecipe > GetProceduralCraftingRecipes()
virtual CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain subsystemTerrain, string[] ingredients, float heatLevel, float playerLevel)
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
static Block[] FindBlocksByCraftingId(string craftingId)
int DisplayOrder
在配方表中的显示顺序,DisplayOrder越小,配方越靠前
float RequiredPlayerLevel
static void DecodeIngredient(string ingredient, out string craftingId, out int? data)
static CraftingRecipe DecodeElementToCraftingRecipe(XElement item, int horizontalLen=3)
static CraftingRecipe FindMatchingRecipe(SubsystemTerrain terrain, string[] ingredients, float heatLevel, float playerLevel)
static bool CompareIngredients(string requiredIngredient, string actualIngredient)
static List< CraftingRecipe > m_recipes
static int DecodeResult(string result)
static List< CraftingRecipe > Recipes
static void LoadData(XElement item)
static bool EnableLevelRestrictions
启用等级限制 Mod在初始化时,设置为false可以让物品合成不受玩家等级限制
static bool TransformRecipe(string[] transformedIngredients, string[] ingredients, int shiftX, int shiftY, bool flip)
static bool MatchRecipe(string[] requiredIngredients, string[] actualIngredients)
static bool TryGetBlock(string blockName, string prop, out string result)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
virtual void LoadCr(ref XElement xElement)
初始化CraftingRecipe
static int MakeBlockValue(int contents)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static List< ModEntity > ModList
所有已启用的模组
static object GetAttributeValue(XElement node, string attributeName, Type type)