9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-22 08:29:21 +00:00

添加special模型生成,完善special

This commit is contained in:
XiaoMoMi
2025-05-09 02:05:02 +08:00
parent 8b2b3c8cf8
commit ef1caaa05a
9 changed files with 47 additions and 16 deletions

View File

@@ -179,6 +179,8 @@ warning.config.item.model.select.case.missing_model: "<yellow>Issue found in fil
warning.config.item.model.select.block_state.missing_property: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block-state-property' argument for property 'minecraft:block_state'.</yellow>"
warning.config.item.model.select.local_time.missing_pattern: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'pattern' argument for property 'minecraft:local_time'.</yellow>"
warning.config.item.model.special.missing_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'type' argument for model 'minecraft:special'.</yellow>"
warning.config.item.model.special.missing_path: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'path' argument for model 'minecraft:special'.</yellow>"
warning.config.item.model.special.invalid_path: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' has an invalid 'path' argument '<arg:2>' for model 'minecraft:special' which contains illegal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters.</yellow>"
warning.config.item.model.special.invalid_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid type '<arg:2>' for model 'minecraft:special'.</yellow>"
warning.config.item.model.special.banner.missing_color: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'color' argument for special model 'minecraft:banner'.</yellow>"
warning.config.item.model.special.bed.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:bed'.</yellow>"
@@ -189,7 +191,6 @@ warning.config.item.model.special.chest.invalid_openness: "<yellow>Issue found i
warning.config.item.model.special.shulker_box.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:shulker_box'.</yellow>"
warning.config.item.model.special.shulker_box.invalid_openness: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid 'openness' value '<arg:2>' for special model 'minecraft:shulker_box'. Valid range '0~1.'</yellow>"
warning.config.item.model.special.head.missing_kind: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'kind' argument for special model 'minecraft:head'.</yellow>"
warning.config.item.model.special.head.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:head'.</yellow>"
warning.config.block.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated block '<arg:1>'. Please check if there is the same configuration in other files.</yellow>"
warning.config.block.missing_state: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'state' argument.</yellow>"
warning.config.block.state.property.missing_type: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'type' argument for property '<arg:2>'.</yellow>"

View File

@@ -167,7 +167,6 @@ warning.config.item.model.special.chest.invalid_openness: "<yellow><arg:0> dosya
warning.config.item.model.special.shulker_box.missing_texture: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' eşyası, 'minecraft:shulker_box' özel modeli için gerekli 'texture' argümanı eksik.</yellow>"
warning.config.item.model.special.shulker_box.invalid_openness: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' eşyası, 'minecraft:shulker_box' özel modeli için geçersiz bir 'openness' değeri '<arg:2>' kullanıyor. Geçerli aralık '0~1.'</yellow>"
warning.config.item.model.special.head.missing_kind: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' eşyası, 'minecraft:head' özel modeli için gerekli 'kind' argümanı eksik.</yellow>"
warning.config.item.model.special.head.missing_texture: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' eşyası, 'minecraft:head' özel modeli için gerekli 'texture' argümanı eksik.</yellow>"
warning.config.block.duplicate: "<yellow><arg:0> dosyasında sorun bulundu - Yinelenen blok '<arg:1>'. Diğer dosyalarda aynı yapılandırmanın olup olmadığını kontrol edin.</yellow>"
warning.config.block.missing_state: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' bloğu gerekli 'state' argümanı eksik.</yellow>"
warning.config.block.state.property.missing_type: "<yellow><arg:0> dosyasında sorun bulundu - '<arg:1>' bloğu, '<arg:2>' özelliği için gerekli 'type' argümanı eksik.</yellow>"

View File

@@ -179,6 +179,8 @@ warning.config.item.model.select.case.missing_model: "<yellow>在文件 <arg:0>
warning.config.item.model.select.block_state.missing_property: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:block_state' 属性缺少必需的 'block-state-property' 参数</yellow>"
warning.config.item.model.select.local_time.missing_pattern: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:local_time' 属性缺少必需的 'pattern' 参数</yellow>"
warning.config.item.model.special.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型缺少必需的 'type' 参数</yellow>"
warning.config.item.model.special.missing_path: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型缺少必需的模型 'path' 参数</yellow>"
warning.config.item.model.special.invalid_path: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型路径 '<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.item.model.special.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型使用了无效类型 '<arg:2>'</yellow>"
warning.config.item.model.special.banner.missing_color: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:banner' 特殊模型缺少必需的 'color' 参数</yellow>"
warning.config.item.model.special.bed.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:bed' 特殊模型缺少必需的 'texture' 参数</yellow>"
@@ -189,7 +191,6 @@ warning.config.item.model.special.chest.invalid_openness: "<yellow>在文件 <ar
warning.config.item.model.special.shulker_box.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:shulker_box' 特殊模型缺少必需的 'texture' 参数</yellow>"
warning.config.item.model.special.shulker_box.invalid_openness: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:shulker_box' 特殊模型使用了无效的 'openness' 值 '<arg:2>' 有效范围应为 0~1</yellow>"
warning.config.item.model.special.head.missing_kind: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:head' 特殊模型缺少必需的 'kind' 参数</yellow>"
warning.config.item.model.special.head.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:head' 特殊模型缺少必需的 'texture' 参数</yellow>"
warning.config.block.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的方块 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>"
warning.config.block.missing_state: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 缺少必需的 'state' 参数</yellow>"
warning.config.block.state.property.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的属性 '<arg:2>' 缺少必需的 'type' 参数</yellow>"

View File

@@ -39,7 +39,7 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> 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());

View File

@@ -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<ModelGeneration> modelsToGenerate() {
if (this.modelGeneration == null) {
return List.of();
} else {
return List.of(this.modelGeneration);
}
}
public static class Factory implements ItemModelFactory {
@Override
public ItemModel create(Map<String, Object> 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<String, Object> generation = MiscUtils.castToMap(arguments.get("generation"), true);
ModelGeneration modelGeneration = null;
if (generation != null) {
modelGeneration = new ModelGeneration(Key.of(base), generation);
}
Map<String, Object> model = MiscUtils.castToMap(arguments.get("model"), false);
return new SpecialItemModel(SpecialModels.fromMap(model), base);
return new SpecialItemModel(SpecialModels.fromMap(model), base, modelGeneration);
}
}
}

View File

@@ -27,7 +27,9 @@ public class ChestSpecialModel implements SpecialModel {
JsonObject json = new JsonObject();
json.addProperty("type", type().toString());
json.addProperty("texture", texture);
if (openness > 0) {
json.addProperty("openness", openness);
}
return json;
}

View File

@@ -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);
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<String, Object> 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);
}

View File

@@ -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);
json.addProperty("openness", openness);
if (orientation != null) {
json.addProperty("orientation", orientation.name().toLowerCase(Locale.ENGLISH));
}
json.addProperty("openness", openness);
return json;
}
@@ -42,7 +47,7 @@ public class ShulkerBoxSpecialModel implements SpecialModel {
public SpecialModel create(Map<String, Object> 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));
}

View File

@@ -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