diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/misc/EquipmentGeneration.java b/core/src/main/java/net/momirealms/craftengine/core/pack/misc/EquipmentGeneration.java index 47430f516..917643964 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/misc/EquipmentGeneration.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/misc/EquipmentGeneration.java @@ -3,7 +3,12 @@ package net.momirealms.craftengine.core.pack.misc; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.momirealms.craftengine.core.item.setting.EquipmentData; +import net.momirealms.craftengine.core.pack.model.tint.Tint; +import net.momirealms.craftengine.core.util.Color; +import net.momirealms.craftengine.core.util.MiscUtils; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -107,15 +112,15 @@ public class EquipmentGeneration implements Supplier { layersJson.add(key, layersArray); } - public record Layer(String texture, boolean dyeable) implements Supplier { + public record Layer(String texture, DyeableData data) implements Supplier { @NotNull public static List fromConfig(Object obj) { if (obj instanceof String texture) { - return List.of(new Layer(texture, false)); + return List.of(new Layer(texture, null)); } else if (obj instanceof Map map) { String texture = map.get("texture").toString(); - return List.of(new Layer(texture, map.containsKey("dyeable"))); + return List.of(new Layer(texture, DyeableData.fromObj(map.get("dyeable")))); } else if (obj instanceof List list) { List layers = new ArrayList<>(); for (Object inner : list) { @@ -131,10 +136,33 @@ public class EquipmentGeneration implements Supplier { public JsonObject get() { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("texture", texture); - if (dyeable) { - jsonObject.add("dyeable", new JsonObject()); + if (this.data != null) { + jsonObject.add("dyeable", this.data.get()); } return jsonObject; } + + public record DyeableData(@Nullable Integer colorWhenUndyed) implements Supplier { + + public static DyeableData fromObj(Object obj) { + if (obj instanceof Map map) { + Map data = MiscUtils.castToMap(map, false); + if (data.containsKey("color-when-undyed")) { + // todo 添加更多数据类型支持 + return new DyeableData(ResourceConfigUtils.getAsInt(data.get("color-when-undyed"), "color-when-undyed")); + } + } + return new DyeableData(null); + } + + @Override + public JsonObject get() { + JsonObject dyeData = new JsonObject(); + if (this.colorWhenUndyed != null) { + dyeData.addProperty("color_when_undyed", this.colorWhenUndyed); + } + return dyeData; + } + } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/Color.java b/core/src/main/java/net/momirealms/craftengine/core/util/Color.java index 24da61b00..0e47529c1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/Color.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/Color.java @@ -20,6 +20,10 @@ public class Color { this(r, g, b, DEFAULT_ALPHA); } + public int toDecimal() { + return DEFAULT_ALPHA << 24 | (r << 16) | (g << 8) | b; + } + public static Color fromString(String[] strings) { if (strings.length == 3) { return new Color(Byte.parseByte(strings[0]), Byte.parseByte(strings[1]), Byte.parseByte(strings[2])); diff --git a/gradle.properties b/gradle.properties index beaf09e99..159a9f1f2 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.57.5 +project_version=0.0.57.6 config_version=37 lang_version=18 project_group=net.momirealms