mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 02:19:23 +00:00
添加color when undyed支持
This commit is contained in:
@@ -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<JsonObject> {
|
||||
layersJson.add(key, layersArray);
|
||||
}
|
||||
|
||||
public record Layer(String texture, boolean dyeable) implements Supplier<JsonObject> {
|
||||
public record Layer(String texture, DyeableData data) implements Supplier<JsonObject> {
|
||||
|
||||
@NotNull
|
||||
public static List<Layer> 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<Layer> layers = new ArrayList<>();
|
||||
for (Object inner : list) {
|
||||
@@ -131,10 +136,33 @@ public class EquipmentGeneration implements Supplier<JsonObject> {
|
||||
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<JsonObject> {
|
||||
|
||||
public static DyeableData fromObj(Object obj) {
|
||||
if (obj instanceof Map<?,?> map) {
|
||||
Map<String, Object> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user