Compare commits
15 Commits
1.21
...
1.20-alter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04f0f4f314 | ||
|
|
c9782a8b69 | ||
|
|
302efe2ee4 | ||
|
|
8ed699b30e | ||
|
|
34dc492d3e | ||
|
|
1d833b106f | ||
|
|
1c0220548c | ||
|
|
e16b4e8489 | ||
|
|
3f588d917a | ||
|
|
582020177c | ||
|
|
22670b6b4a | ||
|
|
0d6613c3ba | ||
|
|
1607aa35ce | ||
|
|
4537dd409d | ||
|
|
268d6e7a6b |
184
build.gradle
184
build.gradle
@@ -1,89 +1,98 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id "idea"
|
||||||
id 'eclipse'
|
id "eclipse"
|
||||||
id 'idea'
|
id "maven-publish"
|
||||||
id 'maven-publish'
|
id 'net.neoforged.moddev.legacyforge' version '2.0.78'
|
||||||
id 'net.neoforged.gradle.userdev' version "${neogradle_version}"
|
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.8" // https://github.com/JetBrains/gradle-idea-ext-plugin
|
||||||
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
id "net.darkhax.curseforgegradle" version "1.1.26"
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ponderInWorkspace = findProject(':Ponder') != null
|
apply from: "./gradle/java.gradle"
|
||||||
|
apply from: "gradle/property_loader.gradle"
|
||||||
|
|
||||||
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
||||||
|
|
||||||
version = mod_version
|
|
||||||
group = 'nl.requios.effortlessbuilding'
|
group = 'nl.requios.effortlessbuilding'
|
||||||
base {
|
base {
|
||||||
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
||||||
|
version = mod_version
|
||||||
}
|
}
|
||||||
|
|
||||||
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
|
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
|
||||||
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.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
|
legacyForge {
|
||||||
|
version = "$minecraft_version-$forge_version"
|
||||||
|
|
||||||
runs {
|
if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) {
|
||||||
// applies to all the run configs below
|
accessTransformers.from "src/main/resources/META-INF/accesstransformer.cfg"
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client {
|
parchment {
|
||||||
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
minecraftVersion = minecraft_version
|
||||||
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
mappingsVersion = parchment_version
|
||||||
|
}
|
||||||
|
|
||||||
if (ponderInWorkspace) {
|
runs {
|
||||||
dependencies {
|
// applies to all the run configs below
|
||||||
runtime project(':Ponder')
|
configureEach {
|
||||||
}
|
systemProperty 'forge.logging.markers', ''
|
||||||
|
systemProperty 'forge.logging.console.level', 'info'
|
||||||
|
jvmArguments = ["-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition"]
|
||||||
|
//jvmArgs("-XX:-OmitStackTraceInFastThrow") // uncomment when you get exceptions with null messages etc
|
||||||
|
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
||||||
|
|
||||||
|
systemProperty 'mixin.debug.export', 'true'
|
||||||
|
systemProperty 'mixin.debug.verbose', 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
client {
|
||||||
|
client()
|
||||||
|
|
||||||
|
gameDirectory = project.file('run')
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
server()
|
||||||
|
|
||||||
|
gameDirectory = project.file('run/server')
|
||||||
|
}
|
||||||
|
|
||||||
|
data {
|
||||||
|
data()
|
||||||
|
|
||||||
|
gameDirectory = project.file('run')
|
||||||
|
systemProperty 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||||
|
systemProperty 'forge.logging.console.level', 'debug'
|
||||||
|
programArguments.addAll("--mod", mod_id as String, "--all", "--output", file("src/generated/resources/").getAbsolutePath(), "--existing", file("src/main/resources").getAbsolutePath())
|
||||||
|
}
|
||||||
|
|
||||||
|
gameTestServer {
|
||||||
|
type = "gameTestServer"
|
||||||
|
|
||||||
|
gameDirectory = project.file('run/gametest')
|
||||||
|
// setForceExit false <- FIXME 1.20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
mods {
|
||||||
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
effortlessbuilding {
|
||||||
programArgument '--nogui'
|
sourceSet sourceSets.main
|
||||||
}
|
}
|
||||||
|
|
||||||
data {
|
|
||||||
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
|
|
||||||
// workingDirectory project.file('run-data')
|
|
||||||
|
|
||||||
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
|
||||||
programArguments.addAll '--mod', "effortlessbuilding", '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include resources generated by data generators.
|
||||||
|
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven { url = "https://maven.createmod.net" } // Ponder, Flywheel
|
||||||
|
maven { url = "https://maven.tterrag.com" } // Registrate
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
// location of the maven for Registrate and Flywheel
|
url = 'https://www.cursemaven.com'
|
||||||
name = 'tterrag maven'
|
content {
|
||||||
url = 'https://maven.tterrag.com'
|
|
||||||
}
|
|
||||||
maven {
|
|
||||||
// Ponder, Flywheel
|
|
||||||
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,25 +111,26 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "net.neoforged:neoforge:${neo_version}"
|
jarJar("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
|
||||||
|
|
||||||
jarJar("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
modCompileOnly("dev.engine-room.flywheel:flywheel-forge-api-${flywheel_minecraft_version}:${flywheel_version}")
|
||||||
|
modRuntimeOnly(jarJar("dev.engine-room.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||||
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 {
|
version {
|
||||||
strictly "[1.0,2.0)"
|
strictly "[1.0,2.0)"
|
||||||
prefer flywheel_version
|
prefer flywheel_version
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
runtimeOnly("dev.engine-room.vanillin:vanillin-neoforge-${flywheel_minecraft_version}:${vanillin_version}")
|
modRuntimeOnly("dev.engine-room.vanillin:vanillin-forge-${flywheel_minecraft_version}:${vanillin_version}")
|
||||||
|
|
||||||
if (ponderInWorkspace) {
|
modImplementation("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
|
||||||
implementation(project(":ponder:Common"))
|
|
||||||
implementation(project(":ponder:NeoForge"))
|
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||||
} else {
|
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||||
implementation("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
if (!Boolean.getBoolean('idea.sync.active')) {
|
||||||
|
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOnly('org.jetbrains:annotations:24.0.1')
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets.main.resources {
|
sourceSets.main.resources {
|
||||||
@@ -131,11 +141,10 @@ 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 {
|
idea {
|
||||||
module {
|
module {
|
||||||
downloadSources = true
|
|
||||||
downloadJavadoc = true
|
downloadJavadoc = true
|
||||||
|
downloadSources = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,13 +155,13 @@ compileJava {
|
|||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes([
|
attributes([
|
||||||
"Specification-Title": "effortlessbuilding",
|
"Specification-Title" : mod_id,
|
||||||
"Specification-Vendor": "requios",
|
"Specification-Vendor" : mod_author,
|
||||||
"Specification-Version": "1",
|
"Specification-Version" : "1",
|
||||||
"Implementation-Title": project.name,
|
"Implementation-Title" : project.name,
|
||||||
"Implementation-Version": project.jar.archiveVersion,
|
"Implementation-Version" : project.jar.archiveVersion,
|
||||||
"Implementation-Vendor" :"requios",
|
"Implementation-Vendor" : mod_author,
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,20 +183,15 @@ java {
|
|||||||
|
|
||||||
tasks.build.dependsOn tasks.jarJar
|
tasks.build.dependsOn tasks.jarJar
|
||||||
|
|
||||||
publishing {
|
project.publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
artifactId = base.archivesName.get()
|
artifactId base.archivesName.get()
|
||||||
|
|
||||||
from components.java
|
from components.java
|
||||||
// fg.component(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
artifact(tasks.jar) {
|
||||||
if (project.hasProperty('mavendir')) {
|
classifier = "all"
|
||||||
maven { url mavendir }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,26 @@ org.gradle.jvmargs=-Xmx3G
|
|||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mod_version = 3.10
|
mod_version = 3.10
|
||||||
artifact_minecraft_version = 1.21.1
|
artifact_minecraft_version = 1.20.1
|
||||||
|
|
||||||
minecraft_version = 1.21.1
|
minecraft_version = 1.20.1
|
||||||
neo_version = 21.1.129
|
forge_version = 47.1.3
|
||||||
neogradle.subsystems.parchment.minecraftVersion = 1.21.1
|
|
||||||
neogradle.subsystems.parchment.mappingsVersion = 2024.11.17
|
|
||||||
neogradle.subsystems.conventions.runs.create-default-run-per-type = false
|
|
||||||
|
|
||||||
neogradle_version = 7.0.181
|
forgegradle_version = 6.0.7
|
||||||
|
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.21.1
|
flywheel_minecraft_version = 1.20.1
|
||||||
flywheel_version = 1.0.2
|
flywheel_version = 1.0.1
|
||||||
vanillin_version = 1.0.0-beta-11
|
vanillin_version = 1.0.0-beta-217
|
||||||
ponder_version = 1.0.46
|
ponder_version = 1.0.51
|
||||||
|
|
||||||
|
# mod options
|
||||||
|
mod_id = effortlessbuilding
|
||||||
|
mod_name = Effortless Building
|
||||||
|
mod_author = Requios
|
||||||
|
mod_description = Makes building easier by providing tools like mirrors, arrays, build modes and a block randomizer. For survival and creative mode.
|
||||||
|
mod_license = GNU LGPLv3
|
||||||
39
gradle/java.gradle
Normal file
39
gradle/java.gradle
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
java.withSourcesJar()
|
||||||
|
java.withJavadocJar()
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes([
|
||||||
|
'Specification-Title' : mod_name,
|
||||||
|
'Specification-Vendor' : mod_author,
|
||||||
|
'Specification-Version' : project.jar.archiveVersion,
|
||||||
|
'Implementation-Title' : project.name,
|
||||||
|
'Implementation-Version' : project.jar.archiveVersion,
|
||||||
|
'Implementation-Vendor' : mod_author,
|
||||||
|
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||||
|
'Timestampe' : System.currentTimeMillis(),
|
||||||
|
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
|
||||||
|
'Built-On-Minecraft' : minecraft_version
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
it.options.encoding = 'UTF-8'
|
||||||
|
it.options.release = 17
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disables Gradle's custom module metadata from being published to maven. The
|
||||||
|
// metadata includes mapped dependencies which are not reasonably consumable by
|
||||||
|
// other mod developers.
|
||||||
|
tasks.withType(GenerateModuleMetadata) {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
javadoc {
|
||||||
|
// Suppress annoying warnings when generating JavaDoc files.
|
||||||
|
options.addStringOption('Xdoclint:none', '-quiet')
|
||||||
|
}
|
||||||
48
gradle/property_loader.gradle
Normal file
48
gradle/property_loader.gradle
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
This module can inject build properties from a JSON file. Each property in the
|
||||||
|
JSON file will be mapped to a build property using the key of that property.
|
||||||
|
Property keys ending with _comment will be skipped.
|
||||||
|
|
||||||
|
If a secretFile property exists and points to a valid JSON file that file will
|
||||||
|
be automatically loaded. You can manually load a file using the loadProperties
|
||||||
|
method.
|
||||||
|
*/
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
|
||||||
|
// Auto detects a secret file and injects it.
|
||||||
|
if (project.rootProject.hasProperty("secretFile")) {
|
||||||
|
project.logger.lifecycle("Automatically loading properties from the secretFile")
|
||||||
|
final def secretsFile = project.rootProject.file(project.rootProject.getProperty("secretFile"))
|
||||||
|
|
||||||
|
if (secretsFile.exists() && secretsFile.name.endsWith(".json")) {
|
||||||
|
loadProperties(secretsFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loads properties using a specified json file.
|
||||||
|
def loadProperties(propertyFile) {
|
||||||
|
if (propertyFile.exists()) {
|
||||||
|
propertyFile.withReader {
|
||||||
|
Map propMap = new JsonSlurper().parse it
|
||||||
|
|
||||||
|
for (entry in propMap) {
|
||||||
|
|
||||||
|
// Filter entries that use _comment in the key.
|
||||||
|
if (!entry.key.endsWith("_comment")) {
|
||||||
|
|
||||||
|
project.ext.set(entry.key, entry.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.logger.lifecycle("Successfully loaded " + propMap.size() + " properties")
|
||||||
|
propMap.clear()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
project.logger.warn("The property file " + propertyFile.getName() + " could not be loaded. It does not exist.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows other scripts to use these methods.
|
||||||
|
ext {
|
||||||
|
loadProperties = this.&loadProperties
|
||||||
|
}
|
||||||
34
gradlew
vendored
34
gradlew
vendored
@@ -15,8 +15,6 @@
|
|||||||
# 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
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -57,7 +55,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/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/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/.
|
||||||
@@ -85,9 +83,10 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
|
||||||
' "$PWD" ) || exit
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# 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
|
||||||
@@ -134,13 +133,10 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
if ! command -v java >/dev/null 2>&1
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
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.
|
||||||
@@ -148,7 +144,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=SC2039,SC3045
|
# shellcheck disable=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
|
||||||
@@ -156,7 +152,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=SC2039,SC3045
|
# shellcheck disable=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
|
||||||
@@ -201,15 +197,11 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
# Collect all arguments for the java command:
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
# * 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,8 +13,6 @@
|
|||||||
@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 ##########################################################################
|
||||||
@@ -45,11 +43,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. 1>&2
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -59,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
echo. 1>&2
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
maven {
|
mavenCentral()
|
||||||
name = 'Official NeoForge Maven'
|
maven { url = 'https://maven.minecraftforge.net/' }
|
||||||
url = 'https://maven.neoforged.net/releases'
|
maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
|
||||||
}
|
maven { url = 'https://maven.parchmentmc.org' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'Effortless Building'
|
||||||
@@ -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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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 = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png");
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.startX = startX;
|
this.startX = startX;
|
||||||
|
|||||||
@@ -2,22 +2,23 @@ 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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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 = EffortlessBuilding.asResource("textures/gui/icons.png");
|
public static final ResourceLocation ICON_ATLAS = Create.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;
|
||||||
@@ -100,6 +101,7 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -129,10 +131,11 @@ 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.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||||
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||||
.setUv(u, v)
|
.uv(u, v)
|
||||||
.setLight(light);
|
.uv2(light)
|
||||||
|
.endVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||||
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 ModConfigSpec spec = builder.build();
|
public static final ForgeConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Visuals {
|
public static class Visuals {
|
||||||
public final BooleanValue showBlockPreviews;
|
public final BooleanValue showBlockPreviews;
|
||||||
|
|||||||
@@ -6,18 +6,18 @@ 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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.minecraftforge.client.event.InputEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
import net.minecraftforge.client.event.ScreenEvent;
|
||||||
import net.neoforged.neoforge.client.event.InputEvent;
|
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
import net.minecraftforge.client.settings.KeyModifier;
|
||||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.neoforged.neoforge.client.settings.KeyConflictContext;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.neoforged.neoforge.client.settings.KeyModifier;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
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.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
||||||
import nl.requios.effortlessbuilding.gui.buildmode.RadialMenu;
|
import nl.requios.effortlessbuilding.gui.buildmode.RadialMenu;
|
||||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreen;
|
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreen;
|
||||||
@@ -55,31 +55,31 @@ 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(),
|
||||||
// EffortlessBuilding.modLoc("dissolve"),
|
// new ResourceLocation(EffortlessBuilding.MODID, "dissolve"),
|
||||||
// DefaultVertexFormat.BLOCK),
|
// DefaultVertexFormat.BLOCK),
|
||||||
// shaderInstance -> BuildRenderTypes.dissolveShaderInstance = shaderInstance);
|
// shaderInstance -> BuildRenderTypes.dissolveShaderInstance = shaderInstance);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientTickPre(ClientTickEvent.Pre event) {
|
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||||
if (!isGameActive()) return;
|
if (!isGameActive()) return;
|
||||||
|
|
||||||
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
if (event.phase == TickEvent.Phase.START) {
|
||||||
|
|
||||||
onMouseInput();
|
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
||||||
|
|
||||||
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
onMouseInput();
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
||||||
public static void onClientTickPost(ClientTickEvent.Post event) {
|
|
||||||
if (!isGameActive()) return;
|
|
||||||
|
|
||||||
Screen gui = Minecraft.getInstance().screen;
|
} else if (event.phase == TickEvent.Phase.END) {
|
||||||
if (gui == null || !gui.isPauseScreen()) {
|
Screen gui = Minecraft.getInstance().screen;
|
||||||
ticksInGame++;
|
if (gui == null || !gui.isPauseScreen()) {
|
||||||
|
ticksInGame++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onMouseInput() {
|
private static void onMouseInput() {
|
||||||
@@ -134,7 +134,7 @@ public class ClientEvents {
|
|||||||
|
|
||||||
//Radial menu
|
//Radial menu
|
||||||
if (keyBindings[0].isDown()) {
|
if (keyBindings[0].isDown()) {
|
||||||
if (!AttachmentHandler.isDisabled(player)) {
|
if (!CapabilityHandler.isDisabled(player)) {
|
||||||
if (!RadialMenu.instance.isVisible()) {
|
if (!RadialMenu.instance.isVisible()) {
|
||||||
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
||||||
}
|
}
|
||||||
@@ -175,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 (AttachmentHandler.isDisabled(player)) {
|
if (CapabilityHandler.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());
|
||||||
@@ -188,7 +188,7 @@ public class ClientEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onGuiOpen(ScreenEvent.Opening event) {
|
public static void onGuiOpen(ScreenEvent 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,9 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||||
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
|
||||||
|
|
||||||
public class CommonConfig {
|
public class CommonConfig {
|
||||||
|
|
||||||
@@ -12,7 +11,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 ModConfigSpec spec = builder.build();
|
public static final ForgeConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Reach {
|
public static class Reach {
|
||||||
public final IntValue creative;
|
public final IntValue creative;
|
||||||
|
|||||||
@@ -2,21 +2,27 @@ package nl.requios.effortlessbuilding;
|
|||||||
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
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.minecraft.world.level.Level;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
import net.neoforged.neoforge.common.util.FakePlayer;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.level.BlockEvent;
|
||||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
|
import nl.requios.effortlessbuilding.capability.PowerLevelCapability;
|
||||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
||||||
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
|
import nl.requios.effortlessbuilding.network.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 +30,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,10 +42,9 @@ public class CommonEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTick(LevelTickEvent.Pre event) {
|
public static void onTick(TickEvent.LevelTickEvent event) {
|
||||||
Level level = event.getLevel();
|
if (event.phase != TickEvent.Phase.START) return;
|
||||||
if (level.isClientSide) return;
|
if (event.side == LogicalSide.CLIENT) return;
|
||||||
if (!level.dimension().equals(Level.OVERWORLD)) return;
|
|
||||||
|
|
||||||
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
||||||
}
|
}
|
||||||
@@ -75,7 +80,9 @@ 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;
|
||||||
|
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||||
|
|
||||||
if (!ServerBuildState.isLikeVanilla(player) && powerLevel.canBreakFar(player)) {
|
if (!ServerBuildState.isLikeVanilla(player) && powerLevel.canBreakFar(player)) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
@@ -95,10 +102,19 @@ public class CommonEvents {
|
|||||||
|
|
||||||
ServerBuildState.handleNewPlayer(player);
|
ServerBuildState.handleNewPlayer(player);
|
||||||
|
|
||||||
((ServerPlayer)player).connection.send(new ModifierSettingsPacket(player));
|
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ModifierSettingsPacket(player));
|
||||||
|
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||||
|
|
||||||
|
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerCaps(AttachCapabilitiesEvent<Entity> event) {
|
||||||
|
if (event.getObject() instanceof Player) {
|
||||||
|
event.addCapability(CapabilityHandler.POWER_LEVEL_CAP, new PowerLevelCapability());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@@ -110,9 +126,11 @@ public class CommonEvents {
|
|||||||
Player clone = event.getEntity();
|
Player clone = event.getEntity();
|
||||||
|
|
||||||
// Copy the power level from the original player to the clone
|
// Copy the power level from the original player to the clone
|
||||||
if (event.isWasDeath() && event.getOriginal().hasData(EffortlessBuilding.POWER_LEVEL)) {
|
original.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataOriginal ->
|
||||||
event.getEntity().setData(EffortlessBuilding.POWER_LEVEL, event.getOriginal().getData(EffortlessBuilding.POWER_LEVEL));
|
clone.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataClone -> {
|
||||||
}
|
dataClone.setPowerLevel(dataOriginal.getPowerLevel());
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -1,47 +1,37 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.Codec;
|
||||||
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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||||
import net.neoforged.fml.config.ModConfig;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.neoforged.fml.loading.FMLEnvironment;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
import net.minecraftforge.network.IContainerFactory;
|
||||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.neoforged.neoforge.network.IContainerFactory;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.neoforged.neoforge.registries.DeferredItem;
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
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.DiamondRandomizerBagItem;
|
import nl.requios.effortlessbuilding.item.*;
|
||||||
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;
|
||||||
@@ -50,7 +40,6 @@ 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 {
|
||||||
@@ -59,61 +48,59 @@ 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();
|
||||||
|
|
||||||
//Registration
|
//Registration
|
||||||
private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
|
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||||
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(BuiltInRegistries.MENU, EffortlessBuilding.MODID);
|
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, EffortlessBuilding.MODID);
|
||||||
private static final DeferredRegister<MapCodec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, 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<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, EffortlessBuilding.MODID);
|
|
||||||
|
|
||||||
public static final DeferredItem<RandomizerBagItem> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
public static final RegistryObject<Item> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
||||||
public static final DeferredItem<GoldenRandomizerBagItem> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
public static final RegistryObject<Item> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
||||||
public static final DeferredItem<DiamondRandomizerBagItem> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
public static final RegistryObject<Item> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
||||||
public static final DeferredItem<ReachUpgrade1Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
public static final RegistryObject<Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
||||||
public static final DeferredItem<ReachUpgrade2Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
public static final RegistryObject<Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
||||||
public static final DeferredItem<ReachUpgrade3Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
public static final RegistryObject<Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
||||||
public static final DeferredItem<PowerLevelItem> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
public static final RegistryObject<Item> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
||||||
public static final DeferredItem<PowerLevelItem> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
public static final RegistryObject<Item> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
||||||
public static final DeferredItem<PowerLevelItem> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
public static final RegistryObject<Item> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
||||||
|
|
||||||
public static final Supplier<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
public static final RegistryObject<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
||||||
public static final Supplier<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
public static final RegistryObject<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
||||||
public static final Supplier<MenuType<DiamondRandomizerBagContainer>> DIAMOND_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("diamond_randomizer_bag", () -> registerContainer(DiamondRandomizerBagContainer::new));
|
public static final RegistryObject<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 static final Supplier<AttachmentType<PowerLevel>> POWER_LEVEL = ATTACHMENT_TYPES.register("power_level", () -> AttachmentType.serializable(PowerLevel::new).build());
|
public EffortlessBuilding() {
|
||||||
|
|
||||||
public EffortlessBuilding(IEventBus modEventBus, ModContainer container, Dist dist) {
|
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
IEventBus forgeEventBus = NeoForge.EVENT_BUS;
|
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
||||||
|
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);
|
|
||||||
|
|
||||||
ITEMS.register(modEventBus);
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus));
|
||||||
CONTAINERS.register(modEventBus);
|
|
||||||
|
|
||||||
LOOT_MODIFIERS.register(modEventBus);
|
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||||
ATTACHMENT_TYPES.register(modEventBus);
|
CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||||
|
|
||||||
|
var singleItemLootModifier = SingleItemLootModifier.CODEC; //load this class to register the loot modifier
|
||||||
|
LOOT_MODIFIERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||||
|
|
||||||
//Register config
|
//Register config
|
||||||
container.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
modLoadingContext.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
||||||
container.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);
|
||||||
if (dist.isClient()) {
|
modLoadingContext.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +111,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;
|
||||||
}
|
}
|
||||||
@@ -143,18 +130,11 @@ 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) {
|
||||||
if (FMLEnvironment.dist.isClient()) {
|
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||||
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,17 +1,15 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.minecraft.client.gui.screens.MenuScreens;
|
||||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
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.BuildSettings;
|
import nl.requios.effortlessbuilding.systems.*;
|
||||||
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
|
||||||
import nl.requios.effortlessbuilding.systems.BuilderFilter;
|
|
||||||
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
|
||||||
|
|
||||||
public class EffortlessBuildingClient {
|
public class EffortlessBuildingClient {
|
||||||
|
|
||||||
@@ -24,12 +22,12 @@ public class EffortlessBuildingClient {
|
|||||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||||
|
|
||||||
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
||||||
modEventBus.addListener(EffortlessBuildingClient::registerMenuScreens);
|
modEventBus.addListener(EffortlessBuildingClient::clientSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerMenuScreens(final RegisterMenuScreensEvent event) {
|
public static void clientSetup(final FMLClientSetupEvent event) {
|
||||||
event.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
MenuScreens.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
||||||
event.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
MenuScreens.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
||||||
event.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
MenuScreens.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
package nl.requios.effortlessbuilding;
|
package nl.requios.effortlessbuilding;
|
||||||
|
|
||||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||||
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 ModConfigSpec spec = builder.build();
|
public static final ForgeConfigSpec spec = builder.build();
|
||||||
|
|
||||||
public static class Validation {
|
public static class Validation {
|
||||||
public final BooleanValue allowInSurvival;
|
public final BooleanValue allowInSurvival;
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
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.neoforged.neoforge.common.util.INBTSerializable;
|
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
|
||||||
|
|
||||||
public class PowerLevel implements INBTSerializable<CompoundTag> {
|
|
||||||
public static final int MAX_POWER_LEVEL = 3; //Common access
|
|
||||||
|
|
||||||
public PowerLevel() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private int powerLevel = 0;
|
|
||||||
|
|
||||||
public int getPowerLevel() {
|
|
||||||
return this.powerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNextPowerLevel() {
|
|
||||||
return Math.min(getPowerLevel() + 1, MAX_POWER_LEVEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPowerLevel(int powerLevel) {
|
|
||||||
this.powerLevel = powerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canIncreasePowerLevel() {
|
|
||||||
return getPowerLevel() < MAX_POWER_LEVEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void increasePowerLevel() {
|
|
||||||
if (canIncreasePowerLevel()) {
|
|
||||||
setPowerLevel(getPowerLevel() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
|
||||||
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
|
||||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
|
||||||
case 1 -> CommonConfig.reach.level1.get();
|
|
||||||
case 2 -> CommonConfig.reach.level2.get();
|
|
||||||
case 3 -> CommonConfig.reach.level3.get();
|
|
||||||
default -> CommonConfig.reach.level0.get();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//How far away we can detect the second and third click of build modes (distance to 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.
|
|
||||||
return getPlacementReach(player, false) + 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
|
||||||
if (player.isCreative()) return CommonConfig.maxBlocksPlacedAtOnce.creative.get();
|
|
||||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
|
||||||
case 1 -> CommonConfig.maxBlocksPlacedAtOnce.level1.get();
|
|
||||||
case 2 -> CommonConfig.maxBlocksPlacedAtOnce.level2.get();
|
|
||||||
case 3 -> CommonConfig.maxBlocksPlacedAtOnce.level3.get();
|
|
||||||
default -> CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
|
||||||
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
|
||||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
|
||||||
case 1 -> CommonConfig.maxBlocksPerAxis.level1.get();
|
|
||||||
case 2 -> CommonConfig.maxBlocksPerAxis.level2.get();
|
|
||||||
case 3 -> CommonConfig.maxBlocksPerAxis.level3.get();
|
|
||||||
default -> CommonConfig.maxBlocksPerAxis.level0.get();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
|
||||||
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
|
||||||
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
|
||||||
case 1 -> CommonConfig.maxMirrorRadius.level1.get();
|
|
||||||
case 2 -> CommonConfig.maxMirrorRadius.level2.get();
|
|
||||||
case 3 -> CommonConfig.maxMirrorRadius.level3.get();
|
|
||||||
default -> CommonConfig.maxMirrorRadius.level0.get();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDisabled(Player player) {
|
|
||||||
return getMaxBlocksPlacedAtOnce(player, false) <= 0 || getMaxBlocksPerAxis(player, false) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canBreakFar(Player player) {
|
|
||||||
return player.getAbilities().instabuild;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canReplaceBlocks(Player player) {
|
|
||||||
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 net.createmod.catnip.theme.Color;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||||
|
|
||||||
public enum BuildModeCategoryEnum {
|
public enum BuildModeCategoryEnum {
|
||||||
BASIC(new Color(0f, .5f, 1f, .8f)),
|
BASIC(new Color(0f, .5f, 1f, .8f)),
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
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.Circle;
|
import nl.requios.effortlessbuilding.buildmode.buildmodes.*;
|
||||||
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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.network.message.IsUsingBuildModePacket;
|
import nl.requios.effortlessbuilding.network.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;
|
||||||
|
|
||||||
PacketDistributor.sendToServer(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
PacketHandler.INSTANCE.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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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.message.PerformRedoPacket;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
import nl.requios.effortlessbuilding.network.message.PerformUndoPacket;
|
import nl.requios.effortlessbuilding.network.PerformRedoPacket;
|
||||||
|
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 -> PacketDistributor.sendToServer(new PerformUndoPacket());
|
case UNDO -> PacketHandler.INSTANCE.sendToServer(new PerformUndoPacket());
|
||||||
case REDO -> PacketDistributor.sendToServer(new PerformRedoPacket());
|
case REDO -> PacketHandler.INSTANCE.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,7 +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.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -65,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 = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
int axisLimit = CapabilityHandler.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();
|
||||||
@@ -94,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 = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
int axisLimit = CapabilityHandler.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();
|
||||||
@@ -140,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 = AttachmentHandler.getBuildModeReach(player);
|
int reach = CapabilityHandler.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,7 +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.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -49,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 = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
int axisLimit = CapabilityHandler.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.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
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.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
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.core.BlockPos;
|
|
||||||
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.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.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
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.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;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -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 = AttachmentHandler.getBuildModeReach(player);
|
int reach = CapabilityHandler.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,9 +3,9 @@ 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.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;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -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 = AttachmentHandler.getBuildModeReach(player);
|
int reach = CapabilityHandler.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,10 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
import net.minecraft.core.BlockPos;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -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 = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
int axisLimit = CapabilityHandler.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,12 +1,12 @@
|
|||||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
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.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;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -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 = AttachmentHandler.getBuildModeReach(player);
|
int reach = CapabilityHandler.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.core.BlockPos;
|
|
||||||
import net.minecraft.core.Vec3i;
|
|
||||||
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.core.Vec3i;
|
||||||
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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import nl.requios.effortlessbuilding.create.foundation.utility.NBTHelper;
|
||||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
import nl.requios.effortlessbuilding.network.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() {
|
||||||
PacketDistributor.sendToServer(new ModifierSettingsPacket(serializeNBT()));
|
PacketHandler.INSTANCE.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,11 +1,12 @@
|
|||||||
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.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public class Mirror extends BaseModifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPowerLevelChanged(int powerLevel) {
|
public void onPowerLevelChanged(int powerLevel) {
|
||||||
radius = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
radius = CapabilityHandler.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.util.Mth;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
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.world.level.block.state.BlockState;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
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 = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
radius = CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
package nl.requios.effortlessbuilding.attachment;
|
package nl.requios.effortlessbuilding.capability;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||||
|
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
|
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||||
|
|
||||||
public class AttachmentHandler {
|
public class CapabilityHandler {
|
||||||
public static final ResourceLocation POWER_LEVEL_CAP = EffortlessBuilding.asResource("power_level");
|
public static final ResourceLocation POWER_LEVEL_CAP = new ResourceLocation(EffortlessBuilding.MODID, "power_level");
|
||||||
|
public static final Capability<IPowerLevel> POWER_LEVEL_CAPABILITY = CapabilityManager.get(new CapabilityToken<>() {
|
||||||
|
});
|
||||||
|
|
||||||
public static void syncToClient(Player player) {
|
public static void syncToClient(Player player) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel == null) return; //Should never be null but just to be sure
|
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||||
|
|
||||||
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Helper methods to reduce boilerplate code
|
//Helper methods to reduce boilerplate code
|
||||||
public static boolean canReplaceBlocks(Player player) {
|
public static boolean canReplaceBlocks(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.canReplaceBlocks(player);
|
return powerLevel.canReplaceBlocks(player);
|
||||||
}
|
}
|
||||||
@@ -30,7 +37,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
public static int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getMaxBlocksPerAxis(player, nextPowerLevel);
|
return powerLevel.getMaxBlocksPerAxis(player, nextPowerLevel);
|
||||||
}
|
}
|
||||||
@@ -40,7 +47,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
public static int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getMaxBlocksPlacedAtOnce(player, nextPowerLevel);
|
return powerLevel.getMaxBlocksPlacedAtOnce(player, nextPowerLevel);
|
||||||
}
|
}
|
||||||
@@ -50,7 +57,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
public static int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getMaxMirrorRadius(player, nextPowerLevel);
|
return powerLevel.getMaxMirrorRadius(player, nextPowerLevel);
|
||||||
}
|
}
|
||||||
@@ -60,7 +67,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getBuildModeReach(Player player) {
|
public static int getBuildModeReach(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getBuildModeReach(player);
|
return powerLevel.getBuildModeReach(player);
|
||||||
}
|
}
|
||||||
@@ -70,7 +77,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getPlacementReach(Player player, boolean nextPowerLevel) {
|
public static int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getPlacementReach(player, nextPowerLevel);
|
return powerLevel.getPlacementReach(player, nextPowerLevel);
|
||||||
}
|
}
|
||||||
@@ -80,7 +87,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getPowerLevel(Player player) {
|
public static int getPowerLevel(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getPowerLevel();
|
return powerLevel.getPowerLevel();
|
||||||
}
|
}
|
||||||
@@ -90,7 +97,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static int getNextPowerLevel(Player player) {
|
public static int getNextPowerLevel(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.getNextPowerLevel();
|
return powerLevel.getNextPowerLevel();
|
||||||
}
|
}
|
||||||
@@ -100,7 +107,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static boolean canIncreasePowerLevel(Player player) {
|
public static boolean canIncreasePowerLevel(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.canIncreasePowerLevel();
|
return powerLevel.canIncreasePowerLevel();
|
||||||
}
|
}
|
||||||
@@ -110,7 +117,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static boolean isDisabled(Player player) {
|
public static boolean isDisabled(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.isDisabled(player);
|
return powerLevel.isDisabled(player);
|
||||||
}
|
}
|
||||||
@@ -120,7 +127,7 @@ public class AttachmentHandler {
|
|||||||
|
|
||||||
public static boolean canBreakFar(Player player) {
|
public static boolean canBreakFar(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
if (powerLevel != null) {
|
if (powerLevel != null) {
|
||||||
return powerLevel.canBreakFar(player);
|
return powerLevel.canBreakFar(player);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package nl.requios.effortlessbuilding.capability;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.common.capabilities.AutoRegisterCapability;
|
||||||
|
|
||||||
|
@AutoRegisterCapability
|
||||||
|
public interface IPowerLevel {
|
||||||
|
|
||||||
|
int getPowerLevel();
|
||||||
|
|
||||||
|
int getNextPowerLevel();
|
||||||
|
|
||||||
|
void setPowerLevel(int powerLevel);
|
||||||
|
|
||||||
|
boolean canIncreasePowerLevel();
|
||||||
|
|
||||||
|
void increasePowerLevel();
|
||||||
|
|
||||||
|
|
||||||
|
int getPlacementReach(Player player, boolean nextPowerLevel);
|
||||||
|
|
||||||
|
int getBuildModeReach(Player player);
|
||||||
|
|
||||||
|
|
||||||
|
int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel);
|
||||||
|
|
||||||
|
|
||||||
|
int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel);
|
||||||
|
|
||||||
|
|
||||||
|
int getMaxMirrorRadius(Player player, boolean nextPowerLevel);
|
||||||
|
|
||||||
|
boolean isDisabled(Player player);
|
||||||
|
|
||||||
|
boolean canBreakFar(Player player);
|
||||||
|
|
||||||
|
boolean canReplaceBlocks(Player player);
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
package nl.requios.effortlessbuilding.capability;
|
||||||
|
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class PowerLevelCapability implements IPowerLevel, ICapabilitySerializable<CompoundTag> {
|
||||||
|
public static final int MAX_POWER_LEVEL = 3; //Common access
|
||||||
|
|
||||||
|
private int powerLevel = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPowerLevel() {
|
||||||
|
return this.powerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNextPowerLevel() {
|
||||||
|
return Math.min(getPowerLevel() + 1, MAX_POWER_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPowerLevel(int powerLevel) {
|
||||||
|
this.powerLevel = powerLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canIncreasePowerLevel() {
|
||||||
|
return getPowerLevel() < MAX_POWER_LEVEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void increasePowerLevel() {
|
||||||
|
if (canIncreasePowerLevel()) {
|
||||||
|
setPowerLevel(getPowerLevel() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
||||||
|
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||||
|
case 1 -> CommonConfig.reach.level1.get();
|
||||||
|
case 2 -> CommonConfig.reach.level2.get();
|
||||||
|
case 3 -> CommonConfig.reach.level3.get();
|
||||||
|
default -> CommonConfig.reach.level0.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//How far away we can detect the second and third click of build modes (distance to player)
|
||||||
|
@Override
|
||||||
|
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.
|
||||||
|
return getPlacementReach(player, false) + 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player.isCreative()) return CommonConfig.maxBlocksPlacedAtOnce.creative.get();
|
||||||
|
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||||
|
case 1 -> CommonConfig.maxBlocksPlacedAtOnce.level1.get();
|
||||||
|
case 2 -> CommonConfig.maxBlocksPlacedAtOnce.level2.get();
|
||||||
|
case 3 -> CommonConfig.maxBlocksPlacedAtOnce.level3.get();
|
||||||
|
default -> CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
||||||
|
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||||
|
case 1 -> CommonConfig.maxBlocksPerAxis.level1.get();
|
||||||
|
case 2 -> CommonConfig.maxBlocksPerAxis.level2.get();
|
||||||
|
case 3 -> CommonConfig.maxBlocksPerAxis.level3.get();
|
||||||
|
default -> CommonConfig.maxBlocksPerAxis.level0.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
||||||
|
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
||||||
|
case 1 -> CommonConfig.maxMirrorRadius.level1.get();
|
||||||
|
case 2 -> CommonConfig.maxMirrorRadius.level2.get();
|
||||||
|
case 3 -> CommonConfig.maxMirrorRadius.level3.get();
|
||||||
|
default -> CommonConfig.maxMirrorRadius.level0.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisabled(Player player) {
|
||||||
|
return getMaxBlocksPlacedAtOnce(player, false) <= 0 || getMaxBlocksPerAxis(player, false) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBreakFar(Player player) {
|
||||||
|
return player.getAbilities().instabuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canReplaceBlocks(Player player) {
|
||||||
|
return player.getAbilities().instabuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||||
|
return CapabilityHandler.POWER_LEVEL_CAPABILITY.orEmpty(cap, LazyOptional.of(() -> this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag serializeNBT() {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putInt("powerLevel", getPowerLevel());
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserializeNBT(CompoundTag nbt) {
|
||||||
|
setPowerLevel(nbt.getInt("powerLevel"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package nl.requios.effortlessbuilding.compatibility;
|
package nl.requios.effortlessbuilding.compatibility;
|
||||||
|
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraftforge.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;
|
||||||
|
|
||||||
|
|||||||
@@ -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 ResourceLocation.fromNamespaceAndPath(EffortlessBuilding.MODID, path);
|
return new ResourceLocation(EffortlessBuilding.MODID, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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,26 @@ 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.outliner.Outliner;
|
||||||
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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.minecraftforge.client.event.ViewportEvent;
|
||||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
||||||
import net.neoforged.neoforge.client.event.ViewportEvent;
|
import net.minecraftforge.event.level.LevelEvent;
|
||||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
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.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;
|
||||||
|
import net.createmod.catnip.render.DefaultSuperRenderTypeBuffer;
|
||||||
|
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||||
|
|
||||||
@EventBusSubscriber(Dist.CLIENT)
|
@EventBusSubscriber(Dist.CLIENT)
|
||||||
public class ClientEvents {
|
public class ClientEvents {
|
||||||
@@ -28,20 +30,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.Post event) {
|
public static void onTick(ClientTickEvent event) {
|
||||||
if (!isGameActive()) return;
|
if (!isGameActive() || event.phase != TickEvent.Phase.END) return;
|
||||||
|
|
||||||
AnimationTickHolder.tick();
|
AnimationTickHolder.tick();
|
||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.tickGhosts();
|
CreateClient.GHOST_BLOCKS.tickGhosts();
|
||||||
// CreateClient.OUTLINER.tickOutlines();
|
// Outliner.getInstance().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 WrappedClientLevel)) {
|
if (world.isClientSide() && world instanceof ClientLevel && !(world instanceof WrappedClientWorld)) {
|
||||||
CreateClient.invalidateRenderers();
|
CreateClient.invalidateRenderers();
|
||||||
AnimationTickHolder.reset();
|
AnimationTickHolder.reset();
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ public class ClientEvents {
|
|||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
||||||
|
|
||||||
// CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
// Outliner.getInstance().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.neoforged.bus.api.SubscribeEvent;
|
import net.minecraftforge.event.level.LevelEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
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.foundation.utility.WorldAttached;
|
||||||
|
|
||||||
@EventBusSubscriber
|
@EventBusSubscriber
|
||||||
public class CommonEvents {
|
public class CommonEvents {
|
||||||
@@ -16,7 +16,7 @@ public class CommonEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(bus = 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 net.createmod.catnip.lang.LangNumberFormat;
|
import nl.requios.effortlessbuilding.create.foundation.utility.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;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,283 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||||
|
|
||||||
|
import net.createmod.catnip.render.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,8 +2,6 @@ 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;
|
||||||
@@ -12,8 +10,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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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;
|
||||||
@@ -108,7 +106,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 = AnimationTickHolder.getPartialTicksUI();
|
partialTicks = minecraft.getFrameTime();
|
||||||
PoseStack ms = graphics.pose();
|
PoseStack ms = graphics.pose();
|
||||||
|
|
||||||
ms.pushPose();
|
ms.pushPose();
|
||||||
@@ -116,8 +114,8 @@ public abstract class AbstractSimiScreen extends Screen {
|
|||||||
prepareFrame();
|
prepareFrame();
|
||||||
|
|
||||||
renderWindowBackground(graphics, mouseX, mouseY, partialTicks);
|
renderWindowBackground(graphics, mouseX, mouseY, partialTicks);
|
||||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
|
||||||
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||||
renderWindowForeground(graphics, mouseX, mouseY, partialTicks);
|
renderWindowForeground(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
endFrame();
|
endFrame();
|
||||||
@@ -125,11 +123,6 @@ 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);
|
||||||
@@ -148,7 +141,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) {
|
||||||
this.renderTransparentBackground(graphics); //Manually draw background
|
renderBackground(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
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,14 +1,13 @@
|
|||||||
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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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 {
|
||||||
|
|
||||||
@@ -61,7 +60,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 = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
this.location = new ResourceLocation(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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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,10 +202,11 @@ 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.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||||
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||||
.setUv(u, v)
|
.uv(u, v)
|
||||||
.setLight(light);
|
.uv2(light)
|
||||||
|
.endVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|||||||
@@ -0,0 +1,229 @@
|
|||||||
|
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.setShaderLights(light1, light2);
|
RenderSystem.setupLevelDiffuseLighting(light1, light2, lightMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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,7 +1,16 @@
|
|||||||
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;
|
||||||
@@ -9,15 +18,10 @@ 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.neoforged.neoforge.client.ClientHooks;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
import net.neoforged.neoforge.client.event.RenderTooltipEvent;
|
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||||
import net.neoforged.neoforge.client.extensions.IGuiGraphicsExtension;
|
import net.minecraftforge.client.extensions.IForgeGuiGraphics;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import org.joml.Matrix4f;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RemovedGuiUtils {
|
public class RemovedGuiUtils {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -34,7 +38,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,
|
||||||
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
||||||
font);
|
font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +53,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,
|
||||||
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
||||||
font);
|
font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +63,11 @@ public class RemovedGuiUtils {
|
|||||||
if (textLines.isEmpty())
|
if (textLines.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<ClientTooltipComponent> list = ClientHooks.gatherTooltipComponents(stack, textLines,
|
List<ClientTooltipComponent> list = ForgeHooksClient.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 (NeoForge.EVENT_BUS.post(event).isCanceled())
|
if (MinecraftForge.EVENT_BUS.post(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PoseStack pStack = graphics.pose();
|
PoseStack pStack = graphics.pose();
|
||||||
@@ -148,7 +152,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);
|
||||||
NeoForge.EVENT_BUS.post(colorEvent);
|
MinecraftForge.EVENT_BUS.post(colorEvent);
|
||||||
backgroundColor = colorEvent.getBackgroundStart();
|
backgroundColor = colorEvent.getBackgroundStart();
|
||||||
borderColorStart = colorEvent.getBorderStart();
|
borderColorStart = colorEvent.getBorderStart();
|
||||||
borderColorEnd = colorEvent.getBorderEnd();
|
borderColorEnd = colorEvent.getBorderEnd();
|
||||||
@@ -175,7 +179,8 @@ 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 = graphics.bufferSource();
|
MultiBufferSource.BufferSource renderType = MultiBufferSource.immediate(Tesselator.getInstance()
|
||||||
|
.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,16 +1,11 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
import net.createmod.catnip.data.Couple;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||||
import net.createmod.catnip.theme.Color;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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 {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
|
||||||
|
public interface TickableGuiEventListener extends GuiEventListener {
|
||||||
|
void tick();
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
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,8 +1,6 @@
|
|||||||
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;
|
||||||
@@ -15,8 +13,9 @@ 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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
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,7 +92,9 @@ 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 = AnimationTickHolder.getPartialTicksUI();
|
partialTicks = minecraft.getFrameTime();
|
||||||
|
|
||||||
|
renderBackground(graphics);
|
||||||
|
|
||||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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,7 +7,8 @@ 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.neoforged.neoforge.items.ItemStackHandler;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
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 {
|
||||||
|
|
||||||
@@ -87,7 +88,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() && ItemStack.isSameItemSameComponents(stack, stackToInsert))
|
if (!allowRepeats() && ItemHandlerHelper.canItemStacksStack(stack, stackToInsert))
|
||||||
break;
|
break;
|
||||||
if (stack.isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
ItemStack copy = stackToInsert.copy();
|
ItemStack copy = stackToInsert.copy();
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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() {
|
||||||
// PacketDistributor.SERVER.noArg().send(new ClearMenuPacket());
|
// PacketHandler.INSTANCE.sendToServer(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.neoforged.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.minecraftforge.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 {
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,301 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||||
|
|
||||||
|
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 dev.engine_room.flywheel.lib.model.baked.PartialModel;
|
||||||
|
import net.createmod.ponder.render.VirtualRenderHelper;
|
||||||
|
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, VirtualRenderHelper.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), VirtualRenderHelper.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, VirtualRenderHelper.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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,10 +1,12 @@
|
|||||||
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;
|
||||||
@@ -37,10 +39,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;
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
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,7 +4,6 @@ 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 {
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ public class Indicator extends AbstractSimiWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
public void render(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 scrollX, double scrollY) {
|
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||||
if (!this.visible || !this.isHovered) return false; //Added
|
if (!this.visible || !this.isHovered) return false; //Added
|
||||||
|
|
||||||
if (inverted)
|
if (inverted)
|
||||||
scrollX *= -1;
|
delta *= -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 = scrollX > 0;
|
context.forward = delta > 0;
|
||||||
|
|
||||||
int priorState = state;
|
int priorState = state;
|
||||||
boolean shifted = AllKeys.shiftDown();
|
boolean shifted = AllKeys.shiftDown();
|
||||||
int step = (int) Math.signum(scrollX) * this.step.apply(context);
|
int step = (int) Math.signum(delta) * 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,20 +11,7 @@ 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.AQUA;
|
import static net.minecraft.ChatFormatting.*;
|
||||||
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.neoforged.neoforge.items.IItemHandlerModifiable;
|
import net.minecraftforge.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 net.createmod.catnip.data.Pair;
|
import nl.requios.effortlessbuilding.create.foundation.utility.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.neoforged.neoforge.items.IItemHandler;
|
import net.minecraftforge.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 (!ItemStack.isSameItemSameComponents(stack, s))
|
if (!ItemHandlerHelper.canItemStacksStack(stack, s))
|
||||||
continue;
|
continue;
|
||||||
int transferred = Math.min(s.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) - s.getCount(), stack.getCount());
|
int transferred = Math.min(s.getMaxStackSize() - 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 -> !ItemStack.isSameItemSameComponents(i, blackListed));
|
test = test.and(i -> !ItemHandlerHelper.canItemStacksStack(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 ItemStack.isSameItemSameComponents(a, b) && a.getCount() + b.getCount() <= a.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
|
return ItemHandlerHelper.canItemStacksStack(a, b) && a.getCount() + b.getCount() <= a.getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
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 {
|
||||||
|
|
||||||
@@ -14,7 +15,8 @@ public class TagDependentIngredientItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldHide() {
|
public boolean shouldHide() {
|
||||||
return BuiltInRegistries.ITEM.getTag(tag).isEmpty() || BuiltInRegistries.ITEM.getTag(tag).get().size() == 0;
|
ITagManager<Item> tagManager = ForgeRegistries.ITEMS.tags();
|
||||||
|
return !tagManager.isKnownTagName(tag) || tagManager.getTag(tag).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
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;
|
||||||
@@ -14,6 +12,8 @@ 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 = ClientFontHelper.cutString(font, markedUp, maxWidthPerLine);
|
List<String> lines = FontHelper.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.neoforged.neoforge.client.model.BakedModelWrapper;
|
import net.minecraftforge.client.model.BakedModelWrapper;
|
||||||
|
|
||||||
public class CustomRenderedItemModel extends BakedModelWrapper<BakedModel> {
|
public class CustomRenderedItemModel extends BakedModelWrapper<BakedModel> {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ 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;
|
||||||
@@ -12,9 +11,10 @@ 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.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||||
import net.neoforged.neoforge.client.model.data.ModelData;
|
import net.minecraftforge.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 {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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,113 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import net.minecraft.world.entity.LivingEntity;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.neoforged.neoforge.event.EventHooks;
|
import net.minecraftforge.event.ForgeEventFactory;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -20,7 +20,7 @@ public abstract class AbstractBlockBreakQueue {
|
|||||||
BlockHelper.destroyBlockAs(world, pos, playerEntity, toDamage, effectChance,
|
BlockHelper.destroyBlockAs(world, pos, playerEntity, toDamage, effectChance,
|
||||||
stack -> drop.accept(pos, stack));
|
stack -> drop.accept(pos, stack));
|
||||||
if (toDamage.isEmpty() && !usedTool.isEmpty())
|
if (toDamage.isEmpty() && !usedTool.isEmpty())
|
||||||
EventHooks.onPlayerDestroyItem(playerEntity, usedTool, InteractionHand.MAIN_HAND);
|
ForgeEventFactory.onPlayerDestroyItem(playerEntity, usedTool, InteractionHand.MAIN_HAND);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||||
|
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.Direction.Axis;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
|
public class AngleHelper {
|
||||||
|
|
||||||
|
public static float horizontalAngle(Direction facing) {
|
||||||
|
if (facing.getAxis().isVertical())
|
||||||
|
return 0;
|
||||||
|
float angle = facing.toYRot();
|
||||||
|
if (facing.getAxis() == Axis.X)
|
||||||
|
angle = -angle;
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float verticalAngle(Direction facing) {
|
||||||
|
return facing == Direction.UP ? -90 : facing == Direction.DOWN ? 90 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float rad(double angle) {
|
||||||
|
if (angle == 0)
|
||||||
|
return 0;
|
||||||
|
return (float) (angle / 180 * Math.PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float deg(double angle) {
|
||||||
|
if (angle == 0)
|
||||||
|
return 0;
|
||||||
|
return (float) (angle * 180 / Math.PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float angleLerp(double pct, double current, double target) {
|
||||||
|
return (float) (current + getShortestAngleDiff(current, target) * pct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getShortestAngleDiff(double current, double target) {
|
||||||
|
current = current % 360;
|
||||||
|
target = target % 360;
|
||||||
|
return (float) (((((target - current) % 360) + 540) % 360) - 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getShortestAngleDiff(double current, double target, float hint) {
|
||||||
|
float diff = getShortestAngleDiff(current, target);
|
||||||
|
if (Mth.equal(Math.abs(diff), 180) && Math.signum(diff) != Math.signum(hint)) {
|
||||||
|
return diff + 360*Math.signum(hint);
|
||||||
|
}
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||||
|
|
||||||
|
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
|
||||||
|
public class AnimationTickHolder {
|
||||||
|
|
||||||
|
private static int ticks;
|
||||||
|
private static int pausedTicks;
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
ticks = 0;
|
||||||
|
pausedTicks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tick() {
|
||||||
|
if (!Minecraft.getInstance()
|
||||||
|
.isPaused()) {
|
||||||
|
ticks = (ticks + 1) % 1_728_000; // wrap around every 24 hours so we maintain enough floating point precision
|
||||||
|
} else {
|
||||||
|
pausedTicks = (pausedTicks + 1) % 1_728_000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTicks() {
|
||||||
|
return getTicks(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTicks(boolean includePaused) {
|
||||||
|
return includePaused ? ticks + pausedTicks : ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getRenderTime() {
|
||||||
|
return getTicks() + getPartialTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getPartialTicks() {
|
||||||
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
return (mc.isPaused() ? mc.pausePartialTick : mc.getFrameTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTicks(LevelAccessor world) {
|
||||||
|
if (world instanceof WrappedClientWorld)
|
||||||
|
return getTicks(((WrappedClientWorld) world).getWrappedWorld());
|
||||||
|
return getTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getRenderTime(LevelAccessor world) {
|
||||||
|
return getTicks(world) + getPartialTicks(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getPartialTicks(LevelAccessor world) {
|
||||||
|
return getPartialTicks();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||||
|
|
||||||
|
public class BBHelper {
|
||||||
|
|
||||||
|
public static BoundingBox encapsulate(BoundingBox bb, BlockPos pos) {
|
||||||
|
return new BoundingBox(Math.min(bb.minX(), pos.getX()), Math.min(bb.minY(), pos.getY()),
|
||||||
|
Math.min(bb.minZ(), pos.getZ()), Math.max(bb.maxX(), pos.getX()), Math.max(bb.maxY(), pos.getY()),
|
||||||
|
Math.max(bb.maxZ(), pos.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoundingBox encapsulate(BoundingBox bb, BoundingBox bb2) {
|
||||||
|
return new BoundingBox(Math.min(bb.minX(), bb2.minX()), Math.min(bb.minY(), bb2.minY()),
|
||||||
|
Math.min(bb.minZ(), bb2.minZ()), Math.max(bb.maxX(), bb2.maxX()), Math.max(bb.maxY(), bb2.maxY()),
|
||||||
|
Math.max(bb.maxZ(), bb2.maxZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.NbtUtils;
|
||||||
|
|
||||||
|
public class BlockFace extends Pair<BlockPos, Direction> {
|
||||||
|
|
||||||
|
public BlockFace(BlockPos first, Direction second) {
|
||||||
|
super(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEquivalent(BlockFace other) {
|
||||||
|
if (equals(other))
|
||||||
|
return true;
|
||||||
|
return getConnectedPos().equals(other.getPos()) && getPos().equals(other.getConnectedPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos() {
|
||||||
|
return getFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getFace() {
|
||||||
|
return getSecond();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getOppositeFace() {
|
||||||
|
return getSecond().getOpposite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getOpposite() {
|
||||||
|
return new BlockFace(getConnectedPos(), getOppositeFace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getConnectedPos() {
|
||||||
|
return getPos().relative(getFace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag serializeNBT() {
|
||||||
|
CompoundTag compoundNBT = new CompoundTag();
|
||||||
|
compoundNBT.put("Pos", NbtUtils.writeBlockPos(getPos()));
|
||||||
|
NBTHelper.writeEnum(compoundNBT, "Face", getFace());
|
||||||
|
return compoundNBT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockFace fromNBT(CompoundTag compound) {
|
||||||
|
return new BlockFace(NbtUtils.readBlockPos(compound.getCompound("Pos")),
|
||||||
|
NBTHelper.readEnum(compound, "Face", Direction.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||||
|
|
||||||
import net.createmod.catnip.nbt.NBTProcessors;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.core.RegistryAccess;
|
|
||||||
import net.minecraft.core.SectionPos;
|
import net.minecraft.core.SectionPos;
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
@@ -19,7 +16,6 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
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.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.item.enchantment.Enchantment;
|
|
||||||
import net.minecraft.world.item.enchantment.Enchantments;
|
import net.minecraft.world.item.enchantment.Enchantments;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.GameRules;
|
import net.minecraft.world.level.GameRules;
|
||||||
@@ -33,41 +29,19 @@ import net.minecraft.world.level.block.SlimeBlock;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
||||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
||||||
import net.minecraft.world.level.block.state.properties.Property;
|
import net.minecraft.world.level.block.state.properties.Property;
|
||||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||||
import net.minecraft.world.level.material.FluidState;
|
import net.minecraft.world.level.material.FluidState;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.minecraftforge.common.IPlantable;
|
||||||
import net.neoforged.neoforge.common.SpecialPlantable;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.neoforged.neoforge.event.level.BlockDropsEvent;
|
import net.minecraftforge.event.level.BlockEvent;
|
||||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class BlockHelper {
|
public class BlockHelper {
|
||||||
private static final List<IntegerProperty> COUNT_STATES = List.of(
|
|
||||||
BlockStateProperties.EGGS,
|
|
||||||
BlockStateProperties.PICKLES,
|
|
||||||
BlockStateProperties.CANDLES
|
|
||||||
);
|
|
||||||
|
|
||||||
private static final List<Block> VINELIKE_BLOCKS = List.of(
|
|
||||||
Blocks.VINE, Blocks.GLOW_LICHEN
|
|
||||||
);
|
|
||||||
|
|
||||||
private static final List<BooleanProperty> VINELIKE_STATES = List.of(
|
|
||||||
BlockStateProperties.UP,
|
|
||||||
BlockStateProperties.NORTH,
|
|
||||||
BlockStateProperties.EAST,
|
|
||||||
BlockStateProperties.SOUTH,
|
|
||||||
BlockStateProperties.WEST,
|
|
||||||
BlockStateProperties.DOWN
|
|
||||||
);
|
|
||||||
|
|
||||||
public static BlockState setZeroAge(BlockState blockState) {
|
public static BlockState setZeroAge(BlockState blockState) {
|
||||||
if (blockState.hasProperty(BlockStateProperties.AGE_1))
|
if (blockState.hasProperty(BlockStateProperties.AGE_1))
|
||||||
@@ -104,54 +78,44 @@ public class BlockHelper {
|
|||||||
Item required = getRequiredItem(block).getItem();
|
Item required = getRequiredItem(block).getItem();
|
||||||
|
|
||||||
boolean needsTwo = block.hasProperty(BlockStateProperties.SLAB_TYPE)
|
boolean needsTwo = block.hasProperty(BlockStateProperties.SLAB_TYPE)
|
||||||
&& block.getValue(BlockStateProperties.SLAB_TYPE) == SlabType.DOUBLE;
|
&& block.getValue(BlockStateProperties.SLAB_TYPE) == SlabType.DOUBLE;
|
||||||
|
|
||||||
if (needsTwo)
|
if (needsTwo)
|
||||||
amount *= 2;
|
amount *= 2;
|
||||||
|
|
||||||
for (IntegerProperty property : COUNT_STATES)
|
if (block.hasProperty(BlockStateProperties.EGGS))
|
||||||
if (block.hasProperty(property))
|
amount *= block.getValue(BlockStateProperties.EGGS);
|
||||||
amount *= block.getValue(property);
|
|
||||||
|
|
||||||
if (VINELIKE_BLOCKS.contains(block.getBlock())) {
|
if (block.hasProperty(BlockStateProperties.PICKLES))
|
||||||
int vineCount = 0;
|
amount *= block.getValue(BlockStateProperties.PICKLES);
|
||||||
|
|
||||||
for (BooleanProperty vineState : VINELIKE_STATES) {
|
|
||||||
if (block.hasProperty(vineState) && block.getValue(vineState)) {
|
|
||||||
vineCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
amount += vineCount - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Try held Item first
|
// Try held Item first
|
||||||
int preferredSlot = player.getInventory().selected;
|
int preferredSlot = player.getInventory().selected;
|
||||||
ItemStack itemstack = player.getInventory()
|
ItemStack itemstack = player.getInventory()
|
||||||
.getItem(preferredSlot);
|
.getItem(preferredSlot);
|
||||||
int count = itemstack.getCount();
|
int count = itemstack.getCount();
|
||||||
if (itemstack.getItem() == required && count > 0) {
|
if (itemstack.getItem() == required && count > 0) {
|
||||||
int taken = Math.min(count, amount - amountFound);
|
int taken = Math.min(count, amount - amountFound);
|
||||||
player.getInventory()
|
player.getInventory()
|
||||||
.setItem(preferredSlot, new ItemStack(itemstack.getItem(), count - taken));
|
.setItem(preferredSlot, new ItemStack(itemstack.getItem(), count - taken));
|
||||||
amountFound += taken;
|
amountFound += taken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search inventory
|
// Search inventory
|
||||||
for (int i = 0; i < player.getInventory()
|
for (int i = 0; i < player.getInventory()
|
||||||
.getContainerSize(); ++i) {
|
.getContainerSize(); ++i) {
|
||||||
if (amountFound == amount)
|
if (amountFound == amount)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ItemStack itemstack = player.getInventory()
|
ItemStack itemstack = player.getInventory()
|
||||||
.getItem(i);
|
.getItem(i);
|
||||||
int count = itemstack.getCount();
|
int count = itemstack.getCount();
|
||||||
if (itemstack.getItem() == required && count > 0) {
|
if (itemstack.getItem() == required && count > 0) {
|
||||||
int taken = Math.min(count, amount - amountFound);
|
int taken = Math.min(count, amount - amountFound);
|
||||||
player.getInventory()
|
player.getInventory()
|
||||||
.setItem(i, new ItemStack(itemstack.getItem(), count - taken));
|
.setItem(i, new ItemStack(itemstack.getItem(), count - taken));
|
||||||
amountFound += taken;
|
amountFound += taken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,7 +124,7 @@ public class BlockHelper {
|
|||||||
// Give back 1 if uneven amount was removed
|
// Give back 1 if uneven amount was removed
|
||||||
if (amountFound % 2 != 0)
|
if (amountFound % 2 != 0)
|
||||||
player.getInventory()
|
player.getInventory()
|
||||||
.add(new ItemStack(required));
|
.add(new ItemStack(required));
|
||||||
amountFound /= 2;
|
amountFound /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,74 +144,68 @@ public class BlockHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void destroyBlock(Level world, BlockPos pos, float effectChance,
|
public static void destroyBlock(Level world, BlockPos pos, float effectChance,
|
||||||
Consumer<ItemStack> droppedItemCallback) {
|
Consumer<ItemStack> droppedItemCallback) {
|
||||||
destroyBlockAs(world, pos, null, ItemStack.EMPTY, effectChance, droppedItemCallback);
|
destroyBlockAs(world, pos, null, ItemStack.EMPTY, effectChance, droppedItemCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean destroyBlockAs(Level world, BlockPos pos, @Nullable Player player, ItemStack usedTool,
|
public static boolean destroyBlockAs(Level world, BlockPos pos, @Nullable Player player, ItemStack usedTool,
|
||||||
float effectChance, Consumer<ItemStack> droppedItemCallback) {
|
float effectChance, Consumer<ItemStack> droppedItemCallback) {
|
||||||
FluidState fluidState = world.getFluidState(pos);
|
FluidState fluidState = world.getFluidState(pos);
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
|
|
||||||
if (world.random.nextFloat() < effectChance)
|
if (world.random.nextFloat() < effectChance)
|
||||||
world.levelEvent(2001, pos, Block.getId(state));
|
world.levelEvent(2001, pos, Block.getId(state));
|
||||||
BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|
BlockEntity tileentity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
|
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
|
||||||
NeoForge.EVENT_BUS.post(event);
|
MinecraftForge.EVENT_BUS.post(event);
|
||||||
if (event.isCanceled())
|
if (event.isCanceled())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (event.getExpToDrop() > 0 && world instanceof ServerLevel)
|
||||||
|
state.getBlock()
|
||||||
|
.popExperience((ServerLevel) world, pos, event.getExpToDrop());
|
||||||
|
|
||||||
usedTool.mineBlock(world, state, pos, player);
|
usedTool.mineBlock(world, state, pos, player);
|
||||||
player.awardStat(Stats.BLOCK_MINED.get(state.getBlock()));
|
player.awardStat(Stats.BLOCK_MINED.get(state.getBlock()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world instanceof ServerLevel serverLevel && world.getGameRules()
|
if (world instanceof ServerLevel && world.getGameRules()
|
||||||
.getBoolean(GameRules.RULE_DOBLOCKDROPS) && !world.restoringBlockSnapshots
|
.getBoolean(GameRules.RULE_DOBLOCKDROPS) && !world.restoringBlockSnapshots
|
||||||
&& (player == null || !player.isCreative())) {
|
&& (player == null || !player.isCreative())) {
|
||||||
List<ItemStack> drops = Block.getDrops(state, serverLevel, pos, blockEntity, player, usedTool);
|
for (ItemStack itemStack : Block.getDrops(state, (ServerLevel) world, pos, tileentity, player, usedTool))
|
||||||
if (player != null) {
|
|
||||||
BlockDropsEvent event = new BlockDropsEvent(serverLevel, pos, state, blockEntity, List.of(), player, usedTool);
|
|
||||||
NeoForge.EVENT_BUS.post(event);
|
|
||||||
if (!event.isCanceled()) {
|
|
||||||
if ( event.getDroppedExperience() > 0)
|
|
||||||
state.getBlock().popExperience(serverLevel, pos, event.getDroppedExperience());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (ItemStack itemStack : drops)
|
|
||||||
droppedItemCallback.accept(itemStack);
|
droppedItemCallback.accept(itemStack);
|
||||||
|
|
||||||
// Simulating IceBlock#playerDestroy. Not calling method directly as it would drop item
|
// Simulating IceBlock#playerDestroy. Not calling method directly as it would drop item
|
||||||
// entities as a side-effect
|
// entities as a side-effect
|
||||||
Registry<Enchantment> enchantmentRegistry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT);
|
if (state.getBlock() instanceof IceBlock && usedTool.getEnchantmentLevel(Enchantments.SILK_TOUCH) == 0) {
|
||||||
if (state.getBlock() instanceof IceBlock && usedTool.getEnchantmentLevel(enchantmentRegistry.getHolderOrThrow(Enchantments.SILK_TOUCH)) == 0) {
|
|
||||||
if (world.dimensionType()
|
if (world.dimensionType()
|
||||||
.ultraWarm())
|
.ultraWarm())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BlockState blockstate = world.getBlockState(pos.below());
|
BlockState belowState = world.getBlockState(pos.below());
|
||||||
if (blockstate.blocksMotion() || blockstate.liquid())
|
if (belowState.blocksMotion() || belowState.liquid())
|
||||||
world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
|
world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
|
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
world.setBlockAndUpdate(pos, fluidState.createLegacyBlock());
|
world.setBlockAndUpdate(pos, fluidState.createLegacyBlock());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSolidWall(BlockGetter reader, BlockPos fromPos, Direction toDirection) {
|
public static boolean isSolidWall(BlockGetter reader, BlockPos fromPos, Direction toDirection) {
|
||||||
return hasBlockSolidSide(reader.getBlockState(fromPos.relative(toDirection)), reader,
|
return hasBlockSolidSide(reader.getBlockState(fromPos.relative(toDirection)), reader,
|
||||||
fromPos.relative(toDirection), toDirection.getOpposite());
|
fromPos.relative(toDirection), toDirection.getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean noCollisionInSpace(BlockGetter reader, BlockPos pos) {
|
public static boolean noCollisionInSpace(BlockGetter reader, BlockPos pos) {
|
||||||
return reader.getBlockState(pos)
|
return reader.getBlockState(pos)
|
||||||
.getCollisionShape(reader, pos)
|
.getCollisionShape(reader, pos)
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void placeRailWithoutUpdate(Level world, BlockState state, BlockPos target) {
|
private static void placeRailWithoutUpdate(Level world, BlockState state, BlockPos target) {
|
||||||
@@ -260,33 +218,18 @@ public class BlockHelper {
|
|||||||
chunk.getSections()[idx] = chunksection;
|
chunk.getSections()[idx] = chunksection;
|
||||||
}
|
}
|
||||||
BlockState old = chunksection.setBlockState(SectionPos.sectionRelative(target.getX()),
|
BlockState old = chunksection.setBlockState(SectionPos.sectionRelative(target.getX()),
|
||||||
SectionPos.sectionRelative(target.getY()), SectionPos.sectionRelative(target.getZ()), state);
|
SectionPos.sectionRelative(target.getY()), SectionPos.sectionRelative(target.getZ()), state);
|
||||||
chunk.setUnsaved(true);
|
chunk.setUnsaved(true);
|
||||||
world.markAndNotifyBlock(target, chunk, old, state, 82, 512);
|
world.markAndNotifyBlock(target, chunk, old, state, 82, 512);
|
||||||
|
|
||||||
world.setBlock(target, state, 82);
|
world.setBlock(target, state, 82);
|
||||||
world.neighborChanged(target, world.getBlockState(target.below())
|
world.neighborChanged(target, world.getBlockState(target.below())
|
||||||
.getBlock(), target.below());
|
.getBlock(), target.below());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompoundTag prepareBlockEntityData(BlockState blockState, BlockEntity blockEntity) {
|
public static boolean placeSchematicBlock(Level world, Player player, BlockState state, BlockPos target, ItemStack stack,
|
||||||
CompoundTag data = null;
|
@Nullable CompoundTag data) {
|
||||||
if (blockEntity == null)
|
BlockEntity existingTile = world.getBlockEntity(target);
|
||||||
return null;
|
|
||||||
RegistryAccess access = blockEntity.getLevel().registryAccess();
|
|
||||||
if (blockEntity instanceof IPartialSafeNBT safeNbtBE) {
|
|
||||||
data = new CompoundTag();
|
|
||||||
safeNbtBE.writeSafe(data, access);
|
|
||||||
data = NBTProcessors.process(blockState, blockEntity, data, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void placeSchematicBlock(Level world, BlockState state, BlockPos target, ItemStack stack,
|
|
||||||
@Nullable CompoundTag data) {
|
|
||||||
BlockEntity existingBlockEntity = world.getBlockEntity(target);
|
|
||||||
boolean alreadyPlaced = false;
|
|
||||||
|
|
||||||
// Piston
|
// Piston
|
||||||
if (state.hasProperty(BlockStateProperties.EXTENDED))
|
if (state.hasProperty(BlockStateProperties.EXTENDED))
|
||||||
@@ -296,69 +239,58 @@ public class BlockHelper {
|
|||||||
|
|
||||||
if (state.getBlock() == Blocks.COMPOSTER)
|
if (state.getBlock() == Blocks.COMPOSTER)
|
||||||
state = Blocks.COMPOSTER.defaultBlockState();
|
state = Blocks.COMPOSTER.defaultBlockState();
|
||||||
else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof SpecialPlantable specialPlantable) {
|
else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable)
|
||||||
alreadyPlaced = true;
|
state = ((IPlantable) state.getBlock()).getPlant(world, target);
|
||||||
if (specialPlantable.canPlacePlantAtPosition(stack, world, target, null))
|
|
||||||
specialPlantable.spawnPlantAtPosition(stack, world, target, null);
|
|
||||||
}
|
|
||||||
else if (state.is(BlockTags.CAULDRONS))
|
else if (state.is(BlockTags.CAULDRONS))
|
||||||
state = Blocks.CAULDRON.defaultBlockState();
|
state = Blocks.CAULDRON.defaultBlockState();
|
||||||
|
|
||||||
if (world.dimensionType()
|
if (world.dimensionType()
|
||||||
.ultraWarm() && state.getFluidState().is(FluidTags.WATER)) {
|
.ultraWarm() && state.getFluidState().is(FluidTags.WATER)) {
|
||||||
int i = target.getX();
|
int i = target.getX();
|
||||||
int j = target.getY();
|
int j = target.getY();
|
||||||
int k = target.getZ();
|
int k = target.getZ();
|
||||||
world.playSound(null, target, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F,
|
world.playSound(null, target, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F,
|
||||||
2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
||||||
|
|
||||||
for (int l = 0; l < 8; ++l) {
|
for (int l = 0; l < 8; ++l) {
|
||||||
world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(),
|
world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(),
|
||||||
0.0D, 0.0D, 0.0D);
|
0.0D, 0.0D, 0.0D);
|
||||||
}
|
}
|
||||||
Block.dropResources(state, world, target);
|
Block.dropResources(state, world, target);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection StatementWithEmptyBody
|
if (state.getBlock() instanceof BaseRailBlock) {
|
||||||
if (alreadyPlaced) {
|
|
||||||
// pass
|
|
||||||
} else if (state.getBlock() instanceof BaseRailBlock) {
|
|
||||||
placeRailWithoutUpdate(world, state, target);
|
placeRailWithoutUpdate(world, state, target);
|
||||||
} else {
|
} else {
|
||||||
world.setBlock(target, state, 18);
|
world.setBlock(target, state, 2); //Changed flag from 18 to 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
// if (existingBlockEntity instanceof IMergeableBE mergeable) {
|
// if (existingTile instanceof IMergeableTE mergeable) {
|
||||||
// BlockEntity loaded = BlockEntity.loadStatic(target, state, data, world.registryAccess());
|
// BlockEntity loaded = BlockEntity.loadStatic(target, state, data);
|
||||||
// if (loaded != null) {
|
// if (existingTile.getType()
|
||||||
// if (existingBlockEntity.getType()
|
// .equals(loaded.getType())) {
|
||||||
// .equals(loaded.getType())) {
|
// mergeable.accept(loaded);
|
||||||
// mergeable.accept(loaded);
|
// return;
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
BlockEntity blockEntity = world.getBlockEntity(target);
|
BlockEntity tile = world.getBlockEntity(target);
|
||||||
if (blockEntity != null) {
|
if (tile != null) {
|
||||||
data.putInt("x", target.getX());
|
data.putInt("x", target.getX());
|
||||||
data.putInt("y", target.getY());
|
data.putInt("y", target.getY());
|
||||||
data.putInt("z", target.getZ());
|
data.putInt("z", target.getZ());
|
||||||
// if (blockEntity instanceof KineticBlockEntity kbe)
|
// if (tile instanceof KineticTileEntity)
|
||||||
// kbe.warnOfMovement();
|
// ((KineticTileEntity) tile).warnOfMovement();
|
||||||
// if (blockEntity instanceof IMultiBlockEntityContainer imbe)
|
tile.load(data);
|
||||||
// if (!imbe.isController())
|
|
||||||
// data.put("Controller", NbtUtils.writeBlockPos(imbe.getController()));
|
|
||||||
blockEntity.loadWithComponents(data, world.registryAccess());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
state.getBlock()
|
state.getBlock().setPlacedBy(world, target, state, null, stack);
|
||||||
.setPlacedBy(world, target, state, null, stack);
|
} catch (Exception ignored) {
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getBounceMultiplier(Block block) {
|
public static double getBounceMultiplier(Block block) {
|
||||||
@@ -370,9 +302,22 @@ public class BlockHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasBlockSolidSide(BlockState p_220056_0_, BlockGetter p_220056_1_, BlockPos p_220056_2_,
|
public static boolean hasBlockSolidSide(BlockState p_220056_0_, BlockGetter p_220056_1_, BlockPos p_220056_2_,
|
||||||
Direction p_220056_3_) {
|
Direction p_220056_3_) {
|
||||||
return !p_220056_0_.is(BlockTags.LEAVES)
|
return !p_220056_0_.is(BlockTags.LEAVES)
|
||||||
&& Block.isFaceFull(p_220056_0_.getCollisionShape(p_220056_1_, p_220056_2_), p_220056_3_);
|
&& Block.isFaceFull(p_220056_0_.getCollisionShape(p_220056_1_, p_220056_2_), p_220056_3_);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean extinguishFire(Level world, @Nullable Player p_175719_1_, BlockPos p_175719_2_,
|
||||||
|
Direction p_175719_3_) {
|
||||||
|
p_175719_2_ = p_175719_2_.relative(p_175719_3_);
|
||||||
|
if (world.getBlockState(p_175719_2_)
|
||||||
|
.getBlock() == Blocks.FIRE) {
|
||||||
|
world.levelEvent(p_175719_1_, 1009, p_175719_2_, 0);
|
||||||
|
world.removeBlock(p_175719_2_, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState copyProperties(BlockState fromState, BlockState toState) {
|
public static BlockState copyProperties(BlockState fromState, BlockState toState) {
|
||||||
@@ -383,7 +328,7 @@ public class BlockHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Comparable<T>> BlockState copyProperty(Property<T> property, BlockState fromState,
|
public static <T extends Comparable<T>> BlockState copyProperty(Property<T> property, BlockState fromState,
|
||||||
BlockState toState) {
|
BlockState toState) {
|
||||||
if (fromState.hasProperty(property) && toState.hasProperty(property)) {
|
if (fromState.hasProperty(property) && toState.hasProperty(property)) {
|
||||||
return toState.setValue(property, fromState.getValue(property));
|
return toState.setValue(property, fromState.getValue(property));
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user