diff --git a/build.gradle b/build.gradle index cd4419d7a..d9f91d49f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id "eclipse" id "idea" id "java-library" - id "net.neoforged.gradle.userdev" version "7.0.192" + id "net.neoforged.gradle.userdev" version "7.1.25" id "me.modmuss50.mod-publish-plugin" version "0.5.2" } @@ -35,12 +35,12 @@ dependencies { implementation "net.neoforged:neoforge:${neoforge_version}" // ModernFix -// runtimeOnly "curse.maven:modernfix-790626:6171686" +// runtimeOnly "curse.maven:modernfix-790626:7969600" // Sodium - compileOnly "net.caffeinemc:sodium-neoforge-mod:0.8.1+mc1.21.11" -// runtimeOnly "net.caffeinemc:sodium-neoforge:0.8.1+mc1.21.11" + compileOnly "net.caffeinemc:sodium-neoforge-mod:0.8.10+mc26.1.2" +// runtimeOnly "net.caffeinemc:sodium-neoforge:0.8.10+mc26.1.2" // Iris -// runtimeOnly "maven.modrinth:iris:1.10.3+1.21.11-neoforge" +// runtimeOnly "maven.modrinth:iris:1.10.9+26.1-neoforge" // Just Enough Items // runtimeOnly "curse.maven:jei-238222:${just_enough_items_file}" diff --git a/gradle.properties b/gradle.properties index 07e8b1246..6c9f142fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false # Minecraft -minecraft_version=1.21.11 -minecraft_dependency=[1.21.11,1.22) -minecraft_suffix=mc1.21.11 -java_target=21 -java_dependency=>=21 -resource_pack_format=75 +minecraft_version=26.1.2 +minecraft_dependency=[26.1,26.2) +minecraft_suffix=mc26.1 +java_target=25 +java_dependency=>=25 +resource_pack_format=84 # NeoForge -neoforge_version=21.11.12-beta -neoforge_dependency=[21.11.12-beta,) +neoforge_version=26.1.2.30-beta +neoforge_dependency=[26.1.2.30-beta,) javafml_dependency=[1,) # Mixin @@ -36,7 +36,7 @@ maven_group=com.supermartijn642 # Publishing publishing_release_type=stable -publishing_game_versions=1.21.11 +publishing_game_versions=26.1 26.1.1 26.1.2 curseforge_project_id=854949 curseforge_required_dependency_ids= curseforge_optional_dependency_ids= @@ -45,4 +45,4 @@ modrinth_required_dependency_ids= modrinth_optional_dependency_ids= # Runtime mods -just_enough_items_file=5630564 +just_enough_items_file=8014757 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2..1b33c55ba 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 index ff23a68d7..1a704683a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 4f906e0c8..23d15a936 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,81 +15,115 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -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"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +132,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; 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 - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - 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" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -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" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd32c..db3a6ac20 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @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%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/com/supermartijn642/fusion/FusionClient.java b/src/main/java/com/supermartijn642/fusion/FusionClient.java index fceaf24bc..96ddadab6 100644 --- a/src/main/java/com/supermartijn642/fusion/FusionClient.java +++ b/src/main/java/com/supermartijn642/fusion/FusionClient.java @@ -13,6 +13,7 @@ import com.supermartijn642.fusion.util.IdentifierUtil; import net.minecraft.client.renderer.chunk.ChunkSectionLayer; import net.minecraft.resources.Identifier; +import net.minecraft.util.Unit; import net.neoforged.fml.ModList; import net.neoforged.fml.ModLoadingContext; import net.neoforged.neoforge.client.event.ModelEvent; @@ -29,7 +30,7 @@ public class FusionClient { public static final Logger LOGGER = LoggerFactory.getLogger("fusion"); - public static final ThreadLocal IS_RENDERING_BREAKING_OVERLAY = new ThreadLocal<>(); + public static final ThreadLocal IS_RENDERING_BREAKING_OVERLAY = new ThreadLocal<>(); public static void init(){ // Register default texture types @@ -85,27 +86,6 @@ public static void init(){ // ClientLifecycleEvents.CLIENT_STARTED.register(client -> PredicateRegistryImpl.finalizeRegistration()); } - public static Optional getChunkLayer(BaseTextureData.RenderType renderType){ - if(renderType == null) - return Optional.empty(); - ChunkSectionLayer material; - //noinspection EnhancedSwitchMigration - switch(renderType){ - case OPAQUE: - material = ChunkSectionLayer.SOLID; - break; - case CUTOUT: - material = ChunkSectionLayer.CUTOUT; - break; - case TRANSLUCENT: - material = ChunkSectionLayer.TRANSLUCENT; - break; - default: - throw new AssertionError(); - } - return Optional.of(material); - } - private static String fusionVersion; public static String getFusionVersion(){ diff --git a/src/main/java/com/supermartijn642/fusion/api/model/BlockModelBakingContext.java b/src/main/java/com/supermartijn642/fusion/api/model/BlockModelBakingContext.java index dda1234ab..addb46044 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/BlockModelBakingContext.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/BlockModelBakingContext.java @@ -1,12 +1,10 @@ package com.supermartijn642.fusion.api.model; -import com.supermartijn642.fusion.util.TextureAtlases; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.Material; +import net.minecraft.client.renderer.block.dispatch.ModelState; import net.minecraft.client.resources.model.ModelBaker; -import net.minecraft.client.resources.model.ModelState; -import net.minecraft.client.resources.model.UnbakedGeometry; +import net.minecraft.client.resources.model.cuboid.ItemTransforms; +import net.minecraft.client.resources.model.geometry.UnbakedGeometry; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; import net.minecraft.util.context.ContextMap; import org.jetbrains.annotations.Nullable; @@ -24,27 +22,12 @@ public interface BlockModelBakingContext { ModelBaker getModelBaker(); /** - * Gets the sprite for the given material. - * @param identifier identifier for the sprite + * Bakes the given material. + * @param material material to bake */ - TextureAtlasSprite getTexture(SpriteIdentifier identifier); + Material.Baked bakeMaterial(Material material); - /** - * Gets the sprite for the given atlas and texture. - * @param atlas atlas which the texture is stitched to - * @param texture texture identifier - */ - default TextureAtlasSprite getTexture(Identifier atlas, Identifier texture){ - return this.getTexture(SpriteIdentifier.of(atlas, texture)); - } - - /** - * Gets the sprite for the given texture on the block atlas. - * @param texture texture identifier - */ - default TextureAtlasSprite getBlockTexture(Identifier texture){ - return this.getTexture(TextureAtlases.getBlocks(), texture); - } + Material missingMaterial(); /** * @return the transformations which should be applied to the model diff --git a/src/main/java/com/supermartijn642/fusion/api/model/DefaultModelTypes.java b/src/main/java/com/supermartijn642/fusion/api/model/DefaultModelTypes.java index 892a3d927..0e3b458e5 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/DefaultModelTypes.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/DefaultModelTypes.java @@ -8,8 +8,8 @@ import com.supermartijn642.fusion.model.types.base.BaseModelType; import com.supermartijn642.fusion.model.types.connecting.ConnectingModelType; import com.supermartijn642.fusion.model.types.vanilla.VanillaModelType; -import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; /** * Contains references to the default model types provided by Fusion. @@ -19,9 +19,9 @@ public class DefaultModelTypes { /** - * Model type used for vanilla {@link BlockModel} instances. + * Model type used for vanilla {@link CuboidModel} instances. */ - public static final ModelType VANILLA = new VanillaModelType(); + public static final ModelType VANILLA = new VanillaModelType(); /** * Model type used for any unknown models added by other mods. */ diff --git a/src/main/java/com/supermartijn642/fusion/api/model/ModelInstance.java b/src/main/java/com/supermartijn642/fusion/api/model/ModelInstance.java index f4847661d..93b6bf8a7 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/ModelInstance.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/ModelInstance.java @@ -1,12 +1,13 @@ package com.supermartijn642.fusion.api.model; import com.supermartijn642.fusion.model.ModelInstanceImpl; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.BlockStateModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.Collection; import java.util.List; @@ -40,10 +41,11 @@ static ModelInstance of(ModelType modelType, T modelData){ /** * Converts the model data into a baked item model. * @param context context for baking the model + * @param transformation inherited transformation for this model * @return a baked model * @see ItemModelBakingContext */ - ItemModel bakeItemModel(ItemModelBakingContext context); + ItemModel bakeItemModel(ItemModelBakingContext context, Matrix4fc transformation); /** * Represents the model as a vanilla {@link BlockModel} instance. May be used gather info from other models, such as with the vanilla 'parent' property. diff --git a/src/main/java/com/supermartijn642/fusion/api/model/ModelType.java b/src/main/java/com/supermartijn642/fusion/api/model/ModelType.java index 629533a7d..aa428591c 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/ModelType.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/ModelType.java @@ -1,11 +1,12 @@ package com.supermartijn642.fusion.api.model; import com.supermartijn642.fusion.api.util.Serializer; -import net.minecraft.client.renderer.block.model.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.Collection; import java.util.List; @@ -30,7 +31,7 @@ public interface ModelType extends Serializer { */ BlockStateModel bakeBlockModel(BlockModelBakingContext context, T data); - ItemModel bakeItemModel(ItemModelBakingContext context, T data); + ItemModel bakeItemModel(ItemModelBakingContext context, T data, Matrix4fc transformation); /** * Represents the model as a vanilla {@link UnbakedModel} instance. May be used gather info from other models, such as with the vanilla 'parent' property. diff --git a/src/main/java/com/supermartijn642/fusion/api/model/SpriteIdentifier.java b/src/main/java/com/supermartijn642/fusion/api/model/SpriteIdentifier.java deleted file mode 100644 index b866be9a9..000000000 --- a/src/main/java/com/supermartijn642/fusion/api/model/SpriteIdentifier.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.supermartijn642.fusion.api.model; - -import com.supermartijn642.fusion.model.SpriteIdentifierImpl; -import net.minecraft.client.resources.model.Material; -import net.minecraft.resources.Identifier; - -/** - * Created 29/04/2023 by SuperMartijn642 - */ -public interface SpriteIdentifier { - - static SpriteIdentifier of(Identifier atlas, Identifier texture){ - return SpriteIdentifierImpl.of(atlas, texture); - } - - static SpriteIdentifier of(Material material){ - return SpriteIdentifierImpl.of(material); - } - - /** - * @return the identifier for the missing texture sprite in the block atlas - */ - static SpriteIdentifier missing(){ - return SpriteIdentifierImpl.MISSING; - } - - Identifier getAtlas(); - - Identifier getTexture(); - - default Material toMaterial(){ - return new Material(this.getAtlas(), this.getTexture()); - } -} diff --git a/src/main/java/com/supermartijn642/fusion/api/model/data/BaseModelData.java b/src/main/java/com/supermartijn642/fusion/api/model/data/BaseModelData.java index e3a7eab3c..cc17a728c 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/data/BaseModelData.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/data/BaseModelData.java @@ -1,6 +1,6 @@ package com.supermartijn642.fusion.api.model.data; -import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; import net.minecraft.resources.Identifier; import java.util.List; @@ -14,7 +14,7 @@ static BaseModelDataBuilder builder(){ return BaseModelDataBuilder.builder(); } - BlockModel getVanillaModel(); + CuboidModel getVanillaModel(); List getParents(); } diff --git a/src/main/java/com/supermartijn642/fusion/api/model/data/VanillaModelDataBuilder.java b/src/main/java/com/supermartijn642/fusion/api/model/data/VanillaModelDataBuilder.java index 989710475..a3035a787 100644 --- a/src/main/java/com/supermartijn642/fusion/api/model/data/VanillaModelDataBuilder.java +++ b/src/main/java/com/supermartijn642/fusion/api/model/data/VanillaModelDataBuilder.java @@ -1,7 +1,8 @@ package com.supermartijn642.fusion.api.model.data; import com.supermartijn642.fusion.model.types.vanilla.VanillaModelDataBuilderImpl; -import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; /** @@ -9,7 +10,7 @@ */ public interface VanillaModelDataBuilder, S> { - static VanillaModelDataBuilder builder(){ + static VanillaModelDataBuilder builder(){ return new VanillaModelDataBuilderImpl(); } @@ -26,7 +27,14 @@ static VanillaModelDataBuilder builder(){ /** * Puts the given texture under the given key. These keys may be used when on faces for elements of this model or its parent's. */ - T texture(String key, Identifier texture); + T texture(String key, Material material); + + /** + * Puts the given texture under the given key. These keys may be used when on faces for elements of this model or its parent's. + */ + default T texture(String key, Identifier texture){ + return texture(key, new Material(texture)); + } S build(); } diff --git a/src/main/java/com/supermartijn642/fusion/api/texture/data/BaseTextureData.java b/src/main/java/com/supermartijn642/fusion/api/texture/data/BaseTextureData.java index 17eabe4ce..b3b1ef3c7 100644 --- a/src/main/java/com/supermartijn642/fusion/api/texture/data/BaseTextureData.java +++ b/src/main/java/com/supermartijn642/fusion/api/texture/data/BaseTextureData.java @@ -12,28 +12,10 @@ static Builder builder(){ return new BaseTextureDataBuilderImpl(); } - @Nullable - RenderType getRenderType(); - boolean isEmissive(); QuadTinting getTinting(); - enum RenderType { - /** - * Pixels in the texture will be rendered fully opaque. - */ - OPAQUE, - /** - * Every pixel in the texture will be either fully transparent or fully opaque. - */ - CUTOUT, - /** - * Pixels will be rendered with the transparency in the texture. - */ - TRANSLUCENT - } - enum QuadTinting { /** * Provides a grass tint based on the biome the model is in. @@ -50,8 +32,6 @@ enum QuadTinting { } interface Builder, S> { - T renderType(@Nullable RenderType type); - T emissive(boolean emissive); T tinting(@Nullable QuadTinting tinting); diff --git a/src/main/java/com/supermartijn642/fusion/api/texture/data/ConnectingTextureData.java b/src/main/java/com/supermartijn642/fusion/api/texture/data/ConnectingTextureData.java index 9c9c76fb0..2a53cd04f 100644 --- a/src/main/java/com/supermartijn642/fusion/api/texture/data/ConnectingTextureData.java +++ b/src/main/java/com/supermartijn642/fusion/api/texture/data/ConnectingTextureData.java @@ -1,7 +1,6 @@ package com.supermartijn642.fusion.api.texture.data; import com.supermartijn642.fusion.texture.types.connecting.ConnectingTextureDataBuilderImpl; -import org.jetbrains.annotations.Nullable; /** * Created 23/10/2023 by SuperMartijn642 @@ -23,27 +22,5 @@ interface Builder extends BaseTextureData.Builder * @see ConnectingTextureLayout */ Builder layout(ConnectingTextureLayout layout); - - /** - * @deprecated use {@link #renderType(BaseTextureData.RenderType)} - */ - @Deprecated - Builder renderType(@Nullable RenderType type); - } - - @Deprecated - enum RenderType { - /** - * Pixels in the texture will be rendered fully opaque. - */ - OPAQUE, - /** - * Every pixel in the texture will be either fully transparent or fully opaque. - */ - CUTOUT, - /** - * Pixels will be rendered with the transparency in the texture. - */ - TRANSLUCENT } } diff --git a/src/main/java/com/supermartijn642/fusion/entity/EntityRenderTypeHelper.java b/src/main/java/com/supermartijn642/fusion/entity/EntityRenderTypeHelper.java index 89554af71..704451c83 100644 --- a/src/main/java/com/supermartijn642/fusion/entity/EntityRenderTypeHelper.java +++ b/src/main/java/com/supermartijn642/fusion/entity/EntityRenderTypeHelper.java @@ -25,17 +25,13 @@ public class EntityRenderTypeHelper { renderTypes.put("entity_solid", RenderTypes::entitySolid); renderTypes.put("entity_solid_z_offset_forward", RenderTypes::entitySolidZOffsetForward); renderTypes.put("entity_cutout", RenderTypes::entityCutout); - renderTypes.put("item_entity_translucent_cull", RenderTypes::itemEntityTranslucentCull); - renderTypes.put("entity_smooth_cutout", RenderTypes::entitySmoothCutout); - renderTypes.put("entity_decal", RenderTypes::entityDecal); - renderTypes.put("entity_no_outline", RenderTypes::entityNoOutline); + renderTypes.put("item_entity_translucent_cull", RenderTypes::itemTranslucent); renderTypes.put("entity_shadow", RenderTypes::entityShadow); - renderTypes.put("entity_alpha", RenderTypes::dragonExplosionAlpha); renderTypes.put("eyes", RenderTypes::eyes); RENDER_TYPES_BY_NAME = renderTypes.build(); ImmutableMap.Builder> outlineRenderTypes = ImmutableMap.builder(); - outlineRenderTypes.put("entity_cutout_no_cull", RenderTypes::entityCutoutNoCull); - outlineRenderTypes.put("entity_cutout_no_cull_z_offset", RenderTypes::entityCutoutNoCullZOffset); + outlineRenderTypes.put("entity_cutout_no_cull", RenderTypes::entityCutout); + outlineRenderTypes.put("entity_cutout_no_cull_z_offset", RenderTypes::entityCutoutZOffset); outlineRenderTypes.put("entity_translucent", RenderTypes::entityTranslucent); outlineRenderTypes.put("entity_translucent_emissive", RenderTypes::entityTranslucentEmissive); VAR_OUTLINE_RENDER_TYPES_BY_NAME = outlineRenderTypes.build(); diff --git a/src/main/java/com/supermartijn642/fusion/extensions/BlockModelExtension.java b/src/main/java/com/supermartijn642/fusion/extensions/CuboidModelExtension.java similarity index 86% rename from src/main/java/com/supermartijn642/fusion/extensions/BlockModelExtension.java rename to src/main/java/com/supermartijn642/fusion/extensions/CuboidModelExtension.java index 9fd3cbc03..668ee707d 100644 --- a/src/main/java/com/supermartijn642/fusion/extensions/BlockModelExtension.java +++ b/src/main/java/com/supermartijn642/fusion/extensions/CuboidModelExtension.java @@ -5,7 +5,7 @@ /** * Created 30/04/2023 by SuperMartijn642 */ -public interface BlockModelExtension { +public interface CuboidModelExtension { ModelInstance getFusionModel(); diff --git a/src/main/java/com/supermartijn642/fusion/mixin/AtlasConfigMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/AtlasConfigMixin.java index 7e9863939..9bcfc2ee7 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/AtlasConfigMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/AtlasConfigMixin.java @@ -1,7 +1,7 @@ package com.supermartijn642.fusion.mixin; import com.supermartijn642.fusion.texture.FusionTextureMetadataSection; -import net.minecraft.client.resources.model.AtlasManager; +import net.minecraft.client.resources.model.sprite.AtlasManager; import net.minecraft.server.packs.metadata.MetadataSectionType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -17,15 +17,16 @@ public class AtlasConfigMixin { @ModifyVariable( - method = "(Lnet/minecraft/resources/Identifier;Lnet/minecraft/resources/Identifier;ZLjava/util/Set;)V", - at = @At("HEAD"), - ordinal = 0 + method = "(Lnet/minecraft/resources/Identifier;Lnet/minecraft/resources/Identifier;ZLjava/util/Set;)V", + at = @At("HEAD"), + argsOnly = true, + name = "additionalMetadata" ) - private static Set> init(Set> set){ - if(set.isEmpty()) + private static Set> init(Set> additionalMetadata){ + if(additionalMetadata.isEmpty()) return Set.of(FusionTextureMetadataSection.TYPE); - ArrayList> copy = new ArrayList<>(set.size() + 1); - copy.addAll(set); + ArrayList> copy = new ArrayList<>(additionalMetadata.size() + 1); + copy.addAll(additionalMetadata); copy.add(FusionTextureMetadataSection.TYPE); return Set.copyOf(copy); } diff --git a/src/main/java/com/supermartijn642/fusion/mixin/BlockRenderDispatcherMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/BlockRenderDispatcherMixin.java index 79c7c7c76..e2eba4c4c 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/BlockRenderDispatcherMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/BlockRenderDispatcherMixin.java @@ -1,7 +1,8 @@ package com.supermartijn642.fusion.mixin; import com.supermartijn642.fusion.FusionClient; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.feature.BlockFeatureRenderer; +import net.minecraft.util.Unit; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -10,22 +11,22 @@ /** * Created 22/08/2025 by SuperMartijn642 */ -@Mixin(BlockRenderDispatcher.class) +@Mixin(BlockFeatureRenderer.class) public class BlockRenderDispatcherMixin { @Inject( - method = "renderBreakingTexture", + method = "renderBreakingBlockModelSubmits", at = @At("HEAD") ) private void renderBreakingTextureHead(CallbackInfo ci){ - FusionClient.IS_RENDERING_BREAKING_OVERLAY.set(true); + FusionClient.IS_RENDERING_BREAKING_OVERLAY.set(Unit.INSTANCE); } @Inject( - method = "renderBreakingTexture", + method = "renderBreakingBlockModelSubmits", at = @At("TAIL") ) private void renderBreakingTextureTail(CallbackInfo ci){ - FusionClient.IS_RENDERING_BREAKING_OVERLAY.set(false); + FusionClient.IS_RENDERING_BREAKING_OVERLAY.remove(); } } diff --git a/src/main/java/com/supermartijn642/fusion/mixin/BlockModelWrapperMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/CuboidItemModelWrapperMixin.java similarity index 76% rename from src/main/java/com/supermartijn642/fusion/mixin/BlockModelWrapperMixin.java rename to src/main/java/com/supermartijn642/fusion/mixin/CuboidItemModelWrapperMixin.java index e2b80c850..0ebaeca28 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/BlockModelWrapperMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/CuboidItemModelWrapperMixin.java @@ -2,11 +2,12 @@ import com.supermartijn642.fusion.model.FusionBlockModel; import net.minecraft.client.color.item.ItemTintSource; -import net.minecraft.client.renderer.item.BlockModelWrapper; +import net.minecraft.client.renderer.item.CuboidItemModelWrapper; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.Identifier; +import org.joml.Matrix4fc; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,24 +18,24 @@ /** * Created 09/04/2025 by SuperMartijn642 */ -@Mixin(BlockModelWrapper.Unbaked.class) -public class BlockModelWrapperMixin { +@Mixin(CuboidItemModelWrapper.Unbaked.class) +public class CuboidItemModelWrapperMixin { @Inject( method = "bake", at = @At("HEAD"), cancellable = true ) - private void bake(ItemModel.BakingContext context, CallbackInfoReturnable ci){ + private void bake(ItemModel.BakingContext context, Matrix4fc transformation, CallbackInfoReturnable ci){ //noinspection DataFlowIssue - BlockModelWrapper.Unbaked unbaked = (BlockModelWrapper.Unbaked)(Object)this; + CuboidItemModelWrapper.Unbaked unbaked = (CuboidItemModelWrapper.Unbaked)(Object)this; Identifier location = unbaked.model(); ResolvedModel wrapper = context.blockModelBaker().getModel(location); if(wrapper != null){ UnbakedModel wrapped = wrapper.wrapped(); if(wrapped instanceof FusionBlockModel fusionBlockModel){ List tintSources = unbaked.tints(); - ItemModel model = fusionBlockModel.bakeItemModel(wrapper, context.blockModelBaker(), tintSources, context.entityModelSet()); + ItemModel model = fusionBlockModel.bakeItemModel(wrapper, context.blockModelBaker(), tintSources, context.entityModelSet(), transformation); ci.setReturnValue(model); } } diff --git a/src/main/java/com/supermartijn642/fusion/mixin/BlockModelMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/CuboidModelMixin.java similarity index 67% rename from src/main/java/com/supermartijn642/fusion/mixin/BlockModelMixin.java rename to src/main/java/com/supermartijn642/fusion/mixin/CuboidModelMixin.java index 45e2e6d00..62ef1fc8f 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/BlockModelMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/CuboidModelMixin.java @@ -1,16 +1,16 @@ package com.supermartijn642.fusion.mixin; import com.supermartijn642.fusion.api.model.ModelInstance; -import com.supermartijn642.fusion.extensions.BlockModelExtension; -import net.minecraft.client.renderer.block.model.BlockModel; +import com.supermartijn642.fusion.extensions.CuboidModelExtension; +import net.minecraft.client.resources.model.cuboid.CuboidModel; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; /** * Created 30/04/2023 by SuperMartijn642 */ -@Mixin(value = BlockModel.class, priority = 900) -public class BlockModelMixin implements BlockModelExtension { +@Mixin(value = CuboidModel.class, priority = 900) +public class CuboidModelMixin implements CuboidModelExtension { @Unique private ModelInstance fusionModel; diff --git a/src/main/java/com/supermartijn642/fusion/mixin/FaceBakeryMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/FaceBakeryMixin.java new file mode 100644 index 000000000..979cafb59 --- /dev/null +++ b/src/main/java/com/supermartijn642/fusion/mixin/FaceBakeryMixin.java @@ -0,0 +1,22 @@ +package com.supermartijn642.fusion.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.mojang.blaze3d.platform.Transparency; +import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; +import net.minecraft.client.renderer.texture.SpriteContents; +import net.minecraft.client.resources.model.cuboid.FaceBakery; +import net.minecraft.client.resources.model.sprite.Material; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(FaceBakery.class) +public class FaceBakeryMixin { + @WrapOperation(method = "computeMaterialTransparency", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/SpriteContents;computeTransparency(FFFF)Lcom/mojang/blaze3d/platform/Transparency;")) + private static Transparency computeMaterialTransparency(SpriteContents instance, float u0, float v0, float u1, float v1, Operation original, Material.Baked material){ + if(material.sprite() instanceof BaseTextureSprite sprite){ + return sprite.computeTransparency(u0, v0, u1, v1); + } + return original.call(instance, u0, v0, u1, v1); + } +} diff --git a/src/main/java/com/supermartijn642/fusion/mixin/FusionMixinPlugin.java b/src/main/java/com/supermartijn642/fusion/mixin/FusionMixinPlugin.java index 833f8209b..3e4b53500 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/FusionMixinPlugin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/FusionMixinPlugin.java @@ -49,7 +49,6 @@ public List getMixins(){ List mixins = new ArrayList<>(); if(this.isSodiumLoaded){ mixins.add("sodium.BlockRendererMixinSodium"); - mixins.add("sodium.ItemRendererMixinSodium"); } return mixins; } diff --git a/src/main/java/com/supermartijn642/fusion/mixin/ItemFeatureRendererMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/ItemFeatureRendererMixin.java new file mode 100644 index 000000000..2064dfbb7 --- /dev/null +++ b/src/main/java/com/supermartijn642/fusion/mixin/ItemFeatureRendererMixin.java @@ -0,0 +1,32 @@ +package com.supermartijn642.fusion.mixin; + +import com.supermartijn642.fusion.api.texture.data.BaseTextureData; +import com.supermartijn642.fusion.texture.QuadTintingHelper; +import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; +import net.minecraft.client.renderer.feature.ItemFeatureRenderer; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * Created 16/09/2024 by SuperMartijn642 + */ +@Mixin(ItemFeatureRenderer.class) +public class ItemFeatureRendererMixin { + + @Inject(method = "getLayerColorSafe([ILnet/minecraft/client/resources/model/geometry/BakedQuad$MaterialInfo;)I", at = @At("HEAD"), cancellable = true) + private static void getLayerColor(int[] tintLayers, BakedQuad.MaterialInfo material, CallbackInfoReturnable ci){ + // In case texture has a custom tinting set, replace the original tinting + if(material.tintIndex() == 39216){ + TextureAtlasSprite sprite = material.sprite(); + if(sprite instanceof BaseTextureSprite){ + BaseTextureData.QuadTinting tinting = ((BaseTextureSprite)sprite).data().getTinting(); + if(tinting != null) + ci.setReturnValue(QuadTintingHelper.getColor(tinting, null, null, null)); + } + } + } +} diff --git a/src/main/java/com/supermartijn642/fusion/mixin/ItemRendererMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/ItemRendererMixin.java deleted file mode 100644 index 0bb9031b5..000000000 --- a/src/main/java/com/supermartijn642/fusion/mixin/ItemRendererMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.supermartijn642.fusion.mixin; - -import com.llamalad7.mixinextras.sugar.Local; -import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; -import com.llamalad7.mixinextras.sugar.ref.LocalRef; -import com.supermartijn642.fusion.api.texture.data.BaseTextureData; -import com.supermartijn642.fusion.texture.QuadTintingHelper; -import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * Created 16/09/2024 by SuperMartijn642 - */ -@Mixin(ItemRenderer.class) -public class ItemRendererMixin { - - @Inject( - method = "renderQuadList", - at = @At( - value = "INVOKE_ASSIGN", - target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;getLayerColorSafe([II)I", - shift = At.Shift.AFTER - ) - ) - private static void renderQuadList(CallbackInfo ci, @Local LocalRef quad, @Local(ordinal = 2) LocalIntRef color){ - // In case texture has a custom tinting set, replace the original tinting - if(quad.get().tintIndex() == 39216){ - TextureAtlasSprite sprite = quad.get().sprite(); - if(sprite instanceof BaseTextureSprite){ - BaseTextureData.QuadTinting tinting = ((BaseTextureSprite)sprite).data().getTinting(); - if(tinting != null) - color.set(QuadTintingHelper.getColor(tinting, null, null, null)); - } - } - } -} diff --git a/src/main/java/com/supermartijn642/fusion/mixin/ModelBakeryMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/ModelBakeryMixin.java index 6faeb58aa..096392866 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/ModelBakeryMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/ModelBakeryMixin.java @@ -6,9 +6,9 @@ import net.minecraft.client.model.geom.EntityModelSet; import net.minecraft.client.renderer.PlayerSkinRenderCache; import net.minecraft.client.renderer.item.ItemModel; -import net.minecraft.client.resources.model.MaterialSet; import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.SpriteGetter; +import net.minecraft.client.resources.model.sprite.MaterialBaker; +import net.minecraft.client.resources.model.sprite.SpriteGetter; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -29,7 +29,7 @@ public class ModelBakeryMixin { private EntityModelSet entityModelSet; @Final @Shadow - private MaterialSet materials; + private SpriteGetter sprites; @Final @Shadow private PlayerSkinRenderCache playerSkinRenderCache; @@ -38,7 +38,7 @@ public class ModelBakeryMixin { method = "bakeModels", at = @At("RETURN") ) - private CompletableFuture applyBlockModelOverlays(CompletableFuture future, SpriteGetter textureGetter, Executor executor){ + private CompletableFuture applyBlockModelOverlays(CompletableFuture future, MaterialBaker materials, Executor taskExecutor){ // Ignore non-vanilla model bakeries //noinspection ConstantValue,EqualsBetweenInconvertibleTypes if(!this.getClass().equals(ModelBakery.class)) @@ -59,12 +59,12 @@ private CompletableFuture applyBlockModelOverlays(Comp } // Apply Fusion model modifiers - ModelBakery.ModelBakerImpl resolver = ((ModelBakery)(Object)this).new ModelBakerImpl(textureGetter, new ModelBakery.PartCacheImpl(), results.missingModels()); + ModelBakery.ModelBakerImpl resolver = ((ModelBakery)(Object)this).new ModelBakerImpl(materials, new ModelBakery.InternerImpl(), results.missingModels()); BlockModelModifierReloadListener.INSTANCE.applyOverlays(results, resolver); ItemModelModifierReloadListener.INSTANCE.applyPredicateModels(results, new ItemModel.BakingContext( resolver, this.entityModelSet, - this.materials, + this.sprites, this.playerSkinRenderCache, results.missingModels().item(), null diff --git a/src/main/java/com/supermartijn642/fusion/mixin/ModelBlockRendererMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/ModelBlockRendererMixin.java index d6ff20b97..6b7e99c2c 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/ModelBlockRendererMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/ModelBlockRendererMixin.java @@ -1,19 +1,18 @@ package com.supermartijn642.fusion.mixin; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; import com.supermartijn642.fusion.api.texture.data.BaseTextureData; import com.supermartijn642.fusion.texture.QuadTintingHelper; import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; +import net.minecraft.client.renderer.block.BlockAndTintGetter; import net.minecraft.client.renderer.block.ModelBlockRenderer; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; /** * Created 07/09/2024 by SuperMartijn642 @@ -21,47 +20,14 @@ @Mixin(ModelBlockRenderer.class) public class ModelBlockRendererMixin { - @ModifyVariable( - method = "putQuadData", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/client/renderer/block/ModelBlockRenderer$CommonRenderStorage;tintCacheValue:I", - shift = At.Shift.AFTER - ), - ordinal = 2 - ) - private int tintQuadCached(int blockColor, BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, PoseStack.Pose pose, BakedQuad quad){ - // In case texture has a custom tinting set, replace the original tinting - if(quad.tintIndex() == 39216){ - TextureAtlasSprite sprite = quad.sprite(); - if(sprite instanceof BaseTextureSprite){ - BaseTextureData.QuadTinting tinting = ((BaseTextureSprite)sprite).data().getTinting(); - if(tinting != null) - return QuadTintingHelper.getColor(tinting, state, level, pos); - } + // In case texture has a custom tinting set, replace the original tinting + @WrapOperation(method = "putQuadWithTint", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/ModelBlockRenderer;getTintColor(Lnet/minecraft/client/renderer/block/BlockAndTintGetter;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;I)I")) + private int getTintColor(ModelBlockRenderer instance, BlockAndTintGetter level, BlockState state, BlockPos pos, int tintIndex, Operation original, @Local(argsOnly = true, name = "quad") BakedQuad quad){ + if (tintIndex == 39216 && quad.materialInfo().sprite() instanceof BaseTextureSprite sprite){ + BaseTextureData.QuadTinting tinting = sprite.data().getTinting(); + if (tinting != null) + return QuadTintingHelper.getColor(tinting, state, level, pos); } - return blockColor; - } - - @ModifyVariable( - method = "putQuadData", - at = @At( - value = "INVOKE_ASSIGN", - target = "Lnet/minecraft/client/color/block/BlockColors;getColor(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockAndTintGetter;Lnet/minecraft/core/BlockPos;I)I", - shift = At.Shift.AFTER - ), - ordinal = 2 - ) - private int tintQuad(int blockColor, BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, PoseStack.Pose pose, BakedQuad quad){ - // In case texture has a custom tinting set, replace the original tinting - if(quad.tintIndex() == 39216){ - TextureAtlasSprite sprite = quad.sprite(); - if(sprite instanceof BaseTextureSprite){ - BaseTextureData.QuadTinting tinting = ((BaseTextureSprite)sprite).data().getTinting(); - if(tinting != null) - return QuadTintingHelper.getColor(tinting, state, level, pos); - } - } - return blockColor; + return original.call(instance, level, state, pos, tintIndex); } } diff --git a/src/main/java/com/supermartijn642/fusion/mixin/ModelManagerMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/ModelManagerMixin.java index 856cd9a15..ef33c0087 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/ModelManagerMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/ModelManagerMixin.java @@ -23,7 +23,7 @@ public class ModelManagerMixin { @Inject( - method = "lambda$loadBlockModels$5(Lnet/minecraft/server/packs/resources/ResourceManager;)Ljava/util/Map;", + method = "lambda$loadBlockModels$0", at = @At("HEAD") ) private static void reloadModelModifiers(ResourceManager resourceManager, CallbackInfoReturnable> ci){ @@ -47,7 +47,7 @@ private static void registerBlockModelOverlays(CallbackInfoReturnable getNamespaces(Set namespaces, PackType type){ @@ -116,7 +116,7 @@ private Set getNamespaces(Set namespaces, PackType type){ } @ModifyVariable( - method = "listResources", + method = "listResources(Lnet/minecraft/server/packs/PackType;Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/server/packs/PackResources$ResourceOutput;)V", at = @At("HEAD"), ordinal = 0 ) diff --git a/src/main/java/com/supermartijn642/fusion/mixin/SingleVariantMixin.java b/src/main/java/com/supermartijn642/fusion/mixin/SingleVariantMixin.java index 1b4a72818..6e6e210ac 100644 --- a/src/main/java/com/supermartijn642/fusion/mixin/SingleVariantMixin.java +++ b/src/main/java/com/supermartijn642/fusion/mixin/SingleVariantMixin.java @@ -1,9 +1,9 @@ package com.supermartijn642.fusion.mixin; import com.supermartijn642.fusion.model.FusionBlockModel; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.block.model.SingleVariant; -import net.minecraft.client.renderer.block.model.Variant; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.SingleVariant; +import net.minecraft.client.renderer.block.dispatch.Variant; import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.UnbakedModel; diff --git a/src/main/java/com/supermartijn642/fusion/mixin/sodium/ItemRendererMixinSodium.java b/src/main/java/com/supermartijn642/fusion/mixin/sodium/ItemRendererMixinSodium.java deleted file mode 100644 index 2e6a7c860..000000000 --- a/src/main/java/com/supermartijn642/fusion/mixin/sodium/ItemRendererMixinSodium.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.supermartijn642.fusion.mixin.sodium; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.supermartijn642.fusion.api.texture.data.BaseTextureData; -import com.supermartijn642.fusion.texture.QuadTintingHelper; -import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.renderer.item.ItemStackRenderState; -import net.minecraft.client.renderer.rendertype.RenderType; -import net.minecraft.world.item.ItemDisplayContext; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Iterator; -import java.util.List; - -/** - * Created 20/12/2025 by SuperMartijn642 - */ -@Mixin(ItemRenderer.class) -public class ItemRendererMixinSodium { - - /* - The goal is to overwrite the quad tinting that normally occurs in ItemRenderer#renderQuadList. - Sodium intercepts #renderQuadList in ItemRenderer#renderItem with a mixin and applies the quad - tinting themselves in their mixin. - - Fusion needs the sprite and hence the quad as context for the tinting. - - Sodium calls #getLayerColorSafe once per quad, so we capture an iterator for the list of quads - in #renderItem and then iterate through them whenever #getLayerColorSafe is called. - Then from #getLayerColorSafe we return Fusion's tinting. - */ - - @Unique - private static final ThreadLocal> lastSubmittedQuads = new ThreadLocal<>(); - - @Inject( - method = "renderItem", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;renderQuadList(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Ljava/util/List;[III)V", - shift = At.Shift.BEFORE - ) - ) - private static void captureQuads(ItemDisplayContext displayContext, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay, int[] colors, List quads, RenderType renderType, ItemStackRenderState.FoilType foilType, CallbackInfo ci){ - for(BakedQuad quad : quads){ - //noinspection resource - if(quad.tintIndex() == 39216 && quad.sprite() instanceof BaseTextureSprite){ - lastSubmittedQuads.set(quads.iterator()); - break; - } - } - } - - @Inject( - method = "getLayerColorSafe", - at = @At("HEAD"), - cancellable = true - ) - private static void overwriteTinting(int[] colors, int tintIndex, CallbackInfoReturnable ci){ - // In case texture has a custom tinting set, replace the original tinting - if(tintIndex != 39216) - return; - - // Find the relevant quad - Iterator quads = lastSubmittedQuads.get(); - if(quads == null) - return; - BaseTextureSprite sprite = null; - while(quads.hasNext()){ - BakedQuad quad = quads.next(); - //noinspection resource - if(quad.tintIndex() == 39216 && quad.sprite() instanceof BaseTextureSprite s){ - sprite = s; - break; - } - } - if(sprite == null) - return; - - // Calculate tinting - BaseTextureData.QuadTinting tinting = sprite.data().getTinting(); - if(tinting != null) - ci.setReturnValue(QuadTintingHelper.getColor(tinting, null, null, null)); - } - - @Inject( - method = "renderItem", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;renderQuadList(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Ljava/util/List;[III)V", - shift = At.Shift.AFTER - ) - ) - private static void clearQuads(CallbackInfo ci){ - lastSubmittedQuads.remove(); - } -} diff --git a/src/main/java/com/supermartijn642/fusion/model/BlockModelBakingContextImpl.java b/src/main/java/com/supermartijn642/fusion/model/BlockModelBakingContextImpl.java index 3480da77d..5fe01aee6 100644 --- a/src/main/java/com/supermartijn642/fusion/model/BlockModelBakingContextImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/BlockModelBakingContextImpl.java @@ -2,10 +2,12 @@ import com.supermartijn642.fusion.api.model.BlockModelBakingContext; import com.supermartijn642.fusion.api.model.ModelInstance; -import com.supermartijn642.fusion.api.model.SpriteIdentifier; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.block.dispatch.ModelState; +import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; import net.minecraft.client.resources.model.*; +import net.minecraft.client.resources.model.cuboid.ItemTransforms; +import net.minecraft.client.resources.model.geometry.UnbakedGeometry; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; import net.minecraft.util.context.ContextMap; @@ -16,9 +18,10 @@ * Created 27/04/2023 by SuperMartijn642 */ public class BlockModelBakingContextImpl implements BlockModelBakingContext { + private static final Material MISSING_MATERIAL = new Material(MissingTextureAtlasSprite.getLocation()); private final ModelBaker modelBaker; - private final Function spriteGetter; + private final Function materialBaker; private final ModelState modelState; private final Identifier modelIdentifier; private final Map dependencies; @@ -29,9 +32,9 @@ public class BlockModelBakingContextImpl implements BlockModelBakingContext { private final UnbakedGeometry topLevelGeometry; private final ContextMap neoforgeAdditionalProperties; - public BlockModelBakingContextImpl(ModelBaker modelBaker, Function spriteGetter, ModelState modelState, Identifier modelIdentifier, Map dependencies, Map topLevelTextureReferences, boolean topLevelAmbientOcclusion, boolean topLevelUseBlockLighting, ItemTransforms topLevelItemTransforms, UnbakedGeometry topLevelGeometry, ContextMap neoforgeAdditionalProperties){ + public BlockModelBakingContextImpl(ModelBaker modelBaker, Function materialBaker, ModelState modelState, Identifier modelIdentifier, Map dependencies, Map topLevelTextureReferences, boolean topLevelAmbientOcclusion, boolean topLevelUseBlockLighting, ItemTransforms topLevelItemTransforms, UnbakedGeometry topLevelGeometry, ContextMap neoforgeAdditionalProperties){ this.modelBaker = modelBaker; - this.spriteGetter = spriteGetter; + this.materialBaker = materialBaker; this.modelState = modelState; this.modelIdentifier = modelIdentifier; this.dependencies = dependencies; @@ -49,13 +52,13 @@ public ModelBaker getModelBaker(){ } @Override - public TextureAtlasSprite getTexture(SpriteIdentifier identifier){ - return this.spriteGetter.apply(identifier.toMaterial()); + public Material.Baked bakeMaterial(Material material){ + return this.materialBaker.apply(material); } @Override - public TextureAtlasSprite getTexture(Identifier atlas, Identifier texture){ - return this.spriteGetter.apply(new Material(atlas, texture)); + public Material missingMaterial(){ + return MISSING_MATERIAL; } @Override diff --git a/src/main/java/com/supermartijn642/fusion/model/FusionBlockModel.java b/src/main/java/com/supermartijn642/fusion/model/FusionBlockModel.java index dad2864a3..3f0949d50 100644 --- a/src/main/java/com/supermartijn642/fusion/model/FusionBlockModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/FusionBlockModel.java @@ -4,19 +4,23 @@ import com.supermartijn642.fusion.api.model.DefaultModelTypes; import com.supermartijn642.fusion.api.model.ItemModelBakingContext; import com.supermartijn642.fusion.api.model.ModelInstance; -import com.supermartijn642.fusion.extensions.BlockModelExtension; +import com.supermartijn642.fusion.extensions.CuboidModelExtension; import com.supermartijn642.fusion.util.IdentifierUtil; import net.minecraft.client.color.item.ItemTintSource; import net.minecraft.client.model.geom.EntityModelSet; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.block.model.TextureSlots; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.ModelState; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.*; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.cuboid.ItemTransforms; +import net.minecraft.client.resources.model.cuboid.MissingCuboidModel; +import net.minecraft.client.resources.model.geometry.UnbakedGeometry; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.resources.Identifier; import net.minecraft.util.context.ContextMap; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.*; @@ -45,7 +49,7 @@ public BlockStateModel bakeBlockModel(ResolvedModel wrapper, ModelBaker modelBak // Create baking context BlockModelBakingContext context = new BlockModelBakingContextImpl( modelBakery, - material -> modelBakery.sprites().get(material, wrapper), + material -> modelBakery.materials().get(material, wrapper), modelState, this.name, this.resolvedDependencies, @@ -64,12 +68,12 @@ public BlockStateModel bakeBlockModel(ResolvedModel wrapper, ModelBaker modelBak } } - public ItemModel bakeItemModel(ResolvedModel wrapper, ModelBaker modelBakery, List tintSources, EntityModelSet entityModelSet){ + public ItemModel bakeItemModel(ResolvedModel wrapper, ModelBaker modelBakery, List tintSources, EntityModelSet entityModelSet, Matrix4fc transformation){ this.resolveDependencies(modelBakery); // Create baking context ItemModelBakingContext context = new ItemModelBakingContextImpl( modelBakery, - material -> modelBakery.sprites().get(material, wrapper), + material -> modelBakery.materials().get(material, wrapper), this.name, this.resolvedDependencies, wrapper.getTopTextureSlots().resolvedValues, @@ -83,7 +87,7 @@ public ItemModel bakeItemModel(ResolvedModel wrapper, ModelBaker modelBakery, Li ); // Let the custom model handle the actual baking try{ - return this.model.bakeItemModel(context); + return this.model.bakeItemModel(context, transformation); }catch(Exception e){ throw new RuntimeException("Encountered an exception while baking item model of type '" + ModelTypeRegistryImpl.getIdentifier(this.model.getModelType()) + "' for '" + this.name + "'!", e); } @@ -121,7 +125,7 @@ private Map resolveDependencies(ModelBaker modelBaker){ } } // Always add missing model - this.resolvedDependencies.put(MissingBlockModel.LOCATION, modelBaker.getModel(MissingBlockModel.LOCATION).wrapped()); + this.resolvedDependencies.put(MissingCuboidModel.LOCATION, modelBaker.getModel(MissingCuboidModel.LOCATION).wrapped()); return this.resolvedDependencies; } @@ -172,11 +176,11 @@ public void fillAdditionalProperties(ContextMap.Builder builder){ public static ModelInstance getModelInstance(UnbakedModel model){ if(model instanceof FusionBlockModel) return ((FusionBlockModel)model).model; - if(model instanceof BlockModel){ - ModelInstance modelInstance = ((BlockModelExtension)model).getFusionModel(); + if(model instanceof CuboidModel){ + ModelInstance modelInstance = ((CuboidModelExtension)model).getFusionModel(); if(modelInstance == null){ - modelInstance = new ModelInstanceImpl<>(DefaultModelTypes.VANILLA, (BlockModel)model); - ((BlockModelExtension)model).setFusionModel(modelInstance); + modelInstance = new ModelInstanceImpl<>(DefaultModelTypes.VANILLA, (CuboidModel)model); + ((CuboidModelExtension)model).setFusionModel(modelInstance); } return modelInstance; } diff --git a/src/main/java/com/supermartijn642/fusion/model/ItemModelBakingContextImpl.java b/src/main/java/com/supermartijn642/fusion/model/ItemModelBakingContextImpl.java index a50852315..f82b37a14 100644 --- a/src/main/java/com/supermartijn642/fusion/model/ItemModelBakingContextImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/ItemModelBakingContextImpl.java @@ -3,9 +3,11 @@ import com.supermartijn642.fusion.api.model.ItemModelBakingContext; import net.minecraft.client.color.item.ItemTintSource; import net.minecraft.client.model.geom.EntityModelSet; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.block.dispatch.BlockModelRotation; import net.minecraft.client.resources.model.*; +import net.minecraft.client.resources.model.cuboid.ItemTransforms; +import net.minecraft.client.resources.model.geometry.UnbakedGeometry; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; import net.minecraft.util.context.ContextMap; @@ -21,8 +23,8 @@ public class ItemModelBakingContextImpl extends BlockModelBakingContextImpl impl private final List tintSources; private final EntityModelSet entityModelSet; - public ItemModelBakingContextImpl(ModelBaker modelBaker, Function spriteGetter, Identifier modelIdentifier, Map dependencies, Map topLevelTextureReferences, boolean topLevelAmbientOcclusion, boolean topLevelUseBlockLighting, ItemTransforms topLevelItemTransforms, UnbakedGeometry topLevelGeometry, ContextMap neoforgeAdditionalProperties, List tintSources, EntityModelSet entityModelSet){ - super(modelBaker, spriteGetter, BlockModelRotation.IDENTITY, modelIdentifier, dependencies, topLevelTextureReferences, topLevelAmbientOcclusion, topLevelUseBlockLighting, topLevelItemTransforms, topLevelGeometry, neoforgeAdditionalProperties); + public ItemModelBakingContextImpl(ModelBaker modelBaker, Function materialBaker, Identifier modelIdentifier, Map dependencies, Map topLevelTextureReferences, boolean topLevelAmbientOcclusion, boolean topLevelUseBlockLighting, ItemTransforms topLevelItemTransforms, UnbakedGeometry topLevelGeometry, ContextMap neoforgeAdditionalProperties, List tintSources, EntityModelSet entityModelSet){ + super(modelBaker, materialBaker, BlockModelRotation.IDENTITY, modelIdentifier, dependencies, topLevelTextureReferences, topLevelAmbientOcclusion, topLevelUseBlockLighting, topLevelItemTransforms, topLevelGeometry, neoforgeAdditionalProperties); this.tintSources = tintSources; this.entityModelSet = entityModelSet; } diff --git a/src/main/java/com/supermartijn642/fusion/model/ModelInstanceImpl.java b/src/main/java/com/supermartijn642/fusion/model/ModelInstanceImpl.java index dcbbe6c78..b1567700b 100644 --- a/src/main/java/com/supermartijn642/fusion/model/ModelInstanceImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/ModelInstanceImpl.java @@ -4,11 +4,12 @@ import com.supermartijn642.fusion.api.model.ItemModelBakingContext; import com.supermartijn642.fusion.api.model.ModelInstance; import com.supermartijn642.fusion.api.model.ModelType; -import net.minecraft.client.renderer.block.model.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.Collection; import java.util.List; @@ -52,8 +53,8 @@ public BlockStateModel bakeBlockModel(BlockModelBakingContext context){ } @Override - public ItemModel bakeItemModel(ItemModelBakingContext context){ - return this.modelType.bakeItemModel(context, this.modelData); + public ItemModel bakeItemModel(ItemModelBakingContext context, Matrix4fc transformation){ + return this.modelType.bakeItemModel(context, this.modelData, transformation); } @Override diff --git a/src/main/java/com/supermartijn642/fusion/model/MutableQuad.java b/src/main/java/com/supermartijn642/fusion/model/MutableQuad.java index 5ff5d8628..e8e2f5781 100644 --- a/src/main/java/com/supermartijn642/fusion/model/MutableQuad.java +++ b/src/main/java/com/supermartijn642/fusion/model/MutableQuad.java @@ -1,12 +1,13 @@ package com.supermartijn642.fusion.model; import net.minecraft.client.model.geom.builders.UVPair; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.core.Direction; import net.neoforged.neoforge.client.model.quad.BakedColors; import net.neoforged.neoforge.client.model.quad.BakedNormals; import org.joml.Vector3f; +import org.jspecify.annotations.Nullable; /** * Created 11/09/2024 by SuperMartijn642 @@ -15,15 +16,14 @@ public class MutableQuad { private final Vector3f[] positions = new Vector3f[4]; private final long[] uvs = new long[4]; - private int tintIndex; private Direction lightFace; - private TextureAtlasSprite sprite; - private boolean shade; - private int lightEmission; + private BakedQuad.MaterialInfo oldMaterialInfo; private boolean hasAmbientOcclusion; private BakedNormals bakedNormals = BakedNormals.UNSPECIFIED; private BakedColors bakedColors = BakedColors.DEFAULT; private boolean emissive = false; + private int tintIndex; + private boolean changedMaterialInfo; public MutableQuad(){ for(int i = 0; i < 4; i++) @@ -35,23 +35,28 @@ public void fillFromBakedQuad(BakedQuad quad){ this.positions[i].set(quad.position(i)); this.uvs[i] = quad.packedUV(i); } - this.tintIndex = quad.tintIndex(); this.lightFace = quad.direction(); - this.sprite = quad.sprite(); - this.shade = quad.shade(); - this.lightEmission = quad.lightEmission(); - this.hasAmbientOcclusion = quad.hasAmbientOcclusion(); + this.oldMaterialInfo = quad.materialInfo(); + this.hasAmbientOcclusion = quad.materialInfo().ambientOcclusion(); this.bakedNormals = quad.bakedNormals(); this.bakedColors = quad.bakedColors(); this.emissive = false; + this.tintIndex = quad.materialInfo().tintIndex(); } public void emissive(boolean emissive){ this.emissive = emissive; + this.changedMaterialInfo = true; } public void ambientOcclusion(boolean ambientOcclusion){ this.hasAmbientOcclusion = ambientOcclusion; + this.changedMaterialInfo = true; + } + + public void tintIndex(int tintIndex){ + this.tintIndex = tintIndex; + this.changedMaterialInfo = true; } public void uv(int vertexIndex, float u, float v){ @@ -82,18 +87,29 @@ public float z(int vertexIndex){ return this.positions[vertexIndex].z(); } - public BakedQuad toBakedQuad(){ + public BakedQuad toBakedQuad(ModelBaker.@Nullable Interner interner){ + BakedQuad.MaterialInfo materialInfo; + if(this.changedMaterialInfo){ + materialInfo = new BakedQuad.MaterialInfo( + this.oldMaterialInfo.sprite(), + this.oldMaterialInfo.layer(), + this.oldMaterialInfo.itemRenderType(), + this.tintIndex, + this.oldMaterialInfo.shade(), + this.emissive ? 15 : this.oldMaterialInfo.lightEmission(), + this.hasAmbientOcclusion + ); + materialInfo = interner != null ? interner.materialInfo(materialInfo) : materialInfo; + }else{ + materialInfo = this.oldMaterialInfo; + } return new BakedQuad( new Vector3f(this.positions[0]), new Vector3f(this.positions[1]), new Vector3f(this.positions[2]), new Vector3f(this.positions[3]), this.uvs[0], this.uvs[1], this.uvs[2], this.uvs[3], - this.tintIndex, this.lightFace, - this.sprite, - this.shade, - this.emissive ? 15 : this.lightEmission, + materialInfo, this.bakedNormals, - this.bakedColors, - this.hasAmbientOcclusion + this.bakedColors ); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/SpriteIdentifierImpl.java b/src/main/java/com/supermartijn642/fusion/model/SpriteIdentifierImpl.java deleted file mode 100644 index dac15bb4f..000000000 --- a/src/main/java/com/supermartijn642/fusion/model/SpriteIdentifierImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.supermartijn642.fusion.model; - -import com.supermartijn642.fusion.api.model.SpriteIdentifier; -import com.supermartijn642.fusion.util.TextureAtlases; -import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; -import net.minecraft.client.resources.model.Material; -import net.minecraft.resources.Identifier; - -/** - * Created 30/04/2023 by SuperMartijn642 - */ -public class SpriteIdentifierImpl implements SpriteIdentifier { - - public static final SpriteIdentifier MISSING = of(TextureAtlases.getBlocks(), MissingTextureAtlasSprite.getLocation()); - - public static SpriteIdentifier of(Identifier atlas, Identifier texture){ - return new SpriteIdentifierImpl(atlas, texture); - } - - public static SpriteIdentifier of(Material material){ - return new SpriteIdentifierImpl(material); - } - - private final Identifier atlas, texture; - private Material material; - - private SpriteIdentifierImpl(Identifier atlas, Identifier texture){ - this.atlas = atlas; - this.texture = texture; - } - - private SpriteIdentifierImpl(Material material){ - this(material.atlasLocation(), material.texture()); - this.material = material; - } - - @Override - public Identifier getAtlas(){ - return this.atlas; - } - - @Override - public Identifier getTexture(){ - return this.texture; - } - - @Override - public Material toMaterial(){ - return this.material == null ? (this.material = SpriteIdentifier.super.toMaterial()) : this.material; - } - - @Override - public final boolean equals(Object o){ - if(!(o instanceof SpriteIdentifierImpl that)) return false; - - return this.atlas.equals(that.atlas) && this.texture.equals(that.texture); - } - - @Override - public int hashCode(){ - int result = this.atlas.hashCode(); - result = 31 * result + this.texture.hashCode(); - return result; - } -} diff --git a/src/main/java/com/supermartijn642/fusion/model/WrappedBakedModel.java b/src/main/java/com/supermartijn642/fusion/model/WrappedBakedModel.java index 20dcbc762..fdf1529fe 100644 --- a/src/main/java/com/supermartijn642/fusion/model/WrappedBakedModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/WrappedBakedModel.java @@ -1,11 +1,12 @@ package com.supermartijn642.fusion.model; -import net.minecraft.client.renderer.block.model.BlockModelPart; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.BlockPos; import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -23,18 +24,18 @@ public WrappedBakedModel(BlockStateModel original){ } @Override - public List collectParts(RandomSource random){ - return this.original.collectParts(random); + public void collectParts(RandomSource random, List parts){ + this.original.collectParts(random, parts); } @Override - public void collectParts(RandomSource random, List parts){ - this.original.collectParts(random, parts); + public Material.Baked particleMaterial(){ + return this.original.particleMaterial(); } @Override - public TextureAtlasSprite particleIcon(){ - return this.original.particleIcon(); + public @BakedQuad.MaterialFlags int materialFlags(){ + return this.original.materialFlags(); } @Override @@ -43,17 +44,17 @@ public TextureAtlasSprite particleIcon(){ } @Override - public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ + public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ this.original.collectParts(level, pos, state, random, parts); } @Override - public List collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random){ - return this.original.collectParts(level, pos, state, random); + public Material.Baked particleMaterial(BlockAndTintGetter level, BlockPos pos, BlockState state){ + return this.original.particleMaterial(level, pos, state); } @Override - public TextureAtlasSprite particleIcon(BlockAndTintGetter level, BlockPos pos, BlockState state){ - return this.original.particleIcon(level, pos, state); + public @BakedQuad.MaterialFlags int materialFlags(BlockAndTintGetter level, BlockPos pos, BlockState state){ + return this.original.materialFlags(level, pos, state); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierBakedModel.java b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierBakedModel.java index 6b41f2d3e..d2d7eb58c 100644 --- a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierBakedModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierBakedModel.java @@ -1,12 +1,13 @@ package com.supermartijn642.fusion.model.modifiers.block; import com.supermartijn642.fusion.FusionClient; -import net.minecraft.client.renderer.block.model.BlockModelPart; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.BlockPos; import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -31,7 +32,7 @@ public BlockModelModifierBakedModel(BlockStateModel original, List parts){ + public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ if(!this.showBreakingOverlay && FusionClient.IS_RENDERING_BREAKING_OVERLAY.get() != null){ this.original.collectParts(level, pos, state, random, parts); return; @@ -50,7 +51,7 @@ public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState stat } @Override - public void collectParts(RandomSource random, List parts){ + public void collectParts(RandomSource random, List parts){ if(!this.showBreakingOverlay && FusionClient.IS_RENDERING_BREAKING_OVERLAY.get() != null){ //noinspection deprecation this.original.collectParts(random, parts); @@ -61,12 +62,22 @@ public void collectParts(RandomSource random, List parts){ } @Override - public TextureAtlasSprite particleIcon(){ - return this.original.particleIcon(); + public Material.Baked particleMaterial(){ + return this.original.particleMaterial(); } @Override - public TextureAtlasSprite particleIcon(BlockAndTintGetter level, BlockPos pos, BlockState state){ - return this.original.particleIcon(level, pos, state); + public Material.Baked particleMaterial(BlockAndTintGetter level, BlockPos pos, BlockState state){ + return this.original.particleMaterial(level, pos, state); + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return this.original.materialFlags(); + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(BlockAndTintGetter level, BlockPos pos, BlockState state){ + return this.original.materialFlags(level, pos, state); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierReloadListener.java b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierReloadListener.java index edde65367..43336d906 100644 --- a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierReloadListener.java +++ b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/BlockModelModifierReloadListener.java @@ -12,9 +12,9 @@ import com.mojang.serialization.JsonOps; import com.supermartijn642.fusion.FusionClient; import com.supermartijn642.fusion.util.IdentifierUtil; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.block.model.SingleVariant; -import net.minecraft.client.renderer.block.model.Variant; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.SingleVariant; +import net.minecraft.client.renderer.block.dispatch.Variant; import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ResolvableModel; import net.minecraft.core.registries.BuiltInRegistries; diff --git a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/PaneCullingBakedModel.java b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/PaneCullingBakedModel.java index 1013eb189..a34847876 100644 --- a/src/main/java/com/supermartijn642/fusion/model/modifiers/block/PaneCullingBakedModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/modifiers/block/PaneCullingBakedModel.java @@ -3,16 +3,15 @@ import com.supermartijn642.fusion.api.util.Pair; import com.supermartijn642.fusion.model.MutableQuad; import com.supermartijn642.fusion.model.WrappedBakedModel; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.BlockModelPart; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.chunk.ChunkSectionLayer; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.util.TriState; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; @@ -42,14 +41,14 @@ public PaneCullingBakedModel(BlockStateModel original){ } @Override - public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ + public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ if(state == null){ - parts.addAll(super.collectParts(level, pos, state, random)); + super.collectParts(level, pos, state, random, parts); return; } // If state has no side properties, then there's nothing to be culled if(!state.hasProperty(BlockStateProperties.NORTH) && !state.hasProperty(BlockStateProperties.SOUTH) && !state.hasProperty(BlockStateProperties.WEST) && !state.hasProperty(BlockStateProperties.EAST)){ - parts.addAll(super.collectParts(level, pos, state, random)); + super.collectParts(level, pos, state, random, parts); return; } @@ -61,17 +60,17 @@ public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState stat if(below.getBlock() != state.getBlock()) below = null; if(above == null && below == null){ - parts.addAll(super.collectParts(level, pos, state, random)); + super.collectParts(level, pos, state, random, parts); return; } - Pair neighbors = Pair.of(above, below); + super.collectParts(level, pos, state, random, parts); // Wrap the parts with a quad filter - for(BlockModelPart part : super.collectParts(level, pos, state, random)) - parts.add(new FilteringModelPart(part, neighbors)); + Pair neighbors = Pair.of(above, below); + parts.replaceAll(part -> new FilteringModelPart(part, neighbors)); } - private List getQuads(BlockModelPart part, Pair neighbors, @Nullable Direction cullDirection){ + private List getQuads(BlockStateModelPart part, Pair neighbors, @Nullable Direction cullDirection){ // Filter out certain quads List quads = part.getQuads(cullDirection); List culledQuads = new ArrayList<>(quads.size()); @@ -114,12 +113,12 @@ private boolean filterQuad(BakedQuad bakedQuad, BlockState stateAbove, BlockStat ); } - private class FilteringModelPart implements BlockModelPart { + private class FilteringModelPart implements BlockStateModelPart { - private final BlockModelPart original; + private final BlockStateModelPart original; private final Pair neighbors; - private FilteringModelPart(BlockModelPart original, Pair neighbors){ + private FilteringModelPart(BlockStateModelPart original, Pair neighbors){ this.original = original; this.neighbors = neighbors; } @@ -135,13 +134,13 @@ public boolean useAmbientOcclusion(){ } @Override - public TextureAtlasSprite particleIcon(){ - return this.original.particleIcon(); + public Material.Baked particleMaterial(){ + return this.original.particleMaterial(); } @Override - public ChunkSectionLayer getRenderType(BlockState state){ - return this.original.getRenderType(state); + public @BakedQuad.MaterialFlags int materialFlags() { + return this.original.materialFlags(); } @Override diff --git a/src/main/java/com/supermartijn642/fusion/model/modifiers/item/ItemModelModifierReloadListener.java b/src/main/java/com/supermartijn642/fusion/model/modifiers/item/ItemModelModifierReloadListener.java index effeb4317..8e5b4f51d 100644 --- a/src/main/java/com/supermartijn642/fusion/model/modifiers/item/ItemModelModifierReloadListener.java +++ b/src/main/java/com/supermartijn642/fusion/model/modifiers/item/ItemModelModifierReloadListener.java @@ -14,7 +14,7 @@ import com.supermartijn642.fusion.model.modifiers.item.predicates.AndItemPredicate; import com.supermartijn642.fusion.model.modifiers.item.predicates.ItemPredicateRegistry; import com.supermartijn642.fusion.util.IdentifierUtil; -import net.minecraft.client.renderer.item.BlockModelWrapper; +import net.minecraft.client.renderer.item.CuboidItemModelWrapper; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ResolvableModel; @@ -24,6 +24,7 @@ import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; import net.minecraft.world.item.Item; +import org.joml.Matrix4f; import java.util.*; @@ -64,7 +65,7 @@ public void applyPredicateModels(ModelBakery.BakingResult results, ItemModel.Bak } private ItemModel getOrBakeModel(Identifier location, Map bakedModels, ItemModel.BakingContext bakingContext){ - return bakedModels.computeIfAbsent(location, l -> new BlockModelWrapper.Unbaked(l, List.of()).bake(bakingContext)); + return bakedModels.computeIfAbsent(location, l -> new CuboidItemModelWrapper.Unbaked(l, Optional.empty(), List.of()).bake(bakingContext, new Matrix4f())); } public void reload(ResourceManager resourceManager){ diff --git a/src/main/java/com/supermartijn642/fusion/model/types/UnknownModelType.java b/src/main/java/com/supermartijn642/fusion/model/types/UnknownModelType.java index 3b9aa7885..6f7804939 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/UnknownModelType.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/UnknownModelType.java @@ -5,19 +5,20 @@ import com.supermartijn642.fusion.api.model.BlockModelBakingContext; import com.supermartijn642.fusion.api.model.ItemModelBakingContext; import com.supermartijn642.fusion.api.model.ModelType; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.block.model.SimpleModelWrapper; -import net.minecraft.client.renderer.block.model.SingleVariant; -import net.minecraft.client.renderer.block.model.TextureSlots; -import net.minecraft.client.renderer.item.BlockModelWrapper; +import net.minecraft.client.renderer.block.dispatch.BlockModelRotation; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.SingleVariant; +import net.minecraft.client.renderer.item.CuboidItemModelWrapper; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.renderer.item.ModelRenderProperties; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BlockModelRotation; -import net.minecraft.client.resources.model.QuadCollection; +import net.minecraft.client.resources.model.SimpleModelWrapper; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.geometry.QuadCollection; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.Collection; import java.util.List; @@ -47,21 +48,21 @@ public Collection getModelDependencies(T data){ public BlockStateModel bakeBlockModel(BlockModelBakingContext context, T data){ TextureSlots textures = new TextureSlots(context.getTopLevelTextureReferences()); boolean ambientOcclusion = context.getTopLevelAmbientOcclusion(); - TextureAtlasSprite particle = context.getModelBaker().sprites().resolveSlot(textures, "particle", () -> context.getModelIdentifier().toString()); + Material.Baked particle = context.getModelBaker().materials().resolveSlot(textures, "particle", () -> context.getModelIdentifier().toString()); QuadCollection quads = context.getTopLevelGeometry().bake(textures, context.getModelBaker(), context.getTransformation(), () -> context.getModelIdentifier().toString(), context.getNeoForgeAdditionalProperties()); return new SingleVariant(new SimpleModelWrapper(quads, ambientOcclusion, particle)); } @Override - public ItemModel bakeItemModel(ItemModelBakingContext context, T data){ + public ItemModel bakeItemModel(ItemModelBakingContext context, T data, Matrix4fc transformation){ TextureSlots textures = new TextureSlots(context.getTopLevelTextureReferences()); - TextureAtlasSprite particle = context.getModelBaker().sprites().resolveSlot(textures, "particle", () -> context.getModelIdentifier().toString()); + Material.Baked particle = context.getModelBaker().materials().resolveSlot(textures, "particle", () -> context.getModelIdentifier().toString()); QuadCollection quads = context.getTopLevelGeometry().bake(textures, context.getModelBaker(), BlockModelRotation.IDENTITY, () -> context.getModelIdentifier().toString()); - return new BlockModelWrapper(context.getTintSources(), quads.getAll(), new ModelRenderProperties( + return new CuboidItemModelWrapper(context.getTintSources(), quads, new ModelRenderProperties( context.getTopLevelUseBlockLighting(), particle, context.getTopLevelItemTransforms() - ), BlockModelWrapper.detectRenderType(quads.getAll())); + ), transformation); } @Override diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseBakedModel.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseBakedModel.java index 664582610..4c687523c 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseBakedModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseBakedModel.java @@ -1,6 +1,5 @@ package com.supermartijn642.fusion.model.types.base; -import com.supermartijn642.fusion.FusionClient; import com.supermartijn642.fusion.api.texture.DefaultTextureTypes; import com.supermartijn642.fusion.api.texture.TextureType; import com.supermartijn642.fusion.api.util.Pair; @@ -9,16 +8,16 @@ import com.supermartijn642.fusion.texture.types.continuous.ContinuousTextureType; import com.supermartijn642.fusion.texture.types.random.RandomTextureSprite; import com.supermartijn642.fusion.texture.types.random.RandomTextureType; -import net.minecraft.client.renderer.ItemBlockRenderTypes; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.BlockModelPart; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.chunk.ChunkSectionLayer; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -29,90 +28,81 @@ */ public class BaseBakedModel implements BlockStateModel { - private final Map,List[]> blockMesh; - private final List> blockRenderTypes; + private final List[] blockMesh; private final List sprites; private final boolean hasSpecialQuads; private final boolean hasAmbientOcclusion; - private final TextureAtlasSprite particleIcon; + private final Material.Baked particleMaterial; + private final @BakedQuad.MaterialFlags int materialFlags; - public BaseBakedModel(List quads, boolean hasAmbientOcclusion, TextureAtlasSprite particleIcon, ChunkSectionLayer neoforgeRenderType){ + public BaseBakedModel(List quads, boolean hasAmbientOcclusion, Material.Baked particleMaterial, ModelBaker.Interner interner){ this.hasAmbientOcclusion = hasAmbientOcclusion; - this.particleIcon = particleIcon; + this.particleMaterial = particleMaterial; // Create block and item meshes from the quads - Map,List[]> blockMesh = new HashMap<>(); - Set> blockRenderTypes = new HashSet<>(); + //noinspection unchecked + List[] blockMesh = new List[7]; HashMap sprites = new HashMap<>(); boolean hasSpecialQuads = false; + @BakedQuad.MaterialFlags int materialFlags = 0; MutableQuad mutableQuad = new MutableQuad(); for(BaseModelQuad quad : quads){ - mutableQuad.fillFromBakedQuad(quad.bakedQuad()); + quad.fill(mutableQuad); mutableQuad.ambientOcclusion(!quad.emissive() && hasAmbientOcclusion); - mutableQuad.emissive(quad.emissive()); // Tag quads which need additional processing int spriteIndex = -1; if(quad.textureType() == DefaultTextureTypes.RANDOM || quad.textureType() == DefaultTextureTypes.CONTINUOUS){ // Give each sprite a unique index - spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().sprite(), o -> sprites.size()); + spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().materialInfo().sprite(), o -> sprites.size()); hasSpecialQuads = true; } - TaggedBakedQuad finishedQuad = new TaggedBakedQuad(mutableQuad.toBakedQuad(), quad.textureType(), spriteIndex); + TaggedBakedQuad finishedQuad = new TaggedBakedQuad(mutableQuad.toBakedQuad(interner), quad.textureType(), spriteIndex); // Add the block quads - Optional layer = FusionClient.getChunkLayer(quad.renderType()); - if(layer.isEmpty() && neoforgeRenderType != null) - layer = Optional.of(neoforgeRenderType); - blockRenderTypes.add(layer); int cullIndex = cullIndex(quad.cullDirection()); - //noinspection unchecked - List[] mesh = blockMesh.computeIfAbsent(layer, r -> new List[7]); - if(mesh[cullIndex] == null) - mesh[cullIndex] = new ArrayList<>(); - mesh[cullIndex].add(finishedQuad); + if(blockMesh[cullIndex] == null) + blockMesh[cullIndex] = new ArrayList<>(); + blockMesh[cullIndex].add(finishedQuad); + materialFlags |= finishedQuad.bakedQuad.materialInfo().flags(); } - this.blockMesh = Map.copyOf(blockMesh); - this.blockRenderTypes = List.copyOf(blockRenderTypes); + this.blockMesh = blockMesh; this.sprites = sprites.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey).toList(); this.hasSpecialQuads = hasSpecialQuads; + this.materialFlags = materialFlags; } @Override - public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ - for(Optional layer : this.blockRenderTypes){ - parts.add(new BlockModelPart() { - @Override - public List getQuads(@Nullable Direction cullDirection){ - return BaseBakedModel.this.getQuads(level, pos, state, cullDirection, random, layer); - } - - @Override - public boolean useAmbientOcclusion(){ - return BaseBakedModel.this.hasAmbientOcclusion; - } - - @Override - public TextureAtlasSprite particleIcon(){ - return BaseBakedModel.this.particleIcon; - } - - @Override - public ChunkSectionLayer getRenderType(BlockState state){ - //noinspection deprecation - return layer.orElseGet(() -> ItemBlockRenderTypes.getChunkRenderType(state)); - } - }); - } + public void collectParts(BlockAndTintGetter level, BlockPos pos, BlockState state, RandomSource random, List parts){ + parts.add(new BlockStateModelPart() { + @Override + public List getQuads(@Nullable Direction cullDirection){ + return BaseBakedModel.this.getQuads(level, pos, state, cullDirection, random); + } + + @Override + public boolean useAmbientOcclusion(){ + return BaseBakedModel.this.hasAmbientOcclusion; + } + + @Override + public Material.Baked particleMaterial(){ + return BaseBakedModel.this.particleMaterial; + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return BaseBakedModel.this.materialFlags; + } + }); } @Override - public void collectParts(RandomSource random, List parts){ + public void collectParts(RandomSource random, List parts){ this.collectParts(null, null, null, random, parts); } - @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - private List getQuads(@Nullable BlockAndTintGetter blockView, @Nullable BlockPos pos, @Nullable BlockState state, @Nullable Direction cullDirection, RandomSource random, Optional layer){ - List quads = this.blockMesh.get(layer)[cullIndex(cullDirection)]; + private List getQuads(@Nullable BlockAndTintGetter blockView, @Nullable BlockPos pos, @Nullable BlockState state, @Nullable Direction cullDirection, RandomSource random){ + List quads = this.blockMesh[cullIndex(cullDirection)]; if(quads == null) return Collections.emptyList(); @@ -148,7 +138,7 @@ private List getQuads(@Nullable BlockAndTintGetter blockView, @Nullab else // Handle continuous texture type ContinuousTextureType.processQuad(mutableQuad, pos, quad.bakedQuad.direction(), (ContinuousTextureSprite)sprite); - bakedQuads.add(mutableQuad.toBakedQuad()); + bakedQuads.add(mutableQuad.toBakedQuad(null)); }else bakedQuads.add(quad.bakedQuad); } @@ -161,8 +151,13 @@ private List getQuads(@Nullable BlockAndTintGetter blockView, @Nullab } @Override - public TextureAtlasSprite particleIcon(){ - return this.particleIcon; + public Material.Baked particleMaterial(){ + return this.particleMaterial; + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return this.materialFlags; } private static int cullIndex(Direction cullDirection){ diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseItemModel.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseItemModel.java index aaa3e7b6e..f6c09f366 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseItemModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseItemModel.java @@ -1,25 +1,23 @@ package com.supermartijn642.fusion.model.types.base; import com.google.common.base.Suppliers; -import com.supermartijn642.fusion.api.util.Pair; import com.supermartijn642.fusion.model.MutableQuad; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.color.item.ItemTintSource; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.Sheets; -import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.item.CuboidItemModelWrapper; import net.minecraft.client.renderer.item.*; -import net.minecraft.client.renderer.rendertype.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.world.entity.ItemOwner; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import org.joml.Vector3fc; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.function.Supplier; /** @@ -29,43 +27,29 @@ public class BaseItemModel implements ItemModel { private final List tints; private final ModelRenderProperties properties; - private final List>> mesh; + private final List mesh = new ArrayList<>(); private final Supplier extents; private final boolean animated; + private final Matrix4fc transformation; - public BaseItemModel(List tints, List quads, ModelRenderProperties properties, RenderType neoforgeItemRenderType, RenderType neoforgeBlockRenderType){ + public BaseItemModel(List tints, List quads, ModelRenderProperties properties, Matrix4fc transformation, ModelBaker.Interner interner){ this.tints = tints; this.properties = properties; - this.extents = Suppliers.memoize(() -> BlockModelWrapper.computeExtents(quads.stream().map(BaseModelQuad::bakedQuad).toList())); + this.extents = Suppliers.memoize(() -> CuboidItemModelWrapper.computeExtents(quads.stream().map(BaseModelQuad::bakedQuad).toList())); // Create the item mesh - Map> mesh = new LinkedHashMap<>(); + @BakedQuad.MaterialFlags int flags = 0; MutableQuad mutableQuad = new MutableQuad(); for(BaseModelQuad quad : quads){ - mutableQuad.fillFromBakedQuad(quad.bakedQuad()); - mutableQuad.emissive(quad.emissive()); - - // Add the item quads - RenderType renderType = quad.bakedQuad().sprite().atlasLocation().equals(TextureAtlas.LOCATION_BLOCKS) ? - neoforgeBlockRenderType == null || quad.renderType() != null ? Sheets.translucentBlockItemSheet() : neoforgeBlockRenderType : - neoforgeItemRenderType == null || quad.renderType() != null ? Sheets.translucentItemSheet() : neoforgeItemRenderType; - List itemQuads = mesh.computeIfAbsent(renderType, k -> new ArrayList<>()); - itemQuads.add(mutableQuad.toBakedQuad()); + quad.fill(mutableQuad); + this.mesh.add(mutableQuad.toBakedQuad(interner)); + flags |= quad.bakedQuad().materialInfo().flags(); } - this.mesh = mesh.entrySet().stream() - .map(entry -> Pair.of(entry.getKey(), entry.getValue())) - .toList(); // Check whether the quads contain animated textures - boolean animated = false; - for(BaseModelQuad quad : quads){ - //noinspection resource - if(quad.bakedQuad().sprite().contents().isAnimated()){ - animated = true; - break; - } - } - this.animated = animated; + this.animated = (flags & BakedQuad.FLAG_ANIMATED) != 0; + + this.transformation = transformation; } @Override @@ -73,27 +57,25 @@ public void update(ItemStackRenderState renderState, ItemStack stack, ItemModelR renderState.appendModelIdentityElement(this); if(this.animated) renderState.setAnimated(); - ItemStackRenderState.FoilType foilType = stack.hasFoil() ? BlockModelWrapper.hasSpecialAnimatedTexture(stack) ? ItemStackRenderState.FoilType.SPECIAL : ItemStackRenderState.FoilType.STANDARD : null; + ItemStackRenderState.FoilType foilType = stack.hasFoil() ? CuboidItemModelWrapper.hasSpecialAnimatedTexture(stack) ? ItemStackRenderState.FoilType.SPECIAL : ItemStackRenderState.FoilType.STANDARD : null; if(foilType != null){ renderState.setAnimated(); renderState.appendModelIdentityElement(foilType); } - int tints = this.tints.size(); - int[] tintValues = new int[tints]; - for(int j = 0; j < tints; j++){ - int tint = this.tints.get(j).calculate(stack, level, owner == null ? null : owner.asLivingEntity()); - tintValues[j] = tint; - renderState.appendModelIdentityElement(tint); - } - for(Pair> pair : this.mesh){ - ItemStackRenderState.LayerRenderState layer = renderState.newLayer(); - if(foilType != null) - layer.setFoilType(foilType); - System.arraycopy(tintValues, 0, layer.prepareTintLayers(tints), 0, tintValues.length); - layer.setExtents(this.extents); - this.properties.applyToLayer(layer, displayContext); - layer.prepareQuadList().addAll(pair.right()); - layer.setRenderType(pair.left()); + ItemStackRenderState.LayerRenderState layer = renderState.newLayer(); + if(foilType != null) + layer.setFoilType(foilType); + if(!this.tints.isEmpty()){ + IntList tintLayers = layer.tintLayers(); + for(ItemTintSource tintSource : this.tints){ + int tint = tintSource.calculate(stack, level, owner == null ? null : owner.asLivingEntity()); + tintLayers.add(tint); + renderState.appendModelIdentityElement(tint); + } } + layer.setExtents(this.extents); + layer.setLocalTransform(this.transformation); + this.properties.applyToLayer(layer, displayContext); + layer.prepareQuadList().addAll(this.mesh); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataBuilderImpl.java index 7931c63d4..7bbb96cf8 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataBuilderImpl.java @@ -2,10 +2,9 @@ import com.supermartijn642.fusion.api.model.data.BaseModelData; import com.supermartijn642.fusion.api.model.data.BaseModelDataBuilder; -import com.supermartijn642.fusion.util.TextureAtlases; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.TextureSlots; -import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.resources.Identifier; import java.util.*; @@ -16,7 +15,7 @@ public class BaseModelDataBuilderImpl implements BaseModelDataBuilder { private final Set parents = new LinkedHashSet<>(); // This should maintain insertion order - private final Map textures = new HashMap<>(); + private final Map textures = new HashMap<>(); @Override public BaseModelDataBuilderImpl parent(Identifier parent){ @@ -34,24 +33,24 @@ public BaseModelDataBuilderImpl texture(String key, String reference){ if(!key.matches("[a-zA-Z_]*")) throw new IllegalArgumentException("Texture reference must only contain characters [a-zA-Z_]!"); - // Prepend '#' character - if(reference.charAt(0) != '#') - reference = '#' + reference; + // Strip '#' character + if(reference.charAt(0) == '#') + reference = reference.substring(1); if(this.textures.containsKey(key)) throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + reference + "'!"); - this.textures.put(key, reference); + this.textures.put(key, new TextureSlots.Reference(reference)); return this; } @Override - public BaseModelDataBuilderImpl texture(String key, Identifier texture){ + public BaseModelDataBuilderImpl texture(String key, Material material){ if(!key.matches("[a-zA-Z_]*")) throw new IllegalArgumentException("Texture reference must only contain characters [a-zA-Z_]!"); if(this.textures.containsKey(key)) - throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + texture + "'!"); + throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + material + "'!"); - this.textures.put(key, texture.toString()); + this.textures.put(key, new TextureSlots.Value(material)); return this; } @@ -60,14 +59,8 @@ public BaseModelData build(){ List parents = new ArrayList<>(this.parents); // Create a vanilla model representation of the properties Identifier parent = parents.isEmpty() ? null : parents.get(0); - TextureSlots.Data.Builder textures = new TextureSlots.Data.Builder(); - this.textures.forEach((key, value) -> { - if(value.charAt(0) == '#') - textures.addReference(key, value.substring(1)); - else - textures.addTexture(key, new Material(TextureAtlases.getBlocks(), Identifier.parse(value))); - }); - BlockModel vanillaModel = new BlockModel(null, null, null, null, textures.build(), parent); + TextureSlots.Data textures = new TextureSlots.Data(Map.copyOf(this.textures)); + CuboidModel vanillaModel = new CuboidModel(null, null, null, null, textures, parent); return new BaseModelDataImpl(vanillaModel, parents, Collections.emptyList()); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataImpl.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataImpl.java index 21316ad1d..3e426ac03 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelDataImpl.java @@ -5,17 +5,18 @@ import com.supermartijn642.fusion.api.model.BlockModelBakingContext; import com.supermartijn642.fusion.api.model.DefaultModelTypes; import com.supermartijn642.fusion.api.model.ModelInstance; -import com.supermartijn642.fusion.api.model.SpriteIdentifier; import com.supermartijn642.fusion.api.model.data.BaseModelData; -import net.minecraft.client.renderer.block.model.*; -import net.minecraft.client.renderer.texture.SpriteContents; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.QuadCollection; -import net.minecraft.client.resources.model.UnbakedGeometry; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.*; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.geometry.QuadCollection; +import net.minecraft.client.resources.model.geometry.UnbakedGeometry; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.core.Direction; import net.minecraft.resources.Identifier; import net.minecraft.world.item.ItemDisplayContext; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Deque; @@ -30,18 +31,18 @@ */ public class BaseModelDataImpl implements BaseModelData { - protected final BlockModel model; + protected final CuboidModel model; protected final List parents; protected final List elements; - public BaseModelDataImpl(BlockModel model, List parents, List elements){ + public BaseModelDataImpl(CuboidModel model, List parents, List elements){ this.model = model; this.parents = ImmutableList.copyOf(parents); this.elements = ImmutableList.copyOf(elements); } @Override - public BlockModel getVanillaModel(){ + public CuboidModel getVanillaModel(){ return this.model; } @@ -111,7 +112,7 @@ public ItemTransform findItemTransform(BlockModelBakingContext context, ItemDisp ); } - public SpriteIdentifier findParticleSprite(BlockModelBakingContext context){ + public Material findParticleMaterial(BlockModelBakingContext context){ ModelInstance model = ModelInstance.of(DefaultModelTypes.BASE, this); // Repeatedly resolve key references until we get to a texture @@ -123,17 +124,17 @@ public SpriteIdentifier findParticleSprite(BlockModelBakingContext context){ TextureSlots.SlotContents contents = this.findProperty(context, model, m -> m.textureSlots().values().get(finalCurrentKey)); // If a key could not be found, return the missing texture if(contents == null) - return SpriteIdentifier.missing(); + return context.missingMaterial(); // If a texture is found return it - if(contents instanceof TextureSlots.Value) - return SpriteIdentifier.of(((TextureSlots.Value)contents).material()); + if(contents instanceof TextureSlots.Value(Material material)) + return material; // Check if a key has already been encountered currentKey = ((TextureSlots.Reference)contents).target(); if(encounteredKeys.contains(currentKey)){ FusionClient.LOGGER.warn("Unable to resolve texture due to circular references {}->'{}' in '{}'!", encounteredKeys.stream().map(o -> "'" + o + "'").collect(Collectors.joining("->")), currentKey, context.getModelIdentifier()); - return SpriteIdentifier.missing(); + return context.missingMaterial(); } encounteredKeys.add(currentKey); } @@ -155,9 +156,10 @@ private void bakeQuads(BlockModelBakingContext context, ModelInstance model, // Bake the faces of each element for(BaseModelElement element : elements){ for(Direction direction : element.original.faces().keySet()){ - BlockElementFace face = element.original.faces().get(direction); - TextureAtlasSprite sprite = context.getTexture(this.resolveMaterial(context, modelStack, face.texture())); - BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker().parts(), element.original.from(), element.original.to(), face, sprite, direction, context.getTransformation(), element.original.rotation(), element.original.shade(), element.original.lightEmission()); + CuboidFace face = element.original.faces().get(direction); + Material unbakedMaterial = this.resolveMaterial(context, modelStack, face.texture()); + Material.Baked material = unbakedMaterial != null ? context.bakeMaterial(unbakedMaterial) : context.bakeMaterial(context.missingMaterial()); + BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker(), element.original.from(), element.original.to(), face, material, direction, context.getTransformation(), element.original.rotation(), element.original.shade(), element.original.lightEmission()); Direction cullDirection = face.cullForDirection() != null ? Direction.rotate(context.getTransformation().transformation().getMatrix(), face.cullForDirection()) : null; output.accept(new BaseModelQuad(quad, cullDirection)); } @@ -192,7 +194,7 @@ private void bakeQuads(BlockModelBakingContext context, ModelInstance model, modelStack.removeLast(); } - protected SpriteIdentifier resolveMaterial(BlockModelBakingContext context, Deque> modelStack, String key){ + protected @Nullable Material resolveMaterial(BlockModelBakingContext context, Deque> modelStack, String key){ if(key.charAt(0) == '#') key = key.substring(1); @@ -218,33 +220,32 @@ protected SpriteIdentifier resolveMaterial(BlockModelBakingContext context, Dequ } // If a key could not be found, return the missing texture if(contents == null) - return SpriteIdentifier.missing(); + return null; // If a texture is found return it - if(contents instanceof TextureSlots.Value) - return SpriteIdentifier.of(((TextureSlots.Value)contents).material()); + if(contents instanceof TextureSlots.Value(Material material)) + return material; // Check if a key has already been encountered currentKey = ((TextureSlots.Reference)contents).target(); if(encounteredKeys.contains(currentKey)){ FusionClient.LOGGER.warn("Unable to resolve texture due to circular references {}->'{}' in '{}'!", encounteredKeys.stream().map(o -> "'" + o + "'").collect(Collectors.joining("->")), currentKey, context.getModelIdentifier()); - return SpriteIdentifier.missing(); + return null; } encounteredKeys.add(currentKey); } } - protected List generateItemModel(BlockModelBakingContext context, Deque> modelStack){ - List elements = new ArrayList<>(); + protected QuadCollection bakeItemModel(BlockModelBakingContext context, Deque> modelStack){ + QuadCollection.Builder quads = new QuadCollection.Builder(); for(int layer = 0; layer < ItemModelGenerator.LAYERS.size(); layer++){ String layerName = ItemModelGenerator.LAYERS.get(layer); - SpriteIdentifier sprite = this.resolveMaterial(context, modelStack, layerName); - if(SpriteIdentifier.missing().equals(sprite)) + Material unbakedMaterial = this.resolveMaterial(context, modelStack, layerName); + if(unbakedMaterial == null) break; - - SpriteContents spriteContents = context.getTexture(sprite).contents(); - elements.addAll(ItemModelGenerator.processFrames(layer, layerName, spriteContents)); + Material.Baked material = context.bakeMaterial(unbakedMaterial); + quads.addAll(context.getModelBaker().compute(new ItemModelGenerator.ItemLayerKey(material, context.getTransformation(), layer))); } - return elements; + return quads.build(); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelElement.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelElement.java index c391a5354..f0ee55483 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelElement.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelElement.java @@ -1,8 +1,8 @@ package com.supermartijn642.fusion.model.types.base; -import net.minecraft.client.renderer.block.model.BlockElement; -import net.minecraft.client.renderer.block.model.BlockElementFace; -import net.minecraft.client.renderer.block.model.BlockElementRotation; +import net.minecraft.client.resources.model.cuboid.CuboidFace; +import net.minecraft.client.resources.model.cuboid.CuboidModelElement; +import net.minecraft.client.resources.model.cuboid.CuboidRotation; import net.minecraft.core.Direction; import org.jetbrains.annotations.Nullable; import org.joml.Vector3fc; @@ -14,9 +14,9 @@ */ public class BaseModelElement { - public final BlockElement original; + public final CuboidModelElement original; - public BaseModelElement(Vector3fc from, Vector3fc to, Map faces, @Nullable BlockElementRotation rotation, boolean shade, int lightEmission){ - this.original = new BlockElement(from, to, faces, rotation, shade, lightEmission); + public BaseModelElement(Vector3fc from, Vector3fc to, Map faces, @Nullable CuboidRotation rotation, boolean shade, int lightEmission){ + this.original = new CuboidModelElement(from, to, faces, rotation, shade, lightEmission); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelQuad.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelQuad.java index 54096d48e..c3c4f6691 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelQuad.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelQuad.java @@ -3,9 +3,10 @@ import com.supermartijn642.fusion.api.texture.SpriteHelper; import com.supermartijn642.fusion.api.texture.TextureType; import com.supermartijn642.fusion.api.texture.data.BaseTextureData; +import com.supermartijn642.fusion.model.MutableQuad; import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; -import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.core.Direction; /** @@ -16,22 +17,21 @@ public class BaseModelQuad { private final BakedQuad bakedQuad; private final TextureType textureType; private final Direction cullDirection; - private final BaseTextureData.RenderType renderType; private final boolean emissive; + private final int tintIndex; public BaseModelQuad(BakedQuad bakedQuad, Direction cullDirection){ - this.textureType = SpriteHelper.getTextureType(bakedQuad.sprite()); + BakedQuad.MaterialInfo materialInfo = bakedQuad.materialInfo(); + TextureAtlasSprite sprite = materialInfo.sprite(); + this.textureType = SpriteHelper.getTextureType(sprite); this.cullDirection = cullDirection; - TextureAtlasSprite sprite = bakedQuad.sprite(); if(sprite instanceof BaseTextureSprite && ((BaseTextureSprite)sprite).data() != null){ BaseTextureData data = ((BaseTextureSprite)sprite).data(); - this.renderType = data.getRenderType(); this.emissive = data.isEmissive(); - if(data.getTinting() != null) // Create an identical quad, but with tint index '39216' - bakedQuad = new BakedQuad(bakedQuad.position0(), bakedQuad.position1(), bakedQuad.position2(), bakedQuad.position3(), bakedQuad.packedUV0(), bakedQuad.packedUV1(), bakedQuad.packedUV2(), bakedQuad.packedUV3(), 39216, bakedQuad.direction(), bakedQuad.sprite(), bakedQuad.shade(), bakedQuad.lightEmission(), bakedQuad.bakedNormals(), bakedQuad.bakedColors(), bakedQuad.hasAmbientOcclusion()); + this.tintIndex = data.getTinting() != null ? 39216 : bakedQuad.materialInfo().tintIndex(); }else{ - this.renderType = null; this.emissive = false; + this.tintIndex = bakedQuad.materialInfo().tintIndex(); } this.bakedQuad = bakedQuad; } @@ -48,11 +48,13 @@ public Direction cullDirection(){ return this.cullDirection; } - public BaseTextureData.RenderType renderType(){ - return this.renderType; - } - public boolean emissive(){ return this.emissive; } + + public void fill(MutableQuad mutableQuad){ + mutableQuad.fillFromBakedQuad(this.bakedQuad); + mutableQuad.emissive(this.emissive); + mutableQuad.tintIndex(this.tintIndex); + } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelType.java b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelType.java index d222caf1e..fad975601 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelType.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/base/BaseModelType.java @@ -10,18 +10,16 @@ import com.supermartijn642.fusion.api.model.ModelType; import com.supermartijn642.fusion.api.model.data.BaseModelData; import com.supermartijn642.fusion.util.IdentifierUtil; -import net.minecraft.client.renderer.block.model.*; -import net.minecraft.client.renderer.chunk.ChunkSectionLayer; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.renderer.item.ModelRenderProperties; -import net.minecraft.client.renderer.rendertype.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.*; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; import net.minecraft.world.item.ItemDisplayContext; -import net.neoforged.neoforge.client.RenderTypeGroup; -import net.neoforged.neoforge.client.model.NeoForgeModelProperties; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.ArrayList; import java.util.Collection; @@ -56,27 +54,25 @@ public BlockStateModel bakeBlockModel(BlockModelBakingContext context, BaseModel List quads = ((BaseModelDataImpl)data).bakeQuads(context); // Gather remaining model properties boolean ambientOcclusion = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::ambientOcclusion, true); - TextureAtlasSprite particleSprite = context.getTexture(((BaseModelDataImpl)data).findParticleSprite(context)); - RenderTypeGroup neoforgeRenderTypeGroup = context.getNeoForgeAdditionalProperties().getOptional(NeoForgeModelProperties.RENDER_TYPE); - ChunkSectionLayer neoforgeRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.block(); + Material.Baked particleMaterial = context.bakeMaterial(((BaseModelDataImpl)data).findParticleMaterial(context)); // Finally, create the model return new BaseBakedModel( quads, ambientOcclusion, - particleSprite, - neoforgeRenderType + particleMaterial, + context.getModelBaker().interner() ); } @Override - public ItemModel bakeItemModel(ItemModelBakingContext context, BaseModelData data){ + public ItemModel bakeItemModel(ItemModelBakingContext context, BaseModelData data, Matrix4fc transformation){ // Check for circular dependencies ((BaseModelDataImpl)data).validateParents(context); // Bake the quads List quads = ((BaseModelDataImpl)data).bakeQuads(context); // Gather remaining model properties - boolean usesBlockLight = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::guiLight, BlockModel.GuiLight.SIDE).lightLikeBlock(); - TextureAtlasSprite particleSprite = context.getTexture(((BaseModelDataImpl)data).findParticleSprite(context)); + boolean usesBlockLight = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::guiLight, CuboidModel.GuiLight.SIDE).lightLikeBlock(); + Material.Baked particleMaterial = context.bakeMaterial(((BaseModelDataImpl)data).findParticleMaterial(context)); //noinspection deprecation ItemTransforms transforms = new ItemTransforms( ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.THIRD_PERSON_LEFT_HAND), @@ -89,23 +85,20 @@ public ItemModel bakeItemModel(ItemModelBakingContext context, BaseModelData dat ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.FIXED), ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.ON_SHELF) ); - RenderTypeGroup neoforgeRenderTypeGroup = context.getNeoForgeAdditionalProperties().getOptional(NeoForgeModelProperties.RENDER_TYPE); - RenderType neoforgeItemRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.entityItem(); - RenderType neoforgeBlockRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.entityBlock(); // Finally, create the model return new BaseItemModel( context.getTintSources(), quads, - new ModelRenderProperties(usesBlockLight, particleSprite, transforms), - neoforgeItemRenderType, - neoforgeBlockRenderType + new ModelRenderProperties(usesBlockLight, particleMaterial, transforms), + transformation, + context.getModelBaker().interner() ); } @Override public BaseModelData deserialize(JsonObject json) throws JsonParseException{ // Deserialize the vanilla model attributes - BlockModel model = DefaultModelTypes.VANILLA.deserialize(json); + CuboidModel model = DefaultModelTypes.VANILLA.deserialize(json); // Read parents if(json.has("parent") && json.has("parents")) throw new JsonParseException("Model can only have either 'parent' or 'parents', not both!"); @@ -131,14 +124,14 @@ public BaseModelData deserialize(JsonObject json) throws JsonParseException{ parents.add(Identifier.parse(parent)); } if(!parents.isEmpty()) - model = new BlockModel(model.geometry(), model.guiLight(), model.ambientOcclusion(), model.transforms(), model.textureSlots(), parents.get(0), model.rootTransform(), model.renderTypeGroup(), model.partVisibility()); + model = new CuboidModel(model.geometry(), model.guiLight(), model.ambientOcclusion(), model.transforms(), model.textureSlots(), parents.get(0), model.rootTransform(), model.partVisibility()); } List elements = List.of(); - if(model.geometry() instanceof SimpleUnbakedGeometry( - List vanillaElements + if(model.geometry() instanceof UnbakedCuboidGeometry( + List vanillaElements )){ elements = new ArrayList<>(vanillaElements.size()); - for(BlockElement element : vanillaElements) + for(CuboidModelElement element : vanillaElements) elements.add(new BaseModelElement(element.from(), element.to(), element.faces(), element.rotation(), element.shade(), element.lightEmission())); } return new BaseModelDataImpl(model, parents, elements); diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingBakedModel.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingBakedModel.java index 11a3ab4d7..22db29fa9 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingBakedModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingBakedModel.java @@ -2,7 +2,6 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; -import com.supermartijn642.fusion.FusionClient; import com.supermartijn642.fusion.api.predicate.ConnectionDirection; import com.supermartijn642.fusion.api.predicate.ConnectionPredicate; import com.supermartijn642.fusion.api.texture.DefaultTextureTypes; @@ -17,16 +16,16 @@ import com.supermartijn642.fusion.texture.types.random.RandomTextureSprite; import com.supermartijn642.fusion.texture.types.random.RandomTextureType; import net.minecraft.client.model.geom.builders.UVPair; -import net.minecraft.client.renderer.ItemBlockRenderTypes; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.BlockModelPart; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.chunk.ChunkSectionLayer; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; +import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; import org.joml.Vector3fc; @@ -88,25 +87,26 @@ private static float[] getPosition(BakedQuad quad, int vertexIndex){ return new float[]{position.x(), position.y(), position.z()}; } - private final List completeBlockMesh; - private final Map,List[]> blockMesh; - private final List> blockRenderTypes; + private final BlockStateModelPart completeBlockMesh; + private final List[] blockMesh; private final List predicates; private final List sprites; private final boolean hasSpecialQuads; private final boolean hasAmbientOcclusion; - private final TextureAtlasSprite particleIcon; + private final Material.Baked particleMaterial; + private final @BakedQuad.MaterialFlags int materialFlags; - public ConnectingBakedModel(List quads, boolean hasAmbientOcclusion, TextureAtlasSprite particleIcon, ChunkSectionLayer neoforgeRenderType){ + public ConnectingBakedModel(List quads, boolean hasAmbientOcclusion, Material.Baked particleMaterial, ModelBaker.Interner interner){ this.hasAmbientOcclusion = hasAmbientOcclusion; - this.particleIcon = particleIcon; + this.particleMaterial = particleMaterial; // Create block and item meshes from the quads - Map,List[]> blockMesh = new HashMap<>(); - Set> blockRenderTypes = new HashSet<>(); + //noinspection unchecked + List[] blockMesh = new List[7]; HashMap predicates = new HashMap<>(); HashMap sprites = new HashMap<>(); boolean hasSpecialQuads = false; + @BakedQuad.MaterialFlags int materialFlags = 0; OrientedMutableQuad mutableQuad = new OrientedMutableQuad(); for(ConnectingModelQuad quad : quads){ TextureType textureType = quad.textureType(); @@ -123,72 +123,60 @@ public ConnectingBakedModel(List quads, boolean hasAmbientO // Give each combination of direction, orientation, and predicate a unique index predicateIndex = predicates.computeIfAbsent(new QuadPredicates(direction, orientation, predicate), o -> predicates.size()); // Give each sprite a unique index - spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().sprite(), o -> sprites.size()); + spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().materialInfo().sprite(), o -> sprites.size()); } // Tag quads which need additional processing if(quad.textureType() == DefaultTextureTypes.RANDOM || quad.textureType() == DefaultTextureTypes.CONTINUOUS){ // Give each sprite a unique index - spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().sprite(), o -> sprites.size()); + spriteIndex = sprites.computeIfAbsent(quad.bakedQuad().materialInfo().sprite(), o -> sprites.size()); hasSpecialQuads = true; } // Submit the quads for(int quadIndex = 0; quadIndex < auxiliaryQuadCount + 1; quadIndex++){ - mutableQuad.fillFromBakedQuad(quad.bakedQuad()); + quad.fill(mutableQuad); mutableQuad.ambientOcclusion(!quad.emissive() && hasAmbientOcclusion); - mutableQuad.emissive(quad.emissive()); // Add the block quad - TaggedBakedQuad finishedQuad = new TaggedBakedQuad(mutableQuad.toBakedQuad(), textureType, spriteIndex, predicateIndex, quadIndex); - Optional layer = FusionClient.getChunkLayer(quad.renderType()); - if(layer.isEmpty() && neoforgeRenderType != null) - layer = Optional.of(neoforgeRenderType); - blockRenderTypes.add(layer); + TaggedBakedQuad finishedQuad = new TaggedBakedQuad(mutableQuad.toBakedQuad(interner), textureType, spriteIndex, predicateIndex, quadIndex); int cullIndex = cullIndex(quad.cullDirection()); - //noinspection unchecked - List[] mesh = blockMesh.computeIfAbsent(layer, r -> new List[7]); - if(mesh[cullIndex] == null) - mesh[cullIndex] = new ArrayList<>(); - mesh[cullIndex].add(finishedQuad); + if(blockMesh[cullIndex] == null) + blockMesh[cullIndex] = new ArrayList<>(); + blockMesh[cullIndex].add(finishedQuad); + materialFlags |= finishedQuad.bakedQuad.materialInfo().flags(); } } - this.blockMesh = Map.copyOf(blockMesh); - this.blockRenderTypes = List.copyOf(blockRenderTypes); + this.blockMesh = blockMesh; this.predicates = predicates.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey).toList(); this.sprites = sprites.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey).toList(); this.hasSpecialQuads = hasSpecialQuads; + this.materialFlags = materialFlags; // Create a mesh of unprocessed quads - List parts = new ArrayList<>(); - for(Map.Entry,List[]> entry : blockMesh.entrySet()){ - Optional layer = entry.getKey(); - //noinspection unchecked - List[] mesh = Arrays.stream(entry.getValue()) - .map(l -> l == null ? List.of() : l.stream().map(q -> q.bakedQuad).toList()) - .toArray(List[]::new); - parts.add(new BlockModelPart() { - @Override - public List getQuads(@Nullable Direction cullDirection){ - return mesh[cullIndex(cullDirection)]; - } + //noinspection unchecked + List[] mesh = Arrays.stream(blockMesh) + .map(l -> l == null ? List.of() : l.stream().map(q -> q.bakedQuad).toList()) + .toArray(List[]::new); + this.completeBlockMesh = new BlockStateModelPart() { + @Override + public List getQuads(@Nullable Direction cullDirection){ + return mesh[cullIndex(cullDirection)]; + } - @Override - public boolean useAmbientOcclusion(){ - return hasAmbientOcclusion; - } + @Override + public boolean useAmbientOcclusion(){ + return hasAmbientOcclusion; + } - @Override - public TextureAtlasSprite particleIcon(){ - return particleIcon; - } + @Override + public Material.Baked particleMaterial(){ + return particleMaterial; + } - @Override - public ChunkSectionLayer getRenderType(BlockState state){ - //noinspection deprecation - return layer.orElseGet(() -> ItemBlockRenderTypes.getChunkRenderType(state)); - } - }); - } - this.completeBlockMesh = List.copyOf(parts); + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return ConnectingBakedModel.this.materialFlags; + } + }; } private static TextureOrientation findOrientation(BakedQuad quad){ @@ -252,11 +240,11 @@ private static TextureOrientation findOrientation(BakedQuad quad){ } @Override - public void collectParts(BlockAndTintGetter blockView, BlockPos pos, BlockState state, RandomSource random, List parts){ + public void collectParts(BlockAndTintGetter blockView, BlockPos pos, BlockState state, RandomSource random, List parts){ // If either level or position is not given, the connected textures cannot be updated, so don't process them boolean processConnectingTextures = blockView != null && pos != null && !this.predicates.isEmpty(); if(!processConnectingTextures && !this.hasSpecialQuads){ - parts.addAll(this.completeBlockMesh); + parts.add(this.completeBlockMesh); return; } @@ -274,95 +262,91 @@ public void collectParts(BlockAndTintGetter blockView, BlockPos pos, BlockState // Create one model part for each render type OrientedMutableQuad mutableQuad = new OrientedMutableQuad(); - for(Optional layer : this.blockRenderTypes){ - List[] mesh = this.blockMesh.get(layer); - //noinspection unchecked - List[] processedMesh = new List[mesh.length]; - for(Direction cullDirection : CULL_DIRECTIONS){ - List quads = this.blockMesh.get(layer)[cullIndex(cullDirection)]; - if(quads == null){ - processedMesh[cullIndex(cullDirection)] = List.of(); - continue; + //noinspection unchecked + List[] processedMesh = new List[this.blockMesh.length]; + for(Direction cullDirection : CULL_DIRECTIONS){ + List quads = this.blockMesh[cullIndex(cullDirection)]; + if(quads == null){ + processedMesh[cullIndex(cullDirection)] = List.of(); + continue; + } + ArrayList bakedQuads = new ArrayList<>(quads.size()); + + for(TaggedBakedQuad quad : quads){ + // Process special texture type quads + if(pos != null && (quad.textureType == DefaultTextureTypes.RANDOM || quad.textureType == DefaultTextureTypes.CONTINUOUS)){ + // Get the sprite + TextureAtlasSprite sprite = this.sprites.get(quad.spriteIndex); + + mutableQuad.fillFromBakedQuad(quad.bakedQuad); + mutableQuad.resetPermutation(); + if(quad.textureType == DefaultTextureTypes.RANDOM) + // Handle random texture type + RandomTextureType.processQuad(mutableQuad, pos, quad.bakedQuad.direction(), random, (RandomTextureSprite)sprite); + else + // Handle continuous texture type + ContinuousTextureType.processQuad(mutableQuad, pos, quad.bakedQuad.direction(), (ContinuousTextureSprite)sprite); + bakedQuads.add(mutableQuad.toBakedQuad(null)); } - ArrayList bakedQuads = new ArrayList<>(quads.size()); - - for(TaggedBakedQuad quad : quads){ - // Process special texture type quads - if(pos != null && (quad.textureType == DefaultTextureTypes.RANDOM || quad.textureType == DefaultTextureTypes.CONTINUOUS)){ - // Get the sprite - TextureAtlasSprite sprite = this.sprites.get(quad.spriteIndex); - - mutableQuad.fillFromBakedQuad(quad.bakedQuad); - mutableQuad.resetPermutation(); - if(quad.textureType == DefaultTextureTypes.RANDOM) - // Handle random texture type - RandomTextureType.processQuad(mutableQuad, pos, quad.bakedQuad.direction(), random, (RandomTextureSprite)sprite); - else - // Handle continuous texture type - ContinuousTextureType.processQuad(mutableQuad, pos, quad.bakedQuad.direction(), (ContinuousTextureSprite)sprite); - bakedQuads.add(mutableQuad.toBakedQuad()); + // Process connecting textures + else if(blockCache != null && quad.textureType == DefaultTextureTypes.CONNECTING){ + // Get the quad index, predicate index, and sprite index + int quadIndex = quad.quadIndex; + int predicateIndex = quad.predicateIndex; + int spriteIndex = quad.spriteIndex; + + // Get the connection predicate + QuadPredicates predicate = this.predicates.get(predicateIndex); + // Check if the connections have already been computed, otherwise compute them + TextureConnections connections = connectionsCache[predicateIndex]; + if(connections == null){ + // Compute the connections + connections = connectionsCache[predicateIndex] = computeConnections(predicate, blockCache); } - // Process connecting textures - else if(blockCache != null && quad.textureType == DefaultTextureTypes.CONNECTING){ - // Get the quad index, predicate index, and sprite index - int quadIndex = quad.quadIndex; - int predicateIndex = quad.predicateIndex; - int spriteIndex = quad.spriteIndex; - - // Get the connection predicate - QuadPredicates predicate = this.predicates.get(predicateIndex); - // Check if the connections have already been computed, otherwise compute them - TextureConnections connections = connectionsCache[predicateIndex]; - if(connections == null){ - // Compute the connections - connections = connectionsCache[predicateIndex] = computeConnections(predicate, blockCache); - } - - // Get the sprite and the texture layout - TextureAtlasSprite sprite = this.sprites.get(spriteIndex); - ConnectingTextureLayout layout = ((ConnectingTextureSprite)sprite).data().getLayout(); - - // Remap the quad's uv - mutableQuad.fillFromBakedQuad(quad.bakedQuad); - mutableQuad.set(predicate.orientation.vertexIndexPermutation); - boolean keepQuad = ConnectingTextureLayoutHandler.get(layout).processBlockQuad(quadIndex, mutableQuad, (ConnectingTextureSprite)sprite, connections); - if(keepQuad) - bakedQuads.add(mutableQuad.toBakedQuad()); - }else - bakedQuads.add(quad.bakedQuad); - } - processedMesh[cullIndex(cullDirection)] = bakedQuads; + // Get the sprite and the texture layout + TextureAtlasSprite sprite = this.sprites.get(spriteIndex); + ConnectingTextureLayout layout = ((ConnectingTextureSprite)sprite).data().getLayout(); + + // Remap the quad's uv + mutableQuad.fillFromBakedQuad(quad.bakedQuad); + mutableQuad.set(predicate.orientation.vertexIndexPermutation); + boolean keepQuad = ConnectingTextureLayoutHandler.get(layout).processBlockQuad(quadIndex, mutableQuad, (ConnectingTextureSprite)sprite, connections); + if(keepQuad) + bakedQuads.add(mutableQuad.toBakedQuad(null)); + }else + bakedQuads.add(quad.bakedQuad); } - // Creat the model part for the mesh - parts.add(new BlockModelPart() { - @Override - public List getQuads(@Nullable Direction cullDirection){ - return processedMesh[cullIndex(cullDirection)]; - } + processedMesh[cullIndex(cullDirection)] = bakedQuads; + } - @Override - public boolean useAmbientOcclusion(){ - return ConnectingBakedModel.this.hasAmbientOcclusion; - } + // Creat the model part for the mesh + parts.add(new BlockStateModelPart() { + @Override + public List getQuads(@Nullable Direction cullDirection){ + return processedMesh[cullIndex(cullDirection)]; + } - @Override - public TextureAtlasSprite particleIcon(){ - return ConnectingBakedModel.this.particleIcon; - } + @Override + public boolean useAmbientOcclusion(){ + return ConnectingBakedModel.this.hasAmbientOcclusion; + } - @Override - public ChunkSectionLayer getRenderType(BlockState state){ - //noinspection deprecation - return layer.orElseGet(() -> ItemBlockRenderTypes.getChunkRenderType(state)); - } - }); - } + @Override + public Material.Baked particleMaterial(){ + return ConnectingBakedModel.this.particleMaterial; + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return ConnectingBakedModel.this.materialFlags; + } + }); } @Override - public void collectParts(RandomSource random, List parts){ + public void collectParts(RandomSource random, List parts){ this.collectParts(null, null, null, random, parts); } @@ -419,8 +403,13 @@ private static boolean shouldConnect(ConnectionPredicate predicate, SurroundingB } @Override - public TextureAtlasSprite particleIcon(){ - return this.particleIcon; + public Material.Baked particleMaterial(){ + return this.particleMaterial; + } + + @Override + public @BakedQuad.MaterialFlags int materialFlags(){ + return this.materialFlags; } private static int cullIndex(Direction cullDirection){ diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingItemModel.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingItemModel.java index a30a864d7..8e1c9bb44 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingItemModel.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingItemModel.java @@ -1,27 +1,25 @@ package com.supermartijn642.fusion.model.types.connecting; import com.google.common.base.Suppliers; -import com.supermartijn642.fusion.api.util.Pair; import com.supermartijn642.fusion.model.types.base.BaseModelQuad; import com.supermartijn642.fusion.texture.types.connecting.ConnectingTextureSprite; import com.supermartijn642.fusion.texture.types.connecting.layouts.ConnectingTextureLayoutHandler; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.color.item.ItemTintSource; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.Sheets; -import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.item.CuboidItemModelWrapper; import net.minecraft.client.renderer.item.*; -import net.minecraft.client.renderer.rendertype.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.world.entity.ItemOwner; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import org.joml.Vector3fc; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.function.Supplier; /** @@ -31,57 +29,44 @@ public class ConnectingItemModel implements ItemModel { private final List tints; private final ModelRenderProperties properties; - private final List>> mesh; + private final List mesh = new ArrayList<>(); private final Supplier extents; private final boolean animated; + private final Matrix4fc transformation; - public ConnectingItemModel(List tints, List quads, ModelRenderProperties properties, RenderType neoforgeItemRenderType, RenderType neoforgeBlockRenderType){ + public ConnectingItemModel(List tints, List quads, ModelRenderProperties properties, Matrix4fc transformation, ModelBaker.Interner interner){ this.tints = tints; this.properties = properties; - this.extents = Suppliers.memoize(() -> BlockModelWrapper.computeExtents(quads.stream().map(BaseModelQuad::bakedQuad).toList())); + this.extents = Suppliers.memoize(() -> CuboidItemModelWrapper.computeExtents(quads.stream().map(BaseModelQuad::bakedQuad).toList())); // Create the item mesh - Map> mesh = new LinkedHashMap<>(); OrientedMutableQuad mutableQuad = new OrientedMutableQuad(); + @BakedQuad.MaterialFlags int flags = 0; for(ConnectingModelQuad quad : quads){ // Some layouts need auxiliary quads, hence simply repeat the quad that many times int auxiliaryQuadCount = quad.hasConnectingTexture() ? ConnectingTextureLayoutHandler.get(quad.getLayout()).getAuxiliaryQuadCount() : 0; // Submit the quads for(int quadIndex = 0; quadIndex < auxiliaryQuadCount + 1; quadIndex++){ - mutableQuad.fillFromBakedQuad(quad.bakedQuad()); - mutableQuad.emissive(quad.emissive()); + quad.fill(mutableQuad); // Add the item quad - RenderType renderType = quad.bakedQuad().sprite().atlasLocation().equals(TextureAtlas.LOCATION_BLOCKS) ? - neoforgeBlockRenderType == null || quad.renderType() != null ? Sheets.translucentBlockItemSheet() : neoforgeBlockRenderType : - neoforgeItemRenderType == null || quad.renderType() != null ? Sheets.translucentItemSheet() : neoforgeItemRenderType; - List itemQuads = mesh.computeIfAbsent(renderType, k -> new ArrayList<>()); // Process the quad if it has a connecting texture // As item mesh does not depend on state, we can run the connecting texture processing immediately if(quad.hasConnectingTexture()){ mutableQuad.set(ConnectingBakedModel.TextureOrientation.NORMAL_0.vertexIndexPermutation); - boolean keepQuad = ConnectingTextureLayoutHandler.get(quad.getLayout()).processItemQuad(quadIndex, mutableQuad, (ConnectingTextureSprite)quad.bakedQuad().sprite()); + boolean keepQuad = ConnectingTextureLayoutHandler.get(quad.getLayout()).processItemQuad(quadIndex, mutableQuad, (ConnectingTextureSprite)quad.bakedQuad().materialInfo().sprite()); mutableQuad.resetPermutation(); if(!keepQuad) continue; } - itemQuads.add(mutableQuad.toBakedQuad()); + this.mesh.add(mutableQuad.toBakedQuad(interner)); + flags |= quad.bakedQuad().materialInfo().flags(); } } - this.mesh = mesh.entrySet().stream() - .map(entry -> Pair.of(entry.getKey(), entry.getValue())) - .toList(); // Check whether the quads contain animated textures - boolean animated = false; - for(BaseModelQuad quad : quads){ - //noinspection resource - if(quad.bakedQuad().sprite().contents().isAnimated()){ - animated = true; - break; - } - } - this.animated = animated; + this.animated = (flags & BakedQuad.FLAG_ANIMATED) != 0; + this.transformation = transformation; } @Override @@ -89,27 +74,25 @@ public void update(ItemStackRenderState renderState, ItemStack stack, ItemModelR renderState.appendModelIdentityElement(this); if(this.animated) renderState.setAnimated(); - ItemStackRenderState.FoilType foilType = stack.hasFoil() ? BlockModelWrapper.hasSpecialAnimatedTexture(stack) ? ItemStackRenderState.FoilType.SPECIAL : ItemStackRenderState.FoilType.STANDARD : null; + ItemStackRenderState.FoilType foilType = stack.hasFoil() ? CuboidItemModelWrapper.hasSpecialAnimatedTexture(stack) ? ItemStackRenderState.FoilType.SPECIAL : ItemStackRenderState.FoilType.STANDARD : null; if(foilType != null){ renderState.setAnimated(); renderState.appendModelIdentityElement(foilType); } - int tints = this.tints.size(); - int[] tintValues = new int[tints]; - for(int j = 0; j < tints; j++){ - int tint = this.tints.get(j).calculate(stack, level, owner == null ? null : owner.asLivingEntity()); - tintValues[j] = tint; - renderState.appendModelIdentityElement(tint); - } - for(Pair> pair : this.mesh){ - ItemStackRenderState.LayerRenderState layer = renderState.newLayer(); - if(foilType != null) - layer.setFoilType(foilType); - System.arraycopy(tintValues, 0, layer.prepareTintLayers(tints), 0, tintValues.length); - layer.setExtents(this.extents); - this.properties.applyToLayer(layer, displayContext); - layer.prepareQuadList().addAll(pair.right()); - layer.setRenderType(pair.left()); + ItemStackRenderState.LayerRenderState layer = renderState.newLayer(); + if(foilType != null) + layer.setFoilType(foilType); + if(!this.tints.isEmpty()){ + IntList tintLayers = layer.tintLayers(); + for(ItemTintSource tintSource : this.tints){ + int tint = tintSource.calculate(stack, level, owner == null ? null : owner.asLivingEntity()); + tintLayers.add(tint); + renderState.appendModelIdentityElement(tint); + } } + layer.setExtents(this.extents); + layer.setLocalTransform(this.transformation); + this.properties.applyToLayer(layer, displayContext); + layer.prepareQuadList().addAll(mesh); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataBuilderImpl.java index ba70ff7ae..032805dad 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataBuilderImpl.java @@ -7,6 +7,7 @@ import com.supermartijn642.fusion.api.predicate.ConnectionPredicate; import com.supermartijn642.fusion.api.util.Either; import com.supermartijn642.fusion.model.types.base.BaseModelDataImpl; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.resources.Identifier; import java.util.LinkedHashMap; @@ -40,8 +41,8 @@ public ConnectingModelDataBuilder texture(String key, String reference){ } @Override - public ConnectingModelDataBuilder texture(String key, Identifier texture){ - this.baseModel.texture(key, texture); + public ConnectingModelDataBuilder texture(String key, Material material){ + this.baseModel.texture(key, material); return this; } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataImpl.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataImpl.java index 0404df077..9cca01216 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelDataImpl.java @@ -10,9 +10,12 @@ import com.supermartijn642.fusion.model.types.base.BaseModelDataImpl; import com.supermartijn642.fusion.model.types.base.BaseModelElement; import com.supermartijn642.fusion.model.types.base.BaseModelQuad; -import net.minecraft.client.renderer.block.model.*; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.*; +import net.minecraft.client.resources.model.geometry.BakedQuad; +import net.minecraft.client.resources.model.geometry.QuadCollection; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.core.Direction; import net.minecraft.resources.Identifier; @@ -27,7 +30,7 @@ public class ConnectingModelDataImpl extends BaseModelDataImpl implements Connec private final Map> connections; - public ConnectingModelDataImpl(BlockModel model, List parents, List elements, Map> connections){ + public ConnectingModelDataImpl(CuboidModel model, List parents, List elements, Map> connections){ //noinspection rawtypes,unchecked super(model, parents, (List)elements); this.connections = Map.copyOf(connections); @@ -71,9 +74,9 @@ private void bakeQuads(BlockModelBakingContext context, ModelInstance model, // Bake the faces of each element for(BaseModelElement element : elements){ for(Direction direction : element.original.faces().keySet()){ - BlockElementFace face = element.original.faces().get(direction); - TextureAtlasSprite sprite = context.getTexture(this.resolveMaterial(context, modelStack, face.texture())); - BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker().parts(), element.original.from(), element.original.to(), face, sprite, direction, context.getTransformation(), element.original.rotation(), element.original.shade(), element.original.lightEmission()); + CuboidFace face = element.original.faces().get(direction); + Material.Baked material = context.bakeMaterial(this.resolveMaterial(context, modelStack, face.texture())); + BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker(), element.original.from(), element.original.to(), face, material, direction, context.getTransformation(), element.original.rotation(), element.original.shade(), element.original.lightEmission()); Direction cullDirection = face.cullForDirection() != null ? Direction.rotate(context.getTransformation().transformation().getMatrix(), face.cullForDirection()) : null; String connectionsKey = element instanceof ConnectingModelElement && ((ConnectingModelElement)element).faceConnectionKeys.containsKey(direction) ? ((ConnectingModelElement)element).faceConnectionKeys.get(direction) : face.texture(); ConnectionPredicate predicate = this.resolveConnectionKey(context, modelStack, connectionsKey); @@ -86,19 +89,22 @@ private void bakeQuads(BlockModelBakingContext context, ModelInstance model, } } - List elements = null; UnbakedModel vanillaModel = model.getAsVanillaModel(); - if(vanillaModel instanceof ItemModelGenerator) - elements = this.generateItemModel(context, modelStack); - else if(vanillaModel != null && vanillaModel.geometry() instanceof SimpleUnbakedGeometry geometry) - elements = geometry.elements(); - if(elements != null && !elements.isEmpty()){ + if(vanillaModel instanceof ItemModelGenerator){ + QuadCollection quads = this.bakeItemModel(context, modelStack); + for(BakedQuad quad : quads.getAll()){ + output.accept(new ConnectingModelQuad(quad, null, null)); + } + // If the model had elements, ignore parent models' elements + modelStack.pop(); + return; + }else if(vanillaModel != null && vanillaModel.geometry() instanceof UnbakedCuboidGeometry geometry && !geometry.elements().isEmpty()){ // Bake the faces of each element - for(BlockElement element : elements){ + for(CuboidModelElement element : geometry.elements()){ for(Direction direction : element.faces().keySet()){ - BlockElementFace face = element.faces().get(direction); - TextureAtlasSprite sprite = context.getTexture(this.resolveMaterial(context, modelStack, face.texture())); - BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker().parts(), element.from(), element.to(), face, sprite, direction, context.getTransformation(), element.rotation(), element.shade(), element.lightEmission()); + CuboidFace face = element.faces().get(direction); + Material.Baked material = context.bakeMaterial(this.resolveMaterial(context, modelStack, face.texture())); + BakedQuad quad = FaceBakery.bakeQuad(context.getModelBaker(), element.from(), element.to(), face, material, direction, context.getTransformation(), element.rotation(), element.shade(), element.lightEmission()); Direction cullDirection = face.cullForDirection() != null ? Direction.rotate(context.getTransformation().transformation().getMatrix(), face.cullForDirection()) : null; String connectionsKey = face.texture(); ConnectionPredicate predicate = this.resolveConnectionKey(context, modelStack, connectionsKey); @@ -152,8 +158,8 @@ private ConnectionPredicate resolveConnectionKey(BlockModelBakingContext context continue; TextureSlots.SlotContents material = vanillaModel.textureSlots().values().get(currentKey); if(material != null){ - newKey = material instanceof TextureSlots.Value ? - ((TextureSlots.Value)material).material().texture().toString() : + newKey = material instanceof TextureSlots.Value(Material value) ? + value.sprite().toString() : ((TextureSlots.Reference)material).target(); break; } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelElement.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelElement.java index 93d25983f..e9a47c983 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelElement.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelElement.java @@ -1,8 +1,8 @@ package com.supermartijn642.fusion.model.types.connecting; import com.supermartijn642.fusion.model.types.base.BaseModelElement; -import net.minecraft.client.renderer.block.model.BlockElementFace; -import net.minecraft.client.renderer.block.model.BlockElementRotation; +import net.minecraft.client.resources.model.cuboid.CuboidFace; +import net.minecraft.client.resources.model.cuboid.CuboidRotation; import net.minecraft.core.Direction; import org.jetbrains.annotations.Nullable; import org.joml.Vector3fc; @@ -17,7 +17,7 @@ public class ConnectingModelElement extends BaseModelElement { public final Map faceConnectionKeys; - public ConnectingModelElement(Vector3fc from, Vector3fc to, Map faces, @Nullable BlockElementRotation rotation, boolean shade, int lightEmission, Map faceConnectionKeys){ + public ConnectingModelElement(Vector3fc from, Vector3fc to, Map faces, @Nullable CuboidRotation rotation, boolean shade, int lightEmission, Map faceConnectionKeys){ super(from, to, faces, rotation, shade, lightEmission); this.faceConnectionKeys = faceConnectionKeys == null ? Collections.emptyMap() : Collections.unmodifiableMap(faceConnectionKeys); } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelQuad.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelQuad.java index 5172df55d..10fd24ee9 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelQuad.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelQuad.java @@ -5,8 +5,8 @@ import com.supermartijn642.fusion.api.texture.data.ConnectingTextureLayout; import com.supermartijn642.fusion.model.types.base.BaseModelQuad; import com.supermartijn642.fusion.texture.types.connecting.ConnectingTextureSprite; -import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.geometry.BakedQuad; import net.minecraft.core.Direction; /** @@ -19,7 +19,7 @@ public class ConnectingModelQuad extends BaseModelQuad { public ConnectingModelQuad(BakedQuad bakedQuad, Direction cullDirection, ConnectionPredicate connectionPredicate){ super(bakedQuad, cullDirection); - TextureAtlasSprite sprite = bakedQuad.sprite(); + TextureAtlasSprite sprite = bakedQuad.materialInfo().sprite(); if(sprite instanceof ConnectingTextureSprite && ((ConnectingTextureSprite)sprite).data() != null){ ConnectingTextureData data = ((ConnectingTextureSprite)sprite).data(); this.predicate = connectionPredicate; diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelType.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelType.java index 45e6a4d12..95ace22d6 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelType.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/ConnectingModelType.java @@ -16,21 +16,18 @@ import com.supermartijn642.fusion.api.util.Either; import com.supermartijn642.fusion.model.types.base.BaseModelDataImpl; import com.supermartijn642.fusion.model.types.base.BaseModelElement; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.BlockStateModel; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.chunk.ChunkSectionLayer; +import net.minecraft.client.renderer.block.dispatch.BlockStateModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.renderer.item.ModelRenderProperties; -import net.minecraft.client.renderer.rendertype.RenderType; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.cuboid.ItemTransforms; +import net.minecraft.client.resources.model.sprite.Material; import net.minecraft.core.Direction; import net.minecraft.resources.Identifier; import net.minecraft.world.item.ItemDisplayContext; -import net.neoforged.neoforge.client.RenderTypeGroup; -import net.neoforged.neoforge.client.model.NeoForgeModelProperties; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4fc; import java.util.*; @@ -66,28 +63,26 @@ public BlockStateModel bakeBlockModel(BlockModelBakingContext context, Connectin List quads = (List)((ConnectingModelDataImpl)data).bakeQuads(context); // Gather remaining model properties boolean ambientOcclusion = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::ambientOcclusion, true); - TextureAtlasSprite particleSprite = context.getTexture(((BaseModelDataImpl)data).findParticleSprite(context)); - RenderTypeGroup neoforgeRenderTypeGroup = context.getNeoForgeAdditionalProperties().getOptional(NeoForgeModelProperties.RENDER_TYPE); - ChunkSectionLayer neoforgeRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.block(); + Material.Baked particleMaterial = context.bakeMaterial(((BaseModelDataImpl)data).findParticleMaterial(context)); // Finally, create the model return new ConnectingBakedModel( quads, ambientOcclusion, - particleSprite, - neoforgeRenderType + particleMaterial, + context.getModelBaker().interner() ); } @Override - public ItemModel bakeItemModel(ItemModelBakingContext context, ConnectingModelData data){ + public ItemModel bakeItemModel(ItemModelBakingContext context, ConnectingModelData data, Matrix4fc transformation){ // Check for circular dependencies ((ConnectingModelDataImpl)data).validateParents(context); // Bake the quads //noinspection unchecked,rawtypes List quads = (List)((ConnectingModelDataImpl)data).bakeQuads(context); // Gather remaining model properties - boolean usesBlockLight = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::guiLight, BlockModel.GuiLight.SIDE).lightLikeBlock(); - TextureAtlasSprite particleSprite = context.getTexture(((BaseModelDataImpl)data).findParticleSprite(context)); + boolean usesBlockLight = ((BaseModelDataImpl)data).findProperty(context, UnbakedModel::guiLight, CuboidModel.GuiLight.SIDE).lightLikeBlock(); + Material.Baked particleMaterial = context.bakeMaterial(((BaseModelDataImpl)data).findParticleMaterial(context)); //noinspection deprecation ItemTransforms transforms = new ItemTransforms( ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.THIRD_PERSON_LEFT_HAND), @@ -100,16 +95,13 @@ public ItemModel bakeItemModel(ItemModelBakingContext context, ConnectingModelDa ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.FIXED), ((BaseModelDataImpl)data).findItemTransform(context, ItemDisplayContext.ON_SHELF) ); - RenderTypeGroup neoforgeRenderTypeGroup = context.getNeoForgeAdditionalProperties().getOptional(NeoForgeModelProperties.RENDER_TYPE); - RenderType neoforgeItemRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.entityItem(); - RenderType neoforgeBlockRenderType = neoforgeRenderTypeGroup == null ? null : neoforgeRenderTypeGroup.entityBlock(); // Finally, create the model return new ConnectingItemModel( context.getTintSources(), quads, - new ModelRenderProperties(usesBlockLight, particleSprite, transforms), - neoforgeItemRenderType, - neoforgeBlockRenderType + new ModelRenderProperties(usesBlockLight, particleMaterial, transforms), + transformation, + context.getModelBaker().interner() ); } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/connecting/SurroundingBlockCache.java b/src/main/java/com/supermartijn642/fusion/model/types/connecting/SurroundingBlockCache.java index 4ca6afd7a..b28372a10 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/connecting/SurroundingBlockCache.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/connecting/SurroundingBlockCache.java @@ -1,7 +1,7 @@ package com.supermartijn642.fusion.model.types.connecting; +import net.minecraft.client.renderer.block.BlockAndTintGetter; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; /** diff --git a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelDataBuilderImpl.java index bee16459c..f0afe9ade 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelDataBuilderImpl.java @@ -1,10 +1,9 @@ package com.supermartijn642.fusion.model.types.vanilla; import com.supermartijn642.fusion.api.model.data.VanillaModelDataBuilder; -import com.supermartijn642.fusion.util.TextureAtlases; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.TextureSlots; -import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.resources.Identifier; import java.util.HashMap; @@ -13,9 +12,9 @@ /** * Created 01/05/2023 by SuperMartijn642 */ -public class VanillaModelDataBuilderImpl implements VanillaModelDataBuilder { +public class VanillaModelDataBuilderImpl implements VanillaModelDataBuilder { - private final Map textures = new HashMap<>(); + private final Map textures = new HashMap<>(); private Identifier parent; @Override @@ -29,36 +28,30 @@ public VanillaModelDataBuilderImpl texture(String key, String reference){ if(!key.matches("[a-zA-Z_]*")) throw new IllegalArgumentException("Texture reference must only contain characters [a-zA-Z_]!"); - // Prepend '#' character - if(reference.charAt(0) != '#') - reference = '#' + reference; + // Strip '#' character + if(reference.charAt(0) == '#') + reference = reference.substring(1); if(this.textures.containsKey(key)) throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + reference + "'!"); - this.textures.put(key, reference); + this.textures.put(key, new TextureSlots.Reference(reference)); return this; } @Override - public VanillaModelDataBuilderImpl texture(String key, Identifier texture){ + public VanillaModelDataBuilderImpl texture(String key, Material material){ if(!key.matches("[a-zA-Z_]*")) throw new IllegalArgumentException("Texture reference must only contain characters [a-zA-Z_]!"); if(this.textures.containsKey(key)) - throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + texture + "'!"); + throw new RuntimeException("Duplicate texture entry for key '" + key + "': '" + this.textures.get(key) + "' and '" + material + "'!"); - this.textures.put(key, texture.toString()); + this.textures.put(key, new TextureSlots.Value(material)); return this; } @Override - public BlockModel build(){ - TextureSlots.Data.Builder textures = new TextureSlots.Data.Builder(); - this.textures.forEach((key, value) -> { - if(value.charAt(0) == '#') - textures.addReference(key, value); - else - textures.addTexture(key, new Material(TextureAtlases.getBlocks(), Identifier.parse(value))); - }); - return new BlockModel(null, null, null, null, textures.build(), this.parent); + public CuboidModel build(){ + TextureSlots.Data textures = new TextureSlots.Data(Map.copyOf(this.textures)); + return new CuboidModel(null, null, null, null, textures, this.parent); } } diff --git a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelSerializer.java b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelSerializer.java index 2e5c8aa80..8395efdf5 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelSerializer.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelSerializer.java @@ -1,9 +1,11 @@ package com.supermartijn642.fusion.model.types.vanilla; import com.google.gson.*; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.renderer.block.model.TextureSlots; +import com.mojang.serialization.JsonOps; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; +import net.minecraft.client.resources.model.sprite.Material; +import net.minecraft.client.resources.model.sprite.TextureSlots; import net.minecraft.resources.Identifier; import java.lang.reflect.Type; @@ -12,22 +14,25 @@ /** * Created 02/05/2023 by SuperMartijn642 */ -public class VanillaModelSerializer implements JsonSerializer { +public class VanillaModelSerializer implements JsonSerializer { - public static final Gson GSON = new GsonBuilder().registerTypeAdapter(BlockModel.class, new VanillaModelSerializer()).disableHtmlEscaping().setPrettyPrinting().create(); + public static final Gson GSON = new GsonBuilder().registerTypeAdapter(CuboidModel.class, new VanillaModelSerializer()).disableHtmlEscaping().setPrettyPrinting().create(); private VanillaModelSerializer(){ } @Override - public JsonElement serialize(BlockModel src, Type typeOfSrc, JsonSerializationContext context){ + public JsonElement serialize(CuboidModel src, Type typeOfSrc, JsonSerializationContext context){ JsonObject json = new JsonObject(); Identifier parent = src.parent(); if(parent != null) json.addProperty("parent", parent.toString()); if(!src.textureSlots().values().isEmpty()){ JsonObject textures = new JsonObject(); - src.textureSlots().values().forEach((key, texture) -> textures.addProperty(key, texture instanceof TextureSlots.Value ? ((TextureSlots.Value)texture).material().texture().toString() : '#' + ((TextureSlots.Reference)texture).target())); + src.textureSlots().values().forEach((key, texture) -> textures.add(key, switch (texture){ + case TextureSlots.Reference(String target) -> new JsonPrimitive("#" + target); + case TextureSlots.Value(Material material) -> Material.CODEC.encodeStart(JsonOps.INSTANCE, material).getOrThrow(); + })); json.add("textures", textures); } if(src.ambientOcclusion() != null) diff --git a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelType.java b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelType.java index 8d3544d7f..23cebe560 100644 --- a/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelType.java +++ b/src/main/java/com/supermartijn642/fusion/model/types/vanilla/VanillaModelType.java @@ -3,20 +3,20 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.supermartijn642.fusion.model.types.UnknownModelType; -import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.resources.model.cuboid.CuboidModel; /** * Created 29/04/2023 by SuperMartijn642 */ -public class VanillaModelType extends UnknownModelType { +public class VanillaModelType extends UnknownModelType { @Override - public BlockModel deserialize(JsonObject json) throws JsonParseException{ - return BlockModel.GSON.fromJson(json, BlockModel.class); + public CuboidModel deserialize(JsonObject json) throws JsonParseException{ + return CuboidModel.GSON.fromJson(json, CuboidModel.class); } @Override - public JsonObject serialize(BlockModel value){ + public JsonObject serialize(CuboidModel value){ return (JsonObject)VanillaModelSerializer.GSON.toJsonTree(value); } } diff --git a/src/main/java/com/supermartijn642/fusion/resources/MinimumVersionWarningScreen.java b/src/main/java/com/supermartijn642/fusion/resources/MinimumVersionWarningScreen.java index b9d78a37b..f1a9ffddb 100644 --- a/src/main/java/com/supermartijn642/fusion/resources/MinimumVersionWarningScreen.java +++ b/src/main/java/com/supermartijn642/fusion/resources/MinimumVersionWarningScreen.java @@ -6,15 +6,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ActiveTextCollector; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.TextAlignment; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.MultiLineLabel; -import net.minecraft.client.gui.render.state.GuiTextRenderState; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.packs.PackSelectionModel; import net.minecraft.client.input.KeyEvent; import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.renderer.state.gui.GuiTextRenderState; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; @@ -95,8 +95,8 @@ protected void init(){ } @Override - public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks){ - super.render(graphics, mouseX, mouseY, partialTicks); + public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTicks){ + super.extractRenderState(graphics, mouseX, mouseY, partialTicks); Matrix3x2fStack poseStack = graphics.pose(); poseStack.pushMatrix(); poseStack.translate(this.width / 2f, this.height / 2f - 110); @@ -104,7 +104,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi // Title int titleLeft = -(this.titleWidth + 17) / 2; graphics.blit(FUSION_LOGO, titleLeft, 0, 0, 0, 12, 12, 12, 12); - graphics.drawString(this.font, this.title, titleLeft + 17, 2, -1); + graphics.text(this.font, this.title, titleLeft + 17, 2, -1); // Content poseStack.popMatrix(); @@ -114,7 +114,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi graphics.fill(-98, 0, 98, 36, ARGB.color(70, 255, 255, 255)); graphics.blit(RenderPipelines.GUI_TEXTURED, this.pack.getIconTexture(), -96, 2, 0, 0, 32, 32, 32, 32); - graphics.drawString(this.font, this.packName, -62, 3, ARGB.color(255, 16777215)); + graphics.text(this.font, this.packName, -62, 3, ARGB.color(255, 16777215)); ActiveTextCollector dummyTextCollector = graphics.textRenderer(); this.packDescription.visitLines(TextAlignment.LEFT, -62, 14, 10, new ActiveTextCollector() { // I want not-white text, so now I have to do this garbage @Override @@ -134,7 +134,7 @@ public void accept(TextAlignment alignment, int x, int y, Parameters parameters, Minecraft.getInstance().font, text, parameters.pose(), left, y, ARGB.color(parameters.opacity(), -8355712), 0, true, true, parameters.scissor() ); if(ARGB.as8BitChannel(parameters.opacity()) != 0) - graphics.guiRenderState.submitText(textRenderState); + graphics.guiRenderState.addText(textRenderState); ActiveTextCollector.findElementUnderCursor(textRenderState, mouseX, mouseY, s -> {}); } @@ -145,7 +145,7 @@ public void acceptScrolling(Component component, int i, int j, int k, int l, int } }); - graphics.hLine(-115, 115, 44, ARGB.color(255, 255, 255)); + graphics.horizontalLine(-115, 115, 44, ARGB.color(255, 255, 255)); int textLeft = -Math.max(this.headerMessage.getWidth(), this.confirmationMessage.getWidth()) / 2; this.headerMessage.visitLines(TextAlignment.LEFT, textLeft, 54, 10, graphics.textRenderer()); @@ -153,13 +153,13 @@ public void acceptScrolling(Component component, int i, int j, int k, int l, int this.confirmationMessage.visitLines(TextAlignment.LEFT, textLeft, 58 + textHeight, 10, graphics.textRenderer()); textHeight += this.confirmationMessage.getLineCount() * 10; - graphics.hLine(-115, 115, 66 + textHeight, ARGB.color(255, 255, 255)); + graphics.horizontalLine(-115, 115, 66 + textHeight, ARGB.color(255, 255, 255)); textLeft = -(this.versionLabelTextWidth + 5 + this.versionTextWidth) / 2; - graphics.drawString(this.font, this.currentVersionLabel, textLeft, 76 + textHeight, ARGB.color(180, 180, 180)); - graphics.drawString(this.font, this.requiredVersionLabel, textLeft, 88 + textHeight, ARGB.color(180, 180, 180)); - graphics.drawString(this.font, this.currentVersion, textLeft + this.versionLabelTextWidth + 5, 76 + textHeight, ARGB.color(255, 16777215)); - graphics.drawString(this.font, this.requiredVersion, textLeft + this.versionLabelTextWidth + 5, 88 + textHeight, ARGB.color(255, 16777215)); + graphics.text(this.font, this.currentVersionLabel, textLeft, 76 + textHeight, ARGB.color(180, 180, 180)); + graphics.text(this.font, this.requiredVersionLabel, textLeft, 88 + textHeight, ARGB.color(180, 180, 180)); + graphics.text(this.font, this.currentVersion, textLeft + this.versionLabelTextWidth + 5, 76 + textHeight, ARGB.color(255, 16777215)); + graphics.text(this.font, this.requiredVersion, textLeft + this.versionLabelTextWidth + 5, 88 + textHeight, ARGB.color(255, 16777215)); poseStack.popMatrix(); } diff --git a/src/main/java/com/supermartijn642/fusion/resources/ResourcePackListTipRenderer.java b/src/main/java/com/supermartijn642/fusion/resources/ResourcePackListTipRenderer.java index 19ae2cfa9..b6298afb4 100644 --- a/src/main/java/com/supermartijn642/fusion/resources/ResourcePackListTipRenderer.java +++ b/src/main/java/com/supermartijn642/fusion/resources/ResourcePackListTipRenderer.java @@ -2,7 +2,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.screens.packs.PackSelectionModel; import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.network.chat.Component; @@ -18,12 +18,12 @@ public class ResourcePackListTipRenderer { private static final Identifier FUSION_LOGO = Identifier.fromNamespaceAndPath("fusion", "textures/resourcepacks/fusion_icon_blurred.png"); - public static void renderBackground(FusionPackMetadata metadata, boolean isVanillaCompatible, GuiGraphics graphics, int x, int y, int width, int height){ + public static void renderBackground(FusionPackMetadata metadata, boolean isVanillaCompatible, GuiGraphicsExtractor graphics, int x, int y, int width, int height){ if(isVanillaCompatible && !metadata.isMinVersionSatisfied()) graphics.fill(x - 1, y - 1, x + width + 1, y + height + 1, ARGB.color(255, 114, 83, 0)); } - public static void renderIcon(FusionPackMetadata metadata, boolean isVanillaCompatible, GuiGraphics graphics, int x, int y, int width, int height){ + public static void renderIcon(FusionPackMetadata metadata, boolean isVanillaCompatible, GuiGraphicsExtractor graphics, int x, int y, int width, int height){ graphics.blit(RenderPipelines.GUI_TEXTURED, FUSION_LOGO, x, y, 0, 0, 12, 12, 12, 12); } diff --git a/src/main/java/com/supermartijn642/fusion/texture/QuadTintingHelper.java b/src/main/java/com/supermartijn642/fusion/texture/QuadTintingHelper.java index 24cfa50d5..78fa48b19 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/QuadTintingHelper.java +++ b/src/main/java/com/supermartijn642/fusion/texture/QuadTintingHelper.java @@ -1,12 +1,11 @@ package com.supermartijn642.fusion.texture; import com.supermartijn642.fusion.api.texture.data.BaseTextureData; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.renderer.BiomeColors; +import net.minecraft.client.color.block.BlockTintSource; +import net.minecraft.client.color.block.BlockTintSources; +import net.minecraft.client.renderer.block.BlockAndTintGetter; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.FoliageColor; -import net.minecraft.world.level.GrassColor; +import net.minecraft.util.ARGB; import net.minecraft.world.level.block.state.BlockState; /** @@ -17,22 +16,10 @@ public class QuadTintingHelper { /** * @see com.supermartijn642.fusion.api.texture.data.BaseTextureData.QuadTinting */ - private static final BlockColor[] TINT_FUNCTIONS = new BlockColor[]{ - (state, level, pos, tintIndex) -> { - if(level == null || pos == null) - return GrassColor.getDefaultColor(); - return BiomeColors.getAverageGrassColor(level, pos); - }, - (state, level, pos, tintIndex) -> { - if(level == null || pos == null) - return FoliageColor.FOLIAGE_DEFAULT; - return BiomeColors.getAverageFoliageColor(level, pos); - }, - (state, level, pos, tintIndex) -> { - if(level == null || pos == null) - return -1; - return BiomeColors.getAverageWaterColor(level, pos); - } + private static final BlockTintSource[] TINT_FUNCTIONS = new BlockTintSource[]{ + BlockTintSources.grass(), + BlockTintSources.foliage(), + BlockTintSources.water() }; static{ @@ -41,7 +28,7 @@ public class QuadTintingHelper { } public static int getColor(BaseTextureData.QuadTinting tinting, BlockState state, BlockAndTintGetter level, BlockPos pos){ - BlockColor tintFunction = TINT_FUNCTIONS[tinting.ordinal()]; - return tintFunction.getColor(state, level, pos, 0) | 0xff000000; + BlockTintSource tintFunction = TINT_FUNCTIONS[tinting.ordinal()]; + return ARGB.opaque(tintFunction.colorInWorld(state, level, pos)); } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataBuilderImpl.java index 66864cc73..26711fe7c 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataBuilderImpl.java @@ -8,16 +8,9 @@ */ public class BaseTextureDataBuilderImpl implements BaseTextureData.Builder { - private BaseTextureData.RenderType renderType; private boolean emissive = false; private BaseTextureData.QuadTinting tinting; - @Override - public BaseTextureDataBuilderImpl renderType(@Nullable BaseTextureData.RenderType renderType){ - this.renderType = renderType; - return this; - } - @Override public BaseTextureDataBuilderImpl emissive(boolean emissive){ this.emissive = emissive; @@ -32,6 +25,6 @@ public BaseTextureDataBuilderImpl tinting(BaseTextureData.@Nullable QuadTinting @Override public BaseTextureData build(){ - return new BaseTextureDataImpl(this.renderType, this.emissive, this.tinting); + return new BaseTextureDataImpl(this.emissive, this.tinting); } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataImpl.java index cb58e0184..a50fbf3c4 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureDataImpl.java @@ -8,21 +8,14 @@ */ public class BaseTextureDataImpl implements BaseTextureData { - private final RenderType renderType; private final boolean emissive; private final QuadTinting tinting; - public BaseTextureDataImpl(RenderType renderType, boolean emissive, QuadTinting tinting){ - this.renderType = renderType; + public BaseTextureDataImpl(boolean emissive, QuadTinting tinting){ this.emissive = emissive; this.tinting = tinting; } - @Override - public @Nullable RenderType getRenderType(){ - return this.renderType; - } - @Override public boolean isEmissive(){ return this.emissive; diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureSprite.java b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureSprite.java index d0d509e18..f5d9f41cc 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureSprite.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureSprite.java @@ -1,5 +1,6 @@ package com.supermartijn642.fusion.texture.types.base; +import com.mojang.blaze3d.platform.Transparency; import com.supermartijn642.fusion.api.texture.data.BaseTextureData; import net.minecraft.client.renderer.texture.SpriteContents; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -20,4 +21,32 @@ public BaseTextureSprite(Identifier atlas, SpriteContents contents, int atlasWid public BaseTextureData data(){ return this.data; } + + public Transparency computeTransparency(float u0, float v0, float u1, float v1){ + return this.contents().computeTransparency(u0, v0, u1, v1); + } + + public static Transparency computeTiledTransparency(TextureAtlasSprite sprite, float u0, float v0, float u1, float v1, int columns, int rows){ + Transparency spriteTransparency = sprite.contents().transparency(); + if(spriteTransparency.isOpaque()){ + return spriteTransparency; + }else if(u0 == 0.0f && v0 == 0.0f && u1 == 1.0f && v1 == 1.0f){ + return spriteTransparency; + } + Transparency transparency = Transparency.NONE; + for(int y = 0; y < rows; y++){ + for(int x = 0; x < columns; x++){ + transparency = transparency.or(sprite.contents().computeTransparency( + (u0 + x) / columns, + (v0 + y) / rows, + (u1 + x) / columns, + (v1 + y) / rows + )); + if(transparency.hasTranslucent()){ + return transparency; + } + } + } + return transparency; + } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureType.java b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureType.java index 098cdd61a..c846a5688 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureType.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/base/BaseTextureType.java @@ -45,19 +45,6 @@ public TextureAtlasSprite createSprite(SpriteCreationContext context, BaseTextur @Override public BaseTextureData deserialize(JsonObject json) throws JsonParseException{ BaseTextureData.Builder builder = BaseTextureData.builder(); - // render_type - if(json.has("render_type")){ - if(!json.get("render_type").isJsonPrimitive() || !json.getAsJsonPrimitive("render_type").isString()) - throw new JsonParseException("Property 'render_type' must be a string!"); - String renderTypeString = json.get("render_type").getAsString(); - BaseTextureData.RenderType renderType; - try{ - renderType = BaseTextureData.RenderType.valueOf(renderTypeString.toUpperCase(Locale.ROOT)); - }catch(IllegalArgumentException e){ - throw new JsonParseException("Property 'render_type' must be one of " + Arrays.toString(BaseTextureData.RenderType.values()).toLowerCase(Locale.ROOT) + ", not '" + renderTypeString + "'!"); - } - builder.renderType(renderType); - } // emissive if(json.has("emissive")){ if(!json.get("emissive").isJsonPrimitive() || !json.getAsJsonPrimitive("emissive").isBoolean()) @@ -83,8 +70,6 @@ public BaseTextureData deserialize(JsonObject json) throws JsonParseException{ @Override public JsonObject serialize(BaseTextureData value){ JsonObject json = new JsonObject(); - if(value.getRenderType() != null) - json.addProperty("render_type", value.getRenderType().name().toLowerCase()); if(value.isEmissive()) json.addProperty("emissive", true); if(value.getTinting() != null) diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataBuilderImpl.java index 11cd28f86..6945bd40c 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataBuilderImpl.java @@ -10,17 +10,10 @@ */ public class ConnectingTextureDataBuilderImpl implements ConnectingTextureData.Builder { - private BaseTextureData.RenderType renderType; private boolean emissive = false; private BaseTextureData.QuadTinting tinting; private ConnectingTextureLayout layout = ConnectingTextureLayout.FULL; - @Override - public ConnectingTextureDataBuilderImpl renderType(@Nullable BaseTextureData.RenderType renderType){ - this.renderType = renderType; - return this; - } - @Override public ConnectingTextureDataBuilderImpl emissive(boolean emissive){ this.emissive = emissive; @@ -39,23 +32,8 @@ public ConnectingTextureData.Builder layout(ConnectingTextureLayout layout){ return this; } - @Override - public ConnectingTextureData.Builder renderType(@Nullable ConnectingTextureData.RenderType type){ - if(type == null) - return this.renderType((BaseTextureData.RenderType)null); - switch(type){ - case OPAQUE: - return this.renderType(BaseTextureData.RenderType.OPAQUE); - case CUTOUT: - return this.renderType(BaseTextureData.RenderType.CUTOUT); - case TRANSLUCENT: - return this.renderType(BaseTextureData.RenderType.TRANSLUCENT); - } - return this; - } - @Override public ConnectingTextureData build(){ - return new ConnectingTextureDataImpl(this.renderType, this.emissive, this.tinting, this.layout); + return new ConnectingTextureDataImpl(this.emissive, this.tinting, this.layout); } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataImpl.java index c3ee94b33..e47062f5d 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureDataImpl.java @@ -1,6 +1,5 @@ package com.supermartijn642.fusion.texture.types.connecting; -import com.supermartijn642.fusion.api.texture.data.BaseTextureData; import com.supermartijn642.fusion.api.texture.data.ConnectingTextureData; import com.supermartijn642.fusion.api.texture.data.ConnectingTextureLayout; import com.supermartijn642.fusion.texture.types.base.BaseTextureDataImpl; @@ -12,8 +11,8 @@ public class ConnectingTextureDataImpl extends BaseTextureDataImpl implements Co private final ConnectingTextureLayout layout; - public ConnectingTextureDataImpl(BaseTextureData.RenderType renderType, boolean emissive, QuadTinting tinting, ConnectingTextureLayout layout){ - super(renderType, emissive, tinting); + public ConnectingTextureDataImpl(boolean emissive, QuadTinting tinting, ConnectingTextureLayout layout){ + super(emissive, tinting); this.layout = layout; } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureSprite.java b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureSprite.java index 9baa92cf6..45145e6a0 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureSprite.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureSprite.java @@ -1,7 +1,9 @@ package com.supermartijn642.fusion.texture.types.connecting; +import com.mojang.blaze3d.platform.Transparency; import com.supermartijn642.fusion.api.texture.data.ConnectingTextureData; import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; +import com.supermartijn642.fusion.texture.types.connecting.layouts.ConnectingTextureLayoutHandler; import net.minecraft.client.renderer.texture.TextureAtlasSprite; /** @@ -42,4 +44,10 @@ public float getStartV(){ public ConnectingTextureData data(){ return (ConnectingTextureData)super.data(); } + + @Override + public Transparency computeTransparency(float u0, float v0, float u1, float v1){ + ConnectingTextureLayoutHandler handler = ConnectingTextureLayoutHandler.get(this.data().getLayout()); + return computeTiledTransparency(this, u0, v0, u1, v1, handler.getWidth(), handler.getHeight()); + } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureType.java b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureType.java index d4c037643..1a54f1543 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureType.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/connecting/ConnectingTextureType.java @@ -26,7 +26,6 @@ public ConnectingTextureData deserialize(JsonObject json) throws JsonParseExcept BaseTextureData base = DefaultTextureTypes.BASE.deserialize(json); // Copy base properties ConnectingTextureData.Builder builder = ConnectingTextureData.builder(); - builder.renderType(base.getRenderType()); builder.emissive(base.isEmissive()); builder.tinting(base.getTinting()); // Deserialize 'layout' diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataBuilderImpl.java index 84374a56a..d74ddfede 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataBuilderImpl.java @@ -9,17 +9,10 @@ */ public class ContinuousTextureDataBuilderImpl implements ContinuousTextureData.Builder { - private BaseTextureData.RenderType renderType; private boolean emissive = false; private BaseTextureData.QuadTinting tinting; private int rows = 1, columns = 1; - @Override - public ContinuousTextureDataBuilderImpl renderType(@Nullable BaseTextureData.RenderType renderType){ - this.renderType = renderType; - return this; - } - @Override public ContinuousTextureDataBuilderImpl emissive(boolean emissive){ this.emissive = emissive; @@ -46,6 +39,6 @@ public ContinuousTextureData.Builder columns(int columns){ @Override public ContinuousTextureData build(){ - return new ContinuousTextureDataImpl(this.renderType, this.emissive, this.tinting, this.rows, this.columns); + return new ContinuousTextureDataImpl(this.emissive, this.tinting, this.rows, this.columns); } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataImpl.java index 63fe6b933..fa4a4019c 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureDataImpl.java @@ -10,8 +10,8 @@ public class ContinuousTextureDataImpl extends BaseTextureDataImpl implements Co private final int rows, columns; - public ContinuousTextureDataImpl(RenderType renderType, boolean emissive, QuadTinting tinting, int rows, int columns){ - super(renderType, emissive, tinting); + public ContinuousTextureDataImpl(boolean emissive, QuadTinting tinting, int rows, int columns){ + super(emissive, tinting); this.rows = rows; this.columns = columns; } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureSprite.java b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureSprite.java index 29fc67f87..37991e567 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureSprite.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureSprite.java @@ -1,5 +1,6 @@ package com.supermartijn642.fusion.texture.types.continuous; +import com.mojang.blaze3d.platform.Transparency; import com.supermartijn642.fusion.api.texture.data.ContinuousTextureData; import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -30,4 +31,10 @@ protected ContinuousTextureSprite(TextureAtlasSprite original, ContinuousTexture public ContinuousTextureData data(){ return (ContinuousTextureData)super.data(); } + + @Override + public Transparency computeTransparency(float u0, float v0, float u1, float v1){ + ContinuousTextureData data = this.data(); + return computeTiledTransparency(this, u0, v0, u1, v1, data.getColumns(), data.getRows()); + } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureType.java b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureType.java index dba2558d3..98fb83c6c 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureType.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/continuous/ContinuousTextureType.java @@ -24,7 +24,6 @@ public ContinuousTextureData deserialize(JsonObject json) throws JsonParseExcept BaseTextureData base = DefaultTextureTypes.BASE.deserialize(json); // Copy base properties ContinuousTextureData.Builder builder = ContinuousTextureData.builder(); - builder.renderType(base.getRenderType()); builder.emissive(base.isEmissive()); builder.tinting(base.getTinting()); // Rows diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataBuilderImpl.java index 20188945f..323865384 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataBuilderImpl.java @@ -9,18 +9,11 @@ */ public class RandomTextureDataBuilderImpl implements RandomTextureData.Builder { - private BaseTextureData.RenderType renderType; private boolean emissive = false; private BaseTextureData.QuadTinting tinting; private int rows = 1, columns = 1, count; private Long seed; - @Override - public RandomTextureDataBuilderImpl renderType(@Nullable BaseTextureData.RenderType renderType){ - this.renderType = renderType; - return this; - } - @Override public RandomTextureDataBuilderImpl emissive(boolean emissive){ this.emissive = emissive; @@ -67,6 +60,6 @@ public RandomTextureData.Builder seed(Long seed){ public RandomTextureData build(){ if(this.count > this.rows * this.columns) throw new IllegalArgumentException("Count cannot be greater than rows * columns!"); - return new RandomTextureDataImpl(this.renderType, this.emissive, this.tinting, this.rows, this.columns, this.count, this.seed); + return new RandomTextureDataImpl(this.emissive, this.tinting, this.rows, this.columns, this.count, this.seed); } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataImpl.java index df9a2dec0..0e6032598 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureDataImpl.java @@ -12,8 +12,8 @@ public class RandomTextureDataImpl extends BaseTextureDataImpl implements Random private final int rows, columns, count; private final Long seed; - public RandomTextureDataImpl(RenderType renderType, boolean emissive, QuadTinting tinting, int rows, int columns, int count, Long seed){ - super(renderType, emissive, tinting); + public RandomTextureDataImpl(boolean emissive, QuadTinting tinting, int rows, int columns, int count, Long seed){ + super(emissive, tinting); this.rows = rows; this.columns = columns; this.count = count; diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureSprite.java b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureSprite.java index b9ce16553..6a631cfae 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureSprite.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureSprite.java @@ -1,5 +1,6 @@ package com.supermartijn642.fusion.texture.types.random; +import com.mojang.blaze3d.platform.Transparency; import com.supermartijn642.fusion.api.texture.data.RandomTextureData; import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -30,4 +31,10 @@ protected RandomTextureSprite(TextureAtlasSprite original, RandomTextureData dat public RandomTextureData data(){ return (RandomTextureData)super.data(); } + + @Override + public Transparency computeTransparency(float u0, float v0, float u1, float v1){ + RandomTextureData data = this.data(); + return computeTiledTransparency(this, u0, v0, u1, v1, data.getColumns(), data.getRows()); + } } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureType.java b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureType.java index 3cafdb922..0ce4f61c0 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureType.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/random/RandomTextureType.java @@ -25,7 +25,6 @@ public RandomTextureData deserialize(JsonObject json) throws JsonParseException{ BaseTextureData base = DefaultTextureTypes.BASE.deserialize(json); // Copy base properties RandomTextureData.Builder builder = RandomTextureData.builder(); - builder.renderType(base.getRenderType()); builder.emissive(base.isEmissive()); builder.tinting(base.getTinting()); // Rows diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataBuilderImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataBuilderImpl.java index 52bb2e120..b2d0b524f 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataBuilderImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataBuilderImpl.java @@ -9,7 +9,6 @@ */ public class ScrollingTextureDataBuilderImpl implements ScrollingTextureData.Builder { - private BaseTextureData.RenderType renderType; private boolean emissive = false; private BaseTextureData.QuadTinting tinting; private ScrollingTextureData.Position startPosition = ScrollingTextureData.Position.TOP_LEFT, endPosition = ScrollingTextureData.Position.BOTTOM_LEFT; @@ -17,12 +16,6 @@ public class ScrollingTextureDataBuilderImpl implements ScrollingTextureData.Bui private ScrollingTextureData.LoopType loopType = ScrollingTextureData.LoopType.RESET; private int loopPause = 0; - @Override - public ScrollingTextureDataBuilderImpl renderType(@Nullable BaseTextureData.RenderType renderType){ - this.renderType = renderType; - return this; - } - @Override public ScrollingTextureDataBuilderImpl emissive(boolean emissive){ this.emissive = emissive; @@ -104,7 +97,7 @@ public ScrollingTextureDataBuilderImpl loopPause(int ticks){ public ScrollingTextureData build(){ return new ScrollingTextureDataImpl( - this.renderType, this.emissive, this.tinting, + this.emissive, this.tinting, this.startPosition, this.endPosition, this.frameTime, this.frameWidth, this.frameHeight, this.loopType, this.loopPause ); } diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataImpl.java b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataImpl.java index eb4540231..b3b20b92a 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataImpl.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureDataImpl.java @@ -13,8 +13,8 @@ public class ScrollingTextureDataImpl extends BaseTextureDataImpl implements Scr private final ScrollingTextureData.LoopType loopType; private final int loopPause; - public ScrollingTextureDataImpl(RenderType renderType, boolean emissive, QuadTinting tinting, Position startPosition, Position endPosition, int frameTime, int frameWidth, int frameHeight, LoopType loopType, int loopPause){ - super(renderType, emissive, tinting); + public ScrollingTextureDataImpl(boolean emissive, QuadTinting tinting, Position startPosition, Position endPosition, int frameTime, int frameWidth, int frameHeight, LoopType loopType, int loopPause){ + super(emissive, tinting); this.startPosition = startPosition; this.endPosition = endPosition; this.frameTime = frameTime; diff --git a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureType.java b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureType.java index 2ebb16b62..a7ac2a11f 100644 --- a/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureType.java +++ b/src/main/java/com/supermartijn642/fusion/texture/types/scrolling/ScrollingTextureType.java @@ -3,6 +3,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.mojang.blaze3d.buffers.GpuBufferSlice; +import com.mojang.blaze3d.platform.Transparency; import com.mojang.blaze3d.systems.GpuDevice; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.textures.GpuTexture; @@ -16,10 +17,12 @@ import com.supermartijn642.fusion.texture.types.base.BaseTextureSprite; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.renderer.texture.SpriteContents; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.metadata.animation.FrameSize; import net.minecraft.util.ARGB; +import net.minecraft.util.Mth; import java.util.ArrayList; import java.util.Arrays; @@ -215,6 +218,30 @@ public boolean isTransparent(int frame, int x, int y){ )) == 0; } + @Override + public Transparency computeTransparency(float u0, float v0, float u1, float v1){ + Transparency baseTransparency = this.transparency(); + if(baseTransparency.isOpaque()){ + return baseTransparency; + }else if(u0 == 0.0f && v0 == 0.0f && u1 == 1.0f && v1 == 1.0f){ + return baseTransparency; + }else{ + int x0 = Mth.floor(u0 * this.width); + int y0 = Mth.floor(v0 * this.height); + int x1 = Mth.ceil(u1 * this.width); + int y1 = Mth.ceil(v1 * this.height); + IntList uniqueFrames = this.animatedTexture.getUniqueFrames(); + Transparency transparency = Transparency.NONE; + for(int i = 0; i < uniqueFrames.size(); i++){ + int frame = uniqueFrames.getInt(i); + int frameX = this.xPositions[frame] * this.width; + int frameY = this.yPositions[frame] * this.height; + transparency = transparency.or(this.originalImage.computeTransparency(frameX + x0, frameY + y0, frameX + x1, frameY + y1)); + } + return transparency; + } + } + private class ScrollingAnimatedTexture extends SpriteContents.AnimatedTexture { public ScrollingAnimatedTexture(){ @@ -227,7 +254,7 @@ public AnimationState createAnimationState(GpuBufferSlice bufferSlice, int offse Int2ObjectMap textureViews = new Int2ObjectOpenHashMap<>(); GpuBufferSlice[] slices = new GpuBufferSlice[ScrollingSpriteContents.this.byMipLevel.length]; - for(int frameIndex : this.getUniqueFrames().toArray()){ + for(int frameIndex : this.getUniqueFrames().toIntArray()){ GpuTexture gpuTexture = gpuDevice.createTexture( () -> ScrollingSpriteContents.this.name + " animation frame " + frameIndex, 5, diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 52d8b6e62..54ae92033 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,13 +1,5 @@ -# BakedQuad -public-f net.minecraft.client.renderer.block.model.BakedQuad tintIndex -# BlockElement -public-f net.minecraft.client.renderer.block.model.BlockElement -# BlockModel -public net.minecraft.client.renderer.block.model.BlockModel GSON -public-f net.minecraft.client.renderer.block.model.BlockModel -# BlockModelWrapper -public net.minecraft.client.renderer.item.BlockModelWrapper detectRenderType(Ljava/util/List;)Ljava/util/function/Function; -public net.minecraft.client.renderer.item.BlockModelWrapper hasSpecialAnimatedTexture(Lnet/minecraft/world/item/ItemStack;)Z +# CuboidItemModelWrapper +public net.minecraft.client.renderer.item.CuboidItemModelWrapper hasSpecialAnimatedTexture(Lnet/minecraft/world/item/ItemStack;)Z # EntityModelSet public net.minecraft.client.model.geom.EntityModelSet roots # FilePackResources$SharedZipFileAccess @@ -15,17 +7,15 @@ public net.minecraft.server.packs.FilePackResources$SharedZipFileAccess file public net.minecraft.server.packs.FilePackResources$SharedZipFileAccess getOrCreateZipFile()Ljava/util/zip/ZipFile; public net.minecraft.server.packs.FilePackResources$SharedZipFileAccess # GuiGraphics -public net.minecraft.client.gui.GuiGraphics guiRenderState -# ItemModelGenerator -public net.minecraft.client.renderer.block.model.ItemModelGenerator processFrames(ILjava/lang/String;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;)Ljava/util/List; +public net.minecraft.client.gui.GuiGraphicsExtractor guiRenderState # LayerDefinition public net.minecraft.client.model.geom.builders.LayerDefinition (Lnet/minecraft/client/model/geom/builders/MeshDefinition;Lnet/minecraft/client/model/geom/builders/MaterialDefinition;)V # ModelBakery$ModelBakerImpl -public net.minecraft.client.resources.model.ModelBakery$ModelBakerImpl (Lnet/minecraft/client/resources/model/ModelBakery;Lnet/minecraft/client/resources/model/SpriteGetter;Lnet/minecraft/client/resources/model/ModelBaker$PartCache;Lnet/minecraft/client/resources/model/ModelBakery$MissingModels;)V +public net.minecraft.client.resources.model.ModelBakery$ModelBakerImpl (Lnet/minecraft/client/resources/model/ModelBakery;Lnet/minecraft/client/resources/model/sprite/MaterialBaker;Lnet/minecraft/client/resources/model/ModelBaker$Interner;Lnet/minecraft/client/resources/model/ModelBakery$MissingModels;)V public net.minecraft.client.resources.model.ModelBakery$ModelBakerImpl -# ModelBakery$PartCacheImpl -public net.minecraft.client.resources.model.ModelBakery$PartCacheImpl ()V -public net.minecraft.client.resources.model.ModelBakery$PartCacheImpl +# ModelBakery$InternerImpl +public net.minecraft.client.resources.model.ModelBakery$InternerImpl ()V +public net.minecraft.client.resources.model.ModelBakery$InternerImpl # ModelDiscovery$ModelWrapper public net.minecraft.client.resources.model.ModelDiscovery$ModelWrapper # ModelLayers @@ -96,12 +86,12 @@ public-f net.minecraft.client.renderer.texture.TextureAtlasSprite v0 public-f net.minecraft.client.renderer.texture.TextureAtlasSprite v1 public net.minecraft.client.renderer.texture.TextureAtlasSprite padding # TextureSlots -public net.minecraft.client.renderer.block.model.TextureSlots resolvedValues -public net.minecraft.client.renderer.block.model.TextureSlots (Ljava/util/Map;)V +public net.minecraft.client.resources.model.sprite.TextureSlots resolvedValues +public net.minecraft.client.resources.model.sprite.TextureSlots (Ljava/util/Map;)V # TextureSlots$Reference -public net.minecraft.client.renderer.block.model.TextureSlots$Reference +public net.minecraft.client.resources.model.sprite.TextureSlots$Reference # TextureSlots$Value -public net.minecraft.client.renderer.block.model.TextureSlots$Value +public net.minecraft.client.resources.model.sprite.TextureSlots$Value # TransferableSelectionList public net.minecraft.client.gui.screens.packs.TransferableSelectionList screen # VertexFormat diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json index 7a32a1642..eabf9cd12 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/modid.mixins.json @@ -9,19 +9,20 @@ "neoforge.DatagenModLoaderMixin", "AgeableMobMixin", "AtlasConfigMixin", - "BlockModelMixin", - "BlockModelWrapperMixin", "BlockRenderDispatcherMixin", "BufferSourceMixin", "CompositePackResourceMixin", + "CuboidItemModelWrapperMixin", + "CuboidModelMixin", "EntityMixin", "EntityModelSetMixin", "EntityRendererMixin", "EntityRenderersMixin", "EntityRenderStateMixin", + "FaceBakeryMixin", "FilePackResourcesMixin", "IntermediaryFormatMixin", - "ItemRendererMixin", + "ItemFeatureRendererMixin", "JarContentsPackResourcesMixin", "ModelBakeryMixin", "ModelBlockRendererMixin",