Compare commits
16 Commits
1.19.4
...
1.20-alter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04f0f4f314 | ||
|
|
c9782a8b69 | ||
|
|
302efe2ee4 | ||
|
|
8ed699b30e | ||
|
|
34dc492d3e | ||
|
|
1d833b106f | ||
|
|
1c0220548c | ||
|
|
e16b4e8489 | ||
|
|
3f588d917a | ||
|
|
582020177c | ||
|
|
22670b6b4a | ||
|
|
08c3b4b42d | ||
|
|
0d6613c3ba | ||
|
|
1607aa35ce | ||
|
|
4537dd409d | ||
|
|
268d6e7a6b |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -20,7 +20,7 @@ build
|
|||||||
# other
|
# other
|
||||||
eclipse
|
eclipse
|
||||||
run
|
run
|
||||||
logs/*
|
runs
|
||||||
|
run-data
|
||||||
|
|
||||||
# Files from Forge MDK
|
repo
|
||||||
forge*changelog.txt
|
|
||||||
175
build.gradle
175
build.gradle
@@ -1,102 +1,94 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
maven { url = 'https://maven.minecraftforge.net' }
|
|
||||||
mavenCentral()
|
|
||||||
maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
|
|
||||||
maven { url = 'https://maven.parchmentmc.org' }
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "net.minecraftforge.gradle:ForgeGradle:${forgegradle_version}"
|
|
||||||
classpath "org.spongepowered:mixingradle:${mixingradle_version}"
|
|
||||||
classpath "org.parchmentmc:librarian:${librarian_version}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
id "idea"
|
||||||
|
id "eclipse"
|
||||||
|
id "maven-publish"
|
||||||
|
id 'net.neoforged.moddev.legacyforge' version '2.0.78'
|
||||||
|
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.8" // https://github.com/JetBrains/gradle-idea-ext-plugin
|
||||||
|
id "net.darkhax.curseforgegradle" version "1.1.26"
|
||||||
}
|
}
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
|
||||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
|
||||||
apply plugin: 'eclipse'
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
apply plugin: 'org.spongepowered.mixin'
|
|
||||||
|
|
||||||
jarJar.enable()
|
apply from: "./gradle/java.gradle"
|
||||||
|
apply from: "gradle/property_loader.gradle"
|
||||||
boolean flywheelInWorkspace = findProject(':Flywheel') != null
|
|
||||||
|
|
||||||
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(17)
|
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 {
|
legacyForge {
|
||||||
mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}"
|
version = "$minecraft_version-$forge_version"
|
||||||
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
|
||||||
|
if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) {
|
||||||
|
accessTransformers.from "src/main/resources/META-INF/accesstransformer.cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
parchment {
|
||||||
|
minecraftVersion = minecraft_version
|
||||||
|
mappingsVersion = parchment_version
|
||||||
|
}
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
client {
|
// applies to all the run configs below
|
||||||
workingDirectory project.file('run')
|
configureEach {
|
||||||
arg '-mixin.config=flywheel.mixins.json'
|
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
|
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
||||||
property 'forge.logging.console.level', 'info'
|
|
||||||
|
|
||||||
mods {
|
systemProperty 'mixin.debug.export', 'true'
|
||||||
effortlessbuilding {
|
systemProperty 'mixin.debug.verbose', 'true'
|
||||||
source sourceSets.main
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
client {
|
||||||
flywheel {
|
client()
|
||||||
source project(":Flywheel").sourceSets.main
|
|
||||||
}
|
gameDirectory = project.file('run')
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
workingDirectory project.file('run/server')
|
server()
|
||||||
property 'forge.logging.console.level', 'info'
|
|
||||||
mods {
|
gameDirectory = project.file('run/server')
|
||||||
effortlessbuilding {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data {
|
data {
|
||||||
workingDirectory project.file('run')
|
data()
|
||||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
gameDirectory = project.file('run')
|
||||||
args '--mod', 'effortlessbuilding', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
effortlessbuilding {
|
effortlessbuilding {
|
||||||
source sourceSets.main
|
sourceSet sourceSets.main
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
// Include resources generated by data generators.
|
||||||
flywheel {
|
sourceSets.main.resources { srcDir 'src/generated/resources' }
|
||||||
source project(":Flywheel").sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven { url = "https://maven.createmod.net" } // Ponder, Flywheel
|
||||||
// location of the maven for Registrate and Flywheel
|
maven { url = "https://maven.tterrag.com" } // Registrate
|
||||||
name = 'tterrag maven'
|
|
||||||
url = 'https://maven.tterrag.com'
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = 'https://www.cursemaven.com'
|
url = 'https://www.cursemaven.com'
|
||||||
@@ -119,23 +111,26 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
jarJar("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
|
||||||
|
|
||||||
jarJar("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
modCompileOnly("dev.engine-room.flywheel:flywheel-forge-api-${flywheel_minecraft_version}:${flywheel_version}")
|
||||||
jarJar.ranged(it, '[0.6.10,0.7)')
|
modRuntimeOnly(jarJar("dev.engine-room.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||||
|
version {
|
||||||
|
strictly "[1.0,2.0)"
|
||||||
|
prefer flywheel_version
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
modRuntimeOnly("dev.engine-room.vanillin:vanillin-forge-${flywheel_minecraft_version}:${vanillin_version}")
|
||||||
|
|
||||||
if (flywheelInWorkspace) {
|
modImplementation("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
|
||||||
implementation project(':Flywheel')
|
|
||||||
} else {
|
|
||||||
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||||
if (!Boolean.getBoolean('idea.sync.active')) {
|
if (!Boolean.getBoolean('idea.sync.active')) {
|
||||||
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOnly('org.jetbrains:annotations:24.0.1')
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets.main.resources {
|
sourceSets.main.resources {
|
||||||
@@ -146,6 +141,13 @@ 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 {
|
||||||
|
module {
|
||||||
|
downloadJavadoc = true
|
||||||
|
downloadSources = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.compilerArgs = ['-Xdiags:verbose']
|
options.compilerArgs = ['-Xdiags:verbose']
|
||||||
}
|
}
|
||||||
@@ -153,12 +155,12 @@ 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")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@@ -179,24 +181,17 @@ java {
|
|||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
jar.finalizedBy('reobfJar')
|
tasks.build.dependsOn tasks.jarJar
|
||||||
tasks.jarJar.finalizedBy('reobfJarJar')
|
|
||||||
|
|
||||||
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)
|
|
||||||
jarJar.component(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
artifact(tasks.jar) {
|
||||||
if (project.hasProperty('mavendir')) {
|
classifier = "all"
|
||||||
maven { url mavendir }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mod_version = 3.5
|
mod_version = 3.10
|
||||||
artifact_minecraft_version = 1.20.1
|
artifact_minecraft_version = 1.20.1
|
||||||
|
|
||||||
minecraft_version = 1.20.1
|
minecraft_version = 1.20.1
|
||||||
@@ -17,4 +17,13 @@ cursegradle_version = 1.4.0
|
|||||||
parchment_version = 2023.09.03
|
parchment_version = 2023.09.03
|
||||||
|
|
||||||
flywheel_minecraft_version = 1.20.1
|
flywheel_minecraft_version = 1.20.1
|
||||||
flywheel_version = 0.6.10-7
|
flywheel_version = 1.0.1
|
||||||
|
vanillin_version = 1.0.0-beta-217
|
||||||
|
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
|
||||||
|
}
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
|
mavenCentral()
|
||||||
maven { url = 'https://maven.minecraftforge.net/' }
|
maven { url = 'https://maven.minecraftforge.net/' }
|
||||||
|
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.5.0'
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'Effortless Building'
|
||||||
@@ -17,6 +17,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
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;
|
||||||
@@ -133,7 +134,7 @@ public class ClientEvents {
|
|||||||
|
|
||||||
//Radial menu
|
//Radial menu
|
||||||
if (keyBindings[0].isDown()) {
|
if (keyBindings[0].isDown()) {
|
||||||
if (!EffortlessBuildingClient.POWER_LEVEL.isDisabled(player)) {
|
if (!CapabilityHandler.isDisabled(player)) {
|
||||||
if (!RadialMenu.instance.isVisible()) {
|
if (!RadialMenu.instance.isVisible()) {
|
||||||
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,7 @@ public class ClientEvents {
|
|||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
//Disabled if max reach is 0, might be set in the config that way.
|
//Disabled if max reach is 0, might be set in the config that way.
|
||||||
if (EffortlessBuildingClient.POWER_LEVEL.isDisabled(player)) {
|
if (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());
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ 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.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
@@ -14,9 +16,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||||||
import net.minecraftforge.fml.LogicalSide;
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
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.ModifierSettingsPacket;
|
import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
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;
|
||||||
|
|
||||||
@@ -74,7 +80,10 @@ public class CommonEvents {
|
|||||||
//Don't cancel event if our custom logic is breaking blocks
|
//Don't cancel event if our custom logic is breaking blocks
|
||||||
if (EffortlessBuilding.SERVER_BLOCK_PLACER.isPlacingOrBreakingBlocks()) return;
|
if (EffortlessBuilding.SERVER_BLOCK_PLACER.isPlacingOrBreakingBlocks()) return;
|
||||||
|
|
||||||
if (!ServerBuildState.isLikeVanilla(player) && EffortlessBuilding.SERVER_POWER_LEVEL.canBreakFar(player)) {
|
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)) {
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +103,34 @@ public class CommonEvents {
|
|||||||
ServerBuildState.handleNewPlayer(player);
|
ServerBuildState.handleNewPlayer(player);
|
||||||
|
|
||||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ModifierSettingsPacket(player));
|
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ModifierSettingsPacket(player));
|
||||||
EffortlessBuilding.SERVER_POWER_LEVEL.sendToClient(player);
|
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
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
|
||||||
|
public static void onClone(PlayerEvent.Clone event) {
|
||||||
|
// If not dead, player is returning from the End
|
||||||
|
if (!event.isWasDeath()) return;
|
||||||
|
|
||||||
|
Player original = event.getOriginal();
|
||||||
|
Player clone = event.getEntity();
|
||||||
|
|
||||||
|
// Copy the power level from the original player to the clone
|
||||||
|
original.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataOriginal ->
|
||||||
|
clone.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataClone -> {
|
||||||
|
dataClone.setPowerLevel(dataOriginal.getPowerLevel());
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import nl.requios.effortlessbuilding.proxy.IProxy;
|
|||||||
import nl.requios.effortlessbuilding.proxy.ServerProxy;
|
import nl.requios.effortlessbuilding.proxy.ServerProxy;
|
||||||
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerBlockPlacer;
|
import nl.requios.effortlessbuilding.systems.ServerBlockPlacer;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerPowerLevel;
|
|
||||||
import nl.requios.effortlessbuilding.systems.UndoRedo;
|
import nl.requios.effortlessbuilding.systems.UndoRedo;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -54,7 +53,6 @@ public class EffortlessBuilding {
|
|||||||
public static final ServerBlockPlacer SERVER_BLOCK_PLACER = new ServerBlockPlacer();
|
public static final ServerBlockPlacer SERVER_BLOCK_PLACER = new ServerBlockPlacer();
|
||||||
public static final UndoRedo UNDO_REDO = new UndoRedo();
|
public static final UndoRedo UNDO_REDO = new UndoRedo();
|
||||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||||
public static final ServerPowerLevel SERVER_POWER_LEVEL = new ServerPowerLevel();
|
|
||||||
|
|
||||||
//Registration
|
//Registration
|
||||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ public class EffortlessBuildingClient {
|
|||||||
public static final BlockPreviews BLOCK_PREVIEWS = new BlockPreviews();
|
public static final BlockPreviews BLOCK_PREVIEWS = new BlockPreviews();
|
||||||
public static final BuilderFilter BUILDER_FILTER = new BuilderFilter();
|
public static final BuilderFilter BUILDER_FILTER = new BuilderFilter();
|
||||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||||
public static final PowerLevel POWER_LEVEL = new PowerLevel();
|
|
||||||
|
|
||||||
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
||||||
modEventBus.addListener(EffortlessBuildingClient::clientSetup);
|
modEventBus.addListener(EffortlessBuildingClient::clientSetup);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
|
import nl.requios.effortlessbuilding.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;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (secondPos == null) return;
|
if (secondPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks we can place per row
|
//Limit amount of blocks we can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = 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();
|
||||||
@@ -93,7 +94,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
if (thirdPos == null) return;
|
if (thirdPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks you can place per row
|
//Limit amount of blocks you can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = 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();
|
||||||
@@ -139,7 +140,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
|||||||
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
|
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
|
||||||
|
|
||||||
//Remove invalid criteria
|
//Remove invalid criteria
|
||||||
int reach = EffortlessBuildingClient.POWER_LEVEL.getBuildModeReach(player);
|
int reach = 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,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
|
import nl.requios.effortlessbuilding.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;
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
|||||||
if (secondPos == null) return;
|
if (secondPos == null) return;
|
||||||
|
|
||||||
//Limit amount of blocks we can place per row
|
//Limit amount of blocks we can place per row
|
||||||
int axisLimit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
int axisLimit = 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();
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
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 = EffortlessBuildingClient.POWER_LEVEL.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.EffortlessBuildingClient;
|
|
||||||
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 = EffortlessBuildingClient.POWER_LEVEL.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
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
|||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
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 = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(player);
|
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;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
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 = EffortlessBuildingClient.POWER_LEVEL.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
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
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;
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ public class Mirror extends BaseModifier {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPowerLevelChanged(int powerLevel) {
|
public void onPowerLevelChanged(int powerLevel) {
|
||||||
radius = EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player);
|
radius = CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performMirrorX(BlockSet blocks, BlockEntry blockEntry) {
|
private void performMirrorX(BlockSet blocks, BlockEntry blockEntry) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import net.minecraft.world.level.block.Rotation;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.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 = EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player);
|
radius = CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package nl.requios.effortlessbuilding.capability;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
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.EffortlessBuilding;
|
||||||
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
|
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||||
|
|
||||||
|
public class CapabilityHandler {
|
||||||
|
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) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Helper methods to reduce boilerplate code
|
||||||
|
public static boolean canReplaceBlocks(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canReplaceBlocks(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxBlocksPerAxis(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxBlocksPerAxis.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxBlocksPlacedAtOnce(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getMaxMirrorRadius(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxMirrorRadius.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBuildModeReach(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getBuildModeReach(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.maxMirrorRadius.level0.get() + 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getPlacementReach(player, nextPowerLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonConfig.reach.level0.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getPowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNextPowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.getNextPowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canIncreasePowerLevel(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canIncreasePowerLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isDisabled(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.isDisabled(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canBreakFar(Player player) {
|
||||||
|
if (player != null) {
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
return powerLevel.canBreakFar(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,9 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create;
|
package nl.requios.effortlessbuilding.create;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import net.createmod.catnip.render.BindableTexture;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
public enum AllSpecialTextures {
|
public enum AllSpecialTextures implements BindableTexture {
|
||||||
|
|
||||||
BLANK("blank.png"),
|
BLANK("blank.png"),
|
||||||
CHECKERED("checkerboard.png"),
|
CHECKERED("checkerboard.png"),
|
||||||
@@ -18,7 +19,7 @@ public enum AllSpecialTextures {
|
|||||||
public static final String ASSET_PATH = "textures/special/";
|
public static final String ASSET_PATH = "textures/special/";
|
||||||
private ResourceLocation location;
|
private ResourceLocation location;
|
||||||
|
|
||||||
private AllSpecialTextures(String filename) {
|
AllSpecialTextures(String filename) {
|
||||||
location = Create.asResource(ASSET_PATH + filename);
|
location = Create.asResource(ASSET_PATH + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create;
|
package nl.requios.effortlessbuilding.create;
|
||||||
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache;
|
import net.createmod.catnip.render.SuperByteBufferCache;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.ghost.GhostBlocks;
|
import nl.requios.effortlessbuilding.create.foundation.utility.ghost.GhostBlocks;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.outliner.Outliner;
|
|
||||||
|
|
||||||
public class CreateClient {
|
public class CreateClient {
|
||||||
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
||||||
public static final Outliner OUTLINER = new Outliner();
|
|
||||||
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
||||||
|
|
||||||
public static void invalidateRenderers() {
|
public static void invalidateRenderers() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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.outliner.Outliner;
|
||||||
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;
|
||||||
@@ -16,10 +17,11 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import nl.requios.effortlessbuilding.create.Create;
|
import nl.requios.effortlessbuilding.create.Create;
|
||||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHolder;
|
import nl.requios.effortlessbuilding.create.foundation.utility.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 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 {
|
||||||
@@ -34,7 +36,7 @@ public class ClientEvents {
|
|||||||
AnimationTickHolder.tick();
|
AnimationTickHolder.tick();
|
||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.tickGhosts();
|
CreateClient.GHOST_BLOCKS.tickGhosts();
|
||||||
CreateClient.OUTLINER.tickOutlines();
|
// Outliner.getInstance().tickOutlines();
|
||||||
CameraAngleAnimationService.tick();
|
CameraAngleAnimationService.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +69,11 @@ public class ClientEvents {
|
|||||||
PoseStack ms = event.getPoseStack();
|
PoseStack ms = event.getPoseStack();
|
||||||
ms.pushPose();
|
ms.pushPose();
|
||||||
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
||||||
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
SuperRenderTypeBuffer buffer = DefaultSuperRenderTypeBuffer.getInstance();
|
||||||
|
|
||||||
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
||||||
|
|
||||||
CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
// Outliner.getInstance().renderOutlines(ms, buffer, pt);
|
||||||
buffer.draw();
|
buffer.draw();
|
||||||
RenderSystem.enableCull();
|
RenderSystem.enableCull();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
import net.createmod.catnip.render.StitchedSprite;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import net.minecraft.world.entity.player.Inventory;
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.PartialModel;
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
||||||
import com.mojang.blaze3d.platform.Lighting;
|
import com.mojang.blaze3d.platform.Lighting;
|
||||||
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.math.Axis;
|
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.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
@@ -184,19 +184,19 @@ public class GuiGameElement {
|
|||||||
RenderType renderType = Sheets.translucentCullBlockSheet();
|
RenderType renderType = Sheets.translucentCullBlockSheet();
|
||||||
blockRenderer.getModelRenderer()
|
blockRenderer.getModelRenderer()
|
||||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel, 1, 1, 1,
|
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel, 1, 1, 1,
|
||||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, null);
|
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, VirtualRenderHelper.VIRTUAL_DATA, null);
|
||||||
} else {
|
} else {
|
||||||
int color = Minecraft.getInstance()
|
int color = Minecraft.getInstance()
|
||||||
.getBlockColors()
|
.getBlockColors()
|
||||||
.getColor(blockState, null, null, 0);
|
.getColor(blockState, null, null, 0);
|
||||||
Color rgb = new Color(color == -1 ? this.color : color);
|
Color rgb = new Color(color == -1 ? this.color : color);
|
||||||
|
|
||||||
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), ModelUtil.VIRTUAL_DATA)) {
|
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), VirtualRenderHelper.VIRTUAL_DATA)) {
|
||||||
RenderType renderType = RenderTypeHelper.getEntityRenderType(chunkType, true);
|
RenderType renderType = RenderTypeHelper.getEntityRenderType(chunkType, true);
|
||||||
blockRenderer.getModelRenderer()
|
blockRenderer.getModelRenderer()
|
||||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel,
|
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel,
|
||||||
rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(),
|
rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(),
|
||||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, chunkType);
|
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, VirtualRenderHelper.VIRTUAL_DATA, chunkType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
|
||||||
import net.minecraft.client.resources.model.BakedModel;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
|
|
||||||
public class BakedModelRenderHelper {
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardBlockRender(BlockState renderedState) {
|
|
||||||
BlockRenderDispatcher dispatcher = Minecraft.getInstance()
|
|
||||||
.getBlockRenderer();
|
|
||||||
return standardModelRender(dispatcher.getBlockModel(renderedState), renderedState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState) {
|
|
||||||
return standardModelRender(model, referenceState, new PoseStack());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState, PoseStack ms) {
|
|
||||||
ShadeSeparatedBufferedData data = ModelUtil.getBufferedData(model, referenceState, ms);
|
|
||||||
SuperByteBuffer sbb = new SuperByteBuffer(data);
|
|
||||||
data.release();
|
|
||||||
return sbb;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.PartialModel;
|
|
||||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache.Compartment;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.AngleHelper;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING;
|
|
||||||
|
|
||||||
public class CachedBufferer {
|
|
||||||
|
|
||||||
public static final Compartment<BlockState> GENERIC_TILE = new Compartment<>();
|
|
||||||
public static final Compartment<PartialModel> PARTIAL = new Compartment<>();
|
|
||||||
public static final Compartment<Pair<Direction, PartialModel>> DIRECTIONAL_PARTIAL = new Compartment<>();
|
|
||||||
|
|
||||||
public static SuperByteBuffer block(BlockState toRender) {
|
|
||||||
return block(GENERIC_TILE, toRender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer block(Compartment<BlockState> compartment, BlockState toRender) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(compartment, toRender, () -> BakedModelRenderHelper.standardBlockRender(toRender));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState,
|
|
||||||
Supplier<PoseStack> modelTransform) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState) {
|
|
||||||
Direction facing = referenceState.getValue(FACING);
|
|
||||||
return partialFacing(partial, referenceState, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState, Direction facing) {
|
|
||||||
return partialDirectional(partial, referenceState, facing,
|
|
||||||
rotateToFace(facing));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialFacingVertical(PartialModel partial, BlockState referenceState, Direction facing) {
|
|
||||||
return partialDirectional(partial, referenceState, facing,
|
|
||||||
rotateToFaceVertical(facing));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SuperByteBuffer partialDirectional(PartialModel partial, BlockState referenceState, Direction dir,
|
|
||||||
Supplier<PoseStack> modelTransform) {
|
|
||||||
return CreateClient.BUFFER_CACHE.get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial),
|
|
||||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Supplier<PoseStack> rotateToFace(Direction facing) {
|
|
||||||
return () -> {
|
|
||||||
PoseStack stack = new PoseStack();
|
|
||||||
TransformStack.cast(stack)
|
|
||||||
.centre()
|
|
||||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
||||||
.rotateX(AngleHelper.verticalAngle(facing))
|
|
||||||
.unCentre();
|
|
||||||
return stack;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Supplier<PoseStack> rotateToFaceVertical(Direction facing) {
|
|
||||||
return () -> {
|
|
||||||
PoseStack stack = new PoseStack();
|
|
||||||
TransformStack.cast(stack)
|
|
||||||
.centre()
|
|
||||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
||||||
.rotateX(AngleHelper.verticalAngle(facing) + 90)
|
|
||||||
.unCentre();
|
|
||||||
return stack;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public final class ForcedDiffuseState {
|
|
||||||
private static final ThreadLocal<ObjectArrayList<DiffuseLightCalculator>> FORCED_DIFFUSE = ThreadLocal.withInitial(ObjectArrayList::new);
|
|
||||||
|
|
||||||
private ForcedDiffuseState() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void pushCalculator(DiffuseLightCalculator calculator) {
|
|
||||||
FORCED_DIFFUSE.get().push(calculator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void popCalculator() {
|
|
||||||
FORCED_DIFFUSE.get().pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static DiffuseLightCalculator getForcedCalculator() {
|
|
||||||
ObjectArrayList<DiffuseLightCalculator> stack = FORCED_DIFFUSE.get();
|
|
||||||
if (stack.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return stack.top();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,492 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
|
||||||
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
|
|
||||||
import com.jozufozu.flywheel.util.Color;
|
|
||||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
|
||||||
import com.jozufozu.flywheel.util.transform.TStack;
|
|
||||||
import com.jozufozu.flywheel.util.transform.Transform;
|
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2IntMap;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.block.render.SpriteShiftEntry;
|
|
||||||
import org.joml.Matrix3f;
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.joml.Quaternionf;
|
|
||||||
import org.joml.Vector3f;
|
|
||||||
import org.joml.Vector4f;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.function.IntPredicate;
|
|
||||||
|
|
||||||
public class SuperByteBuffer implements Transform<SuperByteBuffer>, TStack<SuperByteBuffer> {
|
|
||||||
|
|
||||||
private final VertexList template;
|
|
||||||
private final IntPredicate shadedPredicate;
|
|
||||||
|
|
||||||
// Vertex Position
|
|
||||||
private final PoseStack transforms = new PoseStack();
|
|
||||||
|
|
||||||
// Vertex Coloring
|
|
||||||
private boolean shouldColor;
|
|
||||||
private int r, g, b, a;
|
|
||||||
private boolean disableDiffuseMult;
|
|
||||||
private DiffuseLightCalculator diffuseCalculator;
|
|
||||||
|
|
||||||
// Vertex Texture Coords
|
|
||||||
private SpriteShiftFunc spriteShiftFunc;
|
|
||||||
|
|
||||||
// Vertex Overlay Color
|
|
||||||
private boolean hasOverlay;
|
|
||||||
private int overlay = OverlayTexture.NO_OVERLAY;
|
|
||||||
|
|
||||||
// Vertex Lighting
|
|
||||||
private boolean useWorldLight;
|
|
||||||
private Matrix4f lightTransform;
|
|
||||||
private boolean hasCustomLight;
|
|
||||||
private int packedLightCoords;
|
|
||||||
private boolean hybridLight;
|
|
||||||
|
|
||||||
// Vertex Normals
|
|
||||||
private boolean fullNormalTransform;
|
|
||||||
|
|
||||||
// Temporary
|
|
||||||
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
|
|
||||||
|
|
||||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState, int unshadedStartVertex) {
|
|
||||||
int vertexCount = drawState.vertexCount();
|
|
||||||
int stride = drawState.format().getVertexSize();
|
|
||||||
|
|
||||||
ShadedVertexList template = new BlockVertexList.Shaded(vertexBuffer, vertexCount, stride, unshadedStartVertex);
|
|
||||||
shadedPredicate = template::isShaded;
|
|
||||||
this.template = template;
|
|
||||||
|
|
||||||
transforms.pushPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer(ShadeSeparatedBufferedData data) {
|
|
||||||
this(data.vertexBuffer(), data.drawState(), data.unshadedStartVertex());
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState) {
|
|
||||||
int vertexCount = drawState.vertexCount();
|
|
||||||
int stride = drawState.format().getVertexSize();
|
|
||||||
|
|
||||||
template = new BlockVertexList(vertexBuffer, vertexCount, stride);
|
|
||||||
shadedPredicate = index -> true;
|
|
||||||
|
|
||||||
transforms.pushPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderInto(PoseStack input, VertexConsumer builder) {
|
|
||||||
if (isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Matrix4f modelMat = new Matrix4f(input.last()
|
|
||||||
.pose());
|
|
||||||
Matrix4f localTransforms = transforms.last()
|
|
||||||
.pose();
|
|
||||||
modelMat.mul(localTransforms);
|
|
||||||
|
|
||||||
Matrix3f normalMat;
|
|
||||||
if (fullNormalTransform) {
|
|
||||||
normalMat = new Matrix3f(input.last()
|
|
||||||
.normal());
|
|
||||||
Matrix3f localNormalTransforms = transforms.last()
|
|
||||||
.normal();
|
|
||||||
normalMat.mul(localNormalTransforms);
|
|
||||||
} else {
|
|
||||||
normalMat = new Matrix3f(transforms.last()
|
|
||||||
.normal());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useWorldLight) {
|
|
||||||
WORLD_LIGHT_CACHE.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
final Vector4f pos = new Vector4f();
|
|
||||||
final Vector3f normal = new Vector3f();
|
|
||||||
final Vector4f lightPos = new Vector4f();
|
|
||||||
|
|
||||||
DiffuseLightCalculator diffuseCalculator = ForcedDiffuseState.getForcedCalculator();
|
|
||||||
final boolean disableDiffuseMult =
|
|
||||||
this.disableDiffuseMult || (ShadersModHandler.isShaderPackInUse() && diffuseCalculator == null);
|
|
||||||
if (diffuseCalculator == null) {
|
|
||||||
diffuseCalculator = this.diffuseCalculator;
|
|
||||||
if (diffuseCalculator == null) {
|
|
||||||
diffuseCalculator = DiffuseLightCalculator.forCurrentLevel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final int vertexCount = template.getVertexCount();
|
|
||||||
for (int i = 0; i < vertexCount; i++) {
|
|
||||||
float x = template.getX(i);
|
|
||||||
float y = template.getY(i);
|
|
||||||
float z = template.getZ(i);
|
|
||||||
|
|
||||||
pos.set(x, y, z, 1F);
|
|
||||||
pos.mul(modelMat);
|
|
||||||
builder.vertex(pos.x(), pos.y(), pos.z());
|
|
||||||
|
|
||||||
float normalX = template.getNX(i);
|
|
||||||
float normalY = template.getNY(i);
|
|
||||||
float normalZ = template.getNZ(i);
|
|
||||||
|
|
||||||
normal.set(normalX, normalY, normalZ);
|
|
||||||
normal.mul(normalMat);
|
|
||||||
float nx = normal.x();
|
|
||||||
float ny = normal.y();
|
|
||||||
float nz = normal.z();
|
|
||||||
|
|
||||||
byte r, g, b, a;
|
|
||||||
if (shouldColor) {
|
|
||||||
r = (byte) this.r;
|
|
||||||
g = (byte) this.g;
|
|
||||||
b = (byte) this.b;
|
|
||||||
a = (byte) this.a;
|
|
||||||
} else {
|
|
||||||
r = template.getR(i);
|
|
||||||
g = template.getG(i);
|
|
||||||
b = template.getB(i);
|
|
||||||
a = template.getA(i);
|
|
||||||
}
|
|
||||||
if (disableDiffuseMult) {
|
|
||||||
builder.color(r, g, b, a);
|
|
||||||
} else {
|
|
||||||
float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz, shadedPredicate.test(i));
|
|
||||||
int colorR = transformColor(r, instanceDiffuse);
|
|
||||||
int colorG = transformColor(g, instanceDiffuse);
|
|
||||||
int colorB = transformColor(b, instanceDiffuse);
|
|
||||||
builder.color(colorR, colorG, colorB, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
float u = template.getU(i);
|
|
||||||
float v = template.getV(i);
|
|
||||||
if (spriteShiftFunc != null) {
|
|
||||||
spriteShiftFunc.shift(builder, u, v);
|
|
||||||
} else {
|
|
||||||
builder.uv(u, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasOverlay) {
|
|
||||||
builder.overlayCoords(overlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
int light;
|
|
||||||
if (useWorldLight) {
|
|
||||||
lightPos.set(((x - .5f) * 15 / 16f) + .5f, (y - .5f) * 15 / 16f + .5f, (z - .5f) * 15 / 16f + .5f, 1f);
|
|
||||||
lightPos.mul(localTransforms);
|
|
||||||
if (lightTransform != null) {
|
|
||||||
lightPos.mul(lightTransform);
|
|
||||||
}
|
|
||||||
|
|
||||||
light = getLight(Minecraft.getInstance().level, lightPos);
|
|
||||||
if (hasCustomLight) {
|
|
||||||
light = maxLight(light, packedLightCoords);
|
|
||||||
}
|
|
||||||
} else if (hasCustomLight) {
|
|
||||||
light = packedLightCoords;
|
|
||||||
} else {
|
|
||||||
light = template.getLight(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hybridLight) {
|
|
||||||
builder.uv2(maxLight(light, template.getLight(i)));
|
|
||||||
} else {
|
|
||||||
builder.uv2(light);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.normal(nx, ny, nz);
|
|
||||||
|
|
||||||
builder.endVertex();
|
|
||||||
}
|
|
||||||
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer reset() {
|
|
||||||
while (!transforms.clear())
|
|
||||||
transforms.popPose();
|
|
||||||
transforms.pushPose();
|
|
||||||
|
|
||||||
shouldColor = false;
|
|
||||||
r = 0;
|
|
||||||
g = 0;
|
|
||||||
b = 0;
|
|
||||||
a = 0;
|
|
||||||
disableDiffuseMult = false;
|
|
||||||
diffuseCalculator = null;
|
|
||||||
spriteShiftFunc = null;
|
|
||||||
hasOverlay = false;
|
|
||||||
overlay = OverlayTexture.NO_OVERLAY;
|
|
||||||
useWorldLight = false;
|
|
||||||
lightTransform = null;
|
|
||||||
hasCustomLight = false;
|
|
||||||
packedLightCoords = 0;
|
|
||||||
hybridLight = false;
|
|
||||||
fullNormalTransform = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return template.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() {
|
|
||||||
template.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PoseStack getTransforms() {
|
|
||||||
return transforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer translate(double x, double y, double z) {
|
|
||||||
transforms.translate(x, y, z);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer multiply(Quaternionf quaternion) {
|
|
||||||
transforms.mulPose(quaternion);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer scale(float factorX, float factorY, float factorZ) {
|
|
||||||
transforms.scale(factorX, factorY, factorZ);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer pushPose() {
|
|
||||||
transforms.pushPose();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer popPose() {
|
|
||||||
transforms.popPose();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer mulPose(Matrix4f pose) {
|
|
||||||
transforms.last()
|
|
||||||
.pose()
|
|
||||||
.mul(pose);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SuperByteBuffer mulNormal(Matrix3f normal) {
|
|
||||||
transforms.last()
|
|
||||||
.normal()
|
|
||||||
.mul(normal);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer transform(PoseStack stack) {
|
|
||||||
transforms.last()
|
|
||||||
.pose()
|
|
||||||
.mul(stack.last()
|
|
||||||
.pose());
|
|
||||||
transforms.last()
|
|
||||||
.normal()
|
|
||||||
.mul(stack.last()
|
|
||||||
.normal());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer rotateCentered(Direction axis, float radians) {
|
|
||||||
translate(.5f, .5f, .5f).rotate(axis, radians)
|
|
||||||
.translate(-.5f, -.5f, -.5f);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer rotateCentered(Quaternionf q) {
|
|
||||||
translate(.5f, .5f, .5f).multiply(q)
|
|
||||||
.translate(-.5f, -.5f, -.5f);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(int r, int g, int b, int a) {
|
|
||||||
shouldColor = true;
|
|
||||||
this.r = r;
|
|
||||||
this.g = g;
|
|
||||||
this.b = b;
|
|
||||||
this.a = a;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(int color) {
|
|
||||||
shouldColor = true;
|
|
||||||
r = ((color >> 16) & 0xFF);
|
|
||||||
g = ((color >> 8) & 0xFF);
|
|
||||||
b = (color & 0xFF);
|
|
||||||
a = 255;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer color(Color c) {
|
|
||||||
return color(c.getRGB());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevents vertex colors from being multiplied by the diffuse value calculated
|
|
||||||
* from the final transformed normal vector. Useful for entity rendering, when
|
|
||||||
* diffuse is applied automatically later.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer disableDiffuse() {
|
|
||||||
disableDiffuseMult = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer diffuseCalculator(DiffuseLightCalculator diffuseCalculator) {
|
|
||||||
this.diffuseCalculator = diffuseCalculator;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUV(SpriteShiftEntry entry) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
builder.uv(entry.getTargetU(u), entry.getTargetV(v));
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollV) {
|
|
||||||
return this.shiftUVScrolling(entry, 0, scrollV);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollU, float scrollV) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
float targetU = u - entry.getOriginal()
|
|
||||||
.getU0() + entry.getTarget()
|
|
||||||
.getU0()
|
|
||||||
+ scrollU;
|
|
||||||
float targetV = v - entry.getOriginal()
|
|
||||||
.getV0() + entry.getTarget()
|
|
||||||
.getV0()
|
|
||||||
+ scrollV;
|
|
||||||
builder.uv(targetU, targetV);
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) {
|
|
||||||
this.spriteShiftFunc = (builder, u, v) -> {
|
|
||||||
float targetU = entry.getTarget()
|
|
||||||
.getU((SpriteShiftEntry.getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16);
|
|
||||||
float targetV = entry.getTarget()
|
|
||||||
.getV((SpriteShiftEntry.getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16);
|
|
||||||
builder.uv(targetU, targetV);
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer overlay() {
|
|
||||||
hasOverlay = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer overlay(int overlay) {
|
|
||||||
hasOverlay = true;
|
|
||||||
this.overlay = overlay;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light() {
|
|
||||||
useWorldLight = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(Matrix4f lightTransform) {
|
|
||||||
useWorldLight = true;
|
|
||||||
this.lightTransform = lightTransform;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(int packedLightCoords) {
|
|
||||||
hasCustomLight = true;
|
|
||||||
this.packedLightCoords = packedLightCoords;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer light(Matrix4f lightTransform, int packedLightCoords) {
|
|
||||||
light(lightTransform);
|
|
||||||
light(packedLightCoords);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses max light from calculated light (world light or custom light) and vertex
|
|
||||||
* light for the final light value. Ineffective if any other light method was
|
|
||||||
* not called.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer hybridLight() {
|
|
||||||
hybridLight = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms normals not only by the local matrix stack, but also by the passed
|
|
||||||
* matrix stack.
|
|
||||||
*/
|
|
||||||
public SuperByteBuffer fullNormalTransform() {
|
|
||||||
fullNormalTransform = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuperByteBuffer forEntityRender() {
|
|
||||||
disableDiffuse();
|
|
||||||
overlay();
|
|
||||||
fullNormalTransform();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int transformColor(byte component, float scale) {
|
|
||||||
return Mth.clamp((int) (Byte.toUnsignedInt(component) * scale), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int transformColor(int component, float scale) {
|
|
||||||
return Mth.clamp((int) (component * scale), 0, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int maxLight(int packedLight1, int packedLight2) {
|
|
||||||
int blockLight1 = LightTexture.block(packedLight1);
|
|
||||||
int skyLight1 = LightTexture.sky(packedLight1);
|
|
||||||
int blockLight2 = LightTexture.block(packedLight2);
|
|
||||||
int skyLight2 = LightTexture.sky(packedLight2);
|
|
||||||
return LightTexture.pack(Math.max(blockLight1, blockLight2), Math.max(skyLight1, skyLight2));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getLight(Level world, Vector4f lightPos) {
|
|
||||||
BlockPos pos = BlockPos.containing(lightPos.x(), lightPos.y(), lightPos.z());
|
|
||||||
return WORLD_LIGHT_CACHE.computeIfAbsent(pos.asLong(), $ -> LevelRenderer.getLightColor(world, pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface SpriteShiftFunc {
|
|
||||||
void shift(VertexConsumer builder, float u, float v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface VertexLighter {
|
|
||||||
int getPackedLight(float x, float y, float z);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
|
|
||||||
public class SuperByteBufferCache {
|
|
||||||
|
|
||||||
protected final Map<Compartment<?>, Cache<Object, SuperByteBuffer>> caches = new HashMap<>();
|
|
||||||
|
|
||||||
public synchronized void registerCompartment(Compartment<?> compartment) {
|
|
||||||
caches.put(compartment, CacheBuilder.newBuilder()
|
|
||||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void registerCompartment(Compartment<?> compartment, long ticksUntilExpired) {
|
|
||||||
caches.put(compartment, CacheBuilder.newBuilder()
|
|
||||||
.expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS)
|
|
||||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> SuperByteBuffer get(Compartment<T> compartment, T key, Callable<SuperByteBuffer> callable) {
|
|
||||||
Cache<Object, SuperByteBuffer> cache = caches.get(compartment);
|
|
||||||
if (cache != null) {
|
|
||||||
try {
|
|
||||||
return cache.get(key, callable);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void invalidate(Compartment<T> compartment, T key) {
|
|
||||||
caches.get(compartment).invalidate(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void invalidate(Compartment<?> compartment) {
|
|
||||||
caches.get(compartment).invalidateAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate() {
|
|
||||||
caches.forEach((compartment, cache) -> cache.invalidateAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Compartment<T> {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import java.util.SortedMap;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
|
||||||
import net.minecraft.Util;
|
|
||||||
import net.minecraft.client.renderer.ChunkBufferBuilderPack;
|
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.Sheets;
|
|
||||||
import net.minecraft.client.resources.model.ModelBakery;
|
|
||||||
|
|
||||||
public class SuperRenderTypeBuffer implements MultiBufferSource {
|
|
||||||
|
|
||||||
private static final SuperRenderTypeBuffer INSTANCE = new SuperRenderTypeBuffer();
|
|
||||||
|
|
||||||
public static SuperRenderTypeBuffer getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SuperRenderTypeBufferPhase earlyBuffer;
|
|
||||||
private SuperRenderTypeBufferPhase defaultBuffer;
|
|
||||||
private SuperRenderTypeBufferPhase lateBuffer;
|
|
||||||
|
|
||||||
public SuperRenderTypeBuffer() {
|
|
||||||
earlyBuffer = new SuperRenderTypeBufferPhase();
|
|
||||||
defaultBuffer = new SuperRenderTypeBufferPhase();
|
|
||||||
lateBuffer = new SuperRenderTypeBufferPhase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexConsumer getEarlyBuffer(RenderType type) {
|
|
||||||
return earlyBuffer.bufferSource.getBuffer(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VertexConsumer getBuffer(RenderType type) {
|
|
||||||
return defaultBuffer.bufferSource.getBuffer(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexConsumer getLateBuffer(RenderType type) {
|
|
||||||
return lateBuffer.bufferSource.getBuffer(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw() {
|
|
||||||
earlyBuffer.bufferSource.endBatch();
|
|
||||||
defaultBuffer.bufferSource.endBatch();
|
|
||||||
lateBuffer.bufferSource.endBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(RenderType type) {
|
|
||||||
earlyBuffer.bufferSource.endBatch(type);
|
|
||||||
defaultBuffer.bufferSource.endBatch(type);
|
|
||||||
lateBuffer.bufferSource.endBatch(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SuperRenderTypeBufferPhase {
|
|
||||||
|
|
||||||
// Visible clones from RenderBuffers
|
|
||||||
private final ChunkBufferBuilderPack fixedBufferPack = new ChunkBufferBuilderPack();
|
|
||||||
private final SortedMap<RenderType, BufferBuilder> fixedBuffers = Util.make(new Object2ObjectLinkedOpenHashMap<>(), map -> {
|
|
||||||
map.put(Sheets.solidBlockSheet(), fixedBufferPack.builder(RenderType.solid()));
|
|
||||||
map.put(Sheets.cutoutBlockSheet(), fixedBufferPack.builder(RenderType.cutout()));
|
|
||||||
map.put(Sheets.bannerSheet(), fixedBufferPack.builder(RenderType.cutoutMipped()));
|
|
||||||
map.put(Sheets.translucentCullBlockSheet(), fixedBufferPack.builder(RenderType.translucent()));
|
|
||||||
put(map, Sheets.shieldSheet());
|
|
||||||
put(map, Sheets.bedSheet());
|
|
||||||
put(map, Sheets.shulkerBoxSheet());
|
|
||||||
put(map, Sheets.signSheet());
|
|
||||||
put(map, Sheets.chestSheet());
|
|
||||||
put(map, RenderType.translucentNoCrumbling());
|
|
||||||
put(map, RenderType.armorGlint());
|
|
||||||
put(map, RenderType.armorEntityGlint());
|
|
||||||
put(map, RenderType.glint());
|
|
||||||
put(map, RenderType.glintDirect());
|
|
||||||
put(map, RenderType.glintTranslucent());
|
|
||||||
put(map, RenderType.entityGlint());
|
|
||||||
put(map, RenderType.entityGlintDirect());
|
|
||||||
put(map, RenderType.waterMask());
|
|
||||||
put(map, RenderTypes.getOutlineSolid());
|
|
||||||
ModelBakery.DESTROY_TYPES.forEach((p_173062_) -> {
|
|
||||||
put(map, p_173062_);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
private final BufferSource bufferSource = MultiBufferSource.immediateWithBuffers(fixedBuffers, new BufferBuilder(256));
|
|
||||||
|
|
||||||
private static void put(Object2ObjectLinkedOpenHashMap<RenderType, BufferBuilder> map, RenderType type) {
|
|
||||||
map.put(type, new BufferBuilder(type.bufferSize()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
|
||||||
import com.jozufozu.flywheel.config.BackendType;
|
|
||||||
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
|
|
||||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
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.utility.AnimationTickHolder;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.RegisteredObjects;
|
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.joml.Vector4f;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class TileEntityRenderHelper {
|
|
||||||
|
|
||||||
public static void renderTileEntities(Level world, Iterable<BlockEntity> customRenderTEs, PoseStack ms,
|
|
||||||
MultiBufferSource buffer) {
|
|
||||||
renderTileEntities(world, null, customRenderTEs, ms, null, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderTileEntities(Level world, Iterable<BlockEntity> customRenderTEs, PoseStack ms,
|
|
||||||
MultiBufferSource buffer, float pt) {
|
|
||||||
renderTileEntities(world, null, customRenderTEs, ms, null, buffer, pt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderTileEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
|
||||||
Iterable<BlockEntity> customRenderTEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer) {
|
|
||||||
renderTileEntities(world, renderWorld, customRenderTEs, ms, lightTransform, buffer,
|
|
||||||
AnimationTickHolder.getPartialTicks());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderTileEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
|
||||||
Iterable<BlockEntity> customRenderTEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer,
|
|
||||||
float pt) {
|
|
||||||
Iterator<BlockEntity> iterator = customRenderTEs.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
BlockEntity tileEntity = iterator.next();
|
|
||||||
if (Backend.getBackendType() == BackendType.INSTANCING && Backend.isFlywheelWorld(renderWorld) && InstancedRenderRegistry.shouldSkipRender(tileEntity))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(tileEntity);
|
|
||||||
if (renderer == null) {
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockPos pos = tileEntity.getBlockPos();
|
|
||||||
ms.pushPose();
|
|
||||||
TransformStack.cast(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
|
|
||||||
tileEntity.setLevel(renderWorld);
|
|
||||||
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
|
||||||
tileEntity.setLevel(world);
|
|
||||||
} else {
|
|
||||||
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
iterator.remove();
|
|
||||||
|
|
||||||
String message = "BlockEntity " + RegisteredObjects.getKeyOrThrow(tileEntity.getType())
|
|
||||||
.toString() + " could not be rendered virtually.";
|
|
||||||
// if (AllConfigs.CLIENT.explainRenderErrors.get())
|
|
||||||
Create.LOGGER.error(message, e);
|
|
||||||
// else
|
|
||||||
// Create.LOGGER.error(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BlockPos getLightPos(@Nullable Matrix4f lightTransform, BlockPos contraptionPos) {
|
|
||||||
if (lightTransform != null) {
|
|
||||||
Vector4f lightVec = new Vector4f(contraptionPos.getX() + .5f, contraptionPos.getY() + .5f, contraptionPos.getZ() + .5f, 1);
|
|
||||||
lightVec.mul(lightTransform);
|
|
||||||
return BlockPos.containing(lightVec.x(), lightVec.y(), lightVec.z());
|
|
||||||
} else {
|
|
||||||
return contraptionPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getCombinedLight(Level world, BlockPos worldPos, @Nullable VirtualRenderWorld renderWorld,
|
|
||||||
BlockPos renderWorldPos) {
|
|
||||||
int worldLight = LevelRenderer.getLightColor(world, worldPos);
|
|
||||||
|
|
||||||
if (renderWorld != null) {
|
|
||||||
int renderWorldLight = LevelRenderer.getLightColor(renderWorld, renderWorldPos);
|
|
||||||
return SuperByteBuffer.maxLight(worldLight, renderWorldLight);
|
|
||||||
}
|
|
||||||
|
|
||||||
return worldLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
||||||
|
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
|
||||||
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 nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
|
import net.createmod.ponder.render.VirtualRenderHelper;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
import net.minecraft.client.renderer.LevelRenderer;
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
@@ -19,7 +20,6 @@ import net.minecraft.util.Mth;
|
|||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.client.model.data.ModelData;
|
import net.minecraftforge.client.model.data.ModelData;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -56,10 +56,10 @@ public abstract class GhostBlockRenderer {
|
|||||||
ms.pushPose();
|
ms.pushPose();
|
||||||
ms.translate(pos.getX(), pos.getY(), pos.getZ());
|
ms.translate(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
|
||||||
for (RenderType layer : model.getRenderTypes(state, RandomSource.create(42L), ModelUtil.VIRTUAL_DATA)) {
|
for (RenderType layer : model.getRenderTypes(state, RandomSource.create(42L), VirtualRenderHelper.VIRTUAL_DATA)) {
|
||||||
VertexConsumer vb = buffer.getEarlyBuffer(layer);
|
VertexConsumer vb = buffer.getEarlyBuffer(layer);
|
||||||
renderer.renderModel(ms.last(), vb, state, model, 1f, 1f, 1f, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY,
|
renderer.renderModel(ms.last(), vb, state, model, 1f, 1f, 1f, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY,
|
||||||
ModelUtil.VIRTUAL_DATA, layer);
|
VirtualRenderHelper.VIRTUAL_DATA, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ms.popPose();
|
ms.popPose();
|
||||||
@@ -92,8 +92,7 @@ public abstract class GhostBlockRenderer {
|
|||||||
ms.translate(-.5, -.5, -.5);
|
ms.translate(-.5, -.5, -.5);
|
||||||
|
|
||||||
renderModel(ms.last(), vb, state, model, color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat(), alpha,
|
renderModel(ms.last(), vb, state, model, color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat(), alpha,
|
||||||
LevelRenderer.getLightColor(mc.level, pos), OverlayTexture.NO_OVERLAY,
|
LevelRenderer.getLightColor(mc.level, pos), OverlayTexture.NO_OVERLAY, VirtualRenderHelper.VIRTUAL_DATA, layer);
|
||||||
ModelUtil.VIRTUAL_DATA, layer);
|
|
||||||
|
|
||||||
ms.popPose();
|
ms.popPose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.core.Direction.Axis;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
public class AABBOutline extends Outline {
|
|
||||||
|
|
||||||
protected AABB bb;
|
|
||||||
|
|
||||||
public AABBOutline(AABB bb) {
|
|
||||||
this.setBounds(bb);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
renderBB(ms, buffer, bb);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderBB(PoseStack ms, SuperRenderTypeBuffer buffer, AABB bb) {
|
|
||||||
Vec3 projectedView = Minecraft.getInstance().gameRenderer.getMainCamera()
|
|
||||||
.getPosition();
|
|
||||||
boolean noCull = bb.contains(projectedView);
|
|
||||||
bb = bb.inflate(noCull ? -1 / 128d : 1 / 128d);
|
|
||||||
noCull |= params.disableCull;
|
|
||||||
|
|
||||||
Vec3 xyz = new Vec3(bb.minX, bb.minY, bb.minZ);
|
|
||||||
Vec3 Xyz = new Vec3(bb.maxX, bb.minY, bb.minZ);
|
|
||||||
Vec3 xYz = new Vec3(bb.minX, bb.maxY, bb.minZ);
|
|
||||||
Vec3 XYz = new Vec3(bb.maxX, bb.maxY, bb.minZ);
|
|
||||||
Vec3 xyZ = new Vec3(bb.minX, bb.minY, bb.maxZ);
|
|
||||||
Vec3 XyZ = new Vec3(bb.maxX, bb.minY, bb.maxZ);
|
|
||||||
Vec3 xYZ = new Vec3(bb.minX, bb.maxY, bb.maxZ);
|
|
||||||
Vec3 XYZ = new Vec3(bb.maxX, bb.maxY, bb.maxZ);
|
|
||||||
|
|
||||||
Vec3 start = xyz;
|
|
||||||
renderAACuboidLine(ms, buffer, start, Xyz);
|
|
||||||
renderAACuboidLine(ms, buffer, start, xYz);
|
|
||||||
renderAACuboidLine(ms, buffer, start, xyZ);
|
|
||||||
|
|
||||||
start = XyZ;
|
|
||||||
renderAACuboidLine(ms, buffer, start, xyZ);
|
|
||||||
renderAACuboidLine(ms, buffer, start, XYZ);
|
|
||||||
renderAACuboidLine(ms, buffer, start, Xyz);
|
|
||||||
|
|
||||||
start = XYz;
|
|
||||||
renderAACuboidLine(ms, buffer, start, xYz);
|
|
||||||
renderAACuboidLine(ms, buffer, start, Xyz);
|
|
||||||
renderAACuboidLine(ms, buffer, start, XYZ);
|
|
||||||
|
|
||||||
start = xYZ;
|
|
||||||
renderAACuboidLine(ms, buffer, start, XYZ);
|
|
||||||
renderAACuboidLine(ms, buffer, start, xyZ);
|
|
||||||
renderAACuboidLine(ms, buffer, start, xYz);
|
|
||||||
|
|
||||||
renderFace(ms, buffer, Direction.NORTH, xYz, XYz, Xyz, xyz, noCull);
|
|
||||||
renderFace(ms, buffer, Direction.SOUTH, XYZ, xYZ, xyZ, XyZ, noCull);
|
|
||||||
renderFace(ms, buffer, Direction.EAST, XYz, XYZ, XyZ, Xyz, noCull);
|
|
||||||
renderFace(ms, buffer, Direction.WEST, xYZ, xYz, xyz, xyZ, noCull);
|
|
||||||
renderFace(ms, buffer, Direction.UP, xYZ, XYZ, XYz, xYz, noCull);
|
|
||||||
renderFace(ms, buffer, Direction.DOWN, xyz, Xyz, XyZ, xyZ, noCull);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void renderFace(PoseStack ms, SuperRenderTypeBuffer buffer, Direction direction, Vec3 p1, Vec3 p2,
|
|
||||||
Vec3 p3, Vec3 p4, boolean noCull) {
|
|
||||||
if (!params.faceTexture.isPresent())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ResourceLocation faceTexture = params.faceTexture.get()
|
|
||||||
.getLocation();
|
|
||||||
float alphaBefore = params.alpha;
|
|
||||||
params.alpha =
|
|
||||||
(direction == params.getHighlightedFace() && params.hightlightedFaceTexture.isPresent()) ? 1 : 0.5f;
|
|
||||||
|
|
||||||
RenderType translucentType = RenderTypes.getOutlineTranslucent(faceTexture, !noCull);
|
|
||||||
VertexConsumer builder = buffer.getLateBuffer(translucentType);
|
|
||||||
|
|
||||||
Axis axis = direction.getAxis();
|
|
||||||
Vec3 uDiff = p2.subtract(p1);
|
|
||||||
Vec3 vDiff = p4.subtract(p1);
|
|
||||||
float maxU = (float) Math.abs(axis == Axis.X ? uDiff.z : uDiff.x);
|
|
||||||
float maxV = (float) Math.abs(axis == Axis.Y ? vDiff.z : vDiff.y);
|
|
||||||
putQuadUV(ms, builder, p1, p2, p3, p4, 0, 0, maxU, maxV, Direction.UP);
|
|
||||||
params.alpha = alphaBefore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBounds(AABB bb) {
|
|
||||||
this.bb = bb;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Iterate;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.VecHelper;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
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.world.phys.Vec3;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class BlockClusterOutline extends Outline {
|
|
||||||
|
|
||||||
private Cluster cluster;
|
|
||||||
|
|
||||||
public BlockClusterOutline(Iterable<BlockPos> selection) {
|
|
||||||
cluster = new Cluster();
|
|
||||||
selection.forEach(cluster::include);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
cluster.visibleEdges.forEach(edge -> {
|
|
||||||
Vec3 start = Vec3.atLowerCornerOf(edge.pos);
|
|
||||||
Direction direction = Direction.get(AxisDirection.POSITIVE, edge.axis);
|
|
||||||
renderAACuboidLine(ms, buffer, start, Vec3.atLowerCornerOf(edge.pos.relative(direction)));
|
|
||||||
});
|
|
||||||
|
|
||||||
Optional<AllSpecialTextures> faceTexture = params.faceTexture;
|
|
||||||
if (!faceTexture.isPresent())
|
|
||||||
return;
|
|
||||||
|
|
||||||
RenderType translucentType = RenderTypes.getOutlineTranslucent(faceTexture.get()
|
|
||||||
.getLocation(), true);
|
|
||||||
VertexConsumer builder = buffer.getLateBuffer(translucentType);
|
|
||||||
|
|
||||||
cluster.visibleFaces.forEach((face, axisDirection) -> {
|
|
||||||
Direction direction = Direction.get(axisDirection, face.axis);
|
|
||||||
BlockPos pos = face.pos;
|
|
||||||
if (axisDirection == AxisDirection.POSITIVE)
|
|
||||||
pos = pos.relative(direction.getOpposite());
|
|
||||||
renderBlockFace(ms, builder, pos, direction);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static Vec3 xyz = new Vec3(-.5, -.5, -.5);
|
|
||||||
static Vec3 Xyz = new Vec3(.5, -.5, -.5);
|
|
||||||
static Vec3 xYz = new Vec3(-.5, .5, -.5);
|
|
||||||
static Vec3 XYz = new Vec3(.5, .5, -.5);
|
|
||||||
static Vec3 xyZ = new Vec3(-.5, -.5, .5);
|
|
||||||
static Vec3 XyZ = new Vec3(.5, -.5, .5);
|
|
||||||
static Vec3 xYZ = new Vec3(-.5, .5, .5);
|
|
||||||
static Vec3 XYZ = new Vec3(.5, .5, .5);
|
|
||||||
|
|
||||||
protected void renderBlockFace(PoseStack ms, VertexConsumer builder, BlockPos pos, Direction face) {
|
|
||||||
Vec3 center = VecHelper.getCenterOf(pos);
|
|
||||||
Vec3 offset = Vec3.atLowerCornerOf(face.getNormal());
|
|
||||||
offset = offset.scale(1 / 128d);
|
|
||||||
center = center.add(offset);
|
|
||||||
|
|
||||||
ms.pushPose();
|
|
||||||
ms.translate(center.x, center.y, center.z);
|
|
||||||
|
|
||||||
switch (face) {
|
|
||||||
case DOWN:
|
|
||||||
putQuad(ms, builder, xyz, Xyz, XyZ, xyZ, face);
|
|
||||||
break;
|
|
||||||
case EAST:
|
|
||||||
putQuad(ms, builder, XYz, XYZ, XyZ, Xyz, face);
|
|
||||||
break;
|
|
||||||
case NORTH:
|
|
||||||
putQuad(ms, builder, xYz, XYz, Xyz, xyz, face);
|
|
||||||
break;
|
|
||||||
case SOUTH:
|
|
||||||
putQuad(ms, builder, XYZ, xYZ, xyZ, XyZ, face);
|
|
||||||
break;
|
|
||||||
case UP:
|
|
||||||
putQuad(ms, builder, xYZ, XYZ, XYz, xYz, face);
|
|
||||||
break;
|
|
||||||
case WEST:
|
|
||||||
putQuad(ms, builder, xYZ, xYz, xyz, xyZ, face);
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Cluster {
|
|
||||||
|
|
||||||
private Map<MergeEntry, AxisDirection> visibleFaces;
|
|
||||||
private Set<MergeEntry> visibleEdges;
|
|
||||||
|
|
||||||
public Cluster() {
|
|
||||||
visibleEdges = new HashSet<>();
|
|
||||||
visibleFaces = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void include(BlockPos pos) {
|
|
||||||
|
|
||||||
// 6 FACES
|
|
||||||
for (Axis axis : Iterate.axes) {
|
|
||||||
Direction direction = Direction.get(AxisDirection.POSITIVE, axis);
|
|
||||||
for (int offset : Iterate.zeroAndOne) {
|
|
||||||
MergeEntry entry = new MergeEntry(axis, pos.relative(direction, offset));
|
|
||||||
if (visibleFaces.remove(entry) == null)
|
|
||||||
visibleFaces.put(entry, offset == 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 12 EDGES
|
|
||||||
for (Axis axis : Iterate.axes) {
|
|
||||||
for (Axis axis2 : Iterate.axes) {
|
|
||||||
if (axis == axis2)
|
|
||||||
continue;
|
|
||||||
for (Axis axis3 : Iterate.axes) {
|
|
||||||
if (axis == axis3)
|
|
||||||
continue;
|
|
||||||
if (axis2 == axis3)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Direction direction = Direction.get(AxisDirection.POSITIVE, axis2);
|
|
||||||
Direction direction2 = Direction.get(AxisDirection.POSITIVE, axis3);
|
|
||||||
|
|
||||||
for (int offset : Iterate.zeroAndOne) {
|
|
||||||
BlockPos entryPos = pos.relative(direction, offset);
|
|
||||||
for (int offset2 : Iterate.zeroAndOne) {
|
|
||||||
entryPos = entryPos.relative(direction2, offset2);
|
|
||||||
MergeEntry entry = new MergeEntry(axis, entryPos);
|
|
||||||
if (!visibleEdges.remove(entry))
|
|
||||||
visibleEdges.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MergeEntry {
|
|
||||||
|
|
||||||
private Axis axis;
|
|
||||||
private BlockPos pos;
|
|
||||||
|
|
||||||
public MergeEntry(Axis axis, BlockPos pos) {
|
|
||||||
this.axis = axis;
|
|
||||||
this.pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o)
|
|
||||||
return true;
|
|
||||||
if (!(o instanceof MergeEntry))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
MergeEntry other = (MergeEntry) o;
|
|
||||||
return this.axis == other.axis && this.pos.equals(other.pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return this.pos.hashCode() * 31 + axis.ordinal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
|
|
||||||
public class ChasingAABBOutline extends AABBOutline {
|
|
||||||
|
|
||||||
AABB targetBB;
|
|
||||||
AABB prevBB;
|
|
||||||
|
|
||||||
public ChasingAABBOutline(AABB bb) {
|
|
||||||
super(bb);
|
|
||||||
prevBB = bb.inflate(0);
|
|
||||||
targetBB = bb.inflate(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void target(AABB target) {
|
|
||||||
targetBB = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
prevBB = bb;
|
|
||||||
setBounds(interpolateBBs(bb, targetBB, .5f));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
renderBB(ms, buffer, interpolateBBs(prevBB, bb, pt));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AABB interpolateBBs(AABB current, AABB target, float pt) {
|
|
||||||
return new AABB(Mth.lerp(pt, current.minX, target.minX),
|
|
||||||
Mth.lerp(pt, current.minY, target.minY), Mth.lerp(pt, current.minZ, target.minZ),
|
|
||||||
Mth.lerp(pt, current.maxX, target.maxX), Mth.lerp(pt, current.maxY, target.maxY),
|
|
||||||
Mth.lerp(pt, current.maxZ, target.maxZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
public class LineOutline extends Outline {
|
|
||||||
|
|
||||||
protected Vec3 start = Vec3.ZERO;
|
|
||||||
protected Vec3 end = Vec3.ZERO;
|
|
||||||
|
|
||||||
public LineOutline set(Vec3 start, Vec3 end) {
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
renderCuboidLine(ms, buffer, start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EndChasingLineOutline extends LineOutline {
|
|
||||||
|
|
||||||
float prevProgress = 0;
|
|
||||||
float progress = 0;
|
|
||||||
private boolean lockStart;
|
|
||||||
|
|
||||||
public EndChasingLineOutline(boolean lockStart) {
|
|
||||||
this.lockStart = lockStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {}
|
|
||||||
|
|
||||||
public EndChasingLineOutline setProgress(float progress) {
|
|
||||||
prevProgress = this.progress;
|
|
||||||
this.progress = progress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LineOutline set(Vec3 start, Vec3 end) {
|
|
||||||
if (!end.equals(this.end))
|
|
||||||
super.set(start, end);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
float distanceToTarget = Mth.lerp(pt, prevProgress, progress);
|
|
||||||
if (!lockStart)
|
|
||||||
distanceToTarget = 1 - distanceToTarget;
|
|
||||||
Vec3 start = lockStart ? this.end : this.start;
|
|
||||||
Vec3 end = lockStart ? this.start : this.end;
|
|
||||||
|
|
||||||
start = end.add(this.start.subtract(end)
|
|
||||||
.scale(distanceToTarget));
|
|
||||||
renderCuboidLine(ms, buffer, start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,246 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
||||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.AngleHelper;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.VecHelper;
|
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
|
||||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.core.Direction.Axis;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import org.joml.Matrix3f;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class Outline {
|
|
||||||
|
|
||||||
protected OutlineParams params;
|
|
||||||
protected Matrix3f transformNormals; // TODO: not used?
|
|
||||||
|
|
||||||
public Outline() {
|
|
||||||
params = new OutlineParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt);
|
|
||||||
|
|
||||||
public void tick() {}
|
|
||||||
|
|
||||||
public OutlineParams getParams() {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderCuboidLine(PoseStack ms, SuperRenderTypeBuffer buffer, Vec3 start, Vec3 end) {
|
|
||||||
Vec3 diff = end.subtract(start);
|
|
||||||
float hAngle = AngleHelper.deg(Mth.atan2(diff.x, diff.z));
|
|
||||||
float hDistance = (float) diff.multiply(1, 0, 1)
|
|
||||||
.length();
|
|
||||||
float vAngle = AngleHelper.deg(Mth.atan2(hDistance, diff.y)) - 90;
|
|
||||||
ms.pushPose();
|
|
||||||
TransformStack.cast(ms)
|
|
||||||
.translate(start)
|
|
||||||
.rotateY(hAngle).rotateX(vAngle);
|
|
||||||
renderAACuboidLine(ms, buffer, Vec3.ZERO, new Vec3(0, 0, diff.length()));
|
|
||||||
ms.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderAACuboidLine(PoseStack ms, SuperRenderTypeBuffer buffer, Vec3 start, Vec3 end) {
|
|
||||||
float lineWidth = params.getLineWidth();
|
|
||||||
if (lineWidth == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
VertexConsumer builder = buffer.getBuffer(RenderTypes.getOutlineSolid());
|
|
||||||
|
|
||||||
Vec3 diff = end.subtract(start);
|
|
||||||
if (diff.x + diff.y + diff.z < 0) {
|
|
||||||
Vec3 temp = start;
|
|
||||||
start = end;
|
|
||||||
end = temp;
|
|
||||||
diff = diff.scale(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 extension = diff.normalize()
|
|
||||||
.scale(lineWidth / 2);
|
|
||||||
Vec3 plane = VecHelper.axisAlingedPlaneOf(diff);
|
|
||||||
Direction face = Direction.getNearest(diff.x, diff.y, diff.z);
|
|
||||||
Axis axis = face.getAxis();
|
|
||||||
|
|
||||||
start = start.subtract(extension);
|
|
||||||
end = end.add(extension);
|
|
||||||
plane = plane.scale(lineWidth / 2);
|
|
||||||
|
|
||||||
Vec3 a1 = plane.add(start);
|
|
||||||
Vec3 b1 = plane.add(end);
|
|
||||||
plane = VecHelper.rotate(plane, -90, axis);
|
|
||||||
Vec3 a2 = plane.add(start);
|
|
||||||
Vec3 b2 = plane.add(end);
|
|
||||||
plane = VecHelper.rotate(plane, -90, axis);
|
|
||||||
Vec3 a3 = plane.add(start);
|
|
||||||
Vec3 b3 = plane.add(end);
|
|
||||||
plane = VecHelper.rotate(plane, -90, axis);
|
|
||||||
Vec3 a4 = plane.add(start);
|
|
||||||
Vec3 b4 = plane.add(end);
|
|
||||||
|
|
||||||
if (params.disableNormals) {
|
|
||||||
face = Direction.UP;
|
|
||||||
putQuad(ms, builder, b4, b3, b2, b1, face);
|
|
||||||
putQuad(ms, builder, a1, a2, a3, a4, face);
|
|
||||||
putQuad(ms, builder, a1, b1, b2, a2, face);
|
|
||||||
putQuad(ms, builder, a2, b2, b3, a3, face);
|
|
||||||
putQuad(ms, builder, a3, b3, b4, a4, face);
|
|
||||||
putQuad(ms, builder, a4, b4, b1, a1, face);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
putQuad(ms, builder, b4, b3, b2, b1, face);
|
|
||||||
putQuad(ms, builder, a1, a2, a3, a4, face.getOpposite());
|
|
||||||
Vec3 vec = a1.subtract(a4);
|
|
||||||
face = Direction.getNearest(vec.x, vec.y, vec.z);
|
|
||||||
putQuad(ms, builder, a1, b1, b2, a2, face);
|
|
||||||
vec = VecHelper.rotate(vec, -90, axis);
|
|
||||||
face = Direction.getNearest(vec.x, vec.y, vec.z);
|
|
||||||
putQuad(ms, builder, a2, b2, b3, a3, face);
|
|
||||||
vec = VecHelper.rotate(vec, -90, axis);
|
|
||||||
face = Direction.getNearest(vec.x, vec.y, vec.z);
|
|
||||||
putQuad(ms, builder, a3, b3, b4, a4, face);
|
|
||||||
vec = VecHelper.rotate(vec, -90, axis);
|
|
||||||
face = Direction.getNearest(vec.x, vec.y, vec.z);
|
|
||||||
putQuad(ms, builder, a4, b4, b1, a1, face);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putQuad(PoseStack ms, VertexConsumer builder, Vec3 v1, Vec3 v2, Vec3 v3, Vec3 v4,
|
|
||||||
Direction normal) {
|
|
||||||
putQuadUV(ms, builder, v1, v2, v3, v4, 0, 0, 1, 1, normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putQuadUV(PoseStack ms, VertexConsumer builder, Vec3 v1, Vec3 v2, Vec3 v3, Vec3 v4, float minU,
|
|
||||||
float minV, float maxU, float maxV, Direction normal) {
|
|
||||||
putVertex(ms, builder, v1, minU, minV, normal);
|
|
||||||
putVertex(ms, builder, v2, maxU, minV, normal);
|
|
||||||
putVertex(ms, builder, v3, maxU, maxV, normal);
|
|
||||||
putVertex(ms, builder, v4, minU, maxV, normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void putVertex(PoseStack ms, VertexConsumer builder, Vec3 pos, float u, float v, Direction normal) {
|
|
||||||
putVertex(ms.last(), builder, (float) pos.x, (float) pos.y, (float) pos.z, u, v, normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void putVertex(PoseStack.Pose pose, VertexConsumer builder, float x, float y, float z, float u, float v, Direction normal) {
|
|
||||||
Color rgb = params.rgb;
|
|
||||||
if (transformNormals == null)
|
|
||||||
transformNormals = pose.normal();
|
|
||||||
|
|
||||||
int xOffset = 0;
|
|
||||||
int yOffset = 0;
|
|
||||||
int zOffset = 0;
|
|
||||||
|
|
||||||
if (normal != null) {
|
|
||||||
xOffset = normal.getStepX();
|
|
||||||
yOffset = normal.getStepY();
|
|
||||||
zOffset = normal.getStepZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.vertex(pose.pose(), x, y, z)
|
|
||||||
.color(rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(), rgb.getAlphaAsFloat() * params.alpha)
|
|
||||||
.uv(u, v)
|
|
||||||
.overlayCoords(OverlayTexture.NO_OVERLAY)
|
|
||||||
.uv2(params.lightMap)
|
|
||||||
.normal(pose.normal(), xOffset, yOffset, zOffset)
|
|
||||||
.endVertex();
|
|
||||||
|
|
||||||
transformNormals = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class OutlineParams {
|
|
||||||
protected Optional<AllSpecialTextures> faceTexture;
|
|
||||||
protected Optional<AllSpecialTextures> hightlightedFaceTexture;
|
|
||||||
protected Direction highlightedFace;
|
|
||||||
protected boolean fadeLineWidth;
|
|
||||||
protected boolean disableCull;
|
|
||||||
protected boolean disableNormals;
|
|
||||||
protected float alpha;
|
|
||||||
protected int lightMap;
|
|
||||||
protected Color rgb;
|
|
||||||
private float lineWidth;
|
|
||||||
|
|
||||||
public OutlineParams() {
|
|
||||||
faceTexture = hightlightedFaceTexture = Optional.empty();
|
|
||||||
alpha = 1;
|
|
||||||
lineWidth = 1 / 32f;
|
|
||||||
fadeLineWidth = true;
|
|
||||||
rgb = Color.WHITE;
|
|
||||||
lightMap = LightTexture.FULL_BRIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// builder
|
|
||||||
|
|
||||||
public OutlineParams colored(int color) {
|
|
||||||
rgb = new Color(color, false);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams colored(Color c) {
|
|
||||||
rgb = c.copy();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams lightMap(int light) {
|
|
||||||
lightMap = light;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams lineWidth(float width) {
|
|
||||||
this.lineWidth = width;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams withFaceTexture(AllSpecialTextures texture) {
|
|
||||||
this.faceTexture = Optional.ofNullable(texture);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams clearTextures() {
|
|
||||||
return this.withFaceTextures(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams withFaceTextures(AllSpecialTextures texture, AllSpecialTextures highlightTexture) {
|
|
||||||
this.faceTexture = Optional.ofNullable(texture);
|
|
||||||
this.hightlightedFaceTexture = Optional.ofNullable(highlightTexture);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams highlightFace(@Nullable Direction face) {
|
|
||||||
highlightedFace = face;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams disableNormals() {
|
|
||||||
disableNormals = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams disableCull() {
|
|
||||||
disableCull = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getter
|
|
||||||
|
|
||||||
public float getLineWidth() {
|
|
||||||
return fadeLineWidth ? alpha * lineWidth : lineWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Direction getHighlightedFace() {
|
|
||||||
return highlightedFace;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.create.foundation.utility.outliner;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.outliner.LineOutline.EndChasingLineOutline;
|
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.outliner.Outline.OutlineParams;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Outliner {
|
|
||||||
|
|
||||||
private final Map<Object, OutlineEntry> outlines = Collections.synchronizedMap(new HashMap<>());
|
|
||||||
private final Map<Object, OutlineEntry> outlinesView = Collections.unmodifiableMap(outlines);
|
|
||||||
|
|
||||||
// Facade
|
|
||||||
|
|
||||||
public OutlineParams showLine(Object slot, Vec3 start, Vec3 end) {
|
|
||||||
if (!outlines.containsKey(slot)) {
|
|
||||||
LineOutline outline = new LineOutline();
|
|
||||||
outlines.put(slot, new OutlineEntry(outline));
|
|
||||||
}
|
|
||||||
OutlineEntry entry = outlines.get(slot);
|
|
||||||
entry.ticksTillRemoval = 1;
|
|
||||||
((LineOutline) entry.outline).set(start, end);
|
|
||||||
return entry.outline.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams endChasingLine(Object slot, Vec3 start, Vec3 end, float chasingProgress, boolean lockStart) {
|
|
||||||
if (!outlines.containsKey(slot)) {
|
|
||||||
EndChasingLineOutline outline = new EndChasingLineOutline(lockStart);
|
|
||||||
outlines.put(slot, new OutlineEntry(outline));
|
|
||||||
}
|
|
||||||
OutlineEntry entry = outlines.get(slot);
|
|
||||||
entry.ticksTillRemoval = 1;
|
|
||||||
((EndChasingLineOutline) entry.outline).setProgress(chasingProgress)
|
|
||||||
.set(start, end);
|
|
||||||
return entry.outline.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams showAABB(Object slot, AABB bb, int ttl) {
|
|
||||||
createAABBOutlineIfMissing(slot, bb);
|
|
||||||
ChasingAABBOutline outline = getAndRefreshAABB(slot, ttl);
|
|
||||||
outline.prevBB = outline.targetBB = outline.bb = bb;
|
|
||||||
return outline.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams showAABB(Object slot, AABB bb) {
|
|
||||||
createAABBOutlineIfMissing(slot, bb);
|
|
||||||
ChasingAABBOutline outline = getAndRefreshAABB(slot);
|
|
||||||
outline.prevBB = outline.targetBB = outline.bb = bb;
|
|
||||||
return outline.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams chaseAABB(Object slot, AABB bb) {
|
|
||||||
createAABBOutlineIfMissing(slot, bb);
|
|
||||||
ChasingAABBOutline outline = getAndRefreshAABB(slot);
|
|
||||||
outline.targetBB = bb;
|
|
||||||
return outline.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutlineParams showCluster(Object slot, Iterable<BlockPos> selection) {
|
|
||||||
BlockClusterOutline outline = new BlockClusterOutline(selection);
|
|
||||||
OutlineEntry entry = new OutlineEntry(outline);
|
|
||||||
outlines.put(slot, entry);
|
|
||||||
return entry.getOutline()
|
|
||||||
.getParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void keep(Object slot) {
|
|
||||||
if (outlines.containsKey(slot))
|
|
||||||
outlines.get(slot).ticksTillRemoval = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ADDED
|
|
||||||
public void keep(Object slot, int ticks) {
|
|
||||||
if (outlines.containsKey(slot))
|
|
||||||
outlines.get(slot).ticksTillRemoval = ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(Object slot) {
|
|
||||||
outlines.remove(slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<OutlineParams> edit(Object slot) {
|
|
||||||
keep(slot);
|
|
||||||
if (outlines.containsKey(slot))
|
|
||||||
return Optional.of(outlines.get(slot)
|
|
||||||
.getOutline()
|
|
||||||
.getParams());
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Object, OutlineEntry> getOutlines() {
|
|
||||||
return outlinesView;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Utility
|
|
||||||
|
|
||||||
private void createAABBOutlineIfMissing(Object slot, AABB bb) {
|
|
||||||
if (!outlines.containsKey(slot) || !(outlines.get(slot).outline instanceof AABBOutline)) {
|
|
||||||
ChasingAABBOutline outline = new ChasingAABBOutline(bb);
|
|
||||||
outlines.put(slot, new OutlineEntry(outline));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChasingAABBOutline getAndRefreshAABB(Object slot) {
|
|
||||||
OutlineEntry entry = outlines.get(slot);
|
|
||||||
entry.ticksTillRemoval = 1;
|
|
||||||
return (ChasingAABBOutline) entry.getOutline();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChasingAABBOutline getAndRefreshAABB(Object slot, int ttl) {
|
|
||||||
OutlineEntry entry = outlines.get(slot);
|
|
||||||
entry.ticksTillRemoval = ttl;
|
|
||||||
return (ChasingAABBOutline) entry.getOutline();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maintenance
|
|
||||||
|
|
||||||
public void tickOutlines() {
|
|
||||||
Iterator<OutlineEntry> iterator = outlines.values()
|
|
||||||
.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
OutlineEntry entry = iterator.next();
|
|
||||||
entry.tick();
|
|
||||||
if (!entry.isAlive())
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderOutlines(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
|
|
||||||
outlines.forEach((key, entry) -> {
|
|
||||||
Outline outline = entry.getOutline();
|
|
||||||
OutlineParams params = outline.getParams();
|
|
||||||
params.alpha = 1;
|
|
||||||
if (entry.isFading()) {
|
|
||||||
int prevTicks = entry.ticksTillRemoval + 1;
|
|
||||||
float fadeticks = OutlineEntry.fadeTicks;
|
|
||||||
float lastAlpha = prevTicks >= 0 ? 1 : 1 + (prevTicks / fadeticks);
|
|
||||||
float currentAlpha = 1 + (entry.ticksTillRemoval / fadeticks);
|
|
||||||
float alpha = Mth.lerp(pt, lastAlpha, currentAlpha);
|
|
||||||
|
|
||||||
params.alpha = alpha * alpha * alpha;
|
|
||||||
if (params.alpha < 1 / 8f)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
outline.render(ms, buffer, pt);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class OutlineEntry {
|
|
||||||
|
|
||||||
static final int fadeTicks = 4;
|
|
||||||
private Outline outline;
|
|
||||||
private int ticksTillRemoval;
|
|
||||||
|
|
||||||
public OutlineEntry(Outline outline) {
|
|
||||||
this.outline = outline;
|
|
||||||
ticksTillRemoval = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
ticksTillRemoval--;
|
|
||||||
outline.tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAlive() {
|
|
||||||
return ticksTillRemoval >= -fadeTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFading() {
|
|
||||||
return ticksTillRemoval < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Outline getOutline() {
|
|
||||||
return outline;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -26,6 +26,7 @@ import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
|||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions.ActionEnum;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions.ActionEnum;
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions.OptionEnum;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions.OptionEnum;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription;
|
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||||
@@ -151,8 +152,10 @@ public class RadialMenu extends Screen {
|
|||||||
modes.add(new MenuRegion(mode));
|
modes.add(new MenuRegion(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Add actions
|
//Add actions
|
||||||
boolean canReplace = minecraft.player != null && EffortlessBuildingClient.POWER_LEVEL.canReplaceBlocks(minecraft.player);
|
boolean canReplace = CapabilityHandler.canReplaceBlocks(minecraft.player);
|
||||||
|
|
||||||
// buttons.add(new MenuButton(ActionEnum.OPEN_PLAYER_SETTINGS, -buttonDistance - 65, -13, Direction.UP));
|
// buttons.add(new MenuButton(ActionEnum.OPEN_PLAYER_SETTINGS, -buttonDistance - 65, -13, Direction.UP));
|
||||||
if (canReplace) {
|
if (canReplace) {
|
||||||
@@ -334,7 +337,7 @@ public class RadialMenu extends Screen {
|
|||||||
guiGraphics.drawString(font, credits, width - font.width(credits) - 4, height - 10, watermarkTextColor);
|
guiGraphics.drawString(font, credits, width - font.width(credits) - 4, height - 10, watermarkTextColor);
|
||||||
|
|
||||||
//Draw power level info
|
//Draw power level info
|
||||||
String powerLevelValue = minecraft.player.isCreative() ? "Creative" : String.valueOf(EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
String powerLevelValue = minecraft.player.isCreative() ? "Creative" : String.valueOf(CapabilityHandler.getPowerLevel(minecraft.player));
|
||||||
String powerLevelText = I18n.get("key.effortlessbuilding.power_level") + ": " + powerLevelValue;
|
String powerLevelText = I18n.get("key.effortlessbuilding.power_level") + ": " + powerLevelValue;
|
||||||
guiGraphics.drawString(font, powerLevelText, width - font.width(powerLevelText) - 4, height - 22, minecraft.player.isCreative() ? watermarkTextColor : ChatFormatting.DARK_PURPLE.getColor());
|
guiGraphics.drawString(font, powerLevelText, width - font.width(powerLevelText) - 4, height - 22, minecraft.player.isCreative() ? watermarkTextColor : ChatFormatting.DARK_PURPLE.getColor());
|
||||||
|
|
||||||
@@ -342,19 +345,19 @@ public class RadialMenu extends Screen {
|
|||||||
if (mouseX >= width - font.width(powerLevelText) - 14 && mouseX <= width && mouseY >= height - 24 && mouseY <= height) {
|
if (mouseX >= width - font.width(powerLevelText) - 14 && mouseX <= width && mouseY >= height - 24 && mouseY <= height) {
|
||||||
var tooltip = new ArrayList<Component>();
|
var tooltip = new ArrayList<Component>();
|
||||||
tooltip.add(Components.literal(powerLevelText).withStyle(ChatFormatting.DARK_PURPLE));
|
tooltip.add(Components.literal(powerLevelText).withStyle(ChatFormatting.DARK_PURPLE));
|
||||||
int placementReach = EffortlessBuildingClient.POWER_LEVEL.getPlacementReach(minecraft.player);
|
int placementReach = CapabilityHandler.getPlacementReach(minecraft.player, false);
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + (placementReach == 0 ? "vanilla" : placementReach + " blocks")));
|
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + (placementReach == 0 ? "vanilla" : placementReach + " blocks")));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(minecraft.player)));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPerAxis(minecraft.player, false)));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPlacedAtOnce(minecraft.player)));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPlacedAtOnce(minecraft.player, false)));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(minecraft.player) + " blocks"));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxMirrorRadius(minecraft.player, false) + " blocks"));
|
||||||
|
|
||||||
if (EffortlessBuildingClient.POWER_LEVEL.canIncreasePowerLevel() && !minecraft.player.isCreative()) {
|
if (CapabilityHandler.canIncreasePowerLevel(minecraft.player) && !minecraft.player.isCreative()) {
|
||||||
tooltip.add(Components.literal(""));
|
tooltip.add(Components.literal(""));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.next_power_level").withStyle(ChatFormatting.DARK_AQUA).append(": " + EffortlessBuildingClient.POWER_LEVEL.getNextPowerLevel()));
|
tooltip.add(Components.translatable("key.effortlessbuilding.next_power_level").withStyle(ChatFormatting.DARK_AQUA).append(": " + CapabilityHandler.getNextPowerLevel(minecraft.player)));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getPlacementReach(minecraft.player, true) + " blocks"));
|
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getPlacementReach(minecraft.player, true) + " blocks"));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(minecraft.player, true)));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPerAxis(minecraft.player, true)));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPlacedAtOnce(minecraft.player, true)));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPlacedAtOnce(minecraft.player, true)));
|
||||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(minecraft.player, true) + " blocks"));
|
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxMirrorRadius(minecraft.player, true) + " blocks"));
|
||||||
tooltip.add(Components.literal(""));
|
tooltip.add(Components.literal(""));
|
||||||
tooltip.addAll(TooltipHelper.cutTextComponent(Components.translatable("key.effortlessbuilding.next_power_level_how"), ChatFormatting.GRAY, ChatFormatting.WHITE));
|
tooltip.addAll(TooltipHelper.cutTextComponent(Components.translatable("key.effortlessbuilding.next_power_level_how"), ChatFormatting.GRAY, ChatFormatting.WHITE));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||||
import nl.requios.effortlessbuilding.gui.elements.LabeledScrollInput;
|
import nl.requios.effortlessbuilding.gui.elements.LabeledScrollInput;
|
||||||
import nl.requios.effortlessbuilding.utilities.MathHelper;
|
import nl.requios.effortlessbuilding.utilities.MathHelper;
|
||||||
@@ -85,7 +85,7 @@ public class ArrayEntry extends BaseModifierEntry<Array> {
|
|||||||
super.onValueChanged();
|
super.onValueChanged();
|
||||||
|
|
||||||
int currentReach = Math.max(-1, getArrayReach());
|
int currentReach = Math.max(-1, getArrayReach());
|
||||||
int maxReach = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPerAxis(Minecraft.getInstance().player);
|
int maxReach = CapabilityHandler.getMaxBlocksPerAxis(Minecraft.getInstance().player, false);
|
||||||
ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED;
|
ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED;
|
||||||
var reachText = "" + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach;
|
var reachText = "" + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach;
|
||||||
reachLabel.text = Component.literal(reachText);
|
reachLabel.text = Component.literal(reachText);
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||||
import nl.requios.effortlessbuilding.AllIcons;
|
import nl.requios.effortlessbuilding.AllIcons;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||||
@@ -101,7 +101,7 @@ public class MirrorEntry extends BaseModifierEntry<Mirror> {
|
|||||||
|
|
||||||
//Radius
|
//Radius
|
||||||
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
||||||
.withRange(0, EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player))
|
.withRange(0, CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||||
.titled(Minecraft.getInstance().player.isCreative() ?
|
.titled(Minecraft.getInstance().player.isCreative() ?
|
||||||
Component.literal("Radius") :
|
Component.literal("Radius") :
|
||||||
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||||
import nl.requios.effortlessbuilding.AllIcons;
|
import nl.requios.effortlessbuilding.AllIcons;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||||
@@ -107,7 +107,7 @@ public class RadialMirrorEntry extends BaseModifierEntry<RadialMirror> {
|
|||||||
|
|
||||||
//Radius
|
//Radius
|
||||||
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
||||||
.withRange(0, EffortlessBuildingClient.POWER_LEVEL.getMaxMirrorRadius(Minecraft.getInstance().player))
|
.withRange(0, CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||||
.titled(Minecraft.getInstance().player.isCreative() ?
|
.titled(Minecraft.getInstance().player.isCreative() ?
|
||||||
Component.literal("Radius") :
|
Component.literal("Radius") :
|
||||||
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.item;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -13,7 +13,8 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -29,33 +30,34 @@ public class PowerLevelItem extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||||
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
|
if (powerLevel.canIncreasePowerLevel()) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
powerLevel.increasePowerLevel();
|
||||||
|
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||||
|
|
||||||
if (world.isClientSide){
|
stack.shrink(1);
|
||||||
|
|
||||||
if (EffortlessBuildingClient.POWER_LEVEL.canIncreasePowerLevel()) {
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||||
|
|
||||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
CapabilityHandler.syncToClient(player);
|
||||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
}
|
||||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("entity.player.levelup"));
|
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
|
||||||
|
|
||||||
|
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||||
} else {
|
} else {
|
||||||
|
if (!world.isClientSide) {
|
||||||
EffortlessBuilding.log(player, "Already reached maximum power level!");
|
EffortlessBuilding.log(player, "Already reached maximum power level!");
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return super.use(world, player, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.item;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -14,7 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
@@ -30,28 +31,29 @@ public class ReachUpgrade1Item extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||||
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
int currentLevel = powerLevel.getPowerLevel();
|
||||||
if (currentLevel == 0) {
|
if (currentLevel == 0) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
powerLevel.increasePowerLevel();
|
||||||
|
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||||
|
|
||||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
stack.shrink(1);
|
||||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
|
||||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("entity.player.levelup"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
|
||||||
|
|
||||||
|
CapabilityHandler.syncToClient(player);
|
||||||
|
}
|
||||||
|
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||||
} else if (currentLevel > 0) {
|
} else if (currentLevel > 0) {
|
||||||
|
if (!world.isClientSide && hand == InteractionHand.MAIN_HAND) {
|
||||||
|
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + powerLevel.getPowerLevel() + ".");
|
||||||
|
|
||||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
|
}
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
}
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.item;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -14,7 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
@@ -28,38 +29,38 @@ public class ReachUpgrade2Item extends Item {
|
|||||||
super(new Item.Properties().stacksTo(1));
|
super(new Item.Properties().stacksTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||||
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
int currentLevel = powerLevel.getPowerLevel();
|
||||||
if (currentLevel == 1) {
|
if (currentLevel == 1) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
powerLevel.increasePowerLevel();
|
||||||
|
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||||
|
|
||||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
stack.shrink(1);
|
||||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
|
||||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("entity.player.levelup"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
|
||||||
|
|
||||||
|
CapabilityHandler.syncToClient(player);
|
||||||
|
}
|
||||||
|
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||||
} else if (currentLevel < 1) {
|
} else if (currentLevel < 1) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
EffortlessBuilding.log(player, "Use Reach Upgrade 1 first.");
|
EffortlessBuilding.log(player, "Use Reach Upgrade 1 first.");
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (currentLevel > 1) {
|
} else if (currentLevel > 1) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + powerLevel.getPowerLevel() + ".");
|
||||||
|
|
||||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
|
}
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
}
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.item;
|
|||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -14,7 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
import nl.requios.effortlessbuilding.CommonConfig;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
@@ -30,37 +31,36 @@ public class ReachUpgrade3Item extends Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||||
|
ItemStack stack = player.getItemInHand(hand);
|
||||||
if (!world.isClientSide) return InteractionResultHolder.consume(player.getItemInHand(hand));
|
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
|
if (powerLevel != null) {
|
||||||
int currentLevel = EffortlessBuildingClient.POWER_LEVEL.getPowerLevel();
|
int currentLevel = powerLevel.getPowerLevel();
|
||||||
if (currentLevel == 2) {
|
if (currentLevel == 2) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
powerLevel.increasePowerLevel();
|
||||||
|
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||||
|
|
||||||
EffortlessBuildingClient.POWER_LEVEL.increasePowerLevel();
|
stack.shrink(1);
|
||||||
EffortlessBuilding.log(player, "Upgraded power level to " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel());
|
|
||||||
player.setItemInHand(hand, ItemStack.EMPTY);
|
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("entity.player.levelup"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
|
||||||
|
|
||||||
|
CapabilityHandler.syncToClient(player);
|
||||||
|
}
|
||||||
|
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||||
} else if (currentLevel < 2) {
|
} else if (currentLevel < 2) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
if (currentLevel == 0) EffortlessBuilding.log(player, "Use Reach Upgrade 1 and 2 first.");
|
if (currentLevel == 0) EffortlessBuilding.log(player, "Use Reach Upgrade 1 and 2 first.");
|
||||||
if (currentLevel == 1) EffortlessBuilding.log(player, "Use Reach Upgrade 2 first.");
|
if (currentLevel == 1) EffortlessBuilding.log(player, "Use Reach Upgrade 2 first.");
|
||||||
|
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (currentLevel > 2) {
|
} else if (currentLevel > 2) {
|
||||||
|
if (!world.isClientSide) {
|
||||||
|
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + powerLevel.getPowerLevel() + ".");
|
||||||
|
|
||||||
EffortlessBuilding.log(player, "Already used this upgrade! Current power level is " + EffortlessBuildingClient.POWER_LEVEL.getPowerLevel() + ".");
|
world.playSound((Player) null, player.blockPosition(), SoundEvents.ARMOR_EQUIP_LEATHER, SoundSource.PLAYERS, 1f, 1f);
|
||||||
|
}
|
||||||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(new ResourceLocation("item.armor.equip_leather"));
|
}
|
||||||
player.playSound(soundEvent, 1f, 1f);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
return InteractionResultHolder.fail(player.getItemInHand(hand));
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public class PacketHandler {
|
|||||||
PROTOCOL_VERSION::equals
|
PROTOCOL_VERSION::equals
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void register() {
|
private static int id = 0;
|
||||||
int id = 0;
|
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
INSTANCE.registerMessage(id++, IsUsingBuildModePacket.class, IsUsingBuildModePacket::encode, IsUsingBuildModePacket::decode,
|
INSTANCE.registerMessage(id++, IsUsingBuildModePacket.class, IsUsingBuildModePacket::encode, IsUsingBuildModePacket::decode,
|
||||||
IsUsingBuildModePacket.Handler::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER));
|
IsUsingBuildModePacket.Handler::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER));
|
||||||
INSTANCE.registerMessage(id++, IsQuickReplacingPacket.class, IsQuickReplacingPacket::encode, IsQuickReplacingPacket::decode,
|
INSTANCE.registerMessage(id++, IsQuickReplacingPacket.class, IsQuickReplacingPacket::encode, IsQuickReplacingPacket::decode,
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package nl.requios.effortlessbuilding.network;
|
package nl.requios.effortlessbuilding.network;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync power level between server and client, for saving and loading.
|
* Sync power level from server to client
|
||||||
*/
|
*/
|
||||||
public class PowerLevelPacket {
|
public class PowerLevelPacket {
|
||||||
|
|
||||||
@@ -31,19 +32,23 @@ public class PowerLevelPacket {
|
|||||||
|
|
||||||
public static class Handler {
|
public static class Handler {
|
||||||
public static void handle(PowerLevelPacket message, Supplier<NetworkEvent.Context> ctx) {
|
public static void handle(PowerLevelPacket message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
if (ctx.get().getDirection().getReceptionSide().isServer()) {
|
NetworkEvent.Context context = ctx.get();
|
||||||
ctx.get().enqueueWork(() -> {
|
if (context.getDirection().getReceptionSide().isClient()) {
|
||||||
var player = ctx.get().getSender();
|
context.enqueueWork(new Runnable() {
|
||||||
//To server, save to persistent player data
|
// Use anon - lambda causes classloading issues
|
||||||
EffortlessBuilding.SERVER_POWER_LEVEL.setPowerLevel(player, message.powerLevel);
|
@Override
|
||||||
});
|
public void run() {
|
||||||
} else {
|
Player player = Minecraft.getInstance().player;
|
||||||
ctx.get().enqueueWork(() -> {
|
if (player != null) {
|
||||||
//To client, load into system
|
player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY, null)
|
||||||
EffortlessBuildingClient.POWER_LEVEL.setPowerLevel(message.powerLevel);
|
.ifPresent(levelCap -> {
|
||||||
|
levelCap.setPowerLevel(message.powerLevel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ctx.get().setPacketHandled(true);
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
context.setPacketHandled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package nl.requios.effortlessbuilding.render;
|
package nl.requios.effortlessbuilding.render;
|
||||||
|
|
||||||
|
import net.createmod.catnip.data.Pair;
|
||||||
|
import net.createmod.catnip.outliner.Outliner;
|
||||||
|
import net.createmod.catnip.theme.Color;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -12,7 +15,6 @@ import nl.requios.effortlessbuilding.*;
|
|||||||
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
||||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
|
||||||
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||||
@@ -76,25 +78,25 @@ public class BlockPreviews {
|
|||||||
if (ClientConfig.visuals.showBlockPreviews.get() && blocks.size() < ClientConfig.visuals.maxBlockPreviews.get()) {
|
if (ClientConfig.visuals.showBlockPreviews.get() && blocks.size() < ClientConfig.visuals.maxBlockPreviews.get()) {
|
||||||
renderBlockPreviews(blocks, false, 0f);
|
renderBlockPreviews(blocks, false, 0f);
|
||||||
|
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.CHECKERED)
|
.withFaceTexture(AllSpecialTextures.CHECKERED)
|
||||||
.disableNormals()
|
.disableLineNormals()
|
||||||
.lineWidth(1 / 32f)
|
.lineWidth(1 / 32f)
|
||||||
.colored(new Color(1f, 1f, 1f, 1f));
|
.colored(new Color(1f, 1f, 1f, 1f));
|
||||||
} else {
|
} else {
|
||||||
//Thicker outline without block previews
|
//Thicker outline without block previews
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.HIGHLIGHT_CHECKERED)
|
.withFaceTexture(AllSpecialTextures.HIGHLIGHT_CHECKERED)
|
||||||
.disableNormals()
|
.disableLineNormals()
|
||||||
.lineWidth(1 / 16f)
|
.lineWidth(1 / 16f)
|
||||||
.colored(new Color(1f, 1f, 1f, 1f));
|
.colored(new Color(1f, 1f, 1f, 1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Breaking
|
//Breaking
|
||||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||||
.withFaceTexture(AllSpecialTextures.THIN_CHECKERED)
|
.withFaceTexture(AllSpecialTextures.THIN_CHECKERED)
|
||||||
.disableNormals()
|
.disableLineNormals()
|
||||||
.lineWidth(1 / 16f)
|
.lineWidth(1 / 16f)
|
||||||
.colored(new Color(0.8f, 0.1f, 0.1f, 1f));
|
.colored(new Color(0.8f, 0.1f, 0.1f, 1f));
|
||||||
}
|
}
|
||||||
@@ -153,8 +155,8 @@ public class BlockPreviews {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateClient.OUTLINER.showAABB("break", aabb)
|
Outliner.getInstance().showAABB("break", aabb)
|
||||||
.disableNormals()
|
.disableLineNormals()
|
||||||
.lineWidth(1 / 64f)
|
.lineWidth(1 / 64f)
|
||||||
.colored(0x222222);
|
.colored(0x222222);
|
||||||
}
|
}
|
||||||
@@ -227,7 +229,7 @@ public class BlockPreviews {
|
|||||||
|
|
||||||
placedBlocksList.add(new PlacedBlocksEntry(ClientEvents.ticksInGame, false, new BlockSet(blocks)));
|
placedBlocksList.add(new PlacedBlocksEntry(ClientEvents.ticksInGame, false, new BlockSet(blocks)));
|
||||||
|
|
||||||
CreateClient.OUTLINER.keep(blocks.firstPos, ClientConfig.visuals.appearAnimationLength.get());
|
Outliner.getInstance().keep(Pair.of(blocks.firstPos, ClientConfig.visuals.appearAnimationLength.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlocksBroken(BlockSet blocks) {
|
public void onBlocksBroken(BlockSet blocks) {
|
||||||
@@ -236,7 +238,7 @@ public class BlockPreviews {
|
|||||||
|
|
||||||
placedBlocksList.add(new PlacedBlocksEntry(ClientEvents.ticksInGame, true, new BlockSet(blocks)));
|
placedBlocksList.add(new PlacedBlocksEntry(ClientEvents.ticksInGame, true, new BlockSet(blocks)));
|
||||||
|
|
||||||
CreateClient.OUTLINER.keep(blocks.firstPos, ClientConfig.visuals.breakAnimationLength.get());
|
Outliner.getInstance().keep(Pair.of(blocks.firstPos, ClientConfig.visuals.breakAnimationLength.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortOnDistanceToPlayer(List<BlockPos> coordinates, Player player) {
|
private void sortOnDistanceToPlayer(List<BlockPos> coordinates, Player player) {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.systems;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.network.IsQuickReplacingPacket;
|
import nl.requios.effortlessbuilding.network.IsQuickReplacingPacket;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
|
|
||||||
@@ -68,6 +68,6 @@ public class BuildSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean canReplaceBlocks(){
|
private boolean canReplaceBlocks(){
|
||||||
return Minecraft.getInstance().player != null && EffortlessBuildingClient.POWER_LEVEL.canReplaceBlocks(Minecraft.getInstance().player);
|
return Minecraft.getInstance().player != null && CapabilityHandler.canReplaceBlocks(Minecraft.getInstance().player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import nl.requios.effortlessbuilding.ClientConfig;
|
|||||||
import nl.requios.effortlessbuilding.ClientEvents;
|
import nl.requios.effortlessbuilding.ClientEvents;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||||
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||||
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
@@ -103,7 +104,8 @@ public class BuilderChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var player = Minecraft.getInstance().player;
|
var player = Minecraft.getInstance().player;
|
||||||
if (player != null && !EffortlessBuildingClient.POWER_LEVEL.canBreakFar(player)) return;
|
if (player == null) return;
|
||||||
|
if (!CapabilityHandler.canBreakFar(player)) return;
|
||||||
|
|
||||||
if (buildingState == BuildingState.IDLE){
|
if (buildingState == BuildingState.IDLE){
|
||||||
buildingState = BuildingState.BREAKING;
|
buildingState = BuildingState.BREAKING;
|
||||||
@@ -197,7 +199,7 @@ public class BuilderChain {
|
|||||||
boolean lookingAtInteractiveObject = ClientBlockUtilities.determineIfLookingAtInteractiveObject(mc, world);
|
boolean lookingAtInteractiveObject = ClientBlockUtilities.determineIfLookingAtInteractiveObject(mc, world);
|
||||||
boolean isShiftKeyDown = player.isShiftKeyDown();
|
boolean isShiftKeyDown = player.isShiftKeyDown();
|
||||||
|
|
||||||
if (lookingAtInteractiveObject && !isShiftKeyDown)
|
if (lookingAtInteractiveObject && !isShiftKeyDown && EffortlessBuildingClient.BUILD_SETTINGS.shouldProtectTileEntities())
|
||||||
return AbilitiesState.NONE;
|
return AbilitiesState.NONE;
|
||||||
|
|
||||||
if (!blockInHand)
|
if (!blockInHand)
|
||||||
@@ -208,7 +210,7 @@ public class BuilderChain {
|
|||||||
|
|
||||||
private BlockEntry findStartPosition(Player player, BuildModeEnum buildMode) {
|
private BlockEntry findStartPosition(Player player, BuildModeEnum buildMode) {
|
||||||
|
|
||||||
int maxReach = EffortlessBuildingClient.POWER_LEVEL.getPlacementReach(player);
|
int maxReach = CapabilityHandler.getPlacementReach(player, false);
|
||||||
|
|
||||||
//Determine if we should look far or nearby
|
//Determine if we should look far or nearby
|
||||||
boolean shouldLookAtNear = buildMode == BuildModeEnum.DISABLED || maxReach < 3;
|
boolean shouldLookAtNear = buildMode == BuildModeEnum.DISABLED || maxReach < 3;
|
||||||
@@ -241,7 +243,7 @@ public class BuilderChain {
|
|||||||
//We can only break
|
//We can only break
|
||||||
|
|
||||||
//Do not break far if we are not allowed to
|
//Do not break far if we are not allowed to
|
||||||
if (!shouldLookAtNear && !EffortlessBuildingClient.POWER_LEVEL.canBreakFar(player)) return null;
|
if (!shouldLookAtNear && !CapabilityHandler.canBreakFar(player)) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockEntry = new BlockEntry(startPos);
|
var blockEntry = new BlockEntry(startPos);
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.systems;
|
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import nl.requios.effortlessbuilding.CommonConfig;
|
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
|
||||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public class PowerLevel {
|
|
||||||
|
|
||||||
private int powerLevel;
|
|
||||||
|
|
||||||
public int getPowerLevel() {
|
|
||||||
return powerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNextPowerLevel() {
|
|
||||||
return Math.min(powerLevel + 1, ServerPowerLevel.MAX_POWER_LEVEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPowerLevel(int powerLevel) {
|
|
||||||
this.powerLevel = powerLevel;
|
|
||||||
EffortlessBuildingClient.BUILD_MODIFIERS.onPowerLevelChanged(powerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canIncreasePowerLevel() {
|
|
||||||
return getPowerLevel() < ServerPowerLevel.MAX_POWER_LEVEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void increasePowerLevel() {
|
|
||||||
if (canIncreasePowerLevel()) {
|
|
||||||
setPowerLevel(getPowerLevel() + 1);
|
|
||||||
PacketHandler.INSTANCE.sendToServer(new PowerLevelPacket(powerLevel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public int getMaxReach(Player player) {
|
|
||||||
return getPlacementReach(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlacementReach(Player player) {
|
|
||||||
return getPlacementReach(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
|
||||||
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) + 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxBlocksPlacedAtOnce(Player player) {
|
|
||||||
return getMaxBlocksPlacedAtOnce(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
return getMaxBlocksPerAxis(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
return getMaxMirrorRadius(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) <= 0 || getMaxBlocksPerAxis(player) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canBreakFar(Player player) {
|
|
||||||
return player.isCreative();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canReplaceBlocks(Player player) {
|
|
||||||
return player.isCreative();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package nl.requios.effortlessbuilding.systems;
|
|||||||
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
public class ServerBuildState {
|
public class ServerBuildState {
|
||||||
private static final String IS_USING_BUILD_MODE_KEY = EffortlessBuilding.MODID + ":isUsingBuildMode";
|
private static final String IS_USING_BUILD_MODE_KEY = EffortlessBuilding.MODID + ":isUsingBuildMode";
|
||||||
@@ -25,7 +26,7 @@ public class ServerBuildState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isQuickReplacing(Player player) {
|
public static boolean isQuickReplacing(Player player) {
|
||||||
if (!EffortlessBuilding.SERVER_POWER_LEVEL.canReplaceBlocks(player)) return false;
|
if (!CapabilityHandler.canReplaceBlocks(player)) return false;
|
||||||
return player.getPersistentData().contains(IS_QUICK_REPLACING_KEY);
|
return player.getPersistentData().contains(IS_QUICK_REPLACING_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package nl.requios.effortlessbuilding.systems;
|
|
||||||
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
|
||||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
|
||||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
|
||||||
|
|
||||||
public class ServerPowerLevel {
|
|
||||||
public static final int MAX_POWER_LEVEL = 3; //Common access
|
|
||||||
private static final String POWER_LEVEL_KEY = EffortlessBuilding.MODID + ":powerLevel";
|
|
||||||
|
|
||||||
public int getPowerLevel(Player player) {
|
|
||||||
if (!player.getPersistentData().contains(POWER_LEVEL_KEY)) return 0;
|
|
||||||
return player.getPersistentData().getInt(POWER_LEVEL_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPowerLevel(Player player, int powerLevel) {
|
|
||||||
player.getPersistentData().putInt(POWER_LEVEL_KEY, powerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendToClient(Player player) {
|
|
||||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(getPowerLevel(player)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canBreakFar(Player player) {
|
|
||||||
return player.isCreative();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canReplaceBlocks(Player player) {
|
|
||||||
return player.isCreative();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -102,7 +102,7 @@ public class BlockSet extends HashMap<BlockPos, BlockEntry> implements Iterable<
|
|||||||
public static class ClientSide {
|
public static class ClientSide {
|
||||||
public static boolean isFull(BlockSet blockSet) {
|
public static boolean isFull(BlockSet blockSet) {
|
||||||
//Limit number of blocks you can place
|
//Limit number of blocks you can place
|
||||||
int limit = EffortlessBuildingClient.POWER_LEVEL.getMaxBlocksPlacedAtOnce(net.minecraft.client.Minecraft.getInstance().player);
|
int limit = CapabilityHandler.getMaxBlocksPlacedAtOnce(net.minecraft.client.Minecraft.getInstance().player, false);
|
||||||
if (blockSet.size() >= limit) {
|
if (blockSet.size() >= limit) {
|
||||||
if (logging) EffortlessBuilding.log("BlockSet limit reached, not adding block.");
|
if (logging) EffortlessBuilding.log("BlockSet limit reached, not adding block.");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import net.minecraft.world.phys.HitResult;
|
|||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public class ClientBlockUtilities {
|
public class ClientBlockUtilities {
|
||||||
@@ -52,7 +52,7 @@ public class ClientBlockUtilities {
|
|||||||
Level world = player.level();
|
Level world = player.level();
|
||||||
|
|
||||||
//base distance off of player ability (config)
|
//base distance off of player ability (config)
|
||||||
float raytraceRange = EffortlessBuildingClient.POWER_LEVEL.getPlacementReach(player);
|
float raytraceRange = CapabilityHandler.getPlacementReach(player, false);
|
||||||
|
|
||||||
Vec3 look = player.getLookAngle();
|
Vec3 look = player.getLookAngle();
|
||||||
Vec3 start = new Vec3(player.getX(), player.getY() + player.getEyeHeight(), player.getZ());
|
Vec3 start = new Vec3(player.getX(), player.getY() + player.getEyeHeight(), player.getZ());
|
||||||
|
|||||||
@@ -7,9 +7,14 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import nl.requios.effortlessbuilding.systems.ServerPowerLevel;
|
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||||
|
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||||
|
import nl.requios.effortlessbuilding.capability.PowerLevelCapability;
|
||||||
|
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||||
|
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||||
|
|
||||||
public class PowerLevelCommand {
|
public class PowerLevelCommand {
|
||||||
|
|
||||||
@@ -32,7 +37,7 @@ public class PowerLevelCommand {
|
|||||||
})))
|
})))
|
||||||
.then(Commands.literal("set")
|
.then(Commands.literal("set")
|
||||||
.then(Commands.argument("target", EntityArgument.player())
|
.then(Commands.argument("target", EntityArgument.player())
|
||||||
.then(Commands.argument("value", IntegerArgumentType.integer(0, ServerPowerLevel.MAX_POWER_LEVEL)).executes(ctx -> {
|
.then(Commands.argument("value", IntegerArgumentType.integer(0, PowerLevelCapability.MAX_POWER_LEVEL)).executes(ctx -> {
|
||||||
|
|
||||||
//Set power level
|
//Set power level
|
||||||
setPowerLevel(ctx.getSource(), EntityArgument.getPlayer(ctx, "target"), ctx.getArgument("value", Integer.class));
|
setPowerLevel(ctx.getSource(), EntityArgument.getPlayer(ctx, "target"), ctx.getArgument("value", Integer.class));
|
||||||
@@ -42,13 +47,16 @@ public class PowerLevelCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void logPowerLevel(CommandSourceStack source, Player player) {
|
private static void logPowerLevel(CommandSourceStack source, Player player) {
|
||||||
int powerLevel = EffortlessBuilding.SERVER_POWER_LEVEL.getPowerLevel(player);
|
int powerLevel = CapabilityHandler.getPowerLevel(player);
|
||||||
source.sendSuccess(() -> Component.translatable("effortlessbuilding.commands.powerlevel", player.getDisplayName(), powerLevel), false);
|
source.sendSuccess(() -> Component.translatable("effortlessbuilding.commands.powerlevel", player.getDisplayName(), powerLevel), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setPowerLevel(CommandSourceStack source, Player player, int powerLevel) throws CommandSyntaxException {
|
private static void setPowerLevel(CommandSourceStack source, Player player, int powerLevel) throws CommandSyntaxException {
|
||||||
EffortlessBuilding.SERVER_POWER_LEVEL.setPowerLevel(player, powerLevel);
|
IPowerLevel powerCap = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||||
EffortlessBuilding.SERVER_POWER_LEVEL.sendToClient(player);
|
if (powerCap == null) return; //Should never be null but just to be sure
|
||||||
|
powerCap.setPowerLevel(powerLevel);
|
||||||
|
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(powerLevel));
|
||||||
|
|
||||||
source.sendSuccess(() -> Component.translatable("effortlessbuilding.commands.powerlevel.success", player.getDisplayName(), powerLevel), true);
|
source.sendSuccess(() -> Component.translatable("effortlessbuilding.commands.powerlevel.success", player.getDisplayName(), powerLevel), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ showAsResourcePack=false
|
|||||||
|
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="effortlessbuilding"
|
modId="effortlessbuilding"
|
||||||
|
# The Implementation-Version property in the jar's MANIFEST.MF file will be used as the mod version at runtime
|
||||||
version="${file.jarVersion}"
|
version="${file.jarVersion}"
|
||||||
displayName="Effortless Building"
|
displayName="Effortless Building"
|
||||||
displayURL="https://minecraft.curseforge.com/projects/effortless-building"
|
displayURL="https://minecraft.curseforge.com/projects/effortless-building"
|
||||||
logoFile="logo.png"
|
logoFile="logo.png"
|
||||||
credits=""
|
#credits=""
|
||||||
authors="Requios"
|
authors="Requios"
|
||||||
description='''
|
description='''
|
||||||
Makes building easier by providing tools like mirrors, arrays, build modes and a block randomizer. For survival and creative mode.
|
Makes building easier by providing tools like mirrors, arrays, build modes and a block randomizer. For survival and creative mode.
|
||||||
@@ -33,6 +34,13 @@ Makes building easier by providing tools like mirrors, arrays, build modes and a
|
|||||||
[[dependencies.effortlessbuilding]]
|
[[dependencies.effortlessbuilding]]
|
||||||
modId="flywheel"
|
modId="flywheel"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
versionRange="[0.6.10,0.7)"
|
versionRange="[1.0.0,2.0)"
|
||||||
ordering="AFTER"
|
ordering="AFTER"
|
||||||
side="CLIENT"
|
side="CLIENT"
|
||||||
|
|
||||||
|
[[dependencies.effortlessbuilding]]
|
||||||
|
modId = "ponder"
|
||||||
|
mandatory = true
|
||||||
|
versionRange = "[0.8,)"
|
||||||
|
ordering = "AFTER"
|
||||||
|
side = "BOTH"
|
||||||
Reference in New Issue
Block a user