mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
添加手动设置旧版模型覆写规则
This commit is contained in:
@@ -156,6 +156,8 @@ warning.config.item.behavior.block.missing_block: "<yellow>Issue found in file <
|
||||
warning.config.item.behavior.furniture.missing_furniture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'furniture' argument for 'furniture_item' behavior.</yellow>"
|
||||
warning.config.item.behavior.liquid_collision.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'liquid_collision_block_item' behavior.</yellow>"
|
||||
warning.config.item.legacy_model.missing_path: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the require 'path' argument for legacy-model.</yellow>"
|
||||
warning.config.item.legacy_model.overrides.missing_path: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the require 'path' argument for legacy-model overrides.</yellow>"
|
||||
warning.config.item.legacy_model.overrides.missing_predicate: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the require 'predicate' argument for legacy-model overrides.</yellow>"
|
||||
warning.config.item.legacy_model.cannot_convert: "<yellow>Issue found in file <arg:0> - Cannot convert 1.21.4+ items to legacy format for item '<arg:1>'. Please manually create 'legacy-model' section for this item.</yellow>"
|
||||
warning.config.item.model.invalid_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid model type '<arg:2>'.</yellow>"
|
||||
warning.config.item.model.tint.missing_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'type' argument for tint.</yellow>"
|
||||
|
||||
@@ -90,8 +90,10 @@ warning.config.condition.match_block_property.missing_properties: "<yellow>在
|
||||
warning.config.condition.match_item.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'match_item' 条件所需的 'id' 参数</yellow>"
|
||||
warning.config.condition.table_bonus.missing_enchantment: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'table_bonus' 条件所需的 'enchantment' 参数</yellow>"
|
||||
warning.config.condition.table_bonus.missing_chances: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'table_bonus' 条件所需的 'chances' 参数</yellow>"
|
||||
|
||||
|
||||
warning.config.condition.permission.missing_permission: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'permission' 条件必需的 'permission' 参数</yellow>"
|
||||
warning.config.condition.equals.missing_value1: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'equals' 条件必需的 'value1' 参数</yellow>"
|
||||
warning.config.condition.equals.missing_value2: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'equals' 条件必需的 'value2' 参数</yellow>"
|
||||
warning.config.condition.expression.missing_expression: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'expression' 条件必需的 'expression' 参数</yellow>"
|
||||
warning.config.structure.not_section: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 应为配置段落 但实际类型为 '<arg:2>'</yellow>"
|
||||
warning.config.image.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的图片配置 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>"
|
||||
warning.config.image.missing_height: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'height' 参数</yellow>"
|
||||
@@ -147,11 +149,16 @@ warning.config.item.invalid_custom_model_data: "<yellow>在文件 <arg:0> 发现
|
||||
warning.config.item.bad_custom_model_data: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用的自定义模型数据 '<arg:2>' 数值过大 建议使用小于 16,777,216 的值</yellow>"
|
||||
warning.config.item.custom_model_data_conflict: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用的自定义模型数据 '<arg:2>' 已被物品 '<arg:3>' 占用</yellow>"
|
||||
warning.config.item.missing_model_id: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少必需的 'custom-model-data' 或 'item-model' 参数</yellow>"
|
||||
warning.config.item.missing_model: "<yellow>在文件 <arg:0> 中发现问题 - 物品 '<arg:1>' 缺少支持 1.21.4+ 资源包必需的 'model' 配置项</yellow>"
|
||||
warning.config.item.behavior.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的行为配置缺少必需的 'type' 参数</yellow>"
|
||||
warning.config.item.behavior.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了无效的行为类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.behavior.block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'block_item' 行为缺少必需的 'block' 参数</yellow>"
|
||||
warning.config.item.behavior.furniture.missing_furniture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'furniture_item' 行为缺少必需的 'furniture' 参数</yellow>"
|
||||
warning.config.item.behavior.liquid_collision.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'liquid_collision_block_item' 行为缺少必需的 'block' 参数</yellow>"
|
||||
warning.config.item.legacy_model.missing_path: "<yellow>在文件 <arg:0> 中发现问题 - 物品 '<arg:1>' 的旧版模型(legacy-model)缺少必需的 'path' 参数</yellow>"
|
||||
warning.config.item.legacy_model.overrides.missing_path: "<yellow>在文件 <arg:0> 中发现问题 - 物品 '<arg:1>' 的旧版模型覆写规则(overrides)缺少必需的 'path' 参数</yellow>"
|
||||
warning.config.item.legacy_model.overrides.missing_predicate: "<yellow>在文件 <arg:0> 中发现问题 - 物品 '<arg:1>' 的旧版模型覆写规则(overrides)缺少必需的 'predicate' 参数</yellow>"
|
||||
warning.config.item.legacy_model.cannot_convert: "<yellow>在文件 <arg:0> 中发现问题 - 无法将物品 '<arg:1>' 自动转换为旧版格式,请手动为此物品创建 'legacy-model' 配置项</yellow>"
|
||||
warning.config.item.model.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了无效的模型类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.model.tint.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的染色配置缺少必需的 'type' 参数</yellow>"
|
||||
warning.config.item.model.tint.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了无效的染色类型 '<arg:2>'</yellow>"
|
||||
@@ -298,10 +305,18 @@ warning.config.conflict_matcher.all_of.missing_terms: "<yellow>在 config.yml
|
||||
warning.config.conflict_matcher.any_of.missing_terms: "<yellow>在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 任一匹配器缺少必需的 'terms' 参数</yellow>"
|
||||
warning.config.conflict_resolution.missing_type: "<yellow>在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案缺少必需的 'type' 参数</yellow>"
|
||||
warning.config.conflict_resolution.invalid_type: "<yellow>在 config.yml 的 'resource-pack.duplicated-files-handler' 处发现问题 - 文件冲突处理器的某个解决方案使用了无效类型 '<arg:0>'</yellow>"
|
||||
warning.config.event.missing_trigger: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'on' argument for event triggers.</yellow>"
|
||||
warning.config.event.invalid_trigger: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid event trigger '<arg:2>'.</yellow>"
|
||||
warning.config.event.missing_trigger: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少事件触发器必需的 'on' 参数</yellow>"
|
||||
warning.config.event.invalid_trigger: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的事件触发器 '<arg:2>'</yellow>"
|
||||
warning.config.event.condition.missing_type: "<yellow>在文件 <arg:0> - 配置项 '<arg:1>' 的事件条件缺少 'type' 参数</yellow>"
|
||||
warning.config.event.condition.invalid_type: "<yellow>在文件 <arg:0> - 配置项 '<arg:1>' 使用了无效的事件条件类型 '<arg:2>'</yellow>"
|
||||
warning.config.function.missing_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'type' argument for function.</yellow>"
|
||||
warning.config.function.invalid_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid function type '<arg:2>'.</yellow>"
|
||||
warning.config.function.command.missing_command: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'command' argument for 'command' function.</yellow>"
|
||||
warning.config.function.missing_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少函数必需的 'type' 参数</yellow>"
|
||||
warning.config.function.invalid_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的函数类型 '<arg:2>'</yellow>"
|
||||
warning.config.function.command.missing_command: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'command' 函数必需的 'command' 参数</yellow>"
|
||||
warning.config.function.actionbar.missing_actionbar: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'actionbar' 函数必需的 'actionbar' 参数</yellow>"
|
||||
warning.config.function.message.missing_message: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'message' 函数必需的 'message' 参数</yellow>"
|
||||
warning.config.selector.missing_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少选择器必需的 'type' 参数</yellow>"
|
||||
warning.config.selector.invalid_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的选择器类型 '<arg:2>'</yellow>"
|
||||
warning.config.selector.invalid_target: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的选择器目标 '<arg:2>'</yellow>"
|
||||
warning.config.resource_pack.item_model.conflict.vanilla: "<yellow>无法为 '<arg:0>' 生成物品模型,因为该物品模型已被原版物品占用</yellow>"
|
||||
warning.config.resource_pack.item_model.already_exist: "<yellow>无法为 '<arg:0>' 生成物品模型,因为文件 '<arg:1>' 已存在</yellow>"
|
||||
warning.config.resource_pack.model.generation.already_exist: "<yellow>无法生成模型,因为模型文件 '<arg:0>' 已存在</yellow>"
|
||||
@@ -7,6 +7,10 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
@@ -55,11 +59,11 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private final BlockParser blockParser;
|
||||
|
||||
// A temporary map used to detect whether the same block state corresponds to multiple models.
|
||||
private final Map<Integer, Key> tempRegistryIdConflictMap = new HashMap<>();
|
||||
private final Map<Integer, Key> tempRegistryIdConflictMap = new Int2ObjectOpenHashMap<>();
|
||||
// A temporary map that converts the custom block registered on the server to the vanilla block ID.
|
||||
private final Map<Integer, Integer> tempBlockAppearanceConvertor = new HashMap<>();
|
||||
private final Map<Integer, Integer> tempBlockAppearanceConvertor = new Int2IntOpenHashMap();
|
||||
// A temporary map that stores the model path of a certain vanilla block state
|
||||
private final Map<Integer, JsonElement> tempVanillaBlockStateModels = new HashMap<>();
|
||||
private final Map<Integer, JsonElement> tempVanillaBlockStateModels = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
// The total amount of blocks registered
|
||||
private int customBlockCount;
|
||||
@@ -79,10 +83,10 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private ImmutableSet<Object> affectedSoundBlocks;
|
||||
private ImmutableMap<Key, Key> soundMapper;
|
||||
// A list to record the order of registration
|
||||
private List<Key> blockRegisterOrder = new ArrayList<>();
|
||||
private List<Key> blockRegisterOrder = new ObjectArrayList<>();
|
||||
|
||||
// a reverted mapper
|
||||
private final Map<Integer, List<Integer>> appearanceToRealState = new HashMap<>();
|
||||
private final Map<Integer, List<Integer>> appearanceToRealState = new Int2ObjectOpenHashMap<>();
|
||||
// Used to store override information of json files
|
||||
private final Map<Key, Map<String, JsonElement>> blockStateOverrides = new HashMap<>();
|
||||
// for mod, real block id -> state models
|
||||
@@ -232,11 +236,11 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
|
||||
public ImmutableMap<Key, List<Integer>> blockAppearanceArranger() {
|
||||
return blockAppearanceArranger;
|
||||
return this.blockAppearanceArranger;
|
||||
}
|
||||
|
||||
public ImmutableMap<Key, List<Integer>> realBlockArranger() {
|
||||
return realBlockArranger;
|
||||
return this.realBlockArranger;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -275,7 +279,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
try {
|
||||
Class<?> modClass = ReflectionUtils.getClazz(CraftEngine.MOD_CLASS);
|
||||
Field amountField = ReflectionUtils.getDeclaredField(modClass, "vanillaRegistrySize");
|
||||
vanillaStateCount = (int) amountField.get(null);
|
||||
vanillaStateCount = amountField.getInt(null);
|
||||
} catch (Exception e) {
|
||||
vanillaStateCount = RegistryUtils.currentBlockRegistrySize();
|
||||
plugin.logger().severe("Fatal error", e);
|
||||
@@ -481,7 +485,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
stateId2ImmutableBlockStates[state.customBlockState().registryId() - BlockStateUtils.vanillaStateSize()] = state;
|
||||
tempBlockAppearanceConvertor.put(state.customBlockState().registryId(), state.vanillaBlockState().registryId());
|
||||
appearanceToRealState.computeIfAbsent(state.vanillaBlockState().registryId(), k -> new ArrayList<>()).add(state.customBlockState().registryId());
|
||||
appearanceToRealState.computeIfAbsent(state.vanillaBlockState().registryId(), k -> new IntArrayList()).add(state.customBlockState().registryId());
|
||||
}
|
||||
|
||||
BukkitBlockManager.this.byId.put(id, block);
|
||||
@@ -649,9 +653,9 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
YamlDocument mappings = Config.instance().loadOrCreateYamlData("mappings.yml");
|
||||
Map<String, String> blockStateMappings = loadBlockStateMappings(mappings);
|
||||
this.validateBlockStateMappings(mappingFile, blockStateMappings);
|
||||
Map<Integer, String> stateMap = new HashMap<>();
|
||||
Map<Integer, String> stateMap = new Int2ObjectOpenHashMap<>();
|
||||
Map<Key, Integer> blockTypeCounter = new LinkedHashMap<>();
|
||||
Map<Integer, Integer> appearanceMapper = new HashMap<>();
|
||||
Map<Integer, Integer> appearanceMapper = new Int2IntOpenHashMap();
|
||||
Map<Key, List<Integer>> appearanceArranger = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : blockStateMappings.entrySet()) {
|
||||
this.processBlockStateMapping(mappingFile, entry, stateMap, blockTypeCounter, appearanceMapper, appearanceArranger);
|
||||
@@ -727,7 +731,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
counter.compute(key, (k, count) -> count == null ? 1 : count + 1);
|
||||
stateMap.put(beforeId, entry.getKey());
|
||||
stateMap.put(afterId, entry.getValue());
|
||||
arranger.computeIfAbsent(key, (k) -> new ArrayList<>()).add(beforeId);
|
||||
arranger.computeIfAbsent(key, (k) -> new IntArrayList()).add(beforeId);
|
||||
} else {
|
||||
String previousState = stateMap.get(previous);
|
||||
plugin.logger().warn(mappingFile, "Duplicate entry: '" + previousState + "' equals '" + entry.getKey() + "'");
|
||||
@@ -776,7 +780,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
Object clientSideBlock = getBlockFromRegistry(createResourceLocation(clientSideBlockType));
|
||||
int amount = blockWithCount.getValue();
|
||||
|
||||
List<Integer> stateIds = new ArrayList<>();
|
||||
List<Integer> stateIds = new IntArrayList();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Key realBlockKey = createRealBlockKey(clientSideBlockType, i);
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -258,6 +258,16 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
public class ItemParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
private static final float VERSION_1_21_2 = 21.2f;
|
||||
private static final float VERSION_1_21_4 = 21.4f;
|
||||
|
||||
private boolean isModernFormatRequired() {
|
||||
return Config.packMaxVersion() >= VERSION_1_21_4;
|
||||
}
|
||||
|
||||
private boolean needsLegacyCompatibility() {
|
||||
return Config.packMinVersion() < VERSION_1_21_4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sectionId() {
|
||||
@@ -338,7 +348,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
// add it to category
|
||||
if (section.containsKey("category")) {
|
||||
plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList());
|
||||
AbstractItemManager.this.plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList());
|
||||
}
|
||||
|
||||
// model part, can be null
|
||||
@@ -353,7 +363,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
throw new LocalizedResourceConfigException("warning.config.item.missing_model_id");
|
||||
}
|
||||
// 1.21.4+必须要配置model区域
|
||||
if (Config.packMaxVersion() >= 21.4f && modelSection == null) {
|
||||
if (isModernFormatRequired() && modelSection == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.missing_model");
|
||||
}
|
||||
|
||||
@@ -362,47 +372,22 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
// 旧版格式
|
||||
TreeSet<LegacyOverridesModel> legacyOverridesModels = null;
|
||||
|
||||
if (Config.packMaxVersion() >= 21.4f) {
|
||||
if (isModernFormatRequired() || (needsLegacyCompatibility() && legacyModelSection == null)) {
|
||||
modernModel = ItemModels.fromMap(modelSection);
|
||||
for (ModelGeneration generation : modernModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
// 如果最低支持版本低于1.21.4,则需要准备旧版overrides模型
|
||||
if (Config.packMinVersion() < 21.4f) {
|
||||
// 如果有旧版格式,就用旧版
|
||||
if (legacyModelSection != null) {
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection);
|
||||
for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides());
|
||||
} else {
|
||||
// 否则把新版格式并转换为旧版
|
||||
legacyOverridesModels = new TreeSet<>();
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
if (legacyOverridesModels.isEmpty()) {
|
||||
TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 最高支持版本不超过1.21.4,所以新版model格式为非必需
|
||||
else {
|
||||
// 如果有旧版格式,就用旧版
|
||||
if (needsLegacyCompatibility()) {
|
||||
if (legacyModelSection != null) {
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection);
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection, customModelData);
|
||||
for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides());
|
||||
} else {
|
||||
// 否则读新版格式并转换为旧版
|
||||
ItemModel model = ItemModels.fromMap(modelSection);
|
||||
for (ModelGeneration generation : model.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>();
|
||||
processModelRecursively(model, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
if (legacyOverridesModels.isEmpty()) {
|
||||
TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString());
|
||||
}
|
||||
@@ -413,29 +398,30 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
if (customModelData != 0) {
|
||||
// use custom model data
|
||||
// check conflict
|
||||
Map<Integer, Key> conflict = cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>());
|
||||
Map<Integer, Key> conflict = AbstractItemManager.this.cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>());
|
||||
if (conflict.containsKey(customModelData)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", String.valueOf(customModelData), conflict.get(customModelData).toString());
|
||||
}
|
||||
conflict.put(customModelData, id);
|
||||
// Parse models
|
||||
if (Config.packMaxVersion() >= 21.4f && modernModel != null) {
|
||||
TreeMap<Integer, ItemModel> map = modernOverrides.computeIfAbsent(material, k -> new TreeMap<>());
|
||||
if (isModernFormatRequired() && modernModel != null) {
|
||||
TreeMap<Integer, ItemModel> map = AbstractItemManager.this.modernOverrides.computeIfAbsent(material, k -> new TreeMap<>());
|
||||
map.put(customModelData, modernModel);
|
||||
}
|
||||
if (Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>());
|
||||
if (needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>());
|
||||
lom.addAll(legacyOverridesModels);
|
||||
}
|
||||
}
|
||||
|
||||
// use item model
|
||||
if (itemModelKey != null) {
|
||||
if (Config.packMaxVersion() >= 21.4f && modernModel != null) {
|
||||
modernItemModels1_21_4.put(itemModelKey, modernModel);
|
||||
if (isModernFormatRequired() && modernModel != null) {
|
||||
AbstractItemManager.this.modernItemModels1_21_4.put(itemModelKey, modernModel);
|
||||
}
|
||||
if (Config.packMaxVersion() >= 21.2f && Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
modernItemModels1_21_2.put(itemModelKey, legacyOverridesModels);
|
||||
if (Config.packMaxVersion() >= VERSION_1_21_2 && needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.modernItemModels1_21_2.computeIfAbsent(itemModelKey, k -> new TreeSet<>());
|
||||
lom.addAll(legacyOverridesModels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,8 +428,10 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
Yaml yaml = new Yaml(new StringKeyConstructor(new LoaderOptions()));
|
||||
for (Pack pack : loadedPacks()) {
|
||||
if (!pack.enabled()) continue;
|
||||
Path configurationFolderPath = pack.configurationFolder();
|
||||
if (!Files.isDirectory(configurationFolderPath)) continue;
|
||||
try {
|
||||
Files.walkFileTree(pack.configurationFolder(), new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(configurationFolderPath, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) {
|
||||
if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(".yml")) {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package net.momirealms.craftengine.core.pack.model;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -31,13 +34,38 @@ public class LegacyItemModel {
|
||||
return path;
|
||||
}
|
||||
|
||||
public static LegacyItemModel fromMap(Map<String, Object> legacyModel) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static LegacyItemModel fromMap(Map<String, Object> legacyModel, int customModelData) {
|
||||
String legacyModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(legacyModel.get("path"), "warning.config.item.legacy_model.missing_path");
|
||||
Map<String, Object> generation = MiscUtils.castToMap(legacyModel.get("generation"), true);
|
||||
ModelGeneration modelGeneration = null;
|
||||
ModelGeneration baseModelGeneration = null;
|
||||
if (generation != null) {
|
||||
modelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation);
|
||||
baseModelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation);
|
||||
}
|
||||
List<Map<String, Object>> overrides = (List<Map<String, Object>>) legacyModel.get("overrides");
|
||||
if (overrides != null) {
|
||||
List<ModelGeneration> modelGenerations = new ArrayList<>();
|
||||
List<LegacyOverridesModel> legacyOverridesModels = new ArrayList<>();
|
||||
if (baseModelGeneration != null) modelGenerations.add(baseModelGeneration);
|
||||
legacyOverridesModels.add(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData));
|
||||
for (Map<String, Object> override : overrides) {
|
||||
String overrideModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(override.get("path"), () -> new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_path"));
|
||||
Map<String, Object> predicate = MiscUtils.castToMap(ResourceConfigUtils.requireNonNullOrThrow(override.get("predicate"), "warning.config.item.legacy_model.overrides.missing_predicate"), false);
|
||||
if (predicate.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_predicate");
|
||||
}
|
||||
Map<String, Object> overrideGeneration = MiscUtils.castToMap(override.get("generation"), true);
|
||||
if (overrideGeneration != null) {
|
||||
modelGenerations.add(ModelGeneration.of(Key.of(overrideModelPath), overrideGeneration));
|
||||
}
|
||||
legacyOverridesModels.add(new LegacyOverridesModel(predicate, overrideModelPath, customModelData));
|
||||
}
|
||||
return new LegacyItemModel(legacyModelPath, legacyOverridesModels, modelGenerations);
|
||||
} else {
|
||||
return new LegacyItemModel(legacyModelPath,
|
||||
List.of(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData)),
|
||||
baseModelGeneration == null ? List.of() : List.of(baseModelGeneration)
|
||||
);
|
||||
}
|
||||
LegacyOverridesModel legacyOverridesModel = new LegacyOverridesModel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.pack.model;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -11,8 +13,8 @@ public class LegacyOverridesModel implements Comparable<LegacyOverridesModel> {
|
||||
private final String model;
|
||||
private final int customModelData;
|
||||
|
||||
public LegacyOverridesModel(Map<String, Object> predicate, String model, int customModelData) {
|
||||
this.predicate = predicate;
|
||||
public LegacyOverridesModel(@Nullable Map<String, Object> predicate, @NotNull String model, int customModelData) {
|
||||
this.predicate = predicate == null ? new HashMap<>() : predicate;
|
||||
this.model = model;
|
||||
this.customModelData = customModelData;
|
||||
if (customModelData > 0) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class IntIdentityList implements IndexedIterable<Integer> {
|
||||
|
||||
public IntIdentityList(int size) {
|
||||
this.size = size;
|
||||
list = new ArrayList<>(size);
|
||||
list = new IntArrayList(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.54.1
|
||||
config_version=32
|
||||
lang_version=12
|
||||
project_version=0.0.54.2
|
||||
config_version=33
|
||||
lang_version=13
|
||||
project_group=net.momirealms
|
||||
latest_supported_version=1.21.5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user