diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml deleted file mode 100644 index 5593d791..00000000 --- a/.github/workflows/gradle-publish.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java#publishing-using-gradle - -name: Gradle Package - -on: - release: - types: [ created ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - branch: [ 1.7.10-forge, 1.10.2-forge, 1.11.2-forge, 1.12.2-forge, 1.14.4-forge, 1.15.2-forge, 1.16.4-forge ] - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Install deps - run: sudo apt install -y pngquant findutils xvfb - - name: Setup Universal Mod Core (and helpers) - env: - BRANCH: ${{ matrix.branch }} - run: ./gradlew umc -D umc.loader=${BRANCH} -D ssh.http=true -Dtarget=release - - name: Gradle compile - run: ./gradlew classes - - name: Process images - run: find src/main/resources/assets/landofsignals/ | grep png | xargs -I foo pngquant -s1 -f --ext .png foo - - name: Run Data (optionalish) - run: xvfb-run --auto-servernum ./gradlew runData || xvfb-run --auto-servernum ./gradlew runData || true - - name: Gradle build - run: ./gradlew build -Dtarget=release - - - name: Build with Gradle - run: gradle build - - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - run: gradle publish - env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a5f679a..9bf15748 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - branch: [ 1.7.10-forge, 1.10.2-forge, 1.11.2-forge, 1.12.2-forge, 1.14.4-forge, 1.15.2-forge, 1.16.5-forge ] + branch: [ 1.7.10-forge, 1.10.2-forge, 1.11.2-forge, 1.12.2-forge, 1.14.4-forge, 1.15.2-forge, 1.16.5-forge, 1.17.1-forge, 1.18.2-forge, 1.19.4-forge, 1.20.1-forge ] steps: - uses: actions/checkout@v3 @@ -28,16 +28,10 @@ jobs: java-version: '8' - name: Install deps run: sudo apt install -y pngquant findutils xvfb - - name: Hack Forge Gradle - run: mkdir -p ~/.gradle/caches/minecraft/; wget 'https://teamopenindustry.cc/maven/hack/ForgeGradleVersion.json' -O ~/.gradle/caches/minecraft/ForgeGradleVersion.json - name: Setup Universal Mod Core (and helpers) env: BRANCH: ${{ matrix.branch }} - run: ./gradlew umc -D umc.loader=${BRANCH} -D ssh.http=true - - name: Hack Forge Gradle Part Two - env: - BRANCH: ${{ matrix.branch }} - run: git apply --ignore-space-change --ignore-whitespace ${BRANCH}.patch || true + run: java -jar UMCSetup.jar ${BRANCH} https - name: Gradle compile run: ./gradlew classes - name: Process images @@ -46,7 +40,13 @@ jobs: run: xvfb-run --auto-servernum ./gradlew runData || xvfb-run --auto-servernum ./gradlew runData || true - name: Gradle build run: ./gradlew build + - name: Download UMC version used for build + run: | + umc_link=$(./gradlew showBuildInfo | grep "universalmodcore") + wget $umc_link -P build/libs/ - uses: actions/upload-artifact@v3 with: name: LandOfSignals ${{matrix.branch}} - path: build/libs/LandOfSignals-${{matrix.branch}}-* + path: | + build/libs/LandOfSignals-${{matrix.branch}}-* + build/libs/UniversalModCore-* diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8d222e59..96fb1f78 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,8 +30,7 @@ jobs: - name: Replace version number with new version run: | sed -i 's/public static final String VERSION.*/public static final String VERSION = "${{ steps.getversion.outputs.version }}";/' src/main/java/net/landofrails/landofsignals/LandOfSignals.java - sed -i "s/String version =.*/String version = '${{ steps.getversion.outputs.version }}'/" ./build.gradle - sed -i 's/"version":.*/"version": "${{ steps.getversion.outputs.version }}",/' src/main/resources/mcmod.info + sed -i '0,/"version":.*/s//"version": "${{ steps.getversion.outputs.version }}",/' ./umc.json - name: Commit and push changes run: | git config --global user.name "MarkenJaden" @@ -46,7 +45,7 @@ jobs: strategy: max-parallel: 1 matrix: - branch: [ 1.7.10-forge, 1.10.2-forge, 1.11.2-forge, 1.12.2-forge, 1.14.4-forge, 1.15.2-forge, 1.16.5-forge ] + branch: [1.7.10-forge, 1.10.2-forge, 1.11.2-forge, 1.12.2-forge, 1.14.4-forge, 1.15.2-forge, 1.16.5-forge] include: - branch: 1.7.10-forge version: 1.7.10 @@ -71,16 +70,10 @@ jobs: java-version: '8' - name: Install deps run: sudo apt install -y pngquant findutils xvfb - - name: Hack Forge Gradle - run: mkdir -p ~/.gradle/caches/minecraft/; wget 'https://teamopenindustry.cc/maven/hack/ForgeGradleVersion.json' -O ~/.gradle/caches/minecraft/ForgeGradleVersion.json - name: Setup Universal Mod Core (and helpers) env: BRANCH: ${{ matrix.branch }} - run: ./gradlew umc -D umc.loader=${BRANCH} -D ssh.http=true -Dtarget=release - - name: Hack Forge Gradle Part Two - env: - BRANCH: ${{ matrix.branch }} - run: git apply --ignore-space-change --ignore-whitespace ${BRANCH}.patch || true + run: java -jar UMCSetup.jar ${BRANCH} https - name: Gradle compile run: ./gradlew classes - name: Process images diff --git a/.gitignore b/.gitignore index bada34f2..df64f103 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,10 @@ hs_err_pid* .gradle build/ +## Built JARs +*.jar +!UMCSetup.jar + # Ignore Gradle GUI config gradle-app.setting @@ -152,3 +156,10 @@ gradle-app.setting # End of https://www.toptal.com/developers/gitignore/api/intellij+all,java,gradle,forgegradle /bin/ + +## Generated +build.gradle +UMC.md +gradle/wrapper/gradle-wrapper.properties +src/main/java/net/landofrails/landofsignals/Mod.java +src/main/resources/mcmod.info \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8089aa4f..627423f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Fixed [#127] : Magnifyingglass crashes server +### BACKUP YOUR WORLD BEFORE UPDATING! #### Release 1.1.0 Fixed #109 : ContentPackComplexSignal can now be added to a contentpackset @@ -19,8 +20,19 @@ Added #108 : Implemented dynamic scaling (see config) #### Release 1.0.4 +#### Alpha 1.0.4-UMC-testbuild + +Fix crash due to some contentpacks still containing null. Improved logic to prevent this from happening again. Fixed missing logging parameter in ContentPackHandlerV2#load +#### Alpha 1.0.3-UMC-testbuild + +This build is compatible with current UMC testbuilds in combination with Immersive Railroading testbuilds. + +We encourage you to backup your world before updating to this build as it is not excluded that there are still major +bugs in it. Please report any bugs you find to our [issue tracker](https://github.com/LandOfRails/LandOfSignals/issues) +or our [discord](https://discord.gg/ykAqHKYjVM). + #### Release 1.0.3 Fixed #82 | 1.7.10 - 1.16.5:\ diff --git a/README.md b/README.md index a3c85d69..74f6d423 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Adds different signalblocks used in a railway lane plan. Preexisting laneblocks **IntelliJ | Eclipse** 1. Get the project from GitHub (via git) -2. ``gradle umc -D umc.loader=1.12.2-forge`` +2. ``java -jar UMCSetup.jar 1.12.2-forge https`` 3. Load gradle changes You should be ready to go ^^ diff --git a/UMCSetup.jar b/UMCSetup.jar new file mode 100644 index 00000000..b429725d Binary files /dev/null and b/UMCSetup.jar differ diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 01665226..00000000 --- a/build.gradle +++ /dev/null @@ -1,57 +0,0 @@ -buildscript { - repositories { - mavenCentral() - jcenter() - maven { url = 'https://teamopenindustry.cc/maven/' } - } - dependencies { - classpath 'cam72cam.universalmodcore:UniversalModCoreGradle:0.1.3' - } -} - -apply plugin: 'cam72cam.universalmodcore' -apply plugin: 'maven' - -String version = '1.2.0' - -universalmodcore { - modPackage = 'net.landofrails.landofsignals' - modClass = 'LandOfSignals' - modName = 'LandOfSignals' - modId = 'landofsignals' - modVersion = version - umcVersion = '1.1.3' -} - -task('umcIntegration') { - doLast { - String umcLoader = System.getProperty("umc.loader") - } -} - -umc.finalizedBy umcIntegration - -if ((new File('umc.gradle')).exists()) { - apply from: 'umc.gradle' -} - -task deployJar(type: Jar) - -configurations { - deployerJars -} - -dependencies { - deployerJars "org.apache.maven.wagon:wagon-ssh:2.9" -} - -task('showBuildInfo') { - doLast { - String minecraftString = version.split('-')[0] - String minecraftLoader = version.split('-')[1] - String umcVersionString = "${minecraftString}-${minecraftLoader}-${universalmodcore.umcVersion}" - System.out.println("Build for MC ${minecraftString} (${minecraftLoader})") - System.out.println("https://teamopenindustry.cc/maven/cam72cam/immersiverailroading/ImmersiveRailroading/${version}/ImmersiveRailroading-${version}.jar") - System.out.println("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/${umcVersionString}/UniversalModCore-${umcVersionString}.jar") - } -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c0..4bb05789 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 81596154..00000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Fri Nov 16 11:18:00 EST 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip diff --git a/gradlew b/gradlew index 4f906e0c..4453ccea 100755 --- a/gradlew +++ b/gradlew @@ -1,21 +1,5 @@ #!/usr/bin/env sh -# -# Copyright 2015 the original author or 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. -# - ############################################################################## ## ## Gradle start up script for UN*X @@ -44,16 +28,16 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # 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"' +DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn () { +warn ( ) { echo "$*" } -die () { +die ( ) { echo echo "$*" echo @@ -82,7 +66,6 @@ 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 @@ -126,11 +109,10 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -156,30 +138,35 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + i=$((i+1)) done case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args -save () { +save ( ) { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd32..f9553162 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,19 +1,3 @@ -@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 - @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -29,18 +13,15 @@ if "%DIRNAME%" == "" set DIRNAME=. 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" +set DEFAULT_JVM_OPTS= @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +35,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto execute +if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,14 +45,28 @@ echo location of your Java installation. goto fail +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + :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 %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 8fb1c3d1..439012d7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,18 @@ -rootProject.name = 'LandOfSignals' +/* + * This settings file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/3.5.1/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ +rootProject.name = 'LandOfSignals' diff --git a/src/main/java/net/landofrails/api/contentpacks/v2/parent/ContentPackModel.java b/src/main/java/net/landofrails/api/contentpacks/v2/parent/ContentPackModel.java index d761d145..3c8daadf 100644 --- a/src/main/java/net/landofrails/api/contentpacks/v2/parent/ContentPackModel.java +++ b/src/main/java/net/landofrails/api/contentpacks/v2/parent/ContentPackModel.java @@ -72,7 +72,7 @@ public ContentPackModel(float[] blockTranslation, float[] itemTranslation, float public void validate(Consumer modelConsumer, ContentPackReferences references) { if (textures == null) { - textures = references.getTexturesOrElse(texturesRef, null); + textures = references.getTexturesOrElse(texturesRef, ""); } if (obj_groups == null) { obj_groups = references.getObj_groupsOrElse(obj_groupsRef, new String[0]); diff --git a/src/main/java/net/landofrails/api/contentpacks/v2/signal/ContentPackSignal.java b/src/main/java/net/landofrails/api/contentpacks/v2/signal/ContentPackSignal.java index c58c3c9c..11c0ec61 100644 --- a/src/main/java/net/landofrails/api/contentpacks/v2/signal/ContentPackSignal.java +++ b/src/main/java/net/landofrails/api/contentpacks/v2/signal/ContentPackSignal.java @@ -57,6 +57,23 @@ public ContentPackSignal(String name, String id, Float rotationSteps, String cre this.itemScaling = itemScaling; } + public static ContentPackSignal fromJson(InputStream inputStream) { + StringBuilder s = new StringBuilder(); + byte[] buffer = new byte[1024]; + int read; + + try { + while ((read = inputStream.read(buffer, 0, 1024)) >= 0) { + s.append(new String(buffer, 0, read)); + } + } catch (IOException e) { + throw new ContentPackException("Cant read ContentPackSignal: " + e.getMessage()); + } + + String json = s.toString(); + return GSON.fromJson(json, ContentPackSignal.class); + } + public String getName() { return name; } @@ -173,23 +190,6 @@ public String getUniqueId() { return uniqueId; } - public static ContentPackSignal fromJson(InputStream inputStream) { - StringBuilder s = new StringBuilder(); - byte[] buffer = new byte[1024]; - int read; - - try { - while ((read = inputStream.read(buffer, 0, 1024)) >= 0) { - s.append(new String(buffer, 0, read)); - } - } catch (IOException e) { - throw new ContentPackException("Cant read ContentPackSignal: " + e.getMessage()); - } - - String json = s.toString(); - return GSON.fromJson(json, ContentPackSignal.class); - } - public void validate(Consumer invalid, ContentPack contentPack) { defaultMissing(); @@ -221,9 +221,12 @@ public void validate(Consumer invalid, ContentPack contentPack) { private void defaultMissing() { - if (states == null || Arrays.stream(states).noneMatch(Objects::isNull)) { + if (states != null && Arrays.stream(states).anyMatch(Objects::isNull)) { + //Replace null with empty string + states = Arrays.stream(states).map(s -> s == null ? "" : s).toArray(String[]::new); + } else if (states == null || Arrays.stream(states).noneMatch(String::isEmpty)) { String[] tempStates = new String[1 + (this.states != null ? this.states.length : 0)]; - tempStates[0] = null; + tempStates[0] = ""; if (this.states != null && this.states.length > 0) { System.arraycopy(this.states, 0, tempStates, 1, this.states.length); } diff --git a/src/main/java/net/landofrails/landofsignals/LOSBlocks.java b/src/main/java/net/landofrails/landofsignals/LOSBlocks.java index de2c92e8..33cba68d 100644 --- a/src/main/java/net/landofrails/landofsignals/LOSBlocks.java +++ b/src/main/java/net/landofrails/landofsignals/LOSBlocks.java @@ -47,37 +47,37 @@ public static void register() { // loads static classes and ctrs final ContentPackSignalPart MISSING_SIGNAL = new ContentPackSignalPart(Static.MISSING, Static.MISSING_NAME, Static.MISSING_OBJ, new float[]{0.5f, 0.5f, 0.5f}, new float[]{0.5f, 0.5f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null + "" }); registerSignalContentPack(MISSING_SIGNAL); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_sperrsignal_sh0", "Sperrsignal Sh0", "models/block/landofsignals/skyman_luna/sperrsignal_sh0/sperrsignal_sh0.obj", new float[]{0.77f, -1.2f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ "off", "white", - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_vorsignal_base", "Vorsignal Base", "models/block/landofsignals/skyman_luna/vr0_hv_vorsignal/boden/vorsignal_boden.obj", new float[]{0.77f, -1.2f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_mast", "Mast", "models/block/landofsignals/skyman_luna/mast/vorsignal_mast.obj", new float[]{0.77f, -1.2f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_vorsignal_kopf", "Vorsignal Kopf", "models/block/landofsignals/skyman_luna/vr0_hv_vorsignal/kopf/vorsignal_kopf.obj", new float[]{0.77f, -1.2f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null, + "", "off", "green", "greenyellow" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_hauptsignal_base", "Hauptsignal Base", "models/block/landofsignals/skyman_luna/hv_hauptsignal/boden/hauptsignal_boden.obj", new float[]{0.77f, -0.4f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_hauptsignal_schild", "Hauptsignal Schild", "models/block/landofsignals/skyman_luna/hv_hauptsignal/schild/hauptsignal_schild.obj", new float[]{0.77f, -1.2f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_skymanluna_hauptsignal_kopf", "Hauptsignal Kopf", "models/block/landofsignals/skyman_luna/hv_hauptsignal/kopf/hauptsignal_kopf.obj", new float[]{0.77f, -0.4f, 0.77f}, new float[]{0.5f, -0.9f, 0.5f}, new float[]{0.63f, 0.63f, 0.63f}, new String[]{ - null, + "", "off", "zs1", "sh1", @@ -86,19 +86,19 @@ public static void register() { })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_gamertv_base", "Base", "models/block/landofsignals/gamertv/boden/hv_boden.obj", new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_gamertv_mast", "Mast", "models/block/landofsignals/gamertv/mast/hv_mast.obj", new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null + "" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_gamertv_vorsignal", "Vorsignal", "models/block/landofsignals/gamertv/vorsignal/hv_vr.obj", new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null, + "", "off", "gruen", "gruenorange" })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_gamertv_hvhp", "HvHp", "models/block/landofsignals/gamertv/kopf/hv_hp.obj", new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null, + "", "off", "hp1", "hp2", @@ -106,7 +106,7 @@ public static void register() { })); registerSignalContentPack(new ContentPackSignalPart("block_signal_part_gamertv_hversatz", "Hv Ersatz", "models/block/landofsignals/gamertv/ersatzsignal/hv_ersatzsignal.obj", new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new String[]{ - null, + "", "an" })); diff --git a/src/main/java/net/landofrails/landofsignals/LandOfSignals.java b/src/main/java/net/landofrails/landofsignals/LandOfSignals.java index b09fd7de..1420e65b 100644 --- a/src/main/java/net/landofrails/landofsignals/LandOfSignals.java +++ b/src/main/java/net/landofrails/landofsignals/LandOfSignals.java @@ -121,7 +121,7 @@ public void clientEvent(final ModEvent event) { break; case SETUP: - GlobalRender.registerOverlay(pt -> new ManipualtorOverlay().draw()); + GlobalRender.registerOverlay((state, partialticks) -> new ManipualtorOverlay().draw()); if(LandOfSignalsConfig.preloadModels) { ContentPackHandler.preloadModels(); diff --git a/src/main/java/net/landofrails/landofsignals/Mod.java b/src/main/java/net/landofrails/landofsignals/Mod.java deleted file mode 100644 index 2891d7fd..00000000 --- a/src/main/java/net/landofrails/landofsignals/Mod.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.landofrails.landofsignals; - -import cam72cam.mod.ModCore; - -@net.minecraftforge.fml.common.Mod(modid = Mod.MODID, name = "LandOfSignals", version = "1.0.3", dependencies = "required-after:universalmodcore@[1.1,1.2)", acceptedMinecraftVersions = "[1.12,1.13)") -@SuppressWarnings({"java:S112", "java:S1118"}) -public class Mod { - public static final String MODID = "landofsignals"; - - public Mod() { - // maybe needed - } - - static { - try { - ModCore.register(new net.landofrails.landofsignals.LandOfSignals()); - } catch (final Exception e) { - throw new RuntimeException("Could not load mod " + MODID, e); - } - } -} diff --git a/src/main/java/net/landofrails/landofsignals/blocks/BlockSignalPartAnimated.java b/src/main/java/net/landofrails/landofsignals/blocks/BlockSignalPartAnimated.java index ca38bfb8..1b2f57ba 100644 --- a/src/main/java/net/landofrails/landofsignals/blocks/BlockSignalPartAnimated.java +++ b/src/main/java/net/landofrails/landofsignals/blocks/BlockSignalPartAnimated.java @@ -55,7 +55,7 @@ public Vec3d getScaling(final String uncheckedId) { } public List getStates(final String uncheckedId) { - return Collections.singletonList(null); + return Collections.singletonList(""); } public String getId(final String uncheckedId) { diff --git a/src/main/java/net/landofrails/landofsignals/contentpacks/ContentPackHandler.java b/src/main/java/net/landofrails/landofsignals/contentpacks/ContentPackHandler.java index 12590d52..c6069ac6 100644 --- a/src/main/java/net/landofrails/landofsignals/contentpacks/ContentPackHandler.java +++ b/src/main/java/net/landofrails/landofsignals/contentpacks/ContentPackHandler.java @@ -4,7 +4,6 @@ import cam72cam.mod.gui.Progress; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.GenericContentPack; import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalGroup; @@ -159,7 +158,7 @@ public static void preloadModels() { // Cache items try { - ItemSignalPartRender.cache().put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + ItemSignalPartRender.cache().put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { String errmsg = "Couldn't preload item with id \"%s\" (objPath: %s). Cause:"; throw new ContentPackException(String.format(errmsg, id, objPath), e); @@ -167,7 +166,7 @@ public static void preloadModels() { // Cache blocks try { - TileSignalPartRender.cache().put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + TileSignalPartRender.cache().put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { String errmsg = "Couldn't preload block with id \"%s\" (objPath: %s). Cause:"; throw new ContentPackException(String.format(errmsg, id, objPath), e); diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java index 80fc583c..719a9fe9 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxComplexSignal.java @@ -7,7 +7,6 @@ import cam72cam.mod.gui.screen.IScreen; import cam72cam.mod.gui.screen.IScreenBuilder; import cam72cam.mod.item.ItemStack; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.serialization.TagCompound; import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalGroup; import net.landofrails.landofsignals.LOSBlocks; @@ -17,7 +16,7 @@ import net.landofrails.landofsignals.serialization.EmptyStringMapper; import net.landofrails.landofsignals.tile.TileComplexSignal; import net.landofrails.landofsignals.tile.TileSignalBox; -import org.lwjgl.opengl.GL11; +import util.Matrix4; import java.util.*; @@ -129,21 +128,19 @@ public void draw(final IScreenBuilder builder) { rightTag.setMap("itemGroupState", Collections.singletonMap(signalGroup, rightState), EmptyStringMapper::toNullString, value -> new TagCompound().setString("string", value)); itemStackRight.setTagCompound(rightTag); - try (final OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 4, (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemStackRight, 0, 0); - } + Matrix4 matrix = new Matrix4(); + matrix.translate((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 4, (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemStackRight, 0, 0, matrix); final TagCompound leftTag = itemStackLeft.getTagCompound(); leftTag.setMap("itemGroupState", Collections.singletonMap(signalGroup, leftState), EmptyStringMapper::toNullString, value -> new TagCompound().setString("string", value)); itemStackLeft.setTagCompound(leftTag); - try (final OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated(((double) GUIHelpers.getScreenWidth() / 2 - (double) builder.getWidth() / 4) - 120, (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemStackLeft, 0, 0); - } + matrix = new Matrix4(); + matrix.translate(((double) GUIHelpers.getScreenWidth() / 2 - (double) builder.getWidth() / 4) - 120, (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemStackLeft, 0, 0, matrix); groupButton.setText(GuiText.LABEL_SIGNALGROUP.toString(modes.get(signalGroup).getGroupName())); } diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java index 5e4b13a9..c7f6666d 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalBoxSignalPart.java @@ -7,7 +7,6 @@ import cam72cam.mod.gui.screen.IScreen; import cam72cam.mod.gui.screen.IScreenBuilder; import cam72cam.mod.item.ItemStack; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.serialization.TagCompound; import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LOSGuis; @@ -15,7 +14,7 @@ import net.landofrails.landofsignals.packet.SignalBoxGuiToServerPacket; import net.landofrails.landofsignals.tile.TileSignalBox; import net.landofrails.landofsignals.tile.TileSignalPart; -import org.lwjgl.opengl.GL11; +import util.Matrix4; import java.util.Objects; @@ -40,9 +39,9 @@ public GuiSignalBoxSignalPart() { states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(tsp.getId()); - originalRightState = tsb.getActiveGroupState(new String[]{null}); + originalRightState = tsb.getActiveGroupState(""); rightState = originalRightState; - originalLeftState = tsb.getInactiveGroupState(new String[]{null}); + originalLeftState = tsb.getInactiveGroupState(""); leftState = originalLeftState; @@ -64,6 +63,13 @@ public static void open(final TileSignalBox tileSignalBox) { LOSGuis.SIGNAL_BOX_SIGNAL_PART.open(MinecraftClient.getPlayer()); } + @SuppressWarnings("java:S1751") + private static T getFirstValue(T[] values) { + for (T object : values) + return object; + return null; + } + @Override public void init(final IScreenBuilder screen) { // Use first available group @@ -115,21 +121,20 @@ public void draw(final IScreenBuilder builder) { rightTag.setString("itemState", rightState); itemStackRight.setTagCompound(rightTag); - try (final OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 4, (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemStackRight, 0, 0); - } + Matrix4 matrix = new Matrix4(); + matrix.translate((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 4, (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemStackRight, 0, 0, matrix); final TagCompound leftTag = itemStackLeft.getTagCompound(); leftTag.setString("itemState", leftState); itemStackLeft.setTagCompound(leftTag); - try (final OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated(((double) GUIHelpers.getScreenWidth() / 2 - (double) builder.getWidth() / 4) - 120, (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemStackLeft, 0, 0); - } + matrix = new Matrix4(); + matrix.translate(((double) GUIHelpers.getScreenWidth() / 2 - (double) builder.getWidth() / 4) - 120, (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemStackLeft, 0, 0, matrix); + groupButton.setText(GuiText.LABEL_SIGNALGROUP.toString("default")); } @@ -145,11 +150,4 @@ else if (useNext) return getFirstValue(states); } - @SuppressWarnings("java:S1751") - private static T getFirstValue(T[] values) { - for (T object : values) - return object; - return null; - } - } diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java index c9500122..406efbe8 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiSignalPrioritization.java @@ -10,7 +10,6 @@ import cam72cam.mod.gui.screen.Slider; import cam72cam.mod.item.ItemStack; import cam72cam.mod.math.Vec3i; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.serialization.TagCompound; import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalGroup; import net.landofrails.landofsignals.LOSBlocks; @@ -20,7 +19,7 @@ import net.landofrails.landofsignals.serialization.EmptyStringMapper; import net.landofrails.landofsignals.tile.TileComplexSignal; import net.landofrails.landofsignals.tile.TileSignalPart; -import org.lwjgl.opengl.GL11; +import util.Matrix4; import java.text.MessageFormat; import java.util.*; @@ -155,12 +154,13 @@ public void draw(IScreenBuilder builder) { refreshItem(); final int scale = 8; - try (final OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 6, (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(item, 0, 0); - } + Matrix4 matrix = new Matrix4(); + matrix.translate((double) GUIHelpers.getScreenWidth() / 2 + (double) builder.getWidth() / 6, (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(item, 0, 0, matrix); + + // TODO: Check if still needed // Slider and GUIHelper.drawItem() are interacting with each other. Fix background: // Has no effect, but makes slider work :) GUIHelpers.drawRect(-175, 120, 200, 20, 0x616161); @@ -210,7 +210,7 @@ private void updateButtons() { private String getTextForIndex(int indexOffset) { int index = entriesIndex + indexOffset; if (states.length > index) { - return MessageFormat.format("{0}. {1}", index + 1, states[index]); + return MessageFormat.format("{0}. {1}", index + 1, states[index].isEmpty() ? "Default" : states[index]); } else { return "-"; } @@ -276,7 +276,7 @@ private boolean initStates(IScreenBuilder screen) { groups = new String[0]; } else { groupStates = tileComplexSignal.getOrderedGroupStates(); - if (groupStates == null || groupStates.size() == 0) { + if (groupStates == null || groupStates.isEmpty()) { screen.close(); return false; } diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileComplexSignalRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileComplexSignalRender.java index e05e2a8c..0818d0f1 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileComplexSignalRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileComplexSignalRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalGroup; import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalState; @@ -16,7 +16,6 @@ import net.landofrails.landofsignals.tile.TileComplexSignal; import net.landofrails.landofsignals.utils.HighlightingUtil; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -28,7 +27,7 @@ private TileComplexSignalRender() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String blockId, Collection groups, String identifier) { @@ -69,14 +68,14 @@ public static void checkCache(String blockId, Map mo final String objId = blockId + identifier + path; Set objTextures = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getContentpackComplexSignals().get(blockId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signalModel : modelEntry.getValue()) { String[] groups = signalModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).filter(Objects::nonNull).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -91,10 +90,10 @@ public static void checkCache(String blockId, Map mo } public static StandardModel render(final TileComplexSignal tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(final TileComplexSignal tsp) { + private static void renderStuff(final TileComplexSignal tsp, RenderState state) { String id = tsp.getId(); @@ -102,17 +101,17 @@ private static void renderStuff(final TileComplexSignal tsp) { id = Static.MISSING; } - renderBase(id, tsp); - renderSignals(id, tsp); + renderBase(id, tsp, state); + renderSignals(id, tsp, state); if(tsp.isHighlighting()){ - HighlightingUtil.renderHighlighting(); + HighlightingUtil.renderHighlighting(state.clone()); } } @SuppressWarnings("java:S1134") - private static void renderBase(String blockId, TileComplexSignal tile) { + private static void renderBase(String blockId, TileComplexSignal tile, RenderState state) { final Vec3d offset = tile.getOffset(); final Vec3d customScaling = tile.getScaling(); @@ -125,28 +124,31 @@ private static void renderBase(String blockId, TileComplexSignal tile) { // Needs to be split from signal final String objId = blockId + "/base/" + path; - final OBJRender renderer = cache.get(objId); + final OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + final ContentPackBlock block = baseModel.getBlock(); final Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); final Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x,1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { @@ -160,7 +162,7 @@ private static void renderBase(String blockId, TileComplexSignal tile) { } @SuppressWarnings("java:S1134") - private static void renderSignals(final String blockId, final TileComplexSignal tile) { + private static void renderSignals(final String blockId, final TileComplexSignal tile, RenderState state) { final Vec3d offset = tile.getOffset(); final Vec3d customScaling = tile.getScaling(); @@ -185,31 +187,32 @@ private static void renderSignals(final String blockId, final TileComplexSignal // Needs to be split from base final String objId = blockId + "/signals/" + path; - final OBJRender renderer = cache.get(objId); + final OBJModel model = cache.get(objId); for (ContentPackModel signalModel : signalModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackBlock block = signalModel.getBlock(); final Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); final Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(signalModel.getTextures())) { - - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x,1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(signalModel.getTextures()).bind(iterationState)) { String[] groups = signalModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { @@ -222,7 +225,6 @@ private static void renderSignals(final String blockId, final TileComplexSignal } - } } diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileCustomLeverRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileCustomLeverRender.java index fc3fa3c1..f0832860 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileCustomLeverRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileCustomLeverRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.lever.ContentPackLever; import net.landofrails.api.contentpacks.v2.parent.ContentPackBlock; @@ -14,7 +14,6 @@ import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.tile.TileCustomLever; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -26,7 +25,7 @@ private TileCustomLeverRender(){ } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String blockId, Map models) { @@ -44,14 +43,14 @@ public static void checkCache(String blockId, Map mo final String objId = blockId + "/" + path; Set objTextures = LOSBlocks.BLOCK_CUSTOM_LEVER.getContentpackLever().get(blockId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel decoModel : modelEntry.getValue()) { String[] groups = decoModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -66,10 +65,10 @@ public static void checkCache(String blockId, Map mo } public static StandardModel render(TileCustomLever tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((renderState, partialTicks) -> renderStuff(renderState, tsp)); } - private static void renderStuff(TileCustomLever tsp) { + private static void renderStuff(RenderState renderState, TileCustomLever tsp) { String id = tsp.getId(); @@ -78,13 +77,13 @@ private static void renderStuff(TileCustomLever tsp) { } if(tsp.isActive()) { - renderActive(id, tsp); + renderActive(renderState, id, tsp); }else{ - renderInactive(id, tsp); + renderInactive(renderState, id, tsp); } } - private static void renderActive(String blockId, TileCustomLever tile) { + private static void renderActive(RenderState renderState, String blockId, TileCustomLever tile) { Vec3d offset = tile.getOffset(); Vec3d customScaling = tile.getScaling(); @@ -99,29 +98,32 @@ private static void renderActive(String blockId, TileCustomLever tile) { String path = activeModels.getKey(); String objId = blockId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel activeModel : activeModels.getValue()) { + + RenderState iterationState = renderState.clone(); + ContentPackBlock block = activeModel.getBlock(); Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(activeModel.getTextures())) { + // Render + iterationState.scale(scale.x, scale.y, scale.z); + iterationState.translate(translate.x, translate.y, translate.z); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(activeModel.getTextures()).bind(iterationState)) { String[] groups = activeModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { @@ -135,7 +137,7 @@ private static void renderActive(String blockId, TileCustomLever tile) { } } - private static void renderInactive(String blockId, TileCustomLever tile) { + private static void renderInactive(RenderState renderState, String blockId, TileCustomLever tile) { Vec3d offset = tile.getOffset(); Vec3d customScaling = tile.getScaling(); @@ -150,29 +152,32 @@ private static void renderInactive(String blockId, TileCustomLever tile) { String path = inactiveModels.getKey(); String objId = blockId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel inactiveModel : inactiveModels.getValue()) { + + RenderState iterationState = renderState.clone(); + ContentPackBlock block = inactiveModel.getBlock(); Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(inactiveModel.getTextures())) { + // Render + iterationState.scale(scale.x, scale.y, scale.z); + iterationState.translate(translate.x, translate.y, translate.z); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(inactiveModel.getTextures()).bind(iterationState)) { String[] groups = inactiveModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileDecoRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileDecoRender.java index 9b5962a6..53bde08b 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileDecoRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileDecoRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.deco.ContentPackDeco; import net.landofrails.api.contentpacks.v2.parent.ContentPackBlock; @@ -14,7 +14,6 @@ import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.tile.TileDeco; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -26,7 +25,7 @@ private TileDecoRender() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String blockId, Map models) { @@ -44,14 +43,14 @@ public static void checkCache(String blockId, Map mo final String objId = blockId + "/" + path; Set objTextures = LOSBlocks.BLOCK_DECO.getContentpackDeco().get(blockId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel decoModel : modelEntry.getValue()) { String[] groups = decoModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -66,10 +65,10 @@ public static void checkCache(String blockId, Map mo } public static StandardModel render(TileDeco tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(TileDeco tsp) { + private static void renderStuff(TileDeco tsp, RenderState state) { String id = tsp.getId(); @@ -77,11 +76,11 @@ private static void renderStuff(TileDeco tsp) { id = Static.MISSING; } - renderBase(id, tsp); + renderBase(id, tsp, state); } - private static void renderBase(String blockId, TileDeco tile) { + private static void renderBase(String blockId, TileDeco tile, RenderState state) { Vec3d offset = tile.getOffset(); Vec3d customScaling = tile.getScaling(); @@ -96,29 +95,32 @@ private static void renderBase(String blockId, TileDeco tile) { String path = baseModels.getKey(); String objId = blockId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackBlock block = baseModel.getBlock(); Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x,1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileMissingRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileMissingRender.java index e4f81456..5c5000ed 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileMissingRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileMissingRender.java @@ -2,40 +2,36 @@ import cam72cam.mod.block.BlockEntity; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; public class TileMissingRender { private TileMissingRender() { } - - private static OBJRender renderer; private static OBJModel model; public static StandardModel render(BlockEntity ts) { - return new StandardModel().addCustom(partialTicks -> renderStuff(ts, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(ts, state)); } @SuppressWarnings("java:S1172") - private static void renderStuff(BlockEntity ts, float partialTicks) { + private static void renderStuff(BlockEntity ts, RenderState state) { try { - if (renderer == null || model == null) { + if (model == null) { model = new OBJModel( new Identifier(LandOfSignals.MODID, Static.MISSING_OBJ), 0); - renderer = new OBJRender(model); } - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(0.5, 0.5, 0.5); + state.translate(0.5, 0.5, 0.5); + try (OBJRender.Binding vbo = model.binder().bind(state)) { - renderer.draw(); + vbo.draw(); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileSignPartRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileSignPartRender.java index 603d9577..f20fb9a5 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileSignPartRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileSignPartRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.parent.ContentPackBlock; import net.landofrails.api.contentpacks.v2.parent.ContentPackModel; @@ -14,7 +14,6 @@ import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.tile.TileSignPart; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -26,7 +25,7 @@ private TileSignPartRender() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String blockId, Map models) { @@ -44,14 +43,14 @@ public static void checkCache(String blockId, Map mo final String objId = blockId + "/" + path; Set objTextures = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(blockId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signModel : modelEntry.getValue()) { String[] groups = signModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -66,10 +65,10 @@ public static void checkCache(String blockId, Map mo } public static StandardModel render(TileSignPart tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(TileSignPart tsp) { + private static void renderStuff(TileSignPart tsp, RenderState state) { String id = tsp.getId(); @@ -77,11 +76,11 @@ private static void renderStuff(TileSignPart tsp) { id = Static.MISSING; } - renderBase(id, tsp); + renderBase(id, tsp, state); } - private static void renderBase(String blockId, TileSignPart tile) { + private static void renderBase(String blockId, TileSignPart tile, RenderState state) { Vec3d offset = tile.getOffset(); Vec3d customScaling = tile.getScaling(); @@ -95,29 +94,32 @@ private static void renderBase(String blockId, TileSignPart tile) { String path = baseModels.getKey(); String objId = blockId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackBlock block = baseModel.getBlock(); Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } /* diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalBoxRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalBoxRender.java index 2db2d9b0..b0f4a516 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalBoxRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalBoxRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.parent.ContentPackBlock; import net.landofrails.api.contentpacks.v2.parent.ContentPackModel; @@ -15,7 +15,6 @@ import net.landofrails.landofsignals.tile.TileSignalBox; import net.landofrails.landofsignals.utils.HighlightingUtil; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -27,7 +26,7 @@ private TileSignalBoxRender() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String blockId, Map models) { @@ -45,14 +44,14 @@ public static void checkCache(String blockId, Map mo final String objId = blockId + "/" + path; Set objTextures = LOSBlocks.BLOCK_SIGNAL_BOX.getContentpackSignalboxes().get(blockId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signalboxModel : modelEntry.getValue()) { String[] groups = signalboxModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -67,10 +66,10 @@ public static void checkCache(String blockId, Map mo } public static StandardModel render(final TileSignalBox tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(final TileSignalBox tsp) { + private static void renderStuff(final TileSignalBox tsp, RenderState state) { String id = tsp.getId(); @@ -78,14 +77,14 @@ private static void renderStuff(final TileSignalBox tsp) { id = Static.MISSING; } - renderBase(id, tsp); + renderBase(id, tsp, state); if(tsp.isHighlighting()){ - HighlightingUtil.renderHighlighting(); + HighlightingUtil.renderHighlighting(state.clone()); } } - private static void renderBase(final String blockId, final TileSignalBox tile) { + private static void renderBase(final String blockId, final TileSignalBox tile, RenderState state) { final Vec3d offset = tile.getOffset(); final Vec3d customScaling = tile.getScaling(); @@ -99,29 +98,32 @@ private static void renderBase(final String blockId, final TileSignalBox tile) { final String path = baseModels.getKey(); final String objId = blockId + "/" + path; - final OBJRender renderer = cache.get(objId); + final OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + final ContentPackBlock block = baseModel.getBlock(); final Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset); final Vec3d scale = Static.multiply(block.getAsVec3d(block::getScaling), customScaling); final Vec3d rotation = block.getAsVec3d(block::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x,1, 0, 0); + iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(tile.getBlockRotate() + rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } catch (Exception e) { diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalLeverRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalLeverRender.java index 8d63fbab..af34a0ad 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalLeverRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalLeverRender.java @@ -1,13 +1,12 @@ package net.landofrails.landofsignals.render.block; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.tile.TileSignalLever; -import org.lwjgl.opengl.GL11; import java.util.Arrays; import java.util.Collections; @@ -20,32 +19,32 @@ private TileSignalLeverRender() { } - private static OBJRender renderer; private static OBJModel model; private static final List groupNames = Arrays.asList("Base01_B01", "Hebelwerk01_H01", "Hebelwerk02_H02"); public static StandardModel render(final TileSignalLever ts) { - return new StandardModel().addCustom(partialTicks -> renderStuff(ts, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(ts, state)); } @SuppressWarnings("java:S1172") - private static void renderStuff(final TileSignalLever ts, final float partialTicks) { + private static void renderStuff(final TileSignalLever ts, RenderState state) { try { - if (renderer == null || model == null) { + if (model == null) { model = new OBJModel( new Identifier(LandOfSignals.MODID, "models/block/landofsignals/signalslever/signalslever.obj"), 0); - renderer = new OBJRender(model); } - try (final OpenGL.With matrix = OpenGL.matrix(); final OpenGL.With tex = renderer.bindTexture()) { - GL11.glTranslated(0.5, 0.6, 0.5); - GL11.glRotated(ts.getBlockRotate(), 0, 1, 0); - renderer.drawGroups(Collections.singleton(groupNames.get(0))); + state.translate(0.5, 0.6, 0.5); + state.rotate(ts.getBlockRotate(), 0,1, 0); - // Animation - GL11.glRotated((ts.getLeverRotate() * 2), 1, 0, 0); - renderer.drawGroups(groupNames.subList(1, groupNames.size() - 1)); + try (OBJRender.Binding vbo = model.binder().bind(state)) { + vbo.draw(Collections.singleton(groupNames.get(0))); + } + // Animation + state.rotate((ts.getLeverRotate() * 2), 1, 0, 0); + try (OBJRender.Binding vbo = model.binder().bind(state)){ + vbo.draw(groupNames.subList(1, groupNames.size() - 1)); } } catch (final Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartAnimatedRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartAnimatedRender.java index 01dcf345..fa6597c0 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartAnimatedRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartAnimatedRender.java @@ -2,14 +2,13 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.tile.TileSignalPartAnimated; -import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import java.util.*; @@ -21,20 +20,19 @@ private TileSignalPartAnimatedRender() { } - private static final Map> cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); private static final List groupNames = Arrays.asList("wing"); public static StandardModel render(final TileSignalPartAnimated tsp) { - return new StandardModel().addCustom(partialTicks -> renderStuff(tsp, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(final TileSignalPartAnimated tsp, final float partialTicks) { + private static void renderStuff(final TileSignalPartAnimated tsp, RenderState state) { final String id = tsp.getId(); if (!cache.containsKey("flare")) { try { final OBJModel flareModel = new OBJModel(new Identifier(LandOfSignals.MODID, "models/block/landofsignals/lamp/flare.obj"), 0); - final OBJRender flareRenderer = new OBJRender(flareModel); - cache.put("flare", Pair.of(flareModel, flareRenderer)); + cache.put("flare", flareModel); } catch (final Exception e) { e.printStackTrace(); } @@ -42,36 +40,38 @@ private static void renderStuff(final TileSignalPartAnimated tsp, final float pa if (!cache.containsKey(id)) { try { final OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getPath(id)), 0, LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getStates(id)); - final OBJRender renderer = new OBJRender(model); - cache.put(id, Pair.of(model, renderer)); + cache.put(id, model); } catch (final Exception e) { e.printStackTrace(); } } - final OBJRender renderer = cache.get(id).getRight(); + final OBJModel model = cache.get(id); final List groupsWithoutWing = new ArrayList<>(); - for (final String s : renderer.model.groups()) groupsWithoutWing.add(s); + for (final String s : model.groups()) groupsWithoutWing.add(s); final boolean wingsExist = groupsWithoutWing.containsAll(groupNames); groupsWithoutWing.removeAll(groupNames); - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture(tsp.getAnimationOrTextureName())) { - final Vec3d scale = Vec3d.ZERO; - GL11.glScaled(scale.x, scale.y, scale.z); - final Vec3d trans = Vec3d.ZERO; - GL11.glTranslated(trans.x, trans.y, trans.z); - GL11.glRotated(tsp.getBlockRotate(), 0, 1, 0); - renderer.drawGroups(groupsWithoutWing); + final Vec3d scale = Vec3d.ZERO; + final Vec3d trans = Vec3d.ZERO; + GL11.glRotated(tsp.getBlockRotate(), 0, 1, 0); + state.scale(scale); + state.translate(trans); + state.rotate(tsp.getBlockRotate(), 0, 1, 0); - if (wingsExist) { - Vec3d center = renderer.model.centerOfGroups(groupNames); - center = new Vec3d(-center.x, -center.y, -center.z); - final Vec3d rotateYaw = center.rotateYaw(tsp.getPartRotate()); + try (OBJRender.Binding vbo = model.binder().texture(tsp.getAnimationOrTextureName()).bind(state)) { + vbo.draw(groupsWithoutWing); + } - GL11.glTranslated(0, -center.y, 0); - GL11.glRotatef(tsp.getPartRotate(), 1, 0, 0); - GL11.glTranslated(0, rotateYaw.y, 0); + if (wingsExist) { + Vec3d center = model.centerOfGroups(groupNames); + center = new Vec3d(-center.x, -center.y, -center.z); + final Vec3d rotateYaw = center.rotateYaw(tsp.getPartRotate()); - renderer.drawGroups(groupNames); + state.translate(0, -center.y, 0); + state.rotate(tsp.getPartRotate(), 1, 0, 0); + state.translate(0, rotateYaw.y, 0); + try(OBJRender.Binding vbo = model.binder().texture(tsp.getAnimationOrTextureName()).bind(state)){ + vbo.draw(groupNames); } } diff --git a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartRender.java b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartRender.java index c15385de..afaeeb4b 100644 --- a/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/block/TileSignalPartRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.api.contentpacks.v2.signal.ContentPackSignal; import net.landofrails.landofsignals.LOSBlocks; @@ -14,7 +14,6 @@ import net.landofrails.landofsignals.tile.TileSignalPart; import net.landofrails.landofsignals.utils.HighlightingUtil; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.Arrays; import java.util.HashMap; @@ -26,13 +25,13 @@ private TileSignalPartRender() { } - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); public static StandardModel render(final TileSignalPart tsp) { - return new StandardModel().addCustom(() -> renderStuff(tsp)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(tsp, state)); } - private static void renderStuff(final TileSignalPart tsp) { + private static void renderStuff(final TileSignalPart tsp, RenderState state) { String id = tsp.getId(); @@ -44,22 +43,22 @@ private static void renderStuff(final TileSignalPart tsp) { if(signal == null) { signal = LOSBlocks.BLOCK_SIGNAL_PART.getContentpackSignals().get(Static.MISSING); - tsp.setState(null); + tsp.setState(""); } if (signal.getUseBase()) { - renderBase(id, signal, tsp); + renderBase(id, signal, tsp, state.clone()); } - renderSignals(id, signal, tsp); + renderSignals(id, signal, tsp, state.clone()); if(tsp.isHighlighting()){ - HighlightingUtil.renderHighlighting(); + HighlightingUtil.renderHighlighting(state.clone()); } } @SuppressWarnings("java:S1134") - private static void renderBase(String blockId, ContentPackSignal signal, TileSignalPart tile) { + private static void renderBase(String blockId, ContentPackSignal signal, TileSignalPart tile, RenderState state) { final Vec3d offset = tile.getOffset(); final Vec3d customScaling = tile.getScaling(); @@ -69,12 +68,12 @@ private static void renderBase(String blockId, ContentPackSignal signal, TileSig if (!cache.containsKey(objPath)) { try { String[] states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(blockId); - cache.put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + cache.put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { throw new ItemRenderException("Error loading item model/renderer...", e); } } - final OBJRender renderer = cache.get(objPath); + final OBJModel model = cache.get(objPath); final float[] originalTranslate = signal.getTranslation(); final Vec3d translate = new Vec3d(originalTranslate[0], originalTranslate[1], originalTranslate[2]).add(offset); @@ -83,14 +82,13 @@ private static void renderBase(String blockId, ContentPackSignal signal, TileSig scale[1] *= customScaling.y; scale[2] *= customScaling.z; - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(base)) { + state.scale(scale[0], scale[1], scale[2]); + state.translate(translate.x, translate.y, translate.z); + state.rotate(tile.getBlockRotate(), 0, 1, 0); + try (OBJRender.Binding vbo = model.binder().texture(base).bind(state)) { // Render - GL11.glScaled(scale[0], scale[1], scale[2]); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(tile.getBlockRotate(), 0, 1, 0); - renderer.draw(); - + vbo.draw(); } catch (Exception e) { // Removes TileEntity on client-side, prevents crash ModCore.error("Removing local SignalPart (x%d, y%d, z%d) due to exceptions: %s", tile.getPos().x, tile.getPos().y, tile.getPos().z, e.getMessage()); @@ -102,7 +100,7 @@ private static void renderBase(String blockId, ContentPackSignal signal, TileSig @SuppressWarnings("java:S1134") - private static void renderSignals(String blockId, ContentPackSignal signal, TileSignalPart tile) { + private static void renderSignals(String blockId, ContentPackSignal signal, TileSignalPart tile, RenderState state) { final Vec3d offset = tile.getOffset(); final Vec3d customScaling = tile.getScaling(); @@ -112,12 +110,12 @@ private static void renderSignals(String blockId, ContentPackSignal signal, Tile if (!cache.containsKey(objPath)) { try { String[] states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(blockId); - cache.put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + cache.put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { throw new ItemRenderException("Error loading item model/renderer...", e); } } - final OBJRender renderer = cache.get(objPath); + final OBJModel model = cache.get(objPath); final float[] originalTranslate = signal.getTranslation(); final Vec3d translate = new Vec3d(originalTranslate[0], originalTranslate[1], originalTranslate[2]).add(offset); @@ -126,14 +124,14 @@ private static void renderSignals(String blockId, ContentPackSignal signal, Tile scale[1] *= customScaling.y; scale[2] *= customScaling.z; - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(signalState)) { - // Render - GL11.glScaled(scale[0], scale[1], scale[2]); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(tile.getBlockRotate(), 0, 1, 0); - renderer.draw(); + state.scale(scale[0], scale[1], scale[2]); + state.translate(translate); + state.rotate(tile.getBlockRotate(), 0, 1, 0); + try (OBJRender.Binding vbo = model.binder().texture(signalState).bind(state)) { + // Render + vbo.draw(); } catch (Exception e) { // Removes TileEntity on client-side, prevents crash ModCore.error("Removing local SignalPart (x%d, y%d, z%d) due to exceptions: %s", tile.getPos().x, tile.getPos().y, tile.getPos().z, e.getMessage()); @@ -142,7 +140,7 @@ private static void renderSignals(String blockId, ContentPackSignal signal, Tile } } - public static Map cache(){ + public static Map cache(){ return cache; } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemComplexSignalRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemComplexSignalRender.java index 914173a7..f35985c4 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemComplexSignalRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemComplexSignalRender.java @@ -4,9 +4,9 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -19,7 +19,6 @@ import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.serialization.EmptyStringMapper; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -27,7 +26,7 @@ @SuppressWarnings("java:S3252") public class ItemComplexSignalRender implements ItemRender.IItemModel { - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); protected static final Map> groupCache = new HashMap<>(); private static final String SIGNAL_IDENTIFIER = "/signals/"; @@ -70,16 +69,24 @@ public static void checkCache(String itemId, Map mod final String objId = itemId + identifier + path; Set objTextures = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getContentpackComplexSignals().get(itemId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + if(objTextures.contains(null)){ + objTextures.remove(null); + objTextures.add(""); + } + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signalModel : modelEntry.getValue()) { String[] groups = signalModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).filter(Objects::nonNull).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); + if(modes.contains(null)){ + modes.remove(null); + modes.add(""); + } groupCache.put(groupCacheId, modes); } } @@ -93,7 +100,7 @@ public static void checkCache(String itemId, Map mod @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((state, partialTicks) -> { final TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -105,25 +112,24 @@ public StandardModel getModel(World world, ItemStack stack) { if (tag.hasKey("itemGroupState")) { itemGroupStates.putAll(tag.getMap("itemGroupState", EmptyStringMapper::fromNullString, value -> value.getString("string"))); } + itemGroupStates.replaceAll((key, value) -> value == null ? "" : value); - renderBase(itemId); - renderSignals(itemId, itemGroupStates); + renderBase(itemId, state); + renderSignals(itemId, itemGroupStates, state); }); } - - @SuppressWarnings("java:S1135") @Override - public void applyTransform(ItemRender.ItemRenderType type) { + public void applyTransform(ItemStack stack, ItemRender.ItemRenderType type, RenderState ctx) { // Implement ItemRenderType with new UMC rendering - ItemRender.IItemModel.super.applyTransform(type); + ItemRender.IItemModel.super.applyTransform(stack, type, ctx); } @SuppressWarnings("java:S1134") - private static void renderBase(String itemId) { + private static void renderBase(String itemId, RenderState state) { checkCache(itemId, LOSBlocks.BLOCK_COMPLEX_SIGNAL.getContentpackComplexSignals().get(itemId).getBase(), "/base/", true); @@ -132,30 +138,32 @@ private static void renderBase(String itemId) { final String path = baseModels.getKey(); final String objId = itemId + "/base/" + path; - final OBJRender renderer = cache.get(objId); + final OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + final ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT); final Vec3d translate = item.getAsVec3d(item::getTranslation); final Vec3d scale = item.getAsVec3d(item::getScaling); final Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { - - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } @@ -165,7 +173,7 @@ private static void renderBase(String itemId) { } @SuppressWarnings("java:S1134") - private static void renderSignals(String itemId, Map itemGroupStates) { + private static void renderSignals(String itemId, Map itemGroupStates, RenderState state) { final Map signalGroups = LOSBlocks.BLOCK_COMPLEX_SIGNAL.getContentpackComplexSignals().get(itemId).getSignals(); checkCache(itemId, signalGroups.values()); @@ -179,32 +187,35 @@ private static void renderSignals(String itemId, Map itemGroupSt final String path = signalModels.getKey(); final String objId = itemId + SIGNAL_IDENTIFIER + path; - final OBJRender renderer = cache.get(objId); + final OBJModel model = cache.get(objId); for (ContentPackModel signalModel : signalModels.getValue()) { + + RenderState iterationState = state.clone(); + final ContentPackItem item = signalModel.getItem().get(ContentPackItemRenderType.DEFAULT); final Vec3d translate = item.getAsVec3d(item::getTranslation); final Vec3d scale = item.getAsVec3d(item::getScaling); final Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(signalModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(signalModel.getTextures()).bind(iterationState)) { // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); - String[] groups = signalModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } + } } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemCustomLeverRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemCustomLeverRender.java index 17aacef2..162dd58d 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemCustomLeverRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemCustomLeverRender.java @@ -4,9 +4,9 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -16,7 +16,6 @@ import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -24,7 +23,7 @@ public class ItemCustomLeverRender implements ItemRender.IItemModel { - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String itemId, Map models) { @@ -42,14 +41,14 @@ public static void checkCache(String itemId, Map mod final String objId = itemId + "/" + path; Set objTextures = LOSBlocks.BLOCK_CUSTOM_LEVER.getContentpackLever().get(itemId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel decoModel : modelEntry.getValue()) { String[] groups = decoModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -65,7 +64,7 @@ public static void checkCache(String itemId, Map mod @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((renderState, partialTicks) -> { TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -73,19 +72,19 @@ public StandardModel getModel(World world, ItemStack stack) { itemId = Static.MISSING; } - renderInactive(itemId); + renderInactive(renderState.clone(), itemId); }); } @Override - public void applyTransform(ItemRender.ItemRenderType type) { + public void applyTransform(ItemStack stack, ItemRender.ItemRenderType type, RenderState ctx) { - // Implement ItemRenderType with new UMC rendering - ItemRender.IItemModel.super.applyTransform(type); + // Implement ItemRenderType + ItemRender.IItemModel.super.applyTransform(stack, type, ctx); } - private static void renderInactive(String itemId) { + private static void renderInactive(RenderState renderState, String itemId) { checkCache(itemId, LOSBlocks.BLOCK_CUSTOM_LEVER.getContentpackLever().get(itemId).getInactive()); @@ -94,29 +93,32 @@ private static void renderInactive(String itemId) { String path = inactiveModels.getKey(); String objId = itemId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel inactiveModel : inactiveModels.getValue()) { + + RenderState iterationState = renderState.clone(); + ContentPackItem item = inactiveModel.getItem().get(ContentPackItemRenderType.DEFAULT); Vec3d translate = item.getAsVec3d(item::getTranslation); Vec3d scale = item.getAsVec3d(item::getScaling); Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(inactiveModel.getTextures())) { + // Render + iterationState.scale(scale.x, scale.y, scale.z); + iterationState.translate(translate.x, translate.y, translate.z); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(inactiveModel.getTextures()).bind(iterationState)) { String[] groups = inactiveModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemDecoRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemDecoRender.java index 2bdedc15..b4c0ff26 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemDecoRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemDecoRender.java @@ -4,9 +4,9 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -16,7 +16,6 @@ import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -24,7 +23,7 @@ public class ItemDecoRender implements ItemRender.IItemModel { - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String itemId, Map models) { @@ -42,14 +41,16 @@ public static void checkCache(String itemId, Map mod final String objId = itemId + "/" + path; Set objTextures = LOSBlocks.BLOCK_DECO.getContentpackDeco().get(itemId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + objTextures.remove(null); + objTextures.add(""); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel decoModel : modelEntry.getValue()) { String[] groups = decoModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -65,7 +66,7 @@ public static void checkCache(String itemId, Map mod @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((state, partialTicks) -> { TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -73,19 +74,19 @@ public StandardModel getModel(World world, ItemStack stack) { itemId = Static.MISSING; } - renderBase(itemId); + renderBase(itemId, state); }); } @Override - public void applyTransform(ItemRender.ItemRenderType type) { - + public void applyTransform(ItemStack stack, ItemRender.ItemRenderType type, RenderState ctx) { // Implement ItemRenderType with new UMC rendering - ItemRender.IItemModel.super.applyTransform(type); + + ItemRender.IItemModel.super.applyTransform(stack, type, ctx); } - private static void renderBase(String itemId) { + private static void renderBase(String itemId, RenderState state) { checkCache(itemId, LOSBlocks.BLOCK_DECO.getContentpackDeco().get(itemId).getBase()); @@ -94,32 +95,39 @@ private static void renderBase(String itemId) { String path = baseModels.getKey(); String objId = itemId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT); Vec3d translate = item.getAsVec3d(item::getTranslation); Vec3d scale = item.getAsVec3d(item::getScaling); Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + state.scale(scale); + state.translate(translate); + state.rotate(rotation.x, 1, 0, 0); + state.rotate(rotation.y, 0, 1, 0); + state.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + String texture = baseModel.getTextures(); + if(texture == null) + texture = ""; + try (OBJRender.Binding vbo = model.binder().texture(texture).bind(state)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } + } } } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignPartRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignPartRender.java index 52618a10..d2414cb3 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignPartRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignPartRender.java @@ -4,9 +4,9 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -16,7 +16,6 @@ import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -24,7 +23,7 @@ public class ItemSignPartRender implements ItemRender.IItemModel { - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String itemId, Map models) { @@ -42,14 +41,16 @@ public static void checkCache(String itemId, Map mod final String objId = itemId + "/" + path; Set objTextures = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(itemId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + objTextures.remove(null); + objTextures.add(""); + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signModel : modelEntry.getValue()) { String[] groups = signModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); @@ -65,7 +66,7 @@ public static void checkCache(String itemId, Map mod @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((state, partialTicks) -> { TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -73,19 +74,19 @@ public StandardModel getModel(World world, ItemStack stack) { itemId = Static.MISSING; } - renderBase(itemId); + renderBase(itemId, state); }); } @Override - public void applyTransform(ItemRender.ItemRenderType type) { + public void applyTransform(ItemStack stack, ItemRender.ItemRenderType type, RenderState ctx) { // Implement ItemRenderType with new UMC rendering - ItemRender.IItemModel.super.applyTransform(type); + ItemRender.IItemModel.super.applyTransform(stack, type, ctx); } - private static void renderBase(String itemId) { + private static void renderBase(String itemId, RenderState state) { checkCache(itemId, LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(itemId).getBase()); @@ -94,29 +95,32 @@ private static void renderBase(String itemId) { String path = baseModels.getKey(); String objId = itemId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT); Vec3d translate = item.getAsVec3d(item::getTranslation); Vec3d scale = item.getAsVec3d(item::getScaling); Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalBoxRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalBoxRender.java index 44e15ead..32771589 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalBoxRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalBoxRender.java @@ -4,9 +4,9 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -16,7 +16,6 @@ import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.function.Predicate; @@ -24,7 +23,7 @@ public class ItemSignalBoxRender implements ItemRender.IItemModel { - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); private static final Map> groupCache = new HashMap<>(); public static void checkCache(String itemId, Map models) { @@ -42,15 +41,23 @@ public static void checkCache(String itemId, Map mod final String objId = itemId + "/" + path; Set objTextures = LOSBlocks.BLOCK_SIGNAL_BOX.getContentpackSignalboxes().get(itemId).getObjTextures().get(path); - OBJRender renderer = new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures)); - cache.putIfAbsent(objId, renderer); + if(objTextures.contains(null)){ + objTextures.remove(null); + objTextures.add(""); + } + OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, path), 0, objTextures); + cache.putIfAbsent(objId, model); for (ContentPackModel signalBoxModel : modelEntry.getValue()) { String[] groups = signalBoxModel.getObj_groups(); if (groups.length > 0) { Predicate targetGroup = renderOBJGroup -> Arrays.stream(groups).anyMatch(renderOBJGroup::startsWith); - List modes = renderer.model.groups().stream().filter(targetGroup) + List modes = model.groups().stream().filter(targetGroup) .collect(Collectors.toCollection(ArrayList::new)); + if(modes.contains(null)){ + modes.remove(null); + modes.add(""); + } String groupCacheId = objId + "@" + String.join("+", groups); groupCache.put(groupCacheId, modes); } @@ -65,7 +72,7 @@ public static void checkCache(String itemId, Map mod @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((state, partialTicks) -> { TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -73,19 +80,18 @@ public StandardModel getModel(World world, ItemStack stack) { itemId = Static.MISSING; } - renderBase(itemId); + renderBase(itemId, state); }); } @Override - public void applyTransform(ItemRender.ItemRenderType type) { - + public void applyTransform(ItemStack stack, ItemRender.ItemRenderType type, RenderState ctx) { // Implement ItemRenderType with new UMC rendering - ItemRender.IItemModel.super.applyTransform(type); + ItemRender.IItemModel.super.applyTransform(stack, type, ctx); } - private static void renderBase(String itemId) { + private static void renderBase(String itemId, RenderState state) { checkCache(itemId, LOSBlocks.BLOCK_SIGNAL_BOX.getContentpackSignalboxes().get(itemId).getBase()); @@ -94,29 +100,32 @@ private static void renderBase(String itemId) { String path = baseModels.getKey(); String objId = itemId + "/" + path; - OBJRender renderer = cache.get(objId); + OBJModel model = cache.get(objId); for (ContentPackModel baseModel : baseModels.getValue()) { + + RenderState iterationState = state.clone(); + ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT); Vec3d translate = item.getAsVec3d(item::getTranslation); Vec3d scale = item.getAsVec3d(item::getScaling); Vec3d rotation = item.getAsVec3d(item::getRotation); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseModel.getTextures())) { + iterationState.scale(scale); + iterationState.translate(translate); + iterationState.rotate(rotation.x, 1, 0, 0); + iterationState.rotate(rotation.y, 0, 1, 0); + iterationState.rotate(rotation.z, 0, 0, 1); - // Render - GL11.glScaled(scale.x, scale.y, scale.z); - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); + try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) { + // Render String[] groups = baseModel.getObj_groups(); if (groups.length == 0) { - renderer.draw(); + vbo.draw(); } else { String groupCacheId = objId + "@" + String.join("+", groups); - renderer.drawGroups(groupCache.get(groupCacheId)); + vbo.draw(groupCache.get(groupCacheId)); } } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartAnimatedRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartAnimatedRender.java index 6d1be921..3201c413 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartAnimatedRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartAnimatedRender.java @@ -4,7 +4,6 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -13,7 +12,6 @@ import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.gui.GuiSignalPartAnimatedBox; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.io.FileNotFoundException; import java.util.Collection; @@ -27,17 +25,18 @@ private ItemSignalPartAnimatedRender() { } public static final boolean IGNOREFNFEXCEPTION = true; - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); @SuppressWarnings("java:S112") public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { final TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); if (itemId == null || !LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getSignalParts().containsKey(itemId)) { itemId = Static.MISSING; } final Collection collection = LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getStates(itemId); + // TODO collection/states: is null okay or should it be replaced with ""? if (!cache.containsKey(itemId)) { try { final OBJModel model; @@ -45,8 +44,7 @@ public static ItemRender.IItemModel getModelFor() { model = new OBJModel(new Identifier(LandOfSignals.MODID, LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getPath(itemId)), 0, collection); else model = new OBJModel(new Identifier(LandOfSignals.MODID, LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getPath(itemId)), 0); - final OBJRender renderer = new OBJRender(model); - cache.put(itemId, renderer); + cache.put(itemId, model); } catch (final FileNotFoundException e) { if (IGNOREFNFEXCEPTION) { ModCore.Mod.error("Model not found: " + e.getMessage(), e.getMessage()); @@ -58,7 +56,7 @@ public static ItemRender.IItemModel getModelFor() { throw new RuntimeException("Error loading item model...", e); } } - final OBJRender renderer = cache.get(itemId); + final OBJModel model = cache.get(itemId); String textureName; if (collection != null) { textureName = GuiSignalPartAnimatedBox.getTexureName(); @@ -67,10 +65,12 @@ public static ItemRender.IItemModel getModelFor() { textureName = null; final Vec3d translate = LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getItemTranslation(itemId); final float scale = (float) LOSBlocks.BLOCK_SIGNAL_PART_ANIMATED.getScaling(itemId).x; - try (final OpenGL.With ignored = OpenGL.matrix(); final OpenGL.With ignored1 = renderer.bindTexture(textureName)) { - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glScaled(scale, scale, scale); - renderer.draw(); + + state.translate(translate); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().texture(textureName).bind(state)) { + vbo.draw(); } }); } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartRender.java index 02573f14..494a1b48 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ItemSignalPartRender.java @@ -3,9 +3,9 @@ import cam72cam.mod.item.ItemStack; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.world.World; @@ -13,7 +13,6 @@ import net.landofrails.landofsignals.LOSBlocks; import net.landofrails.landofsignals.LandOfSignals; import net.landofrails.landofsignals.utils.Static; -import org.lwjgl.opengl.GL11; import java.util.Arrays; import java.util.HashMap; @@ -21,11 +20,11 @@ @SuppressWarnings("java:S3252") public class ItemSignalPartRender implements ItemRender.IItemModel { - private static final Map cache = new HashMap<>(); + private static final Map cache = new HashMap<>(); @Override public StandardModel getModel(World world, ItemStack stack) { - return new StandardModel().addCustom(() -> { + return new StandardModel().addCustom((state, partialTicks) -> { final TagCompound tag = stack.getTagCompound(); String itemId = tag.getString("itemId"); @@ -37,16 +36,19 @@ public StandardModel getModel(World world, ItemStack stack) { if (tag.hasKey("itemState") && !itemId.equals(Static.MISSING)) { itemState = tag.getString("itemState"); } + if(itemState == null){ + itemState = ""; + } ContentPackSignal signal = LOSBlocks.BLOCK_SIGNAL_PART.getContentpackSignals().get(itemId); - renderBase(signal, itemId); - renderSignals(signal, itemId, itemState); + renderBase(signal, itemId, state); + renderSignals(signal, itemId, itemState, state); }); } @SuppressWarnings("java:S1134") - private static void renderBase(ContentPackSignal signal, String itemId) { + private static void renderBase(ContentPackSignal signal, String itemId, RenderState state) { String baseState = signal.getBase(); @@ -59,54 +61,54 @@ private static void renderBase(ContentPackSignal signal, String itemId) { if (!cache.containsKey(objPath)) { try { String[] states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(itemId); - cache.put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + cache.put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { throw new ItemRenderException("Error loading item model/renderer...", e); } } - final OBJRender renderer = cache.get(objPath); + final OBJModel model = cache.get(objPath); final float[] translate = signal.getItemTranslation(); final float[] scale = signal.getItemScaling(); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(baseState)) { + state.translate(translate[0], translate[1], translate[2]); + state.scale(scale[0], scale[1], scale[2]); - // Render - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glScaled(scale[0], scale[1], scale[2]); + try (OBJRender.Binding vbo = model.binder().texture(baseState).bind(state)) { - renderer.draw(); + // Render + vbo.draw(); } } @SuppressWarnings("java:S1134") - private static void renderSignals(ContentPackSignal signal, String itemId, String itemState) { + private static void renderSignals(ContentPackSignal signal, String itemId, String itemState, RenderState state) { String objPath = signal.getModel(); if (!cache.containsKey(objPath)) { try { String[] states = LOSBlocks.BLOCK_SIGNAL_PART.getAllStates(itemId); - cache.put(objPath, new OBJRender(new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)))); + cache.put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states))); } catch (Exception e) { throw new ItemRenderException("Error loading item model/renderer...", e); } } - final OBJRender renderer = cache.get(objPath); + final OBJModel model = cache.get(objPath); final float[] translate = signal.getItemTranslation(); final float[] scale = signal.getItemScaling(); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = renderer.bindTexture(itemState)) { + state.translate(translate[0], translate[1], translate[2]); + state.scale(scale[0], scale[1], scale[2]); - // Render - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glScaled(scale[0], scale[1], scale[2]); + try (OBJRender.Binding vbo = model.binder().texture(itemState).bind(state)) { - renderer.draw(); + // Render + vbo.draw(); } } - public static Map cache(){ + public static Map cache(){ return cache; } diff --git a/src/main/java/net/landofrails/landofsignals/render/item/ObjItemRender.java b/src/main/java/net/landofrails/landofsignals/render/item/ObjItemRender.java index 15336d33..038eb1fe 100644 --- a/src/main/java/net/landofrails/landofsignals/render/item/ObjItemRender.java +++ b/src/main/java/net/landofrails/landofsignals/render/item/ObjItemRender.java @@ -4,12 +4,10 @@ import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; -import org.lwjgl.opengl.GL11; import java.io.FileNotFoundException; import java.util.Collection; @@ -23,7 +21,7 @@ public class ObjItemRender { private ObjItemRender() { } - protected static final Map cache = new HashMap<>(); + protected static final Map cache = new HashMap<>(); public static ItemRender.IItemModel getModelFor(final Identifier id, final Vec3d translate, final float scale) { return getModelFor(id, translate, Vec3d.ZERO, null, scale); @@ -32,7 +30,7 @@ public static ItemRender.IItemModel getModelFor(final Identifier id, final Vec3d @SuppressWarnings("java:S112") public static ItemRender.IItemModel getModelFor(final Identifier id, final Vec3d translate, final Vec3d rotation, final Collection collection, final float scale) { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { if (!cache.containsKey(id)) { try { final OBJModel model; @@ -41,8 +39,7 @@ public static ItemRender.IItemModel getModelFor(final Identifier id, final Vec3d } else { model = new OBJModel(id, 0); } - final OBJRender renderer = new OBJRender(model); - cache.put(id, renderer); + cache.put(id, model); } catch (final FileNotFoundException e) { if (IGNOREFNFEXCEPTION) { ModCore.Mod.error("Model not found: " + e.getMessage(), e.getMessage()); @@ -54,19 +51,21 @@ public static ItemRender.IItemModel getModelFor(final Identifier id, final Vec3d throw new RuntimeException("Error loading item model...", e); } } - final OBJRender renderer = cache.get(id); + final OBJModel model = cache.get(id); String textureName = null; final TagCompound tag = stack.getTagCompound(); if (collection != null && tag.hasKey("textureName")) { textureName = tag.getString("textureName"); } - try (final OpenGL.With ignored = OpenGL.matrix(); final OpenGL.With ignored1 = renderer.bindTexture(textureName)) { - GL11.glTranslated(translate.x, translate.y, translate.z); - GL11.glRotated(rotation.x, 1, 0, 0); - GL11.glRotated(rotation.y, 0, 1, 0); - GL11.glRotated(rotation.z, 0, 0, 1); - GL11.glScaled(scale, scale, scale); - renderer.draw(); + + state.translate(translate); + state.rotate(rotation.x, 1, 0, 0); + state.rotate(rotation.y, 0, 1, 0); + state.rotate(rotation.z, 0, 0, 1); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().texture(textureName).bind(state)) { + vbo.draw(); } }); } diff --git a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java index 6a0ddf5b..c61f8f31 100644 --- a/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java +++ b/src/main/java/net/landofrails/landofsignals/tile/TileSignalPart.java @@ -36,7 +36,7 @@ public class TileSignalPart extends BlockEntity implements IManipulate { @TagField("id") private final String id; @TagField("texturePath") - private String texturePath; + private String texturePath = ""; @TagField(value = "orderedStates", mapper = StringArrayMapper.class) private String[] orderedStates; // for server only @@ -94,7 +94,7 @@ public int getBlockRotate() { } public String getState() { - if ("null".equals(texturePath)) return null; + if ("null".equals(texturePath)) return ""; else return texturePath; } diff --git a/src/main/java/net/landofrails/landofsignals/utils/HighlightingUtil.java b/src/main/java/net/landofrails/landofsignals/utils/HighlightingUtil.java index 49b79e48..8be5b728 100644 --- a/src/main/java/net/landofrails/landofsignals/utils/HighlightingUtil.java +++ b/src/main/java/net/landofrails/landofsignals/utils/HighlightingUtil.java @@ -1,11 +1,10 @@ package net.landofrails.landofsignals.utils; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import cam72cam.mod.resource.Identifier; import net.landofrails.landofsignals.LandOfSignals; -import org.lwjgl.opengl.GL11; import java.time.LocalDateTime; import java.util.ArrayList; @@ -16,7 +15,7 @@ public class HighlightingUtil { - private static OBJRender render; + private static OBJModel model; private static final Random RANDOM = new Random(); private static LocalDateTime colortime = LocalDateTime.now(); @@ -26,18 +25,23 @@ private HighlightingUtil(){ } @SuppressWarnings("java:S1141") - public static void renderHighlighting() { + public static void renderHighlighting(RenderState state) { try { - OBJRender render = getOBJRender(); - try (OpenGL.With ignored1 = OpenGL.matrix(); OpenGL.With ignored2 = render.bindTexture(getColor())) { - GL11.glTranslated(0.5,0,0.5); - render.draw(); + + OBJModel model = getOBJModel(); + state.translate(0.5, 0, 0.5); + try (OBJRender.Binding vbo = model.binder().texture(getColor()).bind(state)) { + + vbo.draw(); + } catch (Exception e) { // Not good, not bad enough to fail } + } catch (Exception e) { // Not good, not bad enough to fail } + } private static String getColor(){ @@ -53,17 +57,16 @@ private static String getColor(){ return color.getFolder(); } - private static OBJRender getOBJRender() throws Exception { - if(render == null){ - OBJModel model = new OBJModel(new Identifier(LandOfSignals.MODID, "models/block/landofsignals/connection-box/connection-box.obj"), 0, HighlightingColors.getAllColorsAsStrings()); - render = new OBJRender(model); + private static OBJModel getOBJModel() throws Exception { + if(model == null){ + model = new OBJModel(new Identifier(LandOfSignals.MODID, "models/block/landofsignals/connection-box/connection-box.obj"), 0, HighlightingColors.getAllColorsAsStrings()); } - return render; + return model; } private enum HighlightingColors { - WHITE(null), + WHITE(""), AMBER("amber"), BLACK("black"), BLUE_LIGHT("blue_light"), diff --git a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockButtonReceiverRenderEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockButtonReceiverRenderEntity.java index a6b39531..74cf9194 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockButtonReceiverRenderEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockButtonReceiverRenderEntity.java @@ -1,14 +1,11 @@ package net.landofrails.stellwand.content.entities.rendering; -import cam72cam.mod.MinecraftClient; -import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import net.landofrails.stellwand.content.entities.storage.BlockButtonReceiverStorageEntity; import net.landofrails.stellwand.utils.compact.IRotatableBlockEntity; -import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.stream.Collectors; @@ -18,7 +15,6 @@ public class BlockButtonReceiverRenderEntity implements IRotatableBlockEntity { private BlockButtonReceiverStorageEntity entity; private OBJModel model; - private OBJRender renderer; private float[] defaultRotation; private float[] defaultTranslation; @@ -45,25 +41,6 @@ public OBJModel getModel() { return model; } - public OBJRender getRenderer() { - if (renderer == null) { - if (entity.contentPackBlockId != null && BlockButtonReceiverStorageEntity.getModels().containsKey(entity.contentPackBlockId)) { - if (!BlockButtonReceiverStorageEntity.getRenderers().containsKey(entity.contentPackBlockId)) { - OBJModel m = BlockButtonReceiverStorageEntity.getModels().get(entity.contentPackBlockId); - BlockButtonReceiverStorageEntity.getRenderers().put(entity.contentPackBlockId, new OBJRender(m)); - } - renderer = BlockButtonReceiverStorageEntity.getRenderers().get(entity.contentPackBlockId); - } else { - if (BlockButtonReceiverStorageEntity.getRenderers().containsKey(BlockButtonReceiverStorageEntity.MISSING)) { - OBJModel m = BlockButtonReceiverStorageEntity.getModels().get(BlockButtonReceiverStorageEntity.MISSING); - BlockButtonReceiverStorageEntity.getRenderers().put(BlockButtonReceiverStorageEntity.MISSING, new OBJRender(m)); - } - renderer = BlockButtonReceiverStorageEntity.getRenderers().get(BlockButtonReceiverStorageEntity.MISSING); - } - } - return renderer; - } - public float[] getTranslation() { if (defaultTranslation == null) { if (entity.contentPackBlockId != null && BlockButtonReceiverStorageEntity.getTranslations().containsKey(entity.contentPackBlockId)) @@ -85,27 +62,28 @@ public float[] getRotation() { } public static StandardModel render(BlockButtonReceiverStorageEntity entity) { - return new StandardModel().addCustom(partialTicks -> renderStuff(entity, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(entity, state)); } @SuppressWarnings("java:S1172") - private static void renderStuff(BlockButtonReceiverStorageEntity entity, float partialTicks) { + private static void renderStuff(BlockButtonReceiverStorageEntity entity, RenderState state) { OBJModel model = entity.renderEntity.getModel(); - OBJRender renderer = entity.renderEntity.getRenderer(); float[] translation = entity.renderEntity.getTranslation(); float[] rotation = entity.renderEntity.getRotation(); String mode = entity.getActive() ? "on" : "off"; boolean wall = entity.getWallMounted(); + state.translate(translation[0], (wall ? .5 : 0) + translation[1], translation[2]); + state.rotate(entity.blockRotation + rotation[1], 0, 1, 0); + state.rotate((wall ? -90 : 0) + rotation[0], 1, 0, 0); + state.rotate(rotation[2], 0, 0, 1); + state.translate(0, (wall ? -.5 : 0), 0); + try { - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture()) { + try (OBJRender.Binding vbo = model.binder().bind(state)) { + - GL11.glTranslated(translation[0], (wall ? .5 : 0) + translation[1], translation[2]); - GL11.glRotated(entity.blockRotation + rotation[1], 0, 1, 0); - GL11.glRotated((wall ? -90 : 0) + rotation[0], 1, 0, 0); - GL11.glRotated(rotation[2], 0, 0, 1); - GL11.glTranslated(0, (wall ? -.5 : 0), 0); ArrayList modes = model.groups().stream().filter(s -> s.startsWith(mode)) @@ -115,9 +93,9 @@ private static void renderStuff(BlockButtonReceiverStorageEntity entity, float p ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } // Muss erst translated werden. @@ -131,51 +109,7 @@ private static void renderStuff(BlockButtonReceiverStorageEntity entity, float p } private static void renderMarking(BlockButtonReceiverStorageEntity entity) { - float[] color = entity.getMarkedColor(); - - // 0.5 is edge of block - final float margin = 0.51f; - - int[][] points = new int[][]{{+1, +1, +1}, {-1, -1, 1}, {-1, +1, -1}, {+1, -1, -1}}; - - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_TEXTURE_2D); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - double distance = MinecraftClient.getPlayer().getPosition().distanceTo(new Vec3d(entity.getPos())); - float width = (10f / (float) distance) + 1; - if (width < 0.01f) - width = 0.01f; - else if (width > 10f) - width = 10f; - GL11.glLineWidth(width); - GL11.glDepthMask(false); - - for (int[] point : points) { - for (short o = 0; o < 3; o++) { - - GL11.glColor3f(1, 1, 1); - GL11.glColor3f(color[0], color[1], color[2]); - - GL11.glBegin(GL11.GL_LINE_STRIP); - - GL11.glVertex3f(point[0] * margin, point[1] * margin, point[2] * margin); - int x = point[0] * (o == 0 ? -1 : 1); - int y = point[1] * (o == 1 ? -1 : 1); - int z = point[2] * (o == 2 ? -1 : 1); - GL11.glVertex3f(x * margin, y * margin, z * margin); - - GL11.glEnd(); - - } - } - - GL11.glDepthMask(true); - GL11.glPopAttrib(); - + // TODO Check if possible } } diff --git a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockFillerRenderEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockFillerRenderEntity.java index 76213095..d86b5c34 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockFillerRenderEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockFillerRenderEntity.java @@ -1,11 +1,9 @@ package net.landofrails.stellwand.content.entities.rendering; -import org.lwjgl.opengl.GL11; - import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import net.landofrails.stellwand.content.entities.storage.BlockFillerStorageEntity; import net.landofrails.stellwand.utils.compact.IRotatableBlockEntity; @@ -13,7 +11,6 @@ public class BlockFillerRenderEntity implements IRotatableBlockEntity { // Rendering private OBJModel model; - private OBJRender renderer; private float[] defaultRotation; private float[] defaultTranslation; @@ -42,25 +39,6 @@ public OBJModel getModel() { return model; } - public OBJRender getRenderer() { - if (renderer == null) { - if (entity.contentPackBlockId != null && BlockFillerStorageEntity.getModels().containsKey(entity.contentPackBlockId)) { - if (!BlockFillerStorageEntity.getRenderers().containsKey(entity.contentPackBlockId)) { - OBJModel m = BlockFillerStorageEntity.getModels().get(entity.contentPackBlockId); - BlockFillerStorageEntity.getRenderers().put(entity.contentPackBlockId, new OBJRender(m)); - } - renderer = BlockFillerStorageEntity.getRenderers().get(entity.contentPackBlockId); - } else { - if (BlockFillerStorageEntity.getRenderers().containsKey(BlockFillerStorageEntity.MISSING)) { - OBJModel m = BlockFillerStorageEntity.getModels().get(BlockFillerStorageEntity.MISSING); - BlockFillerStorageEntity.getRenderers().put(BlockFillerStorageEntity.MISSING, new OBJRender(m)); - } - renderer = BlockFillerStorageEntity.getRenderers().get(BlockFillerStorageEntity.MISSING); - } - } - return renderer; - } - public float[] getTranslation() { if (defaultTranslation == null) { if (entity.contentPackBlockId != null && BlockFillerStorageEntity.getTranslations().containsKey(entity.contentPackBlockId)) @@ -82,27 +60,24 @@ public float[] getRotation() { } public static StandardModel render(BlockFillerStorageEntity entity) { - return new StandardModel().addCustom(partialTicks -> renderStuff(entity, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(entity, state)); } - private static void renderStuff(BlockFillerStorageEntity entity, float partialTicks) { + private static void renderStuff(BlockFillerStorageEntity entity, RenderState state) { - OBJRender renderer = entity.renderEntity.getRenderer(); + OBJModel model = entity.renderEntity.getModel(); float[] translation = entity.renderEntity.getTranslation(); float[] rotation = entity.renderEntity.getRotation(); - try { - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture()) { - GL11.glTranslated(translation[0], translation[1], translation[2]); - - GL11.glRotated(rotation[0], 1, 0, 0); - GL11.glRotated(entity.blockRotation + rotation[1], 0, 1, 0); - GL11.glRotated(rotation[2], 0, 0, 1); + state.translate(translation[0], translation[1], translation[2]); - renderer.draw(); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(entity.blockRotation + rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); - } - } catch (Exception e) { + try (OBJRender.Binding vbo = model.binder().bind(state)) { + vbo.draw(); + }catch (Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockMultisignalRenderEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockMultisignalRenderEntity.java index ebe7577f..83f0edd2 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockMultisignalRenderEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockMultisignalRenderEntity.java @@ -1,14 +1,11 @@ package net.landofrails.stellwand.content.entities.rendering; -import cam72cam.mod.MinecraftClient; -import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import net.landofrails.stellwand.content.entities.storage.BlockMultisignalStorageEntity; import net.landofrails.stellwand.utils.compact.IRotatableBlockEntity; -import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.Map; @@ -19,7 +16,6 @@ public class BlockMultisignalRenderEntity implements IRotatableBlockEntity { private BlockMultisignalStorageEntity entity; private OBJModel model; - private OBJRender renderer; private float[] defaultRotation; private float[] defaultTranslation; @@ -46,25 +42,6 @@ public OBJModel getModel() { return model; } - public OBJRender getRenderer() { - if (renderer == null) { - if (entity.contentPackBlockId != null && BlockMultisignalStorageEntity.getModels().containsKey(entity.contentPackBlockId)) { - if (!BlockMultisignalStorageEntity.getRenderers().containsKey(entity.contentPackBlockId)) { - OBJModel m = BlockMultisignalStorageEntity.getModels().get(entity.contentPackBlockId); - BlockMultisignalStorageEntity.getRenderers().put(entity.contentPackBlockId, new OBJRender(m)); - } - renderer = BlockMultisignalStorageEntity.getRenderers().get(entity.contentPackBlockId); - } else { - if (BlockMultisignalStorageEntity.getRenderers().containsKey(BlockMultisignalStorageEntity.MISSING)) { - OBJModel m = BlockMultisignalStorageEntity.getModels().get(BlockMultisignalStorageEntity.MISSING); - BlockMultisignalStorageEntity.getRenderers().put(BlockMultisignalStorageEntity.MISSING, new OBJRender(m)); - } - renderer = BlockMultisignalStorageEntity.getRenderers().get(BlockMultisignalStorageEntity.MISSING); - } - } - return renderer; - } - public float[] getTranslation() { if (defaultTranslation == null) { if (entity.contentPackBlockId != null && BlockMultisignalStorageEntity.getTranslations().containsKey(entity.contentPackBlockId)) @@ -86,29 +63,30 @@ public float[] getRotation() { } public static StandardModel render(BlockMultisignalStorageEntity entity) { - return new StandardModel().addCustom(partialTicks -> renderStuff(entity, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(entity, state)); } @SuppressWarnings("java:S1172") - private static void renderStuff(BlockMultisignalStorageEntity entity, float partialTicks) { + private static void renderStuff(BlockMultisignalStorageEntity entity, RenderState state) { OBJModel model = entity.getRenderEntity().getModel(); - OBJRender renderer = entity.getRenderEntity().getRenderer(); float[] translation = entity.getRenderEntity().getTranslation(); float[] rotation = entity.getRenderEntity().getRotation(); Map displayModes = entity.getDisplayModes(); + state.translate(translation[0], translation[1], translation[2]); + + state.rotate(rotation[0], 1, 0, 0); + state.rotate(entity.blockRotation + rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + try { - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture()) { + try (OBJRender.Binding vbo = model.binder().bind(state)) { - GL11.glTranslated(translation[0], translation[1], translation[2]); - GL11.glRotated(rotation[0], 1, 0, 0); - GL11.glRotated(entity.blockRotation + rotation[1], 0, 1, 0); - GL11.glRotated(rotation[2], 0, 0, 1); if (displayModes == null || displayModes.isEmpty()) { - renderer.draw(); + vbo.draw(); } else { ArrayList modes = new ArrayList<>(); @@ -119,9 +97,9 @@ private static void renderStuff(BlockMultisignalStorageEntity entity, float part ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } @@ -137,54 +115,7 @@ private static void renderStuff(BlockMultisignalStorageEntity entity, float part } private static void renderMarking(BlockMultisignalStorageEntity entity) { - float[] color = entity.getMarkedColor(); - - // 0.5 is edge of block - final float margin = 0.51f; - - int[][] points = new int[][]{{+1, +1, +1}, {-1, -1, 1}, {-1, +1, -1}, {+1, -1, -1}}; - - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_TEXTURE_2D); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - double distance = MinecraftClient.getPlayer().getPosition().distanceTo(new Vec3d(entity.getPos())); - float width = (10f / (float) distance) + 1; - if (width < 0.01f) - width = 0.01f; - else if (width > 10f) - width = 10f; - GL11.glLineWidth(width); - GL11.glDepthMask(false); - - float[] translation = entity.getRenderEntity().getTranslation(); - GL11.glTranslated(0.0, 0.5 - translation[1], 0.0); - - for (int[] point : points) { - for (short o = 0; o < 3; o++) { - - GL11.glColor3f(1, 1, 1); - GL11.glColor3f(color[0], color[1], color[2]); - - GL11.glBegin(GL11.GL_LINE_STRIP); - - GL11.glVertex3f(point[0] * margin, point[1] * margin, point[2] * margin); - int x = point[0] * (o == 0 ? -1 : 1); - int y = point[1] * (o == 1 ? -1 : 1); - int z = point[2] * (o == 2 ? -1 : 1); - GL11.glVertex3f(x * margin, y * margin, z * margin); - - GL11.glEnd(); - - } - } - - GL11.glDepthMask(true); - GL11.glPopAttrib(); - + // TODO Check if possible } } diff --git a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSenderRenderEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSenderRenderEntity.java index af818149..f957902f 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSenderRenderEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSenderRenderEntity.java @@ -1,11 +1,9 @@ package net.landofrails.stellwand.content.entities.rendering; -import org.lwjgl.opengl.GL11; - import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import net.landofrails.stellwand.content.entities.storage.BlockSenderStorageEntity; import net.landofrails.stellwand.utils.compact.IRotatableBlockEntity; @@ -43,25 +41,6 @@ public OBJModel getModel() { return model; } - public OBJRender getRenderer() { - if (renderer == null) { - if (entity.contentPackBlockId != null && BlockSenderStorageEntity.getModels().containsKey(entity.contentPackBlockId)) { - if (!BlockSenderStorageEntity.getRenderers().containsKey(entity.contentPackBlockId)) { - OBJModel m = BlockSenderStorageEntity.getModels().get(entity.contentPackBlockId); - BlockSenderStorageEntity.getRenderers().put(entity.contentPackBlockId, new OBJRender(m)); - } - renderer = BlockSenderStorageEntity.getRenderers().get(entity.contentPackBlockId); - } else { - if (BlockSenderStorageEntity.getRenderers().containsKey(BlockSenderStorageEntity.MISSING)) { - OBJModel m = BlockSenderStorageEntity.getModels().get(BlockSenderStorageEntity.MISSING); - BlockSenderStorageEntity.getRenderers().put(BlockSenderStorageEntity.MISSING, new OBJRender(m)); - } - renderer = BlockSenderStorageEntity.getRenderers().get(BlockSenderStorageEntity.MISSING); - } - } - return renderer; - } - public float[] getTranslation() { if (defaultTranslation == null) { if (entity.contentPackBlockId != null && BlockSenderStorageEntity.getTranslations().containsKey(entity.contentPackBlockId)) @@ -83,25 +62,24 @@ public float[] getRotation() { } public static StandardModel render(BlockSenderStorageEntity entity) { - return new StandardModel().addCustom(partialTicks -> renderStuff(entity, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(entity, state)); } - private static void renderStuff(BlockSenderStorageEntity entity, float partialTicks) { + private static void renderStuff(BlockSenderStorageEntity entity, RenderState state) { - OBJRender renderer = entity.renderEntity.getRenderer(); + OBJModel model = entity.renderEntity.getModel(); float[] translation = entity.renderEntity.getTranslation(); float[] rotation = entity.renderEntity.getRotation(); - try { - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture()) { - GL11.glTranslated(translation[0], translation[1], translation[2]); - - GL11.glRotated(rotation[0], 1, 0, 0); - GL11.glRotated(entity.blockRotation + rotation[1], 0, 1, 0); - GL11.glRotated(rotation[2], 0, 0, 1); + state.translate(translation[0], translation[1], translation[2]); - renderer.draw(); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(entity.blockRotation + rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + try { + try (OBJRender.Binding vbo = model.binder().bind(state)) { + vbo.draw(); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSignalRenderEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSignalRenderEntity.java index 01e988db..381163bc 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSignalRenderEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/rendering/BlockSignalRenderEntity.java @@ -1,14 +1,11 @@ package net.landofrails.stellwand.content.entities.rendering; -import cam72cam.mod.MinecraftClient; -import cam72cam.mod.math.Vec3d; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; +import cam72cam.mod.render.opengl.RenderState; import net.landofrails.stellwand.content.entities.storage.BlockSignalStorageEntity; import net.landofrails.stellwand.utils.compact.IRotatableBlockEntity; -import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.stream.Collectors; @@ -45,25 +42,6 @@ public OBJModel getModel() { return model; } - public OBJRender getRenderer() { - if (renderer == null) { - if (entity.contentPackBlockId != null && BlockSignalStorageEntity.getModels().containsKey(entity.contentPackBlockId)) { - if (!BlockSignalStorageEntity.getRenderers().containsKey(entity.contentPackBlockId)) { - OBJModel m = BlockSignalStorageEntity.getModels().get(entity.contentPackBlockId); - BlockSignalStorageEntity.getRenderers().put(entity.contentPackBlockId, new OBJRender(m)); - } - renderer = BlockSignalStorageEntity.getRenderers().get(entity.contentPackBlockId); - } else { - if (BlockSignalStorageEntity.getRenderers().containsKey(BlockSignalStorageEntity.MISSING)) { - OBJModel m = BlockSignalStorageEntity.getModels().get(BlockSignalStorageEntity.MISSING); - BlockSignalStorageEntity.getRenderers().put(BlockSignalStorageEntity.MISSING, new OBJRender(m)); - } - renderer = BlockSignalStorageEntity.getRenderers().get(BlockSignalStorageEntity.MISSING); - } - } - return renderer; - } - public float[] getTranslation() { if (defaultTranslation == null) { if (entity.contentPackBlockId != null && BlockSignalStorageEntity.getTranslations().containsKey(entity.contentPackBlockId)) @@ -85,29 +63,29 @@ public float[] getRotation() { } public static StandardModel render(BlockSignalStorageEntity entity) { - return new StandardModel().addCustom(partialTicks -> renderStuff(entity, partialTicks)); + return new StandardModel().addCustom((state, partialTicks) -> renderStuff(entity, state)); } @SuppressWarnings("java:S1172") - private static void renderStuff(BlockSignalStorageEntity entity, float partialTicks) { + private static void renderStuff(BlockSignalStorageEntity entity, RenderState state) { OBJModel model = entity.renderEntity.getModel(); - OBJRender renderer = entity.renderEntity.getRenderer(); float[] translation = entity.renderEntity.getTranslation(); float[] rotation = entity.renderEntity.getRotation(); String mode = entity.getDisplayMode(); - try { - try (OpenGL.With matrix = OpenGL.matrix(); OpenGL.With tex = renderer.bindTexture()) { - GL11.glTranslated(translation[0], translation[1], translation[2]); + state.translate(translation[0], translation[1], translation[2]); + + state.rotate(rotation[0], 1, 0, 0); + state.rotate(entity.blockRotation + rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); - GL11.glRotated(rotation[0], 1, 0, 0); - GL11.glRotated(entity.blockRotation + rotation[1], 0, 1, 0); - GL11.glRotated(rotation[2], 0, 0, 1); + try { + try (OBJRender.Binding vbo = model.binder().bind(state)) { if (mode == null) { - renderer.draw(); + vbo.draw(); } else { ArrayList modes = model.groups().stream().filter(s -> s.startsWith(mode)) @@ -117,9 +95,9 @@ private static void renderStuff(BlockSignalStorageEntity entity, float partialTi ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } @@ -135,51 +113,7 @@ private static void renderStuff(BlockSignalStorageEntity entity, float partialTi } private static void renderMarking(BlockSignalStorageEntity entity) { - float[] color = entity.getMarkedColor(); - - // 0.5 is edge of block - final float margin = 0.51f; - - int[][] points = new int[][]{{+1, +1, +1}, {-1, -1, 1}, {-1, +1, -1}, {+1, -1, -1}}; - - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_TEXTURE_2D); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - double distance = MinecraftClient.getPlayer().getPosition().distanceTo(new Vec3d(entity.getPos())); - float width = (10f / (float) distance) + 1; - if (width < 0.01f) - width = 0.01f; - else if (width > 10f) - width = 10f; - GL11.glLineWidth(width); - GL11.glDepthMask(false); - - for (int[] point : points) { - for (short o = 0; o < 3; o++) { - - GL11.glColor3f(1, 1, 1); - GL11.glColor3f(color[0], color[1], color[2]); - - GL11.glBegin(GL11.GL_LINE_STRIP); - - GL11.glVertex3f(point[0] * margin, point[1] * margin, point[2] * margin); - int x = point[0] * (o == 0 ? -1 : 1); - int y = point[1] * (o == 1 ? -1 : 1); - int z = point[2] * (o == 2 ? -1 : 1); - GL11.glVertex3f(x * margin, y * margin, z * margin); - - GL11.glEnd(); - - } - } - - GL11.glDepthMask(true); - GL11.glPopAttrib(); - + // TODO Check if possible } } diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockButtonReceiverStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockButtonReceiverStorageEntity.java index a2dcbb66..df3d7a3e 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockButtonReceiverStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockButtonReceiverStorageEntity.java @@ -2,7 +2,6 @@ import cam72cam.mod.ModCore; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.serialization.TagField; @@ -24,7 +23,6 @@ public class BlockButtonReceiverStorageEntity extends BlockButtonReceiverFunctio // Statics public static final String MISSING = "missing"; protected static Map models = new HashMap<>(); - protected static Map renderers = new HashMap<>(); protected static Map rotations = new HashMap<>(); protected static Map translations = new HashMap<>(); protected static Map wallMountable = new HashMap<>(); @@ -136,10 +134,6 @@ public static Map getModels() { return models; } - public static Map getRenderers() { - return renderers; - } - public static Map getRotations() { return rotations; } @@ -161,14 +155,6 @@ public float[] getMarkedColor() { return markedColor; } - /** - * Releases the renderer in to the wild and frees the cache preventing a deadlock situation - */ - public static void releaseRenderersIntoTheWild() { - getRenderers().forEach((k, v) -> v.free()); - getRenderers().clear(); - } - // Map old versions to newer ones @Override public void load(TagCompound nbt) { diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockFillerStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockFillerStorageEntity.java index 13a84bbf..7b7432be 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockFillerStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockFillerStorageEntity.java @@ -2,7 +2,6 @@ import cam72cam.mod.ModCore; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.serialization.TagField; @@ -27,7 +26,6 @@ public class BlockFillerStorageEntity extends BlockFillerFunctionEntity { public static final String MISSING = "missing"; protected static Map models = new HashMap<>(); - protected static Map renderers = new HashMap<>(); protected static Map rotations = new HashMap<>(); protected static Map translations = new HashMap<>(); protected static Map directionFrom = new HashMap<>(); @@ -110,10 +108,6 @@ public static Map getModels() { return models; } - public static Map getRenderers() { - return renderers; - } - public static Map getRotations() { return rotations; } @@ -122,14 +116,6 @@ public static Map getTranslations() { return translations; } - /** - * Releases the renderer in to the wild and frees the cache preventing a deadlock situation - */ - public static void releaseRenderersIntoTheWild() { - getRenderers().forEach((k, v) -> v.free()); - getRenderers().clear(); - } - // Map old versions to newer ones @Override public void load(TagCompound nbt) { diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockMultisignalStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockMultisignalStorageEntity.java index 8e6c92c3..44dd4496 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockMultisignalStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockMultisignalStorageEntity.java @@ -3,7 +3,6 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.serialization.TagField; @@ -27,7 +26,6 @@ public class BlockMultisignalStorageEntity extends BlockMultisignalFunctionEntit // Statics public static final String MISSING = "missing"; protected static Map models = new HashMap<>(); - protected static Map renderers = new HashMap<>(); protected static Map rotations = new HashMap<>(); protected static Map translations = new HashMap<>(); protected static Map>> possibleModes = new LinkedHashMap<>(); @@ -194,10 +192,6 @@ public static Map getModels() { return models; } - public static Map getRenderers() { - return renderers; - } - public static Map getRotations() { return rotations; } @@ -219,14 +213,6 @@ public float[] getMarkedColor() { return markedColor; } - /** - * Releases the renderer in to the wild and frees the cache preventing a deadlock situation - */ - public static void releaseRenderersIntoTheWild() { - getRenderers().forEach((k, v) -> v.free()); - getRenderers().clear(); - } - // Map old versions to newer ones @Override public void load(TagCompound nbt) { diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java index d5096222..ea3f9b31 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSenderStorageEntity.java @@ -4,7 +4,6 @@ import cam72cam.mod.block.BlockEntity; import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.serialization.TagField; @@ -31,7 +30,6 @@ public class BlockSenderStorageEntity extends BlockSenderFunctionEntity { public static final String MISSING = "missing"; protected static Map models = new HashMap<>(); - protected static Map renderers = new HashMap<>(); protected static Map rotations = new HashMap<>(); protected static Map translations = new HashMap<>(); protected static Map directionFrom = new HashMap<>(); @@ -172,10 +170,6 @@ public static Map getModels() { return models; } - public static Map getRenderers() { - return renderers; - } - public static Map getRotations() { return rotations; } @@ -184,14 +178,6 @@ public static Map getTranslations() { return translations; } - /** - * Releases the renderer in to the wild and frees the cache preventing a deadlock situation - */ - public static void releaseRenderersIntoTheWild() { - getRenderers().forEach((k, v) -> v.free()); - getRenderers().clear(); - } - // Map old versions to newer ones @Override public void load(TagCompound nbt) { diff --git a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSignalStorageEntity.java b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSignalStorageEntity.java index 2dcf0e04..e98afd02 100644 --- a/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSignalStorageEntity.java +++ b/src/main/java/net/landofrails/stellwand/content/entities/storage/BlockSignalStorageEntity.java @@ -3,7 +3,6 @@ import cam72cam.mod.ModCore; import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; -import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; import cam72cam.mod.serialization.TagCompound; import cam72cam.mod.serialization.TagField; @@ -29,7 +28,6 @@ public class BlockSignalStorageEntity extends BlockSignalFunctionEntity { // Statics public static final String MISSING = "missing"; protected static Map models = new HashMap<>(); - protected static Map renderers = new HashMap<>(); protected static Map rotations = new HashMap<>(); protected static Map translations = new HashMap<>(); protected static Map> possibleModes = new HashMap<>(); @@ -164,10 +162,6 @@ public static Map getModels() { return models; } - public static Map getRenderers() { - return renderers; - } - public static Map getRotations() { return rotations; } @@ -189,14 +183,6 @@ public float[] getMarkedColor() { return markedColor; } - /** - * Releases the renderer in to the wild and frees the cache preventing a deadlock situation - */ - public static void releaseRenderersIntoTheWild() { - getRenderers().forEach((k, v) -> v.free()); - getRenderers().clear(); - } - // Map old versions to newer ones @Override public void load(TagCompound nbt) { diff --git a/src/main/java/net/landofrails/stellwand/content/guis/SelectSenderModes.java b/src/main/java/net/landofrails/stellwand/content/guis/SelectSenderModes.java index a93dcd63..c77d2f78 100644 --- a/src/main/java/net/landofrails/stellwand/content/guis/SelectSenderModes.java +++ b/src/main/java/net/landofrails/stellwand/content/guis/SelectSenderModes.java @@ -9,13 +9,12 @@ import cam72cam.mod.gui.screen.IScreenBuilder; import cam72cam.mod.item.ItemStack; import cam72cam.mod.math.Vec3i; -import cam72cam.mod.render.OpenGL; import net.landofrails.landofsignals.gui.GuiText; import net.landofrails.stellwand.content.entities.storage.BlockSenderStorageEntity; import net.landofrails.stellwand.content.messages.EMessage; import net.landofrails.stellwand.content.network.ChangeSenderModes; import net.landofrails.stellwand.utils.compact.SignalContainer; -import org.lwjgl.opengl.GL11; +import util.Matrix4; import java.util.Collection; import java.util.LinkedList; @@ -150,22 +149,22 @@ public void draw(IScreenBuilder builder) { private void drawBlocks(IScreenBuilder builder) { int scale = 8; - try (OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated( - (double) GUIHelpers.getScreenWidth() / 2 - + (double) builder.getWidth() / 4, - (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemPowerOn, 0, 0); - } - try (OpenGL.With ignored = OpenGL.matrix()) { - GL11.glTranslated( - ((double) GUIHelpers.getScreenWidth() / 2 - - (double) builder.getWidth() / 4) - 120, - (double) builder.getHeight() / 4, 0); - GL11.glScaled(scale, scale, 1); - GUIHelpers.drawItem(itemPowerOff, 0, 0); - } + Matrix4 matrix = new Matrix4(); + matrix.translate( + (double) GUIHelpers.getScreenWidth() / 2 + + (double) builder.getWidth() / 4, + (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemPowerOn, 0, 0, matrix); + + matrix = new Matrix4(); + matrix.translate( + ((double) GUIHelpers.getScreenWidth() / 2 + - (double) builder.getWidth() / 4) - 120, + (double) builder.getHeight() / 4, 0); + matrix.scale(scale, scale, 1); + GUIHelpers.drawItem(itemPowerOff, 0, 0, matrix); + } @SuppressWarnings("java:S2259") diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButton.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButton.java index 8f98cb99..041fd87d 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButton.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButton.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -37,7 +35,6 @@ public class ItemBlockButton extends CustomItem { // VARIABLES public static final String MISSING = "missing"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -130,7 +127,7 @@ public void onClickAir(Player player, World world, Player.Hand hand) { public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockButtonReceiver.init(); @@ -140,13 +137,6 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); - float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); // Enables the gui to display different modes @@ -154,16 +144,18 @@ public static ItemRender.IItemModel getModelFor() { String mode = customMode != null ? customMode : modes.get(itemId); float scale = scales.get(itemId); OBJModel model = models.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); + + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().bind(state)) { if (mode == null) { - renderer.draw(); + vbo.draw(); } else { @@ -174,9 +166,9 @@ public static ItemRender.IItemModel getModelFor() { ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButtonReceiver.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButtonReceiver.java index b54e7257..25c4dded 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButtonReceiver.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockButtonReceiver.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -37,7 +35,6 @@ public class ItemBlockButtonReceiver extends CustomItem { // VARIABLES public static final String MISSING = "missing"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -130,7 +127,7 @@ public void onClickAir(Player player, World world, Player.Hand hand) { public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockButtonReceiver.init(); @@ -140,13 +137,6 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); - float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); // Enables the gui to display different modes @@ -154,16 +144,18 @@ public static ItemRender.IItemModel getModelFor() { String mode = customMode != null ? customMode : modes.get(itemId); float scale = scales.get(itemId); OBJModel model = models.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); + + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().bind(state)) { if (mode == null) { - renderer.draw(); + vbo.draw(); } else { @@ -174,9 +166,9 @@ public static ItemRender.IItemModel getModelFor() { ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockFiller.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockFiller.java index 28c07c22..b5a96d3e 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockFiller.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockFiller.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -35,7 +33,6 @@ public class ItemBlockFiller extends CustomItem { public static final String MISSING = "missing"; private static final String ITEMID = "itemId"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -94,39 +91,41 @@ public List getTooltip(ItemStack itemStack) { // Init class public static void init() { - if (renderers.isEmpty()) { + if(!models.isEmpty()) + return; + + try { + Identifier id = new Identifier(Stellwand.DOMAIN, "models/block/others/blocknotfound/blocknotfound.obj"); + OBJModel model = new OBJModel(id, 0); + models.put(MISSING, model); + // Renderers in render function + rotations.put(MISSING, new float[]{15, 195, 0}); + translations.put(MISSING, new float[]{0.5f, 0.5f, 0.5f}); + scales.put(MISSING, 0.7f); + } catch (Exception e) { + e.printStackTrace(); + } + + // ContentPack + for (Entry entry : Content.getBlockFillers().entrySet()) { try { - Identifier id = new Identifier(Stellwand.DOMAIN, "models/block/others/blocknotfound/blocknotfound.obj"); + ContentPackEntry cpe = entry.getKey(); + String packId = entry.getValue(); + String itemName = cpe.getBlockId(packId); + ContentPackEntryItem item = cpe.getItem(); + Identifier id = new Identifier("stellwand", item.getModel()); OBJModel model = new OBJModel(id, 0); - models.put(MISSING, model); + + models.put(itemName, model); // Renderers in render function - rotations.put(MISSING, new float[]{15, 195, 0}); - translations.put(MISSING, new float[]{0.5f, 0.5f, 0.5f}); - scales.put(MISSING, 0.7f); + rotations.put(itemName, item.getRotation()); + translations.put(itemName, item.getTranslation()); + scales.put(itemName, 0.7f); } catch (Exception e) { e.printStackTrace(); } - - // ContentPack - for (Entry entry : Content.getBlockFillers().entrySet()) { - try { - ContentPackEntry cpe = entry.getKey(); - String packId = entry.getValue(); - String itemName = cpe.getBlockId(packId); - ContentPackEntryItem item = cpe.getItem(); - Identifier id = new Identifier("stellwand", item.getModel()); - OBJModel model = new OBJModel(id, 0); - - models.put(itemName, model); - // Renderers in render function - rotations.put(itemName, item.getRotation()); - translations.put(itemName, item.getTranslation()); - scales.put(itemName, 0.7f); - } catch (Exception e) { - e.printStackTrace(); - } - } } + } @Override @@ -152,7 +151,7 @@ private boolean isStandingInBlock(Vec3i vec3i) { @SuppressWarnings({"java:S3776", "java:S112"}) public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockFiller.init(); @@ -162,25 +161,20 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); + OBJModel model = models.get(itemId); float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); float scale = scales.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); - renderer.draw(); + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + try (OBJRender.Binding vbo = model.binder().bind(state)) { + vbo.draw(); } }); } diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockMultisignal.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockMultisignal.java index 4f5a2d89..0366a83f 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockMultisignal.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockMultisignal.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -37,7 +35,6 @@ public class ItemBlockMultisignal extends CustomItem { // VARIABLES public static final String MISSING = "missing"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -130,7 +127,7 @@ public void onClickAir(Player player, World world, Player.Hand hand) { public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockMultisignal.init(); @@ -140,13 +137,6 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); - float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); // Enables the gui to display different modes @@ -154,16 +144,18 @@ public static ItemRender.IItemModel getModelFor() { String mode = customMode != null ? customMode : modeList.get(itemId); float scale = scales.get(itemId); OBJModel model = models.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); + + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().bind(state)) { if (mode == null) { - renderer.draw(); + vbo.draw(); } else { @@ -172,9 +164,9 @@ public static ItemRender.IItemModel getModelFor() { if (!modes.isEmpty()) { model.groups().stream().filter(s -> s.startsWith("general")).forEach(modes::add); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } @@ -205,5 +197,4 @@ public List getTooltip(ItemStack itemStack) { return Collections.singletonList(lore); } - } diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSender.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSender.java index 27fb7538..21d0b0aa 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSender.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSender.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -35,7 +33,6 @@ public class ItemBlockSender extends CustomItem { private static final String ITEMID = "itemId"; public static final String MISSING = "missing"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -94,7 +91,7 @@ public List getTooltip(ItemStack itemStack) { // Init class public static void init() { - if (renderers.isEmpty()) { + if (models.isEmpty()) { try { Identifier id = new Identifier(Stellwand.DOMAIN, "models/block/others/blocknotfound/blocknotfound.obj"); OBJModel model = new OBJModel(id, 0); @@ -153,7 +150,7 @@ private boolean isStandingInBlock(Vec3i vec3i) { @SuppressWarnings({"java:S3776", "java:S112"}) public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockSender.init(); @@ -163,25 +160,20 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); + OBJModel model = models.get(itemId); float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); float scale = scales.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); - renderer.draw(); + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + try (OBJRender.Binding vbo = model.binder().bind(state)) { + vbo.draw(); } }); } diff --git a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSignal.java b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSignal.java index ae17f88e..cf51f39f 100644 --- a/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSignal.java +++ b/src/main/java/net/landofrails/stellwand/content/items/ItemBlockSignal.java @@ -9,7 +9,6 @@ import cam72cam.mod.math.Vec3i; import cam72cam.mod.model.obj.OBJModel; import cam72cam.mod.render.ItemRender; -import cam72cam.mod.render.OpenGL; import cam72cam.mod.render.StandardModel; import cam72cam.mod.render.obj.OBJRender; import cam72cam.mod.resource.Identifier; @@ -24,7 +23,6 @@ import net.landofrails.stellwand.contentpacks.Content; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry; import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryItem; -import org.lwjgl.opengl.GL11; import java.util.*; import java.util.Map.Entry; @@ -37,7 +35,6 @@ public class ItemBlockSignal extends CustomItem { // VARIABLES public static final String MISSING = "missing"; private static Map models = new HashMap<>(); - private static Map renderers = new HashMap<>(); private static Map rotations = new HashMap<>(); private static Map translations = new HashMap<>(); private static Map scales = new HashMap<>(); @@ -130,7 +127,7 @@ public void onClickAir(Player player, World world, Player.Hand hand) { public static ItemRender.IItemModel getModelFor() { - return (world, stack) -> new StandardModel().addCustom(() -> { + return (world, stack) -> new StandardModel().addCustom((state, partialTicks) -> { ItemBlockSignal.init(); @@ -140,13 +137,6 @@ public static ItemRender.IItemModel getModelFor() { itemId = MISSING; } - if (renderers.get(itemId) == null) { - OBJModel model = models.get(itemId); - renderers.put(itemId, new OBJRender(model)); - } - - OBJRender renderer = renderers.get(itemId); - float[] translate = translations.get(itemId); float[] rotation = rotations.get(itemId); // Enables the gui to display different modes @@ -154,16 +144,18 @@ public static ItemRender.IItemModel getModelFor() { String mode = customMode != null ? customMode : modes.get(itemId); float scale = scales.get(itemId); OBJModel model = models.get(itemId); - try (OpenGL.With ignored = OpenGL.matrix(); OpenGL.With ignored1 = renderer.bindTexture()) { - GL11.glTranslated(translate[0], translate[1], translate[2]); - GL11.glRotatef(rotation[0], 1, 0, 0); - GL11.glRotatef(rotation[1], 0, 1, 0); - GL11.glRotatef(rotation[2], 0, 0, 1); - GL11.glScaled(scale, scale, scale); + + state.translate(translate[0], translate[1], translate[2]); + state.rotate(rotation[0], 1, 0, 0); + state.rotate(rotation[1], 0, 1, 0); + state.rotate(rotation[2], 0, 0, 1); + state.scale(scale, scale, scale); + + try (OBJRender.Binding vbo = model.binder().bind(state)) { if (mode == null) { - renderer.draw(); + vbo.draw(); } else { @@ -174,9 +166,9 @@ public static ItemRender.IItemModel getModelFor() { ArrayList generals = model.groups().stream().filter(s -> s.startsWith("general")) .collect(Collectors.toCollection(ArrayList::new)); modes.addAll(generals); - renderer.drawGroups(modes); + vbo.draw(modes); } else { - renderer.drawGroups(model.groups()); + vbo.draw(model.groups()); } } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info deleted file mode 100644 index d386cbbf..00000000 --- a/src/main/resources/mcmod.info +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "modid": "landofsignals", - "name": "LandOfSignals", - "description": "Adds fancy railroad signals, signs, decor and other stuff to the game. Use best in combination with a train mod.", - "version": "1.2.0", - "mcversion": "1.12.2", - "url": "https://discord.gg/ykAqHKYjVM", - "updateUrl": "https://www.curseforge.com/minecraft/mc-mods/landofsignals", - "authorList": ["SeltixSub#2272", "MarkenJaden#7787"], - "credits": "", - "logoFile": "", - "screenshots": [], - "dependencies": [] - } -] diff --git a/template.gradle b/template.gradle new file mode 100644 index 00000000..7dede7a0 --- /dev/null +++ b/template.gradle @@ -0,0 +1,34 @@ +//BUILDSCRIPT// + +//PLUGINS// +apply plugin: 'maven-publish' + + +version = '#MINECRAFT#-#LOADER#-#VERSION#' +if (!"release".equalsIgnoreCase(System.getProperty("target"))) { + try { + version += "-" + 'git rev-parse --verify --short=7 HEAD'.execute().text.trim() + } catch (Exception ex) { + version += "-unknown" + } +} +group = "net.landofrails.landofsignals" +archivesBaseName = "LandOfSignals" + +//MINECRAFT// + +//DEPENDENCIES// + +//JAR// + +task('showBuildInfo') { + doLast { + String minecraftString = "#MINECRAFT#" + String minecraftLoader = "#LOADER#" + String umcVersionString = "#MINECRAFT#-#LOADER#-#UMC_VERSION#" + System.out.println("Build for MC #MINECRAFT# (#LOADER#)") + System.out.println("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/${umcVersionString}/UniversalModCore-${umcVersionString}.jar") + } +} + +build.finalizedBy showBuildInfo diff --git a/umc.json b/umc.json new file mode 100644 index 00000000..12dd84b8 --- /dev/null +++ b/umc.json @@ -0,0 +1,13 @@ +{ + "mod": { + "pkg": "net.landofrails.landofsignals", + "cls": "LandOfSignals", + "name": "LandOfSignals", + "id": "landofsignals", + "version": "1.2.0", + "dependencies": {} + }, + "umc": { + "version": "latest" + } +}