From 7d440c32a32b63154a1126508ab157bd9b79ab9d Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Tue, 24 Jun 2025 02:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0use-player-texture=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/pack/misc/EquipmentGeneration.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) 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 15f060a6d..e353e28c5 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 @@ -110,23 +110,32 @@ public class EquipmentGeneration implements Supplier { layersJson.add(key, layersArray); } - public record Layer(String texture, DyeableData data) implements Supplier { + public record Layer(String texture, DyeableData data, boolean usePlayerTexture) implements Supplier { @NotNull public static List fromConfig(Object obj) { - if (obj instanceof String texture) { - 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, DyeableData.fromObj(map.get("dyeable")))); - } else if (obj instanceof List list) { - List layers = new ArrayList<>(); - for (Object inner : list) { - layers.addAll(fromConfig(inner)); + switch (obj) { + case String texture -> { + return List.of(new Layer(texture, null, false)); + } + case Map map -> { + Map data = MiscUtils.castToMap(map, false); + String texture = data.get("texture").toString(); + return List.of(new Layer(texture, + DyeableData.fromObj(data.get("dyeable")), + ResourceConfigUtils.getAsBoolean(data.getOrDefault("use-player-texture", false), "use-player-texture") + )); + } + case List list -> { + List layers = new ArrayList<>(); + for (Object inner : list) { + layers.addAll(fromConfig(inner)); + } + return layers; + } + case null, default -> { + return List.of(); } - return layers; - } else { - return List.of(); } } @@ -137,6 +146,9 @@ public class EquipmentGeneration implements Supplier { if (this.data != null) { jsonObject.add("dyeable", this.data.get()); } + if (this.usePlayerTexture) { + jsonObject.addProperty("use_player_texture", true); + } return jsonObject; } @@ -146,7 +158,6 @@ public class EquipmentGeneration implements Supplier { 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")); } }