9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-24 17:39:30 +00:00

修复一些tint和texture的问题

This commit is contained in:
XiaoMoMi
2025-05-10 00:09:38 +08:00
parent a705a8e8de
commit 289cc5028c
7 changed files with 47 additions and 20 deletions

View File

@@ -41,8 +41,10 @@ public abstract class AbstractModelGenerator implements ModelGenerator {
Map<String, String> textures = model.texturesOverride();
if (textures != null) {
for (Map.Entry<String, String> texture : textures.entrySet()) {
if (!ResourceLocation.isValid(texture.getValue())) {
throw new LocalizedResourceConfigException("warning.config.model.generation.texture.invalid", texture.getKey(), texture.getValue());
if (texture.getValue().charAt(0) != '#') {
if (!ResourceLocation.isValid(texture.getValue())) {
throw new LocalizedResourceConfigException("warning.config.model.generation.texture.invalid", texture.getKey(), texture.getValue());
}
}
}
}

View File

@@ -10,9 +10,9 @@ import java.util.Map;
public class ConstantTint implements Tint {
public static final Factory FACTORY = new Factory();
private final Either<Integer, List<Integer>> value;
private final Either<Integer, List<Float>> value;
public ConstantTint(Either<Integer, List<Integer>> value) {
public ConstantTint(Either<Integer, List<Float>> value) {
this.value = value;
}

View File

@@ -10,10 +10,10 @@ import java.util.Map;
public class CustomModelDataTint implements Tint {
public static final Factory FACTORY = new Factory();
private final Either<Integer, List<Integer>> value;
private final Either<Integer, List<Float>> value;
private final int index;
public CustomModelDataTint(Either<Integer, List<Integer>> value, int index) {
public CustomModelDataTint(Either<Integer, List<Float>> value, int index) {
this.index = index;
this.value = value;
}

View File

@@ -9,10 +9,10 @@ import java.util.Map;
public class SimpleDefaultTint implements Tint {
public static final Factory FACTORY = new Factory();
private final Either<Integer, List<Integer>> value;
private final Either<Integer, List<Float>> value;
private final Key type;
public SimpleDefaultTint(Either<Integer, List<Integer>> value, Key type) {
public SimpleDefaultTint(Either<Integer, List<Float>> value, Key type) {
this.value = value;
this.type = type;
}

View File

@@ -12,16 +12,16 @@ public interface Tint extends Supplier<JsonObject> {
Key type();
default void applyAnyTint(JsonObject json, Either<Integer, List<Integer>> value, String key) {
default void applyAnyTint(JsonObject json, Either<Integer, List<Float>> value, String key) {
if (value.primary().isPresent()) {
json.addProperty(key, value.primary().get());
} else {
List<Integer> list = value.fallback().get();
List<Float> list = value.fallback().get();
if (list.size() != 3) {
throw new RuntimeException("Invalid tint value list size: " + list.size() + " which is expected to be 3");
}
JsonArray array = new JsonArray();
for (int i : list) {
for (float i : list) {
array.add(i);
}
json.add(key, array);

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.core.pack.model.tint;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.incendo.cloud.type.Either;
import java.util.ArrayList;
@@ -11,27 +12,51 @@ public interface TintFactory {
Tint create(Map<String, Object> arguments);
default Either<Integer, List<Integer>> parseTintValue(Object value) {
default Either<Integer, List<Float>> parseTintValue(Object value) {
if (value instanceof Number i) {
return Either.ofPrimary(i.intValue());
} else if (value instanceof List<?> list) {
if (list.size() == 3) {
List<Integer> intList = new ArrayList<>();
for (Object o : list) {
intList.add(Integer.parseInt(o.toString()));
List<String> strList = MiscUtils.getAsStringList(list);
boolean hasDot = false;
for (String str : strList) {
if (str.contains(".")) {
hasDot = true;
break;
}
}
return Either.ofFallback(intList);
List<Float> fList = new ArrayList<>();
for (String str : strList) {
if (hasDot) {
fList.add(Float.parseFloat(str));
} else {
fList.add(convertToFloat(Integer.parseInt(str)));
}
}
return Either.ofFallback(fList);
}
} else if (value instanceof String s) {
String[] split = s.split(",");
if (split.length == 3) {
List<Integer> intList = new ArrayList<>();
List<Float> fList = new ArrayList<>();
boolean hasDot = s.contains(".");
for (String string : split) {
intList.add(Integer.parseInt(string));
if (hasDot) {
fList.add(Float.parseFloat(string));
} else {
fList.add(convertToFloat(Integer.parseInt(string)));
}
}
return Either.ofFallback(intList);
return Either.ofFallback(fList);
}
}
throw new LocalizedResourceConfigException("warning.config.item.model.tint.invalid_value", value.toString());
}
static float convertToFloat(int value) {
if (value < 0 || value > 255) {
throw new IllegalArgumentException("Tint value out of range: " + value + ". Allowed range is [0,255]");
}
return value / 255.0f;
}
}

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.53.3
project_version=0.0.53.4
config_version=32
lang_version=12
project_group=net.momirealms