mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 20:09:39 +00:00
Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36d98fcb22 | ||
|
|
44c5b9617a | ||
|
|
f3f1677db8 | ||
|
|
d396b611ad | ||
|
|
08f4c0f9db | ||
|
|
50b0d22dc2 | ||
|
|
7fed54264e | ||
|
|
be87401be6 | ||
|
|
94254006df | ||
|
|
f79774df65 | ||
|
|
2f2fc22df3 | ||
|
|
26300bbb1b | ||
|
|
88e4d2fd6c | ||
|
|
bb52476d27 | ||
|
|
6d60477b93 | ||
|
|
362724610c | ||
|
|
ea4a3cdf0b | ||
|
|
65959268d0 | ||
|
|
58d820cd7e | ||
|
|
685d68bd9c | ||
|
|
ad63d2d62c | ||
|
|
d2730ccca8 | ||
|
|
e9257b8739 | ||
|
|
3984225faa | ||
|
|
52db6b56d6 | ||
|
|
34bfe513f1 | ||
|
|
42d7ed58aa | ||
|
|
9a4f0f9b99 | ||
|
|
be90a01725 | ||
|
|
e5e8250d44 | ||
|
|
062a03ffc2 | ||
|
|
9f5afaaec3 | ||
|
|
b05f17a477 | ||
|
|
57caf08212 | ||
|
|
085ec79c21 | ||
|
|
38641268ae | ||
|
|
fe8e723638 | ||
|
|
16debfd518 | ||
|
|
8cfc3e1f4a | ||
|
|
2c808fae43 | ||
|
|
1649c3c0c6 | ||
|
|
b84286ba3b |
No files matched your search
@@ -39,6 +39,7 @@ body:
|
||||
- Java 19
|
||||
- Java 20
|
||||
- Java 21
|
||||
- Java 25
|
||||
- Other (Please Specify)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -36,3 +36,4 @@ addon.local.gradle
|
||||
addon.local.gradle.kts
|
||||
addon.late.local.gradle
|
||||
addon.late.local.gradle.kts
|
||||
local/
|
||||
@@ -9,13 +9,13 @@
|
||||
|
||||
## **Beta Quality - Here there be Dragons**
|
||||
* Shaders - Beta
|
||||
* Complementary & BSL mostly function, but have some bugs
|
||||
* Sildurs, Seus, and any other shader probably doesn't work
|
||||
* Complementary + Euphoria Patches is the primary compatibility target
|
||||
* Sildurs, Seus, and any other shaders might work
|
||||
|
||||
|
||||
# Required Dependencies
|
||||
* [UniMixins](https://github.com/LegacyModdingMC/UniMixins/releases) >= 0.1.23
|
||||
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.8.21
|
||||
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.9.0
|
||||
* NOTE: Some mods are not required, but a specific version is required if present - see: `Permanent Incompatibilities` below.
|
||||
|
||||
# Known (temporary) Incompatibilities
|
||||
@@ -38,7 +38,7 @@
|
||||
* [Amazing Trophies 1.2.1 and below](https://github.com/GTNewHorizons/Amazing-Trophies/releases) - Use 1.2.2+
|
||||
* [LWJGL3ify 1.5.4 and below](https://github.com/GTNewHorizons/lwjgl3ify/releases/) - Use the latest version available, 1.5.7+
|
||||
* [ArchaicFix 0.6.2 and below](https://www.curseforge.com/minecraft/mc-mods/archaicfix/files/all?page=1&pageSize=20) - Use 0.7.0 or above
|
||||
* [Hodgepodge 2.4.3 and below](https://github.com/GTNewHorizons/Hodgepodge/releases) - Use 0.4.5 or above
|
||||
* [Hodgepodge 2.4.3 and below](https://github.com/GTNewHorizons/Hodgepodge/releases) - Use 2.4.5 or above
|
||||
* CodeChicken[Core](https://github.com/GTNewHorizons/CodeChickenCore/releases)/[Lib](https://github.com/GTNewHorizons/CodeChickenLib/releases) <1.2.0 - Threading issues, use 1.3.0+
|
||||
* Neodymium - Untested, but unlikely to be compatible. (Chunk Meshing is definitely incompatible, other features might work depending on config)
|
||||
* SmoothFont - Equivalent functionality added
|
||||
@@ -83,3 +83,5 @@
|
||||
* Code from both glsl-transformation-lib and Monocle taken under their respective LGPL 3.0 licenses
|
||||
* FalseTweaks
|
||||
* FalsePattern for [FalseTweaks](https://github.com/falsepattern/falsetweaks) - Item Rendering Optimizations taken from FalseTweaks under the LGPL 3.0 license
|
||||
* Beddium
|
||||
* Venn and Falsepattern for [Beddium](https://github.com/vfx-dev/Beddium) - MinimapRenderer, SafeChunkTracker, and some debug commands adapted under the LGPL 3.0 License
|
||||
+14
-7
@@ -5,11 +5,8 @@ plugins {
|
||||
minecraft {
|
||||
extraRunJvmArguments.add("-Dangelica.enableTestBlocks=true")
|
||||
extraRunJvmArguments.add("-Dangelica.dumpClass=true")
|
||||
/* extraRunJvmArguments.addAll(
|
||||
"-Dlegacy.debugClassLoading=true",
|
||||
"-Dlegacy.debugClassLoadingFiner=true",
|
||||
"-Dlegacy.debugClassLoadingSave=true")*/
|
||||
|
||||
// extraRunJvmArguments.addAll("-Dlegacy.debugClassLoadingSave=true")
|
||||
// extraRunJvmArguments.addAll("-Drfb.dumpLoadedClasses=true", "-Drfb.dumpLoadedClassesPerTransformer=true")
|
||||
//extraRunJvmArguments.add("-Dangelica.redirectorLogspam=true")
|
||||
}
|
||||
|
||||
@@ -32,9 +29,10 @@ tasks.test {
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
inputs.property("version", project.version.toString())
|
||||
val projectVersion = project.version.toString()
|
||||
inputs.property("version", projectVersion)
|
||||
filesMatching("META-INF/rfb-plugin/*") {
|
||||
expand("version" to project.version.toString())
|
||||
expand("version" to projectVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +42,12 @@ tasks.register<Copy>("copyDependencies") {
|
||||
from(configurations.default)
|
||||
into("testDependencies")
|
||||
}
|
||||
|
||||
val embedOnly: Configuration by configurations
|
||||
|
||||
tasks.shadowJar {
|
||||
from(embedOnly.map(::zipTree))
|
||||
relocate("com.mitchej123", "com.mitchej123")
|
||||
relocate("org.embeddedt", "org.embeddedt")
|
||||
}
|
||||
|
||||
+22
-7
@@ -46,19 +46,32 @@ configurations {
|
||||
// Can be enabled for testing if desired
|
||||
// runtimeClasspath.extendsFrom(transformedMod)
|
||||
// testRuntimeClasspath.extendsFrom(transformedMod)
|
||||
|
||||
// Embed in JAR without relocation (compile only, shadowed into JAR)
|
||||
embedOnly
|
||||
embedOnly.canBeConsumed = false
|
||||
embedOnly.canBeResolved = true
|
||||
compileClasspath.extendsFrom(embedOnly)
|
||||
testCompileClasspath.extendsFrom(embedOnly)
|
||||
}
|
||||
|
||||
|
||||
// Exclude self-reference from all configurations - prevents transitive Angelica deps from resolving against this project
|
||||
configurations.all {
|
||||
exclude group: "com.github.GTNewHorizons", module: "Angelica"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.7.14")
|
||||
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.7.14:dev")
|
||||
|
||||
compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.7") { transitive = false }
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.34") { transitive = false }
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||
compileOnly("org.projectlombok:lombok:1.18.42") { transitive = false }
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.42")
|
||||
|
||||
// Iris Shaders
|
||||
compileOnly('org.jetbrains:annotations:26.0.2')
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.8.21:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.0:dev")
|
||||
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-25.g3a943bb") {
|
||||
exclude module: "antlr4" // we only want to shadow the runtime module
|
||||
@@ -66,6 +79,10 @@ dependencies {
|
||||
shadowImplementation("org.antlr:antlr4-runtime:4.13.2")
|
||||
compileOnly "org.apache.ant:ant:1.8.2"
|
||||
|
||||
// Celeritas (transitive=false: deps provided by GTNHLib/runtime)
|
||||
embedOnly("org.embeddedt.celeritas:celeritas-common:2.5.2-GTNH") { transitive = false }
|
||||
embedOnly("org.embeddedt.celeritas:celeritas-lwjgl2-service:2.5.2-GTNH") { transitive = false }
|
||||
|
||||
// Because who doesn't want NEI
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.8.35-GTNH:dev')
|
||||
devOnlyNonPublishable('com.github.GTNewHorizons:CodeChickenCore:1.4.7:dev')
|
||||
@@ -99,7 +116,7 @@ dependencies {
|
||||
compileOnly(rfg.deobf("curse.maven:xaeros-minimap-263420:5060684"))
|
||||
compileOnly(rfg.deobf("curse.maven:security-craft-64760:2818228"))
|
||||
|
||||
runtimeOnlyNonPublishable(rfg.deobf("CoreTweaks:CoreTweaks:0.3.3.2"))
|
||||
// runtimeOnlyNonPublishable("com.github.GTNewHorizons:CoreTweaks:0.3.3.6-GTNH")
|
||||
// For testing alternative splash screens, can be sourced from https://github.com/MalTeeez/ModernSplash/releases
|
||||
//runtimeOnly(rfg.deobf(files("dependencies/modernsplash-1.7.10-1.2.2-dev.jar")))
|
||||
|
||||
@@ -115,8 +132,6 @@ dependencies {
|
||||
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||
testImplementation("org.mockito:mockito-core:3.+")
|
||||
testImplementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209")
|
||||
// testAnnotationProcessor("com.github.GTNewHorizons:jabel-javac-plugin:1.0.2-GTNH") // Soon :tm:
|
||||
testAnnotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:1.0.1")
|
||||
|
||||
testImplementation('org.junit.platform:junit-platform-engine')
|
||||
testImplementation('org.junit.platform:junit-platform-reporting')
|
||||
|
||||
+32
-13
@@ -39,9 +39,33 @@ remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/co
|
||||
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
|
||||
developmentEnvironmentUserName = Developer
|
||||
|
||||
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
|
||||
# See https://github.com/bsideup/jabel for details on how this works.
|
||||
enableModernJavaSyntax = true
|
||||
# Enables modern Java syntax support. Valid values:
|
||||
# - false: No modern syntax, Java 8 only
|
||||
# - jabel: Jabel syntax-only support, compiles to J8 bytecode
|
||||
# - jvmDowngrader: Full modern Java via JVM Downgrader (syntax + stdlib APIs)
|
||||
# - modern: Native modern Java bytecode, no downgrading
|
||||
enableModernJavaSyntax = jvmDowngrader
|
||||
|
||||
# If set, ignores the above setting and compiles with the given toolchain. This may cause unexpected issues,
|
||||
# and should *not* be used in most situations. -1 disables this.
|
||||
# forceToolchainVersion = -1
|
||||
|
||||
# Target JVM version for JVM Downgrader bytecode downgrading.
|
||||
# Only used when enableModernJavaSyntax = jvmDowngrader
|
||||
# downgradeTargetVersion = 8
|
||||
|
||||
# Comma-separated list of Java versions for multi-release jar support (JVM Downgrader only).
|
||||
# Classes will be available in META-INF/versions/N/ for each version N in this list.
|
||||
# Default: "21,25" (J25+ gets native classes, J21-24 gets partial downgrade, J8-20 gets full downgrade).
|
||||
jvmDowngraderMultiReleaseVersions = 17, 21, 25
|
||||
|
||||
# Specifies how JVM Downgrader API stubs are provided. Options:
|
||||
# - shade: Shade minimized stubs into the jar
|
||||
# - gtnhlib: GTNHLib provides stubs at runtime (adds version constraint)
|
||||
# - external: Another dependency provides stubs (no constraint, no warning)
|
||||
# - (empty): Warning reminding you to configure stubs
|
||||
# Note: 'shade' option requires you to verify license compliance, see: https://github.com/unimined/JvmDowngrader/blob/main/LICENSE.md
|
||||
jvmDowngraderStubsProvider = gtnhlib
|
||||
|
||||
# Enables injecting missing generics into the decompiled source code for a better coding experience.
|
||||
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
|
||||
@@ -55,22 +79,13 @@ generateGradleTokenClass = com.gtnewhorizons.angelica.Tags
|
||||
# Name of the token containing the project's current version to generate/replace.
|
||||
gradleTokenVersion = VERSION
|
||||
|
||||
# [DEPRECATED] Mod ID replacement token.
|
||||
gradleTokenModId =
|
||||
|
||||
# [DEPRECATED] Mod name replacement token.
|
||||
gradleTokenModName =
|
||||
|
||||
# [DEPRECATED] Mod Group replacement token.
|
||||
gradleTokenGroupName =
|
||||
|
||||
# [DEPRECATED]
|
||||
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
|
||||
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
|
||||
# version in @Mod([...], version = VERSION, [...]).
|
||||
# Leave these properties empty to skip individual token replacements.
|
||||
replaceGradleTokenInFile =
|
||||
# replaceGradleTokenInFile =
|
||||
|
||||
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
|
||||
# leave this property empty.
|
||||
@@ -209,3 +224,7 @@ disableSpotless = true
|
||||
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
||||
# ideaCheckSpotlessOnBuild = true
|
||||
|
||||
# Non-GTNH properties
|
||||
org.gradle.configuration-cache = true
|
||||
org.gradle.jvmargs = -Xmx2g
|
||||
org.gradle.parallel = true
|
||||
Vendored
BIN
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -114,7 +114,6 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -172,7 +171,6 @@ fi
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
@@ -212,8 +210,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+1
-2
@@ -70,11 +70,10 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -15,23 +15,6 @@ repositories {
|
||||
includeGroup 'mega'
|
||||
}
|
||||
}
|
||||
exclusiveContent {
|
||||
forRepository {
|
||||
ivy {
|
||||
name = 'CoreTweaks releases'
|
||||
url = 'https://github.com/makamys/CoreTweaks/releases/download/'
|
||||
patternLayout {
|
||||
artifact '[revision]/[module]-1.7.10-[revision]+nomixin(-[classifier])(.[ext])'
|
||||
}
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
}
|
||||
}
|
||||
filter {
|
||||
includeGroup('CoreTweaks')
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = 'taumc'
|
||||
url = 'https://maven.taumc.org/releases'
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("com.gtnewhorizons.gtnhsettingsconvention") version("2.0.6")
|
||||
id("com.gtnewhorizons.gtnhsettingsconvention") version("2.0.18")
|
||||
}
|
||||
@@ -9,10 +9,14 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@LateMixin
|
||||
@SuppressWarnings("unused")
|
||||
public class AngelicaLateMixins implements ILateMixinLoader {
|
||||
|
||||
@Override
|
||||
public String getMixinConfig() {
|
||||
int v = Runtime.version().feature();
|
||||
if (v >= 21) return "mixins.angelica.late.j21.json";
|
||||
if (v >= 17) return "mixins.angelica.late.j17.json";
|
||||
return "mixins.angelica.late.json";
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.gtnewhorizons.angelica.utils.AnimationMode;
|
||||
import com.gtnewhorizons.angelica.utils.ManagedEnum;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -29,6 +31,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
guiFactory = "com.gtnewhorizons.angelica.config.AngelicaGuiConfigFactory")
|
||||
public class AngelicaMod {
|
||||
public static final String MOD_ID = "angelica";
|
||||
public static final Logger LOGGER = LogManager.getLogger("Angelica");
|
||||
|
||||
@SidedProxy(clientSide = "com.gtnewhorizons.angelica.proxy.ClientProxy", serverSide = "com.gtnewhorizons.angelica.proxy.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SpriteExtension;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class TextureServices {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void updateTextureAnimation(IIcon icon) {
|
||||
if(icon instanceof IPatchedTextureAtlasSprite patchedSprite) {
|
||||
patchedSprite.markNeedsAnimationUpdate();
|
||||
if (icon instanceof SpriteExtension ext) {
|
||||
ext.celeritas$markActive();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.gtnewhorizon.gtnhlib.util.font.GlyphReplacements;
|
||||
import com.gtnewhorizons.angelica.config.FontConfig;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.FontRendererAccessor;
|
||||
import cpw.mods.fml.client.SplashProgress;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.coderbot.iris.gl.program.Program;
|
||||
import net.coderbot.iris.gl.program.ProgramBuilder;
|
||||
@@ -508,10 +507,16 @@ public class BatchingFontRenderer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FontConfig.enableCustomFont) {
|
||||
if (FontConfig.enableCustomFont && FontConfig.enableGlyphReplacements) {
|
||||
String chrReplacement = GlyphReplacements.customGlyphs.get(String.valueOf(chr));
|
||||
if (chrReplacement != null) {
|
||||
chr = chrReplacement.charAt(0);
|
||||
char replacement = chrReplacement.charAt(0);
|
||||
boolean isReplacementCharAvailable =
|
||||
FontProviderCustom.getPrimary().isGlyphAvailable(replacement)
|
||||
|| FontProviderCustom.getFallback().isGlyphAvailable(replacement);
|
||||
if (isReplacementCharAvailable) {
|
||||
chr = replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +543,6 @@ public class BatchingFontRenderer {
|
||||
final float vSz = fontProvider.getVSize(chr);
|
||||
final float itOff = curItalic ? 1.0F : 0.0F; // italic offset
|
||||
final float shadowOffset = fontProvider.getShadowOffset();
|
||||
final float xShift = (fontProvider instanceof FontProviderCustom ? getGlyphScaleX() * FontConfig.customFontScale : 0.0f); // corrective factor to improve text alignment
|
||||
final int shadowCopies = FontConfig.shadowCopies;
|
||||
final int boldCopies = FontConfig.boldCopies;
|
||||
final ResourceLocation texture = fontProvider.getTexture(chr);
|
||||
@@ -547,20 +551,20 @@ public class BatchingFontRenderer {
|
||||
if (enableShadow) {
|
||||
for (int n = 1; n <= shadowCopies; n++) {
|
||||
final float shadowOffsetPart = shadowOffset * ((float) n / shadowCopies);
|
||||
pushTexRect(curX + shadowOffsetPart - xShift, heightNorth + shadowOffsetPart, glyphW - 1.0f, heightSouth, itOff, curShadowColor, uStart, vStart, uSz, vSz);
|
||||
pushTexRect(curX + shadowOffsetPart, heightNorth + shadowOffsetPart, glyphW - 1.0f, heightSouth, itOff, curShadowColor, uStart, vStart, uSz, vSz);
|
||||
|
||||
if (curBold) {
|
||||
pushTexRect(curX + 2.0f * shadowOffsetPart - xShift, heightNorth + shadowOffsetPart, glyphW - 1.0f, heightSouth, itOff, curShadowColor, uStart, vStart, uSz, vSz);
|
||||
pushTexRect(curX + 2.0f * shadowOffsetPart, heightNorth + shadowOffsetPart, glyphW - 1.0f, heightSouth, itOff, curShadowColor, uStart, vStart, uSz, vSz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pushTexRect(curX - xShift, heightNorth, glyphW - 1.0f, heightSouth, itOff, curColor, uStart, vStart, uSz, vSz);
|
||||
pushTexRect(curX, heightNorth, glyphW - 1.0f, heightSouth, itOff, curColor, uStart, vStart, uSz, vSz);
|
||||
|
||||
if (curBold) {
|
||||
for (int n = 1; n <= boldCopies; n++) {
|
||||
final float shadowOffsetPart = shadowOffset * ((float) n / boldCopies);
|
||||
pushTexRect(curX + shadowOffsetPart - xShift, heightNorth, glyphW - 1.0f, heightSouth, itOff, curColor, uStart, vStart, uSz, vSz);
|
||||
pushTexRect(curX + shadowOffsetPart, heightNorth, glyphW - 1.0f, heightSouth, itOff, curColor, uStart, vStart, uSz, vSz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +40,6 @@ public final class FontProviderCustom implements FontProvider {
|
||||
private FontProviderCustom(byte id) {
|
||||
this.id = id;
|
||||
Font[] availableFonts = FontStrategist.getAvailableFonts();
|
||||
if (availableFonts.length == 0) {
|
||||
LOGGER.fatal("There seem to be no fonts available on this system! Disabling custom font and throwing an exception in an attempt to restore the session.");
|
||||
FontConfig.enableCustomFont = false;
|
||||
ConfigurationManager.save(FontConfig.class);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
String myFontName = switch (this.id) {
|
||||
case 0 -> FontConfig.customFontNamePrimary;
|
||||
case 1 -> FontConfig.customFontNameFallback;
|
||||
|
||||
@@ -27,34 +27,40 @@ public class FontStrategist {
|
||||
public static final Logger LOGGER = LogManager.getLogger("Angelica");
|
||||
|
||||
static {
|
||||
// get available fonts without duplicates (250 copies of dialog.plain need not apply)
|
||||
Font[] availableFontsDirty = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
||||
HashMap<String, Font> fontSet = new HashMap<>();
|
||||
HashMultiset<String> duplicates = HashMultiset.create(); // for debugging
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
LOGGER.warn("GraphicsEnvironment.isHeadless() returned true! Custom fonts will be unavailable. This is likely a MacOS issue.");
|
||||
availableFonts = new Font[0];
|
||||
} else {
|
||||
// get available fonts without duplicates (250 copies of dialog.plain need not apply)
|
||||
Font[] availableFontsDirty = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
||||
HashMap<String, Font> fontSet = new HashMap<>();
|
||||
HashMultiset<String> duplicates = HashMultiset.create(); // for debugging
|
||||
|
||||
for (Font font : availableFontsDirty) {
|
||||
String fontName = font.getFontName();
|
||||
if (fontSet.containsKey(fontName)) {
|
||||
duplicates.add(fontName);
|
||||
} else {
|
||||
fontSet.put(fontName, font);
|
||||
}
|
||||
}
|
||||
|
||||
if (!duplicates.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder(duplicates.size() + " duplicate font(s) found in the list reported by Java: ");
|
||||
for (Iterator<String> iter = duplicates.stream().distinct().iterator(); iter.hasNext(); ) {
|
||||
String dupe = iter.next();
|
||||
sb.append(duplicates.count(dupe)).append("x ").append(dupe);
|
||||
if (iter.hasNext()) {
|
||||
sb.append(", ");
|
||||
for (Font font : availableFontsDirty) {
|
||||
String fontName = font.getFontName();
|
||||
if (fontSet.containsKey(fontName)) {
|
||||
duplicates.add(fontName);
|
||||
} else {
|
||||
fontSet.put(fontName, font);
|
||||
}
|
||||
}
|
||||
sb.append(". Some fonts may be missing from the font selection menu.");
|
||||
LOGGER.warn(sb.toString());
|
||||
}
|
||||
|
||||
availableFonts = fontSet.values().stream().sorted(Comparator.comparing(Font::getFontName)).toArray(Font[]::new);
|
||||
if (!duplicates.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder(duplicates.size() + " duplicate font(s) found in the list reported by Java: ");
|
||||
for (Iterator<String> iter = duplicates.stream().distinct().iterator(); iter.hasNext(); ) {
|
||||
String dupe = iter.next();
|
||||
sb.append(duplicates.count(dupe)).append("x ").append(dupe);
|
||||
if (iter.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(". Some fonts may be missing from the font selection menu.");
|
||||
LOGGER.warn(sb.toString());
|
||||
}
|
||||
availableFonts = fontSet.values().stream().sorted(Comparator.comparing(Font::getFontName)).toArray(Font[]::new);
|
||||
|
||||
LOGGER.info("Got {} fonts from GraphicsEnvironment ({} after deduplication)", availableFontsDirty.length, availableFonts.length);
|
||||
}
|
||||
|
||||
// create and add the resource pack that provides fonts
|
||||
HashMap<String, File> packMap = new HashMap<>();
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.gtnewhorizons.angelica.client.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.config.EntityLightConfig;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.config.EntityLightConfigStorage;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.config.EntityTypeEntry;
|
||||
import jss.notfine.core.Settings;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.Option;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionGroup;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionImpl;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionImpact;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
|
||||
import me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DynamicLightsOptionPages {
|
||||
|
||||
public static OptionPage dynamicLights() {
|
||||
if (!DynamicLights.configEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<OptionGroup> groups = new ArrayList<>();
|
||||
|
||||
groups.add(OptionGroup.createBuilder()
|
||||
.add(Settings.DYNAMIC_LIGHTS.option)
|
||||
.add(Settings.DYNAMIC_LIGHTS_SHADER_FORCE.option)
|
||||
.build());
|
||||
|
||||
groups.add(OptionGroup.createBuilder()
|
||||
.add(Settings.DYNAMIC_LIGHTS_FRUSTUM_CULLING.option)
|
||||
.add(Settings.DYNAMIC_LIGHTS_ADAPTIVE_TICKING.option)
|
||||
.add(Settings.DYNAMIC_LIGHTS_CULL_TIMEOUT.option)
|
||||
.build());
|
||||
|
||||
groups.add(OptionGroup.createBuilder()
|
||||
.add(Settings.DYNAMIC_LIGHTS_SLOW_DIST.option)
|
||||
.add(Settings.DYNAMIC_LIGHTS_SLOWER_DIST.option)
|
||||
.add(Settings.DYNAMIC_LIGHTS_BACKGROUND_DIST.option)
|
||||
.build());
|
||||
|
||||
// Entity type toggles - grouped by mod ID
|
||||
List<EntityTypeEntry> allEntities = EntityLightConfig.getAllEntityTypes();
|
||||
Map<String, List<EntityTypeEntry>> byMod = new LinkedHashMap<>();
|
||||
|
||||
for (EntityTypeEntry entry : allEntities) {
|
||||
byMod.computeIfAbsent(entry.getModId(), _ -> new ArrayList<>()).add(entry);
|
||||
}
|
||||
|
||||
// Create a group for each mod's entities
|
||||
for (Map.Entry<String, List<EntityTypeEntry>> modEntry : byMod.entrySet()) {
|
||||
String modId = modEntry.getKey();
|
||||
List<EntityTypeEntry> entities = modEntry.getValue();
|
||||
|
||||
OptionGroup.Builder groupBuilder = OptionGroup.createBuilder();
|
||||
|
||||
for (EntityTypeEntry entity : entities) {
|
||||
Option<Boolean> option = createEntityOption(entity);
|
||||
if (option != null) {
|
||||
groupBuilder.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
// Only add group if it has options
|
||||
OptionGroup group = groupBuilder.build();
|
||||
if (!group.getOptions().isEmpty()) {
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
return new OptionPage(I18n.format("options.dynamiclights.page"), ImmutableList.copyOf(groups));
|
||||
}
|
||||
|
||||
private static Option<Boolean> createEntityOption(EntityTypeEntry entry) {
|
||||
final String className = entry.getClassName();
|
||||
|
||||
// Resolve class once during option creation, not on every get/set
|
||||
Class<?> resolvedClass;
|
||||
try {
|
||||
resolvedClass = Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Class not loaded, skip this option
|
||||
return null;
|
||||
}
|
||||
|
||||
final Class<?> entityClass = resolvedClass;
|
||||
|
||||
return OptionImpl.createBuilder(Boolean.class, EntityLightConfigStorage.INSTANCE)
|
||||
.setName(entry.getDisplayName() + " (" + entry.getModId() + ")")
|
||||
.setTooltip(I18n.format("options.dynamiclights.entity.tooltip", entry.getDisplayName()))
|
||||
.setControl(TickBoxControl::new)
|
||||
.setBinding(
|
||||
(_, value) -> EntityLightConfig.setEntityTypeEnabled(entityClass, value),
|
||||
storage -> EntityLightConfig.isEntityTypeEnabled(entityClass)
|
||||
)
|
||||
.setImpact(OptionImpact.LOW)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class FontConfigScreen extends GuiScreen {
|
||||
private final String searchPrompt;
|
||||
private final String testAreaPrompt;
|
||||
private List<String> testAreaInfo;
|
||||
private List<String> noFontsWarning;
|
||||
private String currentPrimaryFontName;
|
||||
private String currentFallbackFontName;
|
||||
private FontList fontList;
|
||||
@@ -332,9 +333,22 @@ public class FontConfigScreen extends GuiScreen {
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float delta) {
|
||||
drawBackground(0);
|
||||
fontList.drawScreen(mouseX, mouseY, delta);
|
||||
searchBox.drawTextBox();
|
||||
// I bet you thought this was drawn inside the search box, not on top of it.
|
||||
|
||||
this.fontList.drawScreen(mouseX, mouseY, delta);
|
||||
if (availableFonts.length == 0) {
|
||||
if (this.noFontsWarning == null) {
|
||||
this.noFontsWarning = this.fontRendererObj.listFormattedStringToWidth(
|
||||
I18n.format("options.angelica.fontconfig.no_fonts_warning"), this.width / 2
|
||||
);
|
||||
}
|
||||
int y = 80;
|
||||
for (String s : this.noFontsWarning) {
|
||||
drawCenteredString(this.fontRendererObj, s, this.width / 3, y, 0xFFFFFF);
|
||||
y += this.fontRendererObj.FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
this.searchBox.drawTextBox();
|
||||
if (!this.searchBox.isFocused() && this.searchBox.getText().isEmpty()) {
|
||||
this.drawCenteredString(this.fontRendererObj, this.searchPrompt,
|
||||
this.searchBox.xPosition + this.fontRendererObj.getStringWidth(this.searchPrompt) / 2 + 4,
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.gtnewhorizons.angelica.commands;
|
||||
|
||||
// Debug commands adapted from Beddium by Ven and FalsePattern
|
||||
|
||||
import com.gtnewhorizons.angelica.debug.ChunkDebugMinimap;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasDebugScreenHandler;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasWorldRenderer;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AngelicaCommand extends CommandBase {
|
||||
|
||||
private static final List<String> SUBCOMMANDS = Arrays.asList("wireframe", "fog", "minimap", "help");
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "angelica";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/angelica <wireframe|fog|minimap|help>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0; // Available to all players (client-side only)
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsMatchingLastWord(args, SUBCOMMANDS.toArray(new String[0]));
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendHelp(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "wireframe" -> handleWireframe(sender);
|
||||
case "fog" -> handleFog(sender);
|
||||
case "minimap" -> handleMinimap(sender);
|
||||
default -> sendHelp(sender);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleWireframe(ICommandSender sender) {
|
||||
CeleritasWorldRenderer.DEBUG_WIREFRAME_MODE = !CeleritasWorldRenderer.DEBUG_WIREFRAME_MODE;
|
||||
final String state = CeleritasWorldRenderer.DEBUG_WIREFRAME_MODE ? "ON" : "OFF";
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[Angelica] " + EnumChatFormatting.WHITE + "Wireframe mode: " + state));
|
||||
}
|
||||
|
||||
private void handleFog(ICommandSender sender) {
|
||||
CeleritasDebugScreenHandler.showFogDebug = !CeleritasDebugScreenHandler.showFogDebug;
|
||||
final String f3State = CeleritasDebugScreenHandler.showFogDebug ? "ON" : "OFF";
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[Angelica] " + EnumChatFormatting.WHITE + "Fog debug (F3): " + f3State));
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + " " + CeleritasDebugScreenHandler.getFogDebugString()));
|
||||
}
|
||||
|
||||
private void handleMinimap(ICommandSender sender) {
|
||||
ChunkDebugMinimap.toggle();
|
||||
final String state = ChunkDebugMinimap.isEnabled() ? "ON" : "OFF";
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[Angelica] " + EnumChatFormatting.WHITE + "Chunk debug minimap: " + state));
|
||||
}
|
||||
|
||||
private void sendHelp(ICommandSender sender) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[Angelica] Debug Commands:"));
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + " /angelica wireframe" + EnumChatFormatting.WHITE + " - Toggle wireframe rendering"));
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + " /angelica fog" + EnumChatFormatting.WHITE + " - Toggle fog debug on F3"));
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GRAY + " /angelica minimap" + EnumChatFormatting.WHITE + " - Toggle chunk debug overlay"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof ICommand cmd) {
|
||||
return this.getCommandName().compareTo(cmd.getCommandName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class BetterCrashesCompat implements StateManager.IResettable {
|
||||
@Override
|
||||
public void resetState() {
|
||||
LOGGER.info("Reloading SodiumRenderer");
|
||||
((IRenderGlobalExt) Minecraft.getMinecraft().renderGlobal).reload();
|
||||
((IRenderGlobalExt) Minecraft.getMinecraft().renderGlobal).angelica$reload();
|
||||
LOGGER.info("Resetting GLStateManager");
|
||||
GLStateManager.reset();
|
||||
}
|
||||
|
||||
@@ -34,10 +34,17 @@ public class MatrixStack {
|
||||
public void pop() {
|
||||
this.matrixStack.removeLast();
|
||||
}
|
||||
public boolean clear() {
|
||||
public boolean isEmpty() {
|
||||
return this.matrixStack.size() == 1;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
while (this.matrixStack.size() > 1) {
|
||||
this.matrixStack.removeLast();
|
||||
}
|
||||
loadIdentity();
|
||||
}
|
||||
|
||||
public void translate(double d, double e, double f) {
|
||||
final Entry lv = (Entry)this.matrixStack.getLast();
|
||||
lv.model.translate((float)d, (float)e, (float)f);
|
||||
|
||||
@@ -4,10 +4,21 @@ import com.gtnewhorizon.gtnhlib.config.Config;
|
||||
|
||||
@Config(modid = "angelica", filename = "angelica-modules")
|
||||
public class AngelicaConfig {
|
||||
@Config.Comment("Enable Sodium rendering")
|
||||
@Config.Comment("Enable Celeritas terrain rendering")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableSodium;
|
||||
public static boolean enableCeleritas;
|
||||
|
||||
@Config.Comment("Enable multi-threaded chunk building for improved performance [Requires Celeritas]")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresWorldRestart
|
||||
public static boolean enableThreadedChunkBuilding;
|
||||
|
||||
@Config.Comment("Number of chunk builder threads. 0 = auto-detect, -1 = use single-threaded fallback")
|
||||
@Config.DefaultInt(0)
|
||||
@Config.RangeInt(min = -1, max = 16)
|
||||
@Config.RequiresWorldRestart
|
||||
public static int chunkBuilderThreadCount;
|
||||
|
||||
@Config.Comment("Enable NotFine Options")
|
||||
@Config.DefaultBoolean(false)
|
||||
@@ -17,11 +28,6 @@ public class AngelicaConfig {
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableReesesSodiumOptions;
|
||||
|
||||
@Config.Comment("Enable Sodium fluid rendering [Experimental]")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableSodiumFluidRendering;
|
||||
|
||||
@Config.Comment("Inject BakedModel rendering into some vanilla blocks")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
@@ -32,7 +38,7 @@ public class AngelicaConfig {
|
||||
@Config.Ignore()
|
||||
public static boolean enableTestBlocks;
|
||||
|
||||
@Config.Comment("Enable Iris Shaders [Requires Sodium]")
|
||||
@Config.Comment("Enable Iris Shaders [Requires Celeritas]")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableIris;
|
||||
@@ -210,4 +216,9 @@ public class AngelicaConfig {
|
||||
@Config.Comment("Register HardcodedCustomUniforms in Iris Shaders. May help with compatibility in certain shader packs")
|
||||
@Config.DefaultBoolean(false)
|
||||
public static boolean enableHardcodedCustomUniforms;
|
||||
|
||||
@Config.Comment("Renders chunks before neighbors are ready. Improves loading at render distance edges, useful for low render distance servers.")
|
||||
@Config.DefaultBoolean(false)
|
||||
public static boolean useVanillaChunkTracking;
|
||||
|
||||
}
|
||||
@@ -70,4 +70,11 @@ public class FontConfig {
|
||||
@Config.DefaultFloat(1.5F)
|
||||
@Config.RangeFloat(min = 0.1F, max = 3F)
|
||||
public static float customFontScale;
|
||||
|
||||
@Config.Comment({"Mods can provide Angelica with a mapping of special characters to either get replaced with " +
|
||||
"different characters or rendered using the default Unicode font. Setting this to false disables the " +
|
||||
"replacement, which is useful in cases where custom fonts have direct support for these special characters. ",
|
||||
"See for additional details: https://github.com/GTNewHorizons/Angelica/issues/1239#issuecomment-3729877936"})
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableGlyphReplacements;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Adapated from: Beddium for usage in Angelica
|
||||
*
|
||||
* Copyright (C) 2025 Ven, FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, only version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gtnewhorizons.angelica.debug;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaRenderSectionManager;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasWorldRenderer;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Debug overlay that renders a minimap showing chunk loading and rendering state. Toggle via /angelica minimap
|
||||
*/
|
||||
public class ChunkDebugMinimap {
|
||||
private static final ChunkDebugMinimap INSTANCE = new ChunkDebugMinimap();
|
||||
@Getter
|
||||
private static volatile boolean enabled = false;
|
||||
|
||||
private static final int RANGE = 32; // Chunks in each direction from player
|
||||
|
||||
public static synchronized void toggle() {
|
||||
if (enabled) disable();
|
||||
else enable();
|
||||
}
|
||||
|
||||
public static synchronized void enable() {
|
||||
if (enabled) return;
|
||||
enabled = true;
|
||||
MinecraftForge.EVENT_BUS.register(INSTANCE);
|
||||
}
|
||||
|
||||
public static synchronized void disable() {
|
||||
if (!enabled) return;
|
||||
enabled = false;
|
||||
MinecraftForge.EVENT_BUS.unregister(INSTANCE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.theWorld == null || mc.thePlayer == null) return;
|
||||
|
||||
final CeleritasWorldRenderer renderer;
|
||||
try {
|
||||
renderer = CeleritasWorldRenderer.getInstance();
|
||||
} catch (IllegalStateException e) {
|
||||
return; // Renderer not initialized
|
||||
}
|
||||
|
||||
final AngelicaRenderSectionManager manager = renderer.getRenderSectionManager();
|
||||
if (manager == null) return;
|
||||
|
||||
final float partialTicks = event.partialTicks;
|
||||
final double pX = mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX) * partialTicks;
|
||||
final double pZ = mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ) * partialTicks;
|
||||
|
||||
final int playerChunkX = ((int) Math.floor(pX)) >> 4;
|
||||
final int playerChunkZ = ((int) Math.floor(pZ)) >> 4;
|
||||
|
||||
// Save GL state
|
||||
GLStateManager.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GLStateManager.glPushMatrix();
|
||||
|
||||
// Setup rendering
|
||||
GLStateManager.glScaled(2, 2, 1);
|
||||
GLStateManager.glTranslated(32, 32, 0);
|
||||
|
||||
GLStateManager.disableLighting();
|
||||
GLStateManager.disableTexture();
|
||||
GLStateManager.disableDepthTest();
|
||||
GLStateManager.enableBlend();
|
||||
GLStateManager.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GLStateManager.glBegin(GL11.GL_QUADS);
|
||||
|
||||
final ChunkProviderClient chunkProvider = (ChunkProviderClient) mc.theWorld.getChunkProvider();
|
||||
|
||||
for (int x = playerChunkX - RANGE; x < playerChunkX + RANGE; x++) {
|
||||
for (int z = playerChunkZ - RANGE; z < playerChunkZ + RANGE; z++) {
|
||||
drawChunk(x, z, playerChunkX, playerChunkZ, manager, chunkProvider);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glEnd();
|
||||
|
||||
// Restore GL state
|
||||
GLStateManager.enableLighting();
|
||||
GLStateManager.enableDepthTest();
|
||||
GLStateManager.disableBlend();
|
||||
GLStateManager.glPopMatrix();
|
||||
GLStateManager.glPopAttrib();
|
||||
}
|
||||
|
||||
private void drawChunk(int chunkX, int chunkZ, int playerChunkX, int playerChunkZ, AngelicaRenderSectionManager manager, ChunkProviderClient chunkProvider) {
|
||||
boolean initialized = false;
|
||||
float r = 0, g = 0, b = 0;
|
||||
|
||||
// Check all 16 sections in the chunk column
|
||||
for (int y = 0; y < 16; y++) {
|
||||
if (manager.isSectionBuilt(chunkX, y, chunkZ) && !manager.isSectionVisuallyEmpty(chunkX, y, chunkZ)) {
|
||||
initialized = true;
|
||||
g = 1; // Green = built
|
||||
if (manager.isSectionVisible(chunkX, y, chunkZ)) {
|
||||
b = 1; // Cyan = visible
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
// Check if chunk is loaded
|
||||
final var chunk = chunkProvider.provideChunk(chunkX, chunkZ);
|
||||
if (chunk instanceof EmptyChunk) {
|
||||
r = 1; // Red = unloaded
|
||||
} else {
|
||||
b = 1; // Blue = loaded but not built
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glColor4f(r, g, b, 0.8f);
|
||||
|
||||
final int xStart = chunkX - playerChunkX;
|
||||
final int zStart = chunkZ - playerChunkZ;
|
||||
final int xEnd = xStart + 1;
|
||||
final int zEnd = zStart + 1;
|
||||
|
||||
GLStateManager.glVertex3d(xStart, zStart, 0);
|
||||
GLStateManager.glVertex3d(xStart, zEnd, 0);
|
||||
GLStateManager.glVertex3d(xEnd, zEnd, 0);
|
||||
GLStateManager.glVertex3d(xEnd, zStart, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Calculates the appropriate tick mode for a dynamic light source based on distance from camera and position relative to camera direction.
|
||||
*/
|
||||
public final class AdaptiveTickCalculator {
|
||||
|
||||
// Distance thresholds in blocks (configurable via settings)
|
||||
private static int slowDistance = 32; // ~2 chunks
|
||||
private static int slowerDistance = 64; // ~4 chunks
|
||||
private static int backgroundDistance = 128; // ~8 chunks
|
||||
|
||||
// Squared thresholds for efficient distance comparison
|
||||
private static int slowDistanceSq = slowDistance * slowDistance;
|
||||
private static int slowerDistanceSq = slowerDistance * slowerDistance;
|
||||
private static int backgroundDistanceSq = backgroundDistance * backgroundDistance;
|
||||
|
||||
private AdaptiveTickCalculator() {}
|
||||
|
||||
/**
|
||||
* Calculate the appropriate tick mode for a light source.
|
||||
*/
|
||||
public static AdaptiveTickMode calculate(@NotNull IDynamicLightSource source, double cameraX, double cameraY, double cameraZ, double lookDirX, double lookDirZ) {
|
||||
double dx = source.angelica$getDynamicLightX() - cameraX;
|
||||
double dy = source.angelica$getDynamicLightY() - cameraY;
|
||||
double dz = source.angelica$getDynamicLightZ() - cameraZ;
|
||||
|
||||
double distSq = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
// Check if behind camera (dot product of direction to source with look direction)
|
||||
// Only use X and Z for horizontal check (more stable as player looks up/down)
|
||||
double dot = dx * lookDirX + dz * lookDirZ;
|
||||
boolean behindCamera = dot < 0;
|
||||
|
||||
// Behind camera always gets BACKGROUND mode
|
||||
if (behindCamera) {
|
||||
return AdaptiveTickMode.BACKGROUND;
|
||||
}
|
||||
|
||||
// Distance-based mode selection
|
||||
if (distSq > backgroundDistanceSq) {
|
||||
return AdaptiveTickMode.BACKGROUND;
|
||||
}
|
||||
if (distSq > slowerDistanceSq) {
|
||||
return AdaptiveTickMode.SLOWER;
|
||||
}
|
||||
if (distSq > slowDistanceSq) {
|
||||
return AdaptiveTickMode.SLOW;
|
||||
}
|
||||
|
||||
return AdaptiveTickMode.REAL_TIME;
|
||||
}
|
||||
|
||||
public static void setSlowDistance(int distance) {
|
||||
slowDistance = distance;
|
||||
slowDistanceSq = distance * distance;
|
||||
}
|
||||
|
||||
public static void setSlowerDistance(int distance) {
|
||||
slowerDistance = distance;
|
||||
slowerDistanceSq = distance * distance;
|
||||
}
|
||||
|
||||
public static void setBackgroundDistance(int distance) {
|
||||
backgroundDistance = distance;
|
||||
backgroundDistanceSq = distance * distance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
/**
|
||||
* Defines tick modes for adaptive dynamic light updates. Distant or off-screen light sources update less frequently to save CPU.
|
||||
*/
|
||||
public enum AdaptiveTickMode {
|
||||
/** Updates every tick - for nearby, visible light sources */
|
||||
REAL_TIME(1),
|
||||
/** Updates every 5 ticks - for light sources at moderate distance */
|
||||
SLOW(5),
|
||||
/** Updates every 10 ticks - for light sources at far distance */
|
||||
SLOWER(10),
|
||||
/** Updates every 20 ticks - for light sources behind the camera or very far */
|
||||
BACKGROUND(20);
|
||||
|
||||
private final int delay;
|
||||
|
||||
AdaptiveTickMode(int delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public boolean shouldTickThisFrame(int worldTick, int sourceHash) {
|
||||
if (delay <= 1) {
|
||||
return true;
|
||||
}
|
||||
return (worldTick % delay) == Math.abs(sourceHash % delay);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.longs.LongIterator;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* Manages deferred chunk rebuilds for dynamic lights with optional frustum culling. Instead of scheduling chunk rebuilds immediately
|
||||
* when light sources move, this tracks pending rebuilds and only schedules visible chunks.
|
||||
*/
|
||||
public class ChunkRebuildManager {
|
||||
|
||||
/** Maps packed chunk position to ticks waiting */
|
||||
private final Long2IntOpenHashMap pendingRebuilds = new Long2IntOpenHashMap();
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
/** Maximum ticks a pending rebuild can wait before being forced through */
|
||||
private static int maxTicksWaiting = 100;
|
||||
|
||||
/** Reusable lists for processVisible - only used from render thread */
|
||||
private final LongArrayList candidates = new LongArrayList();
|
||||
private final LongArrayList toRebuild = new LongArrayList();
|
||||
private final LongArrayList toIncrement = new LongArrayList();
|
||||
|
||||
public static void setMaxTicksWaiting(int ticks) {
|
||||
maxTicksWaiting = Math.max(20, Math.min(ticks, 600)); // Clamp 1-30 seconds (20-600 ticks)
|
||||
}
|
||||
|
||||
public void requestRebuild(int x, int y, int z) {
|
||||
final long packed = CoordinatePacker.pack(x, y, z);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
// Reset wait counter if already pending, otherwise add new entry
|
||||
pendingRebuilds.put(packed, 0);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void processVisible(Viewport viewport, @NotNull IDynamicLightWorldRenderer renderer) {
|
||||
candidates.clear();
|
||||
toRebuild.clear();
|
||||
toIncrement.clear();
|
||||
|
||||
// Phase 1: Collect all pending chunks with read lock (fast)
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
if (pendingRebuilds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Collect candidates that might need processing
|
||||
final var iterator = pendingRebuilds.long2IntEntrySet().fastIterator();
|
||||
while (iterator.hasNext()) {
|
||||
final var entry = iterator.next();
|
||||
final long packed = entry.getLongKey();
|
||||
final int ticksWaiting = entry.getIntValue();
|
||||
|
||||
// Force process if no viewport or waited too long
|
||||
if (viewport == null || ticksWaiting >= maxTicksWaiting) {
|
||||
toRebuild.add(packed);
|
||||
} else {
|
||||
candidates.add(packed);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
|
||||
// Phase 2: Check visibility
|
||||
for (int i = 0; i < candidates.size(); i++) {
|
||||
long packed = candidates.getLong(i);
|
||||
int x = CoordinatePacker.unpackX(packed);
|
||||
int y = CoordinatePacker.unpackY(packed);
|
||||
int z = CoordinatePacker.unpackZ(packed);
|
||||
|
||||
if (isChunkVisible(viewport, x, y, z)) {
|
||||
toRebuild.add(packed);
|
||||
} else {
|
||||
toIncrement.add(packed);
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 3: Update map with write lock (brief)
|
||||
if (!toRebuild.isEmpty() || !toIncrement.isEmpty()) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
// Remove chunks we're going to rebuild
|
||||
LongIterator rebuildIter = toRebuild.iterator();
|
||||
while (rebuildIter.hasNext()) {
|
||||
pendingRebuilds.remove(rebuildIter.nextLong());
|
||||
}
|
||||
LongIterator incIter = toIncrement.iterator();
|
||||
while (incIter.hasNext()) {
|
||||
long packed = incIter.nextLong();
|
||||
int current = pendingRebuilds.get(packed);
|
||||
if (pendingRebuilds.containsKey(packed)) {
|
||||
pendingRebuilds.put(packed, current + 1);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 4: Schedule rebuilds outside of lock
|
||||
for (int i = 0; i < toRebuild.size(); i++) {
|
||||
final long packed = toRebuild.getLong(i);
|
||||
renderer.scheduleRebuildForChunk(
|
||||
CoordinatePacker.unpackX(packed),
|
||||
CoordinatePacker.unpackY(packed),
|
||||
CoordinatePacker.unpackZ(packed),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isChunkVisible(Viewport viewport, int chunkX, int chunkY, int chunkZ) {
|
||||
// Convert chunk section coords to block coords
|
||||
int blockX = chunkX << 4;
|
||||
int blockY = chunkY << 4;
|
||||
int blockZ = chunkZ << 4;
|
||||
|
||||
// Check if the 16x16x16 chunk section box is visible
|
||||
return viewport.isBoxVisible(
|
||||
blockX, blockY, blockZ,
|
||||
blockX + 16, blockY + 16, blockZ + 16
|
||||
);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
pendingRebuilds.clear();
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int getPendingCount() {
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
return pendingRebuilds.size();
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import com.gtnewhorizons.angelica.api.IDynamicLightProducer;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.battlegear2.Battlegear2Compat;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.config.EntityLightConfig;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.PrimedEntityAccessor;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
|
||||
import mods.battlegear2.api.core.IBattlePlayer;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -22,20 +23,28 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DynamicLights {
|
||||
private static DynamicLights instance;
|
||||
private static IDynamicLightWorldRenderer activeRenderer;
|
||||
public static DynamicLightsMode Mode = DynamicLightsMode.OFF;
|
||||
public static boolean ShaderForce = false;
|
||||
public static boolean FrustumCullingEnabled = true;
|
||||
public static boolean AdaptiveTickingEnabled = true;
|
||||
|
||||
public static final boolean configEnabled = AngelicaConfig.enableDynamicLights;
|
||||
|
||||
@@ -43,6 +52,7 @@ public class DynamicLights {
|
||||
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
|
||||
private final Set<IDynamicLightSource> dynamicLightSources = new ObjectOpenHashSet<>();
|
||||
private final ReentrantReadWriteLock lightSourcesLock = new ReentrantReadWriteLock();
|
||||
private final ChunkRebuildManager chunkRebuildManager = new ChunkRebuildManager();
|
||||
private long lastUpdate = System.currentTimeMillis();
|
||||
private int lastUpdateCount = 0;
|
||||
|
||||
@@ -60,12 +70,20 @@ public class DynamicLights {
|
||||
(ShaderForce || !IrisApi.getInstance().isShaderPackInUse());
|
||||
}
|
||||
|
||||
public static IDynamicLightWorldRenderer getActiveRenderer() {
|
||||
return activeRenderer;
|
||||
}
|
||||
|
||||
public static void setActiveRenderer(IDynamicLightWorldRenderer renderer) {
|
||||
activeRenderer = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all light sources.
|
||||
*
|
||||
* @param renderer the renderer
|
||||
*/
|
||||
public void updateAll(@NotNull SodiumWorldRenderer renderer) {
|
||||
public void updateAll(@NotNull IDynamicLightWorldRenderer renderer) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
@@ -74,8 +92,43 @@ public class DynamicLights {
|
||||
this.lastUpdate = now;
|
||||
this.lastUpdateCount = 0;
|
||||
|
||||
// Get camera info for adaptive ticking
|
||||
double cameraX = 0, cameraY = 0, cameraZ = 0;
|
||||
double lookDirX = 0, lookDirZ = 1;
|
||||
int worldTick = 0;
|
||||
|
||||
if (AdaptiveTickingEnabled) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.theWorld != null && mc.renderViewEntity != null) {
|
||||
cameraX = mc.renderViewEntity.posX;
|
||||
cameraY = mc.renderViewEntity.posY + mc.renderViewEntity.getEyeHeight();
|
||||
cameraZ = mc.renderViewEntity.posZ;
|
||||
worldTick = (int) (mc.theWorld.getTotalWorldTime() & 0x7FFFFFFF);
|
||||
|
||||
// Calculate look direction from yaw (normalized horizontal direction)
|
||||
float yaw = mc.renderViewEntity.rotationYaw;
|
||||
double yawRad = Math.toRadians(yaw);
|
||||
lookDirX = -Math.sin(yawRad);
|
||||
lookDirZ = Math.cos(yawRad);
|
||||
}
|
||||
}
|
||||
|
||||
this.lightSourcesLock.readLock().lock();
|
||||
for (var lightSource : this.dynamicLightSources) {
|
||||
// Entity type filter
|
||||
if (!EntityLightConfig.isEntityTypeEnabled(lightSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Adaptive ticking filter
|
||||
if (AdaptiveTickingEnabled) {
|
||||
AdaptiveTickMode mode = AdaptiveTickCalculator.calculate(
|
||||
lightSource, cameraX, cameraY, cameraZ, lookDirX, lookDirZ);
|
||||
if (!mode.shouldTickThisFrame(worldTick, lightSource.hashCode())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (lightSource.angelica$updateDynamicLight(renderer))
|
||||
this.lastUpdateCount++;
|
||||
}
|
||||
@@ -107,8 +160,8 @@ public class DynamicLights {
|
||||
it = dynamicLightSources.next();
|
||||
if (it.equals(lightSource)) {
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null)
|
||||
lightSource.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
if (activeRenderer != null)
|
||||
lightSource.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -130,10 +183,10 @@ public class DynamicLights {
|
||||
it = dynamicLightSources.next();
|
||||
if (filter.test(it)) {
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null) {
|
||||
if (activeRenderer != null) {
|
||||
if (it.angelica$getLuminance() > 0)
|
||||
it.angelica$resetDynamicLight();
|
||||
it.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
it.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -153,10 +206,10 @@ public class DynamicLights {
|
||||
while (dynamicLightSources.hasNext()) {
|
||||
it = dynamicLightSources.next();
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null) {
|
||||
if (activeRenderer != null) {
|
||||
if (it.angelica$getLuminance() > 0)
|
||||
it.angelica$resetDynamicLight();
|
||||
it.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
it.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +256,20 @@ public class DynamicLights {
|
||||
return MathHelper.clamp_double(result, 0, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dynamic light level at an exact world position (for smooth per-vertex lighting).
|
||||
*/
|
||||
public double getDynamicLightLevel(double x, double y, double z) {
|
||||
double result = 0;
|
||||
this.lightSourcesLock.readLock().lock();
|
||||
for (var lightSource : this.dynamicLightSources) {
|
||||
result = maxDynamicLightLevelExact(x, y, z, lightSource, result);
|
||||
}
|
||||
this.lightSourcesLock.readLock().unlock();
|
||||
|
||||
return MathHelper.clamp_double(result, 0, 15);
|
||||
}
|
||||
|
||||
public double getDynamicLightLevel(@NotNull BlockPos pos) {
|
||||
return this.getDynamicLightLevel(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
@@ -229,6 +296,29 @@ public class DynamicLights {
|
||||
return currentLightLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates dynamic light level at an exact position (no block center offset).
|
||||
* Used for smooth per-vertex lighting.
|
||||
*/
|
||||
public static double maxDynamicLightLevelExact(double x, double y, double z, @NotNull IDynamicLightSource lightSource, double currentLightLevel) {
|
||||
int luminance = lightSource.angelica$getLuminance();
|
||||
if (luminance > 0) {
|
||||
double dx = x - lightSource.angelica$getDynamicLightX();
|
||||
double dy = y - lightSource.angelica$getDynamicLightY();
|
||||
double dz = z - lightSource.angelica$getDynamicLightZ();
|
||||
|
||||
double distanceSquared = dx * dx + dy * dy + dz * dz;
|
||||
if (distanceSquared <= MAX_RADIUS_SQUARED) {
|
||||
double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
|
||||
double lightLevel = multiplier * (double) luminance;
|
||||
if (lightLevel > currentLightLevel) {
|
||||
return lightLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentLightLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic light level generated by the light source at the specified position.
|
||||
*
|
||||
@@ -245,6 +335,51 @@ public class DynamicLights {
|
||||
return this.getLightmapWithDynamicLight(this.getDynamicLightLevel(x, y, z), lightmap);
|
||||
}
|
||||
|
||||
public List<IDynamicLightSource> getSourcesForChunk(int chunkMinX, int chunkMinY, int chunkMinZ) {
|
||||
// Chunk center
|
||||
final double centerX = chunkMinX + 8.0;
|
||||
final double centerY = chunkMinY + 8.0;
|
||||
final double centerZ = chunkMinZ + 8.0;
|
||||
|
||||
// Max distance from chunk center to any corner is sqrt(3) * 8 ≈ 13.86
|
||||
// Add MAX_RADIUS to get the search radius (13.86 + 7.75)^2 ≈ 467
|
||||
final double searchRadiusSq = 470.0; // Slightly padded for safety
|
||||
|
||||
List<IDynamicLightSource> result = null;
|
||||
|
||||
this.lightSourcesLock.readLock().lock();
|
||||
try {
|
||||
for (IDynamicLightSource source : this.dynamicLightSources) {
|
||||
double dx = source.angelica$getDynamicLightX() - centerX;
|
||||
double dy = source.angelica$getDynamicLightY() - centerY;
|
||||
double dz = source.angelica$getDynamicLightZ() - centerZ;
|
||||
double distSq = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
if (distSq <= searchRadiusSq) {
|
||||
if (result == null) {
|
||||
result = new ArrayList<>();
|
||||
}
|
||||
result.add(source);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.lightSourcesLock.readLock().unlock();
|
||||
}
|
||||
|
||||
return result != null ? result : Collections.emptyList();
|
||||
}
|
||||
|
||||
public double getDynamicLightLevelFromSources(double x, double y, double z, List<IDynamicLightSource> sources) {
|
||||
if (sources == null || sources.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
double result = 0;
|
||||
for (int i = 0, size = sources.size(); i < size; i++) {
|
||||
result = maxDynamicLightLevelExact(x, y, z, sources.get(i), result);
|
||||
}
|
||||
return MathHelper.clamp_double(result, 0, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lightmap with combined light levels.
|
||||
*
|
||||
@@ -275,7 +410,7 @@ public class DynamicLights {
|
||||
* @param renderer the renderer
|
||||
* @param chunkPos the chunk position
|
||||
*/
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, @NotNull IBlockPos chunkPos) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, @NotNull IBlockPos chunkPos) {
|
||||
scheduleChunkRebuild(renderer, chunkPos.getX(), chunkPos.getY(), chunkPos.getZ());
|
||||
}
|
||||
|
||||
@@ -285,14 +420,37 @@ public class DynamicLights {
|
||||
* @param renderer the renderer
|
||||
* @param chunkPos the packed chunk position
|
||||
*/
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, long chunkPos) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, long chunkPos) {
|
||||
scheduleChunkRebuild(renderer, CoordinatePacker.unpackX(chunkPos), CoordinatePacker.unpackY(chunkPos), CoordinatePacker.unpackZ(chunkPos));
|
||||
}
|
||||
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, int x, int y, int z) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, int x, int y, int z) {
|
||||
if (FrustumCullingEnabled && instance != null) {
|
||||
instance.chunkRebuildManager.requestRebuild(x, y, z);
|
||||
} else {
|
||||
renderer.scheduleRebuildForChunk(x, y, z, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleChunkRebuildForRemoval(@NotNull IDynamicLightWorldRenderer renderer, int x, int y, int z) {
|
||||
renderer.scheduleRebuildForChunk(x, y, z, false);
|
||||
}
|
||||
|
||||
public static void scheduleChunkRebuildForRemoval(@NotNull IDynamicLightWorldRenderer renderer, long chunkPos) {
|
||||
scheduleChunkRebuildForRemoval(renderer, CoordinatePacker.unpackX(chunkPos), CoordinatePacker.unpackY(chunkPos), CoordinatePacker.unpackZ(chunkPos));
|
||||
}
|
||||
|
||||
public void processChunkRebuilds(@Nullable Viewport viewport) {
|
||||
if (activeRenderer == null) {
|
||||
return;
|
||||
}
|
||||
chunkRebuildManager.processVisible(viewport, activeRenderer);
|
||||
}
|
||||
|
||||
public ChunkRebuildManager getChunkRebuildManager() {
|
||||
return chunkRebuildManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the tracked chunk sets.
|
||||
*
|
||||
@@ -333,10 +491,7 @@ public class DynamicLights {
|
||||
* @param submergedInWater {@code true} if the stack is submerged in water, else {@code false}
|
||||
* @return the luminance of the item
|
||||
*/
|
||||
public static int getLuminanceFromItemStack(@NotNull ItemStack stack, boolean submergedInWater) {
|
||||
// TODO only have certain items not glow in water?
|
||||
if (submergedInWater) return 0;
|
||||
|
||||
public static int getLuminanceFromItemStack(@NotNull ItemStack stack) {
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof ItemBlock itemBlock) {
|
||||
Block block = itemBlock.field_150939_a;
|
||||
@@ -354,49 +509,53 @@ public class DynamicLights {
|
||||
|
||||
public static int getLuminanceFromEntity(@NotNull Entity entity) {
|
||||
|
||||
if (entity.fire > 0) return 15;
|
||||
if (entity.isBurning()) return 15;
|
||||
|
||||
boolean inWater = entity.isInsideOfMaterial(Material.water);
|
||||
|
||||
// TODO only have certain items not glow in water?
|
||||
if (inWater) return 0;
|
||||
|
||||
if (entity instanceof EntityItem item) {
|
||||
return getLuminanceFromItemStack(item.getEntityItem(), item.isInsideOfMaterial(Material.water));
|
||||
return getLuminanceFromItemStack(item.getEntityItem());
|
||||
}
|
||||
|
||||
int luminance = 0;
|
||||
if (entity instanceof EntityLivingBase living) {
|
||||
int luminance = 0;
|
||||
|
||||
boolean inWater = living.isInsideOfMaterial(Material.water);
|
||||
|
||||
// check equipment + hand for light (should work for all entities)
|
||||
ItemStack itemStack;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if ((itemStack = living.getEquipmentInSlot(i)) != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(itemStack, inWater));
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
if (ModStatus.isBattlegearLoaded &&
|
||||
living instanceof EntityPlayer player &&
|
||||
player instanceof IBattlePlayer battlePlayer &&
|
||||
battlePlayer.battlegear2$isBattlemode()
|
||||
) {
|
||||
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand, inWater));
|
||||
if (living instanceof EntityPlayer player) {
|
||||
if (ModStatus.isBattlegearLoaded &&
|
||||
player instanceof IBattlePlayer battlePlayer &&
|
||||
battlePlayer.battlegear2$isBattlemode()
|
||||
) {
|
||||
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ModStatus.isBackhandLoaded && living instanceof EntityPlayer player){
|
||||
ItemStack offhand = ModStatus.backhandCompat.getOffhandItem(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand, inWater));
|
||||
else if (ModStatus.isBackhandLoaded){
|
||||
ItemStack offhand = ModStatus.backhandCompat.getOffhandItem(player);
|
||||
if (offhand != null) {
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ModStatus.isBaublesLoaded && living instanceof EntityPlayer player){
|
||||
var playerBaubles = PlayerHandler.getPlayerBaubles(player);
|
||||
if (playerBaubles != null){
|
||||
for (int i = 0; i < playerBaubles.getSizeInventory(); i++){
|
||||
var stack = playerBaubles.getStackInSlot(i);
|
||||
if (stack != null){
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(stack, inWater));
|
||||
if (ModStatus.isBaublesLoaded){
|
||||
var playerBaubles = PlayerHandler.getPlayerBaubles(player);
|
||||
if (playerBaubles != null){
|
||||
for (int i = 0; i < playerBaubles.getSizeInventory(); i++){
|
||||
var stack = playerBaubles.getStackInSlot(i);
|
||||
if (stack != null){
|
||||
luminance = Math.max(luminance, getLuminanceFromItemStack(stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -406,7 +565,10 @@ public class DynamicLights {
|
||||
}
|
||||
|
||||
// TODO: Creepers? TNT? Dusts?
|
||||
if (entity instanceof PrimedEntityAccessor primedEntity) {
|
||||
luminance = Math.max(luminance, primedEntity.angelica$getLuminance());
|
||||
}
|
||||
|
||||
return 0;
|
||||
return luminance;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -27,11 +26,13 @@ public interface IDynamicLightSource {
|
||||
double angelica$getDynamicLightZ();
|
||||
|
||||
/**
|
||||
* Returns the dynamic light source world.
|
||||
* Returns the dynamic light source world renderer.
|
||||
*
|
||||
* @return the world instance
|
||||
* @return the world renderer instance
|
||||
*/
|
||||
SodiumWorldRenderer angelica$getDynamicLightWorld();
|
||||
default IDynamicLightWorldRenderer angelica$getDynamicLightWorld() {
|
||||
return DynamicLights.getActiveRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the dynamic light is enabled or not.
|
||||
@@ -72,8 +73,9 @@ public interface IDynamicLightSource {
|
||||
* Executed at each tick.
|
||||
*/
|
||||
void angelica$dynamicLightTick();
|
||||
default void angelica$updateLights() {}
|
||||
|
||||
boolean angelica$updateDynamicLight(@NotNull SodiumWorldRenderer renderer);
|
||||
boolean angelica$updateDynamicLight(@NotNull IDynamicLightWorldRenderer renderer);
|
||||
|
||||
void angelica$scheduleTrackedChunksRebuild(@NotNull SodiumWorldRenderer renderer);
|
||||
void angelica$scheduleTrackedChunksRebuild(@NotNull IDynamicLightWorldRenderer renderer);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
/**
|
||||
* Common interface for world renderers that support dynamic lights chunk rebuilds.
|
||||
* Implemented by CeleritasWorldRenderer.
|
||||
*/
|
||||
public interface IDynamicLightWorldRenderer {
|
||||
/**
|
||||
* Schedules a chunk rebuild for the render section at the given chunk coordinates.
|
||||
*/
|
||||
void scheduleRebuildForChunk(int x, int y, int z, boolean important);
|
||||
|
||||
/**
|
||||
* Returns whether this renderer is currently active (has a world loaded).
|
||||
*/
|
||||
boolean isActive();
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights.config;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.concurrent.cas.CasMap;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightSource;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class EntityLightConfig {
|
||||
private static final Logger LOGGER = LogManager.getLogger("Angelica/DynamicLights");
|
||||
|
||||
private static final Set<String> disabledClassNames = ConcurrentHashMap.newKeySet();
|
||||
private static final CasMap<Class<?>, Boolean> enabledCache = new CasMap<>();
|
||||
|
||||
private static File configFile;
|
||||
private static boolean initialized = false;
|
||||
|
||||
private EntityLightConfig() {}
|
||||
|
||||
public static void init(@NotNull File configDir) {
|
||||
if (initialized) return;
|
||||
|
||||
configFile = new File(configDir, "angelica-dynamiclights-entities.txt");
|
||||
load();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public static boolean isEntityTypeEnabled(@NotNull IDynamicLightSource source) {
|
||||
if (!initialized) return true;
|
||||
return isEntityTypeEnabled(source.getClass());
|
||||
}
|
||||
|
||||
public static boolean isEntityTypeEnabled(@NotNull Class<?> entityClass) {
|
||||
if (!initialized) return true;
|
||||
|
||||
Boolean cached = enabledCache.get(entityClass);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
final boolean enabled = !disabledClassNames.contains(entityClass.getName());
|
||||
Boolean existing = enabledCache.putIfAbsent(entityClass, enabled);
|
||||
return existing != null ? existing : enabled;
|
||||
}
|
||||
|
||||
public static void setEntityTypeEnabled(@NotNull Class<?> entityClass, boolean enabled) {
|
||||
enabledCache.put(entityClass, enabled);
|
||||
|
||||
final String className = entityClass.getName();
|
||||
if (enabled) {
|
||||
disabledClassNames.remove(className);
|
||||
} else {
|
||||
disabledClassNames.add(className);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<EntityTypeEntry> getAllEntityTypes() {
|
||||
List<EntityTypeEntry> entries = new ArrayList<>();
|
||||
Set<String> seenClasses = new HashSet<>();
|
||||
|
||||
Map<String, Class<? extends Entity>> stringToClass = EntityList.stringToClassMapping;
|
||||
|
||||
for (Map.Entry<String, Class<? extends Entity>> entry : stringToClass.entrySet()) {
|
||||
String entityId = entry.getKey();
|
||||
Class<?> entityClass = entry.getValue();
|
||||
String className = entityClass.getName();
|
||||
|
||||
if (seenClasses.contains(className)) continue;
|
||||
seenClasses.add(className);
|
||||
|
||||
String modId = getModIdForEntity(entityClass, entityId);
|
||||
String displayName = getDisplayName(entityId, entityClass);
|
||||
boolean enabled = !disabledClassNames.contains(className);
|
||||
|
||||
entries.add(new EntityTypeEntry(displayName, className, modId, enabled));
|
||||
}
|
||||
|
||||
// Sort by mod ID, then by display name
|
||||
entries.sort((a, b) -> {
|
||||
int modCompare = a.getModId().compareToIgnoreCase(b.getModId());
|
||||
if (modCompare != 0) return modCompare;
|
||||
return a.getDisplayName().compareToIgnoreCase(b.getDisplayName());
|
||||
});
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String getModIdForEntity(Class<?> entityClass, String entityId) {
|
||||
// Check EntityRegistry for mod entity entries
|
||||
if (Entity.class.isAssignableFrom(entityClass)) {
|
||||
EntityRegistry.EntityRegistration registration = EntityRegistry.instance()
|
||||
.lookupModSpawn((Class<? extends Entity>) entityClass, false);
|
||||
if (registration != null && registration.getContainer() != null) {
|
||||
return registration.getContainer().getModId();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it's a vanilla entity (no dot in entity ID)
|
||||
if (!entityId.contains(".")) {
|
||||
return "minecraft";
|
||||
}
|
||||
|
||||
// Extract mod ID from entity ID (format: modid.EntityName)
|
||||
int dotIndex = entityId.indexOf('.');
|
||||
if (dotIndex > 0) {
|
||||
return entityId.substring(0, dotIndex);
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private static String getDisplayName(String entityId, Class<?> entityClass) {
|
||||
// Use the simple class name, removing package
|
||||
String simpleName = entityClass.getSimpleName();
|
||||
if (simpleName.isEmpty()) {
|
||||
// Anonymous class, use entity ID
|
||||
return entityId;
|
||||
}
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
if (configFile == null || !configFile.exists()) return;
|
||||
|
||||
disabledClassNames.clear();
|
||||
enabledCache.clear();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(configFile))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||
|
||||
// Lines are entity class names that are DISABLED
|
||||
disabledClassNames.add(line);
|
||||
}
|
||||
LOGGER.info("Loaded {} disabled entity types from config", disabledClassNames.size());
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to load entity light config: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
if (configFile == null) return;
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(configFile))) {
|
||||
writer.write("# Angelica Dynamic Lights - Disabled Entity Types");
|
||||
writer.newLine();
|
||||
writer.write("# Each line is a fully qualified class name of an entity type that is DISABLED.");
|
||||
writer.newLine();
|
||||
writer.write("# Remove a line to re-enable dynamic lighting for that entity type.");
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
List<String> sorted = new ArrayList<>(disabledClassNames);
|
||||
Collections.sort(sorted);
|
||||
|
||||
for (String className : sorted) {
|
||||
writer.write(className);
|
||||
writer.newLine();
|
||||
}
|
||||
|
||||
LOGGER.info("Saved {} disabled entity types to config", disabledClassNames.size());
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to save entity light config: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights.config;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
|
||||
|
||||
public class EntityLightConfigStorage implements OptionStorage<EntityLightConfigStorage> {
|
||||
|
||||
public static final EntityLightConfigStorage INSTANCE = new EntityLightConfigStorage();
|
||||
|
||||
private EntityLightConfigStorage() {}
|
||||
|
||||
@Override
|
||||
public EntityLightConfigStorage getData() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
EntityLightConfig.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EntityTypeEntry {
|
||||
private final String displayName;
|
||||
private final String className;
|
||||
private final String modId;
|
||||
private boolean enabled;
|
||||
|
||||
public EntityTypeEntry(@NotNull String displayName, @NotNull String className, @NotNull String modId, boolean enabled) {
|
||||
this.displayName = displayName;
|
||||
this.className = className;
|
||||
this.modId = modId;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public String getModId() {
|
||||
return modId;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return displayName + " (" + modId + ") [" + (enabled ? "ON" : "OFF") + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkFogMode;
|
||||
|
||||
public class AngelicaFogService implements FogService {
|
||||
private final float[] fogColorArray = new float[4];
|
||||
|
||||
@Override
|
||||
public float getFogEnd() {
|
||||
return GLStateManager.getFogState().getEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogStart() {
|
||||
return GLStateManager.getFogState().getStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogDensity() {
|
||||
return GLStateManager.getFogState().getDensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFogShapeIndex() {
|
||||
return 0; // 1.7.10 only has one fog shape
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogCutoff() {
|
||||
return getFogEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getFogColor() {
|
||||
final var fogState = GLStateManager.getFogState();
|
||||
final var color = fogState.getFogColor();
|
||||
fogColorArray[0] = (float) color.x;
|
||||
fogColorArray[1] = (float) color.y;
|
||||
fogColorArray[2] = (float) color.z;
|
||||
fogColorArray[3] = fogState.getFogAlpha();
|
||||
return fogColorArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkFogMode getFogMode() {
|
||||
if (!GLStateManager.getFogMode().isEnabled()) {
|
||||
return ChunkFogMode.NONE;
|
||||
}
|
||||
return ChunkFogMode.fromGLMode(GLStateManager.getFogState().getFogMode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.mitchej123.glsm.GLStateManagerService;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class AngelicaGLStateManagerService implements GLStateManagerService {
|
||||
|
||||
private IntBuffer intArrayBuffer = BufferUtils.createIntBuffer(16);
|
||||
|
||||
private IntBuffer getIntArrayBuffer(int size) {
|
||||
if (intArrayBuffer.capacity() < size) {
|
||||
intArrayBuffer = BufferUtils.createIntBuffer(size);
|
||||
}
|
||||
intArrayBuffer.clear();
|
||||
return intArrayBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
// ===================== QUERY OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGetInteger(int pname) {
|
||||
return GLStateManager.glGetInteger(pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String glGetString(int pname) {
|
||||
return GL11.glGetString(pname);
|
||||
}
|
||||
|
||||
// ===================== FRAMEBUFFER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenFramebuffers() {
|
||||
return GL30.glGenFramebuffers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteFramebuffers(int framebuffer) {
|
||||
GL30.glDeleteFramebuffers(framebuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindFramebuffer(int target, int framebuffer) {
|
||||
GL30.glBindFramebuffer(target, framebuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glCheckFramebufferStatus(int target) {
|
||||
return GL30.glCheckFramebufferStatus(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) {
|
||||
GL30.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
||||
}
|
||||
|
||||
// ===================== SHADER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glCreateShader(int type) {
|
||||
return GL20.glCreateShader(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glCompileShader(int shader) {
|
||||
GL20.glCompileShader(shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetShaderi(int shader, int pname) {
|
||||
return GL20.glGetShaderi(shader, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String glGetShaderInfoLog(int shader, int maxLength) {
|
||||
return GL20.glGetShaderInfoLog(shader, maxLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteShader(int shader) {
|
||||
GL20.glDeleteShader(shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glCreateProgram() {
|
||||
return GL20.glCreateProgram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glAttachShader(int program, int shader) {
|
||||
GL20.glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glLinkProgram(int program) {
|
||||
GL20.glLinkProgram(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetProgrami(int program, int pname) {
|
||||
return GL20.glGetProgrami(program, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUseProgram(int program) {
|
||||
GLStateManager.glUseProgram(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteProgram(int program) {
|
||||
GL20.glDeleteProgram(program);
|
||||
}
|
||||
|
||||
// ===================== UNIFORM/ATTRIBUTE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGetUniformLocation(int program, CharSequence name) {
|
||||
return GL20.glGetUniformLocation(program, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniform1i(int location, int value) {
|
||||
GL20.glUniform1i(location, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetAttribLocation(int program, CharSequence name) {
|
||||
return GL20.glGetAttribLocation(program, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindAttribLocation(int program, int index, CharSequence name) {
|
||||
GL20.glBindAttribLocation(program, index, name);
|
||||
}
|
||||
|
||||
// ===================== VAO OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenVertexArrays() {
|
||||
return GL30.glGenVertexArrays();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindVertexArray(int array) {
|
||||
GL30.glBindVertexArray(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteVertexArrays(int array) {
|
||||
GL30.glDeleteVertexArrays(array);
|
||||
}
|
||||
|
||||
// ===================== BUFFER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenBuffers() {
|
||||
return GL15.glGenBuffers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindBuffer(int target, int buffer) {
|
||||
GL15.glBindBuffer(target, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteBuffers(int buffer) {
|
||||
GL15.glDeleteBuffers(buffer);
|
||||
}
|
||||
|
||||
// ===================== TEXTURE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenTextures() {
|
||||
return GL11.glGenTextures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glGenTextures(int[] textures) {
|
||||
IntBuffer buffer = getIntArrayBuffer(textures.length);
|
||||
GL11.glGenTextures(buffer);
|
||||
buffer.get(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteTextures(int texture) {
|
||||
GLStateManager.glDeleteTextures(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteTextures(int[] textures) {
|
||||
IntBuffer buffer = getIntArrayBuffer(textures.length);
|
||||
buffer.put(textures);
|
||||
buffer.flip();
|
||||
GLStateManager.glDeleteTextures(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glActiveTexture(int texture) {
|
||||
GLStateManager.glActiveTexture(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetTexLevelParameteri(int target, int level, int pname) {
|
||||
return GLStateManager.glGetTexLevelParameteri(target, level, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetTexLevelParameter(int target, int level, int pname) {
|
||||
return GLStateManager.glGetTexLevelParameteri(target, level, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
|
||||
GL11.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glPixelStorei(int pname, int param) {
|
||||
GLStateManager.glPixelStorei(pname, param);
|
||||
}
|
||||
|
||||
// ===================== STATE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void enableCullFace() {
|
||||
GLStateManager.enableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableCullFace() {
|
||||
GLStateManager.disableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableBlend() {
|
||||
GLStateManager.enableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableBlend() {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
|
||||
GLStateManager.tryBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDepthTest() {
|
||||
GLStateManager.enableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDepthTest() {
|
||||
GLStateManager.disableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDepthFunc(int func) {
|
||||
GLStateManager.glDepthFunc(func);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDepthMask(boolean flag) {
|
||||
GLStateManager.glDepthMask(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glViewport(int x, int y, int width, int height) {
|
||||
GLStateManager.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
|
||||
GLStateManager.glColorMask(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(float red, float green, float blue, float alpha) {
|
||||
GLStateManager.glClearColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int mask) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
// ===================== MOJANG ADDITIONS =====================
|
||||
|
||||
@Override
|
||||
public void clear(int mask, boolean checkError) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTexture(int texture) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveTexture() {
|
||||
return GLStateManager.getActiveTextureUnit() + GL13.GL_TEXTURE0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveTextureAccessor() {
|
||||
return GLStateManager.getActiveTextureUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBoundTexture(int internalUnit) {
|
||||
return GLStateManager.getBoundTextureForServerState(internalUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveBoundTexture() {
|
||||
return GLStateManager.getBoundTextureForServerState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewportWidth() {
|
||||
return GLStateManager.getViewportState().width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewportHeight() {
|
||||
return GLStateManager.getViewportState().height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDepthStateMask() {
|
||||
return GLStateManager.getDepthState().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlendEnabled() {
|
||||
return GLStateManager.getBlendMode().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoundTexture(int unit, int texture) {
|
||||
int currentUnit = GLStateManager.getActiveTextureUnit();
|
||||
if (currentUnit != unit) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + unit);
|
||||
}
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
if (currentUnit != unit) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + currentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureBinding(int unit) {
|
||||
return GLStateManager.getBoundTextureForServerState(unit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.mitchej123.glsm.RenderSystemService;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class AngelicaRenderSystemService implements RenderSystemService {
|
||||
|
||||
// Shader state (Mojang-specific, tracked here)
|
||||
private final int[] shaderTextures = new int[16];
|
||||
private final float[] shaderColor = {1f, 1f, 1f, 1f};
|
||||
private final float[] shaderFogColor = {0f, 0f, 0f, 1f};
|
||||
private float shaderFogStart = 0f;
|
||||
private float shaderFogEnd = 0f;
|
||||
private int fogShape = 0;
|
||||
private float shaderLineWidth = 1f;
|
||||
private final Matrix4f projectionMatrix = new Matrix4f();
|
||||
private final FloatBuffer projectionMatrixBuffer = BufferUtils.createFloatBuffer(16);
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
// ===================== TEXTURE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void glActiveTexture(int texture) {
|
||||
GLStateManager.glActiveTexture(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTexture(int texture) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
// ===================== STATE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void enableCullFace() {
|
||||
GLStateManager.enableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableCullFace() {
|
||||
GLStateManager.disableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableBlend() {
|
||||
GLStateManager.enableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableBlend() {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultBlendFunc() {
|
||||
GLStateManager.defaultBlendFunc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
|
||||
GLStateManager.tryBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnknownBlendState() {
|
||||
// No-op: Angelica tracks blend state accurately
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDepthTest() {
|
||||
GLStateManager.enableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDepthTest() {
|
||||
GLStateManager.disableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depthFunc(int depthFunc) {
|
||||
GLStateManager.glDepthFunc(depthFunc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depthMask(boolean flag) {
|
||||
GLStateManager.glDepthMask(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glViewport(int x, int y, int width, int height) {
|
||||
GLStateManager.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(float red, float green, float blue, float alpha) {
|
||||
GLStateManager.glClearColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int mask, boolean checkError) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
// ===================== UNIFORM OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void glUniform1i(int location, int value) {
|
||||
GL20.glUniform1i(location, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniformMatrix3(int location, boolean transpose, FloatBuffer value) {
|
||||
GL20.glUniformMatrix3(location, transpose, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniformMatrix4(int location, boolean transpose, FloatBuffer value) {
|
||||
GL20.glUniformMatrix4(location, transpose, value);
|
||||
}
|
||||
|
||||
// ===================== THREAD ASSERTIONS =====================
|
||||
|
||||
@Override
|
||||
public void assertOnRenderThread() {
|
||||
// No-op: 1.7.10 is single-threaded for rendering
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertOnRenderThreadOrInit() {
|
||||
// No-op: 1.7.10 is single-threaded for rendering
|
||||
}
|
||||
|
||||
// ===================== SHADER STATE =====================
|
||||
|
||||
@Override
|
||||
public void setShaderTexture(int shaderTexture, int textureId) {
|
||||
if (shaderTexture >= 0 && shaderTexture < 16) {
|
||||
shaderTextures[shaderTexture] = textureId;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getShaderTexture(int shaderTexture) {
|
||||
return (shaderTexture >= 0 && shaderTexture < 16) ? shaderTextures[shaderTexture] : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderColor(float red, float green, float blue, float alpha) {
|
||||
shaderColor[0] = red;
|
||||
shaderColor[1] = green;
|
||||
shaderColor[2] = blue;
|
||||
shaderColor[3] = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getShaderColor() {
|
||||
return shaderColor.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderLineWidth(float lineWidth) {
|
||||
shaderLineWidth = lineWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderLineWidth() {
|
||||
return shaderLineWidth;
|
||||
}
|
||||
|
||||
// ===================== FOG STATE =====================
|
||||
|
||||
@Override
|
||||
public void setShaderFogColor(float red, float green, float blue, float alpha) {
|
||||
shaderFogColor[0] = red;
|
||||
shaderFogColor[1] = green;
|
||||
shaderFogColor[2] = blue;
|
||||
shaderFogColor[3] = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getShaderFogColor() {
|
||||
return shaderFogColor.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderFogStart(float start) {
|
||||
shaderFogStart = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderFogStart() {
|
||||
return shaderFogStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderFogEnd(float end) {
|
||||
shaderFogEnd = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderFogEnd() {
|
||||
return shaderFogEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFogShape(int shape) {
|
||||
fogShape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFogShape() {
|
||||
return fogShape;
|
||||
}
|
||||
|
||||
// ===================== PROJECTION MATRIX =====================
|
||||
|
||||
@Override
|
||||
public Matrix4f getProjectionMatrix() {
|
||||
return new Matrix4f(projectionMatrix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectionMatrixOrth(Matrix4f m) {
|
||||
projectionMatrix.set(m);
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
projectionMatrix.get(projectionMatrixBuffer);
|
||||
projectionMatrixBuffer.rewind();
|
||||
GLStateManager.glLoadMatrix(projectionMatrixBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectionMatrixOrigin(Matrix4f m) {
|
||||
setProjectionMatrixOrth(m);
|
||||
}
|
||||
}
|
||||
@@ -369,6 +369,8 @@ public class DisplayListManager {
|
||||
// Flush any pending delta, then record pop.
|
||||
flushMatrix();
|
||||
currentRecorder.recordPopMatrix();
|
||||
// Invalidate cached transform
|
||||
matrixGeneration++;
|
||||
}
|
||||
|
||||
public static void recordViewport(int x, int y, int width, int height) {
|
||||
@@ -1024,7 +1026,6 @@ public class DisplayListManager {
|
||||
|
||||
final CompiledDisplayList compiled = displayListCache.get(list);
|
||||
if (compiled != null) {
|
||||
GLStateManager.trySyncProgram();
|
||||
final int prevList = currentRenderingList;
|
||||
currentRenderingList = list;
|
||||
compiled.render();
|
||||
@@ -1043,7 +1044,6 @@ public class DisplayListManager {
|
||||
} else {
|
||||
// Positive IDs - fall back to native GL display lists
|
||||
// This happens for lists allocated but never compiled via glNewList
|
||||
GLStateManager.trySyncProgram();
|
||||
GL11.glCallList(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ public final class GLDebug {
|
||||
GL43.glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_NOTIFICATION, null, false);
|
||||
GL43.glDebugMessageCallback(proc);
|
||||
|
||||
// Enable synchronous debug output so errors are reported immediately with accurate stack traces
|
||||
GL11.glEnable(GL43.GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
|
||||
if ((GL11.glGetInteger(GL30.GL_CONTEXT_FLAGS) & GL43.GL_CONTEXT_FLAG_DEBUG_BIT) == 0) {
|
||||
LOGGER.warn("[GL] Warning: A non-debug context may not produce any debug output.");
|
||||
GL11.glEnable(GL43.GL_DEBUG_OUTPUT);
|
||||
@@ -125,6 +128,9 @@ public final class GLDebug {
|
||||
ARBDebugOutput.glDebugMessageControlARB(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_LOW, null, false);
|
||||
ARBDebugOutput.glDebugMessageControlARB(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_NOTIFICATION, null, false);
|
||||
ARBDebugOutput.glDebugMessageCallbackARB(proc);
|
||||
|
||||
// Enable synchronous debug output so errors are reported immediately with accurate stack traces
|
||||
GL11.glEnable(ARBDebugOutput.GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
return 1;
|
||||
} else if (GLStateManager.capabilities.GL_AMD_debug_output) {
|
||||
LOGGER.info("[GL] Using AMD_debug_output for error logging.");
|
||||
|
||||
@@ -46,8 +46,6 @@ import net.coderbot.iris.gbuffer_overrides.state.StateTracker;
|
||||
import net.coderbot.iris.gl.blending.AlphaTestStorage;
|
||||
import net.coderbot.iris.gl.blending.BlendModeStorage;
|
||||
import net.coderbot.iris.gl.blending.DepthColorStorage;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.samplers.IrisSamplers;
|
||||
import net.coderbot.iris.texture.pbr.PBRTextureManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -68,6 +66,7 @@ import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL14;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GLContext;
|
||||
import org.lwjgl.opengl.KHRDebug;
|
||||
@@ -135,9 +134,9 @@ public class GLStateManager {
|
||||
@Setter @Getter private static boolean runningSplash = true;
|
||||
|
||||
private static volatile boolean splashComplete = false;
|
||||
private static volatile Thread drawableGLHolder = MainThread;
|
||||
// Reference to SharedDrawable so makeCurrent() can distinguish it from DrawableGL
|
||||
@Setter private static volatile Drawable sharedDrawable = null;
|
||||
@Getter @Setter private static Thread drawableGLHolder = MainThread;
|
||||
// Reference to DrawableGL (main display context) - works with both FML and BLS splash
|
||||
@Setter private static Drawable drawableGL = null;
|
||||
|
||||
public static boolean isCachingEnabled() {
|
||||
if (splashComplete) return true;
|
||||
@@ -330,6 +329,7 @@ public class GLStateManager {
|
||||
@Getter protected static final ViewPortStateStack viewportState = new ViewPortStateStack();
|
||||
|
||||
@Getter protected static int activeProgram = 0;
|
||||
@Getter protected static int listBase = 0;
|
||||
|
||||
public static void reset() {
|
||||
runningSplash = true;
|
||||
@@ -352,14 +352,6 @@ public class GLStateManager {
|
||||
projectionMatrix.clear();
|
||||
}
|
||||
|
||||
// Iris Listeners
|
||||
private static Runnable blendFuncListener = null;
|
||||
private static Runnable fogToggleListener = null;
|
||||
private static Runnable fogModeListener = null;
|
||||
private static Runnable fogStartListener = null;
|
||||
private static Runnable fogEndListener = null;
|
||||
private static Runnable fogDensityListener = null;
|
||||
|
||||
/**
|
||||
* Check if a display list exists (has been compiled and stored).
|
||||
* Delegates to DisplayListManager.
|
||||
@@ -430,15 +422,8 @@ public class GLStateManager {
|
||||
|
||||
public static void init() {
|
||||
RenderSystem.initRenderer();
|
||||
IrisSamplers.initRenderer();
|
||||
|
||||
if (Iris.enabled) {
|
||||
StateUpdateNotifiers.blendFuncNotifier = listener -> blendFuncListener = listener;
|
||||
StateUpdateNotifiers.fogToggleNotifier = listener -> fogToggleListener = listener;
|
||||
StateUpdateNotifiers.fogModeNotifier = listener -> fogModeListener = listener;
|
||||
StateUpdateNotifiers.fogStartNotifier = listener -> fogStartListener = listener;
|
||||
StateUpdateNotifiers.fogEndNotifier = listener -> fogEndListener = listener;
|
||||
StateUpdateNotifiers.fogDensityNotifier = listener -> fogDensityListener = listener;
|
||||
}
|
||||
if(BYPASS_CACHE) {
|
||||
LOGGER.info("GLStateManager cache bypassed");
|
||||
}
|
||||
@@ -822,6 +807,7 @@ public class GLStateManager {
|
||||
return switch (pname) {
|
||||
case GL11.GL_ALPHA_TEST_FUNC -> alphaState.getFunction();
|
||||
case GL11.GL_DEPTH_FUNC -> depthState.getFunc();
|
||||
case GL11.GL_LIST_BASE -> listBase;
|
||||
case GL11.GL_LIST_MODE -> DisplayListManager.getListMode();
|
||||
case GL11.GL_MATRIX_MODE -> matrixMode.getMode();
|
||||
case GL11.GL_SHADE_MODEL -> shadeModelState.getValue();
|
||||
@@ -1027,9 +1013,6 @@ public class GLStateManager {
|
||||
if (caching) blendState.setSrcDstRgb(srcFactor, dstFactor);
|
||||
GL11.glBlendFunc(srcFactor, dstFactor);
|
||||
}
|
||||
|
||||
// Iris
|
||||
if (blendFuncListener != null) blendFuncListener.run();
|
||||
}
|
||||
|
||||
public static void glBlendEquation(int mode) {
|
||||
@@ -1071,9 +1054,6 @@ public class GLStateManager {
|
||||
if (caching) blendState.setAll(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
OpenGlHelper.glBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
// Iris
|
||||
if (blendFuncListener != null) blendFuncListener.run();
|
||||
}
|
||||
|
||||
public static void checkCompiling() {
|
||||
@@ -1765,12 +1745,6 @@ public class GLStateManager {
|
||||
glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, j);
|
||||
}
|
||||
|
||||
public static void trySyncProgram() {
|
||||
if (Iris.enabled) {
|
||||
Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::syncProgram);
|
||||
}
|
||||
}
|
||||
|
||||
public static void glBegin(int mode) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
// Record to immediate mode recorder
|
||||
@@ -1780,7 +1754,6 @@ public class GLStateManager {
|
||||
}
|
||||
return; // Don't call actual GL during recording
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glBegin(mode);
|
||||
}
|
||||
|
||||
@@ -1851,7 +1824,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1859,7 +1831,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1867,7 +1838,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1875,7 +1845,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices_count, type, indices_buffer_offset);
|
||||
}
|
||||
|
||||
@@ -1883,7 +1852,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, count, type, indices);
|
||||
}
|
||||
|
||||
@@ -1895,7 +1863,6 @@ public class GLStateManager {
|
||||
return;
|
||||
}
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawBuffer(mode);
|
||||
}
|
||||
|
||||
@@ -1910,7 +1877,6 @@ public class GLStateManager {
|
||||
}
|
||||
return;
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawArrays(mode, first, count);
|
||||
}
|
||||
|
||||
@@ -2151,9 +2117,6 @@ public class GLStateManager {
|
||||
}
|
||||
}
|
||||
fogMode.enable();
|
||||
if (fogToggleListener != null) {
|
||||
fogToggleListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static void disableFog() {
|
||||
@@ -2165,9 +2128,6 @@ public class GLStateManager {
|
||||
}
|
||||
}
|
||||
fogMode.disable();
|
||||
if (fogToggleListener != null) {
|
||||
fogToggleListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static void glFog(int pname, FloatBuffer param) {
|
||||
@@ -2181,7 +2141,7 @@ public class GLStateManager {
|
||||
// TODO: Iris Notifier
|
||||
if (HAS_MULTIPLE_SET.contains(pname)) {
|
||||
GL11.glFog(pname, param);
|
||||
|
||||
|
||||
if (pname == GL11.GL_FOG_COLOR && isCachingEnabled()) {
|
||||
final float red = param.get(0);
|
||||
final float green = param.get(1);
|
||||
@@ -2233,24 +2193,9 @@ public class GLStateManager {
|
||||
// Only update cached state when caching is enabled
|
||||
if (isCachingEnabled()) {
|
||||
switch (pname) {
|
||||
case GL11.GL_FOG_DENSITY -> {
|
||||
fogState.setDensity(param);
|
||||
if (fogDensityListener != null) {
|
||||
fogDensityListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_START -> {
|
||||
fogState.setStart(param);
|
||||
if (fogStartListener != null) {
|
||||
fogStartListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_END -> {
|
||||
fogState.setEnd(param);
|
||||
if (fogEndListener != null) {
|
||||
fogEndListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_DENSITY -> fogState.setDensity(param);
|
||||
case GL11.GL_FOG_START -> fogState.setStart(param);
|
||||
case GL11.GL_FOG_END -> fogState.setEnd(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2267,9 +2212,6 @@ public class GLStateManager {
|
||||
// Only update cached state when caching is enabled
|
||||
if (isCachingEnabled() && pname == GL11.GL_FOG_MODE) {
|
||||
fogState.setFogMode(param);
|
||||
if (fogModeListener != null) {
|
||||
fogModeListener.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2319,31 +2261,31 @@ public class GLStateManager {
|
||||
drawable.makeCurrent();
|
||||
CurrentThread = Thread.currentThread();
|
||||
|
||||
// During splash, track which thread holds DrawableGL for caching
|
||||
if (!splashComplete && sharedDrawable != null) {
|
||||
if (drawable == sharedDrawable) {
|
||||
// Switching to SharedDrawable - disable caching for this thread
|
||||
if (drawableGLHolder == CurrentThread) {
|
||||
drawableGLHolder = null;
|
||||
// Post-splash: single context, always cache
|
||||
if (splashComplete) return;
|
||||
|
||||
if (drawableGL == null) {
|
||||
// Lazy-capture DrawableGL reference (Display.getDrawable()) on first opportunity
|
||||
try {
|
||||
if (drawable == Display.getDrawable()) {
|
||||
drawableGL = drawable;
|
||||
}
|
||||
} else {
|
||||
// Switching to DrawableGL - enable caching for this thread
|
||||
drawableGLHolder = CurrentThread;
|
||||
} catch (Exception e) {
|
||||
// Display not ready - can't identify DrawableGL yet, will retry next call
|
||||
LOGGER.warn("Display not ready in makeCurrent", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the current thread holds DrawableGL (the main display context).
|
||||
* Called by mixins at context switch points during splash.
|
||||
*/
|
||||
public static void setCachingEnabled(boolean enabled) {
|
||||
final Thread current = Thread.currentThread();
|
||||
if (enabled) {
|
||||
drawableGLHolder = current;
|
||||
} else if (drawableGLHolder == current) {
|
||||
if (drawableGL != null && drawable == drawableGL) {
|
||||
// Switching TO DrawableGL - enable caching for this thread
|
||||
drawableGLHolder = CurrentThread;
|
||||
}
|
||||
else if (drawableGLHolder == CurrentThread) {
|
||||
// This thread held DrawableGL but is switching AWAY - disable caching
|
||||
drawableGLHolder = null;
|
||||
}
|
||||
// else: Thread switching to non-DrawableGL, wasn't holder - no change needed
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2353,7 +2295,7 @@ public class GLStateManager {
|
||||
public static void markSplashComplete() {
|
||||
splashComplete = true;
|
||||
drawableGLHolder = null;
|
||||
sharedDrawable = null;
|
||||
drawableGL = null;
|
||||
}
|
||||
|
||||
public static void glNewList(int list, int mode) {
|
||||
@@ -2521,7 +2463,7 @@ public class GLStateManager {
|
||||
// Reset relative transform - subsequent transforms are relative to loaded matrix
|
||||
DisplayListManager.resetRelativeTransform();
|
||||
if (mode == RecordMode.COMPILE) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (isCachingEnabled()) {
|
||||
@@ -3646,24 +3588,28 @@ public class GLStateManager {
|
||||
|
||||
// Display List Commands
|
||||
public static void glCallLists(IntBuffer lists) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glCallLists in display lists not yet implemented - if you see this, please report!");
|
||||
while (lists.hasRemaining()) {
|
||||
final int listId = lists.get() + listBase;
|
||||
glCallList(listId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void glCallLists(ShortBuffer lists) {
|
||||
while (lists.hasRemaining()) {
|
||||
final int listId = (lists.get() & 0xFFFF) + listBase;
|
||||
glCallList(listId);
|
||||
}
|
||||
GL11.glCallLists(lists);
|
||||
}
|
||||
|
||||
public static void glCallLists(ByteBuffer lists) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glCallLists in display lists not yet implemented - if you see this, please report!");
|
||||
while (lists.hasRemaining()) {
|
||||
final int listId = (lists.get() & 0xFF) + listBase;
|
||||
glCallList(listId);
|
||||
}
|
||||
GL11.glCallLists(lists);
|
||||
}
|
||||
|
||||
public static void glListBase(int base) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glListBase in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
GL11.glListBase(base);
|
||||
listBase = base;
|
||||
}
|
||||
|
||||
// Clip Plane Commands
|
||||
@@ -3841,4 +3787,56 @@ public class GLStateManager {
|
||||
return VENDOR == NVIDIA;
|
||||
}
|
||||
|
||||
@Getter protected static int drawFramebuffer = 0;
|
||||
@Getter protected static int readFramebuffer = 0;
|
||||
|
||||
public static void glBindFramebuffer(int target, int framebuffer) {
|
||||
if (target == GL30.GL_FRAMEBUFFER) {
|
||||
if (drawFramebuffer == framebuffer && readFramebuffer == framebuffer) return;
|
||||
drawFramebuffer = framebuffer;
|
||||
readFramebuffer = framebuffer;
|
||||
} else if (target == GL30.GL_DRAW_FRAMEBUFFER) {
|
||||
if (drawFramebuffer == framebuffer) return;
|
||||
drawFramebuffer = framebuffer;
|
||||
} else if (target == GL30.GL_READ_FRAMEBUFFER) {
|
||||
if (readFramebuffer == framebuffer) return;
|
||||
readFramebuffer = framebuffer;
|
||||
}
|
||||
GL30.glBindFramebuffer(target, framebuffer);
|
||||
}
|
||||
|
||||
public static void glDeleteFramebuffers(int framebuffer) {
|
||||
if (drawFramebuffer == framebuffer) drawFramebuffer = 0;
|
||||
if (readFramebuffer == framebuffer) readFramebuffer = 0;
|
||||
GL30.glDeleteFramebuffers(framebuffer);
|
||||
}
|
||||
|
||||
public static int glGenFramebuffers() {
|
||||
return GL30.glGenFramebuffers();
|
||||
}
|
||||
|
||||
public static int glCheckFramebufferStatus(int target) {
|
||||
return GL30.glCheckFramebufferStatus(target);
|
||||
}
|
||||
|
||||
public static void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) {
|
||||
GL30.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
||||
}
|
||||
|
||||
public static void setActiveTexture(int textureUnit) {
|
||||
glActiveTexture(textureUnit);
|
||||
}
|
||||
|
||||
public static void setLightmapTextureCoords(int unit, float x, float y) {
|
||||
GL13.glMultiTexCoord2f(unit, x, y);
|
||||
if (unit == GL13.GL_TEXTURE1) {
|
||||
OpenGlHelper.lastBrightnessX = x;
|
||||
OpenGlHelper.lastBrightnessY = y;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFramebufferEnabled() {
|
||||
return OpenGlHelper.framebufferSupported && Minecraft.getMinecraft().gameSettings.fboEnable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,14 +10,23 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.ARBBufferStorage;
|
||||
import org.lwjgl.opengl.ARBClearBufferObject;
|
||||
import org.lwjgl.opengl.ARBClearTexture;
|
||||
import org.lwjgl.opengl.ARBShaderImageLoadStore;
|
||||
import org.lwjgl.opengl.ARBShaderStorageBufferObject;
|
||||
import org.lwjgl.opengl.EXTShaderImageLoadStore;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL33;
|
||||
import org.lwjgl.opengl.GL40;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
import org.lwjgl.opengl.GL43;
|
||||
import org.lwjgl.opengl.GL44;
|
||||
import org.lwjgl.opengl.NVXGpuMemoryInfo;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
@@ -31,6 +40,16 @@ public class RenderSystem {
|
||||
private static final Logger LOGGER = LogManager.getLogger("RenderSystem");
|
||||
private static DSAAccess dsaState;
|
||||
private static boolean supportsCompute;
|
||||
private static boolean supportsImageLoadStore;
|
||||
private static boolean supportsSSBO;
|
||||
private static boolean supportsBufferStorage;
|
||||
private static boolean supportsClearTexture;
|
||||
private static boolean supportsSamplerObjects;
|
||||
private static int maxImageUnits;
|
||||
private static int maxSSBOBindings;
|
||||
|
||||
// Sampler object state tracking (null if unsupported)
|
||||
private static int[] samplers;
|
||||
|
||||
private RenderSystem() {}
|
||||
|
||||
@@ -54,6 +73,46 @@ public class RenderSystem {
|
||||
}
|
||||
|
||||
supportsCompute = supportsCompute();
|
||||
|
||||
supportsImageLoadStore = GLStateManager.capabilities.OpenGL42 || GLStateManager.capabilities.GL_ARB_shader_image_load_store || GLStateManager.capabilities.GL_EXT_shader_image_load_store;
|
||||
supportsSSBO = GLStateManager.capabilities.OpenGL43 || GLStateManager.capabilities.GL_ARB_shader_storage_buffer_object;
|
||||
supportsBufferStorage = GLStateManager.capabilities.OpenGL44 || GLStateManager.capabilities.GL_ARB_buffer_storage;
|
||||
supportsClearTexture = GLStateManager.capabilities.OpenGL44 || GLStateManager.capabilities.GL_ARB_clear_texture;
|
||||
|
||||
// Cache maximum image units
|
||||
if (supportsImageLoadStore) {
|
||||
if (GLStateManager.capabilities.OpenGL42) {
|
||||
maxImageUnits = GL11.glGetInteger(GL42.GL_MAX_IMAGE_UNITS);
|
||||
} else if (GLStateManager.capabilities.GL_ARB_shader_image_load_store) {
|
||||
maxImageUnits = GL11.glGetInteger(ARBShaderImageLoadStore.GL_MAX_IMAGE_UNITS);
|
||||
} else {
|
||||
maxImageUnits = GL11.glGetInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT);
|
||||
}
|
||||
} else {
|
||||
maxImageUnits = 0;
|
||||
}
|
||||
|
||||
// Cache maximum SSBO bindings
|
||||
if (supportsSSBO) {
|
||||
if (GLStateManager.capabilities.OpenGL43) {
|
||||
maxSSBOBindings = GL11.glGetInteger(GL43.GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS);
|
||||
} else {
|
||||
maxSSBOBindings = GL11.glGetInteger(ARBShaderStorageBufferObject.GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS);
|
||||
}
|
||||
} else {
|
||||
maxSSBOBindings = 0;
|
||||
}
|
||||
|
||||
// Check for sampler objects support (GL 3.3+ or ARB extension)
|
||||
supportsSamplerObjects = GLStateManager.capabilities.OpenGL33
|
||||
|| GLStateManager.capabilities.GL_ARB_sampler_objects;
|
||||
if (supportsSamplerObjects) {
|
||||
samplers = new int[GL11.glGetInteger(GL20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)];
|
||||
}
|
||||
|
||||
LOGGER.info("Image Load/Store: {}, Max Image Units: {}", supportsImageLoadStore, maxImageUnits);
|
||||
LOGGER.info("SSBO: {}, Max SSBO Bindings: {}", supportsSSBO, maxSSBOBindings);
|
||||
LOGGER.info("Buffer Storage: {}, Clear Texture: {}, Sampler Objects: {}", supportsBufferStorage, supportsClearTexture, supportsSamplerObjects);
|
||||
}
|
||||
|
||||
public static void generateMipmaps(int texture, int mipmapTarget) {
|
||||
@@ -65,8 +124,8 @@ public class RenderSystem {
|
||||
}
|
||||
|
||||
public static void texImage2D(int texture, int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable ByteBuffer pixels) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
GLStateManager.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer matrix) {
|
||||
@@ -74,7 +133,7 @@ public class RenderSystem {
|
||||
}
|
||||
|
||||
public static void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) {
|
||||
GL11.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
|
||||
GLStateManager.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
|
||||
}
|
||||
|
||||
public static void uniform1f(int location, float v0) {
|
||||
@@ -147,6 +206,17 @@ public class RenderSystem {
|
||||
dsaState.textureSubImage2D(texture, target, level, xoffset, yoffset, width, height, format, type, pixels);
|
||||
}
|
||||
|
||||
|
||||
public static void texImage1D(int texture, int target, int level, int internalformat, int width, int border, int format, int type, ByteBuffer pixels) {
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL11.glTexImage1D(target, level, internalformat, width, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static void texImage3D(int texture, int target, int level, int internalformat, int width, int height, int depth, int border, int format, int type, ByteBuffer pixels) {
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL12.glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
|
||||
}
|
||||
|
||||
public static String getProgramInfoLog(int program) {
|
||||
return GL20.glGetProgramInfoLog(program, GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH));
|
||||
}
|
||||
@@ -208,13 +278,27 @@ public class RenderSystem {
|
||||
}
|
||||
|
||||
public static int getMaxImageUnits() {
|
||||
if (GLStateManager.capabilities.OpenGL42) {
|
||||
return GL11.glGetInteger(GL42.GL_MAX_IMAGE_UNITS);
|
||||
} else if (GLStateManager.capabilities.GL_EXT_shader_image_load_store) {
|
||||
return GL11.glGetInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return maxImageUnits;
|
||||
}
|
||||
|
||||
public static boolean supportsImageLoadStore() {
|
||||
return supportsImageLoadStore;
|
||||
}
|
||||
|
||||
public static boolean supportsSSBO() {
|
||||
return supportsSSBO;
|
||||
}
|
||||
|
||||
public static boolean supportsBufferStorage() {
|
||||
return supportsBufferStorage;
|
||||
}
|
||||
|
||||
public static boolean supportsClearTexture() {
|
||||
return supportsClearTexture;
|
||||
}
|
||||
|
||||
public static int getMaxSSBOBindings() {
|
||||
return maxSSBOBindings;
|
||||
}
|
||||
|
||||
public static void getProgramiv(int program, int value, IntBuffer storage) {
|
||||
@@ -229,6 +313,14 @@ public class RenderSystem {
|
||||
GL43.glDispatchCompute(workGroups.x, workGroups.y, workGroups.z);
|
||||
}
|
||||
|
||||
public static void dispatchComputeIndirect(long offset) {
|
||||
GL43.glDispatchComputeIndirect(offset);
|
||||
}
|
||||
|
||||
public static void bindBuffer(int target, int buffer) {
|
||||
GL15.glBindBuffer(target, buffer);
|
||||
}
|
||||
|
||||
public static void memoryBarrier(int barriers) {
|
||||
if (supportsCompute) {
|
||||
GL42.glMemoryBarrier(barriers);
|
||||
@@ -255,19 +347,23 @@ public class RenderSystem {
|
||||
dsaState.bindTextureToUnit(unit, texture);
|
||||
}
|
||||
|
||||
public static void bindTextureToUnit(int target, int unit, int texture) {
|
||||
dsaState.bindTextureToUnit(target, unit, texture);
|
||||
}
|
||||
|
||||
public static final FloatBuffer PROJECTION_MATRIX_BUFFER = BufferUtils.createFloatBuffer(16);
|
||||
public static void setupProjectionMatrix(Matrix4f matrix) {
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPushMatrix();
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GLStateManager.glPushMatrix();
|
||||
matrix.get(0, PROJECTION_MATRIX_BUFFER);
|
||||
GL11.glLoadMatrix(PROJECTION_MATRIX_BUFFER);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GLStateManager.glLoadMatrix(PROJECTION_MATRIX_BUFFER);
|
||||
GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
}
|
||||
|
||||
public static void restoreProjectionMatrix() {
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GLStateManager.glPopMatrix();
|
||||
GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
}
|
||||
|
||||
public static void blitFramebuffer(int source, int dest, int offsetX, int offsetY, int width, int height, int offsetX2, int offsetY2, int width2, int height2, int bufferChoice, int filter) {
|
||||
@@ -290,4 +386,100 @@ public class RenderSystem {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int createBuffers() {
|
||||
return GL15.glGenBuffers();
|
||||
}
|
||||
|
||||
public static void bindBufferBase(int target, int index, int buffer) {
|
||||
GL30.glBindBufferBase(target, index, buffer);
|
||||
}
|
||||
|
||||
public static void bufferStorage(int target, long size, int flags) {
|
||||
if (GLStateManager.capabilities.OpenGL44) {
|
||||
GL44.glBufferStorage(target, size, flags);
|
||||
} else if (GLStateManager.capabilities.GL_ARB_buffer_storage) {
|
||||
ARBBufferStorage.glBufferStorage(target, size, flags);
|
||||
} else {
|
||||
// Fallback: use mutable storage
|
||||
GL15.glBufferData(target, size, GL15.GL_DYNAMIC_DRAW);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearBufferSubData(int target, int internalFormat, long offset, long size, int format, int type, int[] data) {
|
||||
if (GLStateManager.capabilities.OpenGL43) {
|
||||
GL43.glClearBufferSubData(target, internalFormat, offset, size, format, type, (ByteBuffer) null);
|
||||
} else if (GLStateManager.capabilities.GL_ARB_clear_buffer_object) {
|
||||
ARBClearBufferObject.glClearBufferSubData(target, internalFormat, offset, size, format, type, (ByteBuffer) null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteBuffers(int buffer) {
|
||||
GL15.glDeleteBuffers(buffer);
|
||||
}
|
||||
|
||||
public static long getVRAM() {
|
||||
if (GLStateManager.capabilities.GL_NVX_gpu_memory_info) {
|
||||
return GL11.glGetInteger(NVXGpuMemoryInfo.GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX) * 1024L;
|
||||
} else {
|
||||
// Default to 4GB if we can't query VRAM
|
||||
return 4294967296L;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearTexImage(int texture, int target, int level, int format, int type) {
|
||||
if (GLStateManager.capabilities.OpenGL44) {
|
||||
GL44.glClearTexImage(texture, level, format, type, (ByteBuffer) null);
|
||||
} else {
|
||||
ARBClearTexture.glClearTexImage(texture, level, format, type, (ByteBuffer) null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void textureStorage1D(int texture, int target, int levels, int internalFormat, int width) {
|
||||
dsaState.textureStorage1D(texture, target, levels, internalFormat, width);
|
||||
}
|
||||
|
||||
public static void textureStorage2D(int texture, int target, int levels, int internalFormat, int width, int height) {
|
||||
dsaState.textureStorage2D(texture, target, levels, internalFormat, width, height);
|
||||
}
|
||||
|
||||
public static void textureStorage3D(int texture, int target, int levels, int internalFormat, int width, int height, int depth) {
|
||||
dsaState.textureStorage3D(texture, target, levels, internalFormat, width, height, depth);
|
||||
}
|
||||
|
||||
public static boolean supportsSamplerObjects() {
|
||||
return supportsSamplerObjects;
|
||||
}
|
||||
|
||||
public static int genSampler() {
|
||||
if (!supportsSamplerObjects) return 0;
|
||||
return GL33.glGenSamplers();
|
||||
}
|
||||
|
||||
public static void destroySampler(int sampler) {
|
||||
if (!supportsSamplerObjects || sampler == 0) return;
|
||||
GL33.glDeleteSamplers(sampler);
|
||||
}
|
||||
|
||||
public static void samplerParameteri(int sampler, int pname, int param) {
|
||||
if (!supportsSamplerObjects || sampler == 0) return;
|
||||
GL33.glSamplerParameteri(sampler, pname, param);
|
||||
}
|
||||
|
||||
public static void bindSamplerToUnit(int unit, int sampler) {
|
||||
if (!supportsSamplerObjects) return;
|
||||
if (samplers[unit] == sampler) return;
|
||||
GL33.glBindSampler(unit, sampler);
|
||||
samplers[unit] = sampler;
|
||||
}
|
||||
|
||||
public static void unbindAllSamplers() {
|
||||
if (!supportsSamplerObjects) return;
|
||||
for (int i = 0; i < samplers.length; i++) {
|
||||
if (samplers[i] != 0) {
|
||||
GL33.glBindSampler(i, 0);
|
||||
samplers[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.gtnewhorizons.angelica.glsm.compat;
|
||||
|
||||
/**
|
||||
* Simple holder for fog color values captured from vanilla rendering.
|
||||
* Used by terrain renderers to access fog state.
|
||||
*/
|
||||
public class FogHelper {
|
||||
public static float red;
|
||||
public static float green;
|
||||
public static float blue;
|
||||
}
|
||||
@@ -94,6 +94,11 @@ public class DSAARB extends DSAUnsupported {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTextureToUnit(int target, int unit, int texture) {
|
||||
bindTextureToUnit(unit, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bufferStorage(int target, FloatBuffer data, int usage) {
|
||||
final int buffer = GL45.glCreateBuffers();
|
||||
@@ -121,4 +126,19 @@ public class DSAARB extends DSAUnsupported {
|
||||
public int createTexture(int target) {
|
||||
return ARBDirectStateAccess.glCreateTextures(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage1D(int texture, int target, int levels, int internalFormat, int width) {
|
||||
ARBDirectStateAccess.glTextureStorage1D(texture, levels, internalFormat, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage2D(int texture, int target, int levels, int internalFormat, int width, int height) {
|
||||
ARBDirectStateAccess.glTextureStorage2D(texture, levels, internalFormat, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage3D(int texture, int target, int levels, int internalFormat, int width, int height, int depth) {
|
||||
ARBDirectStateAccess.glTextureStorage3D(texture, levels, internalFormat, width, height, depth);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public interface DSAAccess {
|
||||
void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height);
|
||||
|
||||
void bindTextureToUnit(int unit, int texture);
|
||||
void bindTextureToUnit(int target, int unit, int texture);
|
||||
|
||||
int bufferStorage(int target, FloatBuffer data, int usage);
|
||||
|
||||
@@ -37,4 +38,9 @@ public interface DSAAccess {
|
||||
|
||||
int createFramebuffer();
|
||||
int createTexture(int target);
|
||||
|
||||
// Texture storage methods for custom images
|
||||
void textureStorage1D(int texture, int target, int levels, int internalFormat, int width);
|
||||
void textureStorage2D(int texture, int target, int levels, int internalFormat, int width, int height);
|
||||
void textureStorage3D(int texture, int target, int levels, int internalFormat, int width, int height, int depth);
|
||||
}
|
||||
@@ -2,12 +2,14 @@ package com.gtnewhorizons.angelica.glsm.dsa;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL31;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
@@ -74,13 +76,13 @@ public class DSAUnsupported implements DSAAccess {
|
||||
|
||||
@Override
|
||||
public void readBuffer(int framebuffer, int buffer) {
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
GL11.glReadBuffer(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBuffers(int framebuffer, IntBuffer buffers) {
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
GL20.glDrawBuffers(buffers);
|
||||
}
|
||||
|
||||
@@ -113,6 +115,12 @@ public class DSAUnsupported implements DSAAccess {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTextureToUnit(int target, int unit, int texture) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + unit);
|
||||
GLStateManager.glBindTexture(target, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bufferStorage(int target, FloatBuffer data, int usage) {
|
||||
final int buffer = GL15.glGenBuffers();
|
||||
@@ -126,21 +134,21 @@ public class DSAUnsupported implements DSAAccess {
|
||||
@Override
|
||||
public void blitFramebuffer(int source, int dest, int offsetX, int offsetY, int width, int height, int offsetX2, int offsetY2, int width2, int height2,
|
||||
int bufferChoice, int filter) {
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_READ_FRAMEBUFFER, source);
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_DRAW_FRAMEBUFFER, dest);
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, source);
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dest);
|
||||
GL30.glBlitFramebuffer(offsetX, offsetY, width, height, offsetX2, offsetY2, width2, height2, bufferChoice, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void framebufferTexture2D(int fb, int fbtarget, int attachment, int target, int texture, int levels) {
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(fbtarget, fb);
|
||||
GLStateManager.glBindFramebuffer(fbtarget, fb);
|
||||
GL30.glFramebufferTexture2D(fbtarget, attachment, target, texture, levels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createFramebuffer() {
|
||||
final int framebuffer = OpenGlHelper.func_153165_e/*glGenFramebuffers*/();
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
final int framebuffer = GLStateManager.glGenFramebuffers();
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
@@ -150,4 +158,28 @@ public class DSAUnsupported implements DSAAccess {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage1D(int texture, int target, int levels, int internalFormat, int width) {
|
||||
final int previous = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_1D);
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL42.glTexStorage1D(target, levels, internalFormat, width);
|
||||
GL11.glBindTexture(target, previous);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage2D(int texture, int target, int levels, int internalFormat, int width, int height) {
|
||||
final int previous = (target == GL11.GL_TEXTURE_2D) ? GLStateManager.getBoundTextureForServerState() : GL11.glGetInteger(GL31.GL_TEXTURE_BINDING_RECTANGLE);
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL42.glTexStorage2D(target, levels, internalFormat, width, height);
|
||||
GL11.glBindTexture(target, previous);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void textureStorage3D(int texture, int target, int levels, int internalFormat, int width, int height, int depth) {
|
||||
final int previous = GL11.glGetInteger(GL12.GL_TEXTURE_BINDING_3D);
|
||||
GL11.glBindTexture(target, texture);
|
||||
GL42.glTexStorage3D(target, levels, internalFormat, width, height, depth);
|
||||
GL11.glBindTexture(target, previous);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.glsm.recording;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.commands.DrawCommand;
|
||||
import me.jellysquid.mods.sodium.client.gl.attribute.BufferVertexFormat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents recorded geometry from a display list compilation.
|
||||
* Contains the vertex data buffer and metadata about draw commands.
|
||||
*/
|
||||
@Desugar
|
||||
public record RecordedGeometry(ByteBuffer buffer, BufferVertexFormat format, List<DrawCommand> drawCommands, int totalVertexCount) {
|
||||
public int getByteSize() {
|
||||
return buffer.remaining();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -17,12 +16,6 @@ public class TextureTracker {
|
||||
|
||||
public static final TextureTracker INSTANCE = new TextureTracker();
|
||||
|
||||
private static Runnable bindTextureListener;
|
||||
|
||||
static {
|
||||
StateUpdateNotifiers.bindTextureNotifier = listener -> bindTextureListener = listener;
|
||||
}
|
||||
|
||||
private final Int2ObjectMap<AbstractTexture> textures = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private boolean lockBindCallback;
|
||||
@@ -45,9 +38,6 @@ public class TextureTracker {
|
||||
}
|
||||
if (GLStateManager.getActiveTextureUnit() == 0) {
|
||||
lockBindCallback = true;
|
||||
if (bindTextureListener != null) {
|
||||
bindTextureListener.run();
|
||||
}
|
||||
if(Iris.enabled) {
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline != null) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiIngame;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraftforge.client.GuiIngameForge;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -68,7 +67,7 @@ public class HUDCaching {
|
||||
XaeroMinimapCore.beforeIngameGuiRender(partialTicks);
|
||||
}
|
||||
|
||||
if (!OpenGlHelper.isFramebufferEnabled()) {
|
||||
if (!GLStateManager.isFramebufferEnabled()) {
|
||||
ingame.renderGameOverlay(partialTicks, hasScreen, mouseX, mouseY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import jss.notfine.asm.AsmTransformers;
|
||||
import jss.notfine.asm.mappings.Namer;
|
||||
import jss.notfine.config.MCPatcherForgeConfig;
|
||||
import jss.notfine.config.NotFineConfig;
|
||||
import com.gtnewhorizons.retrofuturabootstrap.SharedConfig;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -45,7 +46,8 @@ import java.util.Set;
|
||||
@IFMLLoadingPlugin.TransformerExclusions({
|
||||
"jss.notfine.asm",
|
||||
"com.gtnewhorizons.angelica.loading",
|
||||
"com.gtnewhorizons.angelica.glsm.GLStateManager"})
|
||||
"com.gtnewhorizons.angelica.glsm.GLStateManager"
|
||||
})
|
||||
public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
|
||||
private static Boolean OBF_ENV;
|
||||
@@ -54,6 +56,10 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
private String[] transformerClasses;
|
||||
|
||||
public AngelicaTweaker() {
|
||||
if (Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE) {
|
||||
addLwjgl3ifyExclusions();
|
||||
}
|
||||
|
||||
try {
|
||||
// Angelica Config
|
||||
ConfigurationManager.registerConfig(AngelicaConfig.class);
|
||||
@@ -78,8 +84,19 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
}
|
||||
|
||||
private static void verifyDependencies() {
|
||||
// Check for fastutil (bundled with GTNHLib since 0.2.1)
|
||||
if (AngelicaTweaker.class.getResource("/it/unimi/dsi/fastutil/ints/Int2ObjectMap.class") == null) {
|
||||
throw new RuntimeException("Missing dependency: Angelica requires GTNHLib 0.2.1 or newer! Download: https://modrinth.com/mod/gtnhlib");
|
||||
throw new RuntimeException("Missing dependency: Angelica requires GTNHLib! Download: https://modrinth.com/mod/gtnhlib");
|
||||
}
|
||||
|
||||
// Check for PrimitiveExtractor/cel.model classes (added in GTNHLib 0.8.21)
|
||||
if (AngelicaTweaker.class.getResource("/com/gtnewhorizon/gtnhlib/client/renderer/PrimitiveExtractor.class") == null) {
|
||||
throw new RuntimeException("GTNHLib is outdated: Angelica requires GTNHLib 0.8.21 or newer! Download: https://modrinth.com/mod/gtnhlib");
|
||||
}
|
||||
|
||||
// Check for jvmdowngrader stubs (bundled with GTNHLib since 0.9.0)
|
||||
if (AngelicaTweaker.class.getResource("/xyz/wagyourtail/jvmdg/exc/MissingStubError.class") == null) {
|
||||
throw new RuntimeException("GTNHLib is outdated: Angelica requires GTNHLib 0.9.0 or newer! Download: https://modrinth.com/mod/gtnhlib");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +142,6 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
boolean rfbLoaded = Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE;
|
||||
if (!rfbLoaded) {
|
||||
tweaks.add("com.gtnewhorizons.angelica.loading.fml.tweakers.AngelicaLateTweaker");
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
tweaks.add("com.gtnewhorizons.angelica.loading.fml.tweakers.SodiumLateTweaker");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,6 +154,9 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
|
||||
@Override
|
||||
public String getMixinConfig() {
|
||||
int v = Runtime.version().feature();
|
||||
if (v >= 21) return "mixins.angelica.early.j21.json";
|
||||
if (v >= 17) return "mixins.angelica.early.j17.json";
|
||||
return "mixins.angelica.early.json";
|
||||
}
|
||||
|
||||
@@ -153,6 +170,19 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
return IMixins.getEarlyMixins(Mixins.class, loadedCoreMods);
|
||||
}
|
||||
|
||||
private static void addLwjgl3ifyExclusions() {
|
||||
var handle = SharedConfig.getRfbTransformers().stream()
|
||||
.filter(transformer -> transformer.id().equals("lwjgl3ify:redirect"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (handle != null) {
|
||||
handle.exclusions().add("org.embeddedt.embeddium");
|
||||
handle.exclusions().add("org.taumc.celeritas");
|
||||
handle.exclusions().add("com.mitchej123.lwjgl.lwjgl3");
|
||||
handle.exclusions().add("com.mitchej123.glsm");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we are in an obfuscated environment, returns false in dev environment.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class SodiumBlockTransformer implements IClassTransformer {
|
||||
public SodiumBlockTransformer() {
|
||||
this.inner = new SodiumBlockTransform(AngelicaTweaker.isObfEnv());
|
||||
this.exclusions = inner.getTransformerExclusions();
|
||||
this.inner.setSodiumSetting();
|
||||
this.inner.setCeleritasSetting();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.loading.fml.tweakers;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class SodiumLateTweaker implements ITweaker {
|
||||
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getLaunchArguments() {
|
||||
String transformer = "com.gtnewhorizons.angelica.loading.fml.transformers.SodiumBlockTransformer";
|
||||
FMLRelaunchLog.finer("Registering transformer %s", transformer);
|
||||
Launch.classLoader.registerTransformer(transformer);
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -233,7 +233,15 @@ public final class AngelicaRedirector {
|
||||
);
|
||||
methodRedirects.put(OpenGlHelper, RedirectMap.newMap()
|
||||
.add("glBlendFunc", "tryBlendFuncSeparate")
|
||||
.add("func_148821_a", "tryBlendFuncSeparate"));
|
||||
.add("func_148821_a", "tryBlendFuncSeparate")
|
||||
.add("func_153171_g", "glBindFramebuffer")
|
||||
.add("func_153174_h", "glDeleteFramebuffers")
|
||||
.add("func_153165_e", "glGenFramebuffers")
|
||||
.add("func_153167_i", "glCheckFramebufferStatus")
|
||||
.add("func_153188_a", "glFramebufferTexture2D")
|
||||
.add("setActiveTexture")
|
||||
.add("setLightmapTextureCoords")
|
||||
.add("isFramebufferEnabled"));
|
||||
methodRedirects.put(EXTBlendFunc, RedirectMap.newMap().add("glBlendFuncSeparateEXT", "tryBlendFuncSeparate"));
|
||||
methodRedirects.put(ARBMultiTexture, RedirectMap.newMap().add("glActiveTextureARB"));
|
||||
methodRedirects.put(Project, RedirectMap.newMap().add("gluPerspective"));
|
||||
|
||||
+10
-10
@@ -58,22 +58,22 @@ public class SodiumBlockTransform {
|
||||
// Block owners we *shouldn't* redirect because they shadow one of our fields
|
||||
private static final Set<String> blockOwnerExclusions = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
// Needed because the config is loaded in LaunchClassLoader, but we need to access it in the parent system loader.
|
||||
private static final MethodHandle angelicaConfigSodiumEnabledGetter;
|
||||
private static boolean isSodiumEnabled;
|
||||
private static final MethodHandle angelicaConfigCeleritasEnabledGetter;
|
||||
private static boolean isCeleritasEnabled;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Class<?> angelicaConfig = Class.forName("com.gtnewhorizons.angelica.config.AngelicaConfig", true, Launch.classLoader);
|
||||
angelicaConfigSodiumEnabledGetter = MethodHandles.lookup().findStaticGetter(angelicaConfig, "enableSodium", boolean.class);
|
||||
angelicaConfigCeleritasEnabledGetter = MethodHandles.lookup().findStaticGetter(angelicaConfig, "enableCeleritas", boolean.class);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSodiumEnabled() {
|
||||
if (isSodiumEnabled) return true;
|
||||
private static boolean isCeleritasEnabled() {
|
||||
if (isCeleritasEnabled) return true;
|
||||
try {
|
||||
return (boolean) angelicaConfigSodiumEnabledGetter.invokeExact();
|
||||
return (boolean) angelicaConfigCeleritasEnabledGetter.invokeExact();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class SodiumBlockTransform {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("net.minecraft.block.Block".equals(transformedName) && isSodiumEnabled()) {
|
||||
if ("net.minecraft.block.Block".equals(transformedName) && isCeleritasEnabled()) {
|
||||
cn.fields.removeIf(field -> BlockBoundsFields.stream().anyMatch(pair -> field.name.equals(pair.getLeft()) || field.name.equals(pair.getRight())));
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class SodiumBlockTransform {
|
||||
for (MethodNode mn : cn.methods) {
|
||||
for (AbstractInsnNode node : mn.instructions.toArray()) {
|
||||
if ((node.getOpcode() == Opcodes.GETFIELD || node.getOpcode() == Opcodes.PUTFIELD) && node instanceof FieldInsnNode fNode) {
|
||||
if (!blockOwnerExclusions.contains(fNode.owner) && isBlockSubclass(fNode.owner) && isSodiumEnabled()) {
|
||||
if (!blockOwnerExclusions.contains(fNode.owner) && isBlockSubclass(fNode.owner) && isCeleritasEnabled()) {
|
||||
Pair<String, String> fieldToRedirect = BlockBoundsFields.stream()
|
||||
.filter(pair -> fNode.name.equals(getFieldName(pair)))
|
||||
.findFirst()
|
||||
@@ -206,7 +206,7 @@ public class SodiumBlockTransform {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void setSodiumSetting() {
|
||||
isSodiumEnabled = true;
|
||||
public void setCeleritasSetting() {
|
||||
isCeleritasEnabled = true;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public enum Mixins implements IMixins {
|
||||
, "angelica.MixinFMLClientHandler"
|
||||
, "angelica.bugfixes.MixinRenderGlobal_DestroyBlock"
|
||||
, "angelica.glsm.MixinSplashProgressCaching"
|
||||
, "angelica.debug.MixinMinecraft_FPSCap"
|
||||
)
|
||||
),
|
||||
|
||||
@@ -73,6 +74,8 @@ public enum Mixins implements IMixins {
|
||||
, "angelica.dynamiclights.MixinEntity"
|
||||
, "angelica.dynamiclights.MixinWorld"
|
||||
, "angelica.dynamiclights.MixinItemRenderer"
|
||||
, "angelica.dynamiclights.MixinEntityCreeper"
|
||||
, "angelica.dynamiclights.MixinEntityTNTPrimed"
|
||||
)
|
||||
),
|
||||
|
||||
@@ -138,36 +141,53 @@ public enum Mixins implements IMixins {
|
||||
)
|
||||
),
|
||||
|
||||
SODIUM(new MixinBuilder()
|
||||
RENDERING_INFRASTRUCTURE(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"sodium.MixinBlock"
|
||||
, "sodium.MixinBlockFluidBase"
|
||||
, "sodium.AccessorBiomeColorEvent"
|
||||
, "sodium.MixinBiomeGenBase"
|
||||
, "sodium.MixinChunk"
|
||||
, "sodium.MixinChunkProviderServer"
|
||||
, "sodium.MixinClientRegistry"
|
||||
, "sodium.MixinEntity_RenderDist"
|
||||
, "sodium.MixinEntityItem_RenderDist"
|
||||
, "sodium.MixinRenderManager"
|
||||
, "sodium.MixinEntityRenderer"
|
||||
, "sodium.MixinFMLClientHandler"
|
||||
, "sodium.MixinForgeHooksClient"
|
||||
, "sodium.MixinGameSettings"
|
||||
, "sodium.MixinFrustrum"
|
||||
, "sodium.MixinMinecraft"
|
||||
, "sodium.MixinRenderBlocks"
|
||||
, "sodium.MixinRenderGlobal"
|
||||
, "sodium.MixinWorldClient"
|
||||
, "sodium.MixinTileEntity"
|
||||
, "sodium.MixinTileEntityMobSpawner"
|
||||
, "sodium.MixinEffectRenderer"
|
||||
, "sodium.MixinTileEntityRendererDispatcher"
|
||||
, "sodium.MixinLongHashMap"
|
||||
, "sodium.MixinRenderingRegistry"
|
||||
, "sodium.MixinPlayerManager"
|
||||
"rendering.MixinBlock"
|
||||
, "rendering.MixinBlockFluidBase"
|
||||
, "rendering.AccessorBiomeColorEvent"
|
||||
, "rendering.MixinBiomeGenBase"
|
||||
, "rendering.MixinChunk"
|
||||
, "rendering.MixinChunkProviderServer"
|
||||
, "rendering.MixinClientRegistry"
|
||||
, "rendering.MixinEntity_RenderDist"
|
||||
, "rendering.MixinEntityItem_RenderDist"
|
||||
, "rendering.MixinEntityRenderer"
|
||||
, "rendering.MixinFMLClientHandler"
|
||||
, "rendering.MixinGameSettings"
|
||||
, "rendering.MixinLongHashMap"
|
||||
, "rendering.MixinMinecraft"
|
||||
, "rendering.MixinPlayerManager"
|
||||
, "rendering.MixinRenderBlocks"
|
||||
, "rendering.MixinRenderingRegistry"
|
||||
, "rendering.MixinTileEntity"
|
||||
, "rendering.MixinTileEntityMobSpawner"
|
||||
, "rendering.MixinTileEntityRendererDispatcher"
|
||||
)
|
||||
),
|
||||
|
||||
CELERITAS(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"celeritas.terrain.ChunkTrackerAccessor"
|
||||
, "celeritas.terrain.MixinChunkProviderClient"
|
||||
, "celeritas.terrain.MixinMinecraft_ChunkUpdates"
|
||||
, "celeritas.terrain.MixinRenderGlobal"
|
||||
, "celeritas.terrain.MixinRenderSectionManager"
|
||||
, "celeritas.terrain.MixinWorldClient"
|
||||
, "celeritas.frustum.MixinFrustrum"
|
||||
, "celeritas.features.culling.MixinEffectRenderer"
|
||||
, "celeritas.features.mipmaps.MixinTextureAtlasSprite"
|
||||
, "celeritas.features.mipmaps.MixinTextureUtil"
|
||||
, "celeritas.features.textures.MixinTextureMap"
|
||||
, "celeritas.features.textures.MixinTextureAtlasSprite"
|
||||
, "celeritas.biome_blending.MixinBlockGrass"
|
||||
, "celeritas.biome_blending.MixinBlockLeaves"
|
||||
, "celeritas.biome_blending.MixinBlockLiquid"
|
||||
, "celeritas.threading.MixinForgeHooksClient"
|
||||
)
|
||||
),
|
||||
|
||||
@@ -180,10 +200,14 @@ public enum Mixins implements IMixins {
|
||||
, "shaders.MixinFramebuffer"
|
||||
, "shaders.MixinItem"
|
||||
, "shaders.MixinLocale"
|
||||
, "shaders.MixinOpenGlHelper"
|
||||
, "shaders.MixinRender"
|
||||
, "shaders.MixinRenderBiped"
|
||||
, "shaders.MixinRenderEntityFlame"
|
||||
, "shaders.MixinRendererLivingEntity"
|
||||
, "shaders.MixinRenderGlobal"
|
||||
, "shaders.MixinRenderHorse"
|
||||
, "shaders.MixinRenderItem"
|
||||
, "shaders.MixinRenderPlayerArmor"
|
||||
, "shaders.MixinTileEntityBeaconRenderer"
|
||||
)
|
||||
),
|
||||
@@ -208,7 +232,7 @@ public enum Mixins implements IMixins {
|
||||
|
||||
ANGELICA_TEXTURE(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris || AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris || AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"angelica.textures.MixinTextureAtlasSprite"
|
||||
, "angelica.textures.MixinTextureUtil"
|
||||
@@ -249,13 +273,8 @@ public enum Mixins implements IMixins {
|
||||
.addClientMixins(
|
||||
"angelica.animation.MixinTextureAtlasSprite",
|
||||
"angelica.animation.MixinTextureMap",
|
||||
"angelica.animation.MixinBlockFire",
|
||||
"angelica.animation.MixinMinecraftForgeClient",
|
||||
"angelica.animation.MixinChunkCache",
|
||||
"angelica.animation.MixinRenderBlocks",
|
||||
"angelica.animation.MixinRenderBlockFluid",
|
||||
"angelica.animation.MixinWorldRenderer",
|
||||
"angelica.animation.MixinRenderItem")),
|
||||
"angelica.animation.MixinRenderBlocks")),
|
||||
|
||||
SCALED_RESOUTION_UNICODE_FIX(new MixinBuilder("Removes unicode languages gui scaling being forced to even values")
|
||||
.setPhase(Phase.EARLY)
|
||||
@@ -295,7 +314,7 @@ public enum Mixins implements IMixins {
|
||||
.setPhase(Phase.LATE)
|
||||
.addRequiredMod(TargetedMod.NTM_SPACE)
|
||||
.setApplyIf(() -> CompatConfig.fixNTMSpace && AngelicaConfig.enableIris)
|
||||
.addClientMixins("client.ntmSpace.MixinSkyProviderCelestial_ShaderCompat")),
|
||||
.addClientMixins("client.ntmSpace.MixinSkyProviderCelestial_ShaderCompat", "client.ntmSpace.MixinSkyProviderLaytheSunset")),
|
||||
|
||||
SPEEDUP_CAMPFIRE_BACKPORT_ANIMATIONS(new MixinBuilder("Add animation speedup support to Campfire Backport")
|
||||
.setPhase(Phase.LATE)
|
||||
@@ -451,12 +470,12 @@ public enum Mixins implements IMixins {
|
||||
),
|
||||
MCPATCHER_FORGE_RENDERPASS_DISPLAYLIST(new MixinBuilder("RenderPass display list allocation increase")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins("mcpatcherforge.renderpass.MixinRenderGlobal_DisplayLists")
|
||||
),
|
||||
MCPATCHER_FORGE_RENDERPASS_FEATURES(new MixinBuilder("RenderPass rendering features")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins("mcpatcherforge.renderpass.MixinRenderGlobal_Features")
|
||||
),
|
||||
MCPATCHER_FORGE_CUSTOM_COLORS(new MixinBuilder()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
|
||||
public interface ChunkTrackerAccessor {
|
||||
Long2IntOpenHashMap angelica$getChunkStatus();
|
||||
LongOpenHashSet angelica$getChunkReady();
|
||||
LongSet angelica$getUnloadQueue();
|
||||
LongSet angelica$getLoadQueue();
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public interface EntityRendererAccessor {
|
||||
float invokeGetNightVisionBrightness(EntityPlayer entityPlayer, float partialTicks);
|
||||
|
||||
/**
|
||||
* Get the lightmap texture for shader binding.
|
||||
*/
|
||||
DynamicTexture getLightmapTexture();
|
||||
}
|
||||
+1
-4
@@ -1,12 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IPatchedTextureAtlasSprite {
|
||||
|
||||
void markNeedsAnimationUpdate();
|
||||
|
||||
boolean needsAnimationUpdate();
|
||||
|
||||
void unmarkNeedsAnimationUpdate();
|
||||
|
||||
void updateAnimationsDryRun();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
public interface IRenderGlobalExt {
|
||||
void scheduleTerrainUpdate();
|
||||
void reload();
|
||||
|
||||
void angelica$scheduleTerrainUpdate();
|
||||
void angelica$reload();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
public interface PrimedEntityAccessor {
|
||||
int angelica$getLuminance();
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
public interface RenderSectionManagerAccessor {
|
||||
Long2ReferenceMap<RenderSection> angelica$getSectionByPosition();
|
||||
ConcurrentLinkedDeque<Runnable> angelica$getAsyncSubmittedTasks();
|
||||
}
|
||||
@@ -14,14 +14,23 @@ import com.gtnewhorizons.angelica.debug.F3Direction;
|
||||
import com.gtnewhorizons.angelica.debug.FrametimeGraph;
|
||||
import com.gtnewhorizons.angelica.debug.TPSGraph;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.config.EntityLightConfig;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.debug.OpenGLDebugging;
|
||||
import com.gtnewhorizons.angelica.hudcaching.HUDCaching;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.IGameSettingsExt;
|
||||
import com.gtnewhorizons.angelica.render.CloudRenderer;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasDebugScreenHandler;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasSetup;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.DefaultChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ThreadedChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.zoom.Zoom;
|
||||
import com.gtnewhorizons.angelica.commands.AngelicaCommand;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
@@ -35,7 +44,6 @@ import java.lang.management.ManagementFactory;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import jss.notfine.core.Settings;
|
||||
import me.jellysquid.mods.sodium.client.SodiumDebugScreenHandler;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.client.IrisDebugScreenHandler;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -84,7 +92,11 @@ public class ClientProxy extends CommonProxy {
|
||||
LOGGER.info("World loaded - Enabling GLSM Cache");
|
||||
}
|
||||
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
if (AngelicaConfig.enableCeleritas) {
|
||||
ChunkTaskRegistry.reset();
|
||||
ChunkTaskRegistry.registerProvider(DefaultChunkTaskProvider.INSTANCE);
|
||||
ChunkTaskRegistry.registerProvider(ThreadedChunkTaskProvider.INSTANCE);
|
||||
|
||||
// Register all blocks. Because blockids are unique to a world, this must be done each load
|
||||
GameData.getBlockRegistry().typeSafeIterable().forEach(o -> {
|
||||
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, true, true);
|
||||
@@ -102,8 +114,11 @@ public class ClientProxy extends CommonProxy {
|
||||
if (AngelicaConfig.enableHudCaching) {
|
||||
HUDCaching.init();
|
||||
}
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
MinecraftForge.EVENT_BUS.register(SodiumDebugScreenHandler.INSTANCE);
|
||||
if (AngelicaConfig.enableCeleritas) {
|
||||
CeleritasSetup.ensureInitialized();
|
||||
MinecraftForge.EVENT_BUS.register(CeleritasDebugScreenHandler.INSTANCE);
|
||||
} else {
|
||||
LOGGER.info("Celeritas is disabled, skipping initialization from init()");
|
||||
}
|
||||
if (AngelicaConfig.enableIris) {
|
||||
MinecraftForge.EVENT_BUS.register(IrisDebugScreenHandler.INSTANCE);
|
||||
@@ -128,6 +143,14 @@ public class ClientProxy extends CommonProxy {
|
||||
if (AngelicaConfig.enableZoom) {
|
||||
Zoom.init();
|
||||
}
|
||||
if (AngelicaConfig.enableDynamicLights) {
|
||||
EntityLightConfig.init(new java.io.File(mc.mcDataDir, "config"));
|
||||
}
|
||||
|
||||
// Register debug commands in dev environment only
|
||||
if (!AngelicaTweaker.isObfEnv()) {
|
||||
ClientCommandHandler.instance.registerCommand(new AngelicaCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasGLSMKeyPressed;
|
||||
@@ -145,7 +168,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
super.postInit(event);
|
||||
|
||||
if (ModStatus.isLotrLoaded && AngelicaConfig.enableSodium && CompatConfig.fixLotr) {
|
||||
if (ModStatus.isLotrLoaded && AngelicaConfig.enableCeleritas && CompatConfig.fixLotr) {
|
||||
try {
|
||||
Class<?> lotrRendering = Class.forName("lotr.common.coremod.LOTRReplacedMethods$BlockRendering");
|
||||
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "naturalBlockClassTable");
|
||||
|
||||
@@ -31,7 +31,6 @@ import jss.notfine.core.Settings;
|
||||
import jss.notfine.gui.options.named.GraphicsQualityOff;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
@@ -40,6 +39,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
public class CloudRenderer implements IResourceManagerReloadListener {
|
||||
// Shared constants.
|
||||
@@ -337,12 +337,12 @@ public class CloudRenderer implements IResourceManagerReloadListener {
|
||||
texColor = newColor;
|
||||
}
|
||||
|
||||
GLStateManager.glActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, COLOR_TEX.getGlTextureId());
|
||||
GLStateManager.enableTexture();
|
||||
|
||||
// Bind the clouds texture last so the shader's sampler2D is correct.
|
||||
GLStateManager.glActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
mc.renderEngine.bindTexture(texture);
|
||||
|
||||
vbo.setupState();
|
||||
@@ -384,9 +384,9 @@ public class CloudRenderer implements IResourceManagerReloadListener {
|
||||
vbo.cleanupState(); // Unbind buffer and disable pointers.
|
||||
|
||||
// Disable our coloring.
|
||||
GLStateManager.glActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GLStateManager.disableTexture();
|
||||
GLStateManager.glActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
// Reset texture matrix.
|
||||
GLStateManager.glMatrixMode(GL11.GL_TEXTURE);
|
||||
|
||||
@@ -11,6 +11,27 @@ public class AngelicaRenderQueue {
|
||||
private static final Thread MAIN_THREAD = Thread.currentThread();
|
||||
private static final Queue<Runnable> TASKS = new ConcurrentLinkedQueue<>();
|
||||
|
||||
// Metrics
|
||||
private static volatile int lastFrameTasksRan = 0;
|
||||
private static volatile long lastFrameTimeNs = 0;
|
||||
|
||||
public static int getQueueDepth() {
|
||||
return TASKS.size();
|
||||
}
|
||||
|
||||
public static int getLastFrameTasksRan() {
|
||||
return lastFrameTasksRan;
|
||||
}
|
||||
|
||||
public static long getLastFrameTimeNs() {
|
||||
return lastFrameTimeNs;
|
||||
}
|
||||
|
||||
public static void recordFrameStats(int tasksRan, long timeNs) {
|
||||
lastFrameTasksRan = tasksRan;
|
||||
lastFrameTimeNs = timeNs;
|
||||
}
|
||||
|
||||
private static final Executor EXECUTOR = (runnable) -> {
|
||||
if(Thread.currentThread() == MAIN_THREAD) {
|
||||
runnable.run();
|
||||
@@ -27,7 +48,7 @@ public class AngelicaRenderQueue {
|
||||
public static int processTasks(int max) {
|
||||
int tasksRun = 0;
|
||||
while(tasksRun < max) {
|
||||
Runnable r = TASKS.poll();
|
||||
final Runnable r = TASKS.poll();
|
||||
if(r == null)
|
||||
break;
|
||||
r.run();
|
||||
@@ -36,11 +57,7 @@ public class AngelicaRenderQueue {
|
||||
return tasksRun;
|
||||
}
|
||||
|
||||
public static int processTasks() {
|
||||
return processTasks(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private static final long WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(50);
|
||||
private static final long WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(20);
|
||||
|
||||
public static void managedBlock(BooleanSupplier isDone) {
|
||||
while(!isDone.getAsBoolean()) {
|
||||
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.BlockRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.model.light.LightPipeline;
|
||||
import org.embeddedt.embeddium.impl.model.light.flat.FlatLightPipeline;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkColorWriter;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.light.LightDataCache;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.light.QuadLightingHelper;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.light.VanillaDiffuseProvider;
|
||||
import org.embeddedt.embeddium.impl.model.light.smooth.SmoothLightPipeline;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import org.embeddedt.embeddium.impl.model.light.data.LightDataAccess;
|
||||
import org.embeddedt.embeddium.impl.model.light.data.QuadLightData;
|
||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildBuffers;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevel;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.util.QuadUtil;
|
||||
|
||||
public class AngelicaChunkBuildContext extends ChunkBuildContext {
|
||||
public static final int NUM_PASSES = 2;
|
||||
|
||||
private final TextureMapExtension textureAtlas;
|
||||
private final ChunkVertexEncoder.Vertex[] vertices = ChunkVertexEncoder.Vertex.uninitializedQuad();
|
||||
@Getter
|
||||
private final WorldSlice worldSlice;
|
||||
@Getter
|
||||
private final BlockRenderContext blockRenderContext = new BlockRenderContext();
|
||||
|
||||
private List<IDynamicLightSource> chunkLightSources;
|
||||
private DynamicLights dynamicLightsInstance;
|
||||
|
||||
private final LightDataCache lightDataCache = new LightDataCache();
|
||||
private final SmoothLightPipeline smoothLightPipeline;
|
||||
private final FlatLightPipeline flatLightPipeline;
|
||||
private final QuadLightData quadLightData = new QuadLightData();
|
||||
private final VertexArrayQuadView quadView;
|
||||
private boolean lightPipelineReady = false;
|
||||
private int originX, originY, originZ;
|
||||
|
||||
public AngelicaChunkBuildContext(RenderPassConfiguration<?> renderPassConfiguration, WorldClient world) {
|
||||
super(renderPassConfiguration);
|
||||
this.textureAtlas = (TextureMapExtension) Minecraft.getMinecraft().getTextureMapBlocks();
|
||||
this.worldSlice = new WorldSlice(world);
|
||||
this.smoothLightPipeline = new SmoothLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false);
|
||||
this.flatLightPipeline = new FlatLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false);
|
||||
this.quadView = new VertexArrayQuadView(vertices);
|
||||
}
|
||||
|
||||
public void setupLightPipeline(int minBlockX, int minBlockY, int minBlockZ) {
|
||||
setupLightPipeline(worldSlice, minBlockX, minBlockY, minBlockZ);
|
||||
}
|
||||
|
||||
public void setupLightPipeline(IBlockAccess blockAccess, int minBlockX, int minBlockY, int minBlockZ) {
|
||||
this.originX = minBlockX;
|
||||
this.originY = minBlockY;
|
||||
this.originZ = minBlockZ;
|
||||
lightDataCache.setWorld(blockAccess);
|
||||
lightDataCache.reset(minBlockX, minBlockY, minBlockZ);
|
||||
smoothLightPipeline.reset();
|
||||
flatLightPipeline.reset();
|
||||
lightPipelineReady = true;
|
||||
}
|
||||
|
||||
public void setupDynamicLights(int chunkOriginX, int chunkOriginY, int chunkOriginZ) {
|
||||
if (DynamicLights.isEnabled()) {
|
||||
this.dynamicLightsInstance = DynamicLights.get();
|
||||
this.chunkLightSources = dynamicLightsInstance.getSourcesForChunk(chunkOriginX, chunkOriginY, chunkOriginZ);
|
||||
} else {
|
||||
this.dynamicLightsInstance = null;
|
||||
this.chunkLightSources = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Material selectMaterial(Material material, TextureAtlasSprite sprite, boolean isShaderPackOverride) {
|
||||
// Don't apply transparency-based optimization when shader pack explicitly overrides the material
|
||||
if (isShaderPackOverride) {
|
||||
return material;
|
||||
}
|
||||
if (sprite != null && sprite.getClass() == TextureAtlasSprite.class && !sprite.hasAnimationMetadata()) {
|
||||
final var transparencyLevel = ((SpriteExtension)sprite).celeritas$getTransparencyLevel();
|
||||
if (transparencyLevel == SpriteTransparencyLevel.OPAQUE && material == AngelicaRenderPassConfiguration.CUTOUT_MIPPED_MATERIAL) {
|
||||
return AngelicaRenderPassConfiguration.SOLID_MATERIAL;
|
||||
} else if (material == AngelicaRenderPassConfiguration.TRANSLUCENT_MATERIAL && transparencyLevel != SpriteTransparencyLevel.TRANSLUCENT) {
|
||||
return AngelicaRenderPassConfiguration.CUTOUT_MIPPED_MATERIAL;
|
||||
}
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void copyRawBuffer(int[] rawBuffer, int vertexCount, ChunkBuildBuffers buffers, Material material, boolean isShaderPackOverride,
|
||||
boolean blockAllowsSmoothLighting) {
|
||||
if (vertexCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var animatedSprites = ((MinecraftBuiltRenderSectionData<TextureAtlasSprite, TileEntity>)buffers.getSectionContextBundle()).animatedSprites;
|
||||
|
||||
if ((vertexCount & 0x3) != 0) {
|
||||
throw new IllegalStateException("Only quads are supported, got: " + vertexCount);
|
||||
}
|
||||
|
||||
final boolean hasDynamicLights = chunkLightSources != null && !chunkLightSources.isEmpty();
|
||||
final boolean separateAo = BlockRenderingSettings.INSTANCE.shouldUseSeparateAo();
|
||||
final boolean celeritasSmoothLighting = SodiumClientMod.options().quality.useCeleritasSmoothLighting;
|
||||
final boolean shaderActive = IrisApi.getInstance().isShaderPackInUse();
|
||||
final boolean useAoCalculation = lightPipelineReady && (separateAo || celeritasSmoothLighting || shaderActive);
|
||||
final boolean stripDiffuse = shaderActive && BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading();
|
||||
final boolean shade = false; // Vanilla bakes it, or we remove it - so no need to shade
|
||||
final ChunkColorWriter colorEncoder = separateAo ? ChunkColorWriter.SEPARATE_AO : ChunkColorWriter.EMBEDDIUM;
|
||||
|
||||
int ptr = 0;
|
||||
final int numQuads = vertexCount / 4;
|
||||
|
||||
final int blockX = blockRenderContext.localPosX;
|
||||
final int blockY = blockRenderContext.localPosY;
|
||||
final int blockZ = blockRenderContext.localPosZ;
|
||||
final int worldX = originX + blockX;
|
||||
final int worldY = originY + blockY;
|
||||
final int worldZ = originZ + blockZ;
|
||||
final boolean isEmissive = useAoCalculation && QuadLightingHelper.isBlockEmissive(worldSlice, worldX, worldY, worldZ);
|
||||
|
||||
for (int quadIdx = 0; quadIdx < numQuads; quadIdx++) {
|
||||
float uSum = 0, vSum = 0;
|
||||
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
final var vertex = vertices[vIdx];
|
||||
vertex.x = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.y = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.z = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
|
||||
final float u = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
final float v = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.u = u;
|
||||
uSum += u;
|
||||
vertex.v = v;
|
||||
vSum += v;
|
||||
|
||||
vertex.color = rawBuffer[ptr++];
|
||||
vertex.vanillaNormal = rawBuffer[ptr++];
|
||||
vertex.light = rawBuffer[ptr++];
|
||||
}
|
||||
|
||||
final int trueNormal = QuadUtil.calculateNormal(vertices);
|
||||
final ModelQuadFacing facing = QuadUtil.findNormalFace(trueNormal);
|
||||
final TextureAtlasSprite sprite = this.textureAtlas.celeritas$findFromUV(uSum * 0.25f, vSum * 0.25f);
|
||||
|
||||
if (sprite != null && sprite.hasAnimationMetadata()) {
|
||||
animatedSprites.add(sprite);
|
||||
}
|
||||
|
||||
// Strip vanilla's baked diffuse when shaders want oldLighting=false - multiply by an inversion factor
|
||||
// instead of attempting to mixin/asm all the places that bake it in
|
||||
if (stripDiffuse) {
|
||||
final float inverseDiffuse = VanillaDiffuseProvider.INSTANCE.getInverseDiffuse(facing);
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
vertices[vIdx].color = VanillaDiffuseProvider.multiplyColor(vertices[vIdx].color, inverseDiffuse);
|
||||
}
|
||||
}
|
||||
|
||||
if (useAoCalculation) {
|
||||
final boolean quadIsFullBright = QuadLightingHelper.isQuadFullBright(vertices);
|
||||
|
||||
if (isEmissive || quadIsFullBright) {
|
||||
Arrays.fill(quadLightData.br, 1.0f);
|
||||
if (isEmissive) {
|
||||
Arrays.fill(quadLightData.lm, LightDataAccess.FULL_BRIGHT);
|
||||
} else {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
quadLightData.lm[i] = vertices[i].light;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quadView.setup(trueNormal, blockX, blockY, blockZ);
|
||||
final ModelQuadFacing lightFace = quadView.getLightFace();
|
||||
final LightPipeline pipeline = blockAllowsSmoothLighting ? smoothLightPipeline : flatLightPipeline;
|
||||
final ModelQuadFacing cullFace = quadView.getCullFace();
|
||||
pipeline.calculate(quadView, worldX, worldY, worldZ, quadLightData, cullFace, lightFace, shade, true);
|
||||
}
|
||||
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
final var vertex = vertices[vIdx];
|
||||
vertex.trueNormal = trueNormal;
|
||||
vertex.color = colorEncoder.writeColor(vertex.color, quadLightData.br[vIdx]);
|
||||
vertex.light = quadLightData.lm[vIdx];
|
||||
}
|
||||
} else {
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
vertices[vIdx].trueNormal = trueNormal;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply dynamic lights after AO calculation so they're not overwritten
|
||||
if (hasDynamicLights) {
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
final var vertex = vertices[vIdx];
|
||||
final double dynamicLevel = dynamicLightsInstance.getDynamicLightLevelFromSources(originX + vertex.x, originY + vertex.y, originZ + vertex.z, chunkLightSources);
|
||||
if (dynamicLevel > 0) {
|
||||
vertex.light = dynamicLightsInstance.getLightmapWithDynamicLight(dynamicLevel, vertex.light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Material correctMaterial = selectMaterial(material, sprite, isShaderPackOverride);
|
||||
final var builder = buffers.get(correctMaterial);
|
||||
|
||||
if (correctMaterial != material && builder.getEncoder() instanceof IrisExtendedChunkVertexEncoder iris) {
|
||||
iris.setContext(blockRenderContext);
|
||||
}
|
||||
|
||||
builder.getVertexBuffer(facing).push(vertices, correctMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.BlockRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.ContextAwareChunkVertexEncoder;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
|
||||
import net.coderbot.iris.vertices.ExtendedDataHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildBuffers;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltSectionMeshParts;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.SectionVisibilityBuilder;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.util.task.CancellationToken;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput> {
|
||||
protected final RenderSection render;
|
||||
protected final int buildTime;
|
||||
protected final Vector3d camera;
|
||||
|
||||
private static final long DEFERRED_BLOCK_TIMEOUT_MS = 10_000; // 10 seconds
|
||||
private static final int MAX_RETRIES = 2;
|
||||
|
||||
protected record DeferredBlock(int x, int y, int z, Block block, int meta, int pass, Material materialOverride, boolean isShaderPackOverride) {}
|
||||
|
||||
public AngelicaChunkBuilderMeshingTask(RenderSection render, int time, Vector3d camera) {
|
||||
this.render = render;
|
||||
this.buildTime = time;
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
protected abstract Tessellator getTessellator();
|
||||
protected abstract void setRenderPass(int pass);
|
||||
protected abstract IBlockAccess getBlockAccess();
|
||||
protected abstract SmoothBiomeColorCache getBiomeColorCache();
|
||||
|
||||
protected boolean isThreaded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean canRenderOffThread(Block block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void onEnterExecute() {}
|
||||
|
||||
protected void onExitExecute() {}
|
||||
|
||||
protected void addExtraCrashInfo(CrashReportCategory category) {}
|
||||
|
||||
@Override
|
||||
public ChunkBuildOutput execute(ChunkBuildContext context, CancellationToken cancellationToken) {
|
||||
final AngelicaChunkBuildContext buildContext = (AngelicaChunkBuildContext) context;
|
||||
final MinecraftBuiltRenderSectionData<TextureAtlasSprite, TileEntity> renderData = new MinecraftBuiltRenderSectionData<>();
|
||||
final SectionVisibilityBuilder occluder = new SectionVisibilityBuilder();
|
||||
|
||||
final ChunkBuildBuffers buffers = buildContext.buffers;
|
||||
buffers.init(renderData, this.render.getSectionIndex());
|
||||
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
final int maxX = minX + 16;
|
||||
final int maxY = minY + 16;
|
||||
final int maxZ = minZ + 16;
|
||||
|
||||
buildContext.setupDynamicLights(minX, minY, minZ);
|
||||
|
||||
final BlockPos blockPos = new BlockPos(minX, minY, minZ);
|
||||
final IBlockAccess region = getBlockAccess();
|
||||
final SmoothBiomeColorCache biomeColorCache = getBiomeColorCache();
|
||||
|
||||
onEnterExecute();
|
||||
|
||||
final Tessellator tessellator = getTessellator();
|
||||
|
||||
try {
|
||||
tessellator.setTranslation(-minX, -minY, -minZ);
|
||||
SmoothBiomeColorCache.setActiveCache(biomeColorCache);
|
||||
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
final Map<Block, BlockRenderLayer> blockTypeIds = provider != null ? provider.getBlockTypeIds() : null;
|
||||
final BlockRenderContext blockRenderContext = buildContext.getBlockRenderContext();
|
||||
|
||||
final boolean threaded = isThreaded();
|
||||
final List<DeferredBlock> deferredBlocks = threaded ? new ArrayList<>() : null;
|
||||
|
||||
final RenderBlocks renderBlocks = new RenderBlocks(region);
|
||||
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
if (cancellationToken.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
blockPos.set(x, y, z);
|
||||
|
||||
final Block block = region.getBlock(x, y, z);
|
||||
|
||||
if (block == Blocks.air) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int meta = region.getBlockMetadata(x, y, z);
|
||||
|
||||
if (block.hasTileEntity(meta)) {
|
||||
final TileEntity tileEntity = region.getTileEntity(x, y, z);
|
||||
if (TileEntityRendererDispatcher.instance.hasSpecialRenderer(tileEntity)) {
|
||||
renderData.globalBlockEntities.add(tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
final boolean canRenderOffThread = !threaded || canRenderOffThread(block);
|
||||
|
||||
// Check for shader pack override
|
||||
final BlockRenderLayer override = blockTypeIds != null ? blockTypeIds.get(block) : null;
|
||||
|
||||
for (int pass = 0; pass < AngelicaChunkBuildContext.NUM_PASSES; pass++) {
|
||||
final boolean canRender;
|
||||
Material materialOverride = null;
|
||||
|
||||
if (override != null) {
|
||||
// Shader pack override controls both pass and material
|
||||
canRender = (pass == override.toVanillaPass());
|
||||
if (canRender) {
|
||||
materialOverride = buffers.getRenderPassConfiguration().getMaterialForRenderType(override);
|
||||
}
|
||||
} else {
|
||||
// Normal block rendering
|
||||
canRender = block.canRenderInPass(pass);
|
||||
}
|
||||
|
||||
if (canRender) {
|
||||
final boolean isShaderPackOverride = materialOverride != null;
|
||||
if (!canRenderOffThread) {
|
||||
deferredBlocks.add(new DeferredBlock(x, y, z, block, meta, pass, materialOverride, isShaderPackOverride));
|
||||
continue;
|
||||
}
|
||||
|
||||
renderBlock(block, meta, x, y, z, pass, tessellator, renderBlocks, buffers, buildContext, blockRenderContext, minX, minY, minZ, materialOverride, isShaderPackOverride);
|
||||
}
|
||||
}
|
||||
|
||||
if (block.isOpaqueCube()) {
|
||||
occluder.markOpaque(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process deferred blocks on main thread if any
|
||||
if (deferredBlocks != null && !deferredBlocks.isEmpty()) {
|
||||
processDeferredBlocks(deferredBlocks, buildContext, buffers, region, minX, minY, minZ);
|
||||
}
|
||||
|
||||
final Reference2ReferenceMap<TerrainRenderPass, BuiltSectionMeshParts> meshes =
|
||||
BuiltSectionMeshParts.groupFromBuildBuffers(buffers,
|
||||
(float) camera.x - minX, (float) camera.y - minY, (float) camera.z - minZ);
|
||||
|
||||
if (!meshes.isEmpty()) {
|
||||
renderData.hasBlockGeometry = true;
|
||||
}
|
||||
|
||||
renderData.visibilityData = occluder.computeVisibilityEncoding();
|
||||
|
||||
SmoothBiomeColorCache.clearActiveCache();
|
||||
tessellator.setTranslation(0, 0, 0);
|
||||
|
||||
CeleritasDebug.incrementChunkUpdateCounter();
|
||||
|
||||
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
||||
|
||||
} catch (ReportedException ex) {
|
||||
throw fillCrashInfo(ex.getCrashReport(), region, blockPos);
|
||||
} catch (Throwable ex) {
|
||||
throw fillCrashInfo(CrashReport.makeCrashReport(ex, "Encountered exception while building chunk meshes"), region, blockPos);
|
||||
} finally {
|
||||
SmoothBiomeColorCache.clearActiveCache();
|
||||
onExitExecute();
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderBlock(Block block, int metadata, int x, int y, int z, int pass, Tessellator tessellator, RenderBlocks renderBlocks, ChunkBuildBuffers buffers, AngelicaChunkBuildContext buildContext, BlockRenderContext blockRenderContext, int originX, int originY, int originZ, Material materialOverride, boolean isShaderPackOverride) {
|
||||
|
||||
final var blockMaterial = block.getMaterial();
|
||||
final boolean isFluid = blockMaterial == net.minecraft.block.material.Material.water || blockMaterial == net.minecraft.block.material.Material.lava;
|
||||
|
||||
// Use material override if provided, otherwise derive from pass
|
||||
// Lava is opaque - use solid to skip unnecessary alpha testing
|
||||
final Material passMaterial;
|
||||
if (materialOverride != null) {
|
||||
passMaterial = materialOverride;
|
||||
} else if (blockMaterial == net.minecraft.block.material.Material.lava) {
|
||||
passMaterial = AngelicaRenderPassConfiguration.SOLID_MATERIAL;
|
||||
} else {
|
||||
passMaterial = buffers.getRenderPassConfiguration().getMaterialForRenderType(BlockRenderLayer.fromVanillaPass(pass));
|
||||
}
|
||||
|
||||
final var encoder = buffers.get(passMaterial).getEncoder();
|
||||
final ContextAwareChunkVertexEncoder contextEncoder = (encoder instanceof ContextAwareChunkVertexEncoder) ? (ContextAwareChunkVertexEncoder) encoder : null;
|
||||
|
||||
blockRenderContext.localPosX = x & 15;
|
||||
blockRenderContext.localPosY = y & 15;
|
||||
blockRenderContext.localPosZ = z & 15;
|
||||
|
||||
if (contextEncoder != null) {
|
||||
final byte lightValue = (byte) block.getLightValue();
|
||||
if (isFluid) {
|
||||
contextEncoder.prepareToRenderFluid(blockRenderContext, block, lightValue);
|
||||
} else {
|
||||
contextEncoder.prepareToRenderBlock(blockRenderContext, block, metadata,
|
||||
ExtendedDataHelper.BLOCK_RENDER_TYPE, lightValue);
|
||||
}
|
||||
}
|
||||
|
||||
setRenderPass(pass);
|
||||
// Trigger side effects from canRenderInPass (some ISBRHs like BuildCraft set global state in this method that gets read elsewhere renderWorldBlock)
|
||||
block.canRenderInPass(pass);
|
||||
tessellator.startDrawingQuads();
|
||||
renderBlocks.renderBlockByRenderType(block, x, y, z);
|
||||
// In modern versions, block models can specify whether to enable AO or not, but here we must
|
||||
// rely on render ID heuristics to figure out which models would have turned it off
|
||||
int vanillaRenderId = block.getRenderType();
|
||||
boolean blockAllowsSmoothLighting = Minecraft.isAmbientOcclusionEnabled() // smooth lighting on
|
||||
&& block.getLightValue() == 0 // does not emit real block light
|
||||
&& vanillaRenderId != 1 // is not a "cross" block
|
||||
&& vanillaRenderId != 40; // is not a double plant block
|
||||
buildContext.copyRawBuffer(tessellator.rawBuffer, tessellator.vertexCount, buffers, passMaterial,
|
||||
isShaderPackOverride, blockAllowsSmoothLighting);
|
||||
tessellator.reset();
|
||||
tessellator.isDrawing = false;
|
||||
|
||||
if (contextEncoder != null) {
|
||||
contextEncoder.finishRenderingBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void processDeferredBlocks(List<DeferredBlock> deferredBlocks, AngelicaChunkBuildContext buildContext, ChunkBuildBuffers buffers, IBlockAccess region, int minX, int minY, int minZ) {
|
||||
|
||||
final BlockRenderContext blockRenderContext = buildContext.getBlockRenderContext();
|
||||
|
||||
final CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
final RenderBlocks mainThreadRenderBlocks = new RenderBlocks(region);
|
||||
final Tessellator mainTessellator = Tessellator.instance;
|
||||
mainTessellator.setTranslation(-minX, -minY, -minZ);
|
||||
|
||||
for (DeferredBlock deferred : deferredBlocks) {
|
||||
renderBlock(deferred.block(), deferred.meta(), deferred.x(), deferred.y(), deferred.z(), deferred.pass(),
|
||||
mainTessellator, mainThreadRenderBlocks, buffers, buildContext,
|
||||
blockRenderContext, minX, minY, minZ, deferred.materialOverride(), deferred.isShaderPackOverride());
|
||||
}
|
||||
|
||||
mainTessellator.setTranslation(0, 0, 0);
|
||||
}, AngelicaRenderQueue.executor());
|
||||
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int retries = 0;
|
||||
while (retries < MAX_RETRIES) {
|
||||
try {
|
||||
future.get(DEFERRED_BLOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
return;
|
||||
} catch (TimeoutException e) {
|
||||
retries++;
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
return;
|
||||
}
|
||||
if (retries >= MAX_RETRIES) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Error during main thread deferred block rendering", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ReportedException fillCrashInfo(CrashReport report, IBlockAccess slice, BlockPos pos) {
|
||||
final CrashReportCategory crashReportSection = report.makeCategory("Block being rendered");
|
||||
|
||||
Block block = Blocks.air;
|
||||
int meta = 0;
|
||||
try {
|
||||
block = slice.getBlock(pos.x, pos.y, pos.z);
|
||||
meta = slice.getBlockMetadata(pos.x, pos.y, pos.z);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
crashReportSection.addCrashSection("Block", block);
|
||||
crashReportSection.addCrashSection("Block location", String.format("World: (%d,%d,%d)", pos.x, pos.y, pos.z));
|
||||
crashReportSection.addCrashSection("Block meta", meta);
|
||||
crashReportSection.addCrashSection("Chunk section", this.render);
|
||||
|
||||
addExtraCrashInfo(crashReportSection);
|
||||
|
||||
return new ReportedException(report);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import org.embeddedt.embeddium.impl.gl.device.RenderDevice;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.DefaultChunkRenderer;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderTextureSlot;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
|
||||
class AngelicaChunkRenderer extends DefaultChunkRenderer {
|
||||
private GlProgram<? extends ChunkShaderInterface> irisProgram;
|
||||
private boolean usingIrisProgram;
|
||||
|
||||
public AngelicaChunkRenderer(RenderDevice device, RenderPassConfiguration<?> renderPassConfiguration) {
|
||||
super(device, renderPassConfiguration);
|
||||
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
if (provider != null) {
|
||||
provider.setRenderPassConfiguration(renderPassConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void begin(TerrainRenderPass pass) {
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
|
||||
// Check if Iris shaders are active and we have an override
|
||||
if (provider != null && provider.isShadersEnabled()) {
|
||||
final GlProgram<? extends ChunkShaderInterface> override = provider.getShaderOverride(pass);
|
||||
if (override != null) {
|
||||
pass.startDrawing();
|
||||
override.bind();
|
||||
override.getInterface().setupState(pass);
|
||||
this.activeProgram = (GlProgram<ChunkShaderInterface>) override;
|
||||
this.irisProgram = override;
|
||||
this.usingIrisProgram = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to default shader
|
||||
this.usingIrisProgram = false;
|
||||
this.irisProgram = null;
|
||||
super.begin(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void end(TerrainRenderPass pass) {
|
||||
if (usingIrisProgram && irisProgram != null) {
|
||||
irisProgram.getInterface().restoreState();
|
||||
irisProgram.unbind();
|
||||
irisProgram = null;
|
||||
usingIrisProgram = false;
|
||||
this.activeProgram = null;
|
||||
pass.endDrawing();
|
||||
return;
|
||||
}
|
||||
|
||||
super.end(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useBlockFaceCulling() {
|
||||
return IrisShaderProviderHolder.shouldUseFaceCulling();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureShaderInterface(ChunkShaderInterface shader) {
|
||||
if (!usingIrisProgram) {
|
||||
shader.setTextureSlot(ChunkShaderTextureSlot.BLOCK, 0);
|
||||
shader.setTextureSlot(ChunkShaderTextureSlot.LIGHT, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Adapated from: Beddium for usage in Angelica
|
||||
*
|
||||
* Copyright (C) 2025 Ven, FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, only version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ChunkTrackerAccessor;
|
||||
import it.unimi.dsi.fastutil.longs.LongCollection;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.longs.LongSets;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.map.ChunkStatus;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.map.ChunkTracker;
|
||||
import org.embeddedt.embeddium.impl.util.PositionUtil;
|
||||
|
||||
/**
|
||||
* Configurable chunk tracker supporting "fast" and "aggressive" loading modes.
|
||||
* Based on Beddium's SafeChunkTracker by Ven and FalsePattern.
|
||||
*
|
||||
* Modes (controlled by {@link AngelicaConfig#useVanillaChunkTracking}):
|
||||
* - Fast (default): Only renders chunks when all 8 neighbors are loaded (better lighting/AO)
|
||||
* - Aggressive: Renders chunks immediately when loaded (faster perceived loading)
|
||||
*
|
||||
* Mode can be switched at runtime via options menu - triggers renderer reload.
|
||||
*/
|
||||
public class AngelicaChunkTracker extends ChunkTracker {
|
||||
private final LongOpenHashSet chunkReadyForced = new LongOpenHashSet();
|
||||
|
||||
private ChunkTrackerAccessor self() {
|
||||
return (ChunkTrackerAccessor) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkStatusAdded(int x, int z, int flags) {
|
||||
final var key = PositionUtil.packChunk(x, z);
|
||||
final var prev = self().angelica$getChunkStatus().get(key);
|
||||
final var cur = prev | flags;
|
||||
|
||||
if (prev == cur) {
|
||||
return;
|
||||
}
|
||||
|
||||
self().angelica$getChunkStatus().put(key, cur);
|
||||
this.updateNeighbors(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkStatusRemoved(int x, int z, int flags) {
|
||||
final var key = PositionUtil.packChunk(x, z);
|
||||
final var prev = self().angelica$getChunkStatus().get(key);
|
||||
final int cur = prev & ~flags;
|
||||
|
||||
if (prev == cur) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cur == self().angelica$getChunkStatus().defaultReturnValue()) {
|
||||
self().angelica$getChunkStatus().remove(key);
|
||||
} else {
|
||||
self().angelica$getChunkStatus().put(key, cur);
|
||||
}
|
||||
|
||||
this.updateNeighbors(x, z);
|
||||
}
|
||||
|
||||
private void updateNeighbors(int x, int z) {
|
||||
for (int ox = -1; ox <= 1; ox++) {
|
||||
for (int oz = -1; oz <= 1; oz++) {
|
||||
this.updateMerged(ox + x, oz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMerged(int x, int z) {
|
||||
final long key = PositionUtil.packChunk(x, z);
|
||||
final int selfFlags = self().angelica$getChunkStatus().get(key);
|
||||
|
||||
// If self doesn't have FLAG_ALL, can't be ready at all
|
||||
if (selfFlags != ChunkStatus.FLAG_ALL) {
|
||||
// Remove from ready if present
|
||||
final boolean wasReady = self().angelica$getChunkReady().remove(key) | this.chunkReadyForced.remove(key);
|
||||
if (wasReady && !self().angelica$getLoadQueue().remove(key)) {
|
||||
self().angelica$getUnloadQueue().add(key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if all neighbors also have FLAG_ALL
|
||||
int mergedFlags = selfFlags;
|
||||
for (int ox = -1; ox <= 1; ox++) {
|
||||
for (int oz = -1; oz <= 1; oz++) {
|
||||
mergedFlags &= self().angelica$getChunkStatus().get(PositionUtil.packChunk(ox + x, oz + z));
|
||||
}
|
||||
}
|
||||
|
||||
if (mergedFlags == ChunkStatus.FLAG_ALL) {
|
||||
// All neighbors ready - add to both sets -- Trigger load if newly added to chunkReadyForced (first time ready)
|
||||
if ((this.chunkReadyForced.add(key) || self().angelica$getChunkReady().add(key)) && !self().angelica$getUnloadQueue().remove(key)) {
|
||||
self().angelica$getLoadQueue().add(key);
|
||||
}
|
||||
} else {
|
||||
// Self ready but neighbors not - add to forced, remove from proper
|
||||
// Trigger load if state changed (moved from proper to forced, or newly forced)
|
||||
if ((this.chunkReadyForced.add(key) || self().angelica$getChunkReady().remove(key)) && !self().angelica$getUnloadQueue().remove(key)) {
|
||||
self().angelica$getLoadQueue().add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongCollection getReadyChunks() {
|
||||
if (AngelicaConfig.useVanillaChunkTracking) {
|
||||
// Aggressive mode: return both ready sets
|
||||
final LongOpenHashSet combined = new LongOpenHashSet(self().angelica$getChunkReady());
|
||||
combined.addAll(this.chunkReadyForced);
|
||||
return LongSets.unmodifiable(combined);
|
||||
} else {
|
||||
// Default mode: only return chunks with all neighbors ready
|
||||
return LongSets.unmodifiable(self().angelica$getChunkReady());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachEvent(ChunkEventHandler loadEventHandler, ChunkEventHandler unloadEventHandler) {
|
||||
ChunkTracker.forEachChunk(self().angelica$getUnloadQueue(), unloadEventHandler);
|
||||
self().angelica$getUnloadQueue().clear();
|
||||
|
||||
ChunkTracker.forEachChunk(self().angelica$getLoadQueue(), loadEventHandler);
|
||||
self().angelica$getLoadQueue().clear();
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.RenderPassHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.util.position.SectionPos;
|
||||
import org.embeddedt.embeddium.impl.util.task.CancellationToken;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class AngelicaMainThreadMeshingTask extends AngelicaChunkBuilderMeshingTask {
|
||||
|
||||
private IBlockAccess blockAccess;
|
||||
private SmoothBiomeColorCache biomeColorCache;
|
||||
|
||||
public AngelicaMainThreadMeshingTask(RenderSection render, int time, Vector3d camera) {
|
||||
super(render, time, camera);
|
||||
initBlockAccess();
|
||||
}
|
||||
|
||||
private void initBlockAccess() {
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
final var world = Minecraft.getMinecraft().theWorld;
|
||||
this.biomeColorCache = ((WorldClientExtension) world).celeritas$getSmoothBiomeColorCache();
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
this.blockAccess = new ChunkCache(world, minX - 1, minY - 1, minZ - 1, minX + 17, minY + 17, minZ + 17, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkBuildOutput execute(ChunkBuildContext context, CancellationToken cancellationToken) {
|
||||
final AngelicaChunkBuildContext buildContext = (AngelicaChunkBuildContext) context;
|
||||
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
buildContext.setupLightPipeline(blockAccess, minX, minY, minZ);
|
||||
|
||||
return super.execute(context, cancellationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tessellator getTessellator() {
|
||||
return Tessellator.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRenderPass(int pass) {
|
||||
RenderPassHelper.setWorldRenderPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBlockAccess getBlockAccess() {
|
||||
return blockAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SmoothBiomeColorCache getBiomeColorCache() {
|
||||
return biomeColorCache;
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.parameters.AlphaCutoffParameter;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AngelicaRenderPassConfiguration {
|
||||
|
||||
public static TerrainRenderPass SOLID_PASS, CUTOUT_MIPPED_PASS, TRANSLUCENT_PASS;
|
||||
public static Material SOLID_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL;
|
||||
|
||||
private record AngelicaPipelineState(int pass, boolean disableAlphaTest) implements TerrainRenderPass.PipelineState {
|
||||
@Override
|
||||
public void setup() {
|
||||
if (pass == 0) {
|
||||
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||
}
|
||||
if (disableAlphaTest) {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (disableAlphaTest) {
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(int pass, boolean disableAlphaTest, ChunkVertexType vertexType) {
|
||||
return TerrainRenderPass.builder()
|
||||
.pipelineState(new AngelicaPipelineState(pass, disableAlphaTest))
|
||||
.vertexType(vertexType)
|
||||
.primitiveType(QuadPrimitiveType.DIRECT);
|
||||
}
|
||||
|
||||
public static RenderPassConfiguration<BlockRenderLayer> build(ChunkVertexType vertexType) {
|
||||
SOLID_PASS = builderForRenderType(0, true, vertexType)
|
||||
.name("solid")
|
||||
.fragmentDiscard(false)
|
||||
.useReverseOrder(false)
|
||||
.build();
|
||||
|
||||
CUTOUT_MIPPED_PASS = builderForRenderType(0, false, vertexType)
|
||||
.name("cutout_mipped")
|
||||
.fragmentDiscard(true)
|
||||
.useReverseOrder(false)
|
||||
.build();
|
||||
|
||||
TRANSLUCENT_PASS = builderForRenderType(1, false, vertexType)
|
||||
.name("translucent")
|
||||
.fragmentDiscard(false)
|
||||
.useReverseOrder(true)
|
||||
.useTranslucencySorting(true)
|
||||
.build();
|
||||
|
||||
TRANSLUCENT_MATERIAL = new Material(TRANSLUCENT_PASS, AlphaCutoffParameter.ZERO, true);
|
||||
SOLID_MATERIAL = new Material(SOLID_PASS, AlphaCutoffParameter.ZERO, true);
|
||||
CUTOUT_MIPPED_MATERIAL = new Material(CUTOUT_MIPPED_PASS, AlphaCutoffParameter.ONE_TENTH, true);
|
||||
|
||||
final ImmutableListMultimap.Builder<BlockRenderLayer, TerrainRenderPass> vanillaRenderStages = ImmutableListMultimap.builder();
|
||||
vanillaRenderStages.put(BlockRenderLayer.SOLID, SOLID_PASS);
|
||||
vanillaRenderStages.put(BlockRenderLayer.CUTOUT, CUTOUT_MIPPED_PASS);
|
||||
vanillaRenderStages.put(BlockRenderLayer.CUTOUT_MIPPED, CUTOUT_MIPPED_PASS);
|
||||
vanillaRenderStages.put(BlockRenderLayer.TRANSLUCENT, TRANSLUCENT_PASS);
|
||||
|
||||
// Material lookup by terrain layer
|
||||
final Map<BlockRenderLayer, Material> renderTypeToMaterialMap = new Reference2ReferenceOpenHashMap<>(4, Reference2ReferenceOpenHashMap.VERY_FAST_LOAD_FACTOR);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.SOLID, SOLID_MATERIAL);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.CUTOUT, CUTOUT_MIPPED_MATERIAL);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.CUTOUT_MIPPED, CUTOUT_MIPPED_MATERIAL);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.TRANSLUCENT, TRANSLUCENT_MATERIAL);
|
||||
|
||||
return new RenderPassConfiguration<>(renderTypeToMaterialMap, vanillaRenderStages.build().asMap(), CUTOUT_MIPPED_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL);
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.CameraTransform;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.lists.SectionTicker;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.AsyncOcclusionMode;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.GenericSectionSpriteTicker;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.embeddedt.embeddium.impl.util.PositionUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.RenderSectionManagerAccessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
public class AngelicaRenderSectionManager extends RenderSectionManager {
|
||||
private boolean initialCameraSectionReady = false;
|
||||
|
||||
private final WorldClient world;
|
||||
private final ClonedChunkSectionCache sectionCache;
|
||||
private final ChunkTaskProvider taskProvider;
|
||||
|
||||
public AngelicaRenderSectionManager(RenderPassConfiguration<?> configuration, WorldClient world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads, ChunkTaskProvider taskProvider) {
|
||||
super(configuration, () -> new AngelicaChunkBuildContext(configuration, world), AngelicaChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads, true /* hasShadowPass = true for Iris */);
|
||||
this.world = world;
|
||||
this.sectionCache = new ClonedChunkSectionCache(world);
|
||||
this.taskProvider = taskProvider;
|
||||
}
|
||||
|
||||
public static AngelicaRenderSectionManager create(ChunkVertexType vertexType, WorldClient world, int renderDistance, CommandList commandList) {
|
||||
final ChunkTaskProvider provider = ChunkTaskRegistry.getActiveProvider();
|
||||
return new AngelicaRenderSectionManager(AngelicaRenderPassConfiguration.build(vertexType), world, renderDistance, commandList, 0, 16, provider.threadCount(), provider);
|
||||
}
|
||||
|
||||
public void setCameraPosition(double x, double y, double z) {
|
||||
this.cameraPosition.set(x, y, z);
|
||||
}
|
||||
|
||||
private boolean isChunkNotLoaded(int chunkX, int chunkZ) {
|
||||
return this.world.getChunkFromChunkCoords(chunkX, chunkZ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSectionAdded(int x, int y, int z) {
|
||||
super.onSectionAdded(x, y, z);
|
||||
|
||||
// If chunk isn't actually loaded (EmptyChunk placeholder), make sections opaque for main pass.
|
||||
// This prevents BFS from traversing through chunks we haven't received from the server.
|
||||
if (isChunkNotLoaded(x, z)) {
|
||||
renderListManager.updateVisibilityData(x, y, z, 0L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Viewport positionedViewport, int frame, boolean spectator) {
|
||||
if (!isInShadowPass() && !initialCameraSectionReady) {
|
||||
var origin = positionedViewport.getChunkCoord();
|
||||
long key = PositionUtil.packSection(origin.x(), origin.y(), origin.z());
|
||||
if (!((RenderSectionManagerAccessor) this).angelica$getSectionByPosition().containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
initialCameraSectionReady = true;
|
||||
}
|
||||
super.update(positionedViewport, frame, spectator);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AsyncOcclusionMode getAsyncOcclusionMode() {
|
||||
return AsyncOcclusionMode.EVERYTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldRespectUpdateTaskQueueSizeLimit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useFogOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDebugInfoShown() {
|
||||
return Minecraft.getMinecraft().gameSettings.showDebugInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldUseOcclusionCulling(Viewport positionedViewport, boolean spectator) {
|
||||
if (!spectator) return true;
|
||||
|
||||
final var camBlockPos = positionedViewport.getBlockCoord();
|
||||
return !this.world.getBlock(camBlockPos.x(), camBlockPos.y(), camBlockPos.z()).isOpaqueCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSectionVisuallyEmpty(int x, int y, int z) {
|
||||
final Chunk chunk = this.world.getChunkFromChunkCoords(x, z);
|
||||
if (chunk.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
final var array = chunk.getBlockStorageArray();
|
||||
if (y < 0 || y >= array.length) {
|
||||
return true;
|
||||
}
|
||||
return array[y] == null || array[y].isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame) {
|
||||
if (isSectionVisuallyEmpty(render.getChunkX(), render.getChunkY(), render.getChunkZ())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.taskProvider.createRebuildTask(render, frame, this.cameraPosition, this.sectionCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invalidateCachedSectionData(RenderSection section) {
|
||||
super.invalidateCachedSectionData(section);
|
||||
this.sectionCache.invalidate(section.getChunkX(), section.getChunkY(), section.getChunkZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChunks(boolean updateImmediately) {
|
||||
this.sectionCache.cleanup();
|
||||
super.updateChunks(updateImmediately);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean allowImportantRebuilds() {
|
||||
return !SodiumClientMod.options().performance.alwaysDeferChunkUpdates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable SectionTicker createSectionTicker() {
|
||||
return new GenericSectionSpriteTicker<>(AngelicaRenderSectionManager::markSpriteActive);
|
||||
}
|
||||
|
||||
private static void markSpriteActive(TextureAtlasSprite sprite) {
|
||||
((SpriteExtension) sprite).celeritas$markActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInShadowPass() {
|
||||
return IrisShaderProviderHolder.isShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getDebugStrings() {
|
||||
List<String> list = new ArrayList<>(super.getDebugStrings());
|
||||
|
||||
// Add thread info
|
||||
var builder = getBuilder();
|
||||
int busyThreads = builder.getBusyThreadCount();
|
||||
int totalThreads = builder.getTotalThreadCount();
|
||||
|
||||
if (totalThreads > 0) {
|
||||
list.add(String.format("Chunk Workers: %d/%d busy", busyThreads, totalThreads));
|
||||
} else {
|
||||
list.add("Chunk Workers: single-threaded");
|
||||
}
|
||||
|
||||
// Main thread queue metrics
|
||||
final int queueDepth = AngelicaRenderQueue.getQueueDepth();
|
||||
final int tasksRan = AngelicaRenderQueue.getLastFrameTasksRan();
|
||||
final double mtTimeMs = AngelicaRenderQueue.getLastFrameTimeNs() / 1_000_000.0;
|
||||
list.add(String.format("MT Queue: %d, ran %d (%.1fms)", queueDepth, tasksRan, mtTimeMs));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderLayer(ChunkRenderMatrices matrices, TerrainRenderPass pass, CameraTransform occlusionCamera, CameraTransform camera) {
|
||||
// Shadow pass graph update is async - must wait for it to complete before rendering
|
||||
if (IrisShaderProviderHolder.isShadowPass()) {
|
||||
finishAllGraphUpdates();
|
||||
}
|
||||
super.renderLayer(matrices, pass, occlusionCamera, camera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process both asyncSubmittedTasks and AngelicaRenderQueue.TASKS.
|
||||
*/
|
||||
@Override
|
||||
public void managedBlock(BooleanSupplier isDone) {
|
||||
final RenderSectionManagerAccessor accessor = (RenderSectionManagerAccessor) this;
|
||||
while (!isDone.getAsBoolean()) {
|
||||
Runnable task = accessor.angelica$getAsyncSubmittedTasks().poll();
|
||||
if (task != null) {
|
||||
task.run();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AngelicaRenderQueue.processTasks(1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LockSupport.parkNanos("Wait", 100000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
public enum BlockRenderLayer {
|
||||
SOLID, // pass 0, no alpha test
|
||||
CUTOUT, // pass 0, alpha test (not mipped)
|
||||
CUTOUT_MIPPED, // pass 0, alpha test (mipped)
|
||||
TRANSLUCENT; // pass 1
|
||||
|
||||
public int toVanillaPass() {
|
||||
return this == TRANSLUCENT ? 1 : 0;
|
||||
}
|
||||
|
||||
public static BlockRenderLayer fromVanillaPass(int pass) {
|
||||
// CUTOUT_MIPPED is the safe default for pass 0
|
||||
// SOLID/CUTOUT are only used for explicit shader pack and material overrides
|
||||
return pass == 0 ? CUTOUT_MIPPED : TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class CeleritasDebug {
|
||||
private static final AtomicInteger chunkUpdateCounter = new AtomicInteger(0);
|
||||
|
||||
public static void incrementChunkUpdateCounter() {
|
||||
chunkUpdateCounter.getAndIncrement();
|
||||
}
|
||||
|
||||
public static int readAndResetChunkUpdateCounter() {
|
||||
return chunkUpdateCounter.getAndSet(0);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.states.FogState;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class CeleritasDebugScreenHandler {
|
||||
public static final CeleritasDebugScreenHandler INSTANCE = new CeleritasDebugScreenHandler();
|
||||
|
||||
/** Toggle for fog debug display on F3 screen */
|
||||
public static boolean showFogDebug = false;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if (!mc.gameSettings.showDebugInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CeleritasWorldRenderer renderer = CeleritasWorldRenderer.getInstance();
|
||||
if (renderer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fog debug on left side (when enabled)
|
||||
if (showFogDebug) {
|
||||
event.left.add(getFogDebugString());
|
||||
}
|
||||
|
||||
if (DynamicLights.configEnabled && DynamicLights.isEnabled()) {
|
||||
event.left.add(getDynamicLightsDebugString());
|
||||
}
|
||||
|
||||
event.right.add("");
|
||||
event.right.add(EnumChatFormatting.GREEN + "Angelica " + Tags.VERSION + " [Celeritas Renderer]");
|
||||
event.right.addAll(renderer.getDebugStrings());
|
||||
event.right.add("");
|
||||
}
|
||||
|
||||
public static String getFogDebugString() {
|
||||
final boolean enabled = GLStateManager.getFogMode().isEnabled();
|
||||
final FogState fog = GLStateManager.getFogState();
|
||||
final String modeName = switch (fog.getFogMode()) {
|
||||
case GL11.GL_LINEAR -> "LINEAR";
|
||||
case GL11.GL_EXP -> "EXP";
|
||||
case GL11.GL_EXP2 -> "EXP2";
|
||||
default -> "?";
|
||||
};
|
||||
return String.format("Fog: %s %s %.0f-%.0f d=%.2f (%.2f, %.2f, %.2f)",
|
||||
enabled ? "ON" : "OFF",
|
||||
modeName,
|
||||
fog.getStart(),
|
||||
fog.getEnd(),
|
||||
fog.getDensity(),
|
||||
fog.getFogColor().x,
|
||||
fog.getFogColor().y,
|
||||
fog.getFogColor().z);
|
||||
}
|
||||
|
||||
public static String getDynamicLightsDebugString() {
|
||||
final DynamicLights dl = DynamicLights.get();
|
||||
int sources = dl.getLightSourcesCount();
|
||||
int updated = dl.getLastUpdateCount();
|
||||
|
||||
if (DynamicLights.FrustumCullingEnabled) {
|
||||
int pending = dl.getChunkRebuildManager().getPendingCount();
|
||||
return String.format("DynLights: %d src, %d upd, %d pending", sources, updated, pending);
|
||||
}
|
||||
return String.format("DynLights: %d sources, %d updated", sources, updated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import org.embeddedt.embeddium.impl.gl.device.GLRenderDevice;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import static com.gtnewhorizons.angelica.loading.AngelicaTweaker.LOGGER;
|
||||
|
||||
public class CeleritasSetup {
|
||||
private static boolean initialized = false;
|
||||
|
||||
public static void ensureInitialized() {
|
||||
if (!initialized && AngelicaConfig.enableCeleritas) {
|
||||
GLRenderDevice.VANILLA_STATE_RESETTER = () -> GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
LOGGER.debug("Celeritas init");
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightWorldRenderer;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.rendering.RenderingState;
|
||||
import net.coderbot.iris.pipeline.ShadowRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkMeshFormats;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import org.embeddedt.embeddium.impl.render.terrain.SimpleWorldRenderer;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CeleritasWorldRenderer extends SimpleWorldRenderer<WorldClient, AngelicaRenderSectionManager, BlockRenderLayer, TileEntity, CeleritasWorldRenderer.TileEntityRenderContext> implements IDynamicLightWorldRenderer {
|
||||
private static final Logger LOGGER = LogManager.getLogger("Angelica");
|
||||
private final Minecraft mc;
|
||||
private static CeleritasWorldRenderer instance;
|
||||
|
||||
/** Debug flag for wireframe rendering mode. Toggle via /angelica wireframe */
|
||||
public static boolean DEBUG_WIREFRAME_MODE = false;
|
||||
|
||||
private final TileEntityRenderContext teRenderContext = new TileEntityRenderContext();
|
||||
private boolean useEntityCulling = true;
|
||||
|
||||
// the volume of a section multiplied by the number of sections to be checked at most
|
||||
private static final double MAX_ENTITY_CHECK_VOLUME = 16 * 16 * 16 * 15;
|
||||
|
||||
private CeleritasWorldRenderer(Minecraft mc) {
|
||||
// Private constructor for singleton
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
public static CeleritasWorldRenderer create(Minecraft mc) {
|
||||
instance = new CeleritasWorldRenderer(mc);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static CeleritasWorldRenderer getInstance() {
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("CeleritasWorldRenderer not initialized");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public AngelicaRenderSectionManager getRenderSectionManager() {
|
||||
return this.renderSectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return this.world != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadWorld(WorldClient world) {
|
||||
super.loadWorld(world);
|
||||
DynamicLights.setActiveRenderer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unloadWorld() {
|
||||
DynamicLights.setActiveRenderer(null);
|
||||
super.unloadWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectiveRenderDistance() {
|
||||
return mc.gameSettings.renderDistanceChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumBuildHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumBuildHeight() {
|
||||
return 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkRenderMatrices createChunkRenderMatrices() {
|
||||
final boolean shadowPass = renderSectionManager.isInShadowPass();
|
||||
final Matrix4f projection = shadowPass ? ShadowRenderer.PROJECTION : RenderingState.INSTANCE.getProjectionMatrix();
|
||||
final Matrix4f modelView = shadowPass ? ShadowRenderer.MODELVIEW : RenderingState.INSTANCE.getModelViewMatrix();
|
||||
return new ChunkRenderMatrices(projection, modelView);
|
||||
}
|
||||
|
||||
private ChunkVertexType chooseVertexType() {
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
if (provider != null && provider.isShadersEnabled()) {
|
||||
final ChunkVertexType extended = provider.getVertexType(ChunkMeshFormats.VANILLA_LIKE);
|
||||
if (extended != ChunkMeshFormats.VANILLA_LIKE) {
|
||||
return extended;
|
||||
}
|
||||
}
|
||||
|
||||
if (SodiumClientMod.options().advanced.useCompactVertexFormat) {
|
||||
return ChunkMeshFormats.COMPACT;
|
||||
}
|
||||
return ChunkMeshFormats.VANILLA_LIKE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AngelicaRenderSectionManager createRenderSectionManager(CommandList commandList) {
|
||||
return AngelicaRenderSectionManager.create(chooseVertexType(), this.world, this.renderDistance, commandList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBlockEntityList(List<TileEntity> list, TileEntityRenderContext context) {
|
||||
for (TileEntity tileEntity : list) {
|
||||
renderTE(tileEntity, context.pass, context.partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTerrain(Viewport viewport, CameraState cameraState, int frame, boolean spectator, boolean updateChunksImmediately) {
|
||||
var transform = viewport.getTransform();
|
||||
|
||||
if (transform.x == 0 && transform.y == 0 && transform.z == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderSectionManager.setCameraPosition(transform.x, transform.y, transform.z);
|
||||
|
||||
this.useEntityCulling = true;
|
||||
|
||||
super.setupTerrain(viewport, cameraState, frame, spectator, updateChunksImmediately);
|
||||
|
||||
// Process deferred dynamic light chunk rebuilds with frustum culling
|
||||
if (DynamicLights.isEnabled() && DynamicLights.FrustumCullingEnabled) {
|
||||
DynamicLights.get().processChunkRebuilds(viewport);
|
||||
}
|
||||
|
||||
// Collect tile entities for shadow pass rendering
|
||||
if (renderSectionManager.isInShadowPass() && IrisShaderProviderHolder.isActive()) {
|
||||
collectTileEntitiesForShadow();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentViewport(Viewport viewport) {
|
||||
this.currentViewport = viewport;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void collectTileEntitiesForShadow() {
|
||||
final SortedRenderLists renderLists = renderSectionManager.getRenderLists();
|
||||
final Iterator<ChunkRenderList> renderListIterator = renderLists.iterator();
|
||||
|
||||
while (renderListIterator.hasNext()) {
|
||||
final var renderList = renderListIterator.next();
|
||||
final var renderRegion = renderList.getRegion();
|
||||
final var renderSectionIterator = renderList.sectionsWithEntitiesIterator();
|
||||
|
||||
if (renderSectionIterator == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (renderSectionIterator.hasNext()) {
|
||||
final var renderSectionId = renderSectionIterator.nextByteAsInt();
|
||||
final var renderSection = renderRegion.getSection(renderSectionId);
|
||||
|
||||
if (renderSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var context = renderSection.getBuiltContext();
|
||||
if (context instanceof MinecraftBuiltRenderSectionData<?, ?> mcData) {
|
||||
final var culledEntities = (List<TileEntity>) mcData.culledBlockEntities;
|
||||
ShadowRenderer.visibleTileEntities.addAll(culledEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var renderSection : renderSectionManager.getSectionsWithGlobalEntities()) {
|
||||
final var context = renderSection.getBuiltContext();
|
||||
if (context instanceof MinecraftBuiltRenderSectionData<?, ?> mcData) {
|
||||
final var globalEntities = (List<TileEntity>) mcData.globalBlockEntities;
|
||||
ShadowRenderer.globalTileEntities.addAll(globalEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawChunkLayer(BlockRenderLayer renderLayer, double x, double y, double z) {
|
||||
if (DEBUG_WIREFRAME_MODE) {
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
}
|
||||
|
||||
super.drawChunkLayer(renderLayer, x, y, z);
|
||||
|
||||
if (DEBUG_WIREFRAME_MODE) {
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
}
|
||||
|
||||
GLStateManager.glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public int renderBlockEntities(float partialTicks) {
|
||||
final int pass = MinecraftForgeClient.getRenderPass();
|
||||
return super.renderBlockEntities(teRenderContext.set(partialTicks, pass));
|
||||
}
|
||||
|
||||
private void renderTE(TileEntity tileEntity, int pass, float partialTicks) {
|
||||
if (!tileEntity.shouldRenderInPass(pass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final AxisAlignedBB aabb = tileEntity.getRenderBoundingBox();
|
||||
|
||||
if (aabb != TileEntity.INFINITE_EXTENT_AABB && !this.currentViewport.isBoxVisible(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
TileEntityRendererDispatcher.instance.renderTileEntity(tileEntity, partialTicks);
|
||||
} catch (RuntimeException e) {
|
||||
if (tileEntity.isInvalid()) {
|
||||
LOGGER.warn("Suppressed exception rendering invalid TileEntity {} at ({}, {}, {})", tileEntity.getClass().getName(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInfiniteExtentsBox(AxisAlignedBB box) {
|
||||
return box == null || Double.isInfinite(box.minX) || Double.isInfinite(box.minY) || Double.isInfinite(box.minZ)
|
||||
|| Double.isInfinite(box.maxX) || Double.isInfinite(box.maxY) || Double.isInfinite(box.maxZ);
|
||||
}
|
||||
|
||||
public boolean isEntityVisible(Entity entity) {
|
||||
// During shadow pass, don't cull entities - shadow rendering uses different frustum
|
||||
if (!this.useEntityCulling || this.renderSectionManager.isInShadowPass()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AxisAlignedBB box = entity.getBoundingBox();
|
||||
if (box == null) {
|
||||
box = entity.boundingBox;
|
||||
}
|
||||
|
||||
if (isInfiniteExtentsBox(box)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// bail on very large entities to avoid checking many sections
|
||||
final double entityVolume = (box.maxX - box.minX) * (box.maxY - box.minY) * (box.maxZ - box.minZ);
|
||||
if (entityVolume > MAX_ENTITY_CHECK_VOLUME) {
|
||||
// TODO: do a frustum check instead, even large entities aren't visible if they're outside the frustum
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.isBoxVisible(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
|
||||
}
|
||||
|
||||
public static class TileEntityRenderContext {
|
||||
public float partialTicks;
|
||||
public int pass;
|
||||
|
||||
public TileEntityRenderContext set(float partialTicks, int pass) {
|
||||
this.partialTicks = partialTicks;
|
||||
this.pass = pass;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import org.embeddedt.embeddium.impl.biome.BiomeColorCache;
|
||||
|
||||
public class SmoothBiomeColorCache extends BiomeColorCache<BiomeGenBase, SmoothBiomeColorCache.ColorType> {
|
||||
private static final ThreadLocal<SmoothBiomeColorCache> activeCache = new ThreadLocal<>();
|
||||
|
||||
public static void setActiveCache(SmoothBiomeColorCache cache) {
|
||||
activeCache.set(cache);
|
||||
}
|
||||
|
||||
public static void clearActiveCache() {
|
||||
activeCache.remove();
|
||||
}
|
||||
|
||||
public static SmoothBiomeColorCache getActiveCache() {
|
||||
return activeCache.get();
|
||||
}
|
||||
|
||||
public SmoothBiomeColorCache(IBlockAccess blockAccess) {
|
||||
super((x, y, z) -> blockAccess.getBiomeGenForCoords(x, z), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int resolveColor(ColorType type, BiomeGenBase biome, int relativeX, int relativeY, int relativeZ) {
|
||||
return switch (type) {
|
||||
case GRASS -> biome.getBiomeGrassColor(relativeX, relativeY, relativeZ);
|
||||
case FOLIAGE -> biome.getBiomeFoliageColor(relativeX, relativeY, relativeZ);
|
||||
case WATER -> biome.getWaterColorMultiplier();
|
||||
};
|
||||
}
|
||||
|
||||
public enum ColorType {
|
||||
GRASS,
|
||||
FOLIAGE,
|
||||
WATER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevel;
|
||||
|
||||
public interface SpriteExtension {
|
||||
SpriteTransparencyLevel celeritas$getTransparencyLevel();
|
||||
|
||||
/** Marks sprite as active for animation. */
|
||||
void celeritas$markActive();
|
||||
|
||||
/** One-shot: returns true if marked, then resets. */
|
||||
boolean celeritas$shouldUpdate();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
public interface TextureMapExtension {
|
||||
TextureAtlasSprite celeritas$findFromUV(float u, float v);
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import org.embeddedt.embeddium.api.util.NormI8;
|
||||
import org.embeddedt.embeddium.impl.model.quad.ModelQuadView;
|
||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFlags;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.util.QuadUtil;
|
||||
|
||||
public class VertexArrayQuadView implements ModelQuadView {
|
||||
private final ChunkVertexEncoder.Vertex[] vertices;
|
||||
private int trueNormal;
|
||||
private int blockX, blockY, blockZ;
|
||||
private ModelQuadFacing lightFace;
|
||||
private int flags;
|
||||
|
||||
public VertexArrayQuadView(ChunkVertexEncoder.Vertex[] vertices) {
|
||||
this.vertices = vertices;
|
||||
}
|
||||
|
||||
public void setup(int trueNormal, int blockX, int blockY, int blockZ) {
|
||||
this.trueNormal = trueNormal;
|
||||
this.blockX = blockX;
|
||||
this.blockY = blockY;
|
||||
this.blockZ = blockZ;
|
||||
this.lightFace = null; // Reset cached lightFace
|
||||
this.flags = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getX(int idx) {
|
||||
return vertices[idx].x - blockX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getY(int idx) {
|
||||
return vertices[idx].y - blockY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZ(int idx) {
|
||||
return vertices[idx].z - blockZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int idx) {
|
||||
return vertices[idx].color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexU(int idx) {
|
||||
return vertices[idx].u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexV(int idx) {
|
||||
return vertices[idx].v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int idx) {
|
||||
return vertices[idx].light;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlags() {
|
||||
if (flags == 0) {
|
||||
flags = ModelQuadFlags.getQuadFlags(this, getLightFace());
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object celeritas$getSprite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelQuadFacing getLightFace() {
|
||||
if (lightFace == null) {
|
||||
lightFace = computeLightFace(trueNormal);
|
||||
}
|
||||
return lightFace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelQuadFacing getNormalFace() {
|
||||
return QuadUtil.findNormalFace(trueNormal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getForgeNormal(int idx) {
|
||||
return vertices[idx].vanillaNormal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComputedFaceNormal() {
|
||||
return trueNormal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cull face of a quad. This is distinct from the light face, as it will not be set for non-axis-aligned
|
||||
* and non-block-grid-aligned quads (i.e. quads on the surface of the 1x1x1 cube).
|
||||
* @return the cull face if present, or UNASSIGNED
|
||||
*/
|
||||
public ModelQuadFacing getCullFace() {
|
||||
// In modern, only quads that are aligned to the block grid can have a cull face, as otherwise
|
||||
// they should not participate in face culling (an adjacent block wouldn't obscure an inset quad)
|
||||
if ((getFlags() & ModelQuadFlags.IS_ALIGNED) == 0) {
|
||||
return ModelQuadFacing.UNASSIGNED;
|
||||
}
|
||||
|
||||
return getNormalFace();
|
||||
}
|
||||
|
||||
private static ModelQuadFacing computeLightFace(int normal) {
|
||||
final float nx = NormI8.unpackX(normal);
|
||||
final float ny = NormI8.unpackY(normal);
|
||||
final float nz = NormI8.unpackZ(normal);
|
||||
|
||||
final float absX = Math.abs(nx);
|
||||
final float absY = Math.abs(ny);
|
||||
final float absZ = Math.abs(nz);
|
||||
|
||||
if (absY >= absX && absY >= absZ) {
|
||||
return ny >= 0 ? ModelQuadFacing.POS_Y : ModelQuadFacing.NEG_Y;
|
||||
} else if (absX >= absZ) {
|
||||
return nx >= 0 ? ModelQuadFacing.POS_X : ModelQuadFacing.NEG_X;
|
||||
} else {
|
||||
return nz >= 0 ? ModelQuadFacing.POS_Z : ModelQuadFacing.NEG_Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
public interface WorldClientExtension {
|
||||
SmoothBiomeColorCache celeritas$getSmoothBiomeColorCache();
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.api;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.BlockRenderLayer;
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IrisShaderProvider {
|
||||
|
||||
boolean isShadersEnabled();
|
||||
|
||||
boolean isShadowPass();
|
||||
|
||||
boolean shouldUseFaceCulling();
|
||||
|
||||
@Nullable GlProgram<? extends ChunkShaderInterface> getShaderOverride(TerrainRenderPass pass);
|
||||
|
||||
ChunkVertexType getVertexType(ChunkVertexType defaultType);
|
||||
|
||||
void setRenderPassConfiguration(RenderPassConfiguration<?> configuration);
|
||||
|
||||
/** Block render layer overrides from shader pack */
|
||||
@Nullable Map<Block, BlockRenderLayer> getBlockTypeIds();
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.api;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class IrisShaderProviderHolder {
|
||||
|
||||
private static IrisShaderProvider provider;
|
||||
|
||||
private IrisShaderProviderHolder() {}
|
||||
|
||||
public static void setProvider(@Nullable IrisShaderProvider provider) {
|
||||
IrisShaderProviderHolder.provider = provider;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IrisShaderProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return provider != null && provider.isShadersEnabled();
|
||||
}
|
||||
|
||||
public static boolean isShadowPass() {
|
||||
return provider != null && provider.isShadowPass();
|
||||
}
|
||||
|
||||
public static boolean shouldUseFaceCulling() {
|
||||
return provider == null || provider.shouldUseFaceCulling();
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
public class BlockRenderContext {
|
||||
public int localPosX, localPosY, localPosZ;
|
||||
public short blockId = -1;
|
||||
public short renderType = -1;
|
||||
public byte lightValue;
|
||||
|
||||
public void set(int localX, int localY, int localZ, short blockId, short renderType, byte lightValue) {
|
||||
this.localPosX = localX;
|
||||
this.localPosY = localY;
|
||||
this.localPosZ = localZ;
|
||||
this.blockId = blockId;
|
||||
this.renderType = renderType;
|
||||
this.lightValue = lightValue;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
blockId = -1;
|
||||
renderType = -1;
|
||||
lightValue = 0;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*;
|
||||
|
||||
import net.coderbot.iris.vertices.IrisQuadView;
|
||||
|
||||
public class CeleritasQuadView implements IrisQuadView {
|
||||
private long writePointer;
|
||||
private int stride;
|
||||
|
||||
public void setup(long ptr, int stride) {
|
||||
this.writePointer = ptr;
|
||||
this.stride = stride;
|
||||
}
|
||||
|
||||
// VANILLA_LIKE format offsets:
|
||||
// Position: floats at 0, 4, 8
|
||||
// Color: int at 12
|
||||
// TexCoord: floats at 16, 20
|
||||
// LightCoord: int at 24
|
||||
|
||||
@Override
|
||||
public float x(int index) {
|
||||
return memGetFloat(writePointer - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float y(int index) {
|
||||
return memGetFloat(writePointer + 4 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float z(int index) {
|
||||
return memGetFloat(writePointer + 8 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float u(int index) {
|
||||
return memGetFloat(writePointer + 16 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float v(int index) {
|
||||
return memGetFloat(writePointer + 20 - stride * (3L - index));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
|
||||
public interface ContextAwareChunkVertexEncoder extends ChunkVertexEncoder {
|
||||
|
||||
void prepareToRenderBlock(BlockRenderContext ctx, Block block, int metadata, short renderType, byte lightValue);
|
||||
|
||||
void prepareToRenderFluid(BlockRenderContext ctx, Block block, byte lightValue);
|
||||
|
||||
void finishRenderingBlock();
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*;
|
||||
import static com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType.STRIDE;
|
||||
import static com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType.encodeMidTexture;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import lombok.Setter;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.vertices.ExtendedDataHelper;
|
||||
import net.coderbot.iris.vertices.NormalHelper;
|
||||
import net.coderbot.iris.vertices.NormI8;
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
* Writes Iris-extended vertices. Delegates base 28 bytes to VANILLA_LIKE encoder.
|
||||
*/
|
||||
public class IrisExtendedChunkVertexEncoder implements ContextAwareChunkVertexEncoder {
|
||||
// Offsets derived from format definition
|
||||
private static final int MID_TEX_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("mc_midTexCoord").getPointer();
|
||||
private static final int TANGENT_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("at_tangent").getPointer();
|
||||
private static final int NORMAL_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("iris_Normal").getPointer();
|
||||
private static final int MC_ENTITY_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("mc_Entity").getPointer();
|
||||
private static final int MID_BLOCK_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("at_midBlock").getPointer();
|
||||
|
||||
private final ChunkVertexEncoder baseEncoder = IrisExtendedChunkVertexType.BASE_TYPE.createEncoder();
|
||||
private final CeleritasQuadView quad = new CeleritasQuadView();
|
||||
private final Vector3f normal = new Vector3f();
|
||||
private final Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches;
|
||||
|
||||
public IrisExtendedChunkVertexEncoder() {
|
||||
this.blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
}
|
||||
|
||||
// Per-quad accumulators
|
||||
private int vertexCount;
|
||||
private float uSum;
|
||||
private float vSum;
|
||||
|
||||
@Setter
|
||||
private BlockRenderContext context;
|
||||
|
||||
@Override
|
||||
public void prepareToRenderBlock(BlockRenderContext ctx, Block block, int metadata, short renderType, byte lightValue) {
|
||||
this.context = ctx;
|
||||
Int2IntMap metaMap = blockMetaMatches != null ? blockMetaMatches.get(block) : null;
|
||||
ctx.blockId = (short) (metaMap != null ? metaMap.get(metadata) : -1);
|
||||
ctx.renderType = renderType;
|
||||
ctx.lightValue = lightValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareToRenderFluid(BlockRenderContext ctx, Block block, byte lightValue) {
|
||||
this.context = ctx;
|
||||
Int2IntMap metaMap = blockMetaMatches != null ? blockMetaMatches.get(block) : null;
|
||||
ctx.blockId = (short) (metaMap != null ? metaMap.get(0) : -1);
|
||||
ctx.renderType = ExtendedDataHelper.FLUID_RENDER_TYPE;
|
||||
ctx.lightValue = lightValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRenderingBlock() {
|
||||
if (context != null) {
|
||||
context.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long write(long ptr, Material material, Vertex vertex, int sectionIndex) {
|
||||
uSum += vertex.u;
|
||||
vSum += vertex.v;
|
||||
vertexCount++;
|
||||
|
||||
final BlockRenderContext ctx = context;
|
||||
|
||||
baseEncoder.write(ptr, material, vertex, sectionIndex);
|
||||
|
||||
// Per-vertex: renderType, midBlock, lightValue
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET + 2, ctx.renderType);
|
||||
final int midBlock = ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, ctx.localPosX, ctx.localPosY, ctx.localPosZ);
|
||||
memPutInt(ptr + MID_BLOCK_OFFSET, midBlock);
|
||||
memPutByte(ptr + MID_BLOCK_OFFSET + 3, ctx.lightValue);
|
||||
|
||||
// Per-quad: midTexCoord, blockId, normal, tangent
|
||||
if (vertexCount == 4) {
|
||||
vertexCount = 0;
|
||||
|
||||
final float midU = uSum * 0.25f;
|
||||
final float midV = vSum * 0.25f;
|
||||
final int midUV = encodeMidTexture(midU, midV);
|
||||
|
||||
memPutInt(ptr + MID_TEX_OFFSET, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE * 2, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE * 3, midUV);
|
||||
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE * 2, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE * 3, ctx.blockId);
|
||||
|
||||
quad.setup(ptr, STRIDE);
|
||||
NormalHelper.computeFaceNormal(normal, quad);
|
||||
final int packedNormal = NormI8.pack(normal);
|
||||
|
||||
memPutInt(ptr + NORMAL_OFFSET, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE * 2, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE * 3, packedNormal);
|
||||
|
||||
final int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, quad);
|
||||
|
||||
memPutInt(ptr + TANGENT_OFFSET, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE * 2, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE * 3, tangent);
|
||||
|
||||
uSum = 0;
|
||||
vSum = 0;
|
||||
}
|
||||
|
||||
return ptr + STRIDE;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import org.embeddedt.embeddium.impl.gl.attribute.GlVertexAttributeFormat;
|
||||
import org.embeddedt.embeddium.impl.gl.attribute.GlVertexFormat;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkMeshFormats;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
|
||||
/**
|
||||
* VANILLA_LIKE (28 bytes) + Iris extensions (20 bytes) = 48 bytes total.
|
||||
*
|
||||
* Iris extensions:
|
||||
* mc_midTexCoord ushort[2] - quad center UV (average of 4 vertices)
|
||||
* at_tangent byte[4] - tangent vector, normalized
|
||||
* iris_Normal byte[3]+1 - face normal, normalized
|
||||
* mc_Entity short[2] - (blockId, renderType)
|
||||
* at_midBlock byte[4] - (xyz offset from block center, lightValue)
|
||||
*/
|
||||
public class IrisExtendedChunkVertexType implements ChunkVertexType {
|
||||
public static final ChunkVertexType BASE_TYPE = ChunkMeshFormats.VANILLA_LIKE;
|
||||
public static final int STRIDE = 48;
|
||||
|
||||
public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(STRIDE)
|
||||
.addAllElements(BASE_TYPE.getVertexFormat())
|
||||
.addElement("mc_midTexCoord", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false)
|
||||
.addElement("at_tangent", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 4, true, false)
|
||||
.addElement("iris_Normal", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 3, true, false)
|
||||
.addElement("mc_Entity", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.SHORT, 2, false, false)
|
||||
.addElement("at_midBlock", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 4, false, false)
|
||||
.build();
|
||||
|
||||
private static final int TEXTURE_MAX_VALUE = 32768;
|
||||
public static final float MID_TEX_SCALE = 1.0f / TEXTURE_MAX_VALUE;
|
||||
|
||||
/** Pack UV as two unsigned shorts: low=u, high=v. */
|
||||
public static int encodeMidTexture(float u, float v) {
|
||||
return ((Math.round(u * TEXTURE_MAX_VALUE) & 0xFFFF)) |
|
||||
((Math.round(v * TEXTURE_MAX_VALUE) & 0xFFFF) << 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkVertexEncoder createEncoder() {
|
||||
return new IrisExtendedChunkVertexEncoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionScale() {
|
||||
return BASE_TYPE.getPositionScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionOffset() {
|
||||
return BASE_TYPE.getPositionOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextureScale() {
|
||||
return BASE_TYPE.getTextureScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlVertexFormat getVertexFormat() {
|
||||
return VERTEX_FORMAT;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.light;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public enum EmptyBlockAccess implements IBlockAccess {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
return Blocks.air;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int min) {
|
||||
return min << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isBlockProvidingPowerTo(int x, int y, int z, int direction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAirBlock(int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
|
||||
return BiomeGenBase.plains;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean extendedLevelsInChunkCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.light;
|
||||
|
||||
import lombok.Setter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.model.light.data.LightDataAccess;
|
||||
|
||||
@Setter
|
||||
public class LightDataCache extends LightDataAccess {
|
||||
private IBlockAccess world;
|
||||
|
||||
@Override
|
||||
protected int compute(int x, int y, int z) {
|
||||
final IBlockAccess world = this.world;
|
||||
final Block block = world.getBlock(x, y, z);
|
||||
|
||||
final boolean fo = block.isOpaqueCube();
|
||||
final boolean fc = block.isNormalCube();
|
||||
final int lu = block.getLightValue(world, x, y, z);
|
||||
|
||||
// Optimize: skip light calculation for opaque blocks with no luminance
|
||||
final int bl, sl;
|
||||
if (fo && lu == 0) {
|
||||
bl = 0;
|
||||
sl = 0;
|
||||
} else {
|
||||
final int packed = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
|
||||
bl = (packed >> 4) & 0xF;
|
||||
sl = (packed >> 20) & 0xF;
|
||||
}
|
||||
|
||||
// AO value - blocks that emit light don't contribute to AO
|
||||
final float ao = lu == 0 ? block.getAmbientOcclusionLightValue() : 1.0f;
|
||||
|
||||
// Opacity check - true if block is view-blocking (solid blocks)
|
||||
final boolean op = block.getMaterial().isOpaque() && block.getLightOpacity() > 0;
|
||||
|
||||
return packFC(fc) | packFO(fo) | packOP(op) | packAO(ao) | packLU(lu) | packSL(sl) | packBL(bl);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.light;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
|
||||
public final class QuadLightingHelper {
|
||||
private QuadLightingHelper() {}
|
||||
|
||||
// Known emissive brightness values set by mods/vanilla
|
||||
public static final int FULL_BRIGHT_15 = (15 << 20) | (15 << 4); // 15728880
|
||||
public static final int FULL_BRIGHT_14 = (14 << 20) | (14 << 4); // 14680288
|
||||
|
||||
public static boolean isBlockEmissive(IBlockAccess world, int x, int y, int z) {
|
||||
final Block block = world.getBlock(x, y, z);
|
||||
try {
|
||||
return block.getMixedBrightnessForBlock(EmptyBlockAccess.INSTANCE, x, y, z) == FULL_BRIGHT_15;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isQuadFullBright(ChunkVertexEncoder.Vertex[] vertices) {
|
||||
final int first = vertices[0].light;
|
||||
|
||||
// Must be a known emissive brightness value
|
||||
if (first != FULL_BRIGHT_15 && first != FULL_BRIGHT_14) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// All 4 vertices must have the same value
|
||||
for (int i = 1; i < 4; i++) {
|
||||
if (vertices[i].light != first) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.light;
|
||||
|
||||
import org.embeddedt.embeddium.api.util.ColorABGR;
|
||||
import org.embeddedt.embeddium.impl.model.light.DiffuseProvider;
|
||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
||||
|
||||
public enum VanillaDiffuseProvider implements DiffuseProvider {
|
||||
INSTANCE;
|
||||
|
||||
private static final float DOWN = 0.5f; // NEG_Y
|
||||
private static final float UP = 1.0f; // POS_Y
|
||||
private static final float NORTH_SOUTH = 0.8f; // NEG_Z, POS_Z
|
||||
private static final float EAST_WEST = 0.6f; // NEG_X, POS_X
|
||||
|
||||
// Inverse values for stripping vanilla's baked diffuse (when oldLighting=false)
|
||||
private static final float INV_DOWN = 1.0f / DOWN; // 2.0
|
||||
private static final float INV_UP = 1.0f / UP; // 1.0
|
||||
private static final float INV_NORTH_SOUTH = 1.0f / NORTH_SOUTH; // 1.25
|
||||
private static final float INV_EAST_WEST = 1.0f / EAST_WEST; // ~1.667
|
||||
|
||||
@Override
|
||||
public float getDiffuse(float normalX, float normalY, float normalZ, boolean shade) {
|
||||
if (!shade) return 1.0f;
|
||||
return Math.min(normalX * normalX * EAST_WEST + normalY * normalY * (normalY >= 0 ? UP : DOWN) + normalZ * normalZ * NORTH_SOUTH, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiffuse(ModelQuadFacing lightFace, boolean shade) {
|
||||
if (!shade) return 1.0f;
|
||||
return switch (lightFace) {
|
||||
case NEG_Y -> DOWN;
|
||||
case POS_Y -> UP;
|
||||
case NEG_Z, POS_Z -> NORTH_SOUTH;
|
||||
case NEG_X, POS_X -> EAST_WEST;
|
||||
case UNASSIGNED -> 1.0f;
|
||||
};
|
||||
}
|
||||
|
||||
public float getInverseDiffuse(ModelQuadFacing lightFace) {
|
||||
return switch (lightFace) {
|
||||
case NEG_Y -> INV_DOWN;
|
||||
case POS_Y -> INV_UP;
|
||||
case NEG_Z, POS_Z -> INV_NORTH_SOUTH;
|
||||
case NEG_X, POS_X -> INV_EAST_WEST;
|
||||
case UNASSIGNED -> 1.0f;
|
||||
};
|
||||
}
|
||||
|
||||
public static int multiplyColor(int color, float factor) {
|
||||
if (factor == 1.0f) {
|
||||
return color;
|
||||
}
|
||||
int r = Math.min(255, (int)(ColorABGR.unpackRed(color) * factor));
|
||||
int g = Math.min(255, (int)(ColorABGR.unpackGreen(color) * factor));
|
||||
int b = Math.min(255, (int)(ColorABGR.unpackBlue(color) * factor));
|
||||
int a = ColorABGR.unpackAlpha(color);
|
||||
return ColorABGR.pack(r, g, b, a);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public interface ChunkTaskProvider {
|
||||
ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition);
|
||||
|
||||
default ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition, ClonedChunkSectionCache sectionCache) {
|
||||
return createRebuildTask(render, frame, cameraPosition);
|
||||
}
|
||||
|
||||
/** @return -1 = single-threaded, 0 = auto-detect, >0 = specific count */
|
||||
int threadCount();
|
||||
|
||||
/** Lower = higher priority */
|
||||
int priority();
|
||||
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public final class ChunkTaskRegistry {
|
||||
private static final Logger LOGGER = LogManager.getLogger("ChunkTaskRegistry");
|
||||
private static final List<ChunkTaskProvider> providers = new ArrayList<>();
|
||||
private static ChunkTaskProvider activeProvider;
|
||||
|
||||
private ChunkTaskRegistry() {}
|
||||
|
||||
public static synchronized void registerProvider(ChunkTaskProvider provider) {
|
||||
providers.add(provider);
|
||||
providers.sort(Comparator.comparingInt(ChunkTaskProvider::priority));
|
||||
activeProvider = null;
|
||||
LOGGER.info("Registered chunk task provider: {} (priority={})",
|
||||
provider.getClass().getSimpleName(), provider.priority());
|
||||
}
|
||||
|
||||
public static synchronized ChunkTaskProvider getActiveProvider() {
|
||||
for (ChunkTaskProvider provider : providers) {
|
||||
if (provider.isEnabled()) {
|
||||
if (activeProvider != provider) {
|
||||
activeProvider = provider;
|
||||
LOGGER.info("Active chunk task provider: {} (threads={})", activeProvider.getClass().getSimpleName(), activeProvider.threadCount());
|
||||
}
|
||||
return activeProvider;
|
||||
}
|
||||
}
|
||||
|
||||
if (activeProvider != DefaultChunkTaskProvider.INSTANCE) {
|
||||
activeProvider = DefaultChunkTaskProvider.INSTANCE;
|
||||
LOGGER.info("Active chunk task provider: single-threaded fallback");
|
||||
}
|
||||
return activeProvider;
|
||||
}
|
||||
|
||||
public static synchronized void reset() {
|
||||
providers.clear();
|
||||
activeProvider = null;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaMainThreadMeshingTask;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public final class DefaultChunkTaskProvider implements ChunkTaskProvider {
|
||||
public static final DefaultChunkTaskProvider INSTANCE = new DefaultChunkTaskProvider();
|
||||
|
||||
private DefaultChunkTaskProvider() {}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition) {
|
||||
return new AngelicaMainThreadMeshingTask(render, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int threadCount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
public final class RenderPassHelper {
|
||||
private static final ThreadLocal<Integer> threadLocalPass = ThreadLocal.withInitial(() -> -1);
|
||||
|
||||
private RenderPassHelper() {}
|
||||
|
||||
public static int getWorldRenderPass() {
|
||||
return GLStateManager.isMainThread() ? ForgeHooksClient.worldRenderPass : threadLocalPass.get();
|
||||
}
|
||||
|
||||
public static void setWorldRenderPass(int pass) {
|
||||
if (GLStateManager.isMainThread()) {
|
||||
ForgeHooksClient.worldRenderPass = pass;
|
||||
} else {
|
||||
threadLocalPass.set(pass);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetWorldRenderPass() {
|
||||
setWorldRenderPass(-1);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaChunkBuilderMeshingTask;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SmoothBiomeColorCache;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.WorldClientExtension;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.util.position.SectionPos;
|
||||
import org.embeddedt.embeddium.impl.util.task.CancellationToken;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaChunkBuildContext;
|
||||
|
||||
public class ThreadedAngelicaChunkBuilderMeshingTask extends AngelicaChunkBuilderMeshingTask {
|
||||
/** Vanilla render types (0-41) are thread-safe. ISBRHs (42+) need @ThreadSafeISBRH. */
|
||||
private static final int MAX_VANILLA_RENDER_TYPE = 41;
|
||||
|
||||
private final @Nullable ChunkRenderContext renderContext;
|
||||
|
||||
private IBlockAccess blockAccess;
|
||||
private SmoothBiomeColorCache biomeColorCache;
|
||||
private boolean enteredLocalMode;
|
||||
|
||||
public ThreadedAngelicaChunkBuilderMeshingTask(RenderSection render, @Nullable ChunkRenderContext renderContext, int time, Vector3d camera) {
|
||||
super(render, time, camera);
|
||||
this.renderContext = renderContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkBuildOutput execute(ChunkBuildContext context, CancellationToken cancellationToken) {
|
||||
final AngelicaChunkBuildContext buildContext = (AngelicaChunkBuildContext) context;
|
||||
initBlockAccess(buildContext);
|
||||
return super.execute(context, cancellationToken);
|
||||
}
|
||||
|
||||
private void initBlockAccess(AngelicaChunkBuildContext buildContext) {
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
if (this.renderContext != null) {
|
||||
final WorldSlice worldSlice = buildContext.getWorldSlice();
|
||||
worldSlice.copyData(this.renderContext);
|
||||
this.blockAccess = worldSlice;
|
||||
this.biomeColorCache = new SmoothBiomeColorCache(worldSlice);
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
buildContext.setupLightPipeline(minX, minY, minZ);
|
||||
} else {
|
||||
// Fallback: direct world access (main thread only)
|
||||
final var world = Minecraft.getMinecraft().theWorld;
|
||||
this.biomeColorCache = ((WorldClientExtension) world).celeritas$getSmoothBiomeColorCache();
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
this.blockAccess = new ChunkCache(world, minX - 1, minY - 1, minZ - 1, minX + 17, minY + 17, minZ + 17, 1);
|
||||
buildContext.setupLightPipeline(this.blockAccess, minX, minY, minZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tessellator getTessellator() {
|
||||
return Tessellator.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRenderPass(int pass) {
|
||||
RenderPassHelper.setWorldRenderPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBlockAccess getBlockAccess() {
|
||||
return blockAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SmoothBiomeColorCache getBiomeColorCache() {
|
||||
return biomeColorCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isThreaded() {
|
||||
return enteredLocalMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canRenderOffThread(Block block) {
|
||||
final int renderType = block.getRenderType();
|
||||
return (renderType >= 0 && renderType <= MAX_VANILLA_RENDER_TYPE)
|
||||
|| AngelicaBlockSafetyRegistry.canBlockRenderOffThread(block, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnterExecute() {
|
||||
enteredLocalMode = !TessellatorManager.isOnMainThread();
|
||||
if (enteredLocalMode) {
|
||||
TessellatorManager.enterLocalMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExitExecute() {
|
||||
if (enteredLocalMode) {
|
||||
RenderPassHelper.resetWorldRenderPass();
|
||||
TessellatorManager.exitLocalMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExtraCrashInfo(CrashReportCategory category) {
|
||||
category.addCrashSection("Thread", Thread.currentThread().getName());
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public final class ThreadedChunkTaskProvider implements ChunkTaskProvider {
|
||||
public static final ThreadedChunkTaskProvider INSTANCE = new ThreadedChunkTaskProvider();
|
||||
|
||||
private ThreadedChunkTaskProvider() {}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition) {
|
||||
return new ThreadedAngelicaChunkBuilderMeshingTask(render, null, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition, ClonedChunkSectionCache sectionCache) {
|
||||
final ChunkSectionPos origin = ChunkSectionPos.from(render.getChunkX(), render.getChunkY(), render.getChunkZ());
|
||||
final ChunkRenderContext context = WorldSlice.prepare(Minecraft.getMinecraft().theWorld, origin, sectionCache);
|
||||
return context == null ? null : new ThreadedAngelicaChunkBuilderMeshingTask(render, context, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int threadCount() {
|
||||
return AngelicaConfig.chunkBuilderThreadCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return AngelicaConfig.enableThreadedChunkBuilding;
|
||||
}
|
||||
}
|
||||
+166
-186
@@ -1,17 +1,17 @@
|
||||
package me.jellysquid.mods.sodium.client.world;
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing;
|
||||
import com.gtnewhorizons.angelica.api.IBlockAccessExtended;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightSource;
|
||||
|
||||
import java.util.List;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSection;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import java.util.Arrays;
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ChunkRenderContext;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSection;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSectionCache;
|
||||
import mega.fluidlogged.api.FLBlockAccess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
@@ -29,6 +29,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Takes a slice of world state (block states, biome and light data arrays) and copies the data for use in off-thread
|
||||
* operations. This allows chunk build tasks to see a consistent snapshot of chunk data at the exact moment the task was
|
||||
@@ -41,6 +43,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
@Optional.Interface(iface = "mega.fluidlogged.api.FLBlockAccess", modid = "fluidlogged")
|
||||
public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
|
||||
private static final EnumSkyBlock[] LIGHT_TYPES = EnumSkyBlock.values();
|
||||
|
||||
// The number of blocks on each axis in a section.
|
||||
@@ -71,7 +74,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
// The world this slice has copied data from
|
||||
private final WorldClient world;
|
||||
|
||||
// Local Section->BlockState table.
|
||||
// Local Section->Block table
|
||||
private final Block[][] blockArrays;
|
||||
private final Fluid[][] fluidArrays;
|
||||
private final int[][] metadataArrays;
|
||||
@@ -79,7 +82,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
// Local Section->Light table
|
||||
private final NibbleArray[][] lightArrays;
|
||||
|
||||
// Local section copies. Read-only.
|
||||
// Local section copies
|
||||
private ClonedChunkSection[] sections;
|
||||
|
||||
// Biome data for each chunk section
|
||||
@@ -89,32 +92,32 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
private int baseX, baseY, baseZ;
|
||||
|
||||
private final int worldHeight;
|
||||
|
||||
private final int[] defaultLightValues;
|
||||
|
||||
// The chunk origin of this slice
|
||||
@Getter
|
||||
private ChunkSectionPos origin;
|
||||
private StructureBoundingBox volume;
|
||||
|
||||
StructureBoundingBox volume;
|
||||
private List<IDynamicLightSource> chunkLightSources;
|
||||
private DynamicLights dynamicLightsInstance;
|
||||
|
||||
public static ChunkRenderContext prepare(World world, ChunkSectionPos origin, ClonedChunkSectionCache sectionCache) {
|
||||
final Chunk chunk = world.getChunkFromChunkCoords(origin.x, origin.z);
|
||||
final ExtendedBlockStorage section = chunk.getBlockStorageArray()[origin.y];
|
||||
|
||||
// If the chunk section is absent or empty, simply terminate now. There will never be anything in this chunk
|
||||
// section to render, so we need to signal that a chunk render task shouldn't created. This saves a considerable
|
||||
// amount of time in queueing instant build tasks and greatly accelerates how quickly the world can be loaded.
|
||||
// If the chunk section is absent or empty, terminate early
|
||||
if (section == null || section.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final StructureBoundingBox volume = new StructureBoundingBox(origin.getMinX() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinY() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinZ() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxX() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxY() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxZ() + NEIGHBOR_BLOCK_RADIUS);
|
||||
final StructureBoundingBox volume = new StructureBoundingBox(
|
||||
origin.getMinX() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinY() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinZ() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxX() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxY() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxZ() + NEIGHBOR_BLOCK_RADIUS
|
||||
);
|
||||
|
||||
// The min/max bounds of the chunks copied by this slice
|
||||
final int minChunkX = origin.x - NEIGHBOR_CHUNK_RADIUS;
|
||||
@@ -130,7 +133,8 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
|
||||
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
|
||||
for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) {
|
||||
sections[getLocalSectionIndex(chunkX - minChunkX, chunkY - minChunkY, chunkZ - minChunkZ)] = sectionCache.acquire(chunkX, chunkY, chunkZ);
|
||||
sections[getLocalSectionIndex(chunkX - minChunkX, chunkY - minChunkY, chunkZ - minChunkZ)] =
|
||||
sectionCache.acquire(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +149,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
this.defaultLightValues[EnumSkyBlock.Sky.ordinal()] = world.provider.hasNoSky ? 0 : EnumSkyBlock.Sky.defaultLightValue;
|
||||
this.defaultLightValues[EnumSkyBlock.Block.ordinal()] = EnumSkyBlock.Block.defaultLightValue;
|
||||
|
||||
this.sections = new ClonedChunkSection[SECTION_TABLE_ARRAY_SIZE];
|
||||
// Note: sections array is assigned in copyData() from ChunkRenderContext
|
||||
this.blockArrays = new Block[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.metadataArrays = new int[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];
|
||||
@@ -183,16 +187,24 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
this.baseZ = (this.origin.z - NEIGHBOR_CHUNK_RADIUS) << 4;
|
||||
Arrays.fill(this.biomeData, null);
|
||||
|
||||
// Pre-filter dynamic light sources for this chunk section
|
||||
if (DynamicLights.isEnabled()) {
|
||||
this.dynamicLightsInstance = DynamicLights.get();
|
||||
this.chunkLightSources = dynamicLightsInstance.getSourcesForChunk(this.origin.getMinX(), this.origin.getMinY(), this.origin.getMinZ());
|
||||
} else {
|
||||
this.dynamicLightsInstance = null;
|
||||
this.chunkLightSources = null;
|
||||
}
|
||||
|
||||
for (int x = 0; x < SECTION_LENGTH; x++) {
|
||||
for (int y = 0; y < SECTION_LENGTH; y++) {
|
||||
for (int z = 0; z < SECTION_LENGTH; z++) {
|
||||
final int idx = getLocalSectionIndex(x, y, z);
|
||||
|
||||
final ClonedChunkSection section = this.sections[idx];
|
||||
|
||||
this.unpackBlockData(this.blockArrays[idx], this.metadataArrays[idx], section, context.getVolume());
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
if (ModStatus.isFluidLoggedLoaded && this.fluidArrays != null) {
|
||||
this.unpackFluidLoggedData(this.fluidArrays[idx], section, context.getVolume());
|
||||
}
|
||||
|
||||
@@ -205,6 +217,10 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
}
|
||||
}
|
||||
|
||||
public ChunkSectionPos getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int min) {
|
||||
if (y < 0 || y >= 256 || x < -30_000_000 || z < -30_000_000 || x >= 30_000_000 || z >= 30_000_000) {
|
||||
@@ -219,8 +235,13 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
blockBrightness = min;
|
||||
}
|
||||
|
||||
if (DynamicLights.isEnabled() && !getBlock(x, y, z).isOpaqueCube()) {
|
||||
return DynamicLights.get().getLightmapWithDynamicLight(x, y, z, (skyBrightness << 20 | blockBrightness << 4));
|
||||
if (chunkLightSources != null && !chunkLightSources.isEmpty() && !getBlock(x, y, z).isOpaqueCube()) {
|
||||
final int lightmap = skyBrightness << 20 | blockBrightness << 4;
|
||||
final double dynamicLevel = dynamicLightsInstance.getDynamicLightLevelFromSources(x + 0.5, y + 0.5, z + 0.5, chunkLightSources);
|
||||
if (dynamicLevel > 0) {
|
||||
return dynamicLightsInstance.getLightmapWithDynamicLight(dynamicLevel, lightmap);
|
||||
}
|
||||
return lightmap;
|
||||
}
|
||||
|
||||
return skyBrightness << 20 | blockBrightness << 4;
|
||||
@@ -257,17 +278,16 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
|
||||
if (!blockBoxContains(this.volume, x, volume.minY, z)) {
|
||||
final int relX = x - this.baseX;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
final int sectionGridBlocks = SECTION_LENGTH << 4;
|
||||
if (relX < 0 || relX >= sectionGridBlocks || relZ < 0 || relZ >= sectionGridBlocks) {
|
||||
return BiomeGenBase.plains;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = 0;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
final BiomeGenBase biome = this.biomeData[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)]
|
||||
final BiomeGenBase biome = this.biomeData[getLocalSectionIndex(relX >> 4, 0, relZ >> 4)]
|
||||
[(x & 15) | (z & 15) << 4];
|
||||
// can be null if biome wasn't generated yet
|
||||
return biome == null ? BiomeGenBase.plains : biome;
|
||||
}
|
||||
|
||||
@@ -286,109 +306,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
return getBlock(x, y, z).isSideSolid(this, x, y, z, side);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedData(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackFluidLoggedDataZ(fluids, section);
|
||||
} else {
|
||||
this.unpackFluidLoggedDataR(fluids, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockData(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackBlockDataZ(blocks, metas, section);
|
||||
} else {
|
||||
this.unpackBlockDataR(blocks, metas, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataR(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataZ(Fluid[] fluids, ClonedChunkSection section) {
|
||||
// TODO: Look into a faster copy for this?
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = pos.getMinX();
|
||||
final int maxBlockX = pos.getMaxX();
|
||||
|
||||
final int minBlockY = pos.getMinY();
|
||||
final int maxBlockY = pos.getMaxY();
|
||||
|
||||
final int minBlockZ = pos.getMinZ();
|
||||
final int maxBlockZ = pos.getMaxZ();
|
||||
|
||||
// TODO: Can this be optimized?
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private static void copyFluids(Fluid[] fluids, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyBlocks(Block[] blocks, int[] metas, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
blocks[blockIdx] = section.getBlock(x & 15, y & 15, z & 15);
|
||||
metas[blockIdx] = section.getBlockMetadata(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockDataR(Block[] blocks, int metas[], ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
copyBlocks(blocks, metas, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private void unpackBlockDataZ(Block[] blocks, int[] metas, ClonedChunkSection section) {
|
||||
// TODO: Look into a faster copy for this?
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = pos.getMinX();
|
||||
final int maxBlockX = pos.getMaxX();
|
||||
|
||||
final int minBlockY = pos.getMinY();
|
||||
final int maxBlockY = pos.getMaxY();
|
||||
|
||||
final int minBlockZ = pos.getMinZ();
|
||||
final int maxBlockZ = pos.getMaxZ();
|
||||
|
||||
// TODO: Can this be optimized?
|
||||
copyBlocks(blocks, metas, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return Blocks.air;
|
||||
@@ -444,13 +362,120 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
|
||||
final NibbleArray lightArray = this.lightArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][type.ordinal()];
|
||||
if (lightArray == null) {
|
||||
// If the array is null, it means the dimension for the current world does not support that light type
|
||||
return this.defaultLightValues[type.ordinal()];
|
||||
}
|
||||
|
||||
return lightArray.get(relX & 15, relY & 15, relZ & 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
// FluidLogged API support
|
||||
|
||||
public @Nullable Fluid fl$getFluid(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z) || this.fluidArrays == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.fluidArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid) {
|
||||
throw new UnsupportedOperationException("Cannot set fluids in a world slice. WorldSlice is read-only");
|
||||
}
|
||||
|
||||
// Internal helper methods
|
||||
|
||||
private void unpackBlockData(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackBlockDataZ(blocks, metas, section);
|
||||
} else {
|
||||
this.unpackBlockDataR(blocks, metas, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedData(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackFluidLoggedDataZ(fluids, section);
|
||||
} else {
|
||||
this.unpackFluidLoggedDataR(fluids, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockDataZ(Block[] blocks, int[] metas, ClonedChunkSection section) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
blocks[blockIdx] = section.getBlock(x & 15, y & 15, z & 15);
|
||||
metas[blockIdx] = section.getBlockMetadata(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockDataR(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
blocks[blockIdx] = section.getBlock(x & 15, y & 15, z & 15);
|
||||
metas[blockIdx] = section.getBlockMetadata(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataZ(Fluid[] fluids, ClonedChunkSection section) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataR(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLocalBlockIndex(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
@@ -459,54 +484,9 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
return y << TABLE_BITS << TABLE_BITS | z << TABLE_BITS | x;
|
||||
}
|
||||
|
||||
public static int getLocalChunkIndex(int x, int z) {
|
||||
return z << TABLE_BITS | x;
|
||||
}
|
||||
|
||||
/// Modern checks if the sky is darkened, which only happens in the nether. However, I think 1.7.10's hasNoSky is
|
||||
/// close enough.
|
||||
public float getBrightness(ModelQuadFacing direction, boolean shaded) {
|
||||
|
||||
if (!shaded) {
|
||||
return world.provider.hasNoSky ? 0.9f : 1.0f;
|
||||
}
|
||||
return switch (direction) {
|
||||
case NEG_Y -> 0.5f;
|
||||
case POS_Y -> 1.0f;
|
||||
case NEG_Z, POS_Z -> 0.8f;
|
||||
default -> 0.6f;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
private static boolean blockBoxContains(StructureBoundingBox box, int x, int y, int z) {
|
||||
return x >= box.minX &&
|
||||
x <= box.maxX &&
|
||||
y >= box.minY &&
|
||||
y <= box.maxY &&
|
||||
z >= box.minZ &&
|
||||
z <= box.maxZ;
|
||||
}
|
||||
|
||||
public @Nullable Fluid fl$getFluid(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.fluidArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public Fluid getFluidRelative(int x, int y, int z) {
|
||||
return this.fluidArrays[getLocalSectionIndex(x >> 4, y >> 4, z >> 4)][getLocalBlockIndex(x & 15, y & 15, z & 15)];
|
||||
}
|
||||
|
||||
public void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid) {
|
||||
throw new UnsupportedOperationException("Cannot set fluids in a world slice. WorldSlice is read-only");
|
||||
return x >= box.minX && x <= box.maxX &&
|
||||
y >= box.minY && y <= box.maxY &&
|
||||
z >= box.minZ && z <= box.maxZ;
|
||||
}
|
||||
}
|
||||
+6
-13
@@ -1,9 +1,10 @@
|
||||
package me.jellysquid.mods.sodium.client.world.cloned;
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
|
||||
public class ChunkRenderContext {
|
||||
|
||||
private final ChunkSectionPos origin;
|
||||
private final ClonedChunkSection[] sections;
|
||||
private final StructureBoundingBox volume;
|
||||
@@ -14,23 +15,15 @@ public class ChunkRenderContext {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public ClonedChunkSection[] getSections() {
|
||||
return this.sections;
|
||||
}
|
||||
|
||||
public ChunkSectionPos getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
public ClonedChunkSection[] getSections() {
|
||||
return this.sections;
|
||||
}
|
||||
|
||||
public StructureBoundingBox getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void releaseResources() {
|
||||
for (ClonedChunkSection section : sections) {
|
||||
if (section != null) {
|
||||
section.getBackingCache().release(section);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
-65
@@ -1,4 +1,4 @@
|
||||
package me.jellysquid.mods.sodium.client.world.cloned;
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
|
||||
|
||||
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
|
||||
import com.gtnewhorizons.angelica.compat.ExtendedBlockStorageExt;
|
||||
@@ -6,7 +6,6 @@ import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import mega.fluidlogged.internal.mixin.hook.FLSubChunk;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -18,24 +17,17 @@ import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ClonedChunkSection {
|
||||
|
||||
private static final ExtendedBlockStorage EMPTY_SECTION = new ExtendedBlockStorage(0, false);
|
||||
|
||||
private final AtomicInteger referenceCount = new AtomicInteger(0);
|
||||
private final ClonedChunkSectionCache backingCache;
|
||||
|
||||
private final Short2ObjectMap<TileEntity> tileEntities;
|
||||
|
||||
private ExtendedBlockStorageExt data;
|
||||
private final World world;
|
||||
|
||||
private ChunkSectionPos pos;
|
||||
|
||||
@Getter
|
||||
private ExtendedBlockStorageExt data;
|
||||
private BiomeGenBase[] biomeData;
|
||||
private final Short2ObjectMap<TileEntity> tileEntities;
|
||||
|
||||
private long lastUsedTimestamp = Long.MAX_VALUE;
|
||||
|
||||
@@ -54,7 +46,7 @@ public class ClonedChunkSection {
|
||||
|
||||
ExtendedBlockStorage section = getChunkSection(chunk, pos);
|
||||
|
||||
if (section == null /*WorldChunk.EMPTY_SECTION*/ /*ChunkSection.isEmpty(section)*/) {
|
||||
if (section == null) {
|
||||
section = EMPTY_SECTION;
|
||||
}
|
||||
|
||||
@@ -63,7 +55,7 @@ public class ClonedChunkSection {
|
||||
|
||||
int bArrLength;
|
||||
if (ModStatus.isEIDBiomeLoaded) {
|
||||
bArrLength = ((ChunkBiomeHook)chunk).getBiomeShortArray().length;
|
||||
bArrLength = ((ChunkBiomeHook) chunk).getBiomeShortArray().length;
|
||||
} else {
|
||||
bArrLength = chunk.getBiomeArray().length;
|
||||
}
|
||||
@@ -72,20 +64,18 @@ public class ClonedChunkSection {
|
||||
this.tileEntities.clear();
|
||||
|
||||
// Check for tile entities
|
||||
for(int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for(int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for(int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
int lX = x & 15, lY = y & 15, lZ = z & 15;
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int lX = x & 15, lY = y & 15, lZ = z & 15;
|
||||
// We have to use this insanity because in 1.7 the tile entity isn't guaranteed to be created
|
||||
// when the chunk gets scheduled for rendering. So we might have to create it.
|
||||
// Cloning is done on the main thread so this will not introduce threading issues
|
||||
Block block = data.getBlockByExtId(lX, lY, lZ);
|
||||
if(block.hasTileEntity(data.getExtBlockMetadata(lX, lY, lZ))) {
|
||||
TileEntity tileentity = chunk.func_150806_e(x & 15, y, z & 15);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
this.tileEntities.put(ChunkSectionPos.packLocal(tileentity.xCoord & 15, tileentity.yCoord & 15, tileentity.zCoord & 15), tileentity);
|
||||
final Block block = data.getBlockByExtId(lX, lY, lZ);
|
||||
if (block.hasTileEntity(data.getExtBlockMetadata(lX, lY, lZ))) {
|
||||
final TileEntity tileEntity = chunk.func_150806_e(x & 15, y, z & 15);
|
||||
if (tileEntity != null) {
|
||||
this.tileEntities.put(ChunkSectionPos.packLocal(tileEntity.xCoord & 15, tileEntity.yCoord & 15, tileEntity.zCoord & 15), tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,9 +83,9 @@ public class ClonedChunkSection {
|
||||
}
|
||||
|
||||
// Fill biome data
|
||||
for(int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for(int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
this.biomeData[((z & 15) << 4) | (x & 15)] = world.getBiomeGenForCoords(x, z);
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
this.biomeData[(x & 15) | ((z & 15) << 4)] = world.getBiomeGenForCoords(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,56 +94,46 @@ public class ClonedChunkSection {
|
||||
return data.getBlockByExtId(x, y, z);
|
||||
}
|
||||
|
||||
public Fluid getFluid(int x, int y, int z) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
return ((FLSubChunk) data).fl$getFluid(x, y, z);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
return data.getExtBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
public Fluid getFluid(int x, int y, int z) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
return ((FLSubChunk) data).fl$getFluid(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NibbleArray getLightArray(EnumSkyBlock type) {
|
||||
if(type == EnumSkyBlock.Sky) {
|
||||
if (type == EnumSkyBlock.Sky) {
|
||||
return (!world.provider.hasNoSky && data.hasSky) ? data.getSkylightArray() : null;
|
||||
}
|
||||
return data.getBlocklightArray();
|
||||
}
|
||||
|
||||
public BiomeGenBase getBiomeForNoiseGen(int x, int y, int z) {
|
||||
return this.biomeData[x | z << 4];
|
||||
public BiomeGenBase[] getBiomeData() {
|
||||
return this.biomeData;
|
||||
}
|
||||
|
||||
public BiomeGenBase getBiomeForNoiseGen(int x, int z) {
|
||||
return this.biomeData[(x & 15) | ((z & 15) << 4)];
|
||||
}
|
||||
|
||||
public TileEntity getBlockEntity(int x, int y, int z) {
|
||||
return this.tileEntities.get(packLocal(x, y, z));
|
||||
return this.tileEntities.get(ChunkSectionPos.packLocal(x, y, z));
|
||||
}
|
||||
|
||||
public ChunkSectionPos getPosition() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
public static boolean isOutOfBuildLimitVertically(int y) {
|
||||
return y < 0 || y >= 256;
|
||||
public ExtendedBlockStorageExt getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
private static ExtendedBlockStorage getChunkSection(Chunk chunk, ChunkSectionPos pos) {
|
||||
if (!isOutOfBuildLimitVertically(ChunkSectionPos.getBlockCoord(pos.y()))) {
|
||||
return chunk.getBlockStorageArray()[pos.y];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void acquireReference() {
|
||||
this.referenceCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public boolean releaseReference() {
|
||||
return this.referenceCount.decrementAndGet() <= 0;
|
||||
public ClonedChunkSectionCache getBackingCache() {
|
||||
return this.backingCache;
|
||||
}
|
||||
|
||||
public long getLastUsedTimestamp() {
|
||||
@@ -164,17 +144,14 @@ public class ClonedChunkSection {
|
||||
this.lastUsedTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public ClonedChunkSectionCache getBackingCache() {
|
||||
return this.backingCache;
|
||||
public static boolean isOutOfBuildLimitVertically(int y) {
|
||||
return y < 0 || y >= 256;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x The local x-coordinate
|
||||
* @param y The local y-coordinate
|
||||
* @param z The local z-coordinate
|
||||
* @return An index which can be used to key entities or blocks within a chunk
|
||||
*/
|
||||
private static short packLocal(int x, int y, int z) {
|
||||
return (short) (x << 8 | z << 4 | y);
|
||||
private static ExtendedBlockStorage getChunkSection(Chunk chunk, ChunkSectionPos pos) {
|
||||
if (!isOutOfBuildLimitVertically(ChunkSectionPos.getBlockCoord(pos.y))) {
|
||||
return chunk.getBlockStorageArray()[pos.y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 486 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user