From ef1caaa05afa367acd6de3d2f76ac5af3d591108 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Fri, 9 May 2025 02:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0special=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=94=9F=E6=88=90=EF=BC=8C=E5=AE=8C=E5=96=84special?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/translations/en.yml | 3 ++- .../src/main/resources/translations/tr.yml | 1 - .../src/main/resources/translations/zh_cn.yml | 3 ++- .../item/factory/BukkitItemFactory.java | 2 +- .../core/pack/model/SpecialItemModel.java | 26 ++++++++++++++++--- .../pack/model/special/ChestSpecialModel.java | 4 ++- .../pack/model/special/HeadSpecialModel.java | 11 +++++--- .../model/special/ShulkerBoxSpecialModel.java | 11 +++++--- gradle.properties | 2 +- 9 files changed, 47 insertions(+), 16 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index ff18b0826..d7240fa55 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -179,6 +179,8 @@ warning.config.item.model.select.case.missing_model: "Issue found in fil warning.config.item.model.select.block_state.missing_property: "Issue found in file - The item '' is missing the required 'block-state-property' argument for property 'minecraft:block_state'." warning.config.item.model.select.local_time.missing_pattern: "Issue found in file - The item '' is missing the required 'pattern' argument for property 'minecraft:local_time'." warning.config.item.model.special.missing_type: "Issue found in file - The item '' is missing the required 'type' argument for model 'minecraft:special'." +warning.config.item.model.special.missing_path: "Issue found in file - The item '' is missing the required 'path' argument for model 'minecraft:special'." +warning.config.item.model.special.invalid_path: "Issue found in file - The item '' has an invalid 'path' argument '' for model 'minecraft:special' which contains illegal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters." warning.config.item.model.special.invalid_type: "Issue found in file - The item '' is using an invalid type '' for model 'minecraft:special'." warning.config.item.model.special.banner.missing_color: "Issue found in file - The item '' is missing the required 'color' argument for special model 'minecraft:banner'." warning.config.item.model.special.bed.missing_texture: "Issue found in file - The item '' is missing the required 'texture' argument for special model 'minecraft:bed'." @@ -189,7 +191,6 @@ warning.config.item.model.special.chest.invalid_openness: "Issue found i warning.config.item.model.special.shulker_box.missing_texture: "Issue found in file - The item '' is missing the required 'texture' argument for special model 'minecraft:shulker_box'." warning.config.item.model.special.shulker_box.invalid_openness: "Issue found in file - The item '' is using an invalid 'openness' value '' for special model 'minecraft:shulker_box'. Valid range '0~1.'" warning.config.item.model.special.head.missing_kind: "Issue found in file - The item '' is missing the required 'kind' argument for special model 'minecraft:head'." -warning.config.item.model.special.head.missing_texture: "Issue found in file - The item '' is missing the required 'texture' argument for special model 'minecraft:head'." warning.config.block.duplicate: "Issue found in file - Duplicated block ''. Please check if there is the same configuration in other files." warning.config.block.missing_state: "Issue found in file - The block '' is missing the required 'state' argument." warning.config.block.state.property.missing_type: "Issue found in file - The block '' is missing the required 'type' argument for property ''." diff --git a/bukkit/loader/src/main/resources/translations/tr.yml b/bukkit/loader/src/main/resources/translations/tr.yml index def783519..7c1c475b5 100644 --- a/bukkit/loader/src/main/resources/translations/tr.yml +++ b/bukkit/loader/src/main/resources/translations/tr.yml @@ -167,7 +167,6 @@ warning.config.item.model.special.chest.invalid_openness: " dosya warning.config.item.model.special.shulker_box.missing_texture: " dosyasında sorun bulundu - '' eşyası, 'minecraft:shulker_box' özel modeli için gerekli 'texture' argümanı eksik." warning.config.item.model.special.shulker_box.invalid_openness: " dosyasında sorun bulundu - '' eşyası, 'minecraft:shulker_box' özel modeli için geçersiz bir 'openness' değeri '' kullanıyor. Geçerli aralık '0~1.'" warning.config.item.model.special.head.missing_kind: " dosyasında sorun bulundu - '' eşyası, 'minecraft:head' özel modeli için gerekli 'kind' argümanı eksik." -warning.config.item.model.special.head.missing_texture: " dosyasında sorun bulundu - '' eşyası, 'minecraft:head' özel modeli için gerekli 'texture' argümanı eksik." warning.config.block.duplicate: " dosyasında sorun bulundu - Yinelenen blok ''. Diğer dosyalarda aynı yapılandırmanın olup olmadığını kontrol edin." warning.config.block.missing_state: " dosyasında sorun bulundu - '' bloğu gerekli 'state' argümanı eksik." warning.config.block.state.property.missing_type: " dosyasında sorun bulundu - '' bloğu, '' özelliği için gerekli 'type' argümanı eksik." diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index d2e6ed5f9..2429e0ff3 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -179,6 +179,8 @@ warning.config.item.model.select.case.missing_model: "在文件 warning.config.item.model.select.block_state.missing_property: "在文件 发现问题 - 物品 '' 的 'minecraft:block_state' 属性缺少必需的 'block-state-property' 参数" warning.config.item.model.select.local_time.missing_pattern: "在文件 发现问题 - 物品 '' 的 'minecraft:local_time' 属性缺少必需的 'pattern' 参数" warning.config.item.model.special.missing_type: "在文件 发现问题 - 物品 '' 的 'minecraft:special' 模型缺少必需的 'type' 参数" +warning.config.item.model.special.missing_path: "在文件 发现问题 - 物品 '' 的 'minecraft:special' 模型缺少必需的模型 'path' 参数" +warning.config.item.model.special.invalid_path: "在文件 发现问题 - 物品 '' 的 'minecraft:special' 模型路径 '' 包含非法字符 请参考 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" warning.config.item.model.special.invalid_type: "在文件 发现问题 - 物品 '' 的 'minecraft:special' 模型使用了无效类型 ''" warning.config.item.model.special.banner.missing_color: "在文件 发现问题 - 物品 '' 的 'minecraft:banner' 特殊模型缺少必需的 'color' 参数" warning.config.item.model.special.bed.missing_texture: "在文件 发现问题 - 物品 '' 的 'minecraft:bed' 特殊模型缺少必需的 'texture' 参数" @@ -189,7 +191,6 @@ warning.config.item.model.special.chest.invalid_openness: "在文件 在文件 发现问题 - 物品 '' 的 'minecraft:shulker_box' 特殊模型缺少必需的 'texture' 参数" warning.config.item.model.special.shulker_box.invalid_openness: "在文件 发现问题 - 物品 '' 的 'minecraft:shulker_box' 特殊模型使用了无效的 'openness' 值 '' 有效范围应为 0~1" warning.config.item.model.special.head.missing_kind: "在文件 发现问题 - 物品 '' 的 'minecraft:head' 特殊模型缺少必需的 'kind' 参数" -warning.config.item.model.special.head.missing_texture: "在文件 发现问题 - 物品 '' 的 'minecraft:head' 特殊模型缺少必需的 'texture' 参数" warning.config.block.duplicate: "在文件 发现问题 - 重复的方块 '' 请检查其他文件中是否存在相同配置" warning.config.block.missing_state: "在文件 发现问题 - 方块 '' 缺少必需的 'state' 参数" warning.config.block.state.property.missing_type: "在文件 发现问题 - 方块 '' 的属性 '' 缺少必需的 'type' 参数" diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/BukkitItemFactory.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/BukkitItemFactory.java index 149f335f5..853271e93 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/BukkitItemFactory.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/factory/BukkitItemFactory.java @@ -39,7 +39,7 @@ public abstract class BukkitItemFactory> extend case "1.21.4" -> { return new ComponentItemFactory1_21_4(plugin); } - case "1.21.5", "1.22", "1.22.1" -> { + case "1.21.5", "1.21.6", "1.22", "1.22.1" -> { return new ComponentItemFactory1_21_5(plugin); } default -> throw new IllegalStateException("Unsupported server version: " + plugin.serverVersion()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/SpecialItemModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/SpecialItemModel.java index 99f125240..ccfa2e026 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/SpecialItemModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/SpecialItemModel.java @@ -1,11 +1,15 @@ package net.momirealms.craftengine.core.pack.model; import com.google.gson.JsonObject; +import net.momirealms.craftengine.core.pack.ResourceLocation; import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration; import net.momirealms.craftengine.core.pack.model.special.SpecialModel; import net.momirealms.craftengine.core.pack.model.special.SpecialModels; +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 org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Map; @@ -15,10 +19,12 @@ public class SpecialItemModel implements ItemModel { public static final Factory FACTORY = new Factory(); private final SpecialModel specialModel; private final String base; + private final ModelGeneration modelGeneration; - public SpecialItemModel(SpecialModel specialModel, String base) { + public SpecialItemModel(SpecialModel specialModel, String base, @Nullable ModelGeneration generation) { this.specialModel = specialModel; this.base = base; + this.modelGeneration = generation; } public SpecialModel specialModel() { @@ -45,16 +51,28 @@ public class SpecialItemModel implements ItemModel { @Override public List modelsToGenerate() { - return List.of(); + if (this.modelGeneration == null) { + return List.of(); + } else { + return List.of(this.modelGeneration); + } } public static class Factory implements ItemModelFactory { @Override public ItemModel create(Map arguments) { - String base = Objects.requireNonNull(arguments.get("base")).toString(); + String base = ResourceConfigUtils.requireNonEmptyStringOrThrow(ResourceConfigUtils.get(arguments, "base", "path"), "warning.config.item.model.special.missing_path"); + if (!ResourceLocation.isValid(base)) { + throw new LocalizedResourceConfigException("warning.config.item.model.special.invalid_path", base); + } + Map generation = MiscUtils.castToMap(arguments.get("generation"), true); + ModelGeneration modelGeneration = null; + if (generation != null) { + modelGeneration = new ModelGeneration(Key.of(base), generation); + } Map model = MiscUtils.castToMap(arguments.get("model"), false); - return new SpecialItemModel(SpecialModels.fromMap(model), base); + return new SpecialItemModel(SpecialModels.fromMap(model), base, modelGeneration); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ChestSpecialModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ChestSpecialModel.java index 31aaf4563..a4cdce121 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ChestSpecialModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ChestSpecialModel.java @@ -27,7 +27,9 @@ public class ChestSpecialModel implements SpecialModel { JsonObject json = new JsonObject(); json.addProperty("type", type().toString()); json.addProperty("texture", texture); - json.addProperty("openness", openness); + if (openness > 0) { + json.addProperty("openness", openness); + } return json; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/HeadSpecialModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/HeadSpecialModel.java index 6f1cf530c..7ee58315d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/HeadSpecialModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/HeadSpecialModel.java @@ -5,6 +5,7 @@ import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; +import java.util.Optional; public class HeadSpecialModel implements SpecialModel { public static final Factory FACTORY = new Factory(); @@ -28,8 +29,12 @@ public class HeadSpecialModel implements SpecialModel { JsonObject json = new JsonObject(); json.addProperty("type", type().toString()); json.addProperty("kind", kind); - json.addProperty("texture", texture); - json.addProperty("animation", animation); + if (texture != null) { + json.addProperty("texture", texture); + } + if (animation != 0) { + json.addProperty("animation", animation); + } return json; } @@ -38,7 +43,7 @@ public class HeadSpecialModel implements SpecialModel { @Override public SpecialModel create(Map arguments) { String kind = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("kind"), "warning.config.item.model.special.head.missing_kind"); - String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.head.missing_texture"); + String texture = Optional.ofNullable(arguments.get("texture")).map(String::valueOf).orElse(null); int animation = ResourceConfigUtils.getAsInt(arguments.getOrDefault("animation", 0), "animation"); return new HeadSpecialModel(kind, texture, animation); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ShulkerBoxSpecialModel.java b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ShulkerBoxSpecialModel.java index 0eaf640a6..2ba8f374c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ShulkerBoxSpecialModel.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/model/special/ShulkerBoxSpecialModel.java @@ -5,9 +5,12 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce import net.momirealms.craftengine.core.util.Direction; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; +import org.jetbrains.annotations.Nullable; +import java.awt.desktop.OpenFilesEvent; import java.util.Locale; import java.util.Map; +import java.util.Optional; public class ShulkerBoxSpecialModel implements SpecialModel { public static final Factory FACTORY = new Factory(); @@ -15,7 +18,7 @@ public class ShulkerBoxSpecialModel implements SpecialModel { private final float openness; private final Direction orientation; - public ShulkerBoxSpecialModel(String texture, float openness, Direction orientation) { + public ShulkerBoxSpecialModel(String texture, float openness, @Nullable Direction orientation) { this.texture = texture; this.openness = openness; this.orientation = orientation; @@ -31,8 +34,10 @@ public class ShulkerBoxSpecialModel implements SpecialModel { JsonObject json = new JsonObject(); json.addProperty("type", type().toString()); json.addProperty("texture", texture); + if (orientation != null) { + json.addProperty("orientation", orientation.name().toLowerCase(Locale.ENGLISH)); + } json.addProperty("openness", openness); - json.addProperty("orientation", orientation.name().toLowerCase(Locale.ENGLISH)); return json; } @@ -42,7 +47,7 @@ public class ShulkerBoxSpecialModel implements SpecialModel { public SpecialModel create(Map arguments) { float openness = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("openness", 0), "openness"); String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.shulker_box.missing_texture"); - Direction orientation = Direction.valueOf(arguments.getOrDefault("orientation", "down").toString().toUpperCase(Locale.ENGLISH)); + Direction orientation = Optional.ofNullable(arguments.get("orientation")).map(String::valueOf).map(String::toUpperCase).map(Direction::valueOf).orElse(null); if (openness > 1 || openness < 0) { throw new LocalizedResourceConfigException("warning.config.item.model.special.shulker_box.invalid_openness", String.valueOf(openness)); } diff --git a/gradle.properties b/gradle.properties index 978455b6b..c7950e2ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.53.2 +project_version=0.0.53.3 config_version=32 lang_version=12 project_group=net.momirealms