9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-22 00:19:17 +00:00
This commit is contained in:
XiaoMoMi
2025-04-28 22:47:18 +08:00
parent 0c24100350
commit adb1eb832b
9 changed files with 40 additions and 91 deletions

View File

@@ -79,7 +79,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.image.invalid_hex: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is using a 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>"

View File

@@ -335,24 +335,10 @@ public class BukkitBlockManager extends AbstractBlockManager {
throw new LocalizedResourceConfigException("warning.config.block.duplicated", path, id);
}
// read block settings
BlockSettings settings;
try {
settings = BlockSettings.fromMap(MiscUtils.castToMap(section.getOrDefault("settings", Map.of()), false));
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
BlockSettings settings = BlockSettings.fromMap(MiscUtils.castToMap(section.getOrDefault("settings", Map.of()), false));
// read loot table
LootTable<ItemStack> lootTable;
try {
lootTable = LootTable.fromMap(MiscUtils.castToMap(section.getOrDefault("loot", Map.of()), false));
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
LootTable<ItemStack> lootTable = LootTable.fromMap(MiscUtils.castToMap(section.getOrDefault("loot", Map.of()), false));
// read states
Map<String, Property<?>> properties;
@@ -440,9 +426,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
Map<String, Object> behaviors = MiscUtils.castToMap(section.getOrDefault("behavior", Map.of()), false);
CustomBlock block;
try {
block = BukkitCustomBlock.builder(id)
CustomBlock block = BukkitCustomBlock.builder(id)
.appearances(appearances)
.variantMapper(variants)
.lootTable(lootTable)
@@ -450,11 +434,6 @@ public class BukkitBlockManager extends AbstractBlockManager {
.settings(settings)
.behavior(behaviors)
.build();
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
// bind appearance and real state
for (ImmutableBlockState state : block.variantProvider().states()) {

View File

@@ -157,14 +157,8 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
List<Map<String, Object>> hitboxConfigs = (List<Map<String, Object>>) placementArguments.getOrDefault("hitboxes", List.of());
List<HitBox> hitboxes = new ArrayList<>();
for (Map<String, Object> config : hitboxConfigs) {
try {
HitBox hitBox = HitBoxTypes.fromMap(config);
hitboxes.add(hitBox);
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
HitBox hitBox = HitBoxTypes.fromMap(config);
hitboxes.add(hitBox);
}
if (hitboxes.isEmpty() && externalModel.isEmpty()) {
hitboxes.add(InteractionHitBox.DEFAULT);
@@ -198,24 +192,10 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
}
// get furniture settings
FurnitureSettings settings;
try {
settings = FurnitureSettings.fromMap(settingsMap);
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
FurnitureSettings settings = FurnitureSettings.fromMap(settingsMap);
// get loot table
LootTable<ItemStack> lootTable;
try {
lootTable = lootMap == null ? null : LootTable.fromMap(lootMap);
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
LootTable<ItemStack> lootTable = lootMap == null ? null : LootTable.fromMap(lootMap);
CustomFurniture furniture = new CustomFurniture(id, settings, placements, lootTable);
byId.put(id, furniture);
}

View File

@@ -339,15 +339,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
}
}
ItemSettings itemSettings;
try {
itemSettings = ItemSettings.fromMap(MiscUtils.castToMap(section.get("settings"), true));
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
ItemSettings itemSettings = ItemSettings.fromMap(MiscUtils.castToMap(section.get("settings"), true));
if (isVanillaItem) {
itemSettings.canPlaceRelatedVanillaBlock(true);
}
@@ -391,15 +383,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
return;
}
ItemModel model;
try {
model = ItemModels.fromMap(modelSection);
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
ItemModel model = ItemModels.fromMap(modelSection);
boolean hasModel = false;
if (customModelData != 0) {
hasModel= true;

View File

@@ -159,14 +159,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
if (AbstractRecipeManager.this.byId.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.recipe.duplicated", path, id);
}
Recipe<T> recipe;
try {
recipe = RecipeTypes.fromMap(id, section);
} catch (LocalizedResourceConfigException e) {
e.setPath(path);
e.setId(id);
throw e;
}
Recipe<T> recipe = RecipeTypes.fromMap(id, section);
try {
markAsCustomRecipe(id);
registerInternalRecipe(id, recipe);

View File

@@ -450,20 +450,27 @@ public abstract class AbstractPackManager implements PackManager {
String key = configEntry.getKey();
try {
Key id = Key.withDefaultNamespace(key, cached.pack().namespace());
if (parser.isTemplate()) {
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
} else if (predicate.test(parser)) {
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
Map<String, Object> configSection1 = castToMap(configSection0, false);
if ((boolean) configSection1.getOrDefault("enable", true)) {
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
try {
if (parser.isTemplate()) {
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
} else if (predicate.test(parser)) {
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
Map<String, Object> configSection1 = castToMap(configSection0, false);
if ((boolean) configSection1.getOrDefault("enable", true)) {
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
}
} else {
TranslationManager.instance().log("warning.config.not_a_section", cached.filePath().toString(), parser.sectionId()[0], configEntry.getKey(), configEntry.getValue().getClass().getSimpleName());
}
} else {
TranslationManager.instance().log("warning.config.not_a_section", cached.filePath().toString(), parser.sectionId()[0], configEntry.getKey(), configEntry.getValue().getClass().getSimpleName());
}
} catch (LocalizedException e) {
if (e instanceof LocalizedResourceConfigException exception) {
exception.setPath(cached.filePath());
exception.setId(cached.prefix() + "." + key);
}
TranslationManager.instance().log(e.node(), e.arguments());
this.plugin.debug(e::node);
}
} catch (LocalizedException e) {
TranslationManager.instance().log(e.node(), e.arguments());
} catch (Exception e) {
this.plugin.logger().warn("Unexpected error loading file " + cached.filePath() + " - '" + parser.sectionId()[0] + "." + key + "'. Please find the cause according to the stacktrace or seek developer help.", e);
}
@@ -482,7 +489,7 @@ public abstract class AbstractPackManager implements PackManager {
String configType = hashIndex != -1 ? key.substring(0, hashIndex) : key;
Optional.ofNullable(this.sectionParsers.get(configType))
.ifPresent(parser -> this.cachedConfigs.computeIfAbsent(parser, k -> new ArrayList<>())
.add(new CachedConfig(castToMap(typeSections0, false), path, pack)));
.add(new CachedConfig(key, castToMap(typeSections0, false), path, pack)));
}
}

View File

@@ -6,12 +6,14 @@ import java.util.Map;
public class CachedConfig {
private final Pack pack;
private final Path filePath;
private final String prefix;
private final Map<String, Object> config;
public CachedConfig(Map<String, Object> config, Path filePath, Pack pack) {
public CachedConfig(String prefix, Map<String, Object> config, Path filePath, Pack pack) {
this.config = config;
this.filePath = filePath;
this.pack = pack;
this.prefix = prefix;
}
public Map<String, Object> config() {
@@ -25,4 +27,8 @@ public class CachedConfig {
public Pack pack() {
return pack;
}
public String prefix() {
return prefix;
}
}

View File

@@ -37,7 +37,7 @@ public class LocalizedResourceConfigException extends LocalizedException {
super.setArgument(0, path.toString());
}
public void setId(Key id) {
super.setArgument(1, id.toString());
public void setId(String id) {
super.setArgument(1, id);
}
}

View File

@@ -23,7 +23,7 @@ public class CharacterUtils {
chars[i] = (char) codePoint;
}
} catch (NumberFormatException e) {
throw new LocalizedResourceConfigException("");
throw new LocalizedResourceConfigException("warning.config.image.invalid_hex", e, hex);
}
}
return chars;