Working on compatibility with Create 6.
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -20,7 +20,7 @@ build
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
logs/*
|
||||
runs
|
||||
run-data
|
||||
|
||||
# Files from Forge MDK
|
||||
forge*changelog.txt
|
||||
repo
|
||||
149
build.gradle
149
build.gradle
@@ -13,90 +13,88 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
||||
id "idea"
|
||||
id "eclipse"
|
||||
id "maven-publish"
|
||||
id "net.neoforged.moddev.legacyforge" version "2.0.74"
|
||||
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.8" // https://github.com/JetBrains/gradle-idea-ext-plugin
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
boolean flywheelInWorkspace = findProject(':Flywheel') != null
|
||||
apply from: "./gradle/java.gradle"
|
||||
apply from: "gradle/property_loader.gradle"
|
||||
|
||||
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
||||
|
||||
version = mod_version
|
||||
group = 'nl.requios.effortlessbuilding'
|
||||
base {
|
||||
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
||||
version = mod_version
|
||||
}
|
||||
|
||||
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'))
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}"
|
||||
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
legacyForge {
|
||||
version = "$minecraft_version-$forge_version"
|
||||
|
||||
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 {
|
||||
client {
|
||||
workingDirectory project.file('run')
|
||||
arg '-mixin.config=flywheel.mixins.json'
|
||||
// applies to all the run configs below
|
||||
configureEach {
|
||||
systemProperty 'forge.logging.markers', ''
|
||||
systemProperty 'forge.logging.console.level', 'info'
|
||||
jvmArguments = ["-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition"]
|
||||
//jvmArgs("-XX:-OmitStackTraceInFastThrow") // uncomment when you get exceptions with null messages etc
|
||||
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
||||
property 'forge.logging.console.level', 'info'
|
||||
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
systemProperty 'mixin.debug.export', 'true'
|
||||
systemProperty 'mixin.debug.verbose', 'true'
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
flywheel {
|
||||
source project(":Flywheel").sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
programArgument '-mixin.config=ponder.mixins.json'
|
||||
}
|
||||
|
||||
client {
|
||||
client()
|
||||
|
||||
gameDirectory = project.file('run')
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory project.file('run/server')
|
||||
property 'forge.logging.console.level', 'info'
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
server()
|
||||
|
||||
gameDirectory = project.file('run/server')
|
||||
}
|
||||
|
||||
data {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
args '--mod', 'effortlessbuilding', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
data()
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
flywheel {
|
||||
source project(":Flywheel").sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
gameDirectory = project.file('run')
|
||||
systemProperty 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||
systemProperty 'forge.logging.console.level', 'debug'
|
||||
programArguments.addAll("--mod", mod_id as String, "--all", "--output", file("src/generated/resources/").getAbsolutePath(), "--existing", file("src/main/resources").getAbsolutePath())
|
||||
}
|
||||
|
||||
gameTestServer {
|
||||
type = "gameTestServer"
|
||||
|
||||
gameDirectory = project.file('run/gametest')
|
||||
// setForceExit false <- FIXME 1.20
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
// location of the maven for Registrate and Flywheel
|
||||
name = 'tterrag maven'
|
||||
url = 'https://maven.tterrag.com'
|
||||
}
|
||||
maven { url = "https://maven.createmod.net" } // Ponder, Flywheel
|
||||
maven { url = "https://maven.tterrag.com" } // Registrate
|
||||
|
||||
maven {
|
||||
url = 'https://www.cursemaven.com'
|
||||
@@ -119,17 +117,18 @@ repositories {
|
||||
}
|
||||
|
||||
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}") {
|
||||
jarJar.ranged(it, '[0.6.11,)')
|
||||
}
|
||||
modCompileOnly("dev.engine-room.flywheel:flywheel-forge-api-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
modRuntimeOnly(jarJar("dev.engine-room.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||
version {
|
||||
strictly "[1.0,2.0)"
|
||||
prefer flywheel_version
|
||||
}
|
||||
})
|
||||
modRuntimeOnly("dev.engine-room.vanillin:vanillin-forge-${flywheel_minecraft_version}:${vanillin_version}")
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
implementation project(':Flywheel')
|
||||
} else {
|
||||
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
}
|
||||
modImplementation("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
|
||||
|
||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||
@@ -146,6 +145,13 @@ tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
downloadJavadoc = true
|
||||
downloadSources = true
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs = ['-Xdiags:verbose']
|
||||
}
|
||||
@@ -179,24 +185,17 @@ java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
jar.finalizedBy('reobfJar')
|
||||
tasks.jarJar.finalizedBy('reobfJarJar')
|
||||
tasks.build.dependsOn tasks.jarJar
|
||||
|
||||
publishing {
|
||||
project.publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId = base.archivesName.get()
|
||||
|
||||
artifactId base.archivesName.get()
|
||||
from components.java
|
||||
fg.component(it)
|
||||
jarJar.component(it)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
if (project.hasProperty('mavendir')) {
|
||||
maven { url mavendir }
|
||||
artifact(tasks.jar) {
|
||||
classifier = "all"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
mod_version = 3.9
|
||||
mod_version = 3.10
|
||||
artifact_minecraft_version = 1.20.1
|
||||
|
||||
minecraft_version = 1.20.1
|
||||
@@ -17,4 +17,13 @@ cursegradle_version = 1.4.0
|
||||
parchment_version = 2023.09.03
|
||||
|
||||
flywheel_minecraft_version = 1.20.1
|
||||
flywheel_version = 0.6.11-13
|
||||
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
|
||||
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
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.createmod.catnip.render.BindableTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public enum AllSpecialTextures {
|
||||
public enum AllSpecialTextures implements BindableTexture {
|
||||
|
||||
BLANK("blank.png"),
|
||||
CHECKERED("checkerboard.png"),
|
||||
@@ -18,7 +19,7 @@ public enum AllSpecialTextures {
|
||||
public static final String ASSET_PATH = "textures/special/";
|
||||
private ResourceLocation location;
|
||||
|
||||
private AllSpecialTextures(String filename) {
|
||||
AllSpecialTextures(String filename) {
|
||||
location = Create.asResource(ASSET_PATH + filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
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.outliner.Outliner;
|
||||
|
||||
public class CreateClient {
|
||||
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 void invalidateRenderers() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package nl.requios.effortlessbuilding.create.events;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.createmod.catnip.outliner.Outliner;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
@@ -16,10 +17,11 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHolder;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.CameraAngleAnimationService;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
||||
import net.createmod.catnip.render.DefaultSuperRenderTypeBuffer;
|
||||
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||
|
||||
@EventBusSubscriber(Dist.CLIENT)
|
||||
public class ClientEvents {
|
||||
@@ -34,7 +36,7 @@ public class ClientEvents {
|
||||
AnimationTickHolder.tick();
|
||||
|
||||
CreateClient.GHOST_BLOCKS.tickGhosts();
|
||||
CreateClient.OUTLINER.tickOutlines();
|
||||
// Outliner.getInstance().tickOutlines();
|
||||
CameraAngleAnimationService.tick();
|
||||
}
|
||||
|
||||
@@ -67,11 +69,11 @@ public class ClientEvents {
|
||||
PoseStack ms = event.getPoseStack();
|
||||
ms.pushPose();
|
||||
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
||||
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
||||
SuperRenderTypeBuffer buffer = DefaultSuperRenderTypeBuffer.getInstance();
|
||||
|
||||
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
||||
|
||||
CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
||||
// Outliner.getInstance().renderOutlines(ms, buffer, pt);
|
||||
buffer.draw();
|
||||
RenderSystem.enableCull();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.resources.ResourceLocation;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
||||
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
||||
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
||||
import com.mojang.blaze3d.platform.Lighting;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import dev.engine_room.flywheel.lib.model.baked.PartialModel;
|
||||
import net.createmod.ponder.render.VirtualRenderHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
@@ -184,19 +184,19 @@ public class GuiGameElement {
|
||||
RenderType renderType = Sheets.translucentCullBlockSheet();
|
||||
blockRenderer.getModelRenderer()
|
||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel, 1, 1, 1,
|
||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, null);
|
||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, VirtualRenderHelper.VIRTUAL_DATA, null);
|
||||
} else {
|
||||
int color = Minecraft.getInstance()
|
||||
.getBlockColors()
|
||||
.getColor(blockState, null, null, 0);
|
||||
Color rgb = new Color(color == -1 ? this.color : color);
|
||||
|
||||
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), ModelUtil.VIRTUAL_DATA)) {
|
||||
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), VirtualRenderHelper.VIRTUAL_DATA)) {
|
||||
RenderType renderType = RenderTypeHelper.getEntityRenderType(chunkType, true);
|
||||
blockRenderer.getModelRenderer()
|
||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel,
|
||||
rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(),
|
||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, 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;
|
||||
|
||||
import net.createmod.catnip.theme.Color;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
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.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.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
@@ -19,7 +20,6 @@ import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
@@ -56,10 +56,10 @@ public abstract class GhostBlockRenderer {
|
||||
ms.pushPose();
|
||||
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);
|
||||
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();
|
||||
@@ -92,8 +92,7 @@ public abstract class GhostBlockRenderer {
|
||||
ms.translate(-.5, -.5, -.5);
|
||||
|
||||
renderModel(ms.last(), vb, state, model, color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat(), alpha,
|
||||
LevelRenderer.getLightColor(mc.level, pos), OverlayTexture.NO_OVERLAY,
|
||||
ModelUtil.VIRTUAL_DATA, layer);
|
||||
LevelRenderer.getLightColor(mc.level, pos), OverlayTexture.NO_OVERLAY, VirtualRenderHelper.VIRTUAL_DATA, layer);
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility.ghost;
|
||||
|
||||
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.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
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.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -12,7 +15,6 @@ import nl.requios.effortlessbuilding.*;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
@@ -76,25 +78,25 @@ public class BlockPreviews {
|
||||
if (ClientConfig.visuals.showBlockPreviews.get() && blocks.size() < ClientConfig.visuals.maxBlockPreviews.get()) {
|
||||
renderBlockPreviews(blocks, false, 0f);
|
||||
|
||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
||||
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||
.withFaceTexture(AllSpecialTextures.CHECKERED)
|
||||
.disableNormals()
|
||||
.disableLineNormals()
|
||||
.lineWidth(1 / 32f)
|
||||
.colored(new Color(1f, 1f, 1f, 1f));
|
||||
} else {
|
||||
//Thicker outline without block previews
|
||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
||||
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||
.withFaceTexture(AllSpecialTextures.HIGHLIGHT_CHECKERED)
|
||||
.disableNormals()
|
||||
.disableLineNormals()
|
||||
.lineWidth(1 / 16f)
|
||||
.colored(new Color(1f, 1f, 1f, 1f));
|
||||
}
|
||||
|
||||
} else {
|
||||
//Breaking
|
||||
CreateClient.OUTLINER.showCluster(outlineID, coordinates)
|
||||
Outliner.getInstance().showCluster(outlineID, coordinates)
|
||||
.withFaceTexture(AllSpecialTextures.THIN_CHECKERED)
|
||||
.disableNormals()
|
||||
.disableLineNormals()
|
||||
.lineWidth(1 / 16f)
|
||||
.colored(new Color(0.8f, 0.1f, 0.1f, 1f));
|
||||
}
|
||||
@@ -153,8 +155,8 @@ public class BlockPreviews {
|
||||
}
|
||||
}
|
||||
|
||||
CreateClient.OUTLINER.showAABB("break", aabb)
|
||||
.disableNormals()
|
||||
Outliner.getInstance().showAABB("break", aabb)
|
||||
.disableLineNormals()
|
||||
.lineWidth(1 / 64f)
|
||||
.colored(0x222222);
|
||||
}
|
||||
@@ -227,7 +229,7 @@ public class BlockPreviews {
|
||||
|
||||
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) {
|
||||
@@ -236,7 +238,7 @@ public class BlockPreviews {
|
||||
|
||||
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) {
|
||||
|
||||
@@ -6,14 +6,15 @@ showAsResourcePack=false
|
||||
|
||||
[[mods]]
|
||||
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}"
|
||||
displayName="Effortless Building"
|
||||
displayName="${mod_name}"
|
||||
displayURL="https://minecraft.curseforge.com/projects/effortless-building"
|
||||
logoFile="logo.png"
|
||||
credits=""
|
||||
authors="Requios"
|
||||
#credits=""
|
||||
authors="${mod_author}"
|
||||
description='''
|
||||
Makes building easier by providing tools like mirrors, arrays, build modes and a block randomizer. For survival and creative mode.
|
||||
${mod_description}
|
||||
'''
|
||||
|
||||
[[dependencies.effortlessbuilding]]
|
||||
@@ -33,6 +34,13 @@ Makes building easier by providing tools like mirrors, arrays, build modes and a
|
||||
[[dependencies.effortlessbuilding]]
|
||||
modId="flywheel"
|
||||
mandatory=true
|
||||
versionRange="[0.6.10,0.7)"
|
||||
versionRange="[1.0.0,2.0)"
|
||||
ordering="AFTER"
|
||||
side="CLIENT"
|
||||
|
||||
[[dependencies.effortlessbuilding]]
|
||||
modId = "ponder"
|
||||
mandatory = true
|
||||
versionRange = "[0.8,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
Reference in New Issue
Block a user