Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64b0fbc0aa | ||
|
|
9476ecbcc5 | ||
|
|
778ae7ddd9 | ||
|
|
08c3b4b42d |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -20,7 +20,7 @@ build
|
|||||||
# other
|
# other
|
||||||
eclipse
|
eclipse
|
||||||
run
|
run
|
||||||
logs/*
|
runs
|
||||||
|
run-data
|
||||||
|
|
||||||
# Files from Forge MDK
|
repo
|
||||||
forge*changelog.txt
|
|
||||||
153
build.gradle
153
build.gradle
@@ -1,29 +1,13 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
maven { url = 'https://maven.minecraftforge.net' }
|
|
||||||
mavenCentral()
|
|
||||||
maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
|
|
||||||
maven { url = 'https://maven.parchmentmc.org' }
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:${forgegradle_version}"
|
|
||||||
classpath "org.spongepowered:mixingradle:${mixingradle_version}"
|
|
||||||
classpath "org.parchmentmc:librarian:${librarian_version}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
id 'eclipse'
|
||||||
|
id 'idea'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'net.neoforged.gradle.userdev' version "${neogradle_version}"
|
||||||
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
||||||
}
|
}
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
|
||||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
|
||||||
apply plugin: 'eclipse'
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
apply plugin: 'org.spongepowered.mixin'
|
|
||||||
|
|
||||||
jarJar.enable()
|
boolean ponderInWorkspace = findProject(':Ponder') != null
|
||||||
|
|
||||||
boolean flywheelInWorkspace = findProject(':Flywheel') != null
|
|
||||||
|
|
||||||
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
||||||
|
|
||||||
@@ -33,61 +17,52 @@ base {
|
|||||||
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
|
||||||
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + ' (' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
|
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + ' (' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
|
||||||
|
|
||||||
minecraft {
|
minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||||
mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}"
|
|
||||||
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
runs {
|
||||||
|
// applies to all the run configs below
|
||||||
|
configureEach { net.neoforged.gradle.dsl.common.runs.run.Run run ->
|
||||||
|
// Recommended logging data for a userdev environment
|
||||||
|
systemProperty 'forge.logging.markers', 'REGISTRIES'
|
||||||
|
|
||||||
|
// Recommended logging level for the console
|
||||||
|
systemProperty 'forge.logging.console.level', 'debug'
|
||||||
|
|
||||||
|
//Limit ram usage for the dev environment to 4GB
|
||||||
|
jvmArgument '-Xmx4G'
|
||||||
|
if (run.project.javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse("").contains("JetBrains")) {
|
||||||
|
jvmArgument '-XX:+AllowEnhancedClassRedefinition'
|
||||||
|
}
|
||||||
|
|
||||||
|
modSource project.sourceSets.main
|
||||||
|
}
|
||||||
|
|
||||||
runs {
|
|
||||||
client {
|
client {
|
||||||
workingDirectory project.file('run')
|
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
||||||
arg '-mixin.config=flywheel.mixins.json'
|
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
||||||
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
|
||||||
property 'forge.logging.console.level', 'info'
|
|
||||||
|
|
||||||
mods {
|
if (ponderInWorkspace) {
|
||||||
effortlessbuilding {
|
dependencies {
|
||||||
source sourceSets.main
|
runtime project(':Ponder')
|
||||||
}
|
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
|
||||||
flywheel {
|
|
||||||
source project(":Flywheel").sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
workingDirectory project.file('run/server')
|
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
||||||
property 'forge.logging.console.level', 'info'
|
programArgument '--nogui'
|
||||||
mods {
|
|
||||||
effortlessbuilding {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data {
|
data {
|
||||||
workingDirectory project.file('run')
|
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
|
||||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
// workingDirectory project.file('run-data')
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
args '--mod', 'effortlessbuilding', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
|
|
||||||
mods {
|
|
||||||
effortlessbuilding {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
||||||
flywheel {
|
programArguments.addAll '--mod', "effortlessbuilding", '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
||||||
source project(":Flywheel").sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +72,18 @@ repositories {
|
|||||||
name = 'tterrag maven'
|
name = 'tterrag maven'
|
||||||
url = 'https://maven.tterrag.com'
|
url = 'https://maven.tterrag.com'
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = 'https://www.cursemaven.com'
|
// Ponder, Flywheel
|
||||||
content {
|
url = "https://maven.createmod.net"
|
||||||
|
}
|
||||||
|
maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven" } // NeoForge config api port, needed by ponder
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
url "https://cursemaven.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
includeGroup "curse.maven"
|
includeGroup "curse.maven"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,22 +102,24 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
implementation "net.neoforged:neoforge:${neo_version}"
|
||||||
|
|
||||||
jarJar("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
jarJar("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
||||||
jarJar.ranged(it, '[0.6.10,0.7)')
|
|
||||||
|
compileOnly("dev.engine-room.flywheel:flywheel-neoforge-api-${flywheel_minecraft_version}:${flywheel_version}")
|
||||||
|
runtimeOnly(jarJar("dev.engine-room.flywheel:flywheel-neoforge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||||
|
version {
|
||||||
|
strictly "[1.0,2.0)"
|
||||||
|
prefer flywheel_version
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
runtimeOnly("dev.engine-room.vanillin:vanillin-neoforge-${flywheel_minecraft_version}:${vanillin_version}")
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
if (ponderInWorkspace) {
|
||||||
implementation project(':Flywheel')
|
implementation(project(":ponder:Common"))
|
||||||
|
implementation(project(":ponder:NeoForge"))
|
||||||
} else {
|
} else {
|
||||||
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
implementation("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
|
||||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
|
||||||
if (!Boolean.getBoolean('idea.sync.active')) {
|
|
||||||
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +131,14 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
||||||
|
idea {
|
||||||
|
module {
|
||||||
|
downloadSources = true
|
||||||
|
downloadJavadoc = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.compilerArgs = ['-Xdiags:verbose']
|
options.compilerArgs = ['-Xdiags:verbose']
|
||||||
}
|
}
|
||||||
@@ -179,8 +172,7 @@ java {
|
|||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
jar.finalizedBy('reobfJar')
|
tasks.build.dependsOn tasks.jarJar
|
||||||
tasks.jarJar.finalizedBy('reobfJarJar')
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
@@ -188,8 +180,7 @@ publishing {
|
|||||||
artifactId = base.archivesName.get()
|
artifactId = base.archivesName.get()
|
||||||
|
|
||||||
from components.java
|
from components.java
|
||||||
fg.component(it)
|
// fg.component(it)
|
||||||
jarJar.component(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,19 @@
|
|||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mod_version = 3.5
|
mod_version = 3.10
|
||||||
artifact_minecraft_version = 1.20.1
|
artifact_minecraft_version = 1.21.1
|
||||||
|
|
||||||
minecraft_version = 1.20.1
|
minecraft_version = 1.21.1
|
||||||
forge_version = 47.1.3
|
neo_version = 21.1.129
|
||||||
|
neogradle.subsystems.parchment.minecraftVersion = 1.21.1
|
||||||
|
neogradle.subsystems.parchment.mappingsVersion = 2024.11.17
|
||||||
|
neogradle.subsystems.conventions.runs.create-default-run-per-type = false
|
||||||
|
|
||||||
forgegradle_version = 6.0.7
|
neogradle_version = 7.0.181
|
||||||
mixingradle_version = 0.7-SNAPSHOT
|
|
||||||
mixin_version = 0.8.5
|
|
||||||
librarian_version = 1.+
|
|
||||||
cursegradle_version = 1.4.0
|
cursegradle_version = 1.4.0
|
||||||
parchment_version = 2023.09.03
|
|
||||||
|
|
||||||
flywheel_minecraft_version = 1.20.1
|
flywheel_minecraft_version = 1.21.1
|
||||||
flywheel_version = 0.6.10-7
|
flywheel_version = 1.0.2
|
||||||
|
vanillin_version = 1.0.0-beta-11
|
||||||
|
ponder_version = 1.0.46
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
34
gradlew
vendored
34
gradlew
vendored
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# 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.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -83,10 +85,9 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# 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
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
' "$PWD" ) || exit
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -133,10 +134,13 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
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.
|
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
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
@@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_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 -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
|||||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
maven { url = 'https://maven.minecraftforge.net/' }
|
maven {
|
||||||
|
name = 'Official NeoForge Maven'
|
||||||
|
url = 'https://maven.neoforged.net/releases'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.createmod.catnip.gui.UIRenderHelper;
|
||||||
|
import net.createmod.catnip.gui.element.ScreenElement;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
|
|
||||||
public enum AllGuiTextures implements ScreenElement {
|
public enum AllGuiTextures implements ScreenElement {
|
||||||
ARRAY_ENTRY("modifiers", 226, 64),
|
ARRAY_ENTRY("modifiers", 226, 64),
|
||||||
@@ -35,7 +35,7 @@ public enum AllGuiTextures implements ScreenElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
||||||
this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png");
|
this.location = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.startX = startX;
|
this.startX = startX;
|
||||||
|
|||||||
@@ -2,23 +2,22 @@ package nl.requios.effortlessbuilding;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.createmod.catnip.gui.element.DelegatedStencilElement;
|
||||||
|
import net.createmod.catnip.gui.element.ScreenElement;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
public class AllIcons implements ScreenElement {
|
public class AllIcons implements ScreenElement {
|
||||||
|
|
||||||
public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png");
|
public static final ResourceLocation ICON_ATLAS = EffortlessBuilding.asResource("textures/gui/icons.png");
|
||||||
public static final int ICON_ATLAS_SIZE = 256;
|
public static final int ICON_ATLAS_SIZE = 256;
|
||||||
private static int x = 0, y = -1;
|
private static int x = 0, y = -1;
|
||||||
private int iconX;
|
private int iconX;
|
||||||
@@ -101,7 +100,6 @@ public class AllIcons implements ScreenElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics guiGraphics, int x, int y) {
|
public void render(GuiGraphics guiGraphics, int x, int y) {
|
||||||
guiGraphics.blit(ICON_ATLAS, x, y, 0, iconX, iconY, 16, 16, 256, 256);
|
guiGraphics.blit(ICON_ATLAS, x, y, 0, iconX, iconY, 16, 16, 256, 256);
|
||||||
}
|
}
|
||||||
@@ -131,11 +129,10 @@ public class AllIcons implements ScreenElement {
|
|||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
||||||
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
builder.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||||
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||||
.uv(u, v)
|
.setUv(u, v)
|
||||||
.uv2(light)
|
.setLight(light);
|
||||||
.endVertex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
|
|
||||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||||
|
|
||||||
public class ClientConfig {
|
public class ClientConfig {
|
||||||
|
|
||||||
private static final Builder builder = new Builder();
|
private static final Builder builder = new Builder();
|
||||||
public static final Visuals visuals = new Visuals(builder);
|
public static final Visuals visuals = new Visuals(builder);
|
||||||
public static final ForgeConfigSpec spec = builder.build();
|
public static final ModConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Visuals {
|
public static class Visuals {
|
||||||
public final BooleanValue showBlockPreviews;
|
public final BooleanValue showBlockPreviews;
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.InputEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.minecraftforge.client.event.ScreenEvent;
|
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
import net.neoforged.neoforge.client.event.InputEvent;
|
||||||
import net.minecraftforge.client.settings.KeyModifier;
|
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.neoforged.neoforge.client.settings.KeyConflictContext;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.neoforged.neoforge.client.settings.KeyModifier;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
||||||
@@ -54,33 +55,33 @@ public class ClientEvents {
|
|||||||
// @SubscribeEvent
|
// @SubscribeEvent
|
||||||
// public static void registerShaders(RegisterShadersEvent event) throws IOException {
|
// public static void registerShaders(RegisterShadersEvent event) throws IOException {
|
||||||
// event.registerShader(new ShaderInstance(event.getResourceManager(),
|
// event.registerShader(new ShaderInstance(event.getResourceManager(),
|
||||||
// new ResourceLocation(EffortlessBuilding.MODID, "dissolve"),
|
// EffortlessBuilding.modLoc("dissolve"),
|
||||||
// DefaultVertexFormat.BLOCK),
|
// DefaultVertexFormat.BLOCK),
|
||||||
// shaderInstance -> BuildRenderTypes.dissolveShaderInstance = shaderInstance);
|
// shaderInstance -> BuildRenderTypes.dissolveShaderInstance = shaderInstance);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
public static void onClientTickPre(ClientTickEvent.Pre event) {
|
||||||
if (!isGameActive()) return;
|
if (!isGameActive()) return;
|
||||||
|
|
||||||
if (event.phase == TickEvent.Phase.START) {
|
|
||||||
|
|
||||||
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
||||||
|
|
||||||
onMouseInput();
|
onMouseInput();
|
||||||
|
|
||||||
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClientTickPost(ClientTickEvent.Post event) {
|
||||||
|
if (!isGameActive()) return;
|
||||||
|
|
||||||
} else if (event.phase == TickEvent.Phase.END) {
|
|
||||||
Screen gui = Minecraft.getInstance().screen;
|
Screen gui = Minecraft.getInstance().screen;
|
||||||
if (gui == null || !gui.isPauseScreen()) {
|
if (gui == null || !gui.isPauseScreen()) {
|
||||||
ticksInGame++;
|
ticksInGame++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void onMouseInput() {
|
private static void onMouseInput() {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
LocalPlayer player = mc.player;
|
LocalPlayer player = mc.player;
|
||||||
@@ -133,7 +134,7 @@ public class ClientEvents {
|
|||||||
|
|
||||||
//Radial menu
|
//Radial menu
|
||||||
if (keyBindings[0].isDown()) {
|
if (keyBindings[0].isDown()) {
|
||||||
if (!EffortlessBuildingClient.POWER_LEVEL.isDisabled(player)) {
|
if (!AttachmentHandler.isDisabled(player)) {
|
||||||
if (!RadialMenu.instance.isVisible()) {
|
if (!RadialMenu.instance.isVisible()) {
|
||||||
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,7 @@ public class ClientEvents {
|
|||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
//Disabled if max reach is 0, might be set in the config that way.
|
//Disabled if max reach is 0, might be set in the config that way.
|
||||||
if (EffortlessBuildingClient.POWER_LEVEL.isDisabled(player)) {
|
if (AttachmentHandler.isDisabled(player)) {
|
||||||
EffortlessBuilding.log(player, "Build modifiers are disabled until your power level has increased. Increase your power level by consuming certain items.");
|
EffortlessBuilding.log(player, "Build modifiers are disabled until your power level has increased. Increase your power level by consuming certain items.");
|
||||||
} else {
|
} else {
|
||||||
mc.setScreen(new ModifiersScreen());
|
mc.setScreen(new ModifiersScreen());
|
||||||
@@ -187,7 +188,7 @@ public class ClientEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onGuiOpen(ScreenEvent event) {
|
public static void onGuiOpen(ScreenEvent.Opening event) {
|
||||||
Player player = Minecraft.getInstance().player;
|
Player player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
EffortlessBuildingClient.BUILDER_CHAIN.cancel();
|
EffortlessBuildingClient.BUILDER_CHAIN.cancel();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
|
|
||||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||||
|
|
||||||
public class CommonConfig {
|
public class CommonConfig {
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class CommonConfig {
|
|||||||
public static final MaxBlocksPlacedAtOnce maxBlocksPlacedAtOnce = new MaxBlocksPlacedAtOnce(builder);
|
public static final MaxBlocksPlacedAtOnce maxBlocksPlacedAtOnce = new MaxBlocksPlacedAtOnce(builder);
|
||||||
public static final MaxBlocksPerAxis maxBlocksPerAxis = new MaxBlocksPerAxis(builder);
|
public static final MaxBlocksPerAxis maxBlocksPerAxis = new MaxBlocksPerAxis(builder);
|
||||||
public static final MaxMirrorRadius maxMirrorRadius = new MaxMirrorRadius(builder);
|
public static final MaxMirrorRadius maxMirrorRadius = new MaxMirrorRadius(builder);
|
||||||
public static final ForgeConfigSpec spec = builder.build();
|
public static final ModConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Reach {
|
public static class Reach {
|
||||||
public final IntValue creative;
|
public final IntValue creative;
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ import net.minecraft.world.InteractionHand;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.neoforged.neoforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.event.level.BlockEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||||
import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||||
import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
|||||||
public class CommonEvents {
|
public class CommonEvents {
|
||||||
|
|
||||||
//Mod Bus Events
|
//Mod Bus Events
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
// @EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||||
public static class ModBusEvents {
|
public static class ModBusEvents {
|
||||||
|
|
||||||
|
|
||||||
@@ -36,9 +36,10 @@ public class CommonEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTick(TickEvent.LevelTickEvent event) {
|
public static void onTick(LevelTickEvent.Pre event) {
|
||||||
if (event.phase != TickEvent.Phase.START) return;
|
Level level = event.getLevel();
|
||||||
if (event.side == LogicalSide.CLIENT) return;
|
if (level.isClientSide) return;
|
||||||
|
if (!level.dimension().equals(Level.OVERWORLD)) return;
|
||||||
|
|
||||||
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
||||||
}
|
}
|
||||||
@@ -74,7 +75,8 @@ public class CommonEvents {
|
|||||||
//Don't cancel event if our custom logic is breaking blocks
|
//Don't cancel event if our custom logic is breaking blocks
|
||||||
if (EffortlessBuilding.SERVER_BLOCK_PLACER.isPlacingOrBreakingBlocks()) return;
|
if (EffortlessBuilding.SERVER_BLOCK_PLACER.isPlacingOrBreakingBlocks()) return;
|
||||||
|
|
||||||
if (!ServerBuildState.isLikeVanilla(player) && EffortlessBuilding.SERVER_POWER_LEVEL.canBreakFar(player)) {
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (!ServerBuildState.isLikeVanilla(player) && powerLevel.canBreakFar(player)) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,8 +95,24 @@ public class CommonEvents {
|
|||||||
|
|
||||||
ServerBuildState.handleNewPlayer(player);
|
ServerBuildState.handleNewPlayer(player);
|
||||||
|
|
||||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ModifierSettingsPacket(player));
|
((ServerPlayer)player).connection.send(new ModifierSettingsPacket(player));
|
||||||
EffortlessBuilding.SERVER_POWER_LEVEL.sendToClient(player);
|
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClone(PlayerEvent.Clone event) {
|
||||||
|
// If not dead, player is returning from the End
|
||||||
|
if (!event.isWasDeath()) return;
|
||||||
|
|
||||||
|
Player original = event.getOriginal();
|
||||||
|
Player clone = event.getEntity();
|
||||||
|
|
||||||
|
// Copy the power level from the original player to the clone
|
||||||
|
if (event.isWasDeath() && event.getOriginal().hasData(EffortlessBuilding.POWER_LEVEL)) {
|
||||||
|
event.getEntity().setData(EffortlessBuilding.POWER_LEVEL, event.getOriginal().getData(EffortlessBuilding.POWER_LEVEL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -1,46 +1,56 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.flag.FeatureFlags;
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.item.CreativeModeTabs;
|
import net.minecraft.world.item.CreativeModeTabs;
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
import net.neoforged.fml.ModContainer;
|
||||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.neoforged.fml.config.ModConfig;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.neoforged.fml.loading.FMLEnvironment;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.minecraftforge.network.IContainerFactory;
|
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.neoforged.neoforge.network.IContainerFactory;
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
import net.neoforged.neoforge.registries.DeferredItem;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||||
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagContainer;
|
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagContainer;
|
||||||
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagContainer;
|
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagContainer;
|
||||||
import nl.requios.effortlessbuilding.gui.RandomizerBagContainer;
|
import nl.requios.effortlessbuilding.gui.RandomizerBagContainer;
|
||||||
import nl.requios.effortlessbuilding.item.*;
|
import nl.requios.effortlessbuilding.item.DiamondRandomizerBagItem;
|
||||||
|
import nl.requios.effortlessbuilding.item.GoldenRandomizerBagItem;
|
||||||
|
import nl.requios.effortlessbuilding.item.PowerLevelItem;
|
||||||
|
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
|
||||||
|
import nl.requios.effortlessbuilding.item.ReachUpgrade1Item;
|
||||||
|
import nl.requios.effortlessbuilding.item.ReachUpgrade2Item;
|
||||||
|
import nl.requios.effortlessbuilding.item.ReachUpgrade3Item;
|
||||||
|
import nl.requios.effortlessbuilding.item.SingleItemLootModifier;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||||
import nl.requios.effortlessbuilding.proxy.IProxy;
|
|
||||||
import nl.requios.effortlessbuilding.proxy.ServerProxy;
|
import nl.requios.effortlessbuilding.proxy.ServerProxy;
|
||||||
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerBlockPlacer;
|
import nl.requios.effortlessbuilding.systems.ServerBlockPlacer;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerPowerLevel;
|
|
||||||
import nl.requios.effortlessbuilding.systems.UndoRedo;
|
import nl.requios.effortlessbuilding.systems.UndoRedo;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Mod(EffortlessBuilding.MODID)
|
@Mod(EffortlessBuilding.MODID)
|
||||||
public class EffortlessBuilding {
|
public class EffortlessBuilding {
|
||||||
@@ -49,60 +59,61 @@ public class EffortlessBuilding {
|
|||||||
public static final Logger logger = LogManager.getLogger();
|
public static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static EffortlessBuilding instance;
|
public static EffortlessBuilding instance;
|
||||||
public static IProxy proxy = DistExecutor.unsafeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
|
||||||
|
|
||||||
public static final ServerBlockPlacer SERVER_BLOCK_PLACER = new ServerBlockPlacer();
|
public static final ServerBlockPlacer SERVER_BLOCK_PLACER = new ServerBlockPlacer();
|
||||||
public static final UndoRedo UNDO_REDO = new UndoRedo();
|
public static final UndoRedo UNDO_REDO = new UndoRedo();
|
||||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||||
public static final ServerPowerLevel SERVER_POWER_LEVEL = new ServerPowerLevel();
|
|
||||||
|
|
||||||
//Registration
|
//Registration
|
||||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
|
||||||
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, EffortlessBuilding.MODID);
|
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(BuiltInRegistries.MENU, EffortlessBuilding.MODID);
|
||||||
public static final DeferredRegister<Codec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, EffortlessBuilding.MODID);
|
private static final DeferredRegister<MapCodec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, EffortlessBuilding.MODID);
|
||||||
|
private static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, EffortlessBuilding.MODID);
|
||||||
|
|
||||||
public static final RegistryObject<Item> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
public static final DeferredItem<RandomizerBagItem> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
||||||
public static final RegistryObject<Item> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
public static final DeferredItem<GoldenRandomizerBagItem> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
||||||
public static final RegistryObject<Item> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
public static final DeferredItem<DiamondRandomizerBagItem> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
||||||
public static final RegistryObject<Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
public static final DeferredItem<ReachUpgrade1Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
||||||
public static final RegistryObject<Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
public static final DeferredItem<ReachUpgrade2Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
||||||
public static final RegistryObject<Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
public static final DeferredItem<ReachUpgrade3Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
||||||
public static final RegistryObject<Item> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
public static final DeferredItem<PowerLevelItem> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
||||||
public static final RegistryObject<Item> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
public static final DeferredItem<PowerLevelItem> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
||||||
public static final RegistryObject<Item> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
public static final DeferredItem<PowerLevelItem> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
||||||
|
|
||||||
public static final RegistryObject<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
public static final Supplier<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
||||||
public static final RegistryObject<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
public static final Supplier<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
||||||
public static final RegistryObject<MenuType<DiamondRandomizerBagContainer>> DIAMOND_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("diamond_randomizer_bag", () -> registerContainer(DiamondRandomizerBagContainer::new));
|
public static final Supplier<MenuType<DiamondRandomizerBagContainer>> DIAMOND_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("diamond_randomizer_bag", () -> registerContainer(DiamondRandomizerBagContainer::new));
|
||||||
|
|
||||||
|
public static final Supplier<MapCodec<SingleItemLootModifier>> SINGLE_ITEM_LOOT_MODIFIER = EffortlessBuilding.LOOT_MODIFIERS.register("single_item_loot_modifier", SingleItemLootModifier.CODEC);
|
||||||
|
|
||||||
public EffortlessBuilding() {
|
public static final Supplier<AttachmentType<PowerLevel>> POWER_LEVEL = ATTACHMENT_TYPES.register("power_level", () -> AttachmentType.serializable(PowerLevel::new).build());
|
||||||
|
|
||||||
|
public EffortlessBuilding(IEventBus modEventBus, ModContainer container, Dist dist) {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
IEventBus forgeEventBus = NeoForge.EVENT_BUS;
|
||||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
|
||||||
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
|
|
||||||
|
|
||||||
modEventBus.addListener(EffortlessBuilding::setup);
|
modEventBus.addListener(EffortlessBuilding::setup);
|
||||||
modEventBus.addListener(EffortlessBuilding::addTabContents);
|
modEventBus.addListener(EffortlessBuilding::addTabContents);
|
||||||
|
modEventBus.addListener(PacketHandler::setupPackets);
|
||||||
|
|
||||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus));
|
ITEMS.register(modEventBus);
|
||||||
|
CONTAINERS.register(modEventBus);
|
||||||
|
|
||||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
LOOT_MODIFIERS.register(modEventBus);
|
||||||
CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
ATTACHMENT_TYPES.register(modEventBus);
|
||||||
|
|
||||||
var singleItemLootModifier = SingleItemLootModifier.CODEC; //load this class to register the loot modifier
|
|
||||||
LOOT_MODIFIERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
|
||||||
|
|
||||||
//Register config
|
//Register config
|
||||||
modLoadingContext.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
container.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
||||||
modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);
|
container.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
||||||
modLoadingContext.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
if (dist.isClient()) {
|
||||||
|
container.registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);
|
||||||
|
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
|
||||||
|
EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setup(final FMLCommonSetupEvent event) {
|
public static void setup(final FMLCommonSetupEvent event) {
|
||||||
PacketHandler.register();
|
|
||||||
|
|
||||||
CompatHelper.setup();
|
CompatHelper.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +124,7 @@ public class EffortlessBuilding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends AbstractContainerMenu> MenuType<T> registerContainer(IContainerFactory<T> fact){
|
public static <T extends AbstractContainerMenu> MenuType<T> registerContainer(IContainerFactory<T> fact) {
|
||||||
MenuType<T> type = new MenuType<T>(fact, FeatureFlags.REGISTRY.allFlags());
|
MenuType<T> type = new MenuType<T>(fact, FeatureFlags.REGISTRY.allFlags());
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -132,11 +143,18 @@ public class EffortlessBuilding {
|
|||||||
|
|
||||||
//Log with translation supported, call either on client or server (which then sends a message)
|
//Log with translation supported, call either on client or server (which then sends a message)
|
||||||
public static void logTranslate(Player player, String prefix, String translationKey, String suffix, boolean actionBar) {
|
public static void logTranslate(Player player, String prefix, String translationKey, String suffix, boolean actionBar) {
|
||||||
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
if (FMLEnvironment.dist.isClient()) {
|
||||||
|
ClientProxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||||
|
} else {
|
||||||
|
ServerProxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void logError(String msg) {
|
public static void logError(String msg) {
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation asResource(String path) {
|
||||||
|
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.MenuScreens;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
||||||
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagScreen;
|
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagScreen;
|
||||||
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagScreen;
|
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagScreen;
|
||||||
import nl.requios.effortlessbuilding.gui.RandomizerBagScreen;
|
import nl.requios.effortlessbuilding.gui.RandomizerBagScreen;
|
||||||
import nl.requios.effortlessbuilding.render.BlockPreviews;
|
import nl.requios.effortlessbuilding.render.BlockPreviews;
|
||||||
import nl.requios.effortlessbuilding.systems.*;
|
import nl.requios.effortlessbuilding.systems.BuildSettings;
|
||||||
|
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
||||||
|
import nl.requios.effortlessbuilding.systems.BuilderFilter;
|
||||||
|
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
||||||
|
|
||||||
public class EffortlessBuildingClient {
|
public class EffortlessBuildingClient {
|
||||||
|
|
||||||
@@ -20,15 +22,14 @@ public class EffortlessBuildingClient {
|
|||||||
public static final BlockPreviews BLOCK_PREVIEWS = new BlockPreviews();
|
public static final BlockPreviews BLOCK_PREVIEWS = new BlockPreviews();
|
||||||
public static final BuilderFilter BUILDER_FILTER = new BuilderFilter();
|
public static final BuilderFilter BUILDER_FILTER = new BuilderFilter();
|
||||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||||
public static final PowerLevel POWER_LEVEL = new PowerLevel();
|
|
||||||
|
|
||||||
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
||||||
modEventBus.addListener(EffortlessBuildingClient::clientSetup);
|
modEventBus.addListener(EffortlessBuildingClient::registerMenuScreens);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clientSetup(final FMLClientSetupEvent event) {
|
public static void registerMenuScreens(final RegisterMenuScreensEvent event) {
|
||||||
MenuScreens.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
event.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
||||||
MenuScreens.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
event.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
||||||
MenuScreens.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
event.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
|
||||||
|
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||||
|
|
||||||
public class ServerConfig {
|
public class ServerConfig {
|
||||||
private static final Builder builder = new Builder();
|
private static final Builder builder = new Builder();
|
||||||
public static final ServerConfig.Validation validation = new ServerConfig.Validation(builder);
|
public static final ServerConfig.Validation validation = new ServerConfig.Validation(builder);
|
||||||
public static final ServerConfig.Memory memory = new ServerConfig.Memory(builder);
|
public static final ServerConfig.Memory memory = new ServerConfig.Memory(builder);
|
||||||
public static final ForgeConfigSpec spec = builder.build();
|
public static final ModConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Validation {
|
public static class Validation {
|
||||||
public final BooleanValue allowInSurvival;
|
public final BooleanValue allowInSurvival;
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package nl.requios.effortlessbuilding.attachment;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
|
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
||||||
|
|
||||||
|
public class AttachmentHandler {
|
||||||
|
public static final ResourceLocation POWER_LEVEL_CAP = EffortlessBuilding.asResource("power_level");
|
||||||
|
|
||||||
|
public static void syncToClient(Player player) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||||
|
|
||||||
|
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Helper methods to reduce boilerplate code
|
||||||
|
public static boolean canReplaceBlocks(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canReplaceBlocks(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxBlocksPerAxis(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxBlocksPerAxis.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxBlocksPlacedAtOnce(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxMirrorRadius(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxMirrorRadius.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBuildModeReach(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getBuildModeReach(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxMirrorRadius.level0.get() + 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getPlacementReach(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.reach.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getPowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNextPowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getNextPowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canIncreasePowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canIncreasePowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isDisabled(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.isDisabled(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canBreakFar(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canBreakFar(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,41 @@
|
|||||||
package nl.requios.effortlessbuilding.systems;
|
package nl.requios.effortlessbuilding.attachment;
|
||||||
|
|
||||||
|
import net.minecraft.core.HolderLookup.Provider;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
|
||||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
public class PowerLevel implements INBTSerializable<CompoundTag> {
|
||||||
public class PowerLevel {
|
public static final int MAX_POWER_LEVEL = 3; //Common access
|
||||||
|
|
||||||
private int powerLevel;
|
public PowerLevel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private int powerLevel = 0;
|
||||||
|
|
||||||
public int getPowerLevel() {
|
public int getPowerLevel() {
|
||||||
return powerLevel;
|
return this.powerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNextPowerLevel() {
|
public int getNextPowerLevel() {
|
||||||
return Math.min(powerLevel + 1, ServerPowerLevel.MAX_POWER_LEVEL);
|
return Math.min(getPowerLevel() + 1, MAX_POWER_LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPowerLevel(int powerLevel) {
|
public void setPowerLevel(int powerLevel) {
|
||||||
this.powerLevel = powerLevel;
|
this.powerLevel = powerLevel;
|
||||||
EffortlessBuildingClient.BUILD_MODIFIERS.onPowerLevelChanged(powerLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canIncreasePowerLevel() {
|
public boolean canIncreasePowerLevel() {
|
||||||
return getPowerLevel() < ServerPowerLevel.MAX_POWER_LEVEL;
|
return getPowerLevel() < MAX_POWER_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void increasePowerLevel() {
|
public void increasePowerLevel() {
|
||||||
if (canIncreasePowerLevel()) {
|
if (canIncreasePowerLevel()) {
|
||||||
setPowerLevel(getPowerLevel() + 1);
|
setPowerLevel(getPowerLevel() + 1);
|
||||||
PacketHandler.INSTANCE.sendToServer(new PowerLevelPacket(powerLevel));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int getMaxReach(Player player) {
|
|
||||||
return getPlacementReach(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlacementReach(Player player) {
|
|
||||||
return getPlacementReach(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||||
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
||||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||||
@@ -59,11 +49,7 @@ public class PowerLevel {
|
|||||||
//How far away we can detect the second and third click of build modes (distance to player)
|
//How far away we can detect the second and third click of build modes (distance to player)
|
||||||
public int getBuildModeReach(Player player) {
|
public int getBuildModeReach(Player player) {
|
||||||
//A bit further than placement reach, so you can build lines when looking to the side without having to move.
|
//A bit further than placement reach, so you can build lines when looking to the side without having to move.
|
||||||
return getPlacementReach(player) + 6;
|
return getPlacementReach(player, false) + 6;
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxBlocksPlacedAtOnce(Player player) {
|
|
||||||
return getMaxBlocksPlacedAtOnce(player, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||||
@@ -76,10 +62,6 @@ public class PowerLevel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxBlocksPerAxis(Player player) {
|
|
||||||
return getMaxBlocksPerAxis(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||||
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
||||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||||
@@ -90,10 +72,6 @@ public class PowerLevel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxMirrorRadius(Player player) {
|
|
||||||
return getMaxMirrorRadius(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||||
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
||||||
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
||||||
@@ -105,14 +83,24 @@ public class PowerLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDisabled(Player player) {
|
public boolean isDisabled(Player player) {
|
||||||
return getMaxBlocksPlacedAtOnce(player) <= 0 || getMaxBlocksPerAxis(player) <= 0;
|
return getMaxBlocksPlacedAtOnce(player, false) <= 0 || getMaxBlocksPerAxis(player, false) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBreakFar(Player player) {
|
public boolean canBreakFar(Player player) {
|
||||||
return player.isCreative();
|
return player.getAbilities().instabuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canReplaceBlocks(Player player) {
|
public boolean canReplaceBlocks(Player player) {
|
||||||
return player.isCreative();
|
return player.getAbilities().instabuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag serializeNBT(Provider provider) {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putInt("powerLevel", getPowerLevel());
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deserializeNBT(Provider provider, CompoundTag nbt) {
|
||||||
|
setPowerLevel(nbt.getInt("powerLevel"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode;
|
package nl.requios.effortlessbuilding.buildmode;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
import net.createmod.catnip.theme.Color;
|
||||||
|
|
||||||
public enum BuildModeCategoryEnum {
|
public enum BuildModeCategoryEnum {
|
||||||
BASIC(new Color(0f, .5f, 1f, .8f)),
|
BASIC(new Color(0f, .5f, 1f, .8f)),
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode;
|
package nl.requios.effortlessbuilding.buildmode;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.AllIcons;
|
import nl.requios.effortlessbuilding.AllIcons;
|
||||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.*;
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Circle;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Cube;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Cylinder;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.DiagonalLine;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.DiagonalWall;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Disabled;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Floor;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Line;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Single;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.SlopeFloor;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Sphere;
|
||||||
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.Wall;
|
||||||
|
|
||||||
public enum BuildModeEnum {
|
public enum BuildModeEnum {
|
||||||
DISABLED("normal", new Disabled(), BuildModeCategoryEnum.BASIC, AllIcons.I_DISABLE),
|
DISABLED("normal", new Disabled(), BuildModeCategoryEnum.BASIC, AllIcons.I_DISABLE),
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.level.ClipContext;
|
import net.minecraft.world.level.ClipContext;
|
||||||
import net.minecraft.world.phys.HitResult;
|
import net.minecraft.world.phys.HitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.network.IsUsingBuildModePacket;
|
import nl.requios.effortlessbuilding.network.message.IsUsingBuildModePacket;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@@ -30,7 +30,7 @@ public class BuildModes {
|
|||||||
public void setBuildMode(BuildModeEnum buildMode) {
|
public void setBuildMode(BuildModeEnum buildMode) {
|
||||||
this.buildMode = buildMode;
|
this.buildMode = buildMode;
|
||||||
|
|
||||||
PacketHandler.INSTANCE.sendToServer(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
PacketDistributor.sendToServer(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
||||||
|
|
||||||
EffortlessBuilding.log(Minecraft.getInstance().player, I18n.get(buildMode.getNameKey()), true);
|
EffortlessBuilding.log(Minecraft.getInstance().player, I18n.get(buildMode.getNameKey()), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode;
|
package nl.requios.effortlessbuilding.buildmode;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import nl.requios.effortlessbuilding.AllIcons;
|
import nl.requios.effortlessbuilding.AllIcons;
|
||||||
import nl.requios.effortlessbuilding.ClientEvents;
|
import nl.requios.effortlessbuilding.ClientEvents;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
import nl.requios.effortlessbuilding.network.message.PerformRedoPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PerformRedoPacket;
|
import nl.requios.effortlessbuilding.network.message.PerformUndoPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PerformUndoPacket;
|
|
||||||
import nl.requios.effortlessbuilding.systems.BuildSettings;
|
import nl.requios.effortlessbuilding.systems.BuildSettings;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@@ -69,8 +69,8 @@ public class ModeOptions {
|
|||||||
if (action == null) return;
|
if (action == null) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case UNDO -> PacketHandler.INSTANCE.sendToServer(new PerformUndoPacket());
|
case UNDO -> PacketDistributor.sendToServer(new PerformUndoPacket());
|
||||||
case REDO -> PacketHandler.INSTANCE.sendToServer(new PerformRedoPacket());
|
case REDO -> PacketDistributor.sendToServer(new PerformRedoPacket());
|
||||||
case OPEN_MODIFIER_SETTINGS -> ClientEvents.openModifierSettings();
|
case OPEN_MODIFIER_SETTINGS -> ClientEvents.openModifierSettings();
|
||||||
case OPEN_PLAYER_SETTINGS -> ClientEvents.openPlayerSettings();
|
case OPEN_PLAYER_SETTINGS -> ClientEvents.openPlayerSettings();
|
||||||
case PREVIOUS_BUILD_MODE -> EffortlessBuildingClient.BUILD_MODES.activatePreviousBuildMode();
|
case PREVIOUS_BUILD_MODE -> EffortlessBuildingClient.BUILD_MODES.activatePreviousBuildMode();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (secondPos == null) return;
|
if (secondPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks we can place per row
|
//Limit amount of blocks we can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||||
|
|
||||||
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
||||||
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
||||||
@@ -93,7 +94,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (thirdPos == null) return;
|
if (thirdPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks you can place per row
|
//Limit amount of blocks you can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||||
|
|
||||||
int x1 = firstPos.getX(), x2 = secondPos.getX(), x3 = thirdPos.getX();
|
int x1 = firstPos.getX(), x2 = secondPos.getX(), x3 = thirdPos.getX();
|
||||||
int y1 = firstPos.getY(), y2 = secondPos.getY(), y3 = thirdPos.getY();
|
int y1 = firstPos.getY(), y2 = secondPos.getY(), y3 = thirdPos.getY();
|
||||||
@@ -139,7 +140,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
|
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
|
||||||
|
|
||||||
//Remove invalid criteria
|
//Remove invalid criteria
|
||||||
int reach = EffortlessBuildingClient.POWER_LEVEL.getBuildModeReach(player);
|
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||||
|
|
||||||
//If none are valid, return empty list of blocks
|
//If none are valid, return empty list of blocks
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
|||||||
if (secondPos == null) return;
|
if (secondPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks we can place per row
|
//Limit amount of blocks we can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||||
|
|
||||||
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
||||||
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||||
@@ -24,7 +24,7 @@ public class Floor extends TwoClicksBuildMode {
|
|||||||
criteriaList.add(new Criteria(yBound, start));
|
criteriaList.add(new Criteria(yBound, start));
|
||||||
|
|
||||||
//Remove invalid criteria
|
//Remove invalid criteria
|
||||||
int reach = EffortlessBuildingClient.POWER_LEVEL.getBuildModeReach(player);
|
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||||
|
|
||||||
//If none are valid, return empty list of blocks
|
//If none are valid, return empty list of blocks
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class Line extends TwoClicksBuildMode {
|
|||||||
criteriaList.add(new Criteria(zBound, firstPos, start));
|
criteriaList.add(new Criteria(zBound, firstPos, start));
|
||||||
|
|
||||||
//Remove invalid criteria
|
//Remove invalid criteria
|
||||||
int reach = EffortlessBuildingClient.POWER_LEVEL.getBuildModeReach(player);
|
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||||
|
|
||||||
//If none are valid, return empty list of blocks
|
//If none are valid, return empty list of blocks
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public class SlopeFloor extends ThreeClicksBuildMode {
|
|||||||
public static List<BlockPos> getSlopeFloorBlocks(Player player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
|
public static List<BlockPos> getSlopeFloorBlocks(Player player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
|
||||||
List<BlockPos> list = new ArrayList<>();
|
List<BlockPos> list = new ArrayList<>();
|
||||||
|
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||||
|
|
||||||
//Determine whether to use x or z axis to slope up
|
//Determine whether to use x or z axis to slope up
|
||||||
boolean onXAxis = true;
|
boolean onXAxis = true;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||||
@@ -28,7 +28,7 @@ public class Wall extends TwoClicksBuildMode {
|
|||||||
criteriaList.add(new Criteria(zBound, firstPos, start, look));
|
criteriaList.add(new Criteria(zBound, firstPos, start, look));
|
||||||
|
|
||||||
//Remove invalid criteria
|
//Remove invalid criteria
|
||||||
int reach = EffortlessBuildingClient.POWER_LEVEL.getBuildModeReach(player);
|
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||||
|
|
||||||
//If none are valid, return empty list of blocks
|
//If none are valid, return empty list of blocks
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmodifier;
|
package nl.requios.effortlessbuilding.buildmodifier;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmodifier;
|
package nl.requios.effortlessbuilding.buildmodifier;
|
||||||
|
|
||||||
|
import net.createmod.catnip.nbt.NBTHelper;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.NBTHelper;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -96,7 +96,7 @@ public class BuildModifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
PacketHandler.INSTANCE.sendToServer(new ModifierSettingsPacket(serializeNBT()));
|
PacketDistributor.sendToServer(new ModifierSettingsPacket(serializeNBT()));
|
||||||
|
|
||||||
//Save locally as well?
|
//Save locally as well?
|
||||||
// var listTag = NBTHelper.writeCompoundList(modifierSettingsList, BaseModifier::serializeNBT);
|
// var listTag = NBTHelper.writeCompoundList(modifierSettingsList, BaseModifier::serializeNBT);
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmodifier;
|
package nl.requios.effortlessbuilding.buildmodifier;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ public class Mirror extends BaseModifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPowerLevelChanged(int powerLevel) {
|
public void onPowerLevelChanged(int powerLevel) {
|
||||||
radius = EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player);
|
radius = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performMirrorX(BlockSet blocks, BlockEntry blockEntry) {
|
private void performMirrorX(BlockSet blocks, BlockEntry blockEntry) {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmodifier;
|
package nl.requios.effortlessbuilding.buildmodifier;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.block.Mirror;
|
import net.minecraft.world.level.block.Mirror;
|
||||||
import net.minecraft.world.level.block.Rotation;
|
import net.minecraft.world.level.block.Rotation;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class RadialMirror extends BaseModifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPowerLevelChanged(int powerLevel) {
|
public void onPowerLevelChanged(int powerLevel) {
|
||||||
radius = EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player);
|
radius = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package nl.requios.effortlessbuilding.compatibility;
|
package nl.requios.effortlessbuilding.compatibility;
|
||||||
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemHelper;
|
import nl.requios.effortlessbuilding.create.foundation.item.ItemHelper;
|
||||||
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create;
|
package nl.requios.effortlessbuilding.create;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.createmod.catnip.render.BindableTexture;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
public enum AllSpecialTextures {
|
public enum AllSpecialTextures implements BindableTexture {
|
||||||
|
|
||||||
BLANK("blank.png"),
|
BLANK("blank.png"),
|
||||||
CHECKERED("checkerboard.png"),
|
CHECKERED("checkerboard.png"),
|
||||||
@@ -18,7 +19,7 @@ public enum AllSpecialTextures {
|
|||||||
public static final String ASSET_PATH = "textures/special/";
|
public static final String ASSET_PATH = "textures/special/";
|
||||||
private ResourceLocation location;
|
private ResourceLocation location;
|
||||||
|
|
||||||
private AllSpecialTextures(String filename) {
|
AllSpecialTextures(String filename) {
|
||||||
location = Create.asResource(ASSET_PATH + filename);
|
location = Create.asResource(ASSET_PATH + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ public class Create {
|
|||||||
public static final Logger LOGGER = LogUtils.getLogger();
|
public static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
public static ResourceLocation asResource(String path) {
|
public static ResourceLocation asResource(String path) {
|
||||||
return new ResourceLocation(EffortlessBuilding.MODID, path);
|
return ResourceLocation.fromNamespaceAndPath(EffortlessBuilding.MODID, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create;
|
package nl.requios.effortlessbuilding.create;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache;
|
import net.createmod.catnip.render.SuperByteBufferCache;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.ghost.GhostBlocks;
|
import nl.requios.effortlessbuilding.create.foundation.utility.ghost.GhostBlocks;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.outliner.Outliner;
|
|
||||||
|
|
||||||
public class CreateClient {
|
public class CreateClient {
|
||||||
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
||||||
public static final Outliner OUTLINER = new Outliner();
|
|
||||||
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
||||||
|
|
||||||
public static void invalidateRenderers() {
|
public static void invalidateRenderers() {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create;
|
|
||||||
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(Dist.CLIENT)
|
|
||||||
public class CreateClientTest {
|
|
||||||
|
|
||||||
// @SubscribeEvent
|
|
||||||
// public static void onTick(TickEvent.ClientTickEvent event) {
|
|
||||||
// CreateClient.GHOST_BLOCKS.showGhostState(1, Blocks.SPRUCE_LOG.defaultBlockState())
|
|
||||||
// .at(0, 120, 0)
|
|
||||||
// .breathingAlpha();
|
|
||||||
// CreateClient.GHOST_BLOCKS.showGhostState(2, Blocks.SPRUCE_LOG.defaultBlockState())
|
|
||||||
// .at(1, 120, 0)
|
|
||||||
// .breathingAlpha();
|
|
||||||
//
|
|
||||||
// CreateClient.OUTLINER.showAABB(1, new AABB(0, 0, 0, 10, 2, 6)
|
|
||||||
// .move(10, 120, 0))
|
|
||||||
// .withFaceTexture(AllSpecialTextures.CHECKERED)
|
|
||||||
// .colored(new Color(0.11f, 0.49f, 0.7f, 1f))
|
|
||||||
//// .colored(0xbfbfbf)
|
|
||||||
// .disableNormals()
|
|
||||||
// .lineWidth(1 / 32f);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -2,24 +2,24 @@ package nl.requios.effortlessbuilding.create.events;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||||
|
import net.createmod.catnip.levelWrappers.WrappedClientLevel;
|
||||||
|
import net.createmod.catnip.render.DefaultSuperRenderTypeBuffer;
|
||||||
|
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.client.event.ViewportEvent;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||||
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
||||||
import net.minecraftforge.event.level.LevelEvent;
|
import net.neoforged.neoforge.client.event.ViewportEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHolder;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.CameraAngleAnimationService;
|
import nl.requios.effortlessbuilding.create.foundation.utility.CameraAngleAnimationService;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
|
||||||
|
|
||||||
@EventBusSubscriber(Dist.CLIENT)
|
@EventBusSubscriber(Dist.CLIENT)
|
||||||
public class ClientEvents {
|
public class ClientEvents {
|
||||||
@@ -28,20 +28,20 @@ public class ClientEvents {
|
|||||||
private static final String BLOCK_PREFIX = "block." + Create.ID;
|
private static final String BLOCK_PREFIX = "block." + Create.ID;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTick(ClientTickEvent event) {
|
public static void onTick(ClientTickEvent.Post event) {
|
||||||
if (!isGameActive() || event.phase != TickEvent.Phase.END) return;
|
if (!isGameActive()) return;
|
||||||
|
|
||||||
AnimationTickHolder.tick();
|
AnimationTickHolder.tick();
|
||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.tickGhosts();
|
CreateClient.GHOST_BLOCKS.tickGhosts();
|
||||||
CreateClient.OUTLINER.tickOutlines();
|
// CreateClient.OUTLINER.tickOutlines();
|
||||||
CameraAngleAnimationService.tick();
|
CameraAngleAnimationService.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onLoadWorld(LevelEvent.Load event) {
|
public static void onLoadWorld(LevelEvent.Load event) {
|
||||||
LevelAccessor world = event.getLevel();
|
LevelAccessor world = event.getLevel();
|
||||||
if (world.isClientSide() && world instanceof ClientLevel && !(world instanceof WrappedClientWorld)) {
|
if (world.isClientSide() && world instanceof ClientLevel && !(world instanceof WrappedClientLevel)) {
|
||||||
CreateClient.invalidateRenderers();
|
CreateClient.invalidateRenderers();
|
||||||
AnimationTickHolder.reset();
|
AnimationTickHolder.reset();
|
||||||
}
|
}
|
||||||
@@ -67,11 +67,11 @@ public class ClientEvents {
|
|||||||
PoseStack ms = event.getPoseStack();
|
PoseStack ms = event.getPoseStack();
|
||||||
ms.pushPose();
|
ms.pushPose();
|
||||||
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
||||||
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
SuperRenderTypeBuffer buffer = DefaultSuperRenderTypeBuffer.getInstance();
|
||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
||||||
|
|
||||||
CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
// CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
||||||
buffer.draw();
|
buffer.draw();
|
||||||
RenderSystem.enableCull();
|
RenderSystem.enableCull();
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.events;
|
package nl.requios.effortlessbuilding.create.events;
|
||||||
|
|
||||||
|
import net.createmod.catnip.data.WorldAttached;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraftforge.event.level.LevelEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.WorldAttached;
|
|
||||||
|
|
||||||
@EventBusSubscriber
|
@EventBusSubscriber
|
||||||
public class CommonEvents {
|
public class CommonEvents {
|
||||||
@@ -16,7 +16,7 @@ public class CommonEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
// @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||||
public static class ModBusEvents {
|
public static class ModBusEvents {
|
||||||
|
|
||||||
// @SubscribeEvent
|
// @SubscribeEvent
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation;
|
package nl.requios.effortlessbuilding.create.foundation;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.LangNumberFormat;
|
import net.createmod.catnip.lang.LangNumberFormat;
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation;
|
|
||||||
|
|
||||||
import net.minecraftforge.forgespi.locating.IModFile;
|
|
||||||
import net.minecraftforge.resource.PathPackResources;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class ModFilePackResources extends PathPackResources {
|
|
||||||
protected final IModFile modFile;
|
|
||||||
protected final String sourcePath;
|
|
||||||
|
|
||||||
public ModFilePackResources(String name, IModFile modFile, String sourcePath) {
|
|
||||||
super(name, true, modFile.findResource(sourcePath));
|
|
||||||
this.modFile = modFile;
|
|
||||||
this.sourcePath = sourcePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Path resolve(String... paths) {
|
|
||||||
String[] allPaths = new String[paths.length + 1];
|
|
||||||
allPaths[0] = sourcePath;
|
|
||||||
System.arraycopy(paths, 0, allPaths, 1, paths.length);
|
|
||||||
return modFile.findResource(allPaths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||||
|
|
||||||
|
import net.createmod.catnip.render.SpriteShiftEntry;
|
||||||
|
|
||||||
|
public class CTSpriteShiftEntry extends SpriteShiftEntry {
|
||||||
|
|
||||||
|
protected final CTType type;
|
||||||
|
|
||||||
|
public CTSpriteShiftEntry(CTType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CTType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetU(float localU, int index) {
|
||||||
|
float uOffset = (index % type.getSheetSize());
|
||||||
|
return getTarget().getU(
|
||||||
|
(getUnInterpolatedU(getOriginal(), localU) + uOffset) / ((float) type.getSheetSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetV(float localV, int index) {
|
||||||
|
float vOffset = (index / type.getSheetSize());
|
||||||
|
return getTarget().getV(
|
||||||
|
(getUnInterpolatedV(getOriginal(), localV) + vOffset) / ((float) type.getSheetSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import nl.requios.effortlessbuilding.create.foundation.block.render.ConnectedTextureBehaviour.CTContext;
|
||||||
|
import nl.requios.effortlessbuilding.create.foundation.block.render.ConnectedTextureBehaviour.ContextRequirement;
|
||||||
|
|
||||||
|
public interface CTType {
|
||||||
|
ResourceLocation getId();
|
||||||
|
|
||||||
|
int getSheetSize();
|
||||||
|
|
||||||
|
ContextRequirement getContextRequirement();
|
||||||
|
|
||||||
|
int getTextureIndex(CTContext context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Direction.Axis;
|
||||||
|
import net.minecraft.core.Direction.AxisDirection;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.BlockAndTintGetter;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class ConnectedTextureBehaviour {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CTSpriteShiftEntry getShift(BlockState state, RandomSource rand, Direction direction,
|
||||||
|
@NotNull TextureAtlasSprite sprite) {
|
||||||
|
return getShift(state, direction, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction,
|
||||||
|
@NotNull TextureAtlasSprite sprite);
|
||||||
|
|
||||||
|
// TODO: allow more than one data type per state/face?
|
||||||
|
@Nullable
|
||||||
|
public abstract CTType getDataType(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction direction);
|
||||||
|
|
||||||
|
public boolean buildContextForOccludedDirections() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isBeingBlocked(BlockState state, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos,
|
||||||
|
Direction face) {
|
||||||
|
BlockPos blockingPos = otherPos.relative(face);
|
||||||
|
BlockState blockState = reader.getBlockState(pos);
|
||||||
|
BlockState blockingState = reader.getBlockState(blockingPos);
|
||||||
|
|
||||||
|
if (!Block.isFaceFull(blockingState.getShape(reader, blockingPos), face.getOpposite()))
|
||||||
|
return false;
|
||||||
|
if (face.getAxis()
|
||||||
|
.choose(pos.getX(), pos.getY(), pos.getZ()) != face.getAxis()
|
||||||
|
.choose(otherPos.getX(), otherPos.getY(), otherPos.getZ()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return connectsTo(state,
|
||||||
|
getCTBlockState(reader, blockState, face.getOpposite(), pos.relative(face), blockingPos), reader, pos,
|
||||||
|
blockingPos, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos,
|
||||||
|
BlockPos otherPos, Direction face, Direction primaryOffset, Direction secondaryOffset) {
|
||||||
|
return connectsTo(state, other, reader, pos, otherPos, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos,
|
||||||
|
BlockPos otherPos, Direction face) {
|
||||||
|
return !isBeingBlocked(state, reader, pos, otherPos, face) && state.getBlock() == other.getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean testConnection(BlockAndTintGetter reader, BlockPos currentPos, BlockState connectiveCurrentState,
|
||||||
|
Direction textureSide, final Direction horizontal, final Direction vertical, int sh, int sv) {
|
||||||
|
BlockState trueCurrentState = reader.getBlockState(currentPos);
|
||||||
|
BlockPos targetPos = currentPos.relative(horizontal, sh)
|
||||||
|
.relative(vertical, sv);
|
||||||
|
BlockState connectiveTargetState =
|
||||||
|
getCTBlockState(reader, trueCurrentState, textureSide, currentPos, targetPos);
|
||||||
|
return connectsTo(connectiveCurrentState, connectiveTargetState, reader, currentPos, targetPos, textureSide,
|
||||||
|
sh == 0 ? null : sh == -1 ? horizontal.getOpposite() : horizontal,
|
||||||
|
sv == 0 ? null : sv == -1 ? vertical.getOpposite() : vertical);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockState getCTBlockState(BlockAndTintGetter reader, BlockState reference, Direction face, BlockPos fromPos,
|
||||||
|
BlockPos toPos) {
|
||||||
|
BlockState blockState = reader.getBlockState(toPos);
|
||||||
|
return blockState.getAppearance(reader, toPos, face, reference, fromPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean reverseUVs(BlockState state, Direction face) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean reverseUVsHorizontally(BlockState state, Direction face) {
|
||||||
|
return reverseUVs(state, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean reverseUVsVertically(BlockState state, Direction face) {
|
||||||
|
return reverseUVs(state, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
|
||||||
|
Axis axis = face.getAxis();
|
||||||
|
return axis.isHorizontal() ? Direction.UP : Direction.NORTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Direction getRightDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
|
||||||
|
Axis axis = face.getAxis();
|
||||||
|
return axis == Axis.X ? Direction.SOUTH : Direction.WEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CTContext buildContext(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face,
|
||||||
|
ContextRequirement requirement) {
|
||||||
|
boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
|
||||||
|
Direction h = getRightDirection(reader, pos, state, face);
|
||||||
|
Direction v = getUpDirection(reader, pos, state, face);
|
||||||
|
h = positive ? h.getOpposite() : h;
|
||||||
|
if (face == Direction.DOWN) {
|
||||||
|
v = v.getOpposite();
|
||||||
|
h = h.getOpposite();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Direction horizontal = h;
|
||||||
|
final Direction vertical = v;
|
||||||
|
|
||||||
|
boolean flipH = reverseUVsHorizontally(state, face);
|
||||||
|
boolean flipV = reverseUVsVertically(state, face);
|
||||||
|
int sh = flipH ? -1 : 1;
|
||||||
|
int sv = flipV ? -1 : 1;
|
||||||
|
|
||||||
|
CTContext context = new CTContext();
|
||||||
|
|
||||||
|
if (requirement.up) {
|
||||||
|
context.up = testConnection(reader, pos, state, face, horizontal, vertical, 0, sv);
|
||||||
|
}
|
||||||
|
if (requirement.down) {
|
||||||
|
context.down = testConnection(reader, pos, state, face, horizontal, vertical, 0, -sv);
|
||||||
|
}
|
||||||
|
if (requirement.left) {
|
||||||
|
context.left = testConnection(reader, pos, state, face, horizontal, vertical, -sh, 0);
|
||||||
|
}
|
||||||
|
if (requirement.right) {
|
||||||
|
context.right = testConnection(reader, pos, state, face, horizontal, vertical, sh, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requirement.topLeft) {
|
||||||
|
context.topLeft =
|
||||||
|
context.up && context.left && testConnection(reader, pos, state, face, horizontal, vertical, -sh, sv);
|
||||||
|
}
|
||||||
|
if (requirement.topRight) {
|
||||||
|
context.topRight =
|
||||||
|
context.up && context.right && testConnection(reader, pos, state, face, horizontal, vertical, sh, sv);
|
||||||
|
}
|
||||||
|
if (requirement.bottomLeft) {
|
||||||
|
context.bottomLeft = context.down && context.left
|
||||||
|
&& testConnection(reader, pos, state, face, horizontal, vertical, -sh, -sv);
|
||||||
|
}
|
||||||
|
if (requirement.bottomRight) {
|
||||||
|
context.bottomRight = context.down && context.right
|
||||||
|
&& testConnection(reader, pos, state, face, horizontal, vertical, sh, -sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CTContext {
|
||||||
|
public static final CTContext EMPTY = new CTContext();
|
||||||
|
|
||||||
|
public boolean up, down, left, right;
|
||||||
|
public boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ContextRequirement {
|
||||||
|
public final boolean up, down, left, right;
|
||||||
|
public final boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||||
|
|
||||||
|
public ContextRequirement(boolean up, boolean down, boolean left, boolean right, boolean topLeft,
|
||||||
|
boolean topRight, boolean bottomLeft, boolean bottomRight) {
|
||||||
|
this.up = up;
|
||||||
|
this.down = down;
|
||||||
|
this.left = left;
|
||||||
|
this.right = right;
|
||||||
|
this.topLeft = topLeft;
|
||||||
|
this.topRight = topRight;
|
||||||
|
this.bottomLeft = bottomLeft;
|
||||||
|
this.bottomRight = bottomRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private boolean up, down, left, right;
|
||||||
|
private boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||||
|
|
||||||
|
public Builder up() {
|
||||||
|
up = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder down() {
|
||||||
|
down = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder left() {
|
||||||
|
left = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder right() {
|
||||||
|
right = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder topLeft() {
|
||||||
|
topLeft = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder topRight() {
|
||||||
|
topRight = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder bottomLeft() {
|
||||||
|
bottomLeft = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder bottomRight() {
|
||||||
|
bottomRight = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder horizontal() {
|
||||||
|
left();
|
||||||
|
right();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder vertical() {
|
||||||
|
up();
|
||||||
|
down();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder axisAligned() {
|
||||||
|
horizontal();
|
||||||
|
vertical();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder corners() {
|
||||||
|
topLeft();
|
||||||
|
topRight();
|
||||||
|
bottomLeft();
|
||||||
|
bottomRight();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder all() {
|
||||||
|
axisAligned();
|
||||||
|
corners();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContextRequirement build() {
|
||||||
|
return new ContextRequirement(up, down, left, right, topLeft, topRight, bottomLeft, bottomRight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Base extends ConnectedTextureBehaviour {
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction,
|
||||||
|
@Nullable TextureAtlasSprite sprite);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public CTType getDataType(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction direction) {
|
||||||
|
CTSpriteShiftEntry shift = getShift(state, direction, null);
|
||||||
|
if (shift == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return shift.getType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
|
|
||||||
public class SpriteShiftEntry {
|
|
||||||
protected StitchedSprite original;
|
|
||||||
protected StitchedSprite target;
|
|
||||||
|
|
||||||
public void set(ResourceLocation originalTextureLocation, ResourceLocation targetTextureLocation) {
|
|
||||||
original = new StitchedSprite(originalTextureLocation);
|
|
||||||
target = new StitchedSprite(targetTextureLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation getOriginalResourceLocation() {
|
|
||||||
return original.getLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation getTargetResourceLocation() {
|
|
||||||
return target.getLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextureAtlasSprite getOriginal() {
|
|
||||||
return original.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextureAtlasSprite getTarget() {
|
|
||||||
return target.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTargetU(float localU) {
|
|
||||||
return getTarget().getU(getUnInterpolatedU(getOriginal(), localU));
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTargetV(float localV) {
|
|
||||||
return getTarget().getV(getUnInterpolatedV(getOriginal(), localV));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getUnInterpolatedU(TextureAtlasSprite sprite, float u) {
|
|
||||||
float f = sprite.getU1() - sprite.getU0();
|
|
||||||
return (u - sprite.getU0()) / f * 16.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getUnInterpolatedV(TextureAtlasSprite sprite, float v) {
|
|
||||||
float f = sprite.getV1() - sprite.getV0();
|
|
||||||
return (v - sprite.getV0()) / f * 16.0F;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ package nl.requios.effortlessbuilding.create.foundation.gui;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||||
|
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
@@ -10,8 +12,8 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
|
|||||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreenList;
|
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreenList;
|
||||||
@@ -106,7 +108,7 @@ public abstract class AbstractSimiScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||||
partialTicks = minecraft.getFrameTime();
|
partialTicks = AnimationTickHolder.getPartialTicksUI();
|
||||||
PoseStack ms = graphics.pose();
|
PoseStack ms = graphics.pose();
|
||||||
|
|
||||||
ms.pushPose();
|
ms.pushPose();
|
||||||
@@ -114,8 +116,8 @@ public abstract class AbstractSimiScreen extends Screen {
|
|||||||
prepareFrame();
|
prepareFrame();
|
||||||
|
|
||||||
renderWindowBackground(graphics, mouseX, mouseY, partialTicks);
|
renderWindowBackground(graphics, mouseX, mouseY, partialTicks);
|
||||||
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
|
||||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
||||||
renderWindowForeground(graphics, mouseX, mouseY, partialTicks);
|
renderWindowForeground(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
endFrame();
|
endFrame();
|
||||||
@@ -123,6 +125,11 @@ public abstract class AbstractSimiScreen extends Screen {
|
|||||||
ms.popPose();
|
ms.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderBackground(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
|
// super.renderBackground(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
boolean keyPressed = super.keyPressed(keyCode, scanCode, modifiers);
|
boolean keyPressed = super.keyPressed(keyCode, scanCode, modifiers);
|
||||||
@@ -141,7 +148,7 @@ public abstract class AbstractSimiScreen extends Screen {
|
|||||||
protected void prepareFrame() {}
|
protected void prepareFrame() {}
|
||||||
|
|
||||||
protected void renderWindowBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
protected void renderWindowBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||||
renderBackground(graphics);
|
this.renderTransparentBackground(graphics); //Manually draw background
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks);
|
protected abstract void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks);
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.createmod.catnip.gui.UIRenderHelper;
|
||||||
|
import net.createmod.catnip.gui.element.ScreenElement;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
|
|
||||||
public enum AllGuiTextures implements ScreenElement {
|
public enum AllGuiTextures implements ScreenElement {
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ public enum AllGuiTextures implements ScreenElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
||||||
this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png");
|
this.location = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.startX = startX;
|
this.startX = startX;
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package nl.requios.effortlessbuilding.create.foundation.gui;
|
|||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.createmod.catnip.gui.element.DelegatedStencilElement;
|
||||||
|
import net.createmod.catnip.gui.element.ScreenElement;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
public class AllIcons implements ScreenElement {
|
public class AllIcons implements ScreenElement {
|
||||||
@@ -202,11 +202,10 @@ public class AllIcons implements ScreenElement {
|
|||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
||||||
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
builder.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||||
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||||
.uv(u, v)
|
.setUv(u, v)
|
||||||
.uv2(light)
|
.setLight(light);
|
||||||
.endVertex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|||||||
@@ -1,229 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import net.minecraft.network.chat.FormattedText;
|
|
||||||
import net.minecraft.network.chat.Style;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.BoxElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.TextStencilElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.BoxWidget;
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class ConfirmationScreen extends AbstractSimiScreen {
|
|
||||||
|
|
||||||
private Screen source;
|
|
||||||
private Consumer<Response> action = _success -> {
|
|
||||||
};
|
|
||||||
private List<FormattedText> text = new ArrayList<>();
|
|
||||||
private boolean centered = false;
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int textWidth;
|
|
||||||
private int textHeight;
|
|
||||||
private boolean tristate;
|
|
||||||
|
|
||||||
private BoxWidget confirm;
|
|
||||||
private BoxWidget confirmDontSave;
|
|
||||||
private BoxWidget cancel;
|
|
||||||
private BoxElement textBackground;
|
|
||||||
|
|
||||||
public enum Response {
|
|
||||||
Confirm, ConfirmDontSave, Cancel
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Removes text lines from the back of the list
|
|
||||||
* */
|
|
||||||
public ConfirmationScreen removeTextLines(int amount) {
|
|
||||||
if (amount > text.size())
|
|
||||||
return clearText();
|
|
||||||
|
|
||||||
text.subList(text.size() - amount, text.size()).clear();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen clearText() {
|
|
||||||
this.text.clear();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen addText(FormattedText text) {
|
|
||||||
this.text.add(text);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen withText(FormattedText text) {
|
|
||||||
return clearText().addText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen at(int x, int y) {
|
|
||||||
this.x = Math.max(x, 0);
|
|
||||||
this.y = Math.max(y, 0);
|
|
||||||
this.centered = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen centered() {
|
|
||||||
this.centered = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen withAction(Consumer<Boolean> action) {
|
|
||||||
this.action = r -> action.accept(r == Response.Confirm);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfirmationScreen withThreeActions(Consumer<Response> action) {
|
|
||||||
this.action = action;
|
|
||||||
this.tristate = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open(@Nonnull Screen source) {
|
|
||||||
this.source = source;
|
|
||||||
Minecraft client = source.getMinecraft();
|
|
||||||
this.init(client, client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight());
|
|
||||||
this.minecraft.screen = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
source.tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
ArrayList<FormattedText> copy = new ArrayList<>(text);
|
|
||||||
text.clear();
|
|
||||||
copy.forEach(t -> text.addAll(font.getSplitter().splitLines(t, 300, Style.EMPTY)));
|
|
||||||
|
|
||||||
textHeight = text.size() * (font.lineHeight + 1) + 4;
|
|
||||||
textWidth = 300;
|
|
||||||
|
|
||||||
if (centered) {
|
|
||||||
x = width/2 - textWidth/2 - 2;
|
|
||||||
y = height/2 - textHeight/2 - 16;
|
|
||||||
} else {
|
|
||||||
x = Math.max(0, x - textWidth / 2);
|
|
||||||
y = Math.max(0, y -= textHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x + textWidth > width) {
|
|
||||||
x = width - textWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y + textHeight + 30 > height) {
|
|
||||||
y = height - textHeight - 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
int buttonX = x + textWidth / 2 - 6 - (int) (70 * (tristate ? 1.5f : 1));
|
|
||||||
|
|
||||||
TextStencilElement confirmText =
|
|
||||||
new TextStencilElement(font, tristate ? "Save" : "Confirm").centered(true, true);
|
|
||||||
confirm = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.Confirm));
|
|
||||||
confirm.showingElement(confirmText.withElementRenderer(BoxWidget.gradientFactory.apply(confirm)));
|
|
||||||
addRenderableWidget(confirm);
|
|
||||||
|
|
||||||
buttonX += 12 + 70;
|
|
||||||
|
|
||||||
if (tristate) {
|
|
||||||
TextStencilElement confirmDontSaveText =
|
|
||||||
new TextStencilElement(font, "Don't Save").centered(true, true);
|
|
||||||
confirmDontSave =
|
|
||||||
new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.ConfirmDontSave));
|
|
||||||
confirmDontSave.showingElement(
|
|
||||||
confirmDontSaveText.withElementRenderer(BoxWidget.gradientFactory.apply(confirmDontSave)));
|
|
||||||
addRenderableWidget(confirmDontSave);
|
|
||||||
buttonX += 12 + 70;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextStencilElement cancelText = new TextStencilElement(font, "Cancel").centered(true, true);
|
|
||||||
cancel = new BoxWidget(buttonX, y + textHeight + 6, 70, 16)
|
|
||||||
.withCallback(() -> accept(Response.Cancel));
|
|
||||||
cancel.showingElement(cancelText.withElementRenderer(BoxWidget.gradientFactory.apply(cancel)));
|
|
||||||
addRenderableWidget(cancel);
|
|
||||||
|
|
||||||
textBackground = new BoxElement()
|
|
||||||
.gradientBorder(Theme.p(Theme.Key.BUTTON_DISABLE))
|
|
||||||
.withBounds(width + 10, textHeight + 35)
|
|
||||||
.at(-5, y - 5);
|
|
||||||
|
|
||||||
if (text.size() == 1)
|
|
||||||
x = (width - font.width(text.get(0))) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClose() {
|
|
||||||
accept(Response.Cancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void accept(Response success) {
|
|
||||||
minecraft.screen = source;
|
|
||||||
action.accept(success);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
textBackground.render(graphics);
|
|
||||||
int offset = font.lineHeight + 1;
|
|
||||||
int lineY = y - offset;
|
|
||||||
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(0, 0, 200);
|
|
||||||
|
|
||||||
for (FormattedText line : text) {
|
|
||||||
lineY += offset;
|
|
||||||
if (line == null)
|
|
||||||
continue;
|
|
||||||
graphics.drawString(font, line.getString(), x, lineY, 0xeaeaea, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWindowBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
endFrame();
|
|
||||||
|
|
||||||
source.render(graphics, 0, 0, 10); // zero mouse coords to prevent further tooltips
|
|
||||||
|
|
||||||
prepareFrame();
|
|
||||||
|
|
||||||
graphics.fillGradient(0, 0, this.width, this.height, 0x70101010, 0x80101010);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void prepareFrame() {
|
|
||||||
UIRenderHelper.swapAndBlitColor(minecraft.getMainRenderTarget(), UIRenderHelper.framebuffer);
|
|
||||||
RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void endFrame() {
|
|
||||||
UIRenderHelper.swapAndBlitColor(UIRenderHelper.framebuffer, minecraft.getMainRenderTarget());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resize(@Nonnull Minecraft client, int width, int height) {
|
|
||||||
super.resize(client, width, height);
|
|
||||||
source.resize(client, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPauseScreen() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.joml.Vector3f;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.math.Axis;
|
import com.mojang.math.Axis;
|
||||||
|
import net.createmod.catnip.gui.ILightingSettings;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public class CustomLightingSettings implements ILightingSettings {
|
public class CustomLightingSettings implements ILightingSettings {
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class CustomLightingSettings implements ILightingSettings {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyLighting() {
|
public void applyLighting() {
|
||||||
RenderSystem.setupLevelDiffuseLighting(light1, light2, lightMatrix);
|
RenderSystem.setShaderLights(light1, light2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.Lighting;
|
|
||||||
|
|
||||||
public interface ILightingSettings {
|
|
||||||
|
|
||||||
void applyLighting();
|
|
||||||
|
|
||||||
static final ILightingSettings DEFAULT_3D = () -> Lighting.setupFor3DItems();
|
|
||||||
static final ILightingSettings DEFAULT_FLAT = () -> Lighting.setupForFlatItems();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.Tesselator;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||||
@@ -18,10 +9,15 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
|||||||
import net.minecraft.network.chat.FormattedText;
|
import net.minecraft.network.chat.FormattedText;
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.neoforged.neoforge.client.ClientHooks;
|
||||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
import net.neoforged.neoforge.client.event.RenderTooltipEvent;
|
||||||
import net.minecraftforge.client.extensions.IForgeGuiGraphics;
|
import net.neoforged.neoforge.client.extensions.IGuiGraphicsExtension;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class RemovedGuiUtils {
|
public class RemovedGuiUtils {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -38,7 +34,7 @@ public class RemovedGuiUtils {
|
|||||||
public static void drawHoveringText(GuiGraphics graphics, List<? extends FormattedText> textLines, int mouseX,
|
public static void drawHoveringText(GuiGraphics graphics, List<? extends FormattedText> textLines, int mouseX,
|
||||||
int mouseY, int screenWidth, int screenHeight, int maxTextWidth, Font font) {
|
int mouseY, int screenWidth, int screenHeight, int maxTextWidth, Font font) {
|
||||||
drawHoveringText(graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
drawHoveringText(graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
||||||
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
||||||
font);
|
font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +49,7 @@ public class RemovedGuiUtils {
|
|||||||
List<? extends FormattedText> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight,
|
List<? extends FormattedText> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight,
|
||||||
int maxTextWidth, Font font) {
|
int maxTextWidth, Font font) {
|
||||||
drawHoveringText(stack, graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
drawHoveringText(stack, graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
||||||
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
||||||
font);
|
font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +59,11 @@ public class RemovedGuiUtils {
|
|||||||
if (textLines.isEmpty())
|
if (textLines.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(stack, textLines,
|
List<ClientTooltipComponent> list = ClientHooks.gatherTooltipComponents(stack, textLines,
|
||||||
stack.getTooltipImage(), mouseX, screenWidth, screenHeight, font);
|
stack.getTooltipImage(), mouseX, screenWidth, screenHeight, font);
|
||||||
RenderTooltipEvent.Pre event =
|
RenderTooltipEvent.Pre event =
|
||||||
new RenderTooltipEvent.Pre(stack, graphics, mouseX, mouseY, screenWidth, screenHeight, font, list, null);
|
new RenderTooltipEvent.Pre(stack, graphics, mouseX, mouseY, screenWidth, screenHeight, font, list, null);
|
||||||
if (MinecraftForge.EVENT_BUS.post(event))
|
if (NeoForge.EVENT_BUS.post(event).isCanceled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PoseStack pStack = graphics.pose();
|
PoseStack pStack = graphics.pose();
|
||||||
@@ -152,7 +148,7 @@ public class RemovedGuiUtils {
|
|||||||
final int zLevel = 400;
|
final int zLevel = 400;
|
||||||
RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, graphics, tooltipX, tooltipY,
|
RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, graphics, tooltipX, tooltipY,
|
||||||
font, backgroundColor, borderColorStart, borderColorEnd, list);
|
font, backgroundColor, borderColorStart, borderColorEnd, list);
|
||||||
MinecraftForge.EVENT_BUS.post(colorEvent);
|
NeoForge.EVENT_BUS.post(colorEvent);
|
||||||
backgroundColor = colorEvent.getBackgroundStart();
|
backgroundColor = colorEvent.getBackgroundStart();
|
||||||
borderColorStart = colorEvent.getBorderStart();
|
borderColorStart = colorEvent.getBorderStart();
|
||||||
borderColorEnd = colorEvent.getBorderEnd();
|
borderColorEnd = colorEvent.getBorderEnd();
|
||||||
@@ -179,8 +175,7 @@ public class RemovedGuiUtils {
|
|||||||
graphics.fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2,
|
graphics.fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2,
|
||||||
tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, zLevel, borderColorEnd, borderColorEnd);
|
tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, zLevel, borderColorEnd, borderColorEnd);
|
||||||
|
|
||||||
MultiBufferSource.BufferSource renderType = MultiBufferSource.immediate(Tesselator.getInstance()
|
MultiBufferSource.BufferSource renderType = graphics.bufferSource();
|
||||||
.getBuilder());
|
|
||||||
pStack.translate(0.0D, 0.0D, zLevel);
|
pStack.translate(0.0D, 0.0D, zLevel);
|
||||||
|
|
||||||
for (int lineNumber = 0; lineNumber < list.size(); ++lineNumber) {
|
for (int lineNumber = 0; lineNumber < list.size(); ++lineNumber) {
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
import net.createmod.catnip.data.Couple;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
import net.createmod.catnip.theme.Color;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Theme {
|
public class Theme {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
|
||||||
|
|
||||||
public interface TickableGuiEventListener extends GuiEventListener {
|
|
||||||
void tick();
|
|
||||||
}
|
|
||||||
@@ -1,327 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
|
||||||
import com.mojang.blaze3d.platform.GlConst;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.platform.Window;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.Tesselator;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
|
||||||
import com.mojang.math.Axis;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.lwjgl.opengl.GL20;
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
public class UIRenderHelper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An FBO that has a stencil buffer for use wherever stencil are necessary. Forcing the main FBO to have a stencil
|
|
||||||
* buffer will cause GL error spam when using fabulous graphics.
|
|
||||||
*/
|
|
||||||
public static CustomRenderTarget framebuffer;
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
RenderSystem.recordRenderCall(() -> {
|
|
||||||
Window mainWindow = Minecraft.getInstance().getWindow();
|
|
||||||
framebuffer = CustomRenderTarget.create(mainWindow);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateWindowSize(Window mainWindow) {
|
|
||||||
if (framebuffer != null)
|
|
||||||
framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void drawFramebuffer(float alpha) {
|
|
||||||
framebuffer.renderWithAlpha(alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switch from src to dst, after copying the contents of src to dst.
|
|
||||||
*/
|
|
||||||
public static void swapAndBlitColor(RenderTarget src, RenderTarget dst) {
|
|
||||||
GlStateManager._glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, src.frameBufferId);
|
|
||||||
GlStateManager._glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dst.frameBufferId);
|
|
||||||
GlStateManager._glBlitFrameBuffer(0, 0, src.viewWidth, src.viewHeight, 0, 0, dst.viewWidth, dst.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
|
|
||||||
|
|
||||||
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, dst.frameBufferId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length) {
|
|
||||||
streak(graphics, angle, x, y, breadth, length, Theme.i(Theme.Key.STREAK));
|
|
||||||
}
|
|
||||||
// angle in degrees; 0° -> fading to the right
|
|
||||||
// x and y specify the middle point of the starting edge
|
|
||||||
// breadth is the total width of the streak
|
|
||||||
|
|
||||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, int color) {
|
|
||||||
int a1 = 0xa0 << 24;
|
|
||||||
int a2 = 0x80 << 24;
|
|
||||||
int a3 = 0x10 << 24;
|
|
||||||
int a4 = 0x00 << 24;
|
|
||||||
|
|
||||||
color &= 0x00FFFFFF;
|
|
||||||
int c1 = a1 | color;
|
|
||||||
int c2 = a2 | color;
|
|
||||||
int c3 = a3 | color;
|
|
||||||
int c4 = a4 | color;
|
|
||||||
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(x, y, 0);
|
|
||||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
|
||||||
|
|
||||||
streak(graphics, breadth / 2, length, c1, c2, c3, c4);
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Color c) {
|
|
||||||
Color color = c.copy().setImmutable();
|
|
||||||
int c1 = color.scaleAlpha(0.625f).getRGB();
|
|
||||||
int c2 = color.scaleAlpha(0.5f).getRGB();
|
|
||||||
int c3 = color.scaleAlpha(0.0625f).getRGB();
|
|
||||||
int c4 = color.scaleAlpha(0f).getRGB();
|
|
||||||
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(x, y, 0);
|
|
||||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
|
||||||
|
|
||||||
streak(graphics, breadth / 2, length, c1, c2, c3, c4);
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void streak(GuiGraphics graphics, int width, int height, int c1, int c2, int c3, int c4) {
|
|
||||||
double split1 = .5;
|
|
||||||
double split2 = .75;
|
|
||||||
graphics.fillGradient(-width, 0, width, (int) (split1 * height), 0, c1, c2);
|
|
||||||
graphics.fillGradient(-width, (int) (split1 * height), width, (int) (split2 * height), 0, c2, c3);
|
|
||||||
graphics.fillGradient(-width, (int) (split2 * height), width, height, 0, c3, c4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
|
||||||
*/
|
|
||||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Couple<Color> c) {
|
|
||||||
angledGradient(graphics, angle, x, y, 0, breadth, length, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
|
||||||
*/
|
|
||||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int z, int breadth, int length, Couple<Color> c) {
|
|
||||||
angledGradient(graphics, angle, x, y, z, breadth, length, c.getFirst(), c.getSecond());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
|
||||||
*/
|
|
||||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Color color1, Color color2) {
|
|
||||||
angledGradient(graphics, angle, x, y, 0, breadth, length, color1, color2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* x and y specify the middle point of the starting edge
|
|
||||||
*
|
|
||||||
* @param angle the angle of the gradient in degrees; 0° means from left to right
|
|
||||||
* @param color1 the color at the starting edge
|
|
||||||
* @param color2 the color at the ending edge
|
|
||||||
* @param breadth the total width of the gradient
|
|
||||||
*/
|
|
||||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int z, int breadth, int length, Color color1, Color color2) {
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(x, y, z);
|
|
||||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
|
||||||
|
|
||||||
int w = breadth / 2;
|
|
||||||
graphics.fillGradient(-w, 0, w, length, 0, color1.getRGB(), color2.getRGB());
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void breadcrumbArrow(GuiGraphics graphics, int x, int y, int z, int width, int height, int indent, Couple<Color> colors) {breadcrumbArrow(graphics, x, y, z, width, height, indent, colors.getFirst(), colors.getSecond());}
|
|
||||||
|
|
||||||
// draws a wide chevron-style breadcrumb arrow pointing left
|
|
||||||
public static void breadcrumbArrow(GuiGraphics graphics, int x, int y, int z, int width, int height, int indent, Color startColor, Color endColor) {
|
|
||||||
PoseStack matrixStack = graphics.pose();
|
|
||||||
matrixStack.pushPose();
|
|
||||||
matrixStack.translate(x - indent, y, z);
|
|
||||||
|
|
||||||
breadcrumbArrow(graphics, width, height, indent, startColor, endColor);
|
|
||||||
|
|
||||||
matrixStack.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void breadcrumbArrow(GuiGraphics graphics, int width, int height, int indent, Color c1, Color c2) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 0,0 x1,y1 ********************* x4,y4 ***** x7,y7
|
|
||||||
* **** ****
|
|
||||||
* **** ****
|
|
||||||
* x0,y0 x2,y2 x5,y5
|
|
||||||
* **** ****
|
|
||||||
* **** ****
|
|
||||||
* x3,y3 ********************* x6,y6 ***** x8,y8
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
float x0 = 0, y0 = height / 2f;
|
|
||||||
float x1 = indent, y1 = 0;
|
|
||||||
float x2 = indent, y2 = height / 2f;
|
|
||||||
float x3 = indent, y3 = height;
|
|
||||||
float x4 = width, y4 = 0;
|
|
||||||
float x5 = width, y5 = height / 2f;
|
|
||||||
float x6 = width, y6 = height;
|
|
||||||
float x7 = indent + width, y7 = 0;
|
|
||||||
float x8 = indent + width, y8 = height;
|
|
||||||
|
|
||||||
indent = Math.abs(indent);
|
|
||||||
width = Math.abs(width);
|
|
||||||
Color fc1 = Color.mixColors(c1, c2, 0);
|
|
||||||
Color fc2 = Color.mixColors(c1, c2, (indent) / (width + 2f * indent));
|
|
||||||
Color fc3 = Color.mixColors(c1, c2, (indent + width) / (width + 2f * indent));
|
|
||||||
Color fc4 = Color.mixColors(c1, c2, 1);
|
|
||||||
|
|
||||||
// RenderSystem.disableTexture();
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.disableCull();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
|
||||||
|
|
||||||
Tesselator tessellator = Tesselator.getInstance();
|
|
||||||
BufferBuilder bufferbuilder = tessellator.getBuilder();
|
|
||||||
Matrix4f model = graphics.pose().last().pose();
|
|
||||||
bufferbuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR);
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x0, y0, 0).color(fc1.getRed(), fc1.getGreen(), fc1.getBlue(), fc1.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x1, y1, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x2, y2, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x0, y0, 0).color(fc1.getRed(), fc1.getGreen(), fc1.getBlue(), fc1.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x2, y2, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x1, y1, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x6, y6, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x5, y5, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x7, y7, 0).color(fc4.getRed(), fc4.getGreen(), fc4.getBlue(), fc4.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
bufferbuilder.vertex(model, x6, y6, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x5, y5, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
|
||||||
bufferbuilder.vertex(model, x8, y8, 0).color(fc4.getRed(), fc4.getGreen(), fc4.getBlue(), fc4.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
tessellator.end();
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
// RenderSystem.enableTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
//just like AbstractGui#drawTexture, but with a color at every vertex
|
|
||||||
public static void drawColoredTexture(GuiGraphics graphics, Color c, int x, int y, int tex_left, int tex_top, int width, int height) {
|
|
||||||
drawColoredTexture(graphics, c, x, y, 0, (float) tex_left, (float) tex_top, width, height, 256, 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void drawColoredTexture(GuiGraphics graphics, Color c, int x, int y, int z, float tex_left, float tex_top, int width, int height, int sheet_width, int sheet_height) {
|
|
||||||
drawColoredTexture(graphics, c, x, x + width, y, y + height, z, width, height, tex_left, tex_top, sheet_width, sheet_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void drawStretched(GuiGraphics graphics, int left, int top, int w, int h, int z, AllGuiTextures tex) {
|
|
||||||
tex.bind();
|
|
||||||
drawTexturedQuad(graphics.pose().last()
|
|
||||||
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + tex.width) / 256f,
|
|
||||||
tex.startY / 256f, (tex.startY + tex.height) / 256f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void drawCropped(GuiGraphics graphics, int left, int top, int w, int h, int z, AllGuiTextures tex) {
|
|
||||||
tex.bind();
|
|
||||||
drawTexturedQuad(graphics.pose().last()
|
|
||||||
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + w) / 256f,
|
|
||||||
tex.startY / 256f, (tex.startY + h) / 256f);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void drawColoredTexture(GuiGraphics graphics, Color c, int left, int right, int top, int bot, int z, int tex_width, int tex_height, float tex_left, float tex_top, int sheet_width, int sheet_height) {
|
|
||||||
drawTexturedQuad(graphics.pose().last().pose(), c, left, right, top, bot, z, (tex_left + 0.0F) / (float) sheet_width, (tex_left + (float) tex_width) / (float) sheet_width, (tex_top + 0.0F) / (float) sheet_height, (tex_top + (float) tex_height) / (float) sheet_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void drawTexturedQuad(Matrix4f m, Color c, int left, int right, int top, int bot, int z, float u1, float u2, float v1, float v2) {
|
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
|
||||||
BufferBuilder bufferbuilder = tesselator.getBuilder();
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
|
|
||||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
|
|
||||||
bufferbuilder.vertex(m, (float) left , (float) bot, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u1, v2).endVertex();
|
|
||||||
bufferbuilder.vertex(m, (float) right, (float) bot, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u2, v2).endVertex();
|
|
||||||
bufferbuilder.vertex(m, (float) right, (float) top, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u2, v1).endVertex();
|
|
||||||
bufferbuilder.vertex(m, (float) left , (float) top, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u1, v1).endVertex();
|
|
||||||
tesselator.end();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void flipForGuiRender(PoseStack poseStack) {
|
|
||||||
poseStack.mulPoseMatrix(new Matrix4f().scaling(1, -1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CustomRenderTarget extends RenderTarget {
|
|
||||||
|
|
||||||
public CustomRenderTarget(boolean useDepth) {
|
|
||||||
super(useDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CustomRenderTarget create(Window mainWindow) {
|
|
||||||
CustomRenderTarget framebuffer = new CustomRenderTarget(true);
|
|
||||||
framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
|
|
||||||
framebuffer.setClearColor(0, 0, 0, 0);
|
|
||||||
framebuffer.enableStencil();
|
|
||||||
return framebuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderWithAlpha(float alpha) {
|
|
||||||
Window window = Minecraft.getInstance().getWindow();
|
|
||||||
|
|
||||||
float vx = (float) window.getGuiScaledWidth();
|
|
||||||
float vy = (float) window.getGuiScaledHeight();
|
|
||||||
float tx = (float) viewWidth / (float) width;
|
|
||||||
float ty = (float) viewHeight / (float) height;
|
|
||||||
|
|
||||||
// RenderSystem.enableTexture();
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
RenderSystem.setShader(() -> Minecraft.getInstance().gameRenderer.blitShader);
|
|
||||||
RenderSystem.getShader().setSampler("DiffuseSampler", colorTextureId);
|
|
||||||
|
|
||||||
bindRead();
|
|
||||||
|
|
||||||
Tesselator tessellator = Tesselator.getInstance();
|
|
||||||
BufferBuilder bufferbuilder = tessellator.getBuilder();
|
|
||||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
|
|
||||||
|
|
||||||
bufferbuilder.vertex(0, vy, 0).color(1, 1, 1, alpha).uv(0, 0).endVertex();
|
|
||||||
bufferbuilder.vertex(vx, vy, 0).color(1, 1, 1, alpha).uv(tx, 0).endVertex();
|
|
||||||
bufferbuilder.vertex(vx, 0, 0).color(1, 1, 1, alpha).uv(tx, ty).endVertex();
|
|
||||||
bufferbuilder.vertex(0, 0, 0).color(1, 1, 1, alpha).uv(0, ty).endVertex();
|
|
||||||
|
|
||||||
tessellator.end();
|
|
||||||
unbindRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||||
|
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
@@ -13,10 +15,8 @@ import net.minecraft.client.renderer.Rect2i;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
@@ -93,9 +93,7 @@ public abstract class AbstractSimiContainerScreen<T extends AbstractContainerMen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||||
partialTicks = minecraft.getFrameTime();
|
partialTicks = AnimationTickHolder.getPartialTicksUI();
|
||||||
|
|
||||||
renderBackground(graphics);
|
|
||||||
|
|
||||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraftforge.network.NetworkEvent.Context;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.networking.SimplePacketBase;
|
|
||||||
|
|
||||||
public class ClearMenuPacket extends SimplePacketBase {
|
|
||||||
|
|
||||||
public ClearMenuPacket() {}
|
|
||||||
|
|
||||||
public ClearMenuPacket(FriendlyByteBuf buffer) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(FriendlyByteBuf buffer) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(Context context) {
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
ServerPlayer player = context.getSender();
|
|
||||||
if (player == null)
|
|
||||||
return;
|
|
||||||
if (!(player.containerMenu instanceof IClearableMenu))
|
|
||||||
return;
|
|
||||||
((IClearableMenu) player.containerMenu).clearContents();
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,8 +7,7 @@ import net.minecraft.world.inventory.ClickType;
|
|||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
|
||||||
|
|
||||||
public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearableMenu {
|
public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearableMenu {
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearable
|
|||||||
ItemStack stackToInsert = playerInventory.getItem(index);
|
ItemStack stackToInsert = playerInventory.getItem(index);
|
||||||
for (int i = 0; i < ghostInventory.getSlots(); i++) {
|
for (int i = 0; i < ghostInventory.getSlots(); i++) {
|
||||||
ItemStack stack = ghostInventory.getStackInSlot(i);
|
ItemStack stack = ghostInventory.getStackInSlot(i);
|
||||||
if (!allowRepeats() && ItemHandlerHelper.canItemStacksStack(stack, stackToInsert))
|
if (!allowRepeats() && ItemStack.isSameItemSameComponents(stack, stackToInsert))
|
||||||
break;
|
break;
|
||||||
if (stack.isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
ItemStack copy = stackToInsert.copy();
|
ItemStack copy = stackToInsert.copy();
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraftforge.network.NetworkEvent.Context;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.networking.SimplePacketBase;
|
|
||||||
|
|
||||||
public class GhostItemSubmitPacket extends SimplePacketBase {
|
|
||||||
|
|
||||||
private final ItemStack item;
|
|
||||||
private final int slot;
|
|
||||||
|
|
||||||
public GhostItemSubmitPacket(ItemStack item, int slot) {
|
|
||||||
this.item = item;
|
|
||||||
this.slot = slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GhostItemSubmitPacket(FriendlyByteBuf buffer) {
|
|
||||||
item = buffer.readItem();
|
|
||||||
slot = buffer.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(FriendlyByteBuf buffer) {
|
|
||||||
buffer.writeItem(item);
|
|
||||||
buffer.writeInt(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(Context context) {
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
ServerPlayer player = context.getSender();
|
|
||||||
if (player == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (player.containerMenu instanceof GhostItemMenu<?> menu) {
|
|
||||||
menu.ghostInventory.setStackInSlot(slot, item);
|
|
||||||
menu.getSlot(36 + slot).setChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
|||||||
public interface IClearableMenu {
|
public interface IClearableMenu {
|
||||||
|
|
||||||
default void sendClearPacket() {
|
default void sendClearPacket() {
|
||||||
// PacketHandler.INSTANCE.sendToServer(new ClearMenuPacket());
|
// PacketDistributor.SERVER.noArg().send(new ClearMenuPacket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearContents();
|
public void clearContents();
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.IInteractionChecker;
|
import nl.requios.effortlessbuilding.create.foundation.utility.IInteractionChecker;
|
||||||
|
|
||||||
public abstract class MenuBase<T> extends AbstractContainerMenu {
|
public abstract class MenuBase<T> extends AbstractContainerMenu {
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.Tesselator;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
|
|
||||||
public class BoxElement extends RenderElement {
|
|
||||||
|
|
||||||
protected Color background = new Color(0xff000000, true);
|
|
||||||
protected Color borderTop = new Color(0x40ffeedd, true);
|
|
||||||
protected Color borderBot = new Color(0x20ffeedd, true);
|
|
||||||
protected int borderOffset = 2;
|
|
||||||
|
|
||||||
public <T extends BoxElement> T withBackground(Color color) {
|
|
||||||
this.background = color;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T withBackground(int color) {
|
|
||||||
return withBackground(new Color(color, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T flatBorder(Color color) {
|
|
||||||
this.borderTop = color;
|
|
||||||
this.borderBot = color;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T flatBorder(int color) {
|
|
||||||
return flatBorder(new Color(color, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T gradientBorder(Couple<Color> colors) {
|
|
||||||
this.borderTop = colors.getFirst();
|
|
||||||
this.borderBot = colors.getSecond();
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T gradientBorder(Color top, Color bot) {
|
|
||||||
this.borderTop = top;
|
|
||||||
this.borderBot = bot;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T gradientBorder(int top, int bot) {
|
|
||||||
return gradientBorder(new Color(top, true), new Color(bot, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxElement> T withBorderOffset(int offset) {
|
|
||||||
this.borderOffset = offset;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
renderBox(graphics.pose());
|
|
||||||
}
|
|
||||||
|
|
||||||
//total box width = 1 * 2 (outer border) + 1 * 2 (inner color border) + 2 * borderOffset + width
|
|
||||||
//defaults to 2 + 2 + 4 + 16 = 24px
|
|
||||||
//batch everything together to save a bunch of gl calls over ScreenUtils
|
|
||||||
protected void renderBox(PoseStack ms) {
|
|
||||||
/*
|
|
||||||
* _____________
|
|
||||||
* _|_____________|_
|
|
||||||
* | | ___________ | |
|
|
||||||
* | | | | | | |
|
|
||||||
* | | | | | | |
|
|
||||||
* | | |--* | | | |
|
|
||||||
* | | | h | | |
|
|
||||||
* | | | --w-+ | | |
|
|
||||||
* | | | | | |
|
|
||||||
* | | |_________| | |
|
|
||||||
* |_|_____________|_|
|
|
||||||
* |_____________|
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
// RenderSystem.disableTexture();
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
|
||||||
|
|
||||||
Matrix4f model = ms.last().pose();
|
|
||||||
int f = borderOffset;
|
|
||||||
Color c1 = background.copy().scaleAlpha(alpha);
|
|
||||||
Color c2 = borderTop.copy().scaleAlpha(alpha);
|
|
||||||
Color c3 = borderBot.copy().scaleAlpha(alpha);
|
|
||||||
Tesselator tessellator = Tesselator.getInstance();
|
|
||||||
BufferBuilder b = tessellator.getBuilder();
|
|
||||||
|
|
||||||
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
|
||||||
//outer top
|
|
||||||
b.vertex(model, x - f - 1 , y - f - 2 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f - 2 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
//outer left
|
|
||||||
b.vertex(model, x - f - 2 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 2 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
//outer bottom
|
|
||||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
//outer right
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 2 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 2 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
//inner background - also render behind the inner edges
|
|
||||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
|
||||||
tessellator.end();
|
|
||||||
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
|
||||||
//inner top - includes corners
|
|
||||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
//inner left - excludes corners
|
|
||||||
b.vertex(model, x - f - 1 , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
//inner bottom - includes corners
|
|
||||||
b.vertex(model, x - f - 1 , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
//inner right - excludes corners
|
|
||||||
b.vertex(model, x + f + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
|
||||||
b.vertex(model, x + f + 1 + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
|
||||||
|
|
||||||
tessellator.end();
|
|
||||||
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
// RenderSystem.enableTexture();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
|
|
||||||
public class CombinedStencilElement extends StencilElement {
|
|
||||||
|
|
||||||
private StencilElement element1;
|
|
||||||
private StencilElement element2;
|
|
||||||
private ElementMode mode;
|
|
||||||
|
|
||||||
private CombinedStencilElement() {}
|
|
||||||
|
|
||||||
public static CombinedStencilElement of(@Nonnull StencilElement element1, @Nonnull StencilElement element2) {
|
|
||||||
return of(element1, element2, ElementMode.FIRST);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CombinedStencilElement of(@Nonnull StencilElement element1, @Nonnull StencilElement element2, ElementMode mode) {
|
|
||||||
CombinedStencilElement e = new CombinedStencilElement();
|
|
||||||
e.element1 = element1;
|
|
||||||
e.element2 = element2;
|
|
||||||
e.mode = mode;
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends CombinedStencilElement> T withFirst(StencilElement element) {
|
|
||||||
this.element1 = element;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends CombinedStencilElement> T withSecond(StencilElement element) {
|
|
||||||
this.element2 = element;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends CombinedStencilElement> T withMode(ElementMode mode) {
|
|
||||||
this.mode = mode;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderStencil(GuiGraphics graphics) {
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
element1.transform(ms);
|
|
||||||
element1.withBounds(width, height);
|
|
||||||
element1.renderStencil(graphics);
|
|
||||||
ms.popPose();
|
|
||||||
ms.pushPose();
|
|
||||||
element2.transform(ms);
|
|
||||||
element2.withBounds(width, height);
|
|
||||||
element2.renderStencil(graphics);
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderElement(GuiGraphics graphics) {
|
|
||||||
if (mode.rendersFirst())
|
|
||||||
element1.<StencilElement>withBounds(width, height).renderElement(graphics);
|
|
||||||
|
|
||||||
if (mode.rendersSecond())
|
|
||||||
element2.<StencilElement>withBounds(width, height).renderElement(graphics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ElementMode {
|
|
||||||
FIRST, SECOND, BOTH;
|
|
||||||
|
|
||||||
boolean rendersFirst() {
|
|
||||||
return this == FIRST || this == BOTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean rendersSecond() {
|
|
||||||
return this == SECOND || this == BOTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
|
|
||||||
public class DelegatedStencilElement extends StencilElement {
|
|
||||||
|
|
||||||
protected static final ElementRenderer EMPTY_RENDERER = (graphics, width, height, alpha) -> {};
|
|
||||||
protected static final ElementRenderer DEFAULT_ELEMENT = (graphics, width, height, alpha) -> UIRenderHelper.angledGradient(graphics, 0, -3, 5, height+4, width+6, new Color(0xff_10dd10).scaleAlpha(alpha), new Color(0xff_1010dd).scaleAlpha(alpha));
|
|
||||||
|
|
||||||
protected ElementRenderer stencil;
|
|
||||||
protected ElementRenderer element;
|
|
||||||
|
|
||||||
public DelegatedStencilElement() {
|
|
||||||
stencil = EMPTY_RENDERER;
|
|
||||||
element = DEFAULT_ELEMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DelegatedStencilElement(ElementRenderer stencil, ElementRenderer element) {
|
|
||||||
this.stencil = stencil;
|
|
||||||
this.element = element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends DelegatedStencilElement> T withStencilRenderer(ElementRenderer renderer) {
|
|
||||||
stencil = renderer;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends DelegatedStencilElement> T withElementRenderer(ElementRenderer renderer) {
|
|
||||||
element = renderer;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderStencil(GuiGraphics graphics) {
|
|
||||||
stencil.render(graphics, width, height, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderElement(GuiGraphics graphics) {
|
|
||||||
element.render(graphics, width, height, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface ElementRenderer {
|
|
||||||
void render(GuiGraphics graphics, int width, int height, float alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,301 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.PartialModel;
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.platform.Lighting;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Axis;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.Sheets;
|
|
||||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
|
||||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.util.RandomSource;
|
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.ItemLike;
|
|
||||||
import net.minecraft.world.level.block.BaseFireBlock;
|
|
||||||
import net.minecraft.world.level.block.Blocks;
|
|
||||||
import net.minecraft.world.level.block.LiquidBlock;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.level.material.Fluid;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.client.RenderTypeHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.ILightingSettings;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.VecHelper;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class GuiGameElement {
|
|
||||||
|
|
||||||
public static GuiRenderBuilder of(ItemStack stack) {
|
|
||||||
return new GuiItemRenderBuilder(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiRenderBuilder of(ItemLike itemProvider) {
|
|
||||||
return new GuiItemRenderBuilder(itemProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiRenderBuilder of(BlockState state) {
|
|
||||||
return new GuiBlockStateRenderBuilder(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiRenderBuilder of(PartialModel partial) {
|
|
||||||
return new GuiBlockPartialRenderBuilder(partial);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiRenderBuilder of(Fluid fluid) {
|
|
||||||
return new GuiBlockStateRenderBuilder(fluid.defaultFluidState()
|
|
||||||
.createLegacyBlock()
|
|
||||||
.setValue(LiquidBlock.LEVEL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class GuiRenderBuilder extends RenderElement {
|
|
||||||
protected double xLocal, yLocal, zLocal;
|
|
||||||
protected double xRot, yRot, zRot;
|
|
||||||
protected double scale = 1;
|
|
||||||
protected int color = 0xFFFFFF;
|
|
||||||
protected Vec3 rotationOffset = Vec3.ZERO;
|
|
||||||
protected ILightingSettings customLighting = null;
|
|
||||||
|
|
||||||
public GuiRenderBuilder atLocal(double x, double y, double z) {
|
|
||||||
this.xLocal = x;
|
|
||||||
this.yLocal = y;
|
|
||||||
this.zLocal = z;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder rotate(double xRot, double yRot, double zRot) {
|
|
||||||
this.xRot = xRot;
|
|
||||||
this.yRot = yRot;
|
|
||||||
this.zRot = zRot;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder rotateBlock(double xRot, double yRot, double zRot) {
|
|
||||||
return this.rotate(xRot, yRot, zRot)
|
|
||||||
.withRotationOffset(VecHelper.getCenterOf(BlockPos.ZERO));
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder scale(double scale) {
|
|
||||||
this.scale = scale;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder color(int color) {
|
|
||||||
this.color = color;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder withRotationOffset(Vec3 offset) {
|
|
||||||
this.rotationOffset = offset;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiRenderBuilder lighting(ILightingSettings lighting) {
|
|
||||||
customLighting = lighting;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void prepareMatrix(PoseStack matrixStack) {
|
|
||||||
matrixStack.pushPose();
|
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
|
||||||
prepareLighting(matrixStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void transformMatrix(PoseStack matrixStack) {
|
|
||||||
matrixStack.translate(x, y, z);
|
|
||||||
matrixStack.scale((float) scale, (float) scale, (float) scale);
|
|
||||||
matrixStack.translate(xLocal, yLocal, zLocal);
|
|
||||||
UIRenderHelper.flipForGuiRender(matrixStack);
|
|
||||||
matrixStack.translate(rotationOffset.x, rotationOffset.y, rotationOffset.z);
|
|
||||||
matrixStack.mulPose(Axis.ZP.rotationDegrees((float) zRot));
|
|
||||||
matrixStack.mulPose(Axis.XP.rotationDegrees((float) xRot));
|
|
||||||
matrixStack.mulPose(Axis.YP.rotationDegrees((float) yRot));
|
|
||||||
matrixStack.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanUpMatrix(PoseStack matrixStack) {
|
|
||||||
matrixStack.popPose();
|
|
||||||
cleanUpLighting(matrixStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void prepareLighting(PoseStack matrixStack) {
|
|
||||||
if (customLighting != null) {
|
|
||||||
customLighting.applyLighting();
|
|
||||||
} else {
|
|
||||||
Lighting.setupFor3DItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanUpLighting(PoseStack matrixStack) {
|
|
||||||
if (customLighting != null) {
|
|
||||||
Lighting.setupFor3DItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class GuiBlockModelRenderBuilder extends GuiRenderBuilder {
|
|
||||||
|
|
||||||
protected BakedModel blockModel;
|
|
||||||
protected BlockState blockState;
|
|
||||||
|
|
||||||
public GuiBlockModelRenderBuilder(BakedModel blockmodel, @Nullable BlockState blockState) {
|
|
||||||
this.blockState = blockState == null ? Blocks.AIR.defaultBlockState() : blockState;
|
|
||||||
this.blockModel = blockmodel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
PoseStack matrixStack = graphics.pose();
|
|
||||||
prepareMatrix(matrixStack);
|
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
BlockRenderDispatcher blockRenderer = mc.getBlockRenderer();
|
|
||||||
MultiBufferSource.BufferSource buffer = mc.renderBuffers()
|
|
||||||
.bufferSource();
|
|
||||||
|
|
||||||
transformMatrix(matrixStack);
|
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
|
|
||||||
renderModel(blockRenderer, buffer, matrixStack);
|
|
||||||
|
|
||||||
cleanUpMatrix(matrixStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void renderModel(BlockRenderDispatcher blockRenderer, MultiBufferSource.BufferSource buffer,
|
|
||||||
PoseStack ms) {
|
|
||||||
if (blockState.getBlock() == Blocks.AIR) {
|
|
||||||
RenderType renderType = Sheets.translucentCullBlockSheet();
|
|
||||||
blockRenderer.getModelRenderer()
|
|
||||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel, 1, 1, 1,
|
|
||||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, null);
|
|
||||||
} else {
|
|
||||||
int color = Minecraft.getInstance()
|
|
||||||
.getBlockColors()
|
|
||||||
.getColor(blockState, null, null, 0);
|
|
||||||
Color rgb = new Color(color == -1 ? this.color : color);
|
|
||||||
|
|
||||||
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), ModelUtil.VIRTUAL_DATA)) {
|
|
||||||
RenderType renderType = RenderTypeHelper.getEntityRenderType(chunkType, true);
|
|
||||||
blockRenderer.getModelRenderer()
|
|
||||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel,
|
|
||||||
rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(),
|
|
||||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, chunkType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.endBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GuiBlockStateRenderBuilder extends GuiBlockModelRenderBuilder {
|
|
||||||
|
|
||||||
public GuiBlockStateRenderBuilder(BlockState blockstate) {
|
|
||||||
super(Minecraft.getInstance()
|
|
||||||
.getBlockRenderer()
|
|
||||||
.getBlockModel(blockstate), blockstate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderModel(BlockRenderDispatcher blockRenderer, MultiBufferSource.BufferSource buffer,
|
|
||||||
PoseStack ms) {
|
|
||||||
if (blockState.getBlock() instanceof BaseFireBlock) {
|
|
||||||
Lighting.setupForFlatItems();
|
|
||||||
super.renderModel(blockRenderer, buffer, ms);
|
|
||||||
Lighting.setupFor3DItems();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.renderModel(blockRenderer, buffer, ms);
|
|
||||||
|
|
||||||
if (blockState.getFluidState()
|
|
||||||
.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// FluidRenderer.renderFluidBox(new FluidStack(blockState.getFluidState()
|
|
||||||
// .getType(), 1000), 0, 0, 0, 1, 1, 1, buffer, ms, LightTexture.FULL_BRIGHT, false);
|
|
||||||
// buffer.endBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GuiBlockPartialRenderBuilder extends GuiBlockModelRenderBuilder {
|
|
||||||
|
|
||||||
public GuiBlockPartialRenderBuilder(PartialModel partial) {
|
|
||||||
super(partial.get(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class GuiItemRenderBuilder extends GuiRenderBuilder {
|
|
||||||
|
|
||||||
private final ItemStack stack;
|
|
||||||
|
|
||||||
public GuiItemRenderBuilder(ItemStack stack) {
|
|
||||||
this.stack = stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiItemRenderBuilder(ItemLike provider) {
|
|
||||||
this(new ItemStack(provider));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
PoseStack matrixStack = graphics.pose();
|
|
||||||
prepareMatrix(matrixStack);
|
|
||||||
transformMatrix(matrixStack);
|
|
||||||
renderItemIntoGUI(matrixStack, stack, customLighting == null);
|
|
||||||
cleanUpMatrix(matrixStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderItemIntoGUI(PoseStack matrixStack, ItemStack stack, boolean useDefaultLighting) {
|
|
||||||
ItemRenderer renderer = Minecraft.getInstance().getItemRenderer();
|
|
||||||
BakedModel bakedModel = renderer.getModel(stack, null, null, 0);
|
|
||||||
|
|
||||||
renderer.textureManager.getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
|
|
||||||
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
|
||||||
matrixStack.pushPose();
|
|
||||||
matrixStack.translate(0, 0, 100.0F);
|
|
||||||
matrixStack.translate(8.0F, -8.0F, 0.0F);
|
|
||||||
matrixStack.scale(16.0F, 16.0F, 16.0F);
|
|
||||||
MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();
|
|
||||||
boolean flatLighting = !bakedModel.usesBlockLight();
|
|
||||||
if (useDefaultLighting && flatLighting) {
|
|
||||||
Lighting.setupForFlatItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.render(stack, ItemDisplayContext.GUI, false, matrixStack, buffer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
|
|
||||||
RenderSystem.disableDepthTest();
|
|
||||||
buffer.endBatch();
|
|
||||||
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
if (useDefaultLighting && flatLighting) {
|
|
||||||
Lighting.setupFor3DItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
matrixStack.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
|
|
||||||
public abstract class RenderElement implements ScreenElement {
|
|
||||||
|
|
||||||
public static final RenderElement EMPTY = new RenderElement() {
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static RenderElement of(ScreenElement renderable) {
|
|
||||||
return new SimpleRenderElement(renderable);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int width = 16, height = 16;
|
|
||||||
protected float x = 0, y = 0, z = 0;
|
|
||||||
protected float alpha = 1f;
|
|
||||||
|
|
||||||
public <T extends RenderElement> T at(float x, float y) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends RenderElement> T at(float x, float y, float z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends RenderElement> T withBounds(int width, int height) {
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends RenderElement> T withAlpha(float alpha) {
|
|
||||||
this.alpha = alpha;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void render(GuiGraphics graphics);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics, int x, int y) {
|
|
||||||
this.at(x, y).render(graphics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SimpleRenderElement extends RenderElement {
|
|
||||||
|
|
||||||
private ScreenElement renderable;
|
|
||||||
|
|
||||||
public SimpleRenderElement(ScreenElement renderable) {
|
|
||||||
this.renderable = renderable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
renderable.render(graphics, (int) x, (int) y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
|
|
||||||
public interface ScreenElement {
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
void render(GuiGraphics graphics, int x, int y);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
|
|
||||||
public abstract class StencilElement extends RenderElement {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(GuiGraphics graphics) {
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
transform(ms);
|
|
||||||
prepareStencil(ms);
|
|
||||||
renderStencil(graphics);
|
|
||||||
prepareElement(ms);
|
|
||||||
renderElement(graphics);
|
|
||||||
cleanUp(ms);
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void renderStencil(GuiGraphics graphics);
|
|
||||||
|
|
||||||
protected abstract void renderElement(GuiGraphics graphics);
|
|
||||||
|
|
||||||
protected void transform(PoseStack ms) {
|
|
||||||
ms.translate(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void prepareStencil(PoseStack ms) {
|
|
||||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
|
||||||
RenderSystem.stencilMask(~0);
|
|
||||||
RenderSystem.clear(GL11.GL_STENCIL_BUFFER_BIT, Minecraft.ON_OSX);
|
|
||||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
|
||||||
RenderSystem.stencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP);
|
|
||||||
RenderSystem.stencilMask(0xFF);
|
|
||||||
RenderSystem.stencilFunc(GL11.GL_NEVER, 1, 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void prepareElement(PoseStack ms) {
|
|
||||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
|
||||||
RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
|
|
||||||
RenderSystem.stencilFunc(GL11.GL_EQUAL, 1, 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanUp(PoseStack ms) {
|
|
||||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.gui.Font;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
|
||||||
|
|
||||||
public class TextStencilElement extends DelegatedStencilElement {
|
|
||||||
|
|
||||||
protected Font font;
|
|
||||||
protected MutableComponent component;
|
|
||||||
protected boolean centerVertically = false;
|
|
||||||
protected boolean centerHorizontally = false;
|
|
||||||
|
|
||||||
public TextStencilElement(Font font) {
|
|
||||||
super();
|
|
||||||
this.font = font;
|
|
||||||
height = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextStencilElement(Font font, String text) {
|
|
||||||
this(font);
|
|
||||||
component = Components.literal(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextStencilElement(Font font, MutableComponent component) {
|
|
||||||
this(font);
|
|
||||||
this.component = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextStencilElement withText(String text) {
|
|
||||||
component = Components.literal(text);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextStencilElement withText(MutableComponent component) {
|
|
||||||
this.component = component;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextStencilElement centered(boolean vertical, boolean horizontal) {
|
|
||||||
this.centerVertically = vertical;
|
|
||||||
this.centerHorizontally = horizontal;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderStencil(GuiGraphics graphics) {
|
|
||||||
float x = 0, y = 0;
|
|
||||||
if (centerHorizontally)
|
|
||||||
x = width / 2f - font.width(component) / 2f;
|
|
||||||
|
|
||||||
if (centerVertically)
|
|
||||||
y = height / 2f - (font.lineHeight - 1) / 2f;
|
|
||||||
|
|
||||||
graphics.drawString(font, component, Math.round(x), Math.round(y), 0xff_000000, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderElement(GuiGraphics graphics) {
|
|
||||||
float x = 0, y = 0;
|
|
||||||
if (centerHorizontally)
|
|
||||||
x = width / 2f - font.width(component) / 2f;
|
|
||||||
|
|
||||||
if (centerVertically)
|
|
||||||
y = height / 2f - (font.lineHeight - 1) / 2f;
|
|
||||||
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(x, y, 0);
|
|
||||||
element.render(graphics, font.width(component), font.lineHeight + 2, alpha);
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MutableComponent getComponent() {
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||||
|
|
||||||
|
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -39,10 +37,10 @@ public abstract class AbstractSimiWidget extends AbstractWidget implements Ticka
|
|||||||
super(x, y, width, height, message);
|
super(x, y, width, height, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
protected ClientTooltipPositioner createTooltipPositioner() {
|
// protected ClientTooltipPositioner createTooltipPositioner() {
|
||||||
return DefaultTooltipPositioner.INSTANCE;
|
// return DefaultTooltipPositioner.INSTANCE;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public <T extends AbstractSimiWidget> T withCallback(BiConsumer<Integer, Integer> cb) {
|
public <T extends AbstractSimiWidget> T withCallback(BiConsumer<Integer, Integer> cb) {
|
||||||
this.onClick = cb;
|
this.onClick = cb;
|
||||||
|
|||||||
@@ -1,226 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.Theme;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.BoxElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.animation.LerpedFloat;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class BoxWidget extends ElementWidget {
|
|
||||||
|
|
||||||
public static final Function<BoxWidget, DelegatedStencilElement.ElementRenderer> gradientFactory = (box) -> (ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, w/2, -2, w + 4, h + 4, box.gradientColor1, box.gradientColor2);
|
|
||||||
|
|
||||||
protected BoxElement box;
|
|
||||||
|
|
||||||
protected Color customBorderTop;
|
|
||||||
protected Color customBorderBot;
|
|
||||||
protected Color customBackground;
|
|
||||||
protected boolean animateColors = true;
|
|
||||||
protected LerpedFloat colorAnimation = LerpedFloat.linear();
|
|
||||||
|
|
||||||
protected Color gradientColor1, gradientColor2;
|
|
||||||
private Color previousColor1, previousColor2;
|
|
||||||
private Color colorTarget1 = Theme.c(getIdleTheme(), true).copy();
|
|
||||||
private Color colorTarget2 = Theme.c(getIdleTheme(), false).copy();
|
|
||||||
|
|
||||||
public BoxWidget() {
|
|
||||||
this(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoxWidget(int x, int y) {
|
|
||||||
this(x, y, 16, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoxWidget(int x, int y, int width, int height) {
|
|
||||||
super(x, y, width, height);
|
|
||||||
box = new BoxElement()
|
|
||||||
.at(x, y)
|
|
||||||
.withBounds(width, height);
|
|
||||||
gradientColor1 = colorTarget1;
|
|
||||||
gradientColor2 = colorTarget2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxWidget> T withBounds(int width, int height) {
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxWidget> T withBorderColors(Couple<Color> colors) {
|
|
||||||
this.customBorderTop = colors.getFirst();
|
|
||||||
this.customBorderBot = colors.getSecond();
|
|
||||||
updateColorsFromState();
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxWidget> T withBorderColors(Color top, Color bot) {
|
|
||||||
this.customBorderTop = top;
|
|
||||||
this.customBorderBot = bot;
|
|
||||||
updateColorsFromState();
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxWidget> T withCustomBackground(Color color) {
|
|
||||||
this.customBackground = color;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends BoxWidget> T animateColors(boolean b) {
|
|
||||||
this.animateColors = b;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
colorAnimation.tickChaser();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(double x, double y) {
|
|
||||||
super.onClick(x, y);
|
|
||||||
|
|
||||||
gradientColor1 = Theme.c(getClickTheme(), true);
|
|
||||||
gradientColor2 = Theme.c(getClickTheme(), false);
|
|
||||||
startGradientAnimation(getColorForState(true), getColorForState(false), true, 0.15);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void beforeRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
super.beforeRender(graphics, mouseX, mouseY, partialTicks);
|
|
||||||
|
|
||||||
if (isHovered != wasHovered) {
|
|
||||||
startGradientAnimation(
|
|
||||||
getColorForState(true),
|
|
||||||
getColorForState(false),
|
|
||||||
isHovered
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colorAnimation.settled()) {
|
|
||||||
gradientColor1 = colorTarget1;
|
|
||||||
gradientColor2 = colorTarget2;
|
|
||||||
} else {
|
|
||||||
float animationValue = 1 - Math.abs(colorAnimation.getValue(partialTicks));
|
|
||||||
gradientColor1 = Color.mixColors(previousColor1, colorTarget1, animationValue);
|
|
||||||
gradientColor2 = Color.mixColors(previousColor2, colorTarget2, animationValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
float fadeValue = fade.getValue(partialTicks);
|
|
||||||
if (fadeValue < .1f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
box.withAlpha(fadeValue);
|
|
||||||
box.withBackground(customBackground != null ? customBackground : Theme.c(Theme.Key.PONDER_BACKGROUND_TRANSPARENT))
|
|
||||||
.gradientBorder(gradientColor1, gradientColor2)
|
|
||||||
.at(getX(), getY(), z)
|
|
||||||
.withBounds(width, height)
|
|
||||||
.render(graphics);
|
|
||||||
|
|
||||||
super.doRender(graphics, mouseX, mouseY, partialTicks);
|
|
||||||
|
|
||||||
wasHovered = isHovered;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMouseOver(double mX, double mY) {
|
|
||||||
if (!active || !visible)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
float padX = 2 + paddingX;
|
|
||||||
float padY = 2 + paddingY;
|
|
||||||
|
|
||||||
return getX() - padX <= mX && getY() - padY <= mY && mX < getX() + padX + width && mY < getY() + padY + height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean clicked(double pMouseX, double pMouseY) {
|
|
||||||
if (!active || !visible)
|
|
||||||
return false;
|
|
||||||
return isMouseOver(pMouseX, pMouseY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoxElement getBox() {
|
|
||||||
return box;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateColorsFromState() {
|
|
||||||
colorTarget1 = getColorForState(true);
|
|
||||||
colorTarget2 = getColorForState(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void animateGradientFromState() {
|
|
||||||
startGradientAnimation(
|
|
||||||
getColorForState(true),
|
|
||||||
getColorForState(false),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startGradientAnimation(Color c1, Color c2, boolean positive, double expSpeed) {
|
|
||||||
if (!animateColors)
|
|
||||||
return;
|
|
||||||
|
|
||||||
colorAnimation.startWithValue(positive ? 1 : -1);
|
|
||||||
colorAnimation.chase(0, expSpeed, LerpedFloat.Chaser.EXP);
|
|
||||||
colorAnimation.tickChaser();
|
|
||||||
|
|
||||||
previousColor1 = gradientColor1;
|
|
||||||
previousColor2 = gradientColor2;
|
|
||||||
|
|
||||||
colorTarget1 = c1;
|
|
||||||
colorTarget2 = c2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startGradientAnimation(Color c1, Color c2, boolean positive) {
|
|
||||||
startGradientAnimation(c1, c2, positive, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color getColorForState(boolean first) {
|
|
||||||
if (!active)
|
|
||||||
return Theme.p(getDisabledTheme()).get(first);
|
|
||||||
|
|
||||||
if (isHovered) {
|
|
||||||
if (first)
|
|
||||||
return customBorderTop != null ? customBorderTop.darker() : Theme.c(getHoverTheme(), true);
|
|
||||||
else
|
|
||||||
return customBorderBot != null ? customBorderBot.darker() : Theme.c(getHoverTheme(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first)
|
|
||||||
return customBorderTop != null ? customBorderTop : Theme.c(getIdleTheme(), true);
|
|
||||||
else
|
|
||||||
return customBorderBot != null ? customBorderBot : Theme.c(getIdleTheme(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Theme.Key getDisabledTheme() {
|
|
||||||
return Theme.Key.BUTTON_DISABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Theme.Key getIdleTheme() {
|
|
||||||
return Theme.Key.BUTTON_IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Theme.Key getHoverTheme() {
|
|
||||||
return Theme.Key.BUTTON_HOVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Theme.Key getClickTheme() {
|
|
||||||
return Theme.Key.BUTTON_CLICK;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.RenderElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.animation.LerpedFloat;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
|
|
||||||
public class ElementWidget extends AbstractSimiWidget {
|
|
||||||
|
|
||||||
protected RenderElement element = RenderElement.EMPTY;
|
|
||||||
|
|
||||||
protected boolean usesFade = false;
|
|
||||||
protected int fadeModX;
|
|
||||||
protected int fadeModY;
|
|
||||||
protected LerpedFloat fade = LerpedFloat.linear().startWithValue(1);
|
|
||||||
|
|
||||||
protected boolean rescaleElement = false;
|
|
||||||
protected float rescaleSizeX;
|
|
||||||
protected float rescaleSizeY;
|
|
||||||
|
|
||||||
protected float paddingX = 0;
|
|
||||||
protected float paddingY = 0;
|
|
||||||
|
|
||||||
public ElementWidget(int x, int y) {
|
|
||||||
super(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElementWidget(int x, int y, int width, int height) {
|
|
||||||
super(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T showingElement(RenderElement element) {
|
|
||||||
this.element = element;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T showing(ScreenElement renderable) {
|
|
||||||
return this.showingElement(RenderElement.of(renderable));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T modifyElement(Consumer<RenderElement> consumer) {
|
|
||||||
if (element != null)
|
|
||||||
consumer.accept(element);
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T mapElement(UnaryOperator<RenderElement> function) {
|
|
||||||
if (element != null)
|
|
||||||
element = function.apply(element);
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T withPadding(float paddingX, float paddingY) {
|
|
||||||
this.paddingX = paddingX;
|
|
||||||
this.paddingY = paddingY;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T enableFade(int fadeModifierX, int fadeModifierY) {
|
|
||||||
this.fade.startWithValue(0);
|
|
||||||
this.usesFade = true;
|
|
||||||
this.fadeModX = fadeModifierX;
|
|
||||||
this.fadeModY = fadeModifierY;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T disableFade() {
|
|
||||||
this.fade.startWithValue(1);
|
|
||||||
this.usesFade = false;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LerpedFloat fade() {
|
|
||||||
return fade;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T fade(float target) {
|
|
||||||
fade.chase(target, 0.1, LerpedFloat.Chaser.EXP);
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rescaling and its effects aren't properly tested with most elements.
|
|
||||||
* Thought it should work fine when using a TextStencilElement.
|
|
||||||
* Check BaseConfigScreen's title for such an example.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public <T extends ElementWidget> T rescaleElement(float rescaleSizeX, float rescaleSizeY) {
|
|
||||||
this.rescaleElement = true;
|
|
||||||
this.rescaleSizeX = rescaleSizeX;
|
|
||||||
this.rescaleSizeY = rescaleSizeY;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends ElementWidget> T disableRescale() {
|
|
||||||
this.rescaleElement = false;
|
|
||||||
//noinspection unchecked
|
|
||||||
return (T) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
fade.tickChaser();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void beforeRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
super.beforeRender(graphics, mouseX, mouseY, partialTicks);
|
|
||||||
isHovered = isMouseOver(mouseX, mouseY);
|
|
||||||
|
|
||||||
float fadeValue = fade.getValue(partialTicks);
|
|
||||||
element.withAlpha(fadeValue);
|
|
||||||
if (fadeValue < 1) {
|
|
||||||
graphics.pose().translate((1 - fadeValue) * fadeModX, (1 - fadeValue) * fadeModY, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
PoseStack ms = graphics.pose();
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(getX() + paddingX, getY() + paddingY, z);
|
|
||||||
float innerWidth = width - 2 * paddingX;
|
|
||||||
float innerHeight = height - 2 * paddingY;
|
|
||||||
float eX = element.getX(), eY = element.getY();
|
|
||||||
if (rescaleElement) {
|
|
||||||
float xScale = innerWidth / rescaleSizeX;
|
|
||||||
float yScale = innerHeight / rescaleSizeY;
|
|
||||||
ms.scale(xScale, yScale, 1);
|
|
||||||
element.at(eX / xScale, eY / yScale);
|
|
||||||
innerWidth /= xScale;
|
|
||||||
innerHeight /= yScale;
|
|
||||||
}
|
|
||||||
element.withBounds((int) innerWidth, (int) innerHeight).render(graphics);
|
|
||||||
ms.popPose();
|
|
||||||
if (rescaleElement) {
|
|
||||||
element.at(eX, eY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderElement getRenderElement() {
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.createmod.catnip.gui.element.ScreenElement;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
|
||||||
|
|
||||||
public class IconButton extends AbstractSimiWidget {
|
public class IconButton extends AbstractSimiWidget {
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Indicator extends AbstractSimiWidget {
|
public class Indicator extends AbstractSimiWidget {
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ public class Indicator extends AbstractSimiWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks ) {
|
public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||||
if (!visible)
|
if (!visible)
|
||||||
return;
|
return;
|
||||||
AllGuiTextures toDraw;
|
AllGuiTextures toDraw;
|
||||||
|
|||||||
@@ -117,21 +117,21 @@ public class ScrollInput extends AbstractSimiWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||||
if (!this.visible || !this.isHovered) return false; //Added
|
if (!this.visible || !this.isHovered) return false; //Added
|
||||||
|
|
||||||
if (inverted)
|
if (inverted)
|
||||||
delta *= -1;
|
scrollX *= -1;
|
||||||
|
|
||||||
StepContext context = new StepContext();
|
StepContext context = new StepContext();
|
||||||
context.control = AllKeys.ctrlDown();
|
context.control = AllKeys.ctrlDown();
|
||||||
context.shift = AllKeys.shiftDown();
|
context.shift = AllKeys.shiftDown();
|
||||||
context.currentValue = state;
|
context.currentValue = state;
|
||||||
context.forward = delta > 0;
|
context.forward = scrollX > 0;
|
||||||
|
|
||||||
int priorState = state;
|
int priorState = state;
|
||||||
boolean shifted = AllKeys.shiftDown();
|
boolean shifted = AllKeys.shiftDown();
|
||||||
int step = (int) Math.signum(delta) * this.step.apply(context);
|
int step = (int) Math.signum(scrollX) * this.step.apply(context);
|
||||||
|
|
||||||
state += step;
|
state += step;
|
||||||
if (shifted)
|
if (shifted)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TooltipArea extends AbstractSimiWidget {
|
public class TooltipArea extends AbstractSimiWidget {
|
||||||
|
|
||||||
public TooltipArea(int x, int y, int width, int height) {
|
public TooltipArea(int x, int y, int width, int height) {
|
||||||
|
|||||||
@@ -11,7 +11,20 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.ChatFormatting.*;
|
import static net.minecraft.ChatFormatting.AQUA;
|
||||||
|
import static net.minecraft.ChatFormatting.BLUE;
|
||||||
|
import static net.minecraft.ChatFormatting.DARK_GRAY;
|
||||||
|
import static net.minecraft.ChatFormatting.DARK_GREEN;
|
||||||
|
import static net.minecraft.ChatFormatting.DARK_PURPLE;
|
||||||
|
import static net.minecraft.ChatFormatting.DARK_RED;
|
||||||
|
import static net.minecraft.ChatFormatting.GOLD;
|
||||||
|
import static net.minecraft.ChatFormatting.GRAY;
|
||||||
|
import static net.minecraft.ChatFormatting.GREEN;
|
||||||
|
import static net.minecraft.ChatFormatting.LIGHT_PURPLE;
|
||||||
|
import static net.minecraft.ChatFormatting.RED;
|
||||||
|
import static net.minecraft.ChatFormatting.STRIKETHROUGH;
|
||||||
|
import static net.minecraft.ChatFormatting.WHITE;
|
||||||
|
import static net.minecraft.ChatFormatting.YELLOW;
|
||||||
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutStringTextComponent;
|
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutStringTextComponent;
|
||||||
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutTextComponent;
|
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutTextComponent;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
import net.neoforged.neoforge.items.IItemHandlerModifiable;
|
||||||
|
|
||||||
public class ItemHandlerWrapper implements IItemHandlerModifiable {
|
public class ItemHandlerWrapper implements IItemHandlerModifiable {
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Pair;
|
import net.createmod.catnip.data.Pair;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.Containers;
|
import net.minecraft.world.Containers;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -40,9 +40,9 @@ public class ItemHelper {
|
|||||||
|
|
||||||
public static void addToList(ItemStack stack, List<ItemStack> stacks) {
|
public static void addToList(ItemStack stack, List<ItemStack> stacks) {
|
||||||
for (ItemStack s : stacks) {
|
for (ItemStack s : stacks) {
|
||||||
if (!ItemHandlerHelper.canItemStacksStack(stack, s))
|
if (!ItemStack.isSameItemSameComponents(stack, s))
|
||||||
continue;
|
continue;
|
||||||
int transferred = Math.min(s.getMaxStackSize() - s.getCount(), stack.getCount());
|
int transferred = Math.min(s.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) - s.getCount(), stack.getCount());
|
||||||
s.grow(transferred);
|
s.grow(transferred);
|
||||||
stack.shrink(transferred);
|
stack.shrink(transferred);
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ public class ItemHelper {
|
|||||||
|
|
||||||
if (!extracting.isEmpty() && !hasEnoughItems && potentialOtherMatch) {
|
if (!extracting.isEmpty() && !hasEnoughItems && potentialOtherMatch) {
|
||||||
ItemStack blackListed = extracting.copy();
|
ItemStack blackListed = extracting.copy();
|
||||||
test = test.and(i -> !ItemHandlerHelper.canItemStacksStack(i, blackListed));
|
test = test.and(i -> !ItemStack.isSameItemSameComponents(i, blackListed));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ public class ItemHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canItemStackAmountsStack(ItemStack a, ItemStack b) {
|
public static boolean canItemStackAmountsStack(ItemStack a, ItemStack b) {
|
||||||
return ItemHandlerHelper.canItemStacksStack(a, b) && a.getCount() + b.getCount() <= a.getMaxStackSize();
|
return ItemStack.isSameItemSameComponents(a, b) && a.getCount() + b.getCount() <= a.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||||
|
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
import net.minecraftforge.registries.tags.ITagManager;
|
|
||||||
|
|
||||||
public class TagDependentIngredientItem extends Item {
|
public class TagDependentIngredientItem extends Item {
|
||||||
|
|
||||||
@@ -15,8 +14,7 @@ public class TagDependentIngredientItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldHide() {
|
public boolean shouldHide() {
|
||||||
ITagManager<Item> tagManager = ForgeRegistries.ITEMS.tags();
|
return BuiltInRegistries.ITEM.getTag(tag).isEmpty() || BuiltInRegistries.ITEM.getTag(tag).get().size() == 0;
|
||||||
return !tagManager.isKnownTagName(tag) || tagManager.getTag(tag).isEmpty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import net.createmod.catnip.data.Couple;
|
||||||
|
import net.createmod.catnip.lang.ClientFontHelper;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
@@ -12,8 +14,6 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription.Palette;
|
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription.Palette;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.FontHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Lang;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Lang;
|
||||||
|
|
||||||
import java.text.BreakIterator;
|
import java.text.BreakIterator;
|
||||||
@@ -81,7 +81,7 @@ public class TooltipHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Font font = Minecraft.getInstance().font;
|
Font font = Minecraft.getInstance().font;
|
||||||
List<String> lines = FontHelper.cutString(font, markedUp, maxWidthPerLine);
|
List<String> lines = ClientFontHelper.cutString(font, markedUp, maxWidthPerLine);
|
||||||
|
|
||||||
// Format
|
// Format
|
||||||
String lineStart = Strings.repeat(" ", indent);
|
String lineStart = Strings.repeat(" ", indent);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.create.foundation.item.render;
|
|||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
import net.minecraft.client.resources.model.BakedModel;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraftforge.client.model.BakedModelWrapper;
|
import net.neoforged.neoforge.client.model.BakedModelWrapper;
|
||||||
|
|
||||||
public class CustomRenderedItemModel extends BakedModelWrapper<BakedModel> {
|
public class CustomRenderedItemModel extends BakedModelWrapper<BakedModel> {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package nl.requios.effortlessbuilding.create.foundation.item.render;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.createmod.catnip.data.Iterate;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
@@ -11,10 +12,9 @@ import net.minecraft.core.Direction;
|
|||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.item.ItemDisplayContext;
|
import net.minecraft.world.item.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
||||||
import net.minecraftforge.client.model.data.ModelData;
|
import net.neoforged.neoforge.client.model.data.ModelData;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Iterate;
|
|
||||||
|
|
||||||
public class PartialItemModelRenderer {
|
public class PartialItemModelRenderer {
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.networking;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraftforge.network.NetworkEvent.Context;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public interface ISyncPersistentData {
|
|
||||||
|
|
||||||
void onPersistentDataUpdated();
|
|
||||||
|
|
||||||
public static class PersistentDataPacket extends SimplePacketBase {
|
|
||||||
|
|
||||||
private int entityId;
|
|
||||||
private Entity entity;
|
|
||||||
private CompoundTag readData;
|
|
||||||
|
|
||||||
public PersistentDataPacket(Entity entity) {
|
|
||||||
this.entity = entity;
|
|
||||||
this.entityId = entity.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistentDataPacket(FriendlyByteBuf buffer) {
|
|
||||||
entityId = buffer.readInt();
|
|
||||||
readData = buffer.readNbt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(FriendlyByteBuf buffer) {
|
|
||||||
buffer.writeInt(entityId);
|
|
||||||
buffer.writeNbt(entity.getPersistentData());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(Context context) {
|
|
||||||
context.enqueueWork(() -> {
|
|
||||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
|
||||||
CompoundTag data = entityByID.getPersistentData();
|
|
||||||
new HashSet<>(data.getAllKeys()).forEach(data::remove);
|
|
||||||
data.merge(readData);
|
|
||||||
if (!(entityByID instanceof ISyncPersistentData))
|
|
||||||
return;
|
|
||||||
((ISyncPersistentData) entityByID).onPersistentDataUpdated();
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.networking;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraftforge.network.NetworkEvent.Context;
|
|
||||||
|
|
||||||
public abstract class SimplePacketBase {
|
|
||||||
|
|
||||||
public abstract void write(FriendlyByteBuf buffer);
|
|
||||||
|
|
||||||
public abstract boolean handle(Context context);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
|
|
||||||
public class BakedModelRenderHelper {
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardBlockRender(BlockState renderedState) {
|
|
||||||
BlockRenderDispatcher dispatcher = Minecraft.getInstance()
|
|
||||||
.getBlockRenderer();
|
|
||||||
return standardModelRender(dispatcher.getBlockModel(renderedState), renderedState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState) {
|
|
||||||
return standardModelRender(model, referenceState, new PoseStack());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState, PoseStack ms) {
|
|
||||||
ShadeSeparatedBufferedData data = ModelUtil.getBufferedData(model, referenceState, ms);
|
|
||||||
SuperByteBuffer sbb = new SuperByteBuffer(data);
|
|
||||||
data.release();
|
|
||||||
return sbb;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import dev.engine_room.flywheel.api.visualization.VisualizationManager;
|
||||||
|
import dev.engine_room.flywheel.lib.transform.TransformStack;
|
||||||
|
import dev.engine_room.flywheel.lib.visualization.VisualizationHelper;
|
||||||
|
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||||
|
import net.createmod.catnip.registry.RegisteredObjectsHelper;
|
||||||
|
import net.createmod.catnip.render.SuperByteBuffer;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.LevelRenderer;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||||
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
|
import nl.requios.effortlessbuilding.create.foundation.virtualWorld.VirtualRenderWorld;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Vector4f;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class BlockEntityRenderHelper {
|
||||||
|
|
||||||
|
public static void renderBlockEntities(Level world, Iterable<BlockEntity> customRenderBEs, PoseStack ms,
|
||||||
|
MultiBufferSource buffer) {
|
||||||
|
renderBlockEntities(world, null, customRenderBEs, ms, null, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderBlockEntities(Level world, Iterable<BlockEntity> customRenderBEs, PoseStack ms,
|
||||||
|
MultiBufferSource buffer, float pt) {
|
||||||
|
renderBlockEntities(world, null, customRenderBEs, ms, null, buffer, pt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderBlockEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||||
|
Iterable<BlockEntity> customRenderBEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer) {
|
||||||
|
renderBlockEntities(world, renderWorld, customRenderBEs, ms, lightTransform, buffer,
|
||||||
|
AnimationTickHolder.getPartialTicks());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderBlockEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||||
|
Iterable<BlockEntity> customRenderBEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer,
|
||||||
|
float pt) {
|
||||||
|
Iterator<BlockEntity> iterator = customRenderBEs.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
BlockEntity blockEntity = iterator.next();
|
||||||
|
if (VisualizationManager.supportsVisualization(world) && VisualizationHelper.skipVanillaRender(blockEntity))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(blockEntity);
|
||||||
|
if (renderer == null) {
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockPos pos = blockEntity.getBlockPos();
|
||||||
|
ms.pushPose();
|
||||||
|
TransformStack.of(ms)
|
||||||
|
.translate(pos);
|
||||||
|
|
||||||
|
try {
|
||||||
|
int worldLight = getCombinedLight(world, getLightPos(lightTransform, pos), renderWorld, pos);
|
||||||
|
|
||||||
|
if (renderWorld != null) {
|
||||||
|
// Swap the real world for the render world so that the renderer gets contraption-local information
|
||||||
|
blockEntity.setLevel(renderWorld);
|
||||||
|
renderer.render(blockEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||||
|
blockEntity.setLevel(world);
|
||||||
|
} else {
|
||||||
|
renderer.render(blockEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
iterator.remove();
|
||||||
|
|
||||||
|
String message = "BlockEntity " + RegisteredObjectsHelper.getKeyOrThrow(blockEntity.getType())
|
||||||
|
.toString() + " could not be rendered virtually.";
|
||||||
|
// if (AllConfigs.CLIENT.explainRenderErrors.get())
|
||||||
|
Create.LOGGER.error(message, e);
|
||||||
|
// else
|
||||||
|
// Create.LOGGER.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
ms.popPose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockPos getLightPos(@Nullable Matrix4f lightTransform, BlockPos contraptionPos) {
|
||||||
|
if (lightTransform != null) {
|
||||||
|
Vector4f lightVec = new Vector4f(contraptionPos.getX() + .5f, contraptionPos.getY() + .5f, contraptionPos.getZ() + .5f, 1);
|
||||||
|
lightVec.mul(lightTransform);
|
||||||
|
return BlockPos.containing(lightVec.x(), lightVec.y(), lightVec.z());
|
||||||
|
} else {
|
||||||
|
return contraptionPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCombinedLight(Level world, BlockPos worldPos, @Nullable VirtualRenderWorld renderWorld,
|
||||||
|
BlockPos renderWorldPos) {
|
||||||
|
int worldLight = LevelRenderer.getLightColor(world, worldPos);
|
||||||
|
|
||||||
|
if (renderWorld != null) {
|
||||||
|
int renderWorldLight = LevelRenderer.getLightColor(renderWorld, renderWorldPos);
|
||||||
|
return SuperByteBuffer.maxLight(worldLight, renderWorldLight);
|
||||||
|
}
|
||||||
|
|
||||||
|
return worldLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.PartialModel;
|
|
||||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache.Compartment;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.AngleHelper;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING;
|
|
||||||
|
|
||||||
public class CachedBufferer {
|
|
||||||
|
|
||||||
public static final Compartment<BlockState> GENERIC_TILE = new Compartment<>();
|
|
||||||
public static final Compartment<PartialModel> PARTIAL = new Compartment<>();
|
|
||||||
public static final Compartment<Pair<Direction, PartialModel>> DIRECTIONAL_PARTIAL = new Compartment<>();
|
|
||||||
|
|
||||||
public static SuperByteBuffer block(BlockState toRender) {
|
|
||||||
return block(GENERIC_TILE, toRender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer block(Compartment<BlockState> compartment, BlockState toRender) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(compartment, toRender, () -> BakedModelRenderHelper.standardBlockRender(toRender));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState,
|
|
||||||
Supplier<PoseStack> modelTransform) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState) {
|
|
||||||
Direction facing = referenceState.getValue(FACING);
|
|
||||||
return partialFacing(partial, referenceState, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState, Direction facing) {
|
|
||||||
return partialDirectional(partial, referenceState, facing,
|
|
||||||
rotateToFace(facing));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacingVertical(PartialModel partial, BlockState referenceState, Direction facing) {
|
|
||||||
return partialDirectional(partial, referenceState, facing,
|
|
||||||
rotateToFaceVertical(facing));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialDirectional(PartialModel partial, BlockState referenceState, Direction dir,
|
|
||||||
Supplier<PoseStack> modelTransform) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial),
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Supplier<PoseStack> rotateToFace(Direction facing) {
|
|
||||||
return () -> {
|
|
||||||
PoseStack stack = new PoseStack();
|
|
||||||
TransformStack.cast(stack)
|
|
||||||
.centre()
|
|
||||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
||||||
.rotateX(AngleHelper.verticalAngle(facing))
|
|
||||||
.unCentre();
|
|
||||||
return stack;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Supplier<PoseStack> rotateToFaceVertical(Direction facing) {
|
|
||||||
return () -> {
|
|
||||||
PoseStack stack = new PoseStack();
|
|
||||||
TransformStack.cast(stack)
|
|
||||||
.centre()
|
|
||||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
||||||
.rotateX(AngleHelper.verticalAngle(facing) + 90)
|
|
||||||
.unCentre();
|
|
||||||
return stack;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public final class ForcedDiffuseState {
|
|
||||||
private static final ThreadLocal<ObjectArrayList<DiffuseLightCalculator>> FORCED_DIFFUSE = ThreadLocal.withInitial(ObjectArrayList::new);
|
|
||||||
|
|
||||||
private ForcedDiffuseState() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void pushCalculator(DiffuseLightCalculator calculator) {
|
|
||||||
FORCED_DIFFUSE.get().push(calculator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void popCalculator() {
|
|
||||||
FORCED_DIFFUSE.get().pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static DiffuseLightCalculator getForcedCalculator() {
|
|
||||||
ObjectArrayList<DiffuseLightCalculator> stack = FORCED_DIFFUSE.get();
|
|
||||||
if (stack.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return stack.top();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,12 @@ package nl.requios.effortlessbuilding.create.foundation.render;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
|
||||||
import net.minecraft.client.renderer.RenderStateShard;
|
import net.minecraft.client.renderer.RenderStateShard;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
|
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
||||||
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
|
|
||||||
// TODO 1.17: use custom shaders instead of vanilla ones
|
// TODO 1.17: use custom shaders instead of vanilla ones
|
||||||
public class RenderTypes extends RenderStateShard {
|
public class RenderTypes extends RenderStateShard {
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Taken from EntityRendererManager
|
|
||||||
*/
|
|
||||||
public class ShadowRenderHelper {
|
|
||||||
|
|
||||||
private static final RenderType SHADOW_LAYER =
|
|
||||||
RenderType.entityNoOutline(new ResourceLocation("textures/misc/shadow.png"));
|
|
||||||
|
|
||||||
public static void renderShadow(PoseStack matrixStack, MultiBufferSource buffer, float opacity, float radius) {
|
|
||||||
PoseStack.Pose entry = matrixStack.last();
|
|
||||||
VertexConsumer builder = buffer.getBuffer(SHADOW_LAYER);
|
|
||||||
|
|
||||||
opacity /= 2;
|
|
||||||
shadowVertex(entry, builder, opacity, -1 * radius, 0, -1 * radius, 0, 0);
|
|
||||||
shadowVertex(entry, builder, opacity, -1 * radius, 0, 1 * radius, 0, 1);
|
|
||||||
shadowVertex(entry, builder, opacity, 1 * radius, 0, 1 * radius, 1, 1);
|
|
||||||
shadowVertex(entry, builder, opacity, 1 * radius, 0, -1 * radius, 1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderShadow(PoseStack matrixStack, MultiBufferSource buffer, LevelReader world,
|
|
||||||
Vec3 pos, float opacity, float radius) {
|
|
||||||
float f = radius;
|
|
||||||
|
|
||||||
double d2 = pos.x();
|
|
||||||
double d0 = pos.y();
|
|
||||||
double d1 = pos.z();
|
|
||||||
int i = Mth.floor(d2 - (double) f);
|
|
||||||
int j = Mth.floor(d2 + (double) f);
|
|
||||||
int k = Mth.floor(d0 - (double) f);
|
|
||||||
int l = Mth.floor(d0);
|
|
||||||
int i1 = Mth.floor(d1 - (double) f);
|
|
||||||
int j1 = Mth.floor(d1 + (double) f);
|
|
||||||
PoseStack.Pose entry = matrixStack.last();
|
|
||||||
VertexConsumer builder = buffer.getBuffer(SHADOW_LAYER);
|
|
||||||
|
|
||||||
for (BlockPos blockpos : BlockPos.betweenClosed(new BlockPos(i, k, i1), new BlockPos(j, l, j1))) {
|
|
||||||
renderBlockShadow(entry, builder, world, blockpos, d2, d0, d1, f,
|
|
||||||
opacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderBlockShadow(PoseStack.Pose entry, VertexConsumer builder,
|
|
||||||
LevelReader world, BlockPos pos, double x, double y, double z,
|
|
||||||
float radius, float opacity) {
|
|
||||||
BlockPos blockpos = pos.below();
|
|
||||||
BlockState blockstate = world.getBlockState(blockpos);
|
|
||||||
if (blockstate.getRenderShape() != RenderShape.INVISIBLE && world.getMaxLocalRawBrightness(pos) > 3) {
|
|
||||||
if (blockstate.isCollisionShapeFullBlock(world, blockpos)) {
|
|
||||||
VoxelShape voxelshape = blockstate.getShape(world, pos.below());
|
|
||||||
if (!voxelshape.isEmpty()) {
|
|
||||||
float brightness = LightTexture.getBrightness(world.dimensionType(), world.getMaxLocalRawBrightness(pos));
|
|
||||||
float f = (float) ((opacity - (y - pos.getY()) / 2.0D) * 0.5D * brightness);
|
|
||||||
if (f >= 0.0F) {
|
|
||||||
if (f > 1.0F) {
|
|
||||||
f = 1.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
AABB AABB = voxelshape.bounds();
|
|
||||||
double d0 = (double) pos.getX() + AABB.minX;
|
|
||||||
double d1 = (double) pos.getX() + AABB.maxX;
|
|
||||||
double d2 = (double) pos.getY() + AABB.minY;
|
|
||||||
double d3 = (double) pos.getZ() + AABB.minZ;
|
|
||||||
double d4 = (double) pos.getZ() + AABB.maxZ;
|
|
||||||
float f1 = (float) (d0 - x);
|
|
||||||
float f2 = (float) (d1 - x);
|
|
||||||
float f3 = (float) (d2 - y + 0.015625D);
|
|
||||||
float f4 = (float) (d3 - z);
|
|
||||||
float f5 = (float) (d4 - z);
|
|
||||||
float f6 = -f1 / 2.0F / radius + 0.5F;
|
|
||||||
float f7 = -f2 / 2.0F / radius + 0.5F;
|
|
||||||
float f8 = -f4 / 2.0F / radius + 0.5F;
|
|
||||||
float f9 = -f5 / 2.0F / radius + 0.5F;
|
|
||||||
shadowVertex(entry, builder, f, f1, f3, f4, f6, f8);
|
|
||||||
shadowVertex(entry, builder, f, f1, f3, f5, f6, f9);
|
|
||||||
shadowVertex(entry, builder, f, f2, f3, f5, f7, f9);
|
|
||||||
shadowVertex(entry, builder, f, f2, f3, f4, f7, f8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void shadowVertex(PoseStack.Pose entry, VertexConsumer builder, float alpha,
|
|
||||||
float x, float y, float z, float u, float v) {
|
|
||||||
builder.vertex(entry.pose(), x, y, z)
|
|
||||||
.color(1.0F, 1.0F, 1.0F, alpha)
|
|
||||||
.uv(u, v)
|
|
||||||
.overlayCoords(OverlayTexture.NO_OVERLAY)
|
|
||||||
.uv2(LightTexture.FULL_BRIGHT)
|
|
||||||
.normal(entry.normal(), 0.0F, 1.0F, 0.0F)
|
|
||||||
.endVertex();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,492 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
|
||||||
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
|
|
||||||
import com.jozufozu.flywheel.util.Color;
|
|
||||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
|
||||||
import com.jozufozu.flywheel.util.transform.TStack;
|
|
||||||
import com.jozufozu.flywheel.util.transform.Transform;
|
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2IntMap;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.block.render.SpriteShiftEntry;
|
|
||||||
import org.joml.Matrix3f;
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.joml.Quaternionf;
|
|
||||||
import org.joml.Vector3f;
|
|
||||||
import org.joml.Vector4f;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.function.IntPredicate;
|
|
||||||
|
|
||||||
public class SuperByteBuffer implements Transform<SuperByteBuffer>, TStack<SuperByteBuffer> {
|
|
||||||
|
|
||||||
private final VertexList template;
|
|
||||||
private final IntPredicate shadedPredicate;
|
|
||||||
|
|
||||||
// Vertex Position
|
|
||||||
private final PoseStack transforms = new PoseStack();
|
|
||||||
|
|
||||||
// Vertex Coloring
|
|
||||||
private boolean shouldColor;
|
|
||||||
private int r, g, b, a;
|
|
||||||
private boolean disableDiffuseMult;
|
|
||||||
private DiffuseLightCalculator diffuseCalculator;
|
|
||||||
|
|
||||||
// Vertex Texture Coords
|
|
||||||
private SpriteShiftFunc spriteShiftFunc;
|
|
||||||
|
|
||||||
// Vertex Overlay Color
|
|
||||||
private boolean hasOverlay;
|
|
||||||
private int overlay = OverlayTexture.NO_OVERLAY;
|
|
||||||
|
|
||||||
// Vertex Lighting
|
|
||||||
private boolean useWorldLight;
|
|
||||||
private Matrix4f lightTransform;
|
|
||||||
private boolean hasCustomLight;
|
|
||||||
private int packedLightCoords;
|
|
||||||
private boolean hybridLight;
|
|
||||||
|
|
||||||
// Vertex Normals
|
|
||||||
private boolean fullNormalTransform;
|
|
||||||
|
|
||||||
// Temporary
|
|
||||||
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
|
|
||||||
|
|
||||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState, int unshadedStartVertex) {
|
|
||||||
int vertexCount = drawState.vertexCount();
|
|
||||||
int stride = drawState.format().getVertexSize();
|
|
||||||
|
|
||||||
ShadedVertexList template = new BlockVertexList.Shaded(vertexBuffer, vertexCount, stride, unshadedStartVertex);
|
|
||||||
shadedPredicate = template::isShaded;
|
|
||||||
this.template = template;
|
|
||||||
|
|
||||||
transforms.pushPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer(ShadeSeparatedBufferedData data) {
|
|
||||||
this(data.vertexBuffer(), data.drawState(), data.unshadedStartVertex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState) {
|
|
||||||
int vertexCount = drawState.vertexCount();
|
|
||||||
int stride = drawState.format().getVertexSize();
|
|
||||||
|
|
||||||
template = new BlockVertexList(vertexBuffer, vertexCount, stride);
|
|
||||||
shadedPredicate = index -> true;
|
|
||||||
|
|
||||||
transforms.pushPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderInto(PoseStack input, VertexConsumer builder) {
|
|
||||||
if (isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Matrix4f modelMat = new Matrix4f(input.last()
|
|
||||||
.pose());
|
|
||||||
Matrix4f localTransforms = transforms.last()
|
|
||||||
.pose();
|
|
||||||
modelMat.mul(localTransforms);
|
|
||||||
|
|
||||||
Matrix3f normalMat;
|
|
||||||
if (fullNormalTransform) {
|
|
||||||
normalMat = new Matrix3f(input.last()
|
|
||||||
.normal());
|
|
||||||
Matrix3f localNormalTransforms = transforms.last()
|
|
||||||
.normal();
|
|
||||||
normalMat.mul(localNormalTransforms);
|
|
||||||
} else {
|
|
||||||
normalMat = new Matrix3f(transforms.last()
|
|
||||||
.normal());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useWorldLight) {
|
|
||||||
WORLD_LIGHT_CACHE.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
final Vector4f pos = new Vector4f();
|
|
||||||
final Vector3f normal = new Vector3f();
|
|
||||||
final Vector4f lightPos = new Vector4f();
|
|
||||||
|
|
||||||
DiffuseLightCalculator diffuseCalculator = ForcedDiffuseState.getForcedCalculator();
|
|
||||||
final boolean disableDiffuseMult =
|
|
||||||
this.disableDiffuseMult || (ShadersModHandler.isShaderPackInUse() && diffuseCalculator == null);
|
|
||||||
if (diffuseCalculator == null) {
|
|
||||||
diffuseCalculator = this.diffuseCalculator;
|
|
||||||
if (diffuseCalculator == null) {
|
|
||||||
diffuseCalculator = DiffuseLightCalculator.forCurrentLevel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final int vertexCount = template.getVertexCount();
|
|
||||||
for (int i = 0; i < vertexCount; i++) {
|
|
||||||
float x = template.getX(i);
|
|
||||||
float y = template.getY(i);
|
|
||||||
float z = template.getZ(i);
|
|
||||||
|
|
||||||
pos.set(x, y, z, 1F);
|
|
||||||
pos.mul(modelMat);
|
|
||||||
builder.vertex(pos.x(), pos.y(), pos.z());
|
|
||||||
|
|
||||||
float normalX = template.getNX(i);
|
|
||||||
float normalY = template.getNY(i);
|
|
||||||
float normalZ = template.getNZ(i);
|
|
||||||
|
|
||||||
normal.set(normalX, normalY, normalZ);
|
|
||||||
normal.mul(normalMat);
|
|
||||||
float nx = normal.x();
|
|
||||||
float ny = normal.y();
|
|
||||||
float nz = normal.z();
|
|
||||||
|
|
||||||
byte r, g, b, a;
|
|
||||||
if (shouldColor) {
|
|
||||||
r = (byte) this.r;
|
|
||||||
g = (byte) this.g;
|
|
||||||
b = (byte) this.b;
|
|
||||||
a = (byte) this.a;
|
|
||||||
} else {
|
|
||||||
r = template.getR(i);
|
|
||||||
g = template.getG(i);
|
|
||||||
b = template.getB(i);
|
|
||||||
a = template.getA(i);
|
|
||||||
}
|
|
||||||
if (disableDiffuseMult) {
|
|
||||||
builder.color(r, g, b, a);
|
|
||||||
} else {
|
|
||||||
float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz, shadedPredicate.test(i));
|
|
||||||
int colorR = transformColor(r, instanceDiffuse);
|
|
||||||
int colorG = transformColor(g, instanceDiffuse);
|
|
||||||
int colorB = transformColor(b, instanceDiffuse);
|
|
||||||
builder.color(colorR, colorG, colorB, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
float u = template.getU(i);
|
|
||||||
float v = template.getV(i);
|
|
||||||
if (spriteShiftFunc != null) {
|
|
||||||
spriteShiftFunc.shift(builder, u, v);
|
|
||||||
} else {
|
|
||||||
builder.uv(u, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasOverlay) {
|
|
||||||
builder.overlayCoords(overlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
int light;
|
|
||||||
if (useWorldLight) {
|
|
||||||
lightPos.set(((x - .5f) * 15 / 16f) + .5f, (y - .5f) * 15 / 16f + .5f, (z - .5f) * 15 / 16f + .5f, 1f);
|
|
||||||
lightPos.mul(localTransforms);
|
|
||||||
if (lightTransform != null) {
|
|
||||||
lightPos.mul(lightTransform);
|
|
||||||
}
|
|
||||||
|
|
||||||
light = getLight(Minecraft.getInstance().level, lightPos);
|
|
||||||
if (hasCustomLight) {
|
|
||||||
light = maxLight(light, packedLightCoords);
|
|
||||||
}
|
|
||||||
} else if (hasCustomLight) {
|
|
||||||
light = packedLightCoords;
|
|
||||||
} else {
|
|
||||||
light = template.getLight(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hybridLight) {
|
|
||||||
builder.uv2(maxLight(light, template.getLight(i)));
|
|
||||||
} else {
|
|
||||||
builder.uv2(light);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.normal(nx, ny, nz);
|
|
||||||
|
|
||||||
builder.endVertex();
|
|
||||||
}
|
|
||||||
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer reset() {
|
|
||||||
while (!transforms.clear())
|
|
||||||
transforms.popPose();
|
|
||||||
transforms.pushPose();
|
|
||||||
|
|
||||||
shouldColor = false;
|
|
||||||
r = 0;
|
|
||||||
g = 0;
|
|
||||||
b = 0;
|
|
||||||
a = 0;
|
|
||||||
disableDiffuseMult = false;
|
|
||||||
diffuseCalculator = null;
|
|
||||||
spriteShiftFunc = null;
|
|
||||||
hasOverlay = false;
|
|
||||||
overlay = OverlayTexture.NO_OVERLAY;
|
|
||||||
useWorldLight = false;
|
|
||||||
lightTransform = null;
|
|
||||||
hasCustomLight = false;
|
|
||||||
packedLightCoords = 0;
|
|
||||||
hybridLight = false;
|
|
||||||
fullNormalTransform = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return template.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() {
|
|
||||||
template.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PoseStack getTransforms() {
|
|
||||||
return transforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer translate(double x, double y, double z) {
|
|
||||||
transforms.translate(x, y, z);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer multiply(Quaternionf quaternion) {
|
|
||||||
transforms.mulPose(quaternion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer scale(float factorX, float factorY, float factorZ) {
|
|
||||||
transforms.scale(factorX, factorY, factorZ);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer pushPose() {
|
|
||||||
transforms.pushPose();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer popPose() {
|
|
||||||
transforms.popPose();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer mulPose(Matrix4f pose) {
|
|
||||||
transforms.last()
|
|
||||||
.pose()
|
|
||||||
.mul(pose);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer mulNormal(Matrix3f normal) {
|
|
||||||
transforms.last()
|
|
||||||
.normal()
|
|
||||||
.mul(normal);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer transform(PoseStack stack) {
|
|
||||||
transforms.last()
|
|
||||||
.pose()
|
|
||||||
.mul(stack.last()
|
|
||||||
.pose());
|
|
||||||
transforms.last()
|
|
||||||
.normal()
|
|
||||||
.mul(stack.last()
|
|
||||||
.normal());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer rotateCentered(Direction axis, float radians) {
|
|
||||||
translate(.5f, .5f, .5f).rotate(axis, radians)
|
|
||||||
.translate(-.5f, -.5f, -.5f);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer rotateCentered(Quaternionf q) {
|
|
||||||
translate(.5f, .5f, .5f).multiply(q)
|
|
||||||
.translate(-.5f, -.5f, -.5f);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(int r, int g, int b, int a) {
|
|
||||||
shouldColor = true;
|
|
||||||
this.r = r;
|
|
||||||
this.g = g;
|
|
||||||
this.b = b;
|
|
||||||
this.a = a;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(int color) {
|
|
||||||
shouldColor = true;
|
|
||||||
r = ((color >> 16) & 0xFF);
|
|
||||||
g = ((color >> 8) & 0xFF);
|
|
||||||
b = (color & 0xFF);
|
|
||||||
a = 255;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(Color c) {
|
|
||||||
return color(c.getRGB());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents vertex colors from being multiplied by the diffuse value calculated
|
|
||||||
* from the final transformed normal vector. Useful for entity rendering, when
|
|
||||||
* diffuse is applied automatically later.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer disableDiffuse() {
|
|
||||||
disableDiffuseMult = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer diffuseCalculator(DiffuseLightCalculator diffuseCalculator) {
|
|
||||||
this.diffuseCalculator = diffuseCalculator;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUV(SpriteShiftEntry entry) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
builder.uv(entry.getTargetU(u), entry.getTargetV(v));
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollV) {
|
|
||||||
return this.shiftUVScrolling(entry, 0, scrollV);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollU, float scrollV) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
float targetU = u - entry.getOriginal()
|
|
||||||
.getU0() + entry.getTarget()
|
|
||||||
.getU0()
|
|
||||||
+ scrollU;
|
|
||||||
float targetV = v - entry.getOriginal()
|
|
||||||
.getV0() + entry.getTarget()
|
|
||||||
.getV0()
|
|
||||||
+ scrollV;
|
|
||||||
builder.uv(targetU, targetV);
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
float targetU = entry.getTarget()
|
|
||||||
.getU((SpriteShiftEntry.getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16);
|
|
||||||
float targetV = entry.getTarget()
|
|
||||||
.getV((SpriteShiftEntry.getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16);
|
|
||||||
builder.uv(targetU, targetV);
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer overlay() {
|
|
||||||
hasOverlay = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer overlay(int overlay) {
|
|
||||||
hasOverlay = true;
|
|
||||||
this.overlay = overlay;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light() {
|
|
||||||
useWorldLight = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(Matrix4f lightTransform) {
|
|
||||||
useWorldLight = true;
|
|
||||||
this.lightTransform = lightTransform;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(int packedLightCoords) {
|
|
||||||
hasCustomLight = true;
|
|
||||||
this.packedLightCoords = packedLightCoords;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(Matrix4f lightTransform, int packedLightCoords) {
|
|
||||||
light(lightTransform);
|
|
||||||
light(packedLightCoords);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses max light from calculated light (world light or custom light) and vertex
|
|
||||||
* light for the final light value. Ineffective if any other light method was
|
|
||||||
* not called.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer hybridLight() {
|
|
||||||
hybridLight = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms normals not only by the local matrix stack, but also by the passed
|
|
||||||
* matrix stack.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer fullNormalTransform() {
|
|
||||||
fullNormalTransform = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer forEntityRender() {
|
|
||||||
disableDiffuse();
|
|
||||||
overlay();
|
|
||||||
fullNormalTransform();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int transformColor(byte component, float scale) {
|
|
||||||
return Mth.clamp((int) (Byte.toUnsignedInt(component) * scale), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int transformColor(int component, float scale) {
|
|
||||||
return Mth.clamp((int) (component * scale), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int maxLight(int packedLight1, int packedLight2) {
|
|
||||||
int blockLight1 = LightTexture.block(packedLight1);
|
|
||||||
int skyLight1 = LightTexture.sky(packedLight1);
|
|
||||||
int blockLight2 = LightTexture.block(packedLight2);
|
|
||||||
int skyLight2 = LightTexture.sky(packedLight2);
|
|
||||||
return LightTexture.pack(Math.max(blockLight1, blockLight2), Math.max(skyLight1, skyLight2));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getLight(Level world, Vector4f lightPos) {
|
|
||||||
BlockPos pos = BlockPos.containing(lightPos.x(), lightPos.y(), lightPos.z());
|
|
||||||
return WORLD_LIGHT_CACHE.computeIfAbsent(pos.asLong(), $ -> LevelRenderer.getLightColor(world, pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface SpriteShiftFunc {
|
|
||||||
void shift(VertexConsumer builder, float u, float v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface VertexLighter {
|
|
||||||
int getPackedLight(float x, float y, float z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
|
|
||||||
public class SuperByteBufferCache {
|
|
||||||
|
|
||||||
protected final Map<Compartment<?>, Cache<Object, SuperByteBuffer>> caches = new HashMap<>();
|
|
||||||
|
|
||||||
public synchronized void registerCompartment(Compartment<?> compartment) {
|
|
||||||
caches.put(compartment, CacheBuilder.newBuilder()
|
|
||||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void registerCompartment(Compartment<?> compartment, long ticksUntilExpired) {
|
|
||||||
caches.put(compartment, CacheBuilder.newBuilder()
|
|
||||||
.expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS)
|
|
||||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> SuperByteBuffer get(Compartment<T> compartment, T key, Callable<SuperByteBuffer> callable) {
|
|
||||||
Cache<Object, SuperByteBuffer> cache = caches.get(compartment);
|
|
||||||
if (cache != null) {
|
|
||||||
try {
|
|
||||||
return cache.get(key, callable);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void invalidate(Compartment<T> compartment, T key) {
|
|
||||||
caches.get(compartment).invalidate(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void invalidate(Compartment<?> compartment) {
|
|
||||||
caches.get(compartment).invalidateAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate() {
|
|
||||||
caches.forEach((compartment, cache) -> cache.invalidateAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Compartment<T> {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user