mirror of
https://github.com/GeyserExtensionists/GeyserModelEnginePackGenerator.git
synced 2025-12-19 15:09:18 +00:00
new materials
This commit is contained in:
@@ -13,10 +13,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class GeneratorMain {
|
||||
public static final Map<String, Entity> entityMap = new HashMap<>();
|
||||
@@ -42,11 +39,12 @@ public class GeneratorMain {
|
||||
String modelId = folder.getName().toLowerCase();
|
||||
|
||||
Entity entity = new Entity(modelId);
|
||||
TextureConfig textureConfig = new TextureConfig();
|
||||
File textureConfigFile = new File(folder, "texture_config.json");
|
||||
ModelConfig modelConfig = new ModelConfig();
|
||||
boolean shouldOverrideConfig = false;
|
||||
File textureConfigFile = new File(folder, "config.json");
|
||||
if (textureConfigFile.exists()) {
|
||||
try {
|
||||
textureConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), TextureConfig.class);
|
||||
modelConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), ModelConfig.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -60,14 +58,15 @@ public class GeneratorMain {
|
||||
String textureName = e.getName().replace(".png", "");
|
||||
Set<String> bindingBones = new HashSet<>();
|
||||
bindingBones.add("*");
|
||||
if (textureConfig.getBingingBones().containsKey(textureName)) {
|
||||
bindingBones = textureConfig.getBingingBones().get(textureName);
|
||||
if (modelConfig.getBingingBones().containsKey(textureName)) {
|
||||
bindingBones = modelConfig.getBingingBones().get(textureName);
|
||||
}
|
||||
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
|
||||
map.put(textureName, new Texture(modelId, currentPath, bindingBones, e.toPath()));
|
||||
entity.setTextureMap(map);
|
||||
if (textureConfig.getBingingBones().isEmpty()) {
|
||||
textureConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||
if (modelConfig.getBingingBones().isEmpty()) {
|
||||
modelConfig.getBingingBones().put(textureName, Set.of("*"));
|
||||
shouldOverrideConfig = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -99,26 +98,30 @@ public class GeneratorMain {
|
||||
}
|
||||
}
|
||||
if (canAdd) {
|
||||
File config = new File(folder, "config.properties");
|
||||
// old config
|
||||
File oldConfig = new File(folder, "config.properties");
|
||||
Properties old = new Properties();
|
||||
try {
|
||||
if (config.exists()) {
|
||||
entity.getConfig().load(new FileReader(config));
|
||||
} else {
|
||||
entity.getConfig().setProperty("head-rotation", "true");
|
||||
entity.getConfig().setProperty("material", "entity_alphatest_change_color");
|
||||
entity.getConfig().setProperty("blend-transition", "true");
|
||||
entity.getConfig().store(new FileWriter(config), "");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Files.writeString(textureConfigFile.toPath(), GSON.toJson(textureConfig));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
if (oldConfig.exists()) {
|
||||
old.load(new FileReader(oldConfig));
|
||||
modelConfig.setMaterial(old.getProperty("material", "entity_alphatest_change_color"));
|
||||
modelConfig.setEnableBlendTransition(Boolean.parseBoolean(old.getProperty("blend-transition", "true")));
|
||||
modelConfig.setEnableHeadRotation(Boolean.parseBoolean(old.getProperty("head-rotation", "true")));
|
||||
shouldOverrideConfig = true;
|
||||
oldConfig.delete();
|
||||
}
|
||||
|
||||
entity.setTextureConfig(textureConfig);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (shouldOverrideConfig) {
|
||||
try {
|
||||
Files.writeString(textureConfigFile.toPath(), GSON.toJson(modelConfig));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
entity.setModelConfig(modelConfig);
|
||||
entity.setPath(currentPath);
|
||||
entityMap.put(modelId, entity);
|
||||
}
|
||||
@@ -237,7 +240,6 @@ public class GeneratorMain {
|
||||
|
||||
for (Map.Entry<String, Entity> entry : entityMap.entrySet()) {
|
||||
Entity entity = entry.getValue();
|
||||
entity.getConfig().setProperty("render_controller", "controller.render." + entry.getKey());
|
||||
entity.modify();
|
||||
|
||||
Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json");
|
||||
|
||||
@@ -57,7 +57,7 @@ public class AnimationController {
|
||||
animationControllers.add("controller.animation." + animation.modelId + "." + id, controller);
|
||||
i++;
|
||||
if (entity != null) {
|
||||
boolean blend = Boolean.parseBoolean(entity.getConfig().getProperty("blend-transition", "true"));
|
||||
boolean blend = entity.getModelConfig().isEnableBlendTransition();
|
||||
if (!blend) {
|
||||
for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) {
|
||||
states.getValue().getAsJsonObject().remove("blend_transition");
|
||||
|
||||
@@ -8,7 +8,6 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
||||
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -25,7 +24,7 @@ public class Entity {
|
||||
"identifier": "modelengine:%entity_id%",
|
||||
"materials": {
|
||||
"default": "%material%",
|
||||
"anim": "entity_alphatest_anim_change_color"
|
||||
"anim": "entity_alphatest_anim_change_color_one_sided"
|
||||
},
|
||||
"textures": {
|
||||
},
|
||||
@@ -56,10 +55,9 @@ public class Entity {
|
||||
RenderController renderController;
|
||||
String path;
|
||||
Map<String, Texture> textureMap = new HashMap<>();
|
||||
TextureConfig textureConfig;
|
||||
ModelConfig modelConfig;
|
||||
|
||||
|
||||
Properties config = new Properties();
|
||||
|
||||
|
||||
|
||||
@@ -72,8 +70,8 @@ public class Entity {
|
||||
json = new JsonParser().parse(TEMPLATE.replace("%entity_id%", modelId)
|
||||
.replace("%geometry%", "geometry.modelengine_" + modelId)
|
||||
.replace("%texture%", "textures/entity/" + path + modelId)
|
||||
.replace("%look_at_target%", Boolean.parseBoolean(config.getProperty("head-rotation", "true".toLowerCase())) ? "animation." + modelId + ".look_at_target" : "animation.none")
|
||||
.replace("%material%", config.getProperty("material", "entity_alphatest_change_color"))).getAsJsonObject();
|
||||
.replace("%look_at_target%", modelConfig.isEnableHeadRotation() ? "animation." + modelId + ".look_at_target" : "animation.none")
|
||||
.replace("%material%", modelConfig.getMaterial())).getAsJsonObject();
|
||||
|
||||
JsonObject description = json.get("minecraft:client_entity").getAsJsonObject().get("description").getAsJsonObject();
|
||||
JsonObject jsonAnimations = description.get("animations").getAsJsonObject();
|
||||
|
||||
@@ -9,6 +9,28 @@ public class Material {
|
||||
"+defines":[
|
||||
"USE_UV_ANIM"
|
||||
]
|
||||
},
|
||||
"entity_change_color_one_sided:entity": {
|
||||
"+defines": [
|
||||
"USE_OVERLAY",
|
||||
"USE_COLOR_MASK"
|
||||
]
|
||||
},
|
||||
"entity_alphatest_change_color_one_sided:entity_change_color_one_sided": {
|
||||
"+defines": [ "ALPHA_TEST" ],
|
||||
"+samplerStates": [
|
||||
{
|
||||
"samplerIndex": 1,
|
||||
"textureWrap": "Repeat"
|
||||
}
|
||||
],
|
||||
"msaaSupport": "Both"
|
||||
},
|
||||
|
||||
"entity_alphatest_anim_change_color_one_sided:entity_alphatest_change_color_one_sided":{
|
||||
"+defines":[
|
||||
"USE_UV_ANIM"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,14 @@ import java.util.Set;
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class TextureConfig {
|
||||
public class ModelConfig {
|
||||
|
||||
@SerializedName("head_rotation")
|
||||
boolean enableHeadRotation = true;
|
||||
@SerializedName("material")
|
||||
String material = "entity_alphatest_change_color_one_sided";
|
||||
@SerializedName("blend_transition")
|
||||
boolean enableBlendTransition = true;
|
||||
@SerializedName("binding_bones")
|
||||
Map<String, Set<String>> bingingBones = new HashMap<>();
|
||||
@SerializedName("anim_textures")
|
||||
@@ -26,7 +32,6 @@ public class TextureConfig {
|
||||
@Getter
|
||||
@Setter
|
||||
public static class AnimTextureOptions {
|
||||
boolean animUv;
|
||||
float fps;
|
||||
int frames;
|
||||
}
|
||||
@@ -2,17 +2,12 @@ package re.imc.geysermodelenginepackgenerator.generator;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.internal.bind.TypeAdapters;
|
||||
import re.imc.geysermodelenginepackgenerator.GeneratorMain;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class RenderController {
|
||||
|
||||
public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_", "uv_");
|
||||
public static final Set<String> NEED_REMOVE_WHEN_SORT = Set.of("pbody_", "plarm_", "prarm_", "plleg_", "prleg_", "phead_", "p_");
|
||||
String modelId;
|
||||
Map<String, Bone> bones;
|
||||
Entity entity;
|
||||
@@ -35,8 +30,8 @@ public class RenderController {
|
||||
for (String key : entity.textureMap.keySet()) {
|
||||
|
||||
Texture texture = entity.textureMap.get(key);
|
||||
Set<String> uvBonesId = entity.getTextureConfig().bingingBones.get(key);
|
||||
TextureConfig.AnimTextureOptions anim = entity.getTextureConfig().getAnimTextures().get(key);
|
||||
Set<String> uvBonesId = entity.getModelConfig().bingingBones.get(key);
|
||||
ModelConfig.AnimTextureOptions anim = entity.getModelConfig().getAnimTextures().get(key);
|
||||
|
||||
JsonObject controller = new JsonObject();
|
||||
|
||||
@@ -106,18 +101,25 @@ public class RenderController {
|
||||
for (String boneName : sorted) {
|
||||
boneName = originalId.get(boneName);
|
||||
JsonObject visibilityItem = new JsonObject();
|
||||
int n = (int) Math.pow(2, (i % 24));
|
||||
Bone bone = bones.get(boneName);
|
||||
|
||||
if (!processedBones.contains(bone) && (uvAllBones.contains(boneName) || uvBonesId.contains("*"))) {
|
||||
int index = i;
|
||||
if (boneName.startsWith("uv_")) {
|
||||
index = sorted.indexOf(bone.parent);
|
||||
}
|
||||
int n = (int) Math.pow(2, (index % 24));
|
||||
|
||||
visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + i / 24 + "') / " + n + "), 2) == 1");
|
||||
partVisibility.add(visibilityItem);
|
||||
if (!uvBonesId.contains("*")) {
|
||||
processedBones.add(bone);
|
||||
}
|
||||
}
|
||||
if (!boneName.startsWith("uv_")) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
controller.add("part_visibility", partVisibility);
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user