9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 12:56:28 +00:00

优化配方类别获取

This commit is contained in:
XiaoMoMi
2025-04-28 20:32:28 +08:00
parent 08172d5463
commit 3a14b950d1
13 changed files with 52 additions and 35 deletions

View File

@@ -66,7 +66,7 @@ command.send_resource_pack.success.multiple: "<white>Send resource packs to <arg
warning.config.not_a_section: "<yellow>Issue found in file <arg:0> - '<arg:1>.<arg:2>' is expected to be a config section while it's actually a(n) '<arg:3>'.</yellow>"
warning.config.image.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'.</yellow>"
warning.config.image.lack_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' violates the bitmap image rule: 'height' should be no lower than 'ascent'.</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' violates the bitmap image rule: 'height'[<arg:2>] should be no lower than 'ascent'[<arg:3>].</yellow>"
warning.config.image.lack_file: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'file' argument.</yellow>"
warning.config.image.invalid_resource_location: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' has a 'file' argument [<arg:2>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
warning.config.image.invalid_font_name: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' has a 'font' argument [<arg:2>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
@@ -74,6 +74,7 @@ warning.config.image.lack_char: "<yellow>Issue found in file <arg:0> - The image
warning.config.image.codepoint_in_use: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using a character[<arg:3>(<arg:4>)] in font <arg:2> that has been used by another image '<arg:5>'.</yellow>"
warning.config.image.invalid_codepoint_grid: "<yellow>Issue found in file <arg:0> - Image '<arg:1>' has an invalid 'chars' codepoint grind.</yellow>"
warning.config.image.file_not_exist: "<yellow>Issue found in file <arg:0> - PNG file '<arg:2>' not found for image '<arg:1>'.</yellow>"
warning.config.image.invalid_hex: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using an unicode character '<arg:2>' that is not a valid hexadecimal (radix 16) value.</yellow>"
warning.config.recipe.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated recipe '<arg:1>'.</yellow>"
warning.config.recipe.lack_type: "<yellow>Issue found in file <arg:0> - The recipe '<arg:1>' is missing the required argument 'type'.</yellow>"
warning.config.recipe.invalid_type: "<yellow>Issue found in file <arg:0> - The recipe '<arg:1>' is using an invalid recipe type '<arg:2>'.</yellow>"
@@ -81,6 +82,8 @@ warning.config.recipe.invalid_item: "<yellow>Issue found in file <arg:0> - The r
warning.config.recipe.lack_ingredient: "<yellow>Issue found in file <arg:0> - The cooking recipe '<arg:1>' is missing the required 'ingredient' argument.</yellow>"
warning.config.recipe.lack_result: "<yellow>Issue found in file <arg:0> - The recipe '<arg:1>' is missing the required argument 'result'.</yellow>"
warning.config.recipe.result.lack_id: "<yellow>Issue found in file <arg:0> - The recipe '<arg:1>' is missing the required argument 'id' for recipe result.</yellow>"
warning.config.recipe.crafting.invalid_category: "<yellow>Issue found in file <arg:0> - The crafting recipe '<arg:1>' is using an invalid category '<arg:2>'. Allowed categories: [BUILDING, REDSTONE, EQUIPMENT, MISC]</yellow>"
warning.config.recipe.cooking.invalid_category: "<yellow>Issue found in file <arg:0> - The cooking recipe '<arg:1>' is using an invalid category '<arg:2>'. Allowed categories: [FOOD, BLOCKS, MISC]</yellow>"
warning.config.recipe.shaped.lack_pattern: "<yellow>Issue found in file <arg:0> - The shaped recipe '<arg:1>' is missing the required argument 'pattern'.</yellow>"
warning.config.recipe.shaped.invalid_pattern: "<yellow>Issue found in file <arg:0> - The shaped recipe '<arg:1>' is using an invalid pattern '<arg:2>'.</yellow>"
warning.config.recipe.shaped.invalid_symbol: "<yellow>Issue found in file <arg:0> - The shaped recipe '<arg:1>' is using an invalid symbol '<arg:2>' in pattern.</yellow>"

View File

@@ -65,8 +65,8 @@ command.send_resource_pack.success.single: "<white>发送资源包给 <arg:0></w
command.send_resource_pack.success.multiple: "<white>发送资源包给 <arg:0> 个玩家</white>"
warning.config.image.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 重复定义</yellow>"
warning.config.image.lack_height: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'height' 高度参数</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 违反位图规则:'height' 高度值不应小于 'ascent' 基准线高度</yellow>"
warning.config.image.no_file: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'file' 文件参数</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 违反位图规则:'height' 高度值[<arg:2>]不应小于 'ascent' 基准线高度[<arg:3>]</yellow>"
warning.config.image.lack_file: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'file' 文件参数</yellow>"
warning.config.image.invalid_resource_location: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 的 'file' 参数 [<arg:2>] 包含非法字符请参考资源路径规范https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
warning.config.image.invalid_font_name: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 的 'font' 字体参数 [<arg:2>] 包含非法字符请参考资源路径规范https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
warning.config.image.lack_char: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'char' 字符参数</yellow>"
@@ -74,7 +74,7 @@ warning.config.image.codepoint_in_use: "<yellow>在文件 <arg:0> 中发现问
warning.config.image.invalid_codepoint_grid: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 的 'chars' 码位网格配置无效</yellow>"
warning.config.image.file_not_exist: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 对应的PNG文件 <arg:2> 不存在</yellow>"
warning.config.recipe.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 配方 '<arg:1>' 重复定义</yellow>"
warning.config.i18n.unknown_locale: "<yellow>在文件 <arg:0> 中发现问题 - 未知的语言区域 '<arg:1>'</yellow>"
warning.config.i18n.unknown_locale: "<yellow>在文件 <arg:0> 中发现问题 - 未知的语言 '<arg:1>'</yellow>"
warning.config.template.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 模板 '<arg:1>' 重复定义</yellow>"
warning.config.vanilla_loot.type_not_exist: "<yellow>在文件 <arg:0> 中发现问题 - 原版战利品 '<arg:1>' 未设置 'type' 类型参数</yellow>"
warning.config.vanilla_loot.block.invalid_target: "<yellow>在文件 <arg:0> 中发现问题 - 原版战利品 '<arg:1>' 中的方块目标 [<arg:2>] 无效</yellow>"

View File

@@ -518,7 +518,7 @@ public abstract class AbstractFontManager implements FontManager {
int height = MiscUtils.getAsInt(heightObj);
int ascent = MiscUtils.getAsInt(section.getOrDefault("ascent", height - 1));
if (height < ascent) {
throw new LocalizedResourceConfigException("warning.config.image.height_smaller_than_ascent", path, id);
throw new LocalizedResourceConfigException("warning.config.image.height_smaller_than_ascent", path, id, String.valueOf(height), String.valueOf(ascent));
}
BitmapImage bitmapImage = new BitmapImage(id, fontKey, height, ascent, resourceLocation, codepointGrid);

View File

@@ -7,10 +7,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
public abstract class AbstractRecipeFactory<T> implements RecipeFactory<T> {
@@ -45,4 +42,24 @@ public abstract class AbstractRecipeFactory<T> implements RecipeFactory<T> {
}
return ingredient;
}
protected CookingRecipeCategory cookingRecipeCategory(Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory;
try {
recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
} catch (IllegalArgumentException e) {
throw new LocalizedResourceConfigException("warning.config.recipe.cooking.invalid_category", e, arguments.get("category").toString());
}
return recipeCategory;
}
protected CraftingRecipeCategory craftingRecipeCategory(Map<String, Object> arguments) {
CraftingRecipeCategory recipeCategory;
try {
recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
} catch (IllegalArgumentException e) {
throw new LocalizedResourceConfigException("warning.config.recipe.crafting.invalid_category", e, arguments.get("category").toString());
}
return recipeCategory;
}
}

View File

@@ -26,12 +26,11 @@ public class CustomBlastingRecipe<T> extends CustomCookingRecipe<T> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<A> create(Key id, Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
Set<Holder<Key>> holders = ingredientHolders(arguments);
return new CustomBlastingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
return new CustomBlastingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
}
}
}

View File

@@ -26,12 +26,11 @@ public class CustomCampfireRecipe<T> extends CustomCookingRecipe<T> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<A> create(Key id, Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
Set<Holder<Key>> holders = ingredientHolders(arguments);
return new CustomCampfireRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
return new CustomCampfireRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
}
}
}

View File

@@ -147,7 +147,6 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
throw new LocalizedResourceConfigException("warning.config.recipe.shaped.invalid_pattern", new IllegalArgumentException("Invalid pattern: " + pattern), pattern.toString());
}
Object ingredientObj = getIngredientOrThrow(arguments);
CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
Map<Character, Ingredient<A>> ingredients = new HashMap<>();
for (Map.Entry<String, Object> entry : MiscUtils.castToMap(ingredientObj, false).entrySet()) {
@@ -168,13 +167,7 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
}
ingredients.put(ch, Ingredient.of(holders));
}
return new CustomShapedRecipe(
id,
recipeCategory,
group,
new Pattern<>(pattern.toArray(new String[0]), ingredients),
parseResult(arguments)
);
return new CustomShapedRecipe(id, craftingRecipeCategory(arguments), group, new Pattern<>(pattern.toArray(new String[0]), ingredients), parseResult(arguments));
}
private boolean validatePattern(List<String> pattern) {

View File

@@ -58,7 +58,6 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<A> create(Key id, Map<String, Object> arguments) {
CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
List<Ingredient<A>> ingredients = new ArrayList<>();
Object ingredientsObject = getIngredientOrThrow(arguments);
@@ -112,7 +111,7 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
}
ingredients.add(Ingredient.of(holders));
}
return new CustomShapelessRecipe(id, recipeCategory, group, ingredients, parseResult(arguments));
return new CustomShapelessRecipe(id, craftingRecipeCategory(arguments), group, ingredients, parseResult(arguments));
}
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -26,12 +27,11 @@ public class CustomSmeltingRecipe<T> extends CustomCookingRecipe<T> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<A> create(Key id, Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
Set<Holder<Key>> holders = ingredientHolders(arguments);
return new CustomSmeltingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
return new CustomSmeltingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
}
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -26,12 +27,11 @@ public class CustomSmokingRecipe<T> extends CustomCookingRecipe<T> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<A> create(Key id, Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
Set<Holder<Key>> holders = ingredientHolders(arguments);
return new CustomSmokingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
return new CustomSmokingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments));
}
}
}

View File

@@ -42,7 +42,7 @@ public class RecipeTypes {
public static <T> Recipe<T> fromMap(Key id, Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.recipe.lack_type", new NullPointerException("recipe type cannot be null"));
throw new LocalizedResourceConfigException("warning.config.recipe.lack_type", new NullPointerException("'type' cannot be null for recipe"));
}
Key key = Key.withDefaultNamespace(type, "minecraft");
RecipeFactory<T> factory = (RecipeFactory<T>) BuiltInRegistries.RECIPE_FACTORY.getValue(key);

View File

@@ -1,5 +1,7 @@
package net.momirealms.craftengine.core.util;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import java.util.stream.IntStream;
public class CharacterUtils {
@@ -11,12 +13,17 @@ public class CharacterUtils {
int length = processedString.length() / 4;
char[] chars = new char[length];
for (int i = 0; i < length; i++) {
int codePoint = Integer.parseInt(processedString.substring(i * 4, i * 4 + 4), 16);
if (Character.isSupplementaryCodePoint(codePoint)) {
chars[i] = Character.highSurrogate(codePoint);
chars[++i] = Character.lowSurrogate(codePoint);
} else {
chars[i] = (char) codePoint;
String hex = processedString.substring(i * 4, i * 4 + 4);
try {
int codePoint = Integer.parseInt(hex, 16);
if (Character.isSupplementaryCodePoint(codePoint)) {
chars[i] = Character.highSurrogate(codePoint);
chars[++i] = Character.lowSurrogate(codePoint);
} else {
chars[i] = (char) codePoint;
}
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("");
}
}
return chars;

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.51
project_version=0.0.52-beta.1
config_version=30
lang_version=8
project_group=net.momirealms