my brain with this codebase ;-; added a config option to disable auto resource pack load

This commit is contained in:
xSquishyLiam
2025-08-22 18:54:49 +01:00
parent f90b8bfaaf
commit e79c4a36ab
24 changed files with 997 additions and 314 deletions

6
.gitignore vendored
View File

@@ -1,3 +1,9 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
target/ target/
!.mvn/wrapper/maven-wrapper.jar !.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/

40
build.gradle.kts Normal file
View File

@@ -0,0 +1,40 @@
plugins {
id("java")
id("io.github.goooler.shadow") version "8.1.7"
}
group = "me.zimzaza4"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://repo.opencollab.dev/main/")
}
dependencies {
compileOnly("org.geysermc.geyser:api:2.8.3-SNAPSHOT")
compileOnly(files("libs/geyserutils-geyser-1.0-SNAPSHOT.jar"))
implementation("org.spongepowered:configurate-yaml:4.2.0-GeyserMC-SNAPSHOT")
implementation("com.google.code.gson:gson:2.13.1")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks.compileJava {
options.encoding = "UTF-8"
}
tasks.shadowJar {
archiveFileName.set("${rootProject.name}-${version}.jar")
relocate("org.spongepowered.configurate", "me.zimzaza4.geysermodelenginepackgenerator.libs.configurate")
}
tasks.build {
dependsOn("shadowJar")
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

251
gradlew vendored Normal file
View File

@@ -0,0 +1,251 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

94
gradlew.bat vendored Normal file
View File

@@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

85
pom.xml
View File

@@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>re.imc</groupId>
<artifactId>GeyserModelEnginePackGenerator</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>opencollab-release-repo</id>
<url>https://repo.opencollab.dev/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>opencollab-snapshot-repo</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.geysermc.geyser</groupId>
<artifactId>api</artifactId>
<version>2.5.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.zimzaza4</groupId>
<artifactId>geyserutils-geyser</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/geyserutils-geyser-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>me.rochblondiaux</groupId>
<artifactId>blockbenchmodelreader</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.github.GeyserMC.PackConverter</groupId>
<artifactId>bedrock-pack-schema</artifactId>
<version>3d8150474d</version>
</dependency>
<dependency>
<groupId>com.github.GeyserMC.PackConverter</groupId>
<artifactId>pack-schema-api</artifactId>
<version>3d8150474d</version>
</dependency>
</dependencies>
</project>

1
settings.gradle.kts Normal file
View File

@@ -0,0 +1 @@
rootProject.name = "GeyserModelEnginePackGenerator"

View File

@@ -17,13 +17,12 @@ import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
public class GeneratorMain { public class GeneratorMain {
public static final Map<String, Entity> entityMap = new HashMap<>(); public static final Map<String, Entity> entityMap = new HashMap<>();
public static final Map<String, Animation> animationMap = new HashMap<>(); public static final Map<String, Animation> animationMap = new HashMap<>();
public static final Map<String, Geometry> geometryMap = new HashMap<>(); public static final Map<String, Geometry> geometryMap = new HashMap<>();
public static final Map<String, Map<String, Texture>> textureMap = new HashMap<>(); public static final Map<String, Map<String, Texture>> textureMap = new HashMap<>();
public static final Gson GSON = new GsonBuilder().setPrettyPrinting() public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
.create();
public static void main(String[] args) { public static void main(String[] args) {
File source = new File(args.length > 0 ? args[0] : "input"); File source = new File(args.length > 0 ? args[0] : "input");
@@ -36,11 +35,11 @@ public class GeneratorMain {
public static void generateFromZip(String currentPath, String modelId, ZipFile zip) { public static void generateFromZip(String currentPath, String modelId, ZipFile zip) {
Entity entity = new Entity(modelId); Entity entity = new Entity(modelId);
if (entityMap.containsKey(modelId)) { if (entityMap.containsKey(modelId)) return;
return;
}
ModelConfig modelConfig = new ModelConfig(); ModelConfig modelConfig = new ModelConfig();
ZipEntry textureConfigFile = null; ZipEntry textureConfigFile = null;
for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) { for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) {
ZipEntry entry = it.next(); ZipEntry entry = it.next();
if (entry.getName().endsWith("config.json")) { if (entry.getName().endsWith("config.json")) {
@@ -69,8 +68,8 @@ public class GeneratorMain {
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>()); Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
try { try {
map.put(textureName, new Texture(modelId, currentPath, bindingBones, zip.getInputStream(e).readAllBytes())); map.put(textureName, new Texture(modelId, currentPath, bindingBones, zip.getInputStream(e).readAllBytes()));
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
entity.setTextureMap(map); entity.setTextureMap(map);
if (modelConfig.getBingingBones().isEmpty()) { if (modelConfig.getBingingBones().isEmpty()) {
@@ -106,6 +105,7 @@ public class GeneratorMain {
} }
} }
} }
if (canAdd) { if (canAdd) {
entity.setModelConfig(modelConfig); entity.setModelConfig(modelConfig);
entity.setPath(currentPath); entity.setPath(currentPath);
@@ -116,20 +116,20 @@ public class GeneratorMain {
public static void generateFromFolder(String currentPath, File folder, boolean root) { public static void generateFromFolder(String currentPath, File folder, boolean root) {
if (folder.listFiles() == null) { if (folder.listFiles() == null) return;
return;
}
String modelId = root ? "" : folder.getName().toLowerCase(); String modelId = root ? "" : folder.getName().toLowerCase();
Entity entity = new Entity(modelId); Entity entity = new Entity(modelId);
ModelConfig modelConfig = new ModelConfig(); ModelConfig modelConfig = new ModelConfig();
boolean shouldOverrideConfig = false; boolean shouldOverrideConfig = false;
File textureConfigFile = new File(folder, "config.json"); File textureConfigFile = new File(folder, "config.json");
if (textureConfigFile.exists()) { if (textureConfigFile.exists()) {
try { try {
modelConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), ModelConfig.class); modelConfig = GSON.fromJson(Files.readString(textureConfigFile.toPath()), ModelConfig.class);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
boolean canAdd = false; boolean canAdd = false;
@@ -140,33 +140,33 @@ public class GeneratorMain {
if (e.getName().endsWith(".zip")) { if (e.getName().endsWith(".zip")) {
try { try {
generateFromZip(currentPath, e.getName().replace(".zip", "").toLowerCase(Locale.ROOT), new ZipFile(e)); generateFromZip(currentPath, e.getName().replace(".zip", "").toLowerCase(Locale.ROOT), new ZipFile(e));
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
} }
if (entityMap.containsKey(modelId)) {
continue; if (entityMap.containsKey(modelId)) continue;
}
if (e.getName().endsWith(".png")) { if (e.getName().endsWith(".png")) {
String textureName = e.getName().replace(".png", ""); String textureName = e.getName().replace(".png", "");
Set<String> bindingBones = new HashSet<>(); Set<String> bindingBones = new HashSet<>();
bindingBones.add("*"); bindingBones.add("*");
if (modelConfig.getBingingBones().containsKey(textureName)) { if (modelConfig.getBingingBones().containsKey(textureName)) bindingBones = modelConfig.getBingingBones().get(textureName);
bindingBones = modelConfig.getBingingBones().get(textureName);
}
Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>()); Map<String, Texture> map = textureMap.computeIfAbsent(modelId, s -> new HashMap<>());
try { try {
map.put(textureName, new Texture(modelId, currentPath, bindingBones, Files.readAllBytes(e.toPath()))); map.put(textureName, new Texture(modelId, currentPath, bindingBones, Files.readAllBytes(e.toPath())));
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
entity.setTextureMap(map); entity.setTextureMap(map);
if (modelConfig.getBingingBones().isEmpty()) { if (modelConfig.getBingingBones().isEmpty()) {
modelConfig.getBingingBones().put(textureName, Set.of("*")); modelConfig.getBingingBones().put(textureName, Set.of("*"));
shouldOverrideConfig = true; shouldOverrideConfig = true;
} }
} }
if (e.getName().endsWith(".json")) { if (e.getName().endsWith(".json")) {
try { try {
String json = Files.readString(e.toPath()); String json = Files.readString(e.toPath());
@@ -189,11 +189,12 @@ public class GeneratorMain {
entity.setGeometry(geometry); entity.setGeometry(geometry);
canAdd = true; canAdd = true;
} }
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
} }
} }
if (canAdd) { if (canAdd) {
// old config // old config
File oldConfig = new File(folder, "config.properties"); File oldConfig = new File(folder, "config.properties");
@@ -208,16 +209,18 @@ public class GeneratorMain {
oldConfig.delete(); oldConfig.delete();
} }
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
if (shouldOverrideConfig) { if (shouldOverrideConfig) {
try { try {
Files.writeString(textureConfigFile.toPath(), GSON.toJson(modelConfig)); Files.writeString(textureConfigFile.toPath(), GSON.toJson(modelConfig));
} catch (IOException ex) { } catch (IOException err) {
ex.printStackTrace(); throw new RuntimeException(err);
} }
} }
entity.setModelConfig(modelConfig); entity.setModelConfig(modelConfig);
entity.setPath(currentPath); entity.setPath(currentPath);
entityMap.put(modelId, entity); entityMap.put(modelId, entity);
@@ -237,14 +240,13 @@ public class GeneratorMain {
File manifestFile = new File(output, "manifest.json"); File manifestFile = new File(output, "manifest.json");
output.mkdirs(); output.mkdirs();
if (!manifestFile.exists()) { if (!manifestFile.exists()) {
try { try {
Files.writeString(manifestFile.toPath(), Files.writeString(manifestFile.toPath(),
PackManifest.generate(), StandardCharsets.UTF_8); PackManifest.generate(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
@@ -263,8 +265,8 @@ public class GeneratorMain {
try { try {
Files.writeString(materialFile.toPath(), Files.writeString(materialFile.toPath(),
Material.TEMPLATE, StandardCharsets.UTF_8); Material.TEMPLATE, StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
@@ -280,9 +282,7 @@ public class GeneratorMain {
pathController.toFile().getParentFile().mkdirs(); pathController.toFile().getParentFile().mkdirs();
path.toFile().getParentFile().mkdirs(); path.toFile().getParentFile().mkdirs();
if (path.toFile().exists()) { if (path.toFile().exists()) continue;
continue;
}
AnimationController controller = new AnimationController(); AnimationController controller = new AnimationController();
controller.load(entry.getValue(), entity); controller.load(entry.getValue(), entity);
@@ -290,8 +290,8 @@ public class GeneratorMain {
try { try {
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8); Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
Files.writeString(pathController, controller.getJson().toString(), StandardCharsets.UTF_8); Files.writeString(pathController, controller.getJson().toString(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
@@ -322,22 +322,20 @@ public class GeneratorMain {
try { try {
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8); Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
} }
} }
if (path.toFile().exists()) { if (path.toFile().exists()) continue;
continue;
}
try { try {
Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8); Files.writeString(path, GSON.toJson(entry.getValue().getJson()), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
@@ -354,8 +352,8 @@ public class GeneratorMain {
if (entry.getValue().getImage() != null) { if (entry.getValue().getImage() != null) {
Files.write(path, entry.getValue().getImage()); Files.write(path, entry.getValue().getImage());
} }
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
} }
@@ -366,13 +364,13 @@ public class GeneratorMain {
Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json"); Path entityPath = entityFolder.toPath().resolve(entity.getPath() + entry.getKey() + ".entity.json");
entityPath.toFile().getParentFile().mkdirs(); entityPath.toFile().getParentFile().mkdirs();
if (entityPath.toFile().exists()) {
continue; if (entityPath.toFile().exists()) continue;
}
try { try {
Files.writeString(entityPath, entity.getJson().toString(), StandardCharsets.UTF_8); Files.writeString(entityPath, entity.getJson().toString(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
// render controller part // render controller part
@@ -387,8 +385,8 @@ public class GeneratorMain {
} }
try { try {
Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8); Files.writeString(renderPath, controller.generate(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
} }
@@ -407,18 +405,17 @@ public class GeneratorMain {
private static boolean isGeometryFile(String json) { private static boolean isGeometryFile(String json) {
try { try {
return new JsonParser().parse(json).getAsJsonObject().has("minecraft:geometry"); return JsonParser.parseString(json).getAsJsonObject().has("minecraft:geometry");
} catch (Throwable e) { } catch (Throwable ignored) {
return false; return false;
} }
} }
private static boolean isAnimationFile(String json) { private static boolean isAnimationFile(String json) {
try { try {
return new JsonParser().parse(json).getAsJsonObject().has("animations"); return JsonParser.parseString(json).getAsJsonObject().has("animations");
} catch (Throwable e) { } catch (Throwable ignored) {
return false; return false;
} }
} }
} }

View File

@@ -1,43 +1,43 @@
package re.imc.geysermodelenginepackgenerator; package re.imc.geysermodelenginepackgenerator;
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.subscribe.Subscribe; import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandExecutor;
import org.geysermc.geyser.api.command.CommandSource; import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserLoadResourcePacksEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineResourcePacksEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.extension.Extension;
import org.geysermc.geyser.api.extension.ExtensionLogger; import org.geysermc.geyser.api.pack.PackCodec;
import org.geysermc.geyser.api.pack.ResourcePack;
import re.imc.geysermodelenginepackgenerator.managers.ConfigManager;
import re.imc.geysermodelenginepackgenerator.generator.Entity; import re.imc.geysermodelenginepackgenerator.generator.Entity;
import re.imc.geysermodelenginepackgenerator.generator.Geometry;
import re.imc.geysermodelenginepackgenerator.util.ZipUtil; import re.imc.geysermodelenginepackgenerator.util.ZipUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
public class ExtensionMain implements Extension { public class GeyserModelEnginePackGenerator implements Extension {
private static GeyserModelEnginePackGenerator extension;
private File source; private File source;
public static ExtensionLogger logger; private Path generatedPackZip;
Path generatedPackZip;
private ConfigManager configManager;
@Subscribe @Subscribe
public void onLoad(GeyserPreInitializeEvent event) { public void onLoad(GeyserPreInitializeEvent event) {
extension = this;
loadManagers();
source = dataFolder().resolve("input").toFile(); source = dataFolder().resolve("input").toFile();
source.mkdirs(); source.mkdirs();
logger = logger();
loadConfig(); loadConfig();
} }
@Subscribe @Subscribe
@@ -45,9 +45,8 @@ public class ExtensionMain implements Extension {
event.register(Command.builder(this) event.register(Command.builder(this)
.name("reload") .name("reload")
.source(CommandSource.class) .source(CommandSource.class)
.executableOnConsole(true) .playerOnly(false)
.description("GeyserModelPackGenerator Reload Command") .description("GeyserModelPackGenerator Reload Command")
.suggestedOpOnly(true)
.permission("geysermodelenginepackgenerator.admin") .permission("geysermodelenginepackgenerator.admin")
.executor((source, command, args) -> { .executor((source, command, args) -> {
loadConfig(); loadConfig();
@@ -57,7 +56,6 @@ public class ExtensionMain implements Extension {
} }
public void loadConfig() { public void loadConfig() {
File generatedPack = dataFolder().resolve("generated_pack").toFile(); File generatedPack = dataFolder().resolve("generated_pack").toFile();
GeneratorMain.startGenerate(source, generatedPack); GeneratorMain.startGenerate(source, generatedPack);
@@ -66,23 +64,28 @@ public class ExtensionMain implements Extension {
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) { try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) {
ZipUtil.compressFolder(generatedPack, null, zipOutputStream); ZipUtil.compressFolder(generatedPack, null, zipOutputStream);
} catch (IOException e) { } catch (IOException err) {
e.printStackTrace(); throw new RuntimeException(err);
} }
for (Entity entity : GeneratorMain.entityMap.values()) { for (Entity entity : GeneratorMain.entityMap.values()) {
entity.register(); entity.register();
} }
} }
private void loadManagers() {
this.configManager = new ConfigManager();
}
@Subscribe @Subscribe
public void onPackLoad(GeyserLoadResourcePacksEvent event) { public void onPackLoad(GeyserDefineResourcePacksEvent event) {
if (Boolean.parseBoolean(System.getProperty("geyser-model-engine-auto-load-pack", "true"))) { if (!configManager.getConfig().getBoolean("options.resource-pack.auto-load")) return;
event.resourcePacks().add(generatedPackZip);
} ResourcePack resourcePack = ResourcePack.builder(PackCodec.path(generatedPackZip)).build();
event.register(resourcePack);
} }
public static GeyserModelEnginePackGenerator getExtension() {
return extension;
}
} }

View File

@@ -4,20 +4,12 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import re.imc.geysermodelenginepackgenerator.GeneratorMain; import re.imc.geysermodelenginepackgenerator.GeneratorMain;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Animation { public class Animation {
public static final String HEAD_TEMPLATE = """ public static final String HEAD_TEMPLATE = """
@@ -29,16 +21,16 @@ public class Animation {
} }
"""; """;
String modelId; private String modelId;
JsonObject json; private JsonObject json;
@Getter private Set<String> animationIds = new HashSet<>();
Set<String> animationIds = new HashSet<>();
String path; private String path;
public void load(String string) { public void load(String string) {
this.json = new JsonParser().parse(string).getAsJsonObject(); this.json = JsonParser.parseString(string).getAsJsonObject();
JsonObject newAnimations = new JsonObject(); JsonObject newAnimations = new JsonObject();
for (Map.Entry<String, JsonElement> element : json.get("animations").getAsJsonObject().entrySet()) { for (Map.Entry<String, JsonElement> element : json.get("animations").getAsJsonObject().entrySet()) {
animationIds.add(element.getKey()); animationIds.add(element.getKey());
JsonObject animation = element.getValue().getAsJsonObject(); JsonObject animation = element.getValue().getAsJsonObject();
@@ -77,7 +69,7 @@ public class Animation {
} }
} }
} }
} catch (Throwable t) {} } catch (Throwable ignored) {}
if (end != null && end.has("lerp_mode") && end.get("lerp_mode").getAsString().equals("catmullrom")) { if (end != null && end.has("lerp_mode") && end.get("lerp_mode").getAsString().equals("catmullrom")) {
end.addProperty("lerp_mode", "linear"); end.addProperty("lerp_mode", "linear");
} }
@@ -98,31 +90,61 @@ public class Animation {
object.addProperty("loop", true); object.addProperty("loop", true);
JsonObject bones = new JsonObject(); JsonObject bones = new JsonObject();
JsonArray array = geometry.getInternal().get("bones").getAsJsonArray(); JsonArray array = geometry.getInternal().get("bones").getAsJsonArray();
int i = 0; int i = 0;
for (JsonElement element : array) { for (JsonElement element : array) {
if (element.isJsonObject()) { if (element.isJsonObject()) {
String name = element.getAsJsonObject().get("name").getAsString(); String name = element.getAsJsonObject().get("name").getAsString();
String parent = ""; String parent = "";
if (element.getAsJsonObject().has("parent")) { if (element.getAsJsonObject().has("parent")) parent = element.getAsJsonObject().get("parent").getAsString();
parent = element.getAsJsonObject().get("parent").getAsString(); if (parent.startsWith("h_") || parent.startsWith("hi_")) continue;
}
if (parent.startsWith("h_") || parent.startsWith("hi_")) {
continue;
}
if (name.startsWith("h_") || name.startsWith("hi_")) { if (name.startsWith("h_") || name.startsWith("hi_")) {
bones.add(name, new JsonParser().parse(HEAD_TEMPLATE)); bones.add(name, JsonParser.parseString(HEAD_TEMPLATE));
i++; i++;
} }
} }
} }
if (i == 0) {
return; if (i == 0) return;
}
GeneratorMain.entityMap GeneratorMain.entityMap.get(modelId).setHasHeadAnimation(true);
.get(modelId).setHasHeadAnimation(true);
object.add("bones", bones); object.add("bones", bones);
json.get("animations").getAsJsonObject().add("animation." + modelId + ".look_at_target", object); json.get("animations").getAsJsonObject().add("animation." + modelId + ".look_at_target", object);
} }
public void setModelId(String modelId) {
this.modelId = modelId;
}
public void setJson(JsonObject json) {
this.json = json;
}
public void setAnimationIds(Set<String> animationIds) {
this.animationIds = animationIds;
}
public String getModelId() {
return modelId;
}
public void setPath(String path) {
this.path = path;
}
public JsonObject getJson() {
return json;
}
public Set<String> getAnimationIds() {
return animationIds;
}
public String getPath() {
return path;
}
} }

View File

@@ -30,13 +30,11 @@ public class AnimationController {
"transitions": [{ "play": "%query% != 0"}] "transitions": [{ "play": "%query% != 0"}]
} }
} }
}"""; }
""";
@Getter private JsonObject json;
JsonObject json; private Entity entity;
@Setter
@Getter
Entity entity;
public void load(Animation animation, Entity entity) { public void load(Animation animation, Entity entity) {
JsonObject root = new JsonObject(); JsonObject root = new JsonObject();
@@ -46,18 +44,19 @@ public class AnimationController {
JsonObject animationControllers = new JsonObject(); JsonObject animationControllers = new JsonObject();
root.add("animation_controllers", animationControllers); root.add("animation_controllers", animationControllers);
List<String> sorted = new ArrayList<>(animation.animationIds); List<String> sorted = new ArrayList<>(animation.getAnimationIds());
int i = 0; int i = 0;
Collections.sort(sorted); Collections.sort(sorted);
for (String id : sorted) { for (String id : sorted) {
id = id.replace(" ", "_"); id = id.replace(" ", "_");
int n = (int) Math.pow(2, (i % 24)); int n = (int) Math.pow(2, (i % 24));
JsonObject controller = new JsonParser().parse(CONTROLLER_TEMPLATE.replace("%anim%", id).replace("%query%", "math.mod(math.floor(query.property('modelengine:anim" + i / 24 + "') / " + n + "), 2)")).getAsJsonObject(); JsonObject controller = JsonParser.parseString(CONTROLLER_TEMPLATE.replace("%anim%", id).replace("%query%", "math.mod(math.floor(query.property('modelengine:anim" + i / 24 + "') / " + n + "), 2)")).getAsJsonObject();
animationControllers.add("controller.animation." + animation.modelId + "." + id, controller); animationControllers.add("controller.animation." + animation.getModelId() + "." + id, controller);
i++; i++;
if (entity != null) { if (entity != null) {
boolean blend = entity.getModelConfig().isEnableBlendTransition(); boolean blend = entity.getModelConfig().isEnableBlendTransition();
if (!blend) { if (!blend) {
for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) { for (Map.Entry<String, JsonElement> states : controller.get("states").getAsJsonObject().entrySet()) {
states.getValue().getAsJsonObject().remove("blend_transition"); states.getValue().getAsJsonObject().remove("blend_transition");
@@ -137,4 +136,20 @@ public class AnimationController {
}"""; }""";
*/ */
public void setJson(JsonObject json) {
this.json = json;
}
public void setEntity(Entity entity) {
this.entity = entity;
}
public JsonObject getJson() {
return json;
}
public Entity getEntity() {
return entity;
}
} }

View File

@@ -1,23 +1,34 @@
package re.imc.geysermodelenginepackgenerator.generator; package re.imc.geysermodelenginepackgenerator.generator;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class Bone { public class Bone {
String name;
String parent; private final String name;
Set<Bone> children = new HashSet<>(); private final String parent;
Set<Bone> allChildren = new HashSet<>(); private final Set<Bone> children;
private final Set<Bone> allChildren;
public Bone(String name, String parent, Set<Bone> children, Set<Bone> allChildren) {
this.name = name;
this.parent = parent;
this.children = children;
this.allChildren = allChildren;
}
public String getName() {
return name;
}
public String getParent() {
return parent;
}
public Set<Bone> getChildren() {
return children;
}
public Set<Bone> getAllChildren() {
return allChildren;
}
} }

View File

@@ -11,14 +11,20 @@ import me.zimzaza4.geyserutils.geyser.GeyserUtils;
import java.util.*; import java.util.*;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Entity { public class Entity {
public static final Set<String> REGISTERED_ENTITIES = new HashSet<>(); public static final Set<String> REGISTERED_ENTITIES = new HashSet<>();
private String modelId;
private JsonObject json;
private boolean hasHeadAnimation = false;
private Animation animation;
private Geometry geometry;
private RenderController renderController;
private String path;
private Map<String, Texture> textureMap = new HashMap<>();
private ModelConfig modelConfig;
public static final String TEMPLATE = """ public static final String TEMPLATE = """
{ {
"format_version": "1.10.0", "format_version": "1.10.0",
@@ -49,28 +55,12 @@ public class Entity {
} }
"""; """;
String modelId;
JsonObject json;
boolean hasHeadAnimation = false;
Animation animation;
Geometry geometry;
RenderController renderController;
String path;
Map<String, Texture> textureMap = new HashMap<>();
ModelConfig modelConfig;
public Entity(String modelId) { public Entity(String modelId) {
this.modelId = modelId; this.modelId = modelId;
} }
public void modify() { public void modify() {
this.json = JsonParser.parseString(TEMPLATE.replace("%entity_id%", modelId)
json = new JsonParser().parse(TEMPLATE.replace("%entity_id%", modelId)
.replace("%geometry%", "geometry.meg_" + modelId) .replace("%geometry%", "geometry.meg_" + modelId)
.replace("%texture%", "textures/entity/" + path + modelId) .replace("%texture%", "textures/entity/" + path + modelId)
.replace("%look_at_target%", modelConfig.isEnableHeadRotation() ? "animation." + modelId + ".look_at_target" : "animation.none") .replace("%look_at_target%", modelConfig.isEnableHeadRotation() ? "animation." + modelId + ".look_at_target" : "animation.none")
@@ -84,7 +74,7 @@ public class Entity {
JsonArray jsonRenderControllers = description.get("render_controllers").getAsJsonArray(); JsonArray jsonRenderControllers = description.get("render_controllers").getAsJsonArray();
Map<String, String> materials = getModelConfig().getTextureMaterials(); Map<String, String> materials = modelConfig.getTextureMaterials();
materials.forEach(jsonMaterials::addProperty); materials.forEach(jsonMaterials::addProperty);
if (modelConfig.getPerTextureUvSize().isEmpty()) { if (modelConfig.getPerTextureUvSize().isEmpty()) {
@@ -93,9 +83,8 @@ public class Entity {
} }
for (String name : textureMap.keySet()) { for (String name : textureMap.keySet()) {
if (name.endsWith("_e")) { if (name.endsWith("_e")) continue;
continue;
}
if (modelConfig.getPerTextureUvSize().containsKey(name)) { if (modelConfig.getPerTextureUvSize().containsKey(name)) {
Integer[] size = modelConfig.getPerTextureUvSize().getOrDefault(name, new Integer[]{16, 16}); Integer[] size = modelConfig.getPerTextureUvSize().getOrDefault(name, new Integer[]{16, 16});
String suffix = size[0] + "_" + size[1]; String suffix = size[0] + "_" + size[1];
@@ -104,14 +93,14 @@ public class Entity {
jsonTextures.addProperty(name, "textures/entity/" + path + modelId + "/" + name); jsonTextures.addProperty(name, "textures/entity/" + path + modelId + "/" + name);
} }
jsonRenderControllers.add("controller.render." + modelId + "_" + name);
jsonRenderControllers.add("controller.render." + modelId + "_" + name);
} }
JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray(); JsonArray animate = description.get("scripts").getAsJsonObject().get("animate").getAsJsonArray();
if (animation != null) { if (animation != null) {
for (String animation : animation.animationIds) { for (String animation : animation.getAnimationIds()) {
animation = animation.replace(" ", "_"); animation = animation.replace(" ", "_");
String controller = "controller.animation." + modelId + "." + animation; String controller = "controller.animation." + modelId + "." + animation;
animate.add(animation + "_control"); animate.add(animation + "_control");
@@ -122,19 +111,14 @@ public class Entity {
} }
public void register() { public void register() {
String id = "modelengine:" + modelId; String id = "modelengine:" + modelId;
boolean registered = REGISTERED_ENTITIES.contains(id); boolean registered = REGISTERED_ENTITIES.contains(id);
if (registered) { if (registered) return;
return;
}
REGISTERED_ENTITIES.add(id); REGISTERED_ENTITIES.add(id);
GeyserUtils.addCustomEntity(id); GeyserUtils.addCustomEntity(id);
if (geometry == null) { if (geometry == null) return;
return;
}
if (!modelConfig.isDisablePartVisibility()) { if (!modelConfig.isDisablePartVisibility()) {
for (int i = 0; i < Math.ceil(geometry.getBones().size() / 24f); i++) { for (int i = 0; i < Math.ceil(geometry.getBones().size() / 24f); i++) {
GeyserUtils.addProperty(id, "modelengine:bone" + i, Integer.class); GeyserUtils.addProperty(id, "modelengine:bone" + i, Integer.class);
@@ -142,10 +126,83 @@ public class Entity {
} }
if (animation != null) { if (animation != null) {
for (int i = 0; i < Math.ceil(animation.animationIds.size() / 24f); i++) { for (int i = 0; i < Math.ceil(animation.getAnimationIds().size() / 24f); i++) {
GeyserUtils.addProperty(id, "modelengine:anim" + i, Integer.class); GeyserUtils.addProperty(id, "modelengine:anim" + i, Integer.class);
} }
} }
GeyserUtils.registerProperties(id); GeyserUtils.registerProperties(id);
} }
public void setModelId(String modelId) {
this.modelId = modelId;
}
public void setJson(JsonObject json) {
this.json = json;
}
public void setHasHeadAnimation(boolean hasHeadAnimation) {
this.hasHeadAnimation = hasHeadAnimation;
}
public void setAnimation(Animation animation) {
this.animation = animation;
}
public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}
public void setRenderController(RenderController renderController) {
this.renderController = renderController;
}
public void setPath(String path) {
this.path = path;
}
public void setTextureMap(Map<String, Texture> textureMap) {
this.textureMap = textureMap;
}
public void setModelConfig(ModelConfig modelConfig) {
this.modelConfig = modelConfig;
}
public String getModelId() {
return modelId;
}
public JsonObject getJson() {
return json;
}
public boolean isHasHeadAnimation() {
return hasHeadAnimation;
}
public Animation getAnimation() {
return animation;
}
public Geometry getGeometry() {
return geometry;
}
public RenderController getRenderController() {
return renderController;
}
public String getPath() {
return path;
}
public Map<String, Texture> getTextureMap() {
return textureMap;
}
public ModelConfig getModelConfig() {
return modelConfig;
}
} }

View File

@@ -5,26 +5,20 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.geysermc.geyser.api.extension.ExtensionLogger;
import re.imc.geysermodelenginepackgenerator.ExtensionMain;
import java.util.*; import java.util.*;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Geometry { public class Geometry {
private String modelId;
private String geometryId;
private JsonObject json;
private Map<String, Bone> bones = new HashMap<>();
String modelId; private String path;
String geometryId;
JsonObject json;
Map<String, Bone> bones = new HashMap<>();
String path;
public void load(String json) { public void load(String json) {
this.json = new JsonParser().parse(json).getAsJsonObject(); this.json = JsonParser.parseString(json).getAsJsonObject();
} }
public void setId(String id) { public void setId(String id) {
geometryId = id; geometryId = id;
@@ -45,7 +39,6 @@ public class Geometry {
} }
public void modify() { public void modify() {
JsonArray array = getInternal().get("bones").getAsJsonArray(); JsonArray array = getInternal().get("bones").getAsJsonArray();
Iterator<JsonElement> iterator = array.iterator(); Iterator<JsonElement> iterator = array.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@@ -55,23 +48,20 @@ public class Geometry {
String parent = element.getAsJsonObject().has("parent") ? element.getAsJsonObject().get("parent").getAsString().toLowerCase() : null; String parent = element.getAsJsonObject().has("parent") ? element.getAsJsonObject().get("parent").getAsString().toLowerCase() : null;
element.getAsJsonObject().remove("name"); element.getAsJsonObject().remove("name");
element.getAsJsonObject().addProperty("name", name); element.getAsJsonObject().addProperty("name", name);
if (name.equals("hitbox") || if (name.equals("hitbox") || name.equals("shadow") || name.equals("mount") || name.startsWith("b_") || name.startsWith("ob_")) {
name.equals("shadow") ||
name.equals("mount") ||
name.startsWith("b_") ||
name.startsWith("ob_")) {
iterator.remove(); iterator.remove();
} else bones.put(name, new Bone(name, parent, new HashSet<>(), new HashSet<>())); } else {
bones.put(name, new Bone(name, parent, new HashSet<>(), new HashSet<>()));
}
} }
for (Bone bone : bones.values()) { for (Bone bone : bones.values()) {
if (bone.parent != null) { if (bone.getParent() != null) {
Bone parent = bones.get(bone.parent); Bone parent = bones.get(bone.getParent());
if (parent != null) { if (parent != null) {
parent.children.add(bone); parent.getChildren().add(bone);
addAllChildren(parent, bone); addAllChildren(parent, bone);
} }
} }
@@ -81,10 +71,46 @@ public class Geometry {
} }
public void addAllChildren(Bone p, Bone c) { public void addAllChildren(Bone p, Bone c) {
p.allChildren.add(c); p.getAllChildren().add(c);
Bone parent = bones.get(p.parent); Bone parent = bones.get(p.getParent());
if (parent != null) { if (parent != null) {
addAllChildren(parent, c); addAllChildren(parent, c);
} }
} }
public void setModelId(String modelId) {
this.modelId = modelId;
}
public void setGeometryId(String geometryId) {
this.geometryId = geometryId;
}
public void setJson(JsonObject json) {
this.json = json;
}
public void setPath(String path) {
this.path = path;
}
public String getModelId() {
return modelId;
}
public String getGeometryId() {
return geometryId;
}
public JsonObject getJson() {
return json;
}
public String getPath() {
return path;
}
public Map<String, Bone> getBones() {
return bones;
}
} }

View File

@@ -9,8 +9,6 @@ import java.util.Set;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Getter
@Setter
@ToString @ToString
public class ModelConfig { public class ModelConfig {
@@ -31,6 +29,38 @@ public class ModelConfig {
@SerializedName("disable_part_visibility") @SerializedName("disable_part_visibility")
boolean disablePartVisibility = true; boolean disablePartVisibility = true;
public void setEnableHeadRotation(boolean enableHeadRotation) {
this.enableHeadRotation = enableHeadRotation;
}
public void setMaterial(String material) {
this.material = material;
}
public void setEnableBlendTransition(boolean enableBlendTransition) {
this.enableBlendTransition = enableBlendTransition;
}
public void setBingingBones(Map<String, Set<String>> bingingBones) {
this.bingingBones = bingingBones;
}
public void setAnimTextures(Map<String, AnimTextureOptions> animTextures) {
this.animTextures = animTextures;
}
public void setTextureMaterials(Map<String, String> textureMaterials) {
this.textureMaterials = textureMaterials;
}
public void setPerTextureUvSize(Map<String, Integer[]> perTextureUvSize) {
this.perTextureUvSize = perTextureUvSize;
}
public void setDisablePartVisibility(boolean disablePartVisibility) {
this.disablePartVisibility = disablePartVisibility;
}
public Map<String, String> getTextureMaterials() { public Map<String, String> getTextureMaterials() {
return textureMaterials != null ? textureMaterials : Map.of(); return textureMaterials != null ? textureMaterials : Map.of();
} }
@@ -39,6 +69,30 @@ public class ModelConfig {
return perTextureUvSize != null ? perTextureUvSize : Map.of(); return perTextureUvSize != null ? perTextureUvSize : Map.of();
} }
public boolean isEnableHeadRotation() {
return enableHeadRotation;
}
public String getMaterial() {
return material;
}
public boolean isEnableBlendTransition() {
return enableBlendTransition;
}
public Map<String, Set<String>> getBingingBones() {
return bingingBones;
}
public Map<String, AnimTextureOptions> getAnimTextures() {
return animTextures;
}
public boolean isDisablePartVisibility() {
return disablePartVisibility;
}
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter

View File

@@ -3,6 +3,7 @@ package re.imc.geysermodelenginepackgenerator.generator;
import java.util.UUID; import java.util.UUID;
public class PackManifest { public class PackManifest {
public static final String TEMPLATE = """ public static final String TEMPLATE = """
{ {
"format_version": 1, "format_version": 1,

View File

@@ -29,11 +29,10 @@ public class RenderController {
root.add("render_controllers", renderControllers); root.add("render_controllers", renderControllers);
Set<Bone> processedBones = new HashSet<>(); Set<Bone> processedBones = new HashSet<>();
boolean singleTexture = entity.textureMap.size() == 1 && entity.modelConfig.getPerTextureUvSize().isEmpty(); boolean singleTexture = entity.getTextureMap().size() == 1 && entity.getModelConfig().getPerTextureUvSize().isEmpty();
for (String key : entity.textureMap.keySet()) { for (String key : entity.getTextureMap().keySet()) {
if (key.endsWith("_e")) { if (key.endsWith("_e")) continue;
continue;
}
// Texture texture = entity.textureMap.get(key); // Texture texture = entity.textureMap.get(key);
Set<String> uvBonesId = entity.getModelConfig().bingingBones.get(key); Set<String> uvBonesId = entity.getModelConfig().bingingBones.get(key);
@@ -149,11 +148,11 @@ public class RenderController {
if (!processedBones.contains(bone) && (uvParent || uvAllBones.contains(boneName) || uvBonesId.contains("*"))) { if (!processedBones.contains(bone) && (uvParent || uvAllBones.contains(boneName) || uvBonesId.contains("*"))) {
int index = i; int index = i;
if (boneName.startsWith("uv_")) { if (boneName.startsWith("uv_")) {
index = sorted.indexOf(bone.parent); index = sorted.indexOf(bone.getParent());
} }
int n = (int) Math.pow(2, (index % 24)); int n = (int) Math.pow(2, (index % 24));
if (entity.modelConfig.isDisablePartVisibility()) { if (entity.getModelConfig().isDisablePartVisibility()) {
visibilityItem.addProperty(boneName, true); visibilityItem.addProperty(boneName, true);
} else { } else {
visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + index / 24 + "') / " + n + "), 2) == 1"); visibilityItem.addProperty(boneName, "math.mod(math.floor(query.property('modelengine:bone" + index / 24 + "') / " + n + "), 2) == 1");

View File

@@ -1,22 +1,34 @@
package re.imc.geysermodelenginepackgenerator.generator; package re.imc.geysermodelenginepackgenerator.generator;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.util.Set; import java.util.Set;
@Getter
@Setter
@AllArgsConstructor
public class Texture { public class Texture {
String modelId; private final String modelId;
String path; private final String path;
Set<String> bindingBones; private final Set<String> bindingBones;
byte[] image; private final byte[] image;
public Texture(String modelId, String path, Set<String> bindingBones, byte[] image) {
this.modelId = modelId;
this.path = path;
this.bindingBones = bindingBones;
this.image = image;
}
public String getModelId() {
return modelId;
}
public String getPath() {
return path;
}
public Set<String> getBindingBones() {
return bindingBones;
}
public byte[] getImage() {
return image;
}
} }

View File

@@ -0,0 +1,20 @@
package re.imc.geysermodelenginepackgenerator.managers;
import re.imc.geysermodelenginepackgenerator.util.FileConfiguration;
public class ConfigManager {
private FileConfiguration config;
public ConfigManager() {
load();
}
public void load() {
this.config = new FileConfiguration("config.yml");
}
public FileConfiguration getConfig() {
return config;
}
}

View File

@@ -0,0 +1,148 @@
package re.imc.geysermodelenginepackgenerator.util;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import re.imc.geysermodelenginepackgenerator.GeyserModelEnginePackGenerator;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class FileConfiguration {
private final GeyserModelEnginePackGenerator extension = GeyserModelEnginePackGenerator.getExtension();
private final Path dataDirectory = extension.dataFolder();
protected final String configFile;
private final CommentedConfigurationNode configurationNode;
public FileConfiguration(String configFile) {
this.configFile = configFile;
this.configurationNode = load(configFile);
}
public FileConfiguration(CommentedConfigurationNode configurationNode, String configFile) {
this.configFile = configFile;
this.configurationNode = configurationNode;
}
private CommentedConfigurationNode load(String fileName) {
try {
if (!Files.exists(this.dataDirectory)) Files.createDirectories(this.dataDirectory);
Path config = this.dataDirectory.resolve(fileName);
if (!Files.exists(config)) {
try (InputStream resourceAsStream = this.extension.getClass().getClassLoader().getResourceAsStream("Extension/" + fileName)) {
Files.copy(resourceAsStream, config);
} catch (IOException err) {
throw new RuntimeException(err);
}
}
YamlConfigurationLoader loader = YamlConfigurationLoader.builder().path(config).build();
return loader.load();
} catch (IOException err) {
throw new RuntimeException(err);
}
}
public FileConfiguration getConfigurationSection(String path) {
CommentedConfigurationNode sectionNode = getConfigurationSectionNode(path);
if (sectionNode == null || sectionNode.virtual()) return null;
return new FileConfiguration(sectionNode, this.configFile);
}
public String getString(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null) return null;
return node.getString();
}
public List<String> getStringList(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null || node.virtual()) return List.of();
try {
return node.getList(String.class, List.of());
} catch (SerializationException err) {
throw new RuntimeException(err);
}
}
public int getInt(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null) return 0;
return node.getInt();
}
public List<Integer> getIntegerList(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null || node.virtual()) return List.of();
try {
return node.getList(Integer.class, List.of());
} catch (SerializationException err) {
throw new RuntimeException(err);
}
}
public double getDouble(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null) return 0;
return node.getDouble();
}
public double getLong(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null) return 0;
return node.getLong();
}
public List<Long> getLongList(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null || node.virtual()) return List.of();
try {
return node.getList(Long.class, List.of());
} catch (SerializationException err) {
throw new RuntimeException(err);
}
}
public boolean getBoolean(String path) {
CommentedConfigurationNode node = getInternal(path);
if (node == null) return false;
return node.getBoolean();
}
public boolean isBoolean(String path) {
CommentedConfigurationNode node = getInternal(path);
return node != null && node.raw() instanceof Boolean;
}
private CommentedConfigurationNode getInternal(String path) {
CommentedConfigurationNode node = toSplitRoot(path, this.configurationNode);
if (node.virtual()) return null;
return node;
}
private CommentedConfigurationNode toSplitRoot(String path, CommentedConfigurationNode node) {
if (path == null) return node;
path = path.startsWith(".") ? path.substring(1) : path;
return node.node(path.contains(".") ? path.split("\\.") : new Object[]{path});
}
private CommentedConfigurationNode getConfigurationSectionNode(String path) {
return getInternal(path);
}
public CommentedConfigurationNode getRootNode() {
return configurationNode;
}
}

View File

@@ -0,0 +1,4 @@
options:
resource-pack:
auto-load: true

View File

@@ -1,6 +1,6 @@
name: GeyserModelEnginePackGenerator name: GeyserModelEnginePackGenerator
id: geysermodelenginepackgenerator id: geysermodelenginepackgenerator
main: re.imc.geysermodelenginepackgenerator.ExtensionMain main: re.imc.geysermodelenginepackgenerator.GeyserModelEnginePackGenerator
api: 1.0.0 api: 2.7.0
version: 1.0.0 version: 1.0.0
authors: [zimzaza4] authors: [zimzaza4]