Compare commits
247 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de33cbce2b | |||
| 2b5f621ff8 | |||
| 1681adc10b | |||
| f606f2b7c2 | |||
| e3f9b66994 | |||
| ec3ff260fe | |||
| fafab30a09 | |||
| 707352ce51 | |||
| a9f5dafefe | |||
| 291ffd311b | |||
| 0e8c0b459b | |||
| c575a2968b | |||
| 0b297b4cd7 | |||
| b8c90985ce | |||
| b924576983 | |||
| a8b62b31a1 | |||
| 95b2d5a908 | |||
| 7d2ccc302d | |||
| 1ba1bff859 | |||
| 9409841c89 | |||
| 6c4e8021d6 | |||
| 4b1623e8c0 | |||
| a1e88bff70 | |||
| f3c20cde30 | |||
| eb601d9276 | |||
| 17a13993cc | |||
| 16e7254179 | |||
| ab055f1a0e | |||
| 0cb3716dc7 | |||
| 71e9877808 | |||
| f05e424c49 | |||
| 646882e1a9 | |||
| 482311fe48 | |||
| 97a80ed887 | |||
| 0e547c80a9 | |||
| b792487b60 | |||
| 7920415d18 | |||
| ada7668c28 | |||
| e7a34f9498 | |||
| 2a5c465923 | |||
| a14a558f0d | |||
| 66db5f0df1 | |||
| 2dc4ba20fb | |||
| 2f14d7ac27 | |||
| 6cc659bda5 | |||
| 206e492e7c | |||
| 09289e72a1 | |||
| 7861b63c99 | |||
| 965b9c948e | |||
| ae4ca8cd6b | |||
| 2dec862c3b | |||
| f9d8073e80 | |||
| 2ca99c29d2 | |||
| 2e4477b533 | |||
| b0c7919dda | |||
| 398c14ee96 | |||
| 422e54b488 | |||
| 36f1c49f49 | |||
| 271f4e8b21 | |||
| b164e4646d | |||
| 14fd5729e2 | |||
| 7c3e279237 | |||
| 2884094dee | |||
| 817c268491 | |||
| 071a306f14 | |||
| c97fea6d0a | |||
| d94faf828d | |||
| 0d6d4b133e | |||
| 5ab6bfb663 | |||
| e087dbc878 | |||
| 391e96ad3d | |||
| fbf812091d | |||
| 7448483f84 | |||
| e3d6e1bcc6 | |||
| fbbcd1b95b | |||
| d8e7325044 | |||
| f17aeca79c | |||
| ac3a223114 | |||
| e4312c2f8b | |||
| 17bde631ac | |||
| 64d8f7ee2d | |||
| d8b3aee9dc | |||
| fce94fa4bf | |||
| 254d671629 | |||
| e66e7e627a | |||
| 578efbf15f | |||
| 8b6bb228e3 | |||
| 611c4606d7 | |||
| 05bdaf0390 | |||
| eb8fcaee36 | |||
| 32a71933d6 | |||
| a4baf9ca0a | |||
| 72bfd0a2bb | |||
| 7ae4a9f460 | |||
| 9bd6fb0105 | |||
| 1f1024251b | |||
| fc516a20d5 | |||
| 791c2c3426 | |||
| b00079897a | |||
| 37b73e1d5c | |||
| 4bd1136713 | |||
| ef98dbd5fd | |||
| 5df0a60b06 | |||
| 9feb20eff8 | |||
| c9267d61a8 | |||
| a29e225a80 | |||
| ae0f3c2b3b | |||
| 852ea75449 | |||
| ab6a5dad2b | |||
| 1a1eaca280 | |||
| 0272f8c57f | |||
| cf09358710 | |||
| b5d833fa3d | |||
| 329dbe9585 | |||
| c7ae7f155e | |||
| 5f7dbb8662 | |||
| ee21548151 | |||
| ca00125960 | |||
| 4067264e72 | |||
| 9c2d243ad4 | |||
| de9d8b0d2e | |||
| 67f4615b34 | |||
| cd7a130ee4 | |||
| 4d17f7aecf | |||
| a59e7500ab | |||
| 40040294e7 | |||
| 783e61ec3d | |||
| e09db5d7df | |||
| 91f9ef3f4b | |||
| d52a3abb14 | |||
| 16370b0b6e | |||
| bfa60b48cf | |||
| 50518bfe21 | |||
| 80e4467829 | |||
| 396315bd05 | |||
| 7a0fec2c2f | |||
| 4afaaa7b12 | |||
| b057041467 | |||
| 33e6ce6376 | |||
| 118ef39c30 | |||
| 1013e1c824 | |||
| b0e924c7fe | |||
| 1777acd1d4 | |||
| 8276a862f8 | |||
| 4329acf91d | |||
| 72f83b40f7 | |||
| a33eb30a53 | |||
| d3e96f50a8 | |||
| 3aefeb98b4 | |||
| 3553ff8e60 | |||
| 945a2c0c5a | |||
| 8c7974e216 | |||
| 37756cd759 | |||
| c60cc4f013 | |||
| 87cce2e33c | |||
| 40ada9c186 | |||
| 55fb458266 | |||
| 79d2466fa2 | |||
| d750e489df | |||
| a206e49b2b | |||
| 0b691ebcd5 | |||
| 3c35c52803 | |||
| 0ed4964ee5 | |||
| b7cf7b61c8 | |||
| 54b0ccfce6 | |||
| 050d00b628 | |||
| 2733201ac3 | |||
| 26bf03205c | |||
| 628d57d216 | |||
| 58ed8259f2 | |||
| 062ed5bcc8 | |||
| 539d152caa | |||
| a1af4335e0 | |||
| e68b112020 | |||
| fab6d187ca | |||
| 0daa00cec2 | |||
| f3036850ce | |||
| 51c8b47bba | |||
| 89efd53d61 | |||
| 7667f51cf3 | |||
| 61eaa5a734 | |||
| 1d589d1a62 | |||
| 03b1eeb77e | |||
| 8446df72f7 | |||
| c07397e9c0 | |||
| 29a92aeb93 | |||
| 8467782b80 | |||
| c8dbb21ea4 | |||
| 63e1c12564 | |||
| 52f58150da | |||
| d1d642a7bb | |||
| 8e45358aad | |||
| a959c7220b | |||
| e06425c5eb | |||
| 66ce258fe1 | |||
| 181881a661 | |||
| af0d8d1d2f | |||
| 6c68e94b96 | |||
| 93313a5c50 | |||
| 0527baa708 | |||
| ce1fbde937 | |||
| 764abdac45 | |||
| b42d3d8f74 | |||
| cd67a773c5 | |||
| 6d7bade7ca | |||
| dea8d4498a | |||
| 2969916f34 | |||
| 8785224c51 | |||
| 605f02a655 | |||
| 8099d37c14 | |||
| dd4dbefe9a | |||
| 52a15fd349 | |||
| 3b3be6aed4 | |||
| aeb7d6d0f9 | |||
| 5336dbafec | |||
| 6079cb4830 | |||
| 50ff174104 | |||
| b77ef89df6 | |||
| a701dd29a9 | |||
| ab36fdd545 | |||
| f87afb34f4 | |||
| 053917d3d7 | |||
| 063ba01970 | |||
| 72a888f3ff | |||
| 0bd36bff1d | |||
| 2bf125b7ac | |||
| ba3cf8fd56 | |||
| 951f2a4ee7 | |||
| d55b1bb3c2 | |||
| 275ecb78c3 | |||
| 64ac0d6017 | |||
| 29381bce7b | |||
| 9fea29cbb6 | |||
| 7e1e5a56e2 | |||
| 059293ebe0 | |||
| 4f9d4e2a14 | |||
| 6bd3c825c3 | |||
| c75595a5e2 | |||
| 266d463873 | |||
| 73c718c676 | |||
| 3df5c04759 | |||
| d72c34a926 | |||
| 8991338be1 | |||
| 6b32ab02d3 | |||
| c5adc3f72a | |||
| 1d0d67d215 | |||
| e5536de44f |
@@ -1,19 +0,0 @@
|
|||||||
**/.git
|
|
||||||
**/.gitlab
|
|
||||||
**/.cache
|
|
||||||
|
|
||||||
buildAllJars
|
|
||||||
|
|
||||||
**/_Misc Files
|
|
||||||
*.bat
|
|
||||||
*.md
|
|
||||||
*.sh
|
|
||||||
*.txt
|
|
||||||
|
|
||||||
coreSubProjects/*.md
|
|
||||||
coreSubProjects/*.txt
|
|
||||||
|
|
||||||
**/.gitignore
|
|
||||||
**/.gitattributes
|
|
||||||
**/.gitlab-cy.yml
|
|
||||||
**/.gitmodules
|
|
||||||
@@ -25,6 +25,8 @@ hs_err_pid*
|
|||||||
Merged/
|
Merged/
|
||||||
# Folder created by the buildAll scripts
|
# Folder created by the buildAll scripts
|
||||||
buildAllJars/
|
buildAllJars/
|
||||||
|
_buildAllJars/
|
||||||
|
_buildWorkers/
|
||||||
|
|
||||||
relocate_natives/.venv/
|
relocate_natives/.venv/
|
||||||
relocate_natives/__pycache__/
|
relocate_natives/__pycache__/
|
||||||
|
|||||||
+21
-2
@@ -4,6 +4,7 @@ image: eclipse-temurin:25
|
|||||||
|
|
||||||
# all stages need to be defined here
|
# all stages need to be defined here
|
||||||
stages:
|
stages:
|
||||||
|
- translations
|
||||||
- build
|
- build
|
||||||
- api
|
- api
|
||||||
- pages
|
- pages
|
||||||
@@ -32,16 +33,20 @@ variables:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
needs:
|
||||||
|
- job: translations
|
||||||
|
artifacts: true
|
||||||
parallel:
|
parallel:
|
||||||
matrix:
|
matrix:
|
||||||
- MC_VER: [
|
- MC_VER: [
|
||||||
"1.26.1",
|
"26.1.2",
|
||||||
"1.21.11", "1.21.10", "1.21.9", "1.21.8", "1.21.6", "1.21.5", "1.21.4", "1.21.3", "1.21.1",
|
"1.21.11", "1.21.10", "1.21.9", "1.21.8", "1.21.6", "1.21.5", "1.21.4", "1.21.3", "1.21.1",
|
||||||
"1.20.6", "1.20.4", "1.20.2", "1.20.1",
|
"1.20.6", "1.20.4", "1.20.2", "1.20.1",
|
||||||
"1.19.4", "1.19.2",
|
"1.19.4", "1.19.2",
|
||||||
"1.18.2",
|
"1.18.2",
|
||||||
"1.17.1",
|
"1.17.1",
|
||||||
"1.16.5"
|
"1.16.5",
|
||||||
|
"1.12.2"
|
||||||
]
|
]
|
||||||
script:
|
script:
|
||||||
# this both runs the unit tests and assembles the code
|
# this both runs the unit tests and assembles the code
|
||||||
@@ -101,3 +106,17 @@ pages:
|
|||||||
- public
|
- public
|
||||||
allow_failure: false
|
allow_failure: false
|
||||||
extends: .build_java
|
extends: .build_java
|
||||||
|
|
||||||
|
translations:
|
||||||
|
stage: translations
|
||||||
|
needs: []
|
||||||
|
image: crowdin/cli:latest
|
||||||
|
script:
|
||||||
|
- if [ "$CI_COMMIT_BEFORE_SHA" = "0000000000000000000000000000000000000000" ] || git diff --name-only "$CI_COMMIT_BEFORE_SHA" "$CI_COMMIT_SHA" -- coreSubProjects/core/src/main/resources/assets/distanthorizons/lang | grep -q .; then crowdin upload sources; fi
|
||||||
|
- crowdin download --export-only-approved --skip-untranslated-files
|
||||||
|
- for f in coreSubProjects/core/src/main/resources/assets/distanthorizons/lang/*.json; do [ -e "$f" ] || continue; sed -i 's/\\\\n/\\n/g' "$f"; n="$(basename "$f" | tr '[:upper:]' '[:lower:]')"; [ "$(basename "$f")" = "$n" ] || mv "$f" "$(dirname "$f")/$n"; done
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- coreSubProjects/core/src/main/resources/assets/distanthorizons/lang/**
|
||||||
|
expire_in: 1 day
|
||||||
|
when: always
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="distant-horizons [cleanroom:runClient]" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
|
<ExternalSystemSettings>
|
||||||
|
<option name="executionName" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
|
<option name="scriptParameters" value="" />
|
||||||
|
<option name="taskDescriptions">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
<option name="taskNames">
|
||||||
|
<list>
|
||||||
|
<option value="cleanroom:runClient" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="vmOptions" />
|
||||||
|
</ExternalSystemSettings>
|
||||||
|
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||||
|
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||||
|
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
|
||||||
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
|
<RunAsTest>false</RunAsTest>
|
||||||
|
<GradleProfilingDisabled>false</GradleProfilingDisabled>
|
||||||
|
<GradleCoverageDisabled>false</GradleCoverageDisabled>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
FROM eclipse-temurin:25-jdk
|
|
||||||
|
|
||||||
WORKDIR /home/build/
|
|
||||||
COPY ./gradlew .
|
|
||||||
RUN chmod +x ./gradlew
|
|
||||||
CMD echo "\r========== [CLEAN: $MC_VER] ==========" && \
|
|
||||||
./gradlew clean -PmcVer="$MC_VER" --gradle-user-home .gradle-cache/ && \
|
|
||||||
echo "\r========== [BUILD: $MC_VER] ==========" && \
|
|
||||||
./gradlew build -PmcVer="$MC_VER" --gradle-user-home .gradle-cache/ && \
|
|
||||||
echo "\r========== [MERGE: $MC_VER] ==========" && \
|
|
||||||
./gradlew mergeJars -PmcVer="$MC_VER" --gradle-user-home .gradle-cache/ && \
|
|
||||||
echo "\r========== [DONE: $MC_VER] =========="
|
|
||||||
@@ -12,91 +12,18 @@ Below is a video demonstrating the system:
|
|||||||
|
|
||||||
<a href="https://youtu.be/SxQdbtjGEsc" target="_blank"></a>
|
<a href="https://youtu.be/SxQdbtjGEsc" target="_blank"></a>
|
||||||
|
|
||||||
<br>
|
## Translations
|
||||||
|
|
||||||
## Minecraft and Library Versions
|
|
||||||
|
|
||||||
### This branch supports the following versions of Minecraft:
|
|
||||||
|
|
||||||
#### 1.20.4, 1.20.3 (Default)
|
|
||||||
Fabric: 0.15.1\
|
|
||||||
Fabric API: 0.91.2+1.20.4\
|
|
||||||
Forge: 49.0.30\
|
|
||||||
NeoForge: 118-beta\
|
|
||||||
Parchment: 1.20.2:2023.12.10\
|
|
||||||
Modmenu: 9.0.0-pre.1
|
|
||||||
|
|
||||||
#### 1.20.2
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.90.4+1.20.2\
|
|
||||||
Forge: 48.0.13\
|
|
||||||
Parchment: 1.20.1:2023.09.03\
|
|
||||||
Modmenu: 8.0.0
|
|
||||||
|
|
||||||
#### 1.20.1, 1.20
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.90.4+1.20.1\
|
|
||||||
Forge: 47.2.1\
|
|
||||||
Parchment: 1.20.1:2023.09.03\
|
|
||||||
Modmenu: 7.2.2
|
|
||||||
|
|
||||||
#### 1.19.4
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.87.1+1.19.4\
|
|
||||||
Forge: 45.2.4\
|
|
||||||
Parchment: 1.19.4:2023.06.26\
|
|
||||||
Modmenu: 6.3.1
|
|
||||||
|
|
||||||
#### 1.19.2
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.76.1+1.19.2\
|
|
||||||
Forge: 43.3.2\
|
|
||||||
Parchment: 1.19.2:2022.11.27\
|
|
||||||
Modmenu: 4.2.0-beta.2
|
|
||||||
|
|
||||||
#### 1.18.2
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.76.0+1.18.2\
|
|
||||||
Forge: 40.2.10\
|
|
||||||
Parchment: 1.18.2:2022.11.06\
|
|
||||||
Modmenu: 3.2.5
|
|
||||||
|
|
||||||
#### 1.17.1, 1.17
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.46.1+1.17\
|
|
||||||
Forge: 37.1.1\
|
|
||||||
Parchment: 1.17.1:2021.12.12\
|
|
||||||
Modmenu: 2.0.14
|
|
||||||
|
|
||||||
#### 1.16.5, 1.16.4
|
|
||||||
Fabric: 0.14.24\
|
|
||||||
Fabric API: 0.42.0+1.16\
|
|
||||||
Forge: 36.2.39\
|
|
||||||
Parchment: 1.16.5:2022.03.06\
|
|
||||||
Modmenu: 1.16.22
|
|
||||||
|
|
||||||
### Versions no longer supported
|
|
||||||
- 1.18.1, 1.18
|
|
||||||
- 1.19.1, 1.19
|
|
||||||
- 1.19.3
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
### Plugin and Library versions
|
|
||||||
|
|
||||||
Gradle: 8.5\
|
|
||||||
Fabric loom: 1.4-SNAPSHOT\
|
|
||||||
Architectury loom (Forge gradle replacement): 1.4-SNAPSHOT\
|
|
||||||
Sponge vanilla gradle: 0.2.1-SNAPSHOT\
|
|
||||||
Java Preprocessor plugin: Manifold Preprocessor
|
|
||||||
|
|
||||||
|
[](https://crowdin.com/project/distant-horizons)\
|
||||||
|
Crowdin Project: [Distant Horizons](https://crowdin.com/project/distant-horizons)\
|
||||||
|
Guidelines: [translations.md](translations.md)
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Source Code Installation
|
## Source Code Installation
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
* A Java Development Kit (JDK) for Java 17 (recommended) or newer. <br>
|
* A Java Development Kit (JDK) for Java 25 (recommended) or newer. <br>
|
||||||
Visit https://www.oracle.com/java/technologies/downloads/ for installers.
|
Visit https://www.oracle.com/java/technologies/downloads/ for installers.
|
||||||
* Git or someway to clone git projects. <br>
|
* Git or someway to clone git projects. <br>
|
||||||
Visit https://git-scm.com/ for installers.
|
Visit https://git-scm.com/ for installers.
|
||||||
@@ -104,15 +31,10 @@ Java Preprocessor plugin: Manifold Preprocessor
|
|||||||
|
|
||||||
**If using IntelliJ:**
|
**If using IntelliJ:**
|
||||||
1. Install the Manifold plugin
|
1. Install the Manifold plugin
|
||||||
|
- https://plugins.jetbrains.com/plugin/10057-manifold-ij
|
||||||
2. Open IDEA and import the build.gradle
|
2. Open IDEA and import the build.gradle
|
||||||
3. Refresh the Gradle project in IDEA if required
|
3. Refresh the Gradle project in IDEA if required
|
||||||
|
|
||||||
**If using Eclipse: (Note that Eclipse doesn't support Manifold's preprocessor!)**
|
|
||||||
1. Run the command: `./gradlew geneclipseruns`
|
|
||||||
2. Run the command: `./gradlew eclipse`
|
|
||||||
3. Make sure eclipse has the JDK 17 installed. (This is needed so that eclipse can run minecraft)
|
|
||||||
4. Import the project into eclipse
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Switching Versions
|
## Switching Versions
|
||||||
@@ -127,72 +49,42 @@ In IntelliJ, you will also need to do a gradle sync if it didn't happen automati
|
|||||||
## Compiling
|
## Compiling
|
||||||
|
|
||||||
Prerequisites:
|
Prerequisites:
|
||||||
- JDK 17 or newer
|
- JDK 25 or newer
|
||||||
|
|
||||||
From the File Explorer:
|
|
||||||
1. Download and extract the project zip
|
|
||||||
2. Download the core from https://gitlab.com/distant-horizons-team/distant-horizons-core and extract into a folder called `coreSubProjects`
|
|
||||||
3. Open a terminal emulator in the project folder (On Windows you can type `cmd` in the title bar)
|
|
||||||
4. Run the commands: `./gradlew assemble` (You may need to use a `.\` on Windows)
|
|
||||||
5. Merge the jars with `./gradlew mergeJars`
|
|
||||||
6. The compiled jar file will be in the folder `Merged`
|
|
||||||
|
|
||||||
From the command line:
|
From the command line:
|
||||||
1. `git clone --recurse-submodules https://gitlab.com/distant-horizons-team/distant-horizons.git`
|
1. `git clone --recurse-submodules https://gitlab.com/distant-horizons-team/distant-horizons.git`
|
||||||
2. `cd distant-horizons`
|
2. `cd distant-horizons`
|
||||||
3. `./gradlew assemble`
|
3. `./gradlew assemble`
|
||||||
4. `./gradlew mergeJars`
|
5. The compiled jar file will be in the folder `\build\libs`
|
||||||
5. The compiled jar file will be in the folder `Merged`
|
|
||||||
|
|
||||||
Run tests with: `./gradlew test`
|
From the File Explorer:
|
||||||
|
1. Download and extract the project zip
|
||||||
|
2. Download the core from https://gitlab.com/distant-horizons-team/distant-horizons-core and extract into a folder called `coreSubProjects`
|
||||||
|
3. Open command prompt/terminal in the project folder
|
||||||
|
4. Run the commands: `./gradlew assemble`
|
||||||
|
6. The compiled jar file will be in the folder `\build\libs`
|
||||||
|
|
||||||
>Note: You can add the argument `-PmcVer=?` to tell gradle to build a selected MC version instead of having to modify the `gradle.properties` file.\
|
>Note: You can add the argument `-PmcVer=?` to tell gradle to build a selected MC version instead of having to modify the `gradle.properties` file.\
|
||||||
> For example: `./gradlew assemble -PmcVer=1.18.2`
|
> For example: `./gradlew assemble -PmcVer=1.18.2`
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Compiling with Docker
|
|
||||||
|
|
||||||
`./compile <version>`
|
|
||||||
|
|
||||||
You can also locally compile the DH jars without a Java environment by using Docker. Where `<version>` is the version of Minecraft to compile for (ie `1.20.1`), or the keyword `all`. See [Versions](#minecraft-and-library-versions) for a list of all supported values.
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## Other commands
|
## Other commands
|
||||||
|
|
||||||
`./gradlew --refresh-dependencies` to refresh local dependencies.
|
|
||||||
|
|
||||||
`./gradlew clean` to delete any compiled code.
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## Note to self
|
|
||||||
|
|
||||||
The Minecraft source code is NOT added to your workspace in an editable way. Minecraft is treated like a normal Library. Sources are there for documentation and research purposes only.
|
|
||||||
|
|
||||||
Source code uses Mojang mappings & [Parchment](https://parchmentmc.org/) mappings.
|
|
||||||
|
|
||||||
To generate the source code run `./gradlew genSources` <br>
|
|
||||||
If your IDE fails to auto-detect the source jars when browsing Minecraft classes; manually select the JAR file ending with -sources.jar when prompted by your IDE. <br>
|
|
||||||
(In IntelliJ it's at the top where it says "choose sources" when browsing a Minecraft class)
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## Other Useful commands
|
|
||||||
|
|
||||||
Run the standalone jar: `./gradlew run` <br>
|
Run the standalone jar: `./gradlew run` <br>
|
||||||
Build the standalone jar: `./gradlew core:build` <br>
|
Build the standalone jar: `./gradlew core:build` <br>
|
||||||
Only build Fabric: `./gradlew fabric:assemble` or `./gradlew fabric:build` <br>
|
Only build Fabric: `./gradlew fabric:assemble` or `./gradlew fabric:build` <br>
|
||||||
Only build Forge: `./gradlew forge:assemble` or `./gradlew forge:build` <br>
|
Only build Forge: `./gradlew forge:assemble` or `./gradlew forge:build` <br>
|
||||||
Run the Fabric client (for debugging): `./gradlew fabric:runClient` <br>
|
Run the Fabric client (for debugging): `./gradlew fabric:runClient` <br>
|
||||||
Run the Forge client (for debugging): `./gradlew forge:runClient` <br>
|
Run the Forge client (for debugging): `./gradlew forge:runClient` <br>
|
||||||
|
Delete all compiled code: `./gradlew clean` <br>
|
||||||
|
Refresh local dependencies: `./gradlew --refresh-dependencies`
|
||||||
|
|
||||||
To build all versions: `./buildAll` (all builds will end up in the `Merged` folder)
|
To build all versions: `./buildAll`
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Open Source Acknowledgements
|
## Open Source Libraries
|
||||||
|
|
||||||
Forgix (To merge multiple mod versions into one jar) [_Formerly_ [_DHJarMerger_](https://github.com/Ran-helo/DHJarMerger)]\
|
Forgix (To merge multiple mod versions into one jar) [_Formerly_ [_DHJarMerger_](https://github.com/Ran-helo/DHJarMerger)]\
|
||||||
https://github.com/PacifistMC/Forgix
|
https://github.com/PacifistMC/Forgix
|
||||||
@@ -208,3 +100,18 @@ https://github.com/blackears/svgSalamander
|
|||||||
|
|
||||||
sqlite-jdbc\
|
sqlite-jdbc\
|
||||||
https://github.com/xerial/sqlite-jdbc
|
https://github.com/xerial/sqlite-jdbc
|
||||||
|
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
Distant Horizons has been graciously provided an open source license for <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a>.
|
||||||
|
|
||||||
|
> <img src="https://www.yourkit.com/images/yklogo.png">
|
||||||
|
>
|
||||||
|
> YourKit supports open source projects with innovative and intelligent tools
|
||||||
|
for monitoring and profiling Java and .NET applications.
|
||||||
|
YourKit is the creator of <a href="https://www.yourkit.com/java/profiler/">YourKit Java Profiler</a>,
|
||||||
|
<a href="https://www.yourkit.com/dotnet-profiler/">YourKit .NET Profiler</a>,
|
||||||
|
and <a href="https://www.yourkit.com/youmonitor/">YourKit YouMonitor</a>.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+27
-1
@@ -4,5 +4,31 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
forgix {
|
forgix {
|
||||||
autoRun = true
|
|
||||||
|
// add the mod loaders to the end of the jar
|
||||||
|
// put together in the format: "a", "a-b", "a-b-c"
|
||||||
|
int loaderCount = 0;
|
||||||
|
String modLoaders = "";
|
||||||
|
((String) gradle.builds_for)
|
||||||
|
.split(",")
|
||||||
|
.each
|
||||||
|
{ loader ->
|
||||||
|
def loaderName = loader.trim()
|
||||||
|
if (modLoaders != "")
|
||||||
|
{
|
||||||
|
modLoaders += "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
modLoaders += loaderName;
|
||||||
|
|
||||||
|
loaderCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// run if there are multiple launchers that need merging
|
||||||
|
autoRun = (loaderCount > 1);
|
||||||
|
|
||||||
|
// merged jars are named in the format:
|
||||||
|
// "DistantHorizons-3.0.1-b-dev-26.1-fabric-neoforge.jar"
|
||||||
|
archiveClassifier = modLoaders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
echo "==================== Note: All build jars will be in the folder called 'buildAllJars' ===================="
|
echo "==================== Note: All build jars will be in the folder called 'buildAllJars' ===================="
|
||||||
mkdir -p buildAllJars
|
mkdir -p buildAllJars
|
||||||
rm -rf buildAllJars/*
|
rm -rf buildAllJars/*
|
||||||
|
rm -rf build/forgix/*
|
||||||
|
|
||||||
# Loop trough everything in the version properties folder
|
# Loop trough everything in the version properties folder
|
||||||
for d in versionProperties/*; do
|
for d in versionProperties/*; do
|
||||||
@@ -19,10 +20,6 @@ for d in versionProperties/*; do
|
|||||||
sh gradlew build -PmcVer=$version
|
sh gradlew build -PmcVer=$version
|
||||||
if [ $? != 0 ]; then continue; fi
|
if [ $? != 0 ]; then continue; fi
|
||||||
|
|
||||||
echo "==================== Merging $version ===================="
|
|
||||||
sh gradlew mergeJars -PmcVer=$version
|
|
||||||
if [ $? != 0 ]; then continue; fi
|
|
||||||
|
|
||||||
echo "==================== Moving jar ===================="
|
echo "==================== Moving jar ===================="
|
||||||
mv build/merged/*.jar buildAllJars/
|
mv build/forgix/*.jar buildAllJars/
|
||||||
done
|
done
|
||||||
|
|||||||
+2
-4
@@ -6,6 +6,7 @@
|
|||||||
echo ==================== Note: All build jars will be in the folder called 'buildAllJars' ====================
|
echo ==================== Note: All build jars will be in the folder called 'buildAllJars' ====================
|
||||||
mkdir buildAllJars
|
mkdir buildAllJars
|
||||||
del buildAllJars/*
|
del buildAllJars/*
|
||||||
|
del build/forgix/*
|
||||||
|
|
||||||
@rem Loop trough everything in the version properties folder
|
@rem Loop trough everything in the version properties folder
|
||||||
for %%f in (versionProperties\*) do (
|
for %%f in (versionProperties\*) do (
|
||||||
@@ -19,11 +20,8 @@ for %%f in (versionProperties\*) do (
|
|||||||
echo ==================== Building !version! ====================
|
echo ==================== Building !version! ====================
|
||||||
call .\gradlew.bat build -PmcVer="!version!"
|
call .\gradlew.bat build -PmcVer="!version!"
|
||||||
|
|
||||||
echo ==================== Merging !version! ====================
|
|
||||||
call .\gradlew.bat mergeJars -PmcVer="!version!"
|
|
||||||
|
|
||||||
echo ==================== Moving jar ====================
|
echo ==================== Moving jar ====================
|
||||||
move build\merged\*.jar buildAllJars\
|
move build\forgix\*.jar buildAllJars\
|
||||||
)
|
)
|
||||||
|
|
||||||
endlocal
|
endlocal
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
@echo off & setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
|
||||||
|
echo ==================== Getting versions to build... ====================
|
||||||
|
mkdir _buildAllJars 2>nul
|
||||||
|
del _buildAllJars\* /Q 2>nul
|
||||||
|
|
||||||
|
set "ROOT=%~dp0"
|
||||||
|
set "WORK_DIR=%ROOT%_buildWorkers"
|
||||||
|
mkdir "%WORK_DIR%" 2>nul
|
||||||
|
|
||||||
|
|
||||||
|
REM get the number of versions to compile
|
||||||
|
set count=0
|
||||||
|
for %%f in (versionProperties\*) do set /a count+=1
|
||||||
|
echo ==================== Found %count% versions to build in parallel ====================
|
||||||
|
|
||||||
|
REM Launch a parallel job for each version
|
||||||
|
for %%f in (%ROOT%versionProperties\*) do (
|
||||||
|
set version=%%~nf
|
||||||
|
|
||||||
|
echo starting [!version!]...
|
||||||
|
start "Build !version!" cmd /c ""%ROOT%build_worker.bat" "!version!" "%ROOT%" "%WORK_DIR%" ""..\..\_buildAllJars"""
|
||||||
|
|
||||||
|
REM Minor timeout between launches so we can stop the build early if we only want
|
||||||
|
REM to test part of the script and to reduce startup load
|
||||||
|
timeout /t 3 /nobreak
|
||||||
|
|
||||||
|
REM 2>nul to supress a harmless warning that the for loop
|
||||||
|
REM "cannot find the drive specified"
|
||||||
|
) 2>nul
|
||||||
|
|
||||||
|
|
||||||
|
echo ==================== All builds started... Completed Jars will be in _buildAllJars ====================
|
||||||
|
endlocal
|
||||||
@@ -18,7 +18,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.gradleup.shadow:shadow-gradle-plugin:9.0.0'
|
implementation 'com.gradleup.shadow:shadow-gradle-plugin:9.0.0'
|
||||||
implementation 'xyz.wagyourtail.unimined:xyz.wagyourtail.unimined.gradle.plugin:1.4.17-kappa'
|
implementation 'xyz.wagyourtail.unimined:xyz.wagyourtail.unimined.gradle.plugin:1.4.18-kappa'
|
||||||
implementation 'xyz.wagyourtail:manifold-gradle:1.0.0-SNAPSHOT'
|
implementation 'xyz.wagyourtail:manifold-gradle:1.0.0-SNAPSHOT'
|
||||||
implementation 'xyz.wagyourtail.jvmdowngrader:xyz.wagyourtail.jvmdowngrader.gradle.plugin:1.3.4'
|
implementation 'xyz.wagyourtail.jvmdowngrader:xyz.wagyourtail.jvmdowngrader.gradle.plugin:1.3.4'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.apache.tools.zip.ZipOutputStream
|
|||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
|
||||||
// Convention plugin for all MC-facing subprojects (common + loaders).
|
// Convention plugin for all MC-facing subprojects (common + loaders).
|
||||||
// Common uses this directly; loaders use it via unimined-fabric/forge/neoforge.
|
// Common uses this directly; loaders use it via unimined-fabric/forge/neoforge.
|
||||||
@@ -23,6 +24,9 @@ plugins {
|
|||||||
|
|
||||||
def isNotCommonProject = project.name != "common"
|
def isNotCommonProject = project.name != "common"
|
||||||
|
|
||||||
|
if (isNotCommonProject) {
|
||||||
|
evaluationDependsOn(":common")
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== Version Properties ====================
|
// ==================== Version Properties ====================
|
||||||
|
|
||||||
@@ -54,7 +58,12 @@ repositories {
|
|||||||
url "https://www.cursemaven.com"
|
url "https://www.cursemaven.com"
|
||||||
content { includeGroup "curse.maven" }
|
content { includeGroup "curse.maven" }
|
||||||
}
|
}
|
||||||
maven { url "https://repo.spongepowered.org/maven/" }
|
maven {
|
||||||
|
url "https://repo.spongepowered.org/maven/"
|
||||||
|
// exclusion is needed since sponge has a deprecated version of fabric
|
||||||
|
// that gradle would prefer to get over the up-to-date version modrinth provides
|
||||||
|
content { excludeGroupByRegex "net\\.fabricmc(\\..*)?" }
|
||||||
|
}
|
||||||
maven { url "https://maven.terraformersmc.com/" }
|
maven { url "https://maven.terraformersmc.com/" }
|
||||||
maven { url "https://maven.neoforged.net/releases/" }
|
maven { url "https://maven.neoforged.net/releases/" }
|
||||||
flatDir {
|
flatDir {
|
||||||
@@ -116,6 +125,15 @@ if (isNotCommonProject) {
|
|||||||
'Multi-Release': true,
|
'Multi-Release': true,
|
||||||
'Main-Class': 'com.seibel.distanthorizons.core.jar.JarMain',
|
'Main-Class': 'com.seibel.distanthorizons.core.jar.JarMain',
|
||||||
)
|
)
|
||||||
|
if (project.name == "cleanroom") {
|
||||||
|
attributes(
|
||||||
|
'ModType': 'CRL',
|
||||||
|
'MixinConfigs': "${mod_id}.default.mixin.json,${mod_id}.mod.mixin.json",
|
||||||
|
'FMLCorePlugin': 'com.seibel.distanthorizons.cleanroom.DistantHorizonsLoadingPlugin',
|
||||||
|
'FMLCorePluginContainsFMLMod': true,
|
||||||
|
'FMLAT': "${gradle.ext.accessWidenerVersion}.distanthorizons_at.cfg"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,9 +146,15 @@ unimined.minecraft(sourceSets.main, true) {
|
|||||||
|
|
||||||
if (gradle.ext.minecraft_version.startsWith("1.")) { // 26.1+ doesn't use obfuscation
|
if (gradle.ext.minecraft_version.startsWith("1.")) { // 26.1+ doesn't use obfuscation
|
||||||
mappings {
|
mappings {
|
||||||
|
if(gradle.ext.minecraft_version.startsWith("1.12.2")){
|
||||||
|
mcp("stable", "39-1.12")
|
||||||
|
}
|
||||||
|
else{
|
||||||
mojmap()
|
mojmap()
|
||||||
devNamespace "mojmap"
|
devNamespace "mojmap"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,18 +184,23 @@ if (isNotCommonProject) {
|
|||||||
source(project(":common").sourceSets.main.allSource)
|
source(project(":common").sourceSets.main.allSource)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Common: fabric for compilation + access widener, no jar remapping or runs
|
|
||||||
unimined.minecraft {
|
unimined.minecraft {
|
||||||
|
if (gradle.ext.minecraft_version.equals("1.12.2")) {
|
||||||
|
cleanroom {
|
||||||
|
loader gradle.ext.cleanroom_loader_version
|
||||||
|
accessTransformer project.file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons_at.cfg")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
fabric {
|
fabric {
|
||||||
loader gradle.ext.fabric_loader_version
|
loader gradle.ext.fabric_loader_version
|
||||||
accessWidener project.file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
accessWidener project.file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defaultRemapJar = false
|
defaultRemapJar = false
|
||||||
runs.off = true
|
runs.off = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== Configurations ====================
|
// ==================== Configurations ====================
|
||||||
|
|
||||||
evaluationDependsOn(":core")
|
evaluationDependsOn(":core")
|
||||||
@@ -286,7 +315,6 @@ class NativeTransformer implements ResourceTransformer {
|
|||||||
if (isNotCommonProject) {
|
if (isNotCommonProject) {
|
||||||
shadowJar {
|
shadowJar {
|
||||||
configurations = [project.configurations.shadowMe]
|
configurations = [project.configurations.shadowMe]
|
||||||
relocate "com.seibel.distanthorizons.common", "loaderCommon.${project.name}.com.seibel.distanthorizons.common"
|
|
||||||
def librariesLocation = "DistantHorizons.libraries"
|
def librariesLocation = "DistantHorizons.libraries"
|
||||||
|
|
||||||
// LZ4
|
// LZ4
|
||||||
@@ -342,34 +370,103 @@ if (isNotCommonProject) {
|
|||||||
def loaderPaths = configurations.minecraftLibraries.resolve().collect { it.path }.toSet()
|
def loaderPaths = configurations.minecraftLibraries.resolve().collect { it.path }.toSet()
|
||||||
tasks.withType(JavaExec).configureEach { runTask ->
|
tasks.withType(JavaExec).configureEach { runTask ->
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
|
if (project.name != "cleanroom") {
|
||||||
classpath = files(shadowJar.archiveFile) + classpath.filter { file ->
|
classpath = files(shadowJar.archiveFile) + classpath.filter { file ->
|
||||||
|
file != shadowJar.archiveFile.get().asFile &&
|
||||||
!file.path.contains(project.buildDir.path) &&
|
!file.path.contains(project.buildDir.path) &&
|
||||||
!file.path.contains("core${File.separator}build") &&
|
!file.path.contains("core${File.separator}build") &&
|
||||||
!file.path.contains("api${File.separator}build") &&
|
!file.path.contains("api${File.separator}build") &&
|
||||||
!file.path.contains("common${File.separator}build") &&
|
!file.path.contains("common${File.separator}build") &&
|
||||||
!(shadowedPaths.contains(file.path) && !loaderPaths.contains(file.path))
|
!(shadowedPaths.contains(file.path) && !loaderPaths.contains(file.path))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// For cleanroom, don't put shadow jar on app classpath.
|
||||||
|
// crl.dev.extrapath loads it via LaunchClassLoader instead.
|
||||||
|
classpath = classpath.filter { file ->
|
||||||
|
!file.path.contains(project.buildDir.path) &&
|
||||||
|
!file.path.contains("core${File.separator}build") &&
|
||||||
|
!file.path.contains("api${File.separator}build") &&
|
||||||
|
!file.path.contains("common${File.separator}build") &&
|
||||||
|
!(shadowedPaths.contains(file.path) && !loaderPaths.contains(file.path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Shared run directory so all loaders use the same worlds
|
// Shared run directory so all loaders use the same worlds
|
||||||
def isClient = runTask.name.toLowerCase().contains("client")
|
def isClient = runTask.name.toLowerCase().contains("client")
|
||||||
runTask.workingDir = rootProject.file("run/${isClient ? 'client' : 'server'}")
|
runTask.workingDir = rootProject.file("run/${isClient ? 'client' : 'server'}")
|
||||||
|
|
||||||
|
// Minecraft automatically has G1GC args present,
|
||||||
|
// remove them so we can use ZGC instead
|
||||||
|
def filteredArgs = runTask.jvmArgs.findAll { arg ->
|
||||||
|
!arg.startsWith("-XX:+UseG1GC") &&
|
||||||
|
!arg.startsWith("-XX:G1") &&
|
||||||
|
!arg.startsWith("-XX:MaxGCPauseMillis")
|
||||||
|
}
|
||||||
|
runTask.jvmArgs = filteredArgs
|
||||||
|
|
||||||
|
if(project.name == "forge"
|
||||||
|
|| project.name == "neoforge"
|
||||||
|
|| project.name == "cleanroom")
|
||||||
|
{
|
||||||
|
// fix (Neo)forge, Cleanroom debug running
|
||||||
|
doFirst {
|
||||||
|
def modsDir = rootProject.file("run/${isClient ? 'client' : 'server'}/mods")
|
||||||
|
modsDir.mkdirs()
|
||||||
|
|
||||||
|
// Remove any stale DH jars before copying the fresh one
|
||||||
|
modsDir.listFiles()?.each({ file ->
|
||||||
|
if (file.name.startsWith(rootProject.mod_name))
|
||||||
|
{
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy shadow jar into mods folder so (Neo)Forge discovers it properly
|
||||||
|
copy {
|
||||||
|
from shadowJar.archiveFile
|
||||||
|
into modsDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JVM args
|
// JVM args
|
||||||
runTask.jvmArgs(
|
runTask.jvmArgs(
|
||||||
"-Dio.netty.leakDetection.level=advanced",
|
"-Dio.netty.leakDetection.level=advanced",
|
||||||
//"-XX:+UseZGC",
|
// TODO only use for modern java versions
|
||||||
|
"-XX:+UseZGC",
|
||||||
|
// TODO don't use for even more modern-er java versions
|
||||||
//"-XX:+ZGenerational",
|
//"-XX:+ZGenerational",
|
||||||
|
rootProject.minecraftMemoryJavaArg,
|
||||||
)
|
)
|
||||||
if (isClient) {
|
if (isClient)
|
||||||
|
{
|
||||||
runTask.jvmArgs(
|
runTask.jvmArgs(
|
||||||
"-Dminecraft.api.auth.host=https://nope.invalid",
|
"-Dminecraft.api.auth.host=https://nope.invalid",
|
||||||
"-Dminecraft.api.account.host=https://nope.invalid",
|
"-Dminecraft.api.account.host=https://nope.invalid",
|
||||||
"-Dminecraft.api.session.host=https://nope.invalid",
|
"-Dminecraft.api.session.host=https://nope.invalid",
|
||||||
"-Dminecraft.api.services.host=https://nope.invalid",
|
"-Dminecraft.api.services.host=https://nope.invalid",
|
||||||
)
|
)
|
||||||
runTask.args("--username", "Dev", "--renderDebugLabels", "--tracy")
|
runTask.args(
|
||||||
|
// use a consistent username for easier debugging in a given world (vs randomly teleporting to a new user each time the game boots)
|
||||||
|
"--username", "Dev",
|
||||||
|
// "--renderDebugLabels" is a Mojang command to show render names in RenderDoc
|
||||||
|
"--renderDebugLabels"
|
||||||
|
)
|
||||||
|
|
||||||
|
// enabling tracy causes constant memory growth so it isn't always desired
|
||||||
|
if (rootProject.minecraftEnableTracy == "true")
|
||||||
|
{
|
||||||
|
// "--tracy" is a Mojang command to allow individual frames to be debugged using Tracy https://github.com/wolfpld/tracy/releases/tag/v0.13.1
|
||||||
|
runTask.args("--tracy")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.downgradeJar.inputFile.set(tasks.named("remapJar").flatMap { it.archiveFile })
|
||||||
|
tasks.jar.finalizedBy(tasks.named("remapJar"))
|
||||||
|
tasks.named("remapJar").configure { finalizedBy(tasks.shadeDowngradedApi) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,16 +478,22 @@ if (isNotCommonProject) {
|
|||||||
def resourceTargets = [
|
def resourceTargets = [
|
||||||
"build_info.json",
|
"build_info.json",
|
||||||
"fabric.mod.json",
|
"fabric.mod.json",
|
||||||
|
"mcmod.info",
|
||||||
"quilt.mod.json",
|
"quilt.mod.json",
|
||||||
"META-INF/mods.toml",
|
"META-INF/mods.toml",
|
||||||
"META-INF/neoforge.mods.toml",
|
"META-INF/neoforge.mods.toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
def compatible_forgemc_versions = "${rootProject.compatible_minecraft_versions}".replaceAll("\"", "").replaceAll("]", ",)")
|
// incoming format: `["26.2.0","26.2-alpha.9"]`
|
||||||
|
// outgoing format: `[26.2.0],[26.2-alpha.9]`
|
||||||
|
def compatible_forgemc_versions = "${rootProject.compatible_minecraft_versions}"
|
||||||
|
.replaceAll("\",\"", "],[")
|
||||||
|
.replaceAll("\"", "")
|
||||||
|
|
||||||
// Quilt contributors
|
// Quilt contributors
|
||||||
def quilt_contributors = []
|
def quilt_contributors = []
|
||||||
def mod_author_list = rootProject.mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
|
def mod_author_list = rootProject.mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
|
||||||
|
def cleanroom_author_list = rootProject.mod_authors.replace('[', '').replace(']', '').split(',').collect({ it.trim().replace('"', '') }).join('", "')
|
||||||
for (dev in mod_author_list) {
|
for (dev in mod_author_list) {
|
||||||
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
|
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
|
||||||
}
|
}
|
||||||
@@ -408,15 +511,18 @@ if (isNotCommonProject) {
|
|||||||
|
|
||||||
def replaceProperties = [
|
def replaceProperties = [
|
||||||
version : rootProject.mod_version,
|
version : rootProject.mod_version,
|
||||||
|
mod_id : rootProject.mod_id,
|
||||||
mod_name : rootProject.mod_readable_name,
|
mod_name : rootProject.mod_readable_name,
|
||||||
group : rootProject.maven_group,
|
group : rootProject.maven_group,
|
||||||
authors : rootProject.mod_authors,
|
authors : rootProject.mod_authors,
|
||||||
|
cleanroom_authors : cleanroom_author_list,
|
||||||
description : rootProject.mod_description,
|
description : rootProject.mod_description,
|
||||||
homepage : rootProject.mod_homepage,
|
homepage : rootProject.mod_homepage,
|
||||||
source : rootProject.mod_source,
|
source : rootProject.mod_source,
|
||||||
issues : rootProject.mod_issues,
|
issues : rootProject.mod_issues,
|
||||||
discord : rootProject.mod_discord,
|
discord : rootProject.mod_discord,
|
||||||
minecraft_version : rootProject.minecraft_version,
|
minecraft_version : rootProject.minecraft_version,
|
||||||
|
accessWidenerVersion : rootProject.accessWidenerVersion,
|
||||||
compatible_minecraft_versions: rootProject.compatible_minecraft_versions,
|
compatible_minecraft_versions: rootProject.compatible_minecraft_versions,
|
||||||
compatible_forgemc_versions : compatible_forgemc_versions,
|
compatible_forgemc_versions : compatible_forgemc_versions,
|
||||||
java_version : rootProject.java_version,
|
java_version : rootProject.java_version,
|
||||||
@@ -427,6 +533,7 @@ if (isNotCommonProject) {
|
|||||||
fabric_incompatibility_list : rootProject.fabric_incompatibility_list,
|
fabric_incompatibility_list : rootProject.fabric_incompatibility_list,
|
||||||
fabric_recommend_list : rootProject.fabric_recommend_list,
|
fabric_recommend_list : rootProject.fabric_recommend_list,
|
||||||
neoforge_version_range : rootProject.neoforge_version_range,
|
neoforge_version_range : rootProject.neoforge_version_range,
|
||||||
|
logo_path : "assets/distanthorizons/icon.png"
|
||||||
]
|
]
|
||||||
|
|
||||||
inputs.properties replaceProperties
|
inputs.properties replaceProperties
|
||||||
@@ -437,7 +544,7 @@ if (isNotCommonProject) {
|
|||||||
|
|
||||||
// Remove unused access wideners
|
// Remove unused access wideners
|
||||||
exclude { file ->
|
exclude { file ->
|
||||||
if (file.name.contains(".distanthorizons.accesswidener") && file.name != "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener") {
|
if ((file.name.contains(".distanthorizons.accesswidener") && file.name != "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -447,17 +554,36 @@ if (isNotCommonProject) {
|
|||||||
|
|
||||||
// ==================== Resource Copy Tasks ====================
|
// ==================== Resource Copy Tasks ====================
|
||||||
|
|
||||||
task copyCommonLoaderResources(type: Copy) {
|
// task copyCommonLoaderResources(type: Copy) {
|
||||||
from project(":common").file("src/main/resources/${rootProject.accessWidenerVersion}.distanthorizons.accesswidener")
|
// from project(":common").file("src/main/resources/${rootProject.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
into(file(project.file("build/resources/main")))
|
// into(file(project.file("build/resources/main")))
|
||||||
rename "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener", "distanthorizons.accesswidener"
|
// rename "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener", "distanthorizons.accesswidener"
|
||||||
}
|
// }
|
||||||
|
|
||||||
task copyCoreResources(type: Copy) {
|
task copyCoreResources(type: Copy) {
|
||||||
from fileTree(project(":core").file("src/main/resources"))
|
from fileTree(project(":core").file("src/main/resources"))
|
||||||
into project.file("build/resources/main")
|
into project.file("build/resources/main")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register("convertJsonToLang") {
|
||||||
|
dependsOn(copyCoreResources)
|
||||||
|
|
||||||
|
File input = project.file("build/resources/main/assets/distanthorizons/lang/en_us.json")
|
||||||
|
File output = project.file("build/resources/main/assets/distanthorizons/lang/en_us.lang")
|
||||||
|
inputs.file(input)
|
||||||
|
outputs.file(output)
|
||||||
|
doLast {
|
||||||
|
output.withWriter("UTF-8") { writer ->
|
||||||
|
writer.writeLine("#PARSE_ESCAPES")
|
||||||
|
new JsonSlurper()
|
||||||
|
.parse(input)
|
||||||
|
.each { key, value ->
|
||||||
|
writer.writeLine("${key}=${value.toString().replace("%", "%%").replace("\n", "\\n")}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== JVMDowngrader ====================
|
// ==================== JVMDowngrader ====================
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
plugins {
|
||||||
|
id 'dh-loader'
|
||||||
|
}
|
||||||
|
|
||||||
|
unimined.minecraft {
|
||||||
|
cleanroom {
|
||||||
|
loader gradle.ext.cleanroom_loader_version
|
||||||
|
useToolchains = false
|
||||||
|
accessTransformer project(":common").file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons_at.cfg")
|
||||||
|
runs.all {
|
||||||
|
systemProperty("crl.dev.mixin", "${mod_id}.default.mixin.json,${mod_id}.mod.mixin.json")
|
||||||
|
systemProperty("fml.coreMods.load", "com.seibel.distanthorizons.cleanroom.DistantHorizonsLoadingPlugin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
@echo off & setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
set "VERSION=%~1"
|
||||||
|
set "ROOT=%~2"
|
||||||
|
set "WORK_DIR=%~3"
|
||||||
|
set "WORKER=%WORK_DIR%\%VERSION%"
|
||||||
|
set "JAR_OUTPUT_DIR=%~4"
|
||||||
|
|
||||||
|
REM remove the ending "\" from the root folder, otherwise the final quote
|
||||||
|
REM in the robocopy command will be escaped and it won't run
|
||||||
|
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
|
||||||
|
set "WORKER=%~3\%~1"
|
||||||
|
|
||||||
|
set "BUILT_JAR_DIR=%WORKER%\build\forgix"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo ==================== [%VERSION%] Copying workspace ====================
|
||||||
|
mkdir "%WORKER%"
|
||||||
|
robocopy "%ROOT%" "%WORKER%" /E /XD "%WORKER%" "_buildWorkers" "buildAllJars" ".gradle" "build" ".git" ".idea" ".gitlab" "run" "testScripts" /NFL /NDL
|
||||||
|
|
||||||
|
echo ==================== [%VERSION%] Cleaning ====================
|
||||||
|
cd /d "%WORKER%"
|
||||||
|
call .\gradlew.bat clean
|
||||||
|
REM optional arg that can be added if we want to log the result to a file
|
||||||
|
REM >"%WORK_DIR%\build_%VERSION%.log" 2>&1
|
||||||
|
|
||||||
|
echo ==================== [%VERSION%] Assembling ====================
|
||||||
|
call .\gradlew.bat assemble -PmcVer="%VERSION%"
|
||||||
|
REM optional arg that can be added if we want to log the result to a file
|
||||||
|
REM >>"%WORK_DIR%\build_%VERSION%.log" 2>&1
|
||||||
|
|
||||||
|
echo ==================== [%VERSION%] Exporting ====================
|
||||||
|
mkdir "%JAR_OUTPUT_DIR%"
|
||||||
|
robocopy "%BUILT_JAR_DIR%" "%JAR_OUTPUT_DIR%" /NFL /NDL
|
||||||
|
|
||||||
|
echo ==================== [%VERSION%] Done ====================
|
||||||
|
endlocal
|
||||||
|
|
||||||
|
REM can be uncommented for debugging
|
||||||
|
REM pause
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
plugins {
|
||||||
|
id 'unimined-cleanroom'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Mod Dependency Helper ====================
|
||||||
|
|
||||||
|
def addMod(path, enabled) {
|
||||||
|
if (enabled == "2")
|
||||||
|
dependencies { modImplementation(path) }
|
||||||
|
else if (enabled == "1")
|
||||||
|
dependencies { compileOnly(path) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Dependencies ====================
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Tasks ====================
|
||||||
|
|
||||||
|
task deleteResources(type: Delete) {
|
||||||
|
delete file("build/resources/main")
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
rename '(.+_at.cfg)', 'META-INF/$1'
|
||||||
|
dependsOn(copyCoreResources)
|
||||||
|
dependsOn(convertJsonToLang)
|
||||||
|
// dependsOn(copyCommonLoaderResources)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('runClient') {
|
||||||
|
dependsOn(copyCoreResources)
|
||||||
|
// dependsOn(copyCommonLoaderResources)
|
||||||
|
finalizedBy(deleteResources)
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcesJar {
|
||||||
|
def commonSources = project(":common").sourcesJar
|
||||||
|
dependsOn commonSources
|
||||||
|
from commonSources.archiveFile.map { zipTree(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+251
@@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||||
|
import com.seibel.distanthorizons.common.util.ProxyUtil;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
|
import com.seibel.distanthorizons.core.network.messages.AbstractNetworkMessage;
|
||||||
|
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
import net.minecraftforge.event.world.ChunkEvent;
|
||||||
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
|
import java.util.concurrent.AbstractExecutorService;
|
||||||
|
|
||||||
|
public class CleanroomClientProxy implements AbstractModInitializer.IEventProxy
|
||||||
|
{
|
||||||
|
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
|
private static final CleanroomPluginPacketSender PACKET_SENDER = (CleanroomPluginPacketSender) SingletonInjector.INSTANCE.get(IPluginPacketSender.class);
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
private static World GetEventLevel(WorldEvent e) { return e.getWorld(); }
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerEvents()
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
MinecraftForge.EVENT_BUS.register(FMLCommonHandler.instance());
|
||||||
|
CleanroomPluginPacketSender.setPacketHandler(ClientApi.INSTANCE::pluginMessageReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// world events //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void clientLevelLoadEvent(WorldEvent.Load event)
|
||||||
|
{
|
||||||
|
LOGGER.info("level load");
|
||||||
|
|
||||||
|
World level = event.getWorld();
|
||||||
|
if (!(level instanceof WorldClient clientLevel))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel, true);
|
||||||
|
ClientApi.INSTANCE.clientLevelLoadEvent(clientLevelWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void clientLevelUnloadEvent(WorldEvent.Unload event)
|
||||||
|
{
|
||||||
|
LOGGER.info("level unload");
|
||||||
|
|
||||||
|
World level = event.getWorld();
|
||||||
|
if (!(level instanceof WorldClient clientLevel))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel);
|
||||||
|
ClientApi.INSTANCE.clientLevelUnloadEvent(clientLevelWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// chunk events //
|
||||||
|
//==============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void rightClickBlockEvent(PlayerInteractEvent.RightClickBlock event)
|
||||||
|
{
|
||||||
|
if (MC.clientConnectedToDedicatedServer())
|
||||||
|
{
|
||||||
|
World level = event.getWorld();
|
||||||
|
|
||||||
|
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(level);
|
||||||
|
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(wrappedLevel, event.getPos().getX(), event.getPos().getZ()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractExecutorService executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||||
|
if (executor != null)
|
||||||
|
{
|
||||||
|
executor.execute(() ->
|
||||||
|
{
|
||||||
|
Chunk chunk = level.getChunk(event.getPos());
|
||||||
|
SharedApi.INSTANCE.applyChunkUpdate(new ChunkWrapper(chunk, wrappedLevel), wrappedLevel);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@SubscribeEvent
|
||||||
|
public void leftClickBlockEvent(PlayerInteractEvent.LeftClickBlock event)
|
||||||
|
{
|
||||||
|
if (MC.clientConnectedToDedicatedServer())
|
||||||
|
{
|
||||||
|
World level = event.getWorld();
|
||||||
|
|
||||||
|
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(level);
|
||||||
|
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(wrappedLevel, event.getPos().getX(), event.getPos().getZ()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractExecutorService executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||||
|
if (executor != null)
|
||||||
|
{
|
||||||
|
executor.execute(() ->
|
||||||
|
{
|
||||||
|
Chunk chunk = level.getChunk(event.getPos());
|
||||||
|
SharedApi.INSTANCE.applyChunkUpdate(new ChunkWrapper(chunk, wrappedLevel), wrappedLevel);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void clientChunkLoadEvent(ChunkEvent.Load event)
|
||||||
|
{
|
||||||
|
if (MC.clientConnectedToDedicatedServer())
|
||||||
|
{
|
||||||
|
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||||
|
IChunkWrapper chunkWrapper = new ChunkWrapper(event.getChunk(), wrappedLevel);
|
||||||
|
SharedApi.INSTANCE.applyChunkUpdate(chunkWrapper, wrappedLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// key bindings //
|
||||||
|
//==============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void registerKeyBindings(InputEvent.KeyInputEvent event)
|
||||||
|
{
|
||||||
|
/* if (Minecraft.getMinecraft().player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAction() != GLFW.GLFW_PRESS)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientApi.INSTANCE.keyPressedEvent(event.getKey());*/
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===========//
|
||||||
|
// rendering //
|
||||||
|
//===========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void afterLevelRenderEvent(TickEvent.RenderTickEvent event)
|
||||||
|
{
|
||||||
|
if (event.type.equals(TickEvent.RenderTickEvent.Type.RENDER))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// should generally only need to be set once per game session
|
||||||
|
// allows DH to render directly to Optifine's level frame buffer,
|
||||||
|
// allowing better shader support
|
||||||
|
MinecraftRenderWrapper.INSTANCE.finalLevelFrameBufferId = GL32.glGetInteger(GL32.GL_FRAMEBUFFER_BINDING);
|
||||||
|
}
|
||||||
|
catch (Exception | Error e)
|
||||||
|
{
|
||||||
|
LOGGER.error("Unexpected error in afterLevelRenderEvent: "+e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onRenderOverlay(RenderGameOverlayEvent.Text event)
|
||||||
|
{
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
if (event.isCanceled()
|
||||||
|
|| !mc.gameSettings.showDebugInfo)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
F3Screen.addStringToDisplay(event.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.cleanroom.modAccessor.ModChecker;
|
||||||
|
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||||
|
import com.seibel.distanthorizons.common.commands.CommandInitializer;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.InternalServerGenerator;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||||
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.event.*;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.core.config.Configurator;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize and setup the Mod. <br>
|
||||||
|
* If you are looking for the real start of the mod
|
||||||
|
* check out the ClientProxy.
|
||||||
|
*/
|
||||||
|
@Mod(modid = ModInfo.ID, name = ModInfo.NAME, version = ModInfo.VERSION)
|
||||||
|
public class CleanroomMain extends AbstractModInitializer
|
||||||
|
{
|
||||||
|
@Mod.Instance
|
||||||
|
public static CleanroomMain instance;
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void preinit(FMLPreInitializationEvent event)
|
||||||
|
{
|
||||||
|
Configurator.setLevel("org.sqlite", Level.INFO);
|
||||||
|
ForgeChunkManager.setForcedChunkLoadingCallback(CleanroomMain.instance, (tickets, world) -> { });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void init(FMLInitializationEvent event)
|
||||||
|
{
|
||||||
|
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||||
|
{
|
||||||
|
this.onInitializeClient();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.onInitializeServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createInitialSharedBindings()
|
||||||
|
{
|
||||||
|
SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||||
|
SingletonInjector.INSTANCE.bind(IPluginPacketSender.class, new CleanroomPluginPacketSender());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void createInitialClientBindings() { /* no additional setup needed currently */ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IEventProxy createClientProxy() { return new CleanroomClientProxy(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IEventProxy createServerProxy(boolean isDedicated) { return new CleanroomServerProxy(isDedicated); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initializeModCompat()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @Override
|
||||||
|
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler)
|
||||||
|
{ MinecraftForge.EVENT_BUS.addListener((RegisterCommandsEvent e) -> { eventHandler.accept(e.getDispatcher()); }); }*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void subscribeClientStartedEvent(Runnable eventHandler)
|
||||||
|
{
|
||||||
|
// Just run the event handler, since there are no proper ClientLifecycleEvent for the client
|
||||||
|
// to signify readiness other than FmlClientSetupEvent
|
||||||
|
eventHandler.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStarting(FMLServerStartingEvent event)
|
||||||
|
{
|
||||||
|
event.registerServerCommand(CommandInitializer.initCommands());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerAboutToStart(FMLServerAboutToStartEvent event)
|
||||||
|
{
|
||||||
|
if (eventHandlerStartServer != null)
|
||||||
|
{
|
||||||
|
eventHandlerStartServer.accept(event.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Consumer<MinecraftServer> eventHandlerStartServer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
|
||||||
|
{
|
||||||
|
eventHandlerStartServer = eventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void runDelayedSetup() { SingletonInjector.INSTANCE.runDelayedSetup(); }
|
||||||
|
|
||||||
|
// ServerWorldLoadEvent
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void dedicatedWorldLoadEvent(FMLServerAboutToStartEvent event)
|
||||||
|
{
|
||||||
|
ServerApi.INSTANCE.serverLoadEvent(event.getServer().isDedicatedServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerWorldUnloadEvent
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void serverWorldUnloadEvent(FMLServerStoppingEvent event)
|
||||||
|
{
|
||||||
|
ServerApi.INSTANCE.serverUnloadEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.network.messages.AbstractNetworkMessage;
|
||||||
|
import com.seibel.distanthorizons.core.network.messages.MessageRegistry;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class CleanroomPluginPacketSender extends AbstractPluginPacketSender
|
||||||
|
{
|
||||||
|
public static final SimpleNetworkWrapper PLUGIN_CHANNEL =
|
||||||
|
NetworkRegistry.INSTANCE.newSimpleChannel(
|
||||||
|
AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void setPacketHandler(Consumer<AbstractNetworkMessage> consumer)
|
||||||
|
{ setPacketHandler((player, message) -> consumer.accept(message)); }
|
||||||
|
static BiConsumer<IServerPlayerWrapper, AbstractNetworkMessage> consumerPacket;
|
||||||
|
public static void setPacketHandler(BiConsumer<IServerPlayerWrapper, AbstractNetworkMessage> consumer)
|
||||||
|
{
|
||||||
|
PLUGIN_CHANNEL.registerMessage(MessageWrapper.Handler.class, MessageWrapper.class, 0, Side.CLIENT);
|
||||||
|
PLUGIN_CHANNEL.registerMessage(MessageWrapper.Handler.class, MessageWrapper.class, 0, Side.SERVER);
|
||||||
|
consumerPacket = consumer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendToServer(AbstractNetworkMessage message)
|
||||||
|
{ PLUGIN_CHANNEL.sendToServer(new MessageWrapper(message)); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendToClient(EntityPlayerMP serverPlayer, AbstractNetworkMessage message)
|
||||||
|
{ PLUGIN_CHANNEL.sendTo(new MessageWrapper(message), serverPlayer); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper classes //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
// Forge doesn't support using abstract classes
|
||||||
|
@SuppressWarnings({"ClassCanBeRecord", "RedundantSuppression"})
|
||||||
|
public static class MessageWrapper implements IMessage
|
||||||
|
{
|
||||||
|
public AbstractNetworkMessage message;
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public MessageWrapper(AbstractNetworkMessage message) { this.message = message; }
|
||||||
|
|
||||||
|
public MessageWrapper()
|
||||||
|
{
|
||||||
|
// For reflection
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
|
int messageId = buf.readByte();
|
||||||
|
message = MessageRegistry.INSTANCE.createMessage(messageId);
|
||||||
|
message.decode(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte(MessageRegistry.INSTANCE.getMessageId(message));
|
||||||
|
message.encode(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Handler implements IMessageHandler<MessageWrapper, IMessage>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageWrapper wrapper, MessageContext context)
|
||||||
|
{
|
||||||
|
if (wrapper.message != null)
|
||||||
|
{
|
||||||
|
if (context.side == Side.SERVER)
|
||||||
|
{
|
||||||
|
consumerPacket.accept(ServerPlayerWrapper.getWrapper(context.getServerHandler().player), wrapper.message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
consumerPacket.accept(null, wrapper.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // No response needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+181
@@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||||
|
import com.seibel.distanthorizons.common.commands.CommandInitializer;
|
||||||
|
import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon;
|
||||||
|
import com.seibel.distanthorizons.common.util.ProxyUtil;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.InternalServerGenerator;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||||
|
import net.minecraftforge.event.world.ChunkEvent;
|
||||||
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import static com.seibel.distanthorizons.cleanroom.CleanroomMain.instance;
|
||||||
|
|
||||||
|
public class CleanroomServerProxy implements AbstractModInitializer.IEventProxy
|
||||||
|
{
|
||||||
|
private static final CleanroomPluginPacketSender PACKET_SENDER = (CleanroomPluginPacketSender) SingletonInjector.INSTANCE.get(IPluginPacketSender.class);
|
||||||
|
private static World GetEventLevel(WorldEvent e) { return e.getWorld(); }
|
||||||
|
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
private final ServerApi serverApi = ServerApi.INSTANCE;
|
||||||
|
private final boolean isDedicated;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerEvents()
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
if (this.isDedicated)
|
||||||
|
{
|
||||||
|
PACKET_SENDER.setPacketHandler(ServerApi.INSTANCE::pluginMessageReceived);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public CleanroomServerProxy(boolean isDedicated) { this.isDedicated = isDedicated; }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// events //
|
||||||
|
//========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
// ServerLevelLoadEvent
|
||||||
|
@SubscribeEvent
|
||||||
|
public void serverLevelLoadEvent(WorldEvent.Load event)
|
||||||
|
{
|
||||||
|
if (GetEventLevel(event) instanceof WorldServer)
|
||||||
|
{
|
||||||
|
this.serverApi.serverLevelLoadEvent(getServerLevelWrapper((WorldServer) GetEventLevel(event)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerLevelUnloadEvent
|
||||||
|
@SubscribeEvent
|
||||||
|
public void serverLevelUnloadEvent(WorldEvent.Unload event)
|
||||||
|
{
|
||||||
|
if (GetEventLevel(event) instanceof WorldServer)
|
||||||
|
{
|
||||||
|
this.serverApi.serverLevelUnloadEvent(getServerLevelWrapper((WorldServer) GetEventLevel(event)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void serverChunkLoadEvent(ChunkEvent.Load event)
|
||||||
|
{
|
||||||
|
ILevelWrapper levelWrapper = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||||
|
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), levelWrapper);
|
||||||
|
this.serverApi.serverChunkLoadEvent(chunk, levelWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void serverChunkSaveEvent(ChunkDataEvent.Save event)
|
||||||
|
{
|
||||||
|
if (event.getWorld() instanceof WorldServer worldServer)
|
||||||
|
{
|
||||||
|
MixinChunkMapCommon.onChunkSave(worldServer, event.getChunk());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event)
|
||||||
|
{ this.serverApi.serverPlayerJoinEvent(getServerPlayerWrapper(event)); }
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event)
|
||||||
|
{ this.serverApi.serverPlayerDisconnectEvent(getServerPlayerWrapper(event)); }
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent event)
|
||||||
|
{
|
||||||
|
this.serverApi.serverPlayerLevelChangeEvent(
|
||||||
|
getServerPlayerWrapper(event),
|
||||||
|
getServerLevelWrapper(event.fromDim, event),
|
||||||
|
getServerLevelWrapper(event.toDim, event)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper methods //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
private static ServerLevelWrapper getServerLevelWrapper(WorldServer level) { return ServerLevelWrapper.getWrapper(level); }
|
||||||
|
|
||||||
|
private static ServerLevelWrapper getServerLevelWrapper(int dimensionId, PlayerEvent event)
|
||||||
|
{
|
||||||
|
MinecraftServer server = event.player.getServer();
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
LOGGER.error("getServerLevelWrapper: server is null for player {}", event.player.getName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getServerLevelWrapper(server.getWorld(dimensionId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ServerPlayerWrapper getServerPlayerWrapper(PlayerEvent event)
|
||||||
|
{ return ServerPlayerWrapper.getWrapper((EntityPlayerMP) event.player); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class DistantHorizonsConfigPlugin implements IMixinConfigPlugin
|
||||||
|
{
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(String mixinPackage)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName)
|
||||||
|
{
|
||||||
|
/* return switch (mixinClassName.split("\\.")[5]) {
|
||||||
|
case "mist" -> Loader.isModLoaded("mist");
|
||||||
|
default -> true;
|
||||||
|
};*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getRefMapperConfig() { return null; }
|
||||||
|
@Override public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { }
|
||||||
|
@Override public List<String> getMixins() { return null; }
|
||||||
|
@Override public void preApply(String targetClassName, ClassNode classNode, String mixinClassName, IMixinInfo mixinInfo) { }
|
||||||
|
@Override public void postApply(String targetClassName, ClassNode classNode, String mixinClassName, IMixinInfo mixinInfo) { }
|
||||||
|
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DistantHorizonsLoadingPlugin implements IFMLLoadingPlugin
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public @Nullable String[] getASMTransformerClass()
|
||||||
|
{
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public @Nullable String getModContainerClass()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public @Nullable String getSetupClass()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void injectData(Map<String, Object> data) { }
|
||||||
|
@Override
|
||||||
|
public @Nullable String getAccessTransformerClass()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.mixins.client;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.commonMixins.MixinVanillaFogCommon;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||||
|
import net.minecraft.init.MobEffects;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(EntityRenderer.class)
|
||||||
|
public class MixinEntityRenderer
|
||||||
|
{
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private DynamicTexture lightmapTexture;
|
||||||
|
|
||||||
|
@Shadow @Final private Minecraft mc;
|
||||||
|
@Shadow @Final private static Logger LOGGER;
|
||||||
|
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
|
||||||
|
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"), method = "updateLightmap")
|
||||||
|
public void onUpdateLightmap(float patrialTicks, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
|
if (mc == null || mc.getWrappedClientLevel() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IClientLevelWrapper clientLevel = mc.getWrappedClientLevel();
|
||||||
|
MinecraftRenderWrapper renderWrapper = (MinecraftRenderWrapper)SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
renderWrapper.setLightmapId(lightmapTexture.getGlTextureId(), clientLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("RETURN"), method = "setupFog")
|
||||||
|
private void disableSetupFog(int startCoords, float partialTicks, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
boolean cancelFog = MixinVanillaFogCommon.cancelFog(startCoords, mc);
|
||||||
|
if (cancelFog)
|
||||||
|
{
|
||||||
|
GlStateManager.setFogStart(A_REALLY_REALLY_BIG_VALUE);
|
||||||
|
GlStateManager.setFogEnd(A_EVEN_LARGER_VALUE);
|
||||||
|
ClientApi.RENDER_STATE.vanillaFogEnabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ClientApi.RENDER_STATE.vanillaFogEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.mixins.client;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
|
import net.minecraft.network.play.server.SPacketJoinGame;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(NetHandlerPlayClient.class)
|
||||||
|
public class MixinNetHandlerPlayClient
|
||||||
|
{
|
||||||
|
@Inject(method = "handleJoinGame", at = @At("RETURN"))
|
||||||
|
private void onHandleJoinGameEnd(SPacketJoinGame packet, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
ClientApi.INSTANCE.onClientOnlyConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "onDisconnect", at = @At("RETURN"))
|
||||||
|
private void onDisconnect(ITextComponent reason, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
ClientApi.INSTANCE.onClientOnlyDisconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.mixins.client;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
|
||||||
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
import net.minecraft.client.gui.GuiOptions;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a button to the menu to goto the config
|
||||||
|
*
|
||||||
|
* @author coolGi
|
||||||
|
* @version 12-02-2021
|
||||||
|
*/
|
||||||
|
@Mixin(GuiOptions.class)
|
||||||
|
public class MixinOptionsScreen extends GuiScreen
|
||||||
|
{
|
||||||
|
// Get the texture for the button
|
||||||
|
@Unique private static final ResourceLocation ICON_TEXTURE = new ResourceLocation(ModInfo.ID, "textures/gui/button.png");
|
||||||
|
|
||||||
|
@Unique private static final int button_id = 99;
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "initGui")
|
||||||
|
private void lodconfig$init(CallbackInfo ci)
|
||||||
|
{
|
||||||
|
if (Config.Client.showDhOptionsButtonInMinecraftUi.get())
|
||||||
|
this.buttonList.add(
|
||||||
|
(new TexturedButtonWidget(
|
||||||
|
button_id,
|
||||||
|
// Where the button is on the screen
|
||||||
|
this.width / 2 - 180, this.height / 6 - 12,
|
||||||
|
// Width and height of the button
|
||||||
|
20, 20,
|
||||||
|
// Offset
|
||||||
|
0, 0,
|
||||||
|
// Some textuary stuff
|
||||||
|
20, ICON_TEXTURE, 20, 40,
|
||||||
|
// Create the button and tell it where to go
|
||||||
|
// For now it goes to the client option by default
|
||||||
|
// Add a title to the button
|
||||||
|
ModInfo.ID + ".title")));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "actionPerformed", cancellable = true)
|
||||||
|
private void lodconfig$actionPerformed(GuiButton button, CallbackInfo ci)
|
||||||
|
{
|
||||||
|
if (button.id == button_id)
|
||||||
|
{
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(GetConfigScreen.getScreen(this));
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.mixins.client;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.RenderGlobal;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.BlockRenderLayer;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL15;
|
||||||
|
import org.lwjgl.opengl.GL20;
|
||||||
|
import org.lwjgl.opengl.GL30;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(RenderGlobal.class)
|
||||||
|
public class MixinRenderGlobal
|
||||||
|
{
|
||||||
|
@Shadow private WorldClient world;
|
||||||
|
|
||||||
|
@Inject(method = "renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I", at = @At("HEAD"))
|
||||||
|
private void renderChunkLayer(BlockRenderLayer blockLayerIn, double partialTicks, int pass, Entity entityIn, CallbackInfoReturnable<Integer> cir)
|
||||||
|
{
|
||||||
|
if (blockLayerIn == BlockRenderLayer.SOLID)
|
||||||
|
{
|
||||||
|
float[] mcProjMatrixRaw = new float[16];
|
||||||
|
GL11.glGetFloatv(GL11.GL_PROJECTION_MATRIX, mcProjMatrixRaw);
|
||||||
|
ClientApi.RENDER_STATE.mcProjectionMatrix = new Mat4f(mcProjMatrixRaw);
|
||||||
|
ClientApi.RENDER_STATE.mcProjectionMatrix.transpose();
|
||||||
|
|
||||||
|
float[] mcModelViewRaw = new float[16];
|
||||||
|
GL11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, mcModelViewRaw);
|
||||||
|
ClientApi.RENDER_STATE.mcModelViewMatrix = new Mat4f(mcModelViewRaw);
|
||||||
|
ClientApi.RENDER_STATE.mcModelViewMatrix.transpose();
|
||||||
|
|
||||||
|
ClientApi.RENDER_STATE.partialTickTime = (float) partialTicks;
|
||||||
|
ClientApi.RENDER_STATE.clientLevelWrapper = ClientLevelWrapper.getWrapperIfDifferent(ClientApi.RENDER_STATE.clientLevelWrapper, this.world);
|
||||||
|
|
||||||
|
int blendSrc = GL11.glGetInteger(GL11.GL_BLEND_SRC);
|
||||||
|
int blendDst = GL11.glGetInteger(GL11.GL_BLEND_DST);
|
||||||
|
int boundTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
|
||||||
|
|
||||||
|
ClientApi.INSTANCE.renderLods();
|
||||||
|
|
||||||
|
GL30.glBindVertexArray(0);
|
||||||
|
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||||
|
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
GL20.glUseProgram(0);
|
||||||
|
|
||||||
|
//Restore vanilla states
|
||||||
|
GlStateManager.depthFunc(GL11.GL_LEQUAL);
|
||||||
|
GlStateManager.bindTexture(boundTexture);
|
||||||
|
GlStateManager.tryBlendFuncSeparate(blendSrc, blendDst, GL11.GL_ONE, GL11.GL_ZERO);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package com.seibel.distanthorizons.cleanroom.mixins.common;
|
||||||
|
|
||||||
|
import net.minecraft.world.storage.ThreadedFileIOBase;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(ThreadedFileIOBase.class)
|
||||||
|
public class MixinThreadedFileIOBase
|
||||||
|
{
|
||||||
|
@Redirect(method = "processQueue", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;sleep(J)V"))
|
||||||
|
private void reduceSleep(long millis) throws InterruptedException
|
||||||
|
{
|
||||||
|
// 0ms between chunks, 5ms when idle
|
||||||
|
Thread.sleep(millis == 25L ? 5L : 0L);
|
||||||
|
}
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.mixins.server;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraftforge.common.util.ITeleporter;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(EntityPlayerMP.class)
|
||||||
|
public abstract class MixinEntityPlayerMP implements IMixinServerPlayer
|
||||||
|
{
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
public MinecraftServer server;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
@Nullable
|
||||||
|
private volatile WorldServer distantHorizons$dimensionChangeDestination;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public WorldServer distantHorizons$getDimensionChangeDestination()
|
||||||
|
{ return this.distantHorizons$dimensionChangeDestination; }
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "changeDimension(ILnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;")
|
||||||
|
public void setDimensionChangeDestination(int destinationDimensionID, ITeleporter teleporter, CallbackInfoReturnable<Entity> cir)
|
||||||
|
{ this.distantHorizons$dimensionChangeDestination = this.server.getWorld(destinationDimensionID); }
|
||||||
|
|
||||||
|
@Inject(at = @At("RETURN"), method = "clearInvulnerableDimensionChange")
|
||||||
|
public void clearDimensionChangeDestination(CallbackInfo ci)
|
||||||
|
{ this.distantHorizons$dimensionChangeDestination = null; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Distant Horizons mod
|
||||||
|
* licensed under the GNU LGPL v3 License.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 James Seibel
|
||||||
|
*
|
||||||
|
* 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, version 3.
|
||||||
|
*
|
||||||
|
* 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 Lesser 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.seibel.distanthorizons.cleanroom.modAccessor;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class ModChecker implements IModChecker
|
||||||
|
{
|
||||||
|
public static final ModChecker INSTANCE = new ModChecker();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isModLoaded(String modid)
|
||||||
|
{
|
||||||
|
return Loader.isModLoaded(modid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File modLocation(String modid)
|
||||||
|
{
|
||||||
|
Stream<ModContainer> foundStream = Loader.instance().getModList().stream().filter(x -> x.getModId().equals(modid));
|
||||||
|
Optional<ModContainer> container = foundStream.findFirst();
|
||||||
|
if (!container.isPresent())
|
||||||
|
{
|
||||||
|
throw new RuntimeException("Mod not found: " + modid);
|
||||||
|
}
|
||||||
|
return container.get().getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"package": "com.seibel.distanthorizons.cleanroom.mixins",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"target": "@env(DEFAULT)",
|
||||||
|
"mixins": [
|
||||||
|
"common.MixinThreadedFileIOBase"
|
||||||
|
],
|
||||||
|
"minVersion": "0.8.7",
|
||||||
|
"server": [
|
||||||
|
"server.MixinEntityPlayerMP"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"client.MixinEntityRenderer",
|
||||||
|
"client.MixinNetHandlerPlayClient",
|
||||||
|
"client.MixinOptionsScreen",
|
||||||
|
"client.MixinRenderGlobal"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"required": false,
|
||||||
|
"package": "com.seibel.distanthorizons.cleanroom.mixins.mod",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"target": "@env(MOD)",
|
||||||
|
"mixins": [],
|
||||||
|
"minVersion": "0.8.7",
|
||||||
|
"plugin": "com.seibel.distanthorizons.cleanroom.DistantHorizonsConfigPlugin",
|
||||||
|
"client": [
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[{
|
||||||
|
"modid": "${mod_id}",
|
||||||
|
"name": "${mod_name}",
|
||||||
|
"version": "${version}",
|
||||||
|
"mcversion": "1.12.2",
|
||||||
|
"description": "${description}",
|
||||||
|
"authorList": ["${cleanroom_authors}"],
|
||||||
|
"credits": "",
|
||||||
|
"url": "",
|
||||||
|
"updateJSON": "",
|
||||||
|
"logoFile": "${logo_path}"
|
||||||
|
}]
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"description": "${mod_name} Resources",
|
||||||
|
"pack_format": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
-20
@@ -1,15 +1,14 @@
|
|||||||
package com.seibel.distanthorizons.common;
|
package com.seibel.distanthorizons.common;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderApi;
|
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
|
||||||
import com.seibel.distanthorizons.common.commands.CommandInitializer;
|
import com.seibel.distanthorizons.common.commands.CommandInitializer;
|
||||||
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
|
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.DhDebugScreenEntry;
|
import com.seibel.distanthorizons.common.wrappers.gui.DhDebugScreenEntry;
|
||||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper;
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.Initializer;
|
||||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
||||||
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
|
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
|
||||||
@@ -21,10 +20,8 @@ import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
|
|||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.StubDebugWireframeRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.StubDebugWireframeRenderer;
|
||||||
import com.seibel.distanthorizons.core.util.NativeDialogUtil;
|
import com.seibel.distanthorizons.common.wrappers.gui.NativeDialogUtil;
|
||||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||||
import com.seibel.distanthorizons.core.util.threading.DhThreadFactory;
|
|
||||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||||
@@ -32,7 +29,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModAccesso
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.dedicated.DedicatedServer;
|
import net.minecraft.server.dedicated.DedicatedServer;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
@@ -41,6 +37,11 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base for all mod loader initializers
|
* Base for all mod loader initializers
|
||||||
* and handles most setup.
|
* and handles most setup.
|
||||||
@@ -64,7 +65,9 @@ public abstract class AbstractModInitializer
|
|||||||
protected abstract IEventProxy createServerProxy(boolean isDedicated);
|
protected abstract IEventProxy createServerProxy(boolean isDedicated);
|
||||||
protected abstract void initializeModCompat();
|
protected abstract void initializeModCompat();
|
||||||
|
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
protected abstract void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler);
|
protected abstract void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler);
|
||||||
|
#endif
|
||||||
|
|
||||||
protected abstract void subscribeClientStartedEvent(Runnable eventHandler);
|
protected abstract void subscribeClientStartedEvent(Runnable eventHandler);
|
||||||
protected abstract void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler);
|
protected abstract void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler);
|
||||||
@@ -97,7 +100,9 @@ public abstract class AbstractModInitializer
|
|||||||
|
|
||||||
// Client uses config for auto-updater, so it's initialized here instead of post-init stage
|
// Client uses config for auto-updater, so it's initialized here instead of post-init stage
|
||||||
this.initConfig();
|
this.initConfig();
|
||||||
logModIncompatibilityWarnings(); // needs to be called after config loading
|
logIncompatibilityWarnings(); // needs to be called after config loading
|
||||||
|
setUnsupportedConfigsBasedOnMcVersion();
|
||||||
|
Initializer.postConfigInit();
|
||||||
|
|
||||||
LOGGER.info(ModInfo.READABLE_NAME + " client Initialized.");
|
LOGGER.info(ModInfo.READABLE_NAME + " client Initialized.");
|
||||||
|
|
||||||
@@ -131,21 +136,33 @@ public abstract class AbstractModInitializer
|
|||||||
this.initializeModCompat();
|
this.initializeModCompat();
|
||||||
|
|
||||||
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized, adding event subscribers...");
|
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized, adding event subscribers...");
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
this.commandInitializer = new CommandInitializer();
|
this.commandInitializer = new CommandInitializer();
|
||||||
this.subscribeRegisterCommandsEvent(dispatcher -> { this.commandInitializer.initCommands(dispatcher); });
|
this.subscribeRegisterCommandsEvent(dispatcher -> { this.commandInitializer.initCommands(dispatcher); });
|
||||||
|
#endif
|
||||||
|
|
||||||
this.subscribeServerStartingEvent(server ->
|
this.subscribeServerStartingEvent(server ->
|
||||||
{
|
{
|
||||||
MinecraftServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
MinecraftServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
||||||
|
|
||||||
this.initConfig();
|
this.initConfig();
|
||||||
|
Initializer.postConfigInit();
|
||||||
this.postInit();
|
this.postInit();
|
||||||
this.postServerInit();
|
this.postServerInit();
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
this.commandInitializer.onServerReady();
|
this.commandInitializer.onServerReady();
|
||||||
|
#endif
|
||||||
|
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
|
|
||||||
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized at " + server.getServerDirectory());
|
String serverFolderPath;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
serverFolderPath = server.getDataDirectory() + "";
|
||||||
|
#else
|
||||||
|
serverFolderPath = server.getServerDirectory() + "";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LOGGER.info(ModInfo.READABLE_NAME + " server Initialized at " + serverFolderPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +178,7 @@ public abstract class AbstractModInitializer
|
|||||||
private void startup()
|
private void startup()
|
||||||
{
|
{
|
||||||
DependencySetup.createSharedBindings();
|
DependencySetup.createSharedBindings();
|
||||||
SharedApi.init();
|
Initializer.preConfigInit();
|
||||||
this.createInitialSharedBindings();
|
this.createInitialSharedBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,9 +280,9 @@ public abstract class AbstractModInitializer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==================================//
|
//======================//
|
||||||
// mod partial compatibility checks //
|
// compatibility checks //
|
||||||
//==================================//
|
//======================//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,7 +291,7 @@ public abstract class AbstractModInitializer
|
|||||||
* This method will log (and display to chat if enabled)
|
* This method will log (and display to chat if enabled)
|
||||||
* these warnings and potential fixes.
|
* these warnings and potential fixes.
|
||||||
*/
|
*/
|
||||||
private static void logModIncompatibilityWarnings()
|
private static void logIncompatibilityWarnings()
|
||||||
{
|
{
|
||||||
boolean showChatWarnings = Config.Common.Logging.Warning.showModCompatibilityWarningsOnStartup.get();
|
boolean showChatWarnings = Config.Common.Logging.Warning.showModCompatibilityWarningsOnStartup.get();
|
||||||
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
|
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
|
||||||
@@ -368,17 +385,17 @@ public abstract class AbstractModInitializer
|
|||||||
if (iris != null)
|
if (iris != null)
|
||||||
{
|
{
|
||||||
// get the currently selected rendering API
|
// get the currently selected rendering API
|
||||||
EDhApiRenderApi renderApi = Config.Client.Advanced.Graphics.Experimental.renderingApi.get();
|
EDhApiRenderingEngine renderApi = Config.Client.Advanced.Graphics.Experimental.renderingEngine.get();
|
||||||
if (renderApi == EDhApiRenderApi.AUTO)
|
if (renderApi == EDhApiRenderingEngine.AUTO)
|
||||||
{
|
{
|
||||||
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||||
renderApi = versionConstants.getDefaultRenderingApi();
|
renderApi = versionConstants.getDefaultRenderingEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iris only supports nataive OpenGL
|
// Iris only supports native OpenGL
|
||||||
if (renderApi != EDhApiRenderApi.OPEN_GL)
|
if (renderApi != EDhApiRenderingEngine.OPEN_GL)
|
||||||
{
|
{
|
||||||
String irisUnsupportedMessage = "Iris doesn't support DH when using the ["+EDhApiRenderApi.BLAZE_3D+"] rendering API, this will need to be fixed on Iris' end. As a temporary fix please change the rendering API to ["+EDhApiRenderApi.OPEN_GL+"] in DH's config file.";
|
String irisUnsupportedMessage = "Iris doesn't support DH when using the ["+ EDhApiRenderingEngine.BLAZE_3D+"] rendering engine, this will need to be fixed on Iris end. As a temporary fix please change the rendering engine to ["+ EDhApiRenderingEngine.OPEN_GL+"] in the DH config file.";
|
||||||
LOGGER.fatal(irisUnsupportedMessage);
|
LOGGER.fatal(irisUnsupportedMessage);
|
||||||
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, irisUnsupportedMessage, "ok", "error");
|
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, irisUnsupportedMessage, "ok", "error");
|
||||||
|
|
||||||
@@ -393,6 +410,24 @@ public abstract class AbstractModInitializer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some Minecraft versions don't support all
|
||||||
|
* DH options.
|
||||||
|
* In that case we need to override what options are available.
|
||||||
|
*/
|
||||||
|
private static void setUnsupportedConfigsBasedOnMcVersion()
|
||||||
|
{
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
Config.Client.Advanced.Graphics.Experimental.renderingEngine.setMcVersionOverrideValue(EDhApiRenderingEngine.OPEN_GL);
|
||||||
|
Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.setMcVersionOverrideValue(EDhApiMcRenderingFadeMode.NONE);
|
||||||
|
Config.Common.WorldGenerator.distantGeneratorMode.setMcVersionOverrideValue(EDhApiDistantGeneratorMode.INTERNAL_SERVER);
|
||||||
|
#elif MC_VER <= MC_1_21_10
|
||||||
|
Config.Client.Advanced.Graphics.Experimental.renderingEngine.setMcVersionOverrideValue(EDhApiRenderingEngine.OPEN_GL);
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+29
-2
@@ -12,10 +12,17 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSende
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.network.PacketBuffer;
|
||||||
|
#else
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
#elif MC_VER <= MC_1_21_10
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
#else
|
#else
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
@@ -30,7 +37,9 @@ public abstract class AbstractPluginPacketSender implements IPluginPacketSender
|
|||||||
.fileLevelConfig(Config.Common.Logging.logNetworkEventToFile)
|
.fileLevelConfig(Config.Common.Logging.logNetworkEventToFile)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
#if MC_VER <= MC_1_20_6
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static final String WRAPPER_PACKET_RESOURCE = ModInfo.RESOURCE_NAMESPACE + ModInfo.WRAPPER_PACKET_PATH;
|
||||||
|
#elif MC_VER <= MC_1_20_6
|
||||||
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = new ResourceLocation(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = new ResourceLocation(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
||||||
#elif MC_VER <= MC_1_21_10
|
#elif MC_VER <= MC_1_21_10
|
||||||
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = ResourceLocation.fromNamespaceAndPath(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = ResourceLocation.fromNamespaceAndPath(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
||||||
@@ -52,14 +61,28 @@ public abstract class AbstractPluginPacketSender implements IPluginPacketSender
|
|||||||
@Override
|
@Override
|
||||||
public final void sendToClient(IServerPlayerWrapper serverPlayer, AbstractNetworkMessage message)
|
public final void sendToClient(IServerPlayerWrapper serverPlayer, AbstractNetworkMessage message)
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
this.sendToClient((EntityPlayerMP) serverPlayer.getWrappedMcObject(), message);
|
||||||
|
#else
|
||||||
this.sendToClient((ServerPlayer) serverPlayer.getWrappedMcObject(), message);
|
this.sendToClient((ServerPlayer) serverPlayer.getWrappedMcObject(), message);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public abstract void sendToClient(EntityPlayerMP serverPlayer, AbstractNetworkMessage message);
|
||||||
|
#else
|
||||||
public abstract void sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage message);
|
public abstract void sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage message);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void sendToServer(AbstractNetworkMessage message);
|
public abstract void sendToServer(AbstractNetworkMessage message);
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public AbstractNetworkMessage decodeMessage(PacketBuffer in)
|
||||||
|
#else
|
||||||
public AbstractNetworkMessage decodeMessage(FriendlyByteBuf in)
|
public AbstractNetworkMessage decodeMessage(FriendlyByteBuf in)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
AbstractNetworkMessage message = null;
|
AbstractNetworkMessage message = null;
|
||||||
|
|
||||||
@@ -100,7 +123,11 @@ public abstract class AbstractPluginPacketSender implements IPluginPacketSender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public void encodeMessage(PacketBuffer out, AbstractNetworkMessage message)
|
||||||
|
#else
|
||||||
public void encodeMessage(FriendlyByteBuf out, AbstractNetworkMessage message)
|
public void encodeMessage(FriendlyByteBuf out, AbstractNetworkMessage message)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
// This is intentionally unhandled, because errors related to this are unlikely to appear in wild
|
// This is intentionally unhandled, because errors related to this are unlikely to appear in wild
|
||||||
Objects.requireNonNull(message);
|
Objects.requireNonNull(message);
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public abstract class AbstractCommand {}
|
||||||
|
|
||||||
|
#else
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||||
@@ -100,3 +104,4 @@ public abstract class AbstractCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+81
-3
@@ -1,12 +1,26 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
||||||
|
import com.seibel.distanthorizons.core.config.types.AbstractConfigBase;
|
||||||
|
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||||
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
|
import net.minecraft.command.CommandBase;
|
||||||
|
import net.minecraft.command.ICommand;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
#else
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
#endif
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_CODEC_CRASH_MESSAGE;
|
import static com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_CODEC_CRASH_MESSAGE;
|
||||||
import static net.minecraft.commands.Commands.literal;
|
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
#else
|
#else
|
||||||
@@ -25,6 +39,70 @@ public class CommandInitializer
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static ICommand initCommands()
|
||||||
|
{
|
||||||
|
return new CommandBase()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getName() { return "dh"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsage(ICommandSender sender) { return "/dh <debug|config|pregen>"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(MinecraftServer server, ICommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
if (DEBUG_CODEC_CRASH_MESSAGE)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh <debug|config|crash|pregen>"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh <debug|config|pregen"));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[0])
|
||||||
|
{
|
||||||
|
case "debug":
|
||||||
|
DebugCommand debugCommand = new DebugCommand();
|
||||||
|
debugCommand.execute(sender);
|
||||||
|
break;
|
||||||
|
case "config":
|
||||||
|
ConfigCommand configCommand = new ConfigCommand();
|
||||||
|
configCommand.execute(sender, args);
|
||||||
|
break;
|
||||||
|
case "crash":
|
||||||
|
if (DEBUG_CODEC_CRASH_MESSAGE)
|
||||||
|
{
|
||||||
|
CrashCommand crashCommand = new CrashCommand();
|
||||||
|
crashCommand.execute(sender, args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "pregen":
|
||||||
|
if (!server.isDedicatedServer())
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Pregen command is only available on dedicated servers"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PregenCommand pregenCommand = new PregenCommand();
|
||||||
|
pregenCommand.execute(server, sender, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sender.sendMessage(new TextComponentString("Unknown subcommand: " + args[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A received command dispatcher, which is held until the server is ready to initialize the commands.
|
* A received command dispatcher, which is held until the server is ready to initialize the commands.
|
||||||
*/
|
*/
|
||||||
@@ -80,5 +158,5 @@ public class CommandInitializer
|
|||||||
|
|
||||||
commandDispatcher.register(builder);
|
commandDispatcher.register(builder);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,25 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.*;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
||||||
import com.seibel.distanthorizons.core.config.types.AbstractConfigBase;
|
import com.seibel.distanthorizons.core.config.types.AbstractConfigBase;
|
||||||
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
#else
|
||||||
|
import com.mojang.brigadier.arguments.*;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
|
import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
|
||||||
|
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||||
|
import static net.minecraft.commands.Commands.argument;
|
||||||
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,16 +28,75 @@ import java.util.function.Function;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.function.ToIntBiFunction;
|
import java.util.function.ToIntBiFunction;
|
||||||
|
|
||||||
import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
|
|
||||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
|
||||||
import static net.minecraft.commands.Commands.argument;
|
|
||||||
import static net.minecraft.commands.Commands.literal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command for managing config.
|
* Command for managing config.
|
||||||
*/
|
*/
|
||||||
public class ConfigCommand extends AbstractCommand
|
public class ConfigCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
private static void setConfigValue(ConfigEntry<?> configEntry, String value)
|
||||||
|
{
|
||||||
|
Class<?> type = configEntry.getType();
|
||||||
|
|
||||||
|
if (type == Boolean.class) ((ConfigEntry) configEntry).set(Boolean.parseBoolean(value));
|
||||||
|
else if (type == Integer.class) ((ConfigEntry) configEntry).set(Integer.parseInt(value));
|
||||||
|
else if (type == Double.class) ((ConfigEntry) configEntry).set(Double.parseDouble(value));
|
||||||
|
else if (type == Float.class) ((ConfigEntry) configEntry).set(Float.parseFloat(value));
|
||||||
|
else if (type == Long.class) ((ConfigEntry) configEntry).set(Long.parseLong(value));
|
||||||
|
else if (type == String.class) ((ConfigEntry) configEntry).set(value);
|
||||||
|
else if (type.isEnum()) ((ConfigEntry) configEntry).set(Enum.valueOf((Class<Enum>) type, value));
|
||||||
|
else throw new RuntimeException("Unsupported config type: " + type.getSimpleName());
|
||||||
|
}
|
||||||
|
public void execute(ICommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh config <name> [value]"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String configName = args[1];
|
||||||
|
AbstractConfigBase<?> found = null;
|
||||||
|
for (AbstractConfigBase<?> entry : ConfigHandler.INSTANCE.configBaseList)
|
||||||
|
{
|
||||||
|
if (entry instanceof ConfigEntry && configName.equals(((ConfigEntry<?>) entry).getChatCommandName()))
|
||||||
|
{
|
||||||
|
found = entry;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Unknown config: " + configName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigEntry<?> configEntry = (ConfigEntry<?>) found;
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Current value of " + configName + " is " + configEntry.get()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String value = args[2];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
setConfigValue(configEntry, value);
|
||||||
|
sender.sendMessage(new TextComponentString("Changed " + configName + " to " + value));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Invalid value: " + value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
private static final List<CommandArgumentData<?>> commandArguments = Arrays.asList(
|
private static final List<CommandArgumentData<?>> commandArguments = Arrays.asList(
|
||||||
new CommandArgumentData<>(Integer.class, configEntry -> integer(configEntry.getMin(), configEntry.getMax()), IntegerArgumentType::getInteger),
|
new CommandArgumentData<>(Integer.class, configEntry -> integer(configEntry.getMin(), configEntry.getMax()), IntegerArgumentType::getInteger),
|
||||||
new CommandArgumentData<>(Double.class, configEntry -> doubleArg(configEntry.getMin(), configEntry.getMax()), DoubleArgumentType::getDouble),
|
new CommandArgumentData<>(Double.class, configEntry -> doubleArg(configEntry.getMin(), configEntry.getMax()), DoubleArgumentType::getDouble),
|
||||||
@@ -150,5 +221,6 @@ public class ConfigCommand extends AbstractCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,60 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||||
import com.seibel.distanthorizons.core.multiplayer.server.ServerPlayerState;
|
import com.seibel.distanthorizons.core.multiplayer.server.ServerPlayerState;
|
||||||
import com.seibel.distanthorizons.core.network.messages.base.CodecCrashMessage;
|
import com.seibel.distanthorizons.core.network.messages.base.CodecCrashMessage;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
#else
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
||||||
import static net.minecraft.commands.Commands.literal;
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
public class CrashCommand extends AbstractCommand
|
public class CrashCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public void execute(ICommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
if (!(sender instanceof EntityPlayerMP))
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("This command can only be run by a player"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh crash <encode|decode>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SharedApi.tryGetDhServerWorld() == null) return;
|
||||||
|
|
||||||
|
ServerPlayerState serverPlayerState = SharedApi.tryGetDhServerWorld()
|
||||||
|
.getServerPlayerStateManager()
|
||||||
|
.getConnectedPlayer(ServerPlayerWrapper.getWrapper((EntityPlayerMP) sender));
|
||||||
|
|
||||||
|
if (serverPlayerState == null) return;
|
||||||
|
|
||||||
|
switch (args[1])
|
||||||
|
{
|
||||||
|
case "encode":
|
||||||
|
serverPlayerState.networkSession.sendMessage(new CodecCrashMessage(CodecCrashMessage.ECrashPhase.ENCODE));
|
||||||
|
break;
|
||||||
|
case "decode":
|
||||||
|
serverPlayerState.networkSession.sendMessage(new CodecCrashMessage(CodecCrashMessage.ECrashPhase.DECODE));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh crash <encode|decode>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
@Override
|
@Override
|
||||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||||
{
|
{
|
||||||
@@ -40,5 +85,6 @@ public class CrashCommand extends AbstractCommand
|
|||||||
return 1;
|
return 1;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,44 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
#else
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.minecraft.commands.Commands.literal;
|
|
||||||
|
|
||||||
public class DebugCommand extends AbstractCommand
|
public class DebugCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
|
private static String getDebugString()
|
||||||
|
{
|
||||||
|
List<String> lines = new ArrayList<>();
|
||||||
|
F3Screen.addStringToDisplay(lines);
|
||||||
|
return String.join("\n", lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
@Override
|
@Override
|
||||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||||
{
|
{
|
||||||
return literal("debug")
|
return literal("debug")
|
||||||
.executes(c -> {
|
.executes(c -> {
|
||||||
List<String> lines = new ArrayList<>();
|
return this.sendSuccessResponse(c, getDebugString(), false);
|
||||||
F3Screen.addStringToDisplay(lines);
|
|
||||||
return this.sendSuccessResponse(c, String.join("\n", lines), false);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
public void execute(ICommandSender sender)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString(getDebugString()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+112
-8
@@ -1,27 +1,36 @@
|
|||||||
package com.seibel.distanthorizons.common.commands;
|
package com.seibel.distanthorizons.common.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||||
import com.seibel.distanthorizons.core.generation.PregenManager;
|
import com.seibel.distanthorizons.core.generation.PregenManager;
|
||||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D;
|
||||||
import com.seibel.distanthorizons.core.world.DhServerWorld;
|
import com.seibel.distanthorizons.core.world.DhServerWorld;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.command.ICommandSender;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
#else
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.DimensionArgument;
|
import net.minecraft.commands.arguments.DimensionArgument;
|
||||||
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
|
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
|
||||||
import net.minecraft.server.level.ColumnPos;
|
import net.minecraft.server.level.ColumnPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CancellationException;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||||
import static net.minecraft.commands.Commands.argument;
|
import static net.minecraft.commands.Commands.argument;
|
||||||
import static net.minecraft.commands.Commands.literal;
|
import static net.minecraft.commands.Commands.literal;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
public class PregenCommand extends AbstractCommand
|
public class PregenCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
@@ -31,6 +40,101 @@ public class PregenCommand extends AbstractCommand
|
|||||||
return world.getPregenManager();
|
return world.getPregenManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public void execute(MinecraftServer server, ICommandSender sender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh pregen <status|start|stop>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[1])
|
||||||
|
{
|
||||||
|
case "status":
|
||||||
|
{
|
||||||
|
String statusString = this.getPregenManager().getStatusString();
|
||||||
|
sender.sendMessage(new TextComponentString(
|
||||||
|
statusString != null ? statusString : "Pregen is not running"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "start":
|
||||||
|
{
|
||||||
|
if (args.length < 5)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Usage: /dh pregen start <dimension> <x> <z> <chunkRadius>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String dimensionName = args[2];
|
||||||
|
int x = Integer.parseInt(args[3]);
|
||||||
|
int z = Integer.parseInt(args[4]);
|
||||||
|
int chunkRadius = args.length >= 6 ? Integer.parseInt(args[5]) : 32;
|
||||||
|
|
||||||
|
// find the world by dimension name
|
||||||
|
WorldServer world = null;
|
||||||
|
for (WorldServer w : server.worlds)
|
||||||
|
{
|
||||||
|
if (w.provider.getDimensionType().getName().equals(dimensionName))
|
||||||
|
{
|
||||||
|
world = w;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Unknown dimension: " + dimensionName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(new TextComponentString("Starting pregen. Progress will be in the server console."));
|
||||||
|
|
||||||
|
final ICommandSender finalSender = sender;
|
||||||
|
CompletableFuture<Void> future = this.getPregenManager().startPregen(
|
||||||
|
ServerLevelWrapper.getWrapper(world),
|
||||||
|
new DhBlockPos2D(x, z),
|
||||||
|
chunkRadius
|
||||||
|
);
|
||||||
|
|
||||||
|
future.whenComplete((result, throwable) -> {
|
||||||
|
if (throwable instanceof CancellationException)
|
||||||
|
{
|
||||||
|
finalSender.sendMessage(new TextComponentString("Pregen is cancelled"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (throwable != null)
|
||||||
|
{
|
||||||
|
finalSender.sendMessage(new TextComponentString("Pregen failed: " + throwable.getMessage()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finalSender.sendMessage(new TextComponentString("Pregen is complete"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Invalid number format"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "stop":
|
||||||
|
{
|
||||||
|
CompletableFuture<Void> runningPregen = this.getPregenManager().getRunningPregen();
|
||||||
|
if (runningPregen == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(new TextComponentString("Pregen is not running"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
runningPregen.cancel(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
sender.sendMessage(new TextComponentString("Unknown subcommand: " + args[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
@Override
|
@Override
|
||||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||||
{
|
{
|
||||||
@@ -110,5 +214,5 @@ public class PregenCommand extends AbstractCommand
|
|||||||
runningPregen.cancel(true);
|
runningPregen.cancel(true);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-5
@@ -1,6 +1,7 @@
|
|||||||
package com.seibel.distanthorizons.common.commonMixins;
|
package com.seibel.distanthorizons.common.commonMixins;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.updater.UpdateModScreen;
|
import com.seibel.distanthorizons.common.wrappers.gui.updater.UpdateModScreen;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
@@ -9,19 +10,25 @@ import com.seibel.distanthorizons.core.jar.installer.ModrinthGetter;
|
|||||||
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
|
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
|
#else
|
||||||
import net.minecraft.client.gui.screens.TitleScreen;
|
import net.minecraft.client.gui.screens.TitleScreen;
|
||||||
|
#endif
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class DhUpdateScreenBase
|
public class DhUpdateScreenBase
|
||||||
{
|
{
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static final Minecraft MC = Minecraft.getMinecraft();
|
||||||
|
#else
|
||||||
private static final Minecraft MC = Minecraft.getInstance();
|
private static final Minecraft MC = Minecraft.getInstance();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
public static void tryShowUpdateScreenAndRunAutoUpdateStartup(Runnable runnable)
|
public static void tryShowUpdateScreenAndRunAutoUpdateStartup(Runnable runnable)
|
||||||
{
|
{
|
||||||
@@ -68,19 +75,31 @@ public class DhUpdateScreenBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// running on the render thread is required since setting the MC screen may trigger
|
||||||
|
// before its allowed, silently failing
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("Update Screen", () ->
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MC.setScreen(new UpdateModScreen(
|
#if MC_VER <= MC_1_12_2
|
||||||
|
DhScreenUtil.showScreen(new UpdateModScreen(
|
||||||
new TitleScreen(false),
|
new TitleScreen(false),
|
||||||
versionId
|
versionId
|
||||||
));
|
));
|
||||||
|
#else
|
||||||
|
DhScreenUtil.setScreen(new UpdateModScreen(
|
||||||
|
new TitleScreen(false),
|
||||||
|
versionId
|
||||||
|
));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// info instead of error since this can be ignored and probably just means
|
// info instead of error since this can be ignored and probably just means
|
||||||
// there isn't a new DH version available
|
// there isn't a new DH version available
|
||||||
LOGGER.info("Unable to show DH update screen, reason: ["+e.getMessage()+"].");
|
LOGGER.error("Unable to show DH update screen, reason: ["+e.getMessage()+"].");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-4
@@ -6,15 +6,23 @@ import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
|||||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
#else
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||||
|
#endif
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
public class MixinChunkMapCommon
|
public class MixinChunkMapCommon
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static void onChunkSave(WorldServer level, Chunk chunk)
|
||||||
|
#else
|
||||||
public static void onChunkSave(ServerLevel level, ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
public static void onChunkSave(ServerLevel level, ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
IServerLevelWrapper levelWrapper = ServerLevelWrapper.getWrapper(level);
|
IServerLevelWrapper levelWrapper = ServerLevelWrapper.getWrapper(level);
|
||||||
|
|
||||||
@@ -37,7 +45,7 @@ public class MixinChunkMapCommon
|
|||||||
|
|
||||||
|
|
||||||
// is this chunk being saved to disk?
|
// is this chunk being saved to disk?
|
||||||
boolean savingChunkToDisk = ci.getReturnValue();
|
boolean savingChunkToDisk = #if MC_VER <= MC_1_12_2 true #else ci.getReturnValue() #endif;
|
||||||
// true means a chunk was saved to disk
|
// true means a chunk was saved to disk
|
||||||
if (!savingChunkToDisk)
|
if (!savingChunkToDisk)
|
||||||
{
|
{
|
||||||
@@ -50,7 +58,12 @@ public class MixinChunkMapCommon
|
|||||||
|
|
||||||
// MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks)
|
// MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks)
|
||||||
// this logic should prevent that from happening
|
// this logic should prevent that from happening
|
||||||
#if MC_VER <= MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
if (!chunk.isTerrainPopulated() || !chunk.isLightPopulated())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#elif MC_VER <= MC_1_17_1
|
||||||
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -67,7 +80,12 @@ public class MixinChunkMapCommon
|
|||||||
// biome validation //
|
// biome validation //
|
||||||
|
|
||||||
// some chunks may be missing their biomes, which cause issues when attempting to save them
|
// some chunks may be missing their biomes, which cause issues when attempting to save them
|
||||||
#if MC_VER <= MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
if (chunk. getBiomeArray() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#elif MC_VER <= MC_1_17_1
|
||||||
if (chunk.getBiomes() == null)
|
if (chunk.getBiomes() == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
+127
@@ -0,0 +1,127 @@
|
|||||||
|
package com.seibel.distanthorizons.common.commonMixins;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
import net.minecraft.init.MobEffects;
|
||||||
|
#elif MC_VER < MC_1_17_1
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
#elif MC_VER < MC_1_21_3
|
||||||
|
import net.minecraft.world.level.material.FogType;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
#elif MC_VER < MC_1_21_6
|
||||||
|
import net.minecraft.world.level.material.FogType;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import com.mojang.blaze3d.shaders.FogShape;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer;
|
||||||
|
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||||
|
import net.minecraft.client.renderer.FogParameters;
|
||||||
|
import org.joml.Vector4f;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
#else
|
||||||
|
import net.minecraft.world.level.material.FogType;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
public class MixinVanillaFogCommon
|
||||||
|
{
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static boolean cancelFog(int startCoords, Minecraft mc)
|
||||||
|
#elif MC_VER < MC_1_21_6
|
||||||
|
public static boolean cancelFog(Camera camera, FogRenderer.FogMode fogMode)
|
||||||
|
#else
|
||||||
|
public static boolean cancelFog()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
EntityPlayerSP entity = mc.player;
|
||||||
|
#elif MC_VER < MC_1_21_6
|
||||||
|
Entity entity = camera.getEntity();
|
||||||
|
#elif MC_VER <= MC_1_21_10
|
||||||
|
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
|
||||||
|
Entity entity = camera.getEntity();
|
||||||
|
#elif MC_VER <= MC_26_1_2
|
||||||
|
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
|
||||||
|
Entity entity = camera.entity();
|
||||||
|
#else
|
||||||
|
Camera camera = Minecraft.getInstance().gameRenderer.mainCamera();
|
||||||
|
Entity entity = camera.entity();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
boolean cameraNotInFluid = cameraNotInFluid(mc);
|
||||||
|
#else
|
||||||
|
boolean cameraNotInFluid = cameraNotInFluid(camera);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
boolean isSpecialFog = entity.isPotionActive(MobEffects.BLINDNESS);
|
||||||
|
#else
|
||||||
|
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
boolean cancelFog = !isSpecialFog;
|
||||||
|
cancelFog = cancelFog && cameraNotInFluid;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
cancelFog = cancelFog && startCoords == 0; // 0 = terrain fog
|
||||||
|
#elif MC_VER < MC_1_21_6
|
||||||
|
cancelFog = cancelFog && (fogMode == FogRenderer.FogMode.FOG_TERRAIN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cancelFog = cancelFog && !SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class).isFogStateSpecial();
|
||||||
|
cancelFog = cancelFog && !Config.Client.Advanced.Graphics.Fog.enableVanillaFog.get();
|
||||||
|
|
||||||
|
|
||||||
|
return cancelFog;
|
||||||
|
}
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static boolean cameraNotInFluid(Minecraft mc)
|
||||||
|
#else
|
||||||
|
private static boolean cameraNotInFluid(Camera camera)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
boolean cameraNotInFluid = mc.getRenderViewEntity() != null && !mc.world.getBlockState(mc.getRenderViewEntity().getPosition()).getMaterial().isLiquid();
|
||||||
|
#elif MC_VER < MC_1_17_1
|
||||||
|
FluidState fluidState = camera.getFluidInCamera();
|
||||||
|
boolean cameraNotInFluid = fluidState.isEmpty();
|
||||||
|
#else
|
||||||
|
FogType fogTypes = camera.getFluidInCamera();
|
||||||
|
boolean cameraNotInFluid = fogTypes == FogType.NONE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return cameraNotInFluid;
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
-57
@@ -26,34 +26,30 @@ public class BlazeDebugWireframeRenderer {}
|
|||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import net.minecraft.resources.Identifier;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles rendering the wireframe particles
|
* Handles rendering the wireframe particles
|
||||||
@@ -64,11 +60,10 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
public static BlazeDebugWireframeRenderer INSTANCE = new BlazeDebugWireframeRenderer();
|
public static BlazeDebugWireframeRenderer INSTANCE = new BlazeDebugWireframeRenderer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** A box from 0,0,0 to 1,1,1 */
|
/** A box from 0,0,0 to 1,1,1 */
|
||||||
private static final float[] BOX_VERTICES = {
|
private static final float[] BOX_VERTICES = {
|
||||||
//region
|
//region
|
||||||
@@ -103,6 +98,7 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
//endregion
|
//endregion
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Mat4f TRANSFORM_MATRIX = new Mat4f();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +110,7 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
private GpuBuffer boxVertexBuffer;
|
private GpuBuffer boxVertexBuffer;
|
||||||
private GpuBuffer boxIndexBuffer;
|
private GpuBuffer boxIndexBuffer;
|
||||||
|
|
||||||
private GpuBuffer uniformBuffer;
|
private final BlazeUniformBufferWrapper uniformBufferWrapper = new BlazeUniformBufferWrapper("debugWireframeUniformBlock");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +139,14 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
{
|
{
|
||||||
pipelineBuilder.withFaceCulling(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(true);
|
pipelineBuilder.withDepthWrite(true);
|
||||||
|
if (RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.FORWARD_Z)
|
||||||
|
{
|
||||||
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.GREATER);
|
||||||
|
}
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.WIREFRAME);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.WIREFRAME);
|
||||||
@@ -155,7 +158,7 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
pipelineBuilder.withUniformBuffer("uniformBlock");
|
pipelineBuilder.withUniformBuffer("uniformBlock");
|
||||||
|
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
||||||
.build();
|
.build();
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat);
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
@@ -181,7 +184,7 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_VERTEX;
|
| GpuBuffer.USAGE_VERTEX;
|
||||||
int size = BOX_VERTICES.length * Float.BYTES;
|
int size = BOX_VERTICES.length * Float.BYTES;
|
||||||
this.boxVertexBuffer = GPU_DEVICE.createBuffer(() -> "distantHorizons:McDebugWireframeBox", usage, size);
|
this.boxVertexBuffer = GPU_DEVICE.createBuffer(() -> "distantHorizons:DebugWireframeBox", usage, size);
|
||||||
|
|
||||||
{
|
{
|
||||||
int length = BOX_VERTICES.length * Float.BYTES;
|
int length = BOX_VERTICES.length * Float.BYTES;
|
||||||
@@ -251,14 +254,7 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putMat4f() // uTransform
|
|
||||||
.putVec4() // uColor
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
Vec3d camPos = MC_RENDER.getCameraExactPosition();
|
Vec3d camPos = MC_RENDER.getCameraExactPosition();
|
||||||
Vec3f camPosFloatThisFrame = new Vec3f((float) camPos.x, (float) camPos.y, (float) camPos.z);
|
Vec3f camPosFloatThisFrame = new Vec3f((float) camPos.x, (float) camPos.y, (float) camPos.z);
|
||||||
|
|
||||||
@@ -271,57 +267,43 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
box.maxPos.y - box.minPos.y,
|
box.maxPos.y - box.minPos.y,
|
||||||
box.maxPos.z - box.minPos.z));
|
box.maxPos.z - box.minPos.z));
|
||||||
|
|
||||||
Mat4f transformMatrix = this.dhMvmProjMatrixThisFrame.copy();
|
TRANSFORM_MATRIX.set(this.dhMvmProjMatrixThisFrame);
|
||||||
transformMatrix.multiply(boxTransform);
|
TRANSFORM_MATRIX.multiply(boxTransform);
|
||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
this.uniformBufferWrapper
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
.putMat4f(TRANSFORM_MATRIX) // uTransform
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
.putVec4f(
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putMat4f(transformMatrix.createJomlMatrix()) // uTransform
|
|
||||||
.putVec4(
|
|
||||||
box.color.getRed() / 255.0f,
|
box.color.getRed() / 255.0f,
|
||||||
box.color.getGreen() / 255.0f,
|
box.color.getGreen() / 255.0f,
|
||||||
box.color.getBlue() / 255.0f,
|
box.color.getBlue() / 255.0f,
|
||||||
box.color.getAlpha() / 255.0f) // uColor
|
box.color.getAlpha() / 255.0f) // uColor
|
||||||
.get()
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.uniformBuffer = BlazeUniformUtil.createBuffer("uniformBlock", uniformBufferSize, this.uniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.uniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
commandEncoder.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render //
|
// render //
|
||||||
|
|
||||||
//try (RenderPass renderPass = commandEncoder.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
// this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
// BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper,
|
||||||
// /*optionalClearColorAsInt*/ OptionalInt.empty(),
|
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper))
|
||||||
// BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
{
|
||||||
// /*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
// Bind instance data //
|
||||||
//{
|
renderPassWrapper.setUniform("uniformBlock", this.uniformBufferWrapper);
|
||||||
// // Bind instance data //
|
|
||||||
// renderPass.setUniform("uniformBlock", this.uniformBuffer);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
//
|
renderPassWrapper.setIndexBuffer(this.boxIndexBuffer);
|
||||||
// renderPass.setPipeline(this.pipeline);
|
|
||||||
// renderPass.setIndexBuffer(this.boxIndexBuffer, VertexFormat.IndexType.INT);
|
renderPassWrapper.setVertexBuffer(this.boxVertexBuffer);
|
||||||
//
|
|
||||||
// renderPass.setVertexBuffer(0, this.boxVertexBuffer);
|
renderPassWrapper.drawIndexed(BOX_OUTLINE_INDICES.length);
|
||||||
//
|
|
||||||
// renderPass.drawIndexed(
|
|
||||||
// /*indexStart*/ 0,
|
|
||||||
// /*firstIndex*/0,
|
|
||||||
// /*indexCount*/BOX_OUTLINE_INDICES.length,
|
|
||||||
// /*instanceCount*/1);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McDebugRenderer"; }
|
}
|
||||||
|
private String getRenderPassName() { return "distantHorizons:DebugRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|||||||
+74
-85
@@ -24,17 +24,10 @@ public class BlazeDhGenericObjectRenderer {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
|
||||||
@@ -43,21 +36,27 @@ import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup
|
|||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericObjectRenderEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericObjectRenderEvent;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericRenderCleanupEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericRenderCleanupEvent;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericRenderSetupEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeGenericRenderSetupEvent;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
|
||||||
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.objects.BlazeGenericObjectVertexContainer;
|
import com.seibel.distanthorizons.common.render.blaze.objects.BlazeGenericObjectVertexContainer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.GenericRenderObjectFactory;
|
import com.seibel.distanthorizons.core.render.renderer.GenericRenderObjectFactory;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.RenderableBoxGroup;
|
import com.seibel.distanthorizons.core.render.renderer.RenderableBoxGroup;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
@@ -68,15 +67,10 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrap
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhGenericRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhGenericRenderer;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +84,7 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
@@ -102,6 +97,10 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
*/
|
*/
|
||||||
public static final boolean RENDER_DEBUG_OBJECTS = false;
|
public static final boolean RENDER_DEBUG_OBJECTS = false;
|
||||||
|
|
||||||
|
private static final DhApiBeforeGenericObjectRenderEvent.EventParam EVENT_PARAM = new DhApiBeforeGenericObjectRenderEvent.EventParam();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final ConcurrentHashMap<Long, RenderableBoxGroup> boxGroupById = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Long, RenderableBoxGroup> boxGroupById = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
|
|
||||||
private GpuBuffer vertUniformBuffer;
|
private final BlazeUniformBufferWrapper vertUniformBufferWrapper = new BlazeUniformBufferWrapper("vertUniformBlock");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -142,7 +141,14 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
{
|
{
|
||||||
pipelineBuilder.withFaceCulling(true);
|
pipelineBuilder.withFaceCulling(true);
|
||||||
pipelineBuilder.withDepthWrite(true);
|
pipelineBuilder.withDepthWrite(true);
|
||||||
|
if (RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.FORWARD_Z)
|
||||||
|
{
|
||||||
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.GREATER);
|
||||||
|
}
|
||||||
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT); // TRANSLUCENT = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT); // TRANSLUCENT = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
@@ -155,7 +161,7 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
pipelineBuilder.withUniformBuffer("vertUniformBlock");
|
pipelineBuilder.withUniformBuffer("vertUniformBlock");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
||||||
.add("aColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
.add("aColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
||||||
.add("aMaterial", BlazeDhVertexFormatUtil.IRIS_MATERIAL)
|
.add("aMaterial", BlazeDhVertexFormatUtil.IRIS_MATERIAL)
|
||||||
@@ -330,16 +336,19 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void render(RenderParams renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao)
|
public void render(RenderParams renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
try (IProfilerWrapper.IProfileBlock generic_profile = profiler.push("setup"))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
//==============//
|
//==============//
|
||||||
// render setup //
|
// render setup //
|
||||||
//==============//
|
//==============//
|
||||||
//#region
|
//#region
|
||||||
|
|
||||||
profiler.push("setup");
|
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam.apiCopy);
|
||||||
|
|
||||||
Vec3d camPos = MC_RENDER.getCameraExactPosition();
|
Vec3d camPos = MC_RENDER.getCameraExactPosition();
|
||||||
|
|
||||||
@@ -385,7 +394,8 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allow API users to cancel this object's rendering
|
// allow API users to cancel this object's rendering
|
||||||
boolean cancelRendering = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericObjectRenderEvent.class, new DhApiBeforeGenericObjectRenderEvent.EventParam(renderEventParam, boxGroup));
|
EVENT_PARAM.update(renderEventParam, boxGroup);
|
||||||
|
boolean cancelRendering = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericObjectRenderEvent.class, EVENT_PARAM);
|
||||||
if (cancelRendering)
|
if (cancelRendering)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -411,28 +421,6 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putIVec3() // uOffsetChunk
|
|
||||||
.putVec3() // uOffsetSubChunk
|
|
||||||
.putIVec3() // uCameraPosChunk
|
|
||||||
.putVec3() // uCameraPosSubChunk
|
|
||||||
|
|
||||||
.putVec3() // aTranslateChunk
|
|
||||||
.putVec3() // aTranslateSubChunk
|
|
||||||
|
|
||||||
.putMat4f() // uProjectionMvm
|
|
||||||
.putInt() // uSkyLight
|
|
||||||
.putInt() // uBlockLight
|
|
||||||
|
|
||||||
.putFloat() // uNorthShading
|
|
||||||
.putFloat() // uSouthShading
|
|
||||||
.putFloat() // uEastShading
|
|
||||||
.putFloat() // uWestShading
|
|
||||||
.putFloat() // uTopShading
|
|
||||||
.putFloat() // uBottomShading
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
Mat4f projectionMvmMatrix = new Mat4f(renderEventParam.dhProjectionMatrix);
|
Mat4f projectionMvmMatrix = new Mat4f(renderEventParam.dhProjectionMatrix);
|
||||||
@@ -441,31 +429,29 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
this.vertUniformBufferWrapper
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
.putVec3i(
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putIVec3(
|
|
||||||
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
|
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
|
||||||
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
|
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
|
||||||
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
|
LodUtil.getChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
|
||||||
) // uOffsetChunk
|
) // uOffsetChunk
|
||||||
.putVec3(
|
.putVec3f(
|
||||||
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
|
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().x),
|
||||||
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
|
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().y),
|
||||||
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
|
LodUtil.getSubChunkPosFromDouble(boxGroup.getOriginBlockPos().z)
|
||||||
) // uOffsetSubChunk
|
) // uOffsetSubChunk
|
||||||
.putIVec3(
|
.putVec3i(
|
||||||
LodUtil.getChunkPosFromDouble(camPos.x),
|
LodUtil.getChunkPosFromDouble(camPos.x),
|
||||||
LodUtil.getChunkPosFromDouble(camPos.y),
|
LodUtil.getChunkPosFromDouble(camPos.y),
|
||||||
LodUtil.getChunkPosFromDouble(camPos.z)
|
LodUtil.getChunkPosFromDouble(camPos.z)
|
||||||
) // uCameraPosChunk
|
) // uCameraPosChunk
|
||||||
.putVec3(
|
.putVec3f(
|
||||||
LodUtil.getSubChunkPosFromDouble(camPos.x),
|
LodUtil.getSubChunkPosFromDouble(camPos.x),
|
||||||
LodUtil.getSubChunkPosFromDouble(camPos.y),
|
LodUtil.getSubChunkPosFromDouble(camPos.y),
|
||||||
LodUtil.getSubChunkPosFromDouble(camPos.z)
|
LodUtil.getSubChunkPosFromDouble(camPos.z)
|
||||||
) // uCameraPosSubChunk
|
) // uCameraPosSubChunk
|
||||||
|
|
||||||
.putMat4f(projectionMvmMatrix.createJomlMatrix()) // uProjectionMvm
|
.putMat4f(projectionMvmMatrix) // uProjectionMvm
|
||||||
.putInt(boxGroup.getSkyLight()) // uSkyLight
|
.putInt(boxGroup.getSkyLight()) // uSkyLight
|
||||||
.putInt(boxGroup.getBlockLight()) // uBlockLight
|
.putInt(boxGroup.getBlockLight()) // uBlockLight
|
||||||
|
|
||||||
@@ -476,13 +462,8 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
.putFloat(shading.top)
|
.putFloat(shading.top)
|
||||||
.putFloat(shading.bottom)
|
.putFloat(shading.bottom)
|
||||||
|
|
||||||
.get()
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.vertUniformBuffer = BlazeUniformUtil.createBuffer("vertUniformBlock", uniformBufferSize, this.vertUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vertUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -491,13 +472,11 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
// render //
|
// render //
|
||||||
|
|
||||||
profiler.popPush("rendering");
|
profiler.popPush("rendering");
|
||||||
profiler.push(boxGroup.getResourceLocationNamespace());
|
try (IProfilerWrapper.IProfileBlock namespace_profile = profiler.push(boxGroup.getResourceLocationNamespace());
|
||||||
profiler.push(boxGroup.getResourceLocationPath());
|
IProfilerWrapper.IProfileBlock location_profile = profiler.push(boxGroup.getResourceLocationPath()))
|
||||||
|
{
|
||||||
this.renderBoxGroupInstanced(renderEventParam, boxGroup, profiler);
|
this.renderBoxGroupInstanced(renderEventParam, boxGroup, profiler);
|
||||||
|
}
|
||||||
profiler.pop(); // resource path
|
|
||||||
profiler.pop(); // resource namespace
|
|
||||||
|
|
||||||
boxGroup.postRender(renderEventParam);
|
boxGroup.postRender(renderEventParam);
|
||||||
}
|
}
|
||||||
@@ -515,11 +494,10 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderCleanupEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderCleanupEvent.class, renderEventParam);
|
||||||
|
|
||||||
profiler.pop();
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McGenericObjectRenderer"; }
|
}
|
||||||
|
private String getRenderPassName() { return "distantHorizons:GenericObjectRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@@ -535,51 +513,40 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
RenderableBoxGroup boxGroup,
|
RenderableBoxGroup boxGroup,
|
||||||
IProfilerWrapper profiler)
|
IProfilerWrapper profiler)
|
||||||
{
|
{
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper))
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// update instance data //
|
// update instance data //
|
||||||
|
|
||||||
profiler.push("vertex setup");
|
|
||||||
|
|
||||||
BlazeGenericObjectVertexContainer container = (BlazeGenericObjectVertexContainer) boxGroup.vertexBufferContainer;
|
BlazeGenericObjectVertexContainer container = (BlazeGenericObjectVertexContainer) boxGroup.vertexBufferContainer;
|
||||||
|
|
||||||
LightMapWrapper lightMapWrapper = (LightMapWrapper) renderEventParam.lightmap;
|
LightMapWrapper lightMapWrapper = (LightMapWrapper) renderEventParam.lightmap;
|
||||||
BlazeTextureViewWrapper lightmapTextureViewWrapper = lightMapWrapper.getTextureViewWrapper();
|
BlazeTextureViewWrapper lightmapTextureViewWrapper = lightMapWrapper.getTextureViewWrapper();
|
||||||
renderPass.bindTexture("uLightMap", lightmapTextureViewWrapper.textureView, lightmapTextureViewWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uLightMap", lightmapTextureViewWrapper);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Bind instance data //
|
// Bind instance data //
|
||||||
profiler.popPush("binding");
|
|
||||||
|
|
||||||
|
|
||||||
renderPass.setUniform("vertUniformBlock", this.vertUniformBuffer);
|
renderPassWrapper.setUniform("vertUniformBlock", this.vertUniformBufferWrapper);
|
||||||
|
|
||||||
// set pipeline
|
// set pipeline
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
renderPass.setIndexBuffer(container.indexGpuBuffer, VertexFormat.IndexType.INT);
|
renderPassWrapper.setIndexBuffer(container.indexGpuBuffer);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, container.vboGpuBuffer);
|
renderPassWrapper.setVertexBuffer(container.vboGpuBuffer);
|
||||||
|
|
||||||
// Draw instanced
|
// Draw instanced
|
||||||
profiler.popPush("render");
|
|
||||||
if (container.uploadedBoxCount > 0)
|
if (container.uploadedBoxCount > 0)
|
||||||
{
|
{
|
||||||
renderPass.drawIndexed(
|
// 36 = 6 faces * 6 verticies per face
|
||||||
/*indexStart*/ 0,
|
renderPassWrapper.drawIndexed(container.uploadedBoxCount * 36);
|
||||||
/*firstIndex*/0,
|
|
||||||
/*indexCount*/container.uploadedBoxCount * 36, // 36 = 6 faces * 6 verticies per face
|
|
||||||
/*instanceCount*/1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -620,5 +587,27 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
// close is called outside the render thread and buffer closing must be done on the render thread
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("Generic Obj Cleanup", () ->
|
||||||
|
{
|
||||||
|
if (this.vertUniformBufferWrapper != null)
|
||||||
|
{
|
||||||
|
this.vertUniformBufferWrapper.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+31
-6
@@ -6,13 +6,18 @@ public class BlazeDhMetaRenderer {}
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.textures.GpuTexture;
|
import com.mojang.blaze3d.textures.GpuTexture;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterColorDepthTextureCreatedEvent;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
||||||
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -25,6 +30,7 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
|
|
||||||
private BlazeDhApplyRenderer applyRenderer;
|
private BlazeDhApplyRenderer applyRenderer;
|
||||||
|
private final float clearDepth;
|
||||||
|
|
||||||
public final BlazeTextureWrapper dhDepthTextureWrapper = BlazeTextureWrapper.createDepth("DhDepthTexture");
|
public final BlazeTextureWrapper dhDepthTextureWrapper = BlazeTextureWrapper.createDepth("DhDepthTexture");
|
||||||
public final BlazeTextureWrapper dhColorTextureWrapper = BlazeTextureWrapper.createColor("DhColorTexture");
|
public final BlazeTextureWrapper dhColorTextureWrapper = BlazeTextureWrapper.createColor("DhColorTexture");
|
||||||
@@ -38,6 +44,9 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
private BlazeDhMetaRenderer()
|
private BlazeDhMetaRenderer()
|
||||||
{
|
{
|
||||||
|
AbstractDhRenderApiDefinition renderApiDefinition = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
this.clearDepth = renderApiDefinition.getRenderDepth().farDepth;
|
||||||
|
|
||||||
this.applyRenderer = new BlazeDhApplyRenderer(
|
this.applyRenderer = new BlazeDhApplyRenderer(
|
||||||
"dh_apply_to_mc",
|
"dh_apply_to_mc",
|
||||||
null,
|
null,
|
||||||
@@ -57,9 +66,24 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void runRenderPassSetup(RenderParams renderParams)
|
public void runRenderPassSetup(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
// textures
|
int oldWidth = this.dhDepthTextureWrapper.getWidth();
|
||||||
this.dhDepthTextureWrapper.tryCreateOrResize();
|
int oldHeight = this.dhDepthTextureWrapper.getHeight();
|
||||||
this.dhColorTextureWrapper.tryCreateOrResize();
|
|
||||||
|
boolean texturesChanged = false;
|
||||||
|
texturesChanged = this.dhDepthTextureWrapper.tryCreateOrResize() | texturesChanged;
|
||||||
|
texturesChanged = this.dhColorTextureWrapper.tryCreateOrResize() | texturesChanged;
|
||||||
|
|
||||||
|
if (texturesChanged)
|
||||||
|
{
|
||||||
|
int newTextureWidth = MC_RENDER.getTargetFramebufferViewportWidth();
|
||||||
|
int newTextureHeight = MC_RENDER.getTargetFramebufferViewportHeight();
|
||||||
|
|
||||||
|
DhApiTextureCreatedParam textureCreatedParam = new DhApiTextureCreatedParam(
|
||||||
|
oldWidth, oldHeight,
|
||||||
|
newTextureWidth, newTextureHeight
|
||||||
|
);
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterColorDepthTextureCreatedEvent.class, textureCreatedParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,7 +92,7 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void applyToMcTexture(RenderParams renderParams)
|
public void applyToMcTexture(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
GpuTexture mcColorTexture = Minecraft.getInstance().getMainRenderTarget().getColorTexture();
|
GpuTexture mcColorTexture = MinecraftRenderWrapper.INSTANCE.getRenderTarget().getColorTexture();
|
||||||
this.applyRenderer.render(this.dhColorTextureWrapper.texture, this.dhDepthTextureWrapper.texture, mcColorTexture);
|
this.applyRenderer.render(this.dhColorTextureWrapper.texture, this.dhDepthTextureWrapper.texture, mcColorTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +108,7 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
this.dhDepthTextureWrapper.clearDepth(1.0f);
|
this.dhDepthTextureWrapper.clearDepth(this.clearDepth);
|
||||||
|
|
||||||
Color color = MC_RENDER.getSkyColor();
|
Color color = MC_RENDER.getSkyColor();
|
||||||
this.dhColorTextureWrapper.clearColor(ColorUtil.toColorInt(color));
|
this.dhColorTextureWrapper.clearColor(ColorUtil.toColorInt(color));
|
||||||
@@ -93,5 +117,6 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+45
-1
@@ -5,6 +5,8 @@ public class BlazeDhRenderApiDefinition {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingApi;
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.objects.BlazeGenericObjectVertexContainer;
|
import com.seibel.distanthorizons.common.render.blaze.objects.BlazeGenericObjectVertexContainer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeDhFarFadeRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeDhFarFadeRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeDhFogRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeDhFogRenderer;
|
||||||
@@ -13,6 +15,8 @@ import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeVanill
|
|||||||
import com.seibel.distanthorizons.common.render.blaze.test.BlazeDhTestTriangleRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.test.BlazeDhTestTriangleRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||||
@@ -20,6 +24,10 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodCont
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.*;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.*;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
|
||||||
public class BlazeDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
public class BlazeDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
||||||
{
|
{
|
||||||
//=========//
|
//=========//
|
||||||
@@ -27,7 +35,43 @@ public class BlazeDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
|||||||
//=========//
|
//=========//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
public String getApiName() { return "Blaze3D"; }
|
private final String apiName;
|
||||||
|
public String getApiName() { return this.apiName; }
|
||||||
|
|
||||||
|
public EDhRenderDepth getRenderDepth()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
return EDhRenderDepth.FORWARD_Z;
|
||||||
|
#else
|
||||||
|
return EDhRenderDepth.REVERSE_Z;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final EDhApiRenderingApi renderApi;
|
||||||
|
public EDhApiRenderingApi getRenderApi() { return renderApi; }
|
||||||
|
public boolean isNativeRenderer() { return false; }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public BlazeDhRenderApiDefinition()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
renderApi = EDhApiRenderingApi.OPEN_GL;
|
||||||
|
#else
|
||||||
|
// use the same rendering API as Minecraft
|
||||||
|
this.renderApi = MinecraftRenderWrapper.INSTANCE.getMcRenderingApi();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this.apiName = "Blaze3D: " + this.getRenderApi();
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|||||||
+74
-103
@@ -5,32 +5,31 @@ public class BlazeDhTerrainRenderer {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeBufferRenderEvent;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeBufferRenderEvent;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeRenderPassEvent;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
@@ -38,34 +37,34 @@ import com.seibel.distanthorizons.core.util.math.Vec3d;
|
|||||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||||
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
|
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhTerrainRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhTerrainRenderer;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/** Renders rendering DH's LOD terrain. */
|
/** Renders rendering DH's LOD terrain. */
|
||||||
public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
|
||||||
public static final BlazeDhTerrainRenderer INSTANCE = new BlazeDhTerrainRenderer();
|
public static final BlazeDhTerrainRenderer INSTANCE = new BlazeDhTerrainRenderer();
|
||||||
|
|
||||||
|
private static final Vec3f MODEL_POS = new Vec3f();
|
||||||
|
/** single event object used to reduce GC pressure */
|
||||||
|
private static final DhApiBeforeBufferRenderEvent.EventParam BEFORE_BUFFER_RENDER_EVENT_PARAM = new DhApiBeforeBufferRenderEvent.EventParam();
|
||||||
|
|
||||||
|
|
||||||
private RenderPipeline opaquePipeline;
|
private RenderPipeline opaquePipeline;
|
||||||
private RenderPipeline transparentPipeline;
|
private RenderPipeline transparentPipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("fragUniformBlock");
|
||||||
private GpuBuffer vertSharedUniformBuffer;
|
private final BlazeUniformBufferWrapper vertSharedUniformBufferWrapper = new BlazeUniformBufferWrapper("vertSharedUniformBlock");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -85,14 +84,28 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
RenderPipelineBuilderWrapper opaquePipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
|
RenderPipelineBuilderWrapper translucentPipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
|
|
||||||
|
// apply shared options to both pipelines
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
|
RenderPipelineBuilderWrapper pipelineBuilder = (i == 0)
|
||||||
|
? opaquePipelineBuilder
|
||||||
|
: translucentPipelineBuilder;
|
||||||
|
|
||||||
pipelineBuilder.withFaceCulling(true);
|
pipelineBuilder.withFaceCulling(true);
|
||||||
pipelineBuilder.withDepthWrite(true);
|
pipelineBuilder.withDepthWrite(true);
|
||||||
|
if (RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.FORWARD_Z)
|
||||||
|
{
|
||||||
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.GREATER);
|
||||||
|
}
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withName("terrain");
|
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uLightMap");
|
pipelineBuilder.withSampler("uLightMap");
|
||||||
|
|
||||||
@@ -103,7 +116,7 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
pipelineBuilder.withUniformBuffer("vertSharedUniformBlock");
|
pipelineBuilder.withUniformBuffer("vertSharedUniformBlock");
|
||||||
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SHORT_XYZ_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SHORT_XYZ_POS)
|
||||||
.add("meta", BlazeDhVertexFormatUtil.META)
|
.add("meta", BlazeDhVertexFormatUtil.META)
|
||||||
.add("vColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
.add("vColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
||||||
@@ -119,15 +132,17 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
// opaque
|
// opaque
|
||||||
{
|
{
|
||||||
pipelineBuilder.withoutBlend();
|
opaquePipelineBuilder.withName("opaque_terrain");
|
||||||
this.opaquePipeline = pipelineBuilder.build();
|
opaquePipelineBuilder.withoutBlend();
|
||||||
|
this.opaquePipeline = opaquePipelineBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// transparent
|
// transparent
|
||||||
{
|
{
|
||||||
|
translucentPipelineBuilder.withName("transparent_terrain");
|
||||||
// TRANSLUCENT = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
// TRANSLUCENT = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT);
|
translucentPipelineBuilder.withBlend(BlendFunction.TRANSLUCENT);
|
||||||
this.transparentPipeline = pipelineBuilder.build();
|
this.transparentPipeline = translucentPipelineBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init = true;
|
this.init = true;
|
||||||
@@ -151,15 +166,16 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
|
try(IProfilerWrapper.IProfileBlock terrain_profile = profiler.push("terrain render"))
|
||||||
profiler.push("vert unique uniforms");
|
{
|
||||||
|
profiler.popPush("vert unique uniforms");
|
||||||
{
|
{
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
||||||
{
|
{
|
||||||
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
||||||
bufferContainer.uniformContainer.tryUpload();
|
bufferContainer.uniformContainer.tryUpload(bufferContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,53 +198,25 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
int i = Config.Client.Advanced.Debugging.enableWhiteWorld.get() ? 1 : 0;
|
||||||
.putInt() // uIsWhiteWorld
|
|
||||||
|
|
||||||
.putFloat() // uWorldYOffset
|
this.vertSharedUniformBufferWrapper
|
||||||
.putFloat() // uMircoOffset
|
.putInt(i) // uIsWhiteWorld
|
||||||
.putFloat() // uEarthRadius
|
|
||||||
|
|
||||||
.putVec3() // uCameraPos
|
|
||||||
.putMat4f() // uCombinedMatrix
|
|
||||||
.get();
|
|
||||||
|
|
||||||
ByteBuffer buffer = MemoryUtil.memAlloc(uniformBufferSize);
|
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
Std140Builder.intoBuffer(buffer)
|
|
||||||
.putInt(0) // uIsWhiteWorld
|
|
||||||
|
|
||||||
.putFloat((float) renderEventParam.worldYOffset) // uWorldYOffset
|
.putFloat((float) renderEventParam.worldYOffset) // uWorldYOffset
|
||||||
.putFloat(0.01f) // uMircoOffset // 0.01 block offset
|
.putFloat(0.01f) // uMircoOffset // 0.01 block offset
|
||||||
.putFloat(earthCurveRatio) // uEarthRadius
|
.putFloat(earthCurveRatio) // uEarthRadius
|
||||||
|
|
||||||
.putVec3(
|
.putVec3f(
|
||||||
(float)renderEventParam.exactCameraPosition.x,
|
(float) renderEventParam.exactCameraPosition.x,
|
||||||
(float)renderEventParam.exactCameraPosition.y,
|
(float) renderEventParam.exactCameraPosition.y,
|
||||||
(float)renderEventParam.exactCameraPosition.z) // uCameraPos
|
(float) renderEventParam.exactCameraPosition.z) // uCameraPos
|
||||||
.putMat4f(combinedMatrix.createJomlMatrix()) // uCombinedMatrix
|
.putMat4f(combinedMatrix) // uCombinedMatrix
|
||||||
.get();
|
.finishAndUpload();
|
||||||
|
|
||||||
this.vertSharedUniformBuffer = BlazeUniformUtil.createBuffer("vertSharedUniformBlock", uniformBufferSize, this.vertSharedUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vertSharedUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
|
|
||||||
MemoryUtil.memFree(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.popPush("set frag uniforms");
|
profiler.popPush("set frag uniforms");
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putFloat() // uClipDistance
|
|
||||||
.putFloat() // uNoiseIntensity
|
|
||||||
.putInt() // uNoiseSteps
|
|
||||||
.putInt() // uNoiseDropoff
|
|
||||||
.putInt() // uDitherDhRendering
|
|
||||||
.putInt() // uNoiseEnabled
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
|
float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
|
||||||
@@ -240,60 +228,49 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
this.fragUniformBufferWrapper
|
||||||
ByteBuffer buffer = MemoryUtil.memAlloc(uniformBufferSize);
|
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putFloat(dhNearClipDistance) // uClipDistance
|
.putFloat(dhNearClipDistance) // uClipDistance
|
||||||
.putFloat(Config.Client.Advanced.Graphics.NoiseTexture.noiseIntensity.get()) // uNoiseIntensity
|
.putFloat(Config.Client.Advanced.Graphics.NoiseTexture.noiseIntensity.get()) // uNoiseIntensity
|
||||||
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.noiseSteps.get()) // uNoiseSteps
|
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.noiseSteps.get()) // uNoiseSteps
|
||||||
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.noiseDropoff.get()) // uNoiseDropoff
|
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.noiseDropoff.get()) // uNoiseDropoff
|
||||||
.putInt(Config.Client.Advanced.Graphics.Quality.ditherDhFade.get() ? 1 : 0) // uDitherDhRendering
|
.putInt(Config.Client.Advanced.Graphics.Quality.ditherDhFade.get() ? 1 : 0) // uDitherDhRendering
|
||||||
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.enableNoiseTexture.get() ? 1 : 0) // uNoiseEnabled
|
.putInt(Config.Client.Advanced.Graphics.NoiseTexture.enableNoiseTexture.get() ? 1 : 0) // uNoiseEnabled
|
||||||
.get()
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.fragUniformBuffer = BlazeUniformUtil.createBuffer("fragUniformBlock", uniformBufferSize, this.fragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
MemoryUtil.memFree(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render pass setup
|
// render pass setup
|
||||||
{
|
{
|
||||||
profiler.popPush("setup");
|
profiler.popPush("rendering");
|
||||||
|
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam.apiCopy);
|
||||||
|
|
||||||
// create a render pass
|
// create a render pass
|
||||||
try(RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper)
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty())
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LightMapWrapper lightMapWrapper = (LightMapWrapper) renderEventParam.lightmap;
|
LightMapWrapper lightMapWrapper = (LightMapWrapper) renderEventParam.lightmap;
|
||||||
BlazeTextureViewWrapper lightmapTextureViewWrapper = lightMapWrapper.getTextureViewWrapper();
|
BlazeTextureViewWrapper lightmapTextureViewWrapper = lightMapWrapper.getTextureViewWrapper();
|
||||||
renderPass.bindTexture("uLightMap", lightmapTextureViewWrapper.textureView, lightmapTextureViewWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uLightMap", lightmapTextureViewWrapper);
|
||||||
|
|
||||||
// set pipeline
|
// set pipeline
|
||||||
renderPass.setPipeline(opaquePass ? this.opaquePipeline : this.transparentPipeline);
|
renderPassWrapper.setPipeline(opaquePass ? this.opaquePipeline : this.transparentPipeline);
|
||||||
|
|
||||||
// shared uniforms
|
// shared uniforms
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPassWrapper.setUniform("fragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
renderPass.setUniform("vertSharedUniformBlock", this.vertSharedUniformBuffer);
|
renderPassWrapper.setUniform("vertSharedUniformBlock", this.vertSharedUniformBufferWrapper);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
||||||
{
|
{
|
||||||
profiler.popPush("binding");
|
|
||||||
|
|
||||||
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
||||||
BlazeLodUniformBufferWrapper uniformWrapper = (BlazeLodUniformBufferWrapper)bufferContainer.uniformContainer;
|
BlazeLodUniformBufferWrapper uniformWrapper = (BlazeLodUniformBufferWrapper) bufferContainer.uniformContainer;
|
||||||
|
|
||||||
boolean columnBuilderDebugEnabled = Config.Client.Advanced.Debugging.ColumnBuilderDebugging.columnBuilderDebugEnable.get();
|
boolean columnBuilderDebugEnabled = Config.Client.Advanced.Debugging.ColumnBuilderDebugging.columnBuilderDebugEnable.get();
|
||||||
if (columnBuilderDebugEnabled)
|
if (columnBuilderDebugEnabled)
|
||||||
@@ -310,12 +287,10 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPass.setUniform("vertUniqueUniformBlock", uniformWrapper.gpuBuffer);
|
renderPassWrapper.setUniform("vertUniqueUniformBlock", uniformWrapper);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
profiler.popPush("rendering");
|
|
||||||
|
|
||||||
// render each buffer
|
// render each buffer
|
||||||
IVertexBufferWrapper[] bufferWrapperList = opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers;
|
IVertexBufferWrapper[] bufferWrapperList = opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers;
|
||||||
for (int i = 0; i < bufferWrapperList.length; i++)
|
for (int i = 0; i < bufferWrapperList.length; i++)
|
||||||
@@ -330,34 +305,30 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
// fire render event
|
// fire render event
|
||||||
{
|
{
|
||||||
Vec3d camPos = renderEventParam.exactCameraPosition;
|
Vec3d camPos = renderEventParam.exactCameraPosition;
|
||||||
Vec3f modelPos = new Vec3f(
|
MODEL_POS.set(
|
||||||
(float) (bufferContainer.minCornerBlockPos.getX() - camPos.x),
|
(float) (bufferContainer.minCornerBlockPos.getX() - camPos.x),
|
||||||
(float) (bufferContainer.minCornerBlockPos.getY() - camPos.y),
|
(float) (bufferContainer.minCornerBlockPos.getY() - camPos.y),
|
||||||
(float) (bufferContainer.minCornerBlockPos.getZ() - camPos.z));
|
(float) (bufferContainer.minCornerBlockPos.getZ() - camPos.z));
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
BEFORE_BUFFER_RENDER_EVENT_PARAM.update(renderEventParam, MODEL_POS);
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, BEFORE_BUFFER_RENDER_EVENT_PARAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPass.setIndexBuffer(bufferWrapper.getIndexGpuBuffer(), VertexFormat.IndexType.INT);
|
renderPassWrapper.setIndexBuffer(bufferWrapper.getIndexGpuBuffer());
|
||||||
renderPass.setVertexBuffer(0, bufferWrapper.vertexGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(bufferWrapper.vertexGpuBuffer);
|
||||||
|
|
||||||
if (!bufferWrapper.vertexGpuBuffer.isClosed())
|
if (!bufferWrapper.vertexGpuBuffer.isClosed())
|
||||||
{
|
{
|
||||||
renderPass.drawIndexed(
|
renderPassWrapper.drawIndexed(bufferWrapper.indexCount);
|
||||||
/*indexStart*/ 0,
|
|
||||||
/*firstIndex*/0,
|
|
||||||
/*indexCount*/bufferWrapper.indexCount,
|
|
||||||
/*instanceCount*/1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
private String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
private String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
||||||
private String getRenderPassName() { return "distantHorizons:McLodRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:TerrainRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|||||||
+36
-22
@@ -29,23 +29,26 @@ import com.mojang.blaze3d.pipeline.BlendFunction;
|
|||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.textures.*;
|
import com.mojang.blaze3d.textures.*;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies the given color texture
|
* Copies the given color texture
|
||||||
@@ -59,11 +62,15 @@ public class BlazeDhApplyRenderer
|
|||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
|
||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
|
|
||||||
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("baseFragUniformBlock");
|
||||||
|
|
||||||
protected GpuBuffer vboGpuBuffer;
|
protected GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
protected final String name;
|
protected final String name;
|
||||||
@@ -92,7 +99,7 @@ public class BlazeDhApplyRenderer
|
|||||||
*/
|
*/
|
||||||
private final String[] uniformNames;
|
private final String[] uniformNames;
|
||||||
/** will be an empty array if unneeded */
|
/** will be an empty array if unneeded */
|
||||||
private final GpuBuffer[] uniformBuffers;
|
private final BlazeUniformBufferWrapper[] uniformBufferWrappers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +135,7 @@ public class BlazeDhApplyRenderer
|
|||||||
this.fragmentShaderPath = fragmentShaderPath;
|
this.fragmentShaderPath = fragmentShaderPath;
|
||||||
|
|
||||||
this.uniformNames = uniformNames;
|
this.uniformNames = uniformNames;
|
||||||
this.uniformBuffers = new GpuBuffer[this.uniformNames.length];
|
this.uniformBufferWrappers = new BlazeUniformBufferWrapper[this.uniformNames.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryInit(
|
private void tryInit(
|
||||||
@@ -179,10 +186,12 @@ public class BlazeDhApplyRenderer
|
|||||||
pipelineBuilder.withUniformBuffer(uniformName);
|
pipelineBuilder.withUniformBuffer(uniformName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pipelineBuilder.withUniformBuffer("baseFragUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uSourceColorTexture");
|
pipelineBuilder.withSampler("uSourceColorTexture");
|
||||||
pipelineBuilder.withSampler("uSourceDepthTexture");
|
pipelineBuilder.withSampler("uSourceDepthTexture");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
||||||
.build();
|
.build();
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat);
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
@@ -191,7 +200,6 @@ public class BlazeDhApplyRenderer
|
|||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -201,7 +209,7 @@ public class BlazeDhApplyRenderer
|
|||||||
//========//
|
//========//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
public void setUniform(String uniformName, GpuBuffer uniformBuffer)
|
public void setUniform(String uniformName, BlazeUniformBufferWrapper uniformBufferWrapper)
|
||||||
{
|
{
|
||||||
// the uniform array should be short enough (less than 10 items)
|
// the uniform array should be short enough (less than 10 items)
|
||||||
// where a sequential search should be plenty fast
|
// where a sequential search should be plenty fast
|
||||||
@@ -210,7 +218,7 @@ public class BlazeDhApplyRenderer
|
|||||||
String nameAtIndex = this.uniformNames[i];
|
String nameAtIndex = this.uniformNames[i];
|
||||||
if (nameAtIndex.equals(uniformName))
|
if (nameAtIndex.equals(uniformName))
|
||||||
{
|
{
|
||||||
this.uniformBuffers[i] = uniformBuffer;
|
this.uniformBufferWrappers[i] = uniformBufferWrapper;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,32 +233,38 @@ public class BlazeDhApplyRenderer
|
|||||||
|
|
||||||
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
|
||||||
|
this.fragUniformBufferWrapper
|
||||||
|
.putInt((RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.REVERSE_Z) ? 1 : 0) // uIsReverseZDepth
|
||||||
|
.finishAndUpload();
|
||||||
|
;
|
||||||
|
|
||||||
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getIdentifierName,
|
this::getIdentifierName,
|
||||||
this.destinationColorTextureViewWrapper.textureView,
|
this.destinationColorTextureViewWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.dummyDepthTextureWrapper))
|
||||||
this.dummyDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uSourceColorTexture", this.sourceColorTextureViewWrapper.textureView, this.sourceColorTextureViewWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uSourceColorTexture", this.sourceColorTextureViewWrapper);
|
||||||
renderPass.bindTexture("uSourceDepthTexture", this.sourceDepthTextureViewWrapper.textureView, this.sourceDepthTextureViewWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uSourceDepthTexture", this.sourceDepthTextureViewWrapper);
|
||||||
|
|
||||||
for (int i = 0; i < this.uniformNames.length; i++)
|
for (int i = 0; i < this.uniformNames.length; i++)
|
||||||
{
|
{
|
||||||
String uniformName = this.uniformNames[i];
|
String uniformName = this.uniformNames[i];
|
||||||
GpuBuffer uniformBuffer = this.uniformBuffers[i];
|
BlazeUniformBufferWrapper uniformBuffer = this.uniformBufferWrappers[i];
|
||||||
if (uniformBuffer == null)
|
if (uniformBuffer == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Missing uniform ["+uniformName+"], please set the uniform before rendering.");
|
throw new IllegalStateException("Missing uniform ["+uniformName+"], please set the uniform before rendering.");
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPass.setUniform(uniformName, uniformBuffer);
|
renderPassWrapper.setUniform(uniformName, uniformBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer);
|
renderPassWrapper.setUniform("baseFragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
renderPass.setPipeline(this.pipeline);
|
|
||||||
|
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer);
|
||||||
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
|
|
||||||
|
renderPassWrapper.draw(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -258,7 +272,7 @@ public class BlazeDhApplyRenderer
|
|||||||
// so we can check if they're missing during next frame's rendering
|
// so we can check if they're missing during next frame's rendering
|
||||||
if (ModInfo.IS_DEV_BUILD)
|
if (ModInfo.IS_DEV_BUILD)
|
||||||
{
|
{
|
||||||
Arrays.fill(this.uniformBuffers, null);
|
Arrays.fill(this.uniformBufferWrappers, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-36
@@ -28,19 +28,16 @@ import com.mojang.blaze3d.buffers.GpuBuffer;
|
|||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.textures.*;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.IDhBlazeTexture;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blindly copies one texture into another.
|
* Blindly copies one texture into another.
|
||||||
*
|
*
|
||||||
@@ -103,7 +100,7 @@ public class BlazeDhCopyRenderer
|
|||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
|
|
||||||
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("McCopyRenderer");
|
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("CopyRenderer");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,48 +114,28 @@ public class BlazeDhCopyRenderer
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
public void render(
|
public void render(
|
||||||
BlazeTextureWrapper sourceColorTextureWrapper,
|
IDhBlazeTexture sourceColorTextureWrapper,
|
||||||
BlazeTextureViewWrapper destinationColorTextureWrapper)
|
IDhBlazeTexture destinationColorTextureWrapper)
|
||||||
{
|
|
||||||
this.render(
|
|
||||||
sourceColorTextureWrapper.textureView, sourceColorTextureWrapper.textureSampler,
|
|
||||||
destinationColorTextureWrapper.textureView);
|
|
||||||
}
|
|
||||||
public void render(
|
|
||||||
BlazeTextureWrapper sourceColorTextureWrapper,
|
|
||||||
BlazeTextureWrapper destinationColorTextureWrapper)
|
|
||||||
{
|
|
||||||
this.render(
|
|
||||||
sourceColorTextureWrapper.textureView, sourceColorTextureWrapper.textureSampler,
|
|
||||||
destinationColorTextureWrapper.textureView);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void render(
|
|
||||||
GpuTextureView sourceTextureView,
|
|
||||||
GpuSampler sourceTextureSampler,
|
|
||||||
GpuTextureView destinationTextureView)
|
|
||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
destinationTextureView,
|
destinationColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.dummyDepthTextureWrapper))
|
||||||
this.dummyDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uCopyTexture", sourceTextureView, sourceTextureSampler);
|
renderPassWrapper.bindTexture("uCopyTexture", sourceColorTextureWrapper);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
||||||
|
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.draw(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRenderPassName() { return "distantHorizons:McCopyRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:CopyRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ import com.seibel.distanthorizons.common.render.openGl.glObject.enums.GLEnums;
|
|||||||
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.RenderableBoxGroup;
|
import com.seibel.distanthorizons.core.render.renderer.RenderableBoxGroup;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|||||||
+25
-54
@@ -25,33 +25,28 @@ public class BlazeDhFarFadeRenderer {}
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFarFadeRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFarFadeRenderer;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fades out DH's far clip plane
|
* Fades out DH's far clip plane
|
||||||
@@ -62,13 +57,14 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
public static final BlazeDhFarFadeRenderer INSTANCE = new BlazeDhFarFadeRenderer();
|
public static final BlazeDhFarFadeRenderer INSTANCE = new BlazeDhFarFadeRenderer();
|
||||||
|
|
||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("fragUniformBlock");
|
||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
@@ -123,7 +119,7 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
|
|
||||||
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("McFadeRenderer");
|
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("DhFarFadeRenderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -151,18 +147,11 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
// textures
|
// textures
|
||||||
this.dhFadeColorTextureWrapper.tryCreateOrResize();
|
this.dhFadeColorTextureWrapper.tryCreateOrResize();
|
||||||
this.mcColorTextureViewWrapper.tryWrap(Minecraft.getInstance().getMainRenderTarget().getColorTexture());
|
this.mcColorTextureViewWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getColorTexture());
|
||||||
|
|
||||||
this.dhFadeDepthTextureWrapper.tryCreateOrResize();
|
this.dhFadeDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putFloat() // uStartFadeBlockDistance
|
|
||||||
.putFloat() // uEndFadeBlockDistance
|
|
||||||
.putMat4f() // uDhInvMvmProj
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
float dhFarClipDistance = RenderUtil.getFarClipPlaneDistanceInBlocks();
|
float dhFarClipDistance = RenderUtil.getFarClipPlaneDistanceInBlocks();
|
||||||
@@ -170,30 +159,14 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
float fadeEndDistance = dhFarClipDistance * 0.9f;
|
float fadeEndDistance = dhFarClipDistance * 0.9f;
|
||||||
|
|
||||||
|
|
||||||
Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(renderParams.mcProjectionMatrix);
|
|
||||||
Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(renderParams.mcModelViewMatrix);
|
|
||||||
|
|
||||||
Mat4f inverseDhMvmProjMatrix = new Mat4f(dhProjectionMatrix);
|
|
||||||
inverseDhMvmProjMatrix.multiply(dhModelViewMatrix);
|
|
||||||
inverseDhMvmProjMatrix.invert();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
fragUniformBufferWrapper
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putFloat(fadeStartDistance) // uStartFadeBlockDistance
|
.putFloat(fadeStartDistance) // uStartFadeBlockDistance
|
||||||
.putFloat(fadeEndDistance) // uEndFadeBlockDistance
|
.putFloat(fadeEndDistance) // uEndFadeBlockDistance
|
||||||
.putMat4f(inverseDhMvmProjMatrix.createJomlMatrix()) // uDhInvMvmProj
|
.putMat4f(renderParams.dhInverseMvmProjectionMatrix) // uDhInvMvmProj
|
||||||
.get()
|
.putInt((RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.REVERSE_Z) ? 1 : 0) // uIsReverseZDepth
|
||||||
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.fragUniformBuffer = BlazeUniformUtil.createBuffer("fragUniformBlock", uniformBufferSize, this.fragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,29 +177,27 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
private void renderFadeToTexture()
|
private void renderFadeToTexture()
|
||||||
{
|
{
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.dhFadeColorTextureWrapper.textureView,
|
this.dhFadeColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.dhFadeDepthTextureWrapper))
|
||||||
this.dhFadeDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
// MC texture
|
// MC texture
|
||||||
renderPass.bindTexture("uMcColorTexture", this.mcColorTextureViewWrapper.textureView, this.mcColorTextureViewWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uMcColorTexture", this.mcColorTextureViewWrapper);
|
||||||
|
|
||||||
// DH textures
|
// DH textures
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper);
|
||||||
renderPass.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper);
|
||||||
|
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPassWrapper.setUniform("fragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer);
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
|
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.draw(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McFadeRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:DhFarFadeRenderer"; }
|
||||||
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+68
-154
@@ -24,43 +24,43 @@ public class BlazeDhFogRenderer {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
|
||||||
import com.mojang.blaze3d.platform.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode;
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFogRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFogRenderer;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import java.util.OptionalDouble;
|
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||||
import java.util.OptionalInt;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
import com.mojang.blaze3d.platform.DestFactor;
|
||||||
|
import com.mojang.blaze3d.platform.SourceFactor;
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.platform.BlendFactor;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders fog onto the LODs.
|
* Renders fog onto the LODs.
|
||||||
@@ -71,6 +71,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
|
|
||||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
@@ -83,7 +84,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("dh_fog_frag_uniform");
|
||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
@@ -109,11 +110,16 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
|
|
||||||
|
BlendFunction blendFunc;
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
blendFunc = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
|
#else
|
||||||
|
blendFunc = new BlendFunction(BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_ALPHA, BlendFactor.ONE, BlendFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
|
#endif
|
||||||
|
|
||||||
this.applyRenderer = new BlazeDhApplyRenderer(
|
this.applyRenderer = new BlazeDhApplyRenderer(
|
||||||
"fog_apply_to_dh",
|
"fog_apply_to_dh",
|
||||||
new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA),
|
blendFunc,
|
||||||
"apply/blaze/vert", "apply/blaze/frag"
|
"apply/blaze/vert", "apply/blaze/frag"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -140,7 +146,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
|
|
||||||
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("McFogRenderer");
|
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("FogRenderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -153,7 +159,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderParams renderParams)
|
public void render(RenderParams renderParams, DhApiFogRenderParam fogRenderParams)
|
||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
@@ -170,144 +176,68 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
this.fogDepthTextureWrapper.tryCreateOrResize();
|
this.fogDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
|
|
||||||
// fog uniforms
|
|
||||||
.putVec4() // uFogColor
|
|
||||||
.putFloat() //uFogScale
|
|
||||||
.putFloat() //uFogVerticalScale
|
|
||||||
// only used for debugging
|
|
||||||
.putInt() //uFogDebugMode // 1 = render everything with fog color // 7 = use debug rendering
|
|
||||||
.putInt() //uFogFalloffType
|
|
||||||
|
|
||||||
// fog config
|
|
||||||
.putFloat() // uFarFogStart
|
|
||||||
.putFloat() // uFarFogLength
|
|
||||||
.putFloat() // uFarFogMin
|
|
||||||
.putFloat() // uFarFogRange
|
|
||||||
.putFloat() // uFarFogDensity
|
|
||||||
|
|
||||||
// height fog config
|
|
||||||
.putFloat() // uHeightFogStart
|
|
||||||
.putFloat() // uHeightFogLength
|
|
||||||
.putFloat() // uHeightFogMin
|
|
||||||
.putFloat() // uHeightFogRange
|
|
||||||
.putFloat() // uHeightFogDensity
|
|
||||||
|
|
||||||
// ??
|
|
||||||
.putInt() // uHeightFogEnabled
|
|
||||||
.putInt() // uHeightFogFalloffType
|
|
||||||
.putInt() // uHeightBasedOnCamera
|
|
||||||
.putFloat() // uHeightFogBaseHeight
|
|
||||||
.putInt() // uHeightFogAppliesUp
|
|
||||||
.putInt() // uHeightFogAppliesDown
|
|
||||||
.putInt() // uUseSphericalFog
|
|
||||||
.putInt() // uHeightFogMixingMode
|
|
||||||
.putFloat() // uCameraBlockYPos
|
|
||||||
|
|
||||||
.putMat4f() // uInvMvmProj
|
|
||||||
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
|
|
||||||
int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH;
|
int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
Mat4f inverseMvmProjMatrix = new Mat4f(renderParams.dhMvmProjMatrix);
|
Mat4f inverseMvmProjMatrix = new Mat4f(renderParams.dhMvmProjMatrix);
|
||||||
inverseMvmProjMatrix.invert();
|
inverseMvmProjMatrix.invert();
|
||||||
|
|
||||||
if (renderParams.dhMvmProjMatrix == null)
|
EDhApiHeightFogMixMode heightFogMixingMode = fogRenderParams.getHeightFogMixingMode();
|
||||||
{
|
boolean heightFogEnabled =
|
||||||
return;
|
heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL
|
||||||
}
|
&& heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL;
|
||||||
|
|
||||||
|
|
||||||
Color fogColor = this.getFogColor(renderParams.partialTicks);
|
|
||||||
|
|
||||||
// fog config
|
|
||||||
float farFogStart = Config.Client.Advanced.Graphics.Fog.farFogStart.get();
|
|
||||||
float farFogEnd = Config.Client.Advanced.Graphics.Fog.farFogEnd.get();
|
|
||||||
float farFogMin = Config.Client.Advanced.Graphics.Fog.farFogMin.get();
|
|
||||||
float farFogMax = Config.Client.Advanced.Graphics.Fog.farFogMax.get();
|
|
||||||
float farFogDensity = Config.Client.Advanced.Graphics.Fog.farFogDensity.get();
|
|
||||||
|
|
||||||
// override fog if underwater
|
|
||||||
if (MC_RENDER.isFogStateSpecial())
|
|
||||||
{
|
|
||||||
// hide everything behind fog
|
|
||||||
farFogStart = 0.0f;
|
|
||||||
farFogEnd = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// height config
|
|
||||||
EDhApiHeightFogMixMode heightFogMixingMode = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMixMode.get();
|
|
||||||
boolean heightFogEnabled = heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL;
|
|
||||||
boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL;
|
boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL;
|
||||||
EDhApiHeightFogDirection heightFogCameraDirection = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDirection.get();
|
|
||||||
|
|
||||||
float heightFogStart = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogStart.get();
|
Color fogColor = fogRenderParams.getFogColor();
|
||||||
float heightFogEnd = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogEnd.get();
|
|
||||||
float heightFogMin = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMin.get();
|
|
||||||
float heightFogMax = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMax.get();
|
|
||||||
float heightFogDensity = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDensity.get();
|
|
||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
this.fragUniformBufferWrapper
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
|
|
||||||
// fog uniforms
|
// fog uniforms
|
||||||
.putVec4(
|
.putVec4f(
|
||||||
fogColor.getRed() / 255.0f,
|
fogColor.getRed() / 255.0f,
|
||||||
fogColor.getGreen() / 255.0f,
|
fogColor.getGreen() / 255.0f,
|
||||||
fogColor.getBlue() / 255.0f,
|
fogColor.getBlue() / 255.0f,
|
||||||
fogColor.getAlpha() / 255.0f) // uFogColor
|
fogColor.getAlpha() / 255.0f) // uFogColor
|
||||||
.putFloat(1.f / lodDrawDistance) //uFogScale
|
.putFloat(1.f / lodDrawDistance) //uFogScale
|
||||||
.putFloat(1.f / MC.getWrappedClientLevel().getMaxHeight()) //uFogVerticalScale
|
.putFloat(1.f / MC.getWrappedClientLevel().getMaxHeight()) //uFogVerticalScale
|
||||||
// only used for debugging
|
.putInt(0) //uFogDebugMode // 0 = normal // 1 = render everything with fog color // 7 = use debug rendering
|
||||||
.putInt(0) //uFogDebugMode // 1 = render everything with fog color // 7 = use debug rendering
|
.putInt(fogRenderParams.getFarFogFalloff().value) //uFogFalloffType
|
||||||
.putInt(Config.Client.Advanced.Graphics.Fog.farFogFalloff.get().value) //uFogFalloffType
|
|
||||||
|
|
||||||
// fog config
|
// fog config
|
||||||
.putFloat(farFogStart) // uFarFogStart
|
.putFloat(fogRenderParams.getFarFogStartPercent()) // uFarFogStart
|
||||||
.putFloat(farFogEnd - farFogStart) // uFarFogLength
|
.putFloat(fogRenderParams.getFarFogEndPercent() - fogRenderParams.getFarFogStartPercent()) // uFarFogLength
|
||||||
.putFloat(farFogMin) // uFarFogMin
|
.putFloat(fogRenderParams.getFarFogMinThickness()) // uFarFogMin
|
||||||
.putFloat(farFogMax - farFogMin) // uFarFogRange
|
.putFloat(fogRenderParams.getFarFogMaxThickness() - fogRenderParams.getFarFogMinThickness()) // uFarFogRange
|
||||||
.putFloat(farFogDensity) // uFarFogDensity
|
.putFloat(fogRenderParams.getFarFogDensity()) // uFarFogDensity
|
||||||
|
|
||||||
// height fog config
|
// height fog config
|
||||||
.putFloat(heightFogStart) // uHeightFogStart
|
.putFloat(fogRenderParams.getHeightFogStartPercent()) // uHeightFogStart
|
||||||
.putFloat(heightFogEnd - heightFogStart) // uHeightFogLength
|
.putFloat(fogRenderParams.getHeightFogEndPercent() - fogRenderParams.getHeightFogStartPercent()) // uHeightFogLength
|
||||||
.putFloat(heightFogMin) // uHeightFogMin
|
.putFloat(fogRenderParams.getHeightFogMinThickness()) // uHeightFogMin
|
||||||
.putFloat(heightFogMax - heightFogMin) // uHeightFogRange
|
.putFloat(fogRenderParams.getHeightFogMaxThickness() - fogRenderParams.getHeightFogMinThickness()) // uHeightFogRange
|
||||||
.putFloat(heightFogDensity) // uHeightFogDensity
|
.putFloat(fogRenderParams.getHeightFogDensity()) // uHeightFogDensity
|
||||||
|
|
||||||
// ??
|
// ??
|
||||||
.putInt(heightFogEnabled ? 1 : 0) // uHeightFogEnabled
|
.putInt(heightFogEnabled ? 1 : 0) // uHeightFogEnabled
|
||||||
.putInt(Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogFalloff.get().value) // uHeightFogFalloffType
|
.putInt(fogRenderParams.getHeightFogFalloff().value) // uHeightFogFalloffType
|
||||||
.putInt(heightFogCameraDirection.basedOnCamera ? 1 : 0) // uHeightBasedOnCamera
|
.putInt(fogRenderParams.getHeightFogDirection().basedOnCamera ? 1 : 0) // uHeightBasedOnCamera
|
||||||
.putFloat(Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogBaseHeight.get()) // uHeightFogBaseHeight
|
.putFloat(fogRenderParams.getHeightFogBaseHeight()) // uHeightFogBaseHeight
|
||||||
.putInt(heightFogCameraDirection.fogAppliesUp ? 1 : 0) // uHeightFogAppliesUp
|
.putInt(fogRenderParams.getHeightFogDirection().fogAppliesUp ? 1 : 0) // uHeightFogAppliesUp
|
||||||
.putInt(heightFogCameraDirection.fogAppliesDown ? 1 : 0) // uHeightFogAppliesDown
|
.putInt(fogRenderParams.getHeightFogDirection().fogAppliesDown ? 1 : 0) // uHeightFogAppliesDown
|
||||||
.putInt(useSphericalFog ? 1 : 0) // uUseSphericalFog
|
.putInt(useSphericalFog ? 1 : 0) // uUseSphericalFog
|
||||||
.putInt(heightFogMixingMode.value) // uHeightFogMixingMode
|
.putInt(heightFogMixingMode.value) // uHeightFogMixingMode
|
||||||
.putFloat((float)MC_RENDER.getCameraExactPosition().y) // uCameraBlockYPos
|
.putFloat((float)MC_RENDER.getCameraExactPosition().y) // uCameraBlockYPos
|
||||||
|
|
||||||
.putMat4f(inverseMvmProjMatrix.createJomlMatrix()) // uInvMvmProj
|
.putMat4f(inverseMvmProjMatrix) // uInvMvmProj
|
||||||
|
|
||||||
.get()
|
.putInt((RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.REVERSE_Z) ? 1 : 0) // uIsReverseZDepth
|
||||||
|
|
||||||
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.fragUniformBuffer = BlazeUniformUtil.createBuffer("fragUniformBlock", uniformBufferSize, this.fragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -316,42 +246,26 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getFogColor(float partialTicks)
|
|
||||||
{
|
|
||||||
Color fogColor;
|
|
||||||
|
|
||||||
if (Config.Client.Advanced.Graphics.Fog.colorMode.get() == EDhApiFogColorMode.USE_SKY_COLOR)
|
|
||||||
{
|
|
||||||
fogColor = MC_RENDER.getSkyColor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fogColor = MC_RENDER.getFogColor(partialTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fogColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderFogToTexture()
|
private void renderFogToTexture()
|
||||||
{
|
{
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.fogColorTextureWrapper.textureView,
|
this.fogColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.fogDepthTextureWrapper))
|
||||||
this.fogDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper);
|
||||||
|
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPassWrapper.setUniform("fragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
|
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.draw(/*indexCount*/ 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McFogRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:FogRenderer"; }
|
||||||
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+48
-78
@@ -24,37 +24,37 @@ public class BlazeDhSsaoRenderer {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
|
||||||
import com.mojang.blaze3d.platform.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhApplyRenderer;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhSsaoRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhSsaoRenderer;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import java.nio.ByteOrder;
|
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||||
import java.util.OptionalDouble;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import java.util.OptionalInt;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
import com.mojang.blaze3d.platform.DestFactor;
|
||||||
|
import com.mojang.blaze3d.platform.SourceFactor;
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.platform.BlendFactor;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Renders SSAO to the DH LODs. */
|
/** Renders SSAO to the DH LODs. */
|
||||||
public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
||||||
@@ -62,6 +62,7 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
@@ -74,8 +75,8 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("fragUniformBlock");
|
||||||
private GpuBuffer applyFragUniformBuffer;
|
private final BlazeUniformBufferWrapper applyFragUniformBufferWrapper = new BlazeUniformBufferWrapper("applyFragUniformBlock");
|
||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
@@ -101,9 +102,17 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BlendFunction blendFunc;
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
blendFunc = new BlendFunction(SourceFactor.ZERO, DestFactor.SRC_ALPHA, SourceFactor.ZERO, DestFactor.ONE);
|
||||||
|
#else
|
||||||
|
blendFunc = new BlendFunction(BlendFactor.ZERO, BlendFactor.SRC_ALPHA, BlendFactor.ZERO, BlendFactor.ONE);
|
||||||
|
#endif
|
||||||
|
|
||||||
this.applyRenderer = new BlazeDhApplyRenderer(
|
this.applyRenderer = new BlazeDhApplyRenderer(
|
||||||
"ssao_apply_to_dh",
|
"ssao_apply_to_dh",
|
||||||
new BlendFunction(SourceFactor.ZERO, DestFactor.SRC_ALPHA, SourceFactor.ZERO, DestFactor.ONE),
|
blendFunc,
|
||||||
"apply/blaze/vert", "ssao/blaze/apply",
|
"apply/blaze/vert", "ssao/blaze/apply",
|
||||||
/*uniforms*/ new String[] { "applyFragUniformBlock" }
|
/*uniforms*/ new String[] { "applyFragUniformBlock" }
|
||||||
);
|
);
|
||||||
@@ -163,32 +172,14 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
|
|
||||||
// frag uniforms
|
// frag uniforms
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putInt() // uSampleCount\
|
|
||||||
|
|
||||||
.putFloat() // uRadius
|
|
||||||
.putFloat() // uStrength
|
|
||||||
.putFloat() // uMinLight
|
|
||||||
.putFloat() // uBias
|
|
||||||
.putFloat() // uFadeDistanceInBlocks
|
|
||||||
|
|
||||||
.putMat4f() // uInvProj
|
|
||||||
.putMat4f() // uProj
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
Mat4f projMatrix = new Mat4f(renderParams.dhProjectionMatrix);
|
Mat4f projMatrix = new Mat4f(renderParams.dhProjectionMatrix);
|
||||||
Mat4f invertedProjMatrix = new Mat4f(renderParams.dhProjectionMatrix);
|
Mat4f invertedProjMatrix = new Mat4f(renderParams.dhProjectionMatrix);
|
||||||
invertedProjMatrix.invert();
|
invertedProjMatrix.invert();
|
||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
this.fragUniformBufferWrapper
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putInt(6) // uSampleCount
|
.putInt(6) // uSampleCount
|
||||||
|
|
||||||
.putFloat(4.0f) // uRadius
|
.putFloat(4.0f) // uRadius
|
||||||
@@ -197,27 +188,16 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
.putFloat(0.02f) // uBias
|
.putFloat(0.02f) // uBias
|
||||||
.putFloat(1_600.0f) // uFadeDistanceInBlocks
|
.putFloat(1_600.0f) // uFadeDistanceInBlocks
|
||||||
|
|
||||||
.putMat4f(invertedProjMatrix.createJomlMatrix())
|
.putMat4f(invertedProjMatrix)
|
||||||
.putMat4f(projMatrix.createJomlMatrix())
|
.putMat4f(projMatrix)
|
||||||
.get()
|
|
||||||
|
.putInt((RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.REVERSE_Z) ? 1 : 0) // uIsReverseZDepth
|
||||||
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.fragUniformBuffer = BlazeUniformUtil.createBuffer("fragUniformBlock", uniformBufferSize, this.fragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply frag uniforms
|
// apply frag uniforms
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putVec2() // uViewSize
|
|
||||||
.putInt() // uBlurRadius
|
|
||||||
.putFloat() // uNearClipPlane
|
|
||||||
.putFloat() // uFarClipPlane
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
float viewWidth = (float)MC_RENDER.getTargetFramebufferViewportWidth();
|
float viewWidth = (float)MC_RENDER.getTargetFramebufferViewportWidth();
|
||||||
@@ -228,51 +208,41 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
this.applyFragUniformBufferWrapper
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
.putVec2f(viewWidth, viewHeight) // uViewSize
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putVec2(viewWidth, viewHeight) // uViewSize
|
|
||||||
.putInt(2) // uBlurRadius
|
.putInt(2) // uBlurRadius
|
||||||
.putFloat(nearClipPlane) // uNearClipPlane
|
.putFloat(nearClipPlane) // uNearClipPlane
|
||||||
.putFloat(farClipPlane) // uFarClipPlane
|
.putFloat(farClipPlane) // uFarClipPlane
|
||||||
.get()
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.applyFragUniformBuffer = BlazeUniformUtil.createBuffer("applyFragUniformBlock", uniformBufferSize, this.applyFragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.applyFragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.renderSsaoToTexture();
|
this.renderSsaoToTexture();
|
||||||
|
|
||||||
this.applyRenderer.setUniform("applyFragUniformBlock", this.applyFragUniformBuffer);
|
this.applyRenderer.setUniform("applyFragUniformBlock", this.applyFragUniformBufferWrapper);
|
||||||
this.applyRenderer.render(this.ssaoColorTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
this.applyRenderer.render(this.ssaoColorTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.texture, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.texture);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderSsaoToTexture()
|
private void renderSsaoToTexture()
|
||||||
{
|
{
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.ssaoColorTextureWrapper.textureView,
|
this.ssaoColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.ssaoDepthTextureWrapper))
|
||||||
this.ssaoDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper);
|
||||||
|
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPassWrapper.setUniform("fragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer);
|
||||||
|
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.draw(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McSsaoRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:SsaoRenderer"; }
|
||||||
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+30
-60
@@ -25,40 +25,30 @@ public class BlazeVanillaFadeRenderer {}
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderPass;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
|
||||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.BlazeDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
import com.seibel.distanthorizons.common.render.blaze.apply.BlazeDhCopyRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazePostProcessUtil;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhVanillaFadeRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhVanillaFadeRenderer;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.OptionalDouble;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fades the vanilla chunks
|
* Fades the vanilla chunks
|
||||||
@@ -69,16 +59,18 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
|
||||||
public static final BlazeVanillaFadeRenderer INSTANCE = new BlazeVanillaFadeRenderer();
|
public static final BlazeVanillaFadeRenderer INSTANCE = new BlazeVanillaFadeRenderer();
|
||||||
|
|
||||||
|
|
||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private final BlazeUniformBufferWrapper fragUniformBufferWrapper = new BlazeUniformBufferWrapper("fragUniformBlock");
|
||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
@@ -136,7 +128,7 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
|
|
||||||
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("McFadeRenderer");
|
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData("VanillaFadeRenderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -164,21 +156,11 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
this.fadeColorTextureWrapper.tryCreateOrResize();
|
this.fadeColorTextureWrapper.tryCreateOrResize();
|
||||||
this.fadeDepthTextureWrapper.tryCreateOrResize();
|
this.fadeDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
this.mcDepthTextureWrapper.tryWrap(Minecraft.getInstance().getMainRenderTarget().getDepthTexture());
|
this.mcDepthTextureWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getDepthTexture());
|
||||||
this.mcColorTextureWrapper.tryWrap(Minecraft.getInstance().getMainRenderTarget().getColorTexture());
|
this.mcColorTextureWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getColorTexture());
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putInt() // uOnlyRenderLods
|
|
||||||
.putFloat() // uStartFadeBlockDistance
|
|
||||||
.putFloat() // uEndFadeBlockDistance
|
|
||||||
.putFloat() // uMaxLevelHeight
|
|
||||||
.putMat4f() // uDhInvMvmProj
|
|
||||||
.putMat4f() // uMcInvMvmProj
|
|
||||||
.get();
|
|
||||||
|
|
||||||
|
|
||||||
// create data //
|
// create data //
|
||||||
|
|
||||||
float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
|
float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks();
|
||||||
@@ -198,34 +180,24 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
Mat4f inverseMcMvmProjMatrix = inverseMcModelViewProjectionMatrix;
|
Mat4f inverseMcMvmProjMatrix = inverseMcModelViewProjectionMatrix;
|
||||||
|
|
||||||
|
|
||||||
Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(renderParams.mcProjectionMatrix);
|
Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(renderParams.dhProjectionMatrix);
|
||||||
Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(renderParams.mcModelViewMatrix);
|
inverseDhModelViewProjectionMatrix.multiply(renderParams.dhModelViewMatrix);
|
||||||
|
|
||||||
Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(dhProjectionMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.multiply(dhModelViewMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.invert();
|
inverseDhModelViewProjectionMatrix.invert();
|
||||||
Mat4f inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
|
Mat4f inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
this.fragUniformBufferWrapper
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
|
||||||
.putInt(Config.Client.Advanced.Debugging.lodOnlyMode.get() ? 1 : 0) // uOnlyRenderLods
|
.putInt(Config.Client.Advanced.Debugging.lodOnlyMode.get() ? 1 : 0) // uOnlyRenderLods
|
||||||
.putFloat(fadeStartDistance) // uStartFadeBlockDistance
|
.putFloat(fadeStartDistance) // uStartFadeBlockDistance
|
||||||
.putFloat(fadeEndDistance) // uEndFadeBlockDistance
|
.putFloat(fadeEndDistance) // uEndFadeBlockDistance
|
||||||
.putFloat(renderParams.clientLevelWrapper.getMaxHeight()) // uMaxLevelHeight
|
.putFloat(renderParams.clientLevelWrapper.getMaxHeight()) // uMaxLevelHeight
|
||||||
.putMat4f(inverseDhMvmProjMatrix.createJomlMatrix()) // uDhInvMvmProj
|
.putMat4f(inverseDhMvmProjMatrix) // uDhInvMvmProj
|
||||||
.putMat4f(inverseMcMvmProjMatrix.createJomlMatrix()) // uMcInvMvmProj
|
.putMat4f(inverseMcMvmProjMatrix) // uMcInvMvmProj
|
||||||
.get()
|
.putInt((RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.REVERSE_Z) ? 1 : 0) // uIsReverseZDepth
|
||||||
|
.finishAndUpload()
|
||||||
;
|
;
|
||||||
|
|
||||||
this.fragUniformBuffer = BlazeUniformUtil.createBuffer("fragUniformBlock", uniformBufferSize, this.fragUniformBuffer);
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -236,28 +208,26 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
private void renderFadeToTexture()
|
private void renderFadeToTexture()
|
||||||
{
|
{
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.fadeColorTextureWrapper.textureView,
|
this.fadeColorTextureWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.fadeDepthTextureWrapper))
|
||||||
this.fadeDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uMcDepthTexture", this.mcDepthTextureWrapper.textureView, this.mcDepthTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uMcDepthTexture", this.mcDepthTextureWrapper);
|
||||||
renderPass.bindTexture("uCombinedMcDhColorTexture", this.mcColorTextureWrapper.textureView, this.mcColorTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uCombinedMcDhColorTexture", this.mcColorTextureWrapper);
|
||||||
|
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper);
|
||||||
renderPass.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureSampler);
|
renderPassWrapper.bindTexture("uDhColorTexture", BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper);
|
||||||
|
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPassWrapper.setUniform("fragUniformBlock", this.fragUniformBufferWrapper);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer);
|
||||||
|
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 4);
|
renderPassWrapper.draw(/*indexCount*/ 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:McFadeRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:VanillaFadeRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|||||||
+12
-11
@@ -35,8 +35,11 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||||||
import com.mojang.blaze3d.textures.*;
|
import com.mojang.blaze3d.textures.*;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPassWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.RenderPipelineBuilderWrapper;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.BlazeTextureViewWrapper;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
@@ -106,7 +109,7 @@ public class BlazeDhTestTriangleRenderer implements IDhTestTriangleRenderer
|
|||||||
pipelineBuilder.withVertexShader("test/blaze/vert");
|
pipelineBuilder.withVertexShader("test/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader("test/blaze/frag");
|
pipelineBuilder.withFragmentShader("test/blaze/frag");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
||||||
.add("vColor", BlazeDhVertexFormatUtil.RGBA_FLOAT_COLOR)
|
.add("vColor", BlazeDhVertexFormatUtil.RGBA_FLOAT_COLOR)
|
||||||
.build();
|
.build();
|
||||||
@@ -164,19 +167,17 @@ public class BlazeDhTestTriangleRenderer implements IDhTestTriangleRenderer
|
|||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
this.mcColorTextureViewWrapper.tryWrap(Minecraft.getInstance().getMainRenderTarget().getColorTexture());
|
this.mcColorTextureViewWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getColorTexture());
|
||||||
this.mcDepthTextureViewWrapper.tryWrap(Minecraft.getInstance().getMainRenderTarget().getDepthTexture());
|
this.mcDepthTextureViewWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getDepthTexture());
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPassWrapper renderPassWrapper = new RenderPassWrapper(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.mcColorTextureViewWrapper.textureView,
|
this.mcColorTextureViewWrapper,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
this.mcDepthTextureViewWrapper))
|
||||||
this.mcDepthTextureViewWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer);
|
renderPassWrapper.setVertexBuffer(this.vboGpuBuffer);
|
||||||
renderPass.setPipeline(this.pipeline);
|
renderPassWrapper.setPipeline(this.pipeline);
|
||||||
renderPass.draw(/*indexStart*/ 0, /*indexCount*/ 3);
|
renderPassWrapper.draw(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private String getRenderPassName() { return "distantHorizons:DhTestRenderer"; }
|
private String getRenderPassName() { return "distantHorizons:DhTestRenderer"; }
|
||||||
|
|||||||
+42
-6
@@ -6,7 +6,7 @@ public class BlazeDhVertexFormatUtil {}
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderApi;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
@@ -16,6 +16,11 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see LodQuadBuilder
|
* @see LodQuadBuilder
|
||||||
*/
|
*/
|
||||||
@@ -43,14 +48,14 @@ public class BlazeDhVertexFormatUtil
|
|||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
EDhApiRenderApi renderingApi = Config.Client.Advanced.Graphics.Experimental.renderingApi.get();
|
EDhApiRenderingEngine renderingApi = Config.Client.Advanced.Graphics.Experimental.renderingEngine.get();
|
||||||
if (renderingApi == EDhApiRenderApi.AUTO)
|
if (renderingApi == EDhApiRenderingEngine.AUTO)
|
||||||
{
|
{
|
||||||
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||||
renderingApi = versionConstants.getDefaultRenderingApi();
|
renderingApi = versionConstants.getDefaultRenderingEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean register = (renderingApi == EDhApiRenderApi.BLAZE_3D);
|
boolean register = (renderingApi == EDhApiRenderingEngine.BLAZE_3D);
|
||||||
if (register)
|
if (register)
|
||||||
{
|
{
|
||||||
LOGGER.debug("Attempting to register ["+VertexFormatElement.class.getSimpleName()+"]...");
|
LOGGER.debug("Attempting to register ["+VertexFormatElement.class.getSimpleName()+"]...");
|
||||||
@@ -70,7 +75,7 @@ public class BlazeDhVertexFormatUtil
|
|||||||
IRIS_NORMAL = VertexFormatElement.register(/*id*/29, /*index*/0, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.GENERIC, /*count*/ 1);
|
IRIS_NORMAL = VertexFormatElement.register(/*id*/29, /*index*/0, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.GENERIC, /*count*/ 1);
|
||||||
|
|
||||||
FLOAT_XYZ_POS = VertexFormatElement.register(/*id*/30, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, /*count*/ 3);
|
FLOAT_XYZ_POS = VertexFormatElement.register(/*id*/30, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, /*count*/ 3);
|
||||||
#else
|
#elif MC_VER <= MC_26_1_2
|
||||||
SCREEN_POS = VertexFormatElement.register(/*id*/22, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 2);
|
SCREEN_POS = VertexFormatElement.register(/*id*/22, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 2);
|
||||||
RGBA_FLOAT_COLOR = VertexFormatElement.register(/*id*/23, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 4);
|
RGBA_FLOAT_COLOR = VertexFormatElement.register(/*id*/23, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 4);
|
||||||
|
|
||||||
@@ -83,6 +88,35 @@ public class BlazeDhVertexFormatUtil
|
|||||||
IRIS_NORMAL = VertexFormatElement.register(/*id*/29, /*index*/0, VertexFormatElement.Type.BYTE, false, /*count*/ 1);
|
IRIS_NORMAL = VertexFormatElement.register(/*id*/29, /*index*/0, VertexFormatElement.Type.BYTE, false, /*count*/ 1);
|
||||||
|
|
||||||
FLOAT_XYZ_POS = VertexFormatElement.register(/*id*/30, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 3);
|
FLOAT_XYZ_POS = VertexFormatElement.register(/*id*/30, /*index*/0, VertexFormatElement.Type.FLOAT, false, /*count*/ 3);
|
||||||
|
#elif MC_VER <= MC_26_1_2
|
||||||
|
|
||||||
|
SCREEN_POS = VertexFormatElement.register(/*id*/22, /*index*/0, GpuFormat.RG32_FLOAT); // 2 floats
|
||||||
|
RGBA_FLOAT_COLOR = VertexFormatElement.register(/*id*/23, /*index*/0, GpuFormat.RGBA32_FLOAT); // 4 floats
|
||||||
|
|
||||||
|
SHORT_XYZ_POS = VertexFormatElement.register(/*id*/24, /*index*/0, GpuFormat.RGB16_UINT); // 3 ushorts
|
||||||
|
BYTE_PAD = VertexFormatElement.register(/*id*/25, /*index*/0, GpuFormat.R8_UINT); // 1 byte
|
||||||
|
|
||||||
|
META = VertexFormatElement.register(/*id*/26, /*index*/0, GpuFormat.R16_UINT); // 1 ushort
|
||||||
|
RGBA_UBYTE_COLOR = VertexFormatElement.register(/*id*/27, /*index*/0, GpuFormat.RGBA8_UNORM); // 4 ubytes
|
||||||
|
IRIS_MATERIAL = VertexFormatElement.register(/*id*/28, /*index*/0, GpuFormat.R8_UINT); // 1 byte
|
||||||
|
IRIS_NORMAL = VertexFormatElement.register(/*id*/29, /*index*/0, GpuFormat.R8_UINT); // 1 byte
|
||||||
|
|
||||||
|
FLOAT_XYZ_POS = VertexFormatElement.register(/*id*/30, /*index*/0, GpuFormat.RGB32_FLOAT); // 3 floats
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
SCREEN_POS = new VertexFormatElement("Screen Pos", Float.BYTES * 2, GpuFormat.RG32_FLOAT);
|
||||||
|
RGBA_FLOAT_COLOR = new VertexFormatElement("RGBA Float Color", Float.BYTES * 4, GpuFormat.RGBA32_FLOAT);
|
||||||
|
|
||||||
|
SHORT_XYZ_POS = new VertexFormatElement("Short XYZ Pos", Short.BYTES * 3, GpuFormat.RGB16_UINT);
|
||||||
|
BYTE_PAD = new VertexFormatElement("Byte Pad", 1, GpuFormat.R8_UINT);
|
||||||
|
|
||||||
|
META = new VertexFormatElement("DH Meta", Short.BYTES, GpuFormat.R16_UINT);
|
||||||
|
RGBA_UBYTE_COLOR = new VertexFormatElement("Rgba Ubyte Color", 4, GpuFormat.RGBA8_UNORM);
|
||||||
|
IRIS_MATERIAL = new VertexFormatElement("Iris Material", 1, GpuFormat.R8_UINT);
|
||||||
|
IRIS_NORMAL = new VertexFormatElement("Iris Normal", 1, GpuFormat.R8_UINT);
|
||||||
|
|
||||||
|
FLOAT_XYZ_POS = new VertexFormatElement("Float XYZ Pos", Float.BYTES * 3, GpuFormat.RGB32_FLOAT);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -118,5 +152,7 @@ public class BlazeDhVertexFormatUtil
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+2
-1
@@ -11,6 +11,7 @@ import com.mojang.blaze3d.systems.CommandEncoder;
|
|||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.BlazeVertexFormatBuilder;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@@ -67,7 +68,7 @@ public class BlazePostProcessUtil
|
|||||||
|
|
||||||
public static VertexFormat createVertexFormat()
|
public static VertexFormat createVertexFormat()
|
||||||
{
|
{
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = new BlazeVertexFormatBuilder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
||||||
.build();
|
.build();
|
||||||
return vertexFormat;
|
return vertexFormat;
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package com.seibel.distanthorizons.common.render.blaze.wrappers;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
public class BlazeVertexFormatBuilder {}
|
||||||
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeDhVertexFormatUtil;
|
||||||
|
|
||||||
|
public class BlazeVertexFormatBuilder
|
||||||
|
{
|
||||||
|
private final VertexFormat.Builder builder;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public BlazeVertexFormatBuilder()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.builder = VertexFormat.builder();
|
||||||
|
#else
|
||||||
|
this.builder = VertexFormat.builder(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==========//
|
||||||
|
// building //
|
||||||
|
//==========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public BlazeVertexFormatBuilder add(String name, VertexFormatElement element)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.builder.add(name, element);
|
||||||
|
#else
|
||||||
|
this.builder.addAttribute(name, element.format());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VertexFormat build() { return this.builder.build(); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+162
@@ -0,0 +1,162 @@
|
|||||||
|
package com.seibel.distanthorizons.common.render.blaze.wrappers;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
public class RenderPassWrapper {}
|
||||||
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderPass;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.texture.IDhBlazeTexture;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeUniformBufferWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
|
||||||
|
import java.util.OptionalDouble;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.IndexType;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public class RenderPassWrapper implements AutoCloseable
|
||||||
|
{
|
||||||
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
private static final GpuDevice GPU_DEVICE = RenderSystem.getDevice();
|
||||||
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
|
||||||
|
|
||||||
|
private final RenderPass renderPass;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public RenderPassWrapper(
|
||||||
|
final Supplier<String> nameGetterFunc,
|
||||||
|
final IDhBlazeTexture colorTexture,
|
||||||
|
final IDhBlazeTexture depthTexture)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
|
nameGetterFunc,
|
||||||
|
colorTexture.getTextureView(),
|
||||||
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
|
depthTexture.getTextureView(),
|
||||||
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty());
|
||||||
|
#else
|
||||||
|
this.renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
|
nameGetterFunc,
|
||||||
|
colorTexture.getTextureView(),
|
||||||
|
/*clearColor*/ Optional.empty(),
|
||||||
|
depthTexture.getTextureView(),
|
||||||
|
/*clearDepth*/ OptionalDouble.empty());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=======//
|
||||||
|
// setup //
|
||||||
|
//=======//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public void bindTexture(
|
||||||
|
final String name,
|
||||||
|
final IDhBlazeTexture textureView)
|
||||||
|
{
|
||||||
|
this.renderPass.bindTexture(
|
||||||
|
name,
|
||||||
|
textureView.getTextureView(),
|
||||||
|
textureView.getTextureSampler());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVertexBuffer(GpuBuffer buffer)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.renderPass.setVertexBuffer(/*slot*/0, buffer);
|
||||||
|
#else
|
||||||
|
this.renderPass.setVertexBuffer(/*slot*/0, buffer.slice());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexBuffer(GpuBuffer buffer)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.renderPass.setIndexBuffer(buffer, VertexFormat.IndexType.INT);
|
||||||
|
#else
|
||||||
|
this.renderPass.setIndexBuffer(buffer, IndexType.INT);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUniform(String uniformName, BlazeUniformBufferWrapper uniformBuffer) { this.renderPass.setUniform(uniformName, uniformBuffer.getGpuBuffer()); }
|
||||||
|
|
||||||
|
public void setPipeline(RenderPipeline pipeline) { this.renderPass.setPipeline(pipeline); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===========//
|
||||||
|
// rendering //
|
||||||
|
//===========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public void draw(int vertexCount)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.renderPass.draw(0, vertexCount);
|
||||||
|
#else
|
||||||
|
this.renderPass.draw(vertexCount, /*instanceCount*/1, /*firstVertex*/0, /*firstInstance*/0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawIndexed(int indexCount)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.renderPass.drawIndexed(
|
||||||
|
/*indexStart*/ 0,
|
||||||
|
/*firstIndex*/0,
|
||||||
|
indexCount,
|
||||||
|
/*instanceCount*/1);
|
||||||
|
#else
|
||||||
|
this.renderPass.drawIndexed(
|
||||||
|
indexCount,
|
||||||
|
/*instanceCount*/1,
|
||||||
|
/*firstVertex*/0,
|
||||||
|
/*vertexOffset*/0,
|
||||||
|
/*firstInstance*/0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() { this.renderPass.close(); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+101
-7
@@ -1,17 +1,30 @@
|
|||||||
package com.seibel.distanthorizons.common.render.blaze.wrappers;
|
package com.seibel.distanthorizons.common.render.blaze.wrappers;
|
||||||
|
|
||||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
|
||||||
import com.mojang.blaze3d.pipeline.ColorTargetState;
|
#if MC_VER <= MC_1_21_10
|
||||||
import com.mojang.blaze3d.pipeline.DepthStencilState;
|
public class RenderPipelineBuilderWrapper {}
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
|
||||||
import com.mojang.blaze3d.platform.CompareOp;
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.pipeline.*;
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
import com.mojang.blaze3d.platform.PolygonMode;
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
import com.mojang.blaze3d.shaders.UniformType;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
import com.mojang.blaze3d.platform.DepthTestFunction;
|
||||||
|
#elif MC_VER <= MC_26_1_2
|
||||||
|
import com.mojang.blaze3d.platform.CompareOp;
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.platform.CompareOp;
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
|
import com.mojang.blaze3d.PrimitiveTopology;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class RenderPipelineBuilderWrapper
|
public class RenderPipelineBuilderWrapper
|
||||||
@@ -119,15 +132,27 @@ public class RenderPipelineBuilderWrapper
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ArrayList<String> samplerNames = new ArrayList<>();
|
||||||
public RenderPipelineBuilderWrapper withSampler(String name) throws IllegalArgumentException
|
public RenderPipelineBuilderWrapper withSampler(String name) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
this.blazePipelineBuilder.withSampler(name);
|
this.blazePipelineBuilder.withSampler(name);
|
||||||
|
#else
|
||||||
|
samplerNames.add(name);
|
||||||
|
#endif
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ArrayList<String> uniformBufferNames = new ArrayList<>();
|
||||||
public RenderPipelineBuilderWrapper withUniformBuffer(String name) throws IllegalArgumentException
|
public RenderPipelineBuilderWrapper withUniformBuffer(String name) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
this.blazePipelineBuilder.withUniform(name, UniformType.UNIFORM_BUFFER);
|
this.blazePipelineBuilder.withUniform(name, UniformType.UNIFORM_BUFFER);
|
||||||
|
#else
|
||||||
|
uniformBufferNames.add(name);
|
||||||
|
#endif
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,15 +231,20 @@ public class RenderPipelineBuilderWrapper
|
|||||||
this.blazePipelineBuilder.withoutBlend();
|
this.blazePipelineBuilder.withoutBlend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DepthTestFunction depthTestFunction;
|
||||||
switch (this.depthTest)
|
switch (this.depthTest)
|
||||||
{
|
{
|
||||||
case NONE:
|
case NONE:
|
||||||
|
depthTestFunction = DepthTestFunction.NO_DEPTH_TEST;
|
||||||
break;
|
break;
|
||||||
case LESS:
|
case LESS:
|
||||||
|
depthTestFunction = DepthTestFunction.LESS_DEPTH_TEST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No depth test defined for type ["+this.depthTest+"].");
|
||||||
}
|
}
|
||||||
this.blazepipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
this.blazePipelineBuilder.withDepthTestFunction(depthTestFunction);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -227,18 +257,31 @@ public class RenderPipelineBuilderWrapper
|
|||||||
case LESS:
|
case LESS:
|
||||||
compareOp = CompareOp.LESS_THAN;
|
compareOp = CompareOp.LESS_THAN;
|
||||||
break;
|
break;
|
||||||
|
case GREATER:
|
||||||
|
compareOp = CompareOp.GREATER_THAN;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("No depth test defined for type ["+this.depthTest+"].");
|
throw new UnsupportedOperationException("No depth test defined for type ["+this.depthTest+"].");
|
||||||
}
|
}
|
||||||
this.blazePipelineBuilder.withDepthStencilState(new DepthStencilState(compareOp, this.writeDepth));
|
this.blazePipelineBuilder.withDepthStencilState(new DepthStencilState(compareOp, this.writeDepth));
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
this.blazePipelineBuilder.withColorTargetState(
|
this.blazePipelineBuilder.withColorTargetState(
|
||||||
new ColorTargetState(
|
new ColorTargetState(
|
||||||
Optional.ofNullable(this.blendFunction),
|
Optional.ofNullable(this.blendFunction),
|
||||||
this.writeColor ? ColorTargetState.WRITE_ALL : ColorTargetState.WRITE_NONE
|
this.writeColor ? ColorTargetState.WRITE_ALL : ColorTargetState.WRITE_NONE
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
#else
|
||||||
|
this.blazePipelineBuilder.withColorTargetState(
|
||||||
|
new ColorTargetState(
|
||||||
|
Optional.ofNullable(this.blendFunction),
|
||||||
|
GpuFormat.RGBA8_UNORM,
|
||||||
|
this.writeColor ? ColorTargetState.WRITE_ALL : ColorTargetState.WRITE_NONE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -246,6 +289,7 @@ public class RenderPipelineBuilderWrapper
|
|||||||
|
|
||||||
// vertex format
|
// vertex format
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
VertexFormat.Mode blazeVertexMode;
|
VertexFormat.Mode blazeVertexMode;
|
||||||
switch (this.vertexMode)
|
switch (this.vertexMode)
|
||||||
{
|
{
|
||||||
@@ -264,8 +308,56 @@ public class RenderPipelineBuilderWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.blazePipelineBuilder.withVertexFormat(vertexFormat, blazeVertexMode);
|
this.blazePipelineBuilder.withVertexFormat(vertexFormat, blazeVertexMode);
|
||||||
|
#else
|
||||||
|
|
||||||
|
PrimitiveTopology primitiveTopology;
|
||||||
|
switch (this.vertexMode)
|
||||||
|
{
|
||||||
|
case TRIANGLES:
|
||||||
|
primitiveTopology = PrimitiveTopology.TRIANGLES;
|
||||||
|
break;
|
||||||
|
case TRIANGLE_FAN:
|
||||||
|
primitiveTopology = PrimitiveTopology.TRIANGLE_FAN;
|
||||||
|
break;
|
||||||
|
case LINES:
|
||||||
|
primitiveTopology = PrimitiveTopology.DEBUG_LINES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No PrimitiveTopology defined for type ["+this.vertexMode+"].");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withVertexBinding(0, vertexFormat);
|
||||||
|
this.blazePipelineBuilder.withPrimitiveTopology(primitiveTopology);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// uniform buffers
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
// handled before this point
|
||||||
|
#else
|
||||||
|
|
||||||
|
BindGroupLayout.Builder bindGroupBuilder = BindGroupLayout.builder();
|
||||||
|
|
||||||
|
for (String name : this.samplerNames)
|
||||||
|
{
|
||||||
|
bindGroupBuilder.withSampler(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String name : this.uniformBufferNames)
|
||||||
|
{
|
||||||
|
bindGroupBuilder.withUniform(name, UniformType.UNIFORM_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
BindGroupLayout bindGroup = bindGroupBuilder.build();
|
||||||
|
this.blazePipelineBuilder.withBindGroupLayout(bindGroup);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return this.blazePipelineBuilder.build();
|
return this.blazePipelineBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +418,7 @@ public class RenderPipelineBuilderWrapper
|
|||||||
public enum EDhDepthTest
|
public enum EDhDepthTest
|
||||||
{
|
{
|
||||||
NONE,
|
NONE,
|
||||||
|
GREATER,
|
||||||
LESS;
|
LESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,3 +442,4 @@ public class RenderPipelineBuilderWrapper
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+1
-6
@@ -140,7 +140,7 @@ public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadIndexBuffer(ByteBuffer buffer, int vertexCount)
|
public void uploadIndexBuffer(ByteBuffer indexBuffer, int vertexCount)
|
||||||
{
|
{
|
||||||
int oldIndexCount = this.indexCount;
|
int oldIndexCount = this.indexCount;
|
||||||
// 4 vertices per face, but 6 indices (IE 2 triangles) per face, aka need to multiply by 1.5
|
// 4 vertices per face, but 6 indices (IE 2 triangles) per face, aka need to multiply by 1.5
|
||||||
@@ -169,17 +169,12 @@ public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
|||||||
this.indexGpuBuffer.close();
|
this.indexGpuBuffer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer indexBuffer = IndexBufferBuilder.createBuffer(this.vertexCount);
|
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_INDEX;
|
| GpuBuffer.USAGE_INDEX;
|
||||||
this.indexGpuBuffer = GPU_DEVICE.createBuffer(BlazeVertexBufferWrapper::getIndexBufferName, usage, indexBuffer.capacity());
|
this.indexGpuBuffer = GPU_DEVICE.createBuffer(BlazeVertexBufferWrapper::getIndexBufferName, usage, indexBuffer.capacity());
|
||||||
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.indexGpuBuffer, /*offset*/ 0, indexBuffer.capacity());
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.indexGpuBuffer, /*offset*/ 0, indexBuffer.capacity());
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, indexBuffer);
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, indexBuffer);
|
||||||
|
|
||||||
MemoryUtil.memFree(indexBuffer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
private static String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
||||||
|
|||||||
+6
-3
@@ -14,7 +14,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
|||||||
|
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
|
|
||||||
public class BlazeTextureViewWrapper
|
public class BlazeTextureViewWrapper implements IDhBlazeTexture
|
||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
@@ -22,8 +22,11 @@ public class BlazeTextureViewWrapper
|
|||||||
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
private static final CommandEncoder COMMAND_ENCODER = GPU_DEVICE.createCommandEncoder();
|
||||||
|
|
||||||
|
|
||||||
public GpuTextureView textureView = null;
|
private GpuTextureView textureView = null;
|
||||||
public GpuSampler textureSampler = null;
|
public GpuTextureView getTextureView() { return this.textureView; }
|
||||||
|
|
||||||
|
private GpuSampler textureSampler = null;
|
||||||
|
public GpuSampler getTextureSampler() { return this.textureSampler; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+77
-21
@@ -5,20 +5,27 @@ public class BlazeTextureWrapper {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.textures.*;
|
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
|
|
||||||
public class BlazeTextureWrapper
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.textures.*;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
|
import org.joml.Vector4f;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public class BlazeTextureWrapper implements IDhBlazeTexture
|
||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
@@ -29,11 +36,20 @@ public class BlazeTextureWrapper
|
|||||||
|
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
public final TextureFormat textureFormat;
|
public final TextureFormat textureFormat;
|
||||||
|
#else
|
||||||
|
public final GpuFormat textureFormat;
|
||||||
|
#endif
|
||||||
|
|
||||||
public GpuTexture texture = null;
|
public GpuTexture texture = null;
|
||||||
public GpuTextureView textureView = null;
|
|
||||||
public GpuSampler textureSampler = null;
|
private GpuTextureView textureView = null;
|
||||||
|
public GpuTextureView getTextureView() { return this.textureView; }
|
||||||
|
|
||||||
|
private GpuSampler textureSampler = null;
|
||||||
|
public GpuSampler getTextureSampler() { return this.textureSampler; }
|
||||||
|
|
||||||
|
|
||||||
private int width = -1;
|
private int width = -1;
|
||||||
private int height = -1;
|
private int height = -1;
|
||||||
@@ -45,10 +61,27 @@ public class BlazeTextureWrapper
|
|||||||
//==============//
|
//==============//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
public static BlazeTextureWrapper createDepth(String name) { return new BlazeTextureWrapper(name, TextureFormat.DEPTH32); }
|
public static BlazeTextureWrapper createDepth(String name)
|
||||||
public static BlazeTextureWrapper createColor(String name) { return new BlazeTextureWrapper(name, TextureFormat.RGBA8); }
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
return new BlazeTextureWrapper(name, TextureFormat.DEPTH32);
|
||||||
|
#else
|
||||||
|
return new BlazeTextureWrapper(name, GpuFormat.D32_FLOAT);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public static BlazeTextureWrapper createColor(String name)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
return new BlazeTextureWrapper(name, TextureFormat.RGBA8);
|
||||||
|
#else
|
||||||
|
return new BlazeTextureWrapper(name, GpuFormat.RGBA8_UNORM);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private BlazeTextureWrapper(String name, TextureFormat textureFormat)
|
private BlazeTextureWrapper(
|
||||||
|
String name,
|
||||||
|
#if MC_VER <= MC_26_1_2 TextureFormat #else GpuFormat #endif textureFormat
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.textureFormat = textureFormat;
|
this.textureFormat = textureFormat;
|
||||||
@@ -79,21 +112,30 @@ public class BlazeTextureWrapper
|
|||||||
//=======//
|
//=======//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
/** does nothing if the texture is already created and the correct size */
|
/**
|
||||||
public void tryCreateOrResize()
|
* does nothing if the texture is already created and the correct size
|
||||||
|
* @return true if the texture was (re)created
|
||||||
|
*/
|
||||||
|
public boolean tryCreateOrResize()
|
||||||
{
|
{
|
||||||
this.tryCreateTexture();
|
boolean textureChanged = this.tryCreateTexture();
|
||||||
this.tryCreateSampler();
|
this.tryCreateSampler();
|
||||||
|
return textureChanged;
|
||||||
}
|
}
|
||||||
private void tryCreateTexture()
|
private boolean tryCreateTexture()
|
||||||
{
|
{
|
||||||
int viewWidth = MC_RENDER.getTargetFramebufferViewportWidth();
|
int viewWidth = MC_RENDER.getTargetFramebufferViewportWidth();
|
||||||
int viewHeight = MC_RENDER.getTargetFramebufferViewportHeight();
|
int viewHeight = MC_RENDER.getTargetFramebufferViewportHeight();
|
||||||
|
|
||||||
if (this.texture == null
|
if (this.texture != null
|
||||||
|| this.width != viewWidth
|
&& this.width == viewWidth
|
||||||
|| this.height != viewHeight)
|
&& this.height == viewHeight)
|
||||||
{
|
{
|
||||||
|
// no changes needed
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this.texture != null)
|
if (this.texture != null)
|
||||||
{
|
{
|
||||||
this.texture.close();
|
this.texture.close();
|
||||||
@@ -107,14 +149,17 @@ public class BlazeTextureWrapper
|
|||||||
| GpuTexture.USAGE_TEXTURE_BINDING
|
| GpuTexture.USAGE_TEXTURE_BINDING
|
||||||
| GpuTexture.USAGE_COPY_SRC
|
| GpuTexture.USAGE_COPY_SRC
|
||||||
| GpuTexture.USAGE_RENDER_ATTACHMENT;
|
| GpuTexture.USAGE_RENDER_ATTACHMENT;
|
||||||
this.texture = GPU_DEVICE.createTexture(this.name,
|
|
||||||
|
this.texture = GPU_DEVICE.createTexture(
|
||||||
|
this.name,
|
||||||
usage,
|
usage,
|
||||||
this.textureFormat,
|
this.textureFormat,
|
||||||
viewWidth, viewHeight,
|
viewWidth, viewHeight,
|
||||||
/*depthOrLayers*/ 1, /*mipLevels*/ 1
|
/*depthOrLayers*/ 1, /*mipLevels*/ 1
|
||||||
);
|
);
|
||||||
this.textureView = GPU_DEVICE.createTextureView(this.texture);
|
this.textureView = GPU_DEVICE.createTextureView(this.texture);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
private void tryCreateSampler()
|
private void tryCreateSampler()
|
||||||
{
|
{
|
||||||
@@ -146,7 +191,18 @@ public class BlazeTextureWrapper
|
|||||||
{
|
{
|
||||||
if (this.texture != null)
|
if (this.texture != null)
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
COMMAND_ENCODER.clearColorTexture(this.texture, clearArgbColor);
|
COMMAND_ENCODER.clearColorTexture(this.texture, clearArgbColor);
|
||||||
|
#else
|
||||||
|
Vector4f clearColor = new Vector4f(
|
||||||
|
// color values should be between 0.0 and 1.0
|
||||||
|
ColorUtil.getRed(clearArgbColor) / 255.0f,
|
||||||
|
ColorUtil.getGreen(clearArgbColor) / 255.0f,
|
||||||
|
ColorUtil.getBlue(clearArgbColor) / 255.0f,
|
||||||
|
ColorUtil.getAlpha(clearArgbColor) / 255.0f
|
||||||
|
);
|
||||||
|
COMMAND_ENCODER.clearColorTexture(this.texture, clearColor);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package com.seibel.distanthorizons.common.render.blaze.wrappers.texture;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
public interface IDhBlazeTexture {}
|
||||||
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.textures.GpuSampler;
|
||||||
|
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||||
|
|
||||||
|
public interface IDhBlazeTexture
|
||||||
|
{
|
||||||
|
|
||||||
|
GpuTextureView getTextureView();
|
||||||
|
GpuSampler getTextureSampler();
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+10
-27
@@ -5,14 +5,10 @@ public class BlazeLodUniformBufferWrapper {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
||||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodContainerUniformBufferWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodContainerUniformBufferWrapper;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
public class BlazeLodUniformBufferWrapper extends BlazeUniformBufferWrapper implements ILodContainerUniformBufferWrapper
|
public class BlazeLodUniformBufferWrapper extends BlazeUniformBufferWrapper implements ILodContainerUniformBufferWrapper
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -37,35 +33,22 @@ public class BlazeLodUniformBufferWrapper extends BlazeUniformBufferWrapper impl
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createUniformData(LodBufferContainer bufferContainer)
|
public void tryUpload(LodBufferContainer bufferContainer)
|
||||||
{
|
|
||||||
Vec3f modelOffset = new Vec3f(
|
|
||||||
(float) (bufferContainer.minCornerBlockPos.getX()),
|
|
||||||
(float) (bufferContainer.minCornerBlockPos.getY()),
|
|
||||||
(float) (bufferContainer.minCornerBlockPos.getZ()));
|
|
||||||
|
|
||||||
// upload data //
|
|
||||||
|
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
|
||||||
.putVec3() // uModelOffset
|
|
||||||
.get();
|
|
||||||
|
|
||||||
ByteBuffer buffer = this.getOrCreateBuffer(uniformBufferSize);
|
|
||||||
Std140Builder.intoBuffer(buffer)
|
|
||||||
.putVec3(modelOffset.x, modelOffset.y, modelOffset.z) // uModelOffset
|
|
||||||
.get();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tryUpload()
|
|
||||||
{
|
{
|
||||||
if (this.uploaded)
|
if (this.uploaded)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.upload();
|
Vec3f modelOffset = new Vec3f(
|
||||||
|
(float) (bufferContainer.minCornerBlockPos.getX()),
|
||||||
|
(float) (bufferContainer.minCornerBlockPos.getY()),
|
||||||
|
(float) (bufferContainer.minCornerBlockPos.getZ()));
|
||||||
|
|
||||||
|
// upload data //
|
||||||
|
this
|
||||||
|
.putVec3f(modelOffset.x, modelOffset.y, modelOffset.z) // uModelOffset
|
||||||
|
.finishAndUpload();
|
||||||
|
|
||||||
this.uploaded = true;
|
this.uploaded = true;
|
||||||
}
|
}
|
||||||
|
|||||||
+155
-41
@@ -7,17 +7,23 @@ public class BlazeUniformBufferWrapper {}
|
|||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
||||||
|
import com.mojang.blaze3d.buffers.Std140Builder;
|
||||||
|
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||||
|
import com.seibel.distanthorizons.common.render.blaze.util.BlazeUniformUtil;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IUniformBufferWrapper;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class BlazeUniformBufferWrapper implements IUniformBufferWrapper
|
public class BlazeUniformBufferWrapper implements AutoCloseable
|
||||||
{
|
{
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
@@ -27,11 +33,22 @@ public class BlazeUniformBufferWrapper implements IUniformBufferWrapper
|
|||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private int cpuBufferSize = 0;
|
/** measured in bytes */
|
||||||
private int gpuBufferSize = 0;
|
private int bufferSize = 0;
|
||||||
|
|
||||||
private ByteBuffer cpuBuffer = null;
|
private ByteBuffer cpuBuffer = null;
|
||||||
public GpuBuffer gpuBuffer = null;
|
|
||||||
|
private GpuBuffer gpuBuffer = null;
|
||||||
|
public GpuBuffer getGpuBuffer() { return this.gpuBuffer; }
|
||||||
|
private GpuBufferSlice bufferSlice = null;
|
||||||
|
|
||||||
|
/** the element count the current CPU Buffer is sized for */
|
||||||
|
private int previousElementCount = 0;
|
||||||
|
/** how many elements are currently in flight (ie being added to the buffer right now) */
|
||||||
|
private int elementCount = 0;
|
||||||
|
/** used to resize the buffers dur first-time setup */
|
||||||
|
private final ArrayList<EUniformElement> uniformElementTypes = new ArrayList<>(0);
|
||||||
|
private Std140Builder uniformBufferBuilder = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -46,63 +63,136 @@ public class BlazeUniformBufferWrapper implements IUniformBufferWrapper
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//========//
|
//=================//
|
||||||
// render //
|
// element builder //
|
||||||
//========//
|
//=================//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
protected ByteBuffer getOrCreateBuffer(int size)
|
public BlazeUniformBufferWrapper putVec2f(float x, float y)
|
||||||
{
|
{
|
||||||
if (this.cpuBuffer == null
|
this.putElement(EUniformElement.VEC2f);
|
||||||
|| this.cpuBufferSize != size)
|
this.uniformBufferBuilder.putVec2(x,y);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putVec3i(int x, int y, int z)
|
||||||
{
|
{
|
||||||
this.cpuBuffer = ByteBuffer.allocateDirect(size);
|
this.putElement(EUniformElement.VEC3i);
|
||||||
|
this.uniformBufferBuilder.putIVec3(x,y,z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putVec3f(float x, float y, float z)
|
||||||
|
{
|
||||||
|
this.putElement(EUniformElement.VEC3f);
|
||||||
|
this.uniformBufferBuilder.putVec3(x,y,z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putVec4f(float x, float y, float z, float w)
|
||||||
|
{
|
||||||
|
this.putElement(EUniformElement.VEC4f);
|
||||||
|
this.uniformBufferBuilder.putVec4(x,y,z,w);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putMat4f(DhApiMat4f matrix)
|
||||||
|
{
|
||||||
|
this.putElement(EUniformElement.MAT4f);
|
||||||
|
this.uniformBufferBuilder.putMat4f(Mat4f.createJomlMatrix(matrix));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putFloat(float f)
|
||||||
|
{
|
||||||
|
this.putElement(EUniformElement.FLOAT);
|
||||||
|
this.uniformBufferBuilder.putFloat(f);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public BlazeUniformBufferWrapper putInt(int i)
|
||||||
|
{
|
||||||
|
this.putElement(EUniformElement.INT);
|
||||||
|
this.uniformBufferBuilder.putInt(i);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
private void putElement(EUniformElement elementTypeEnum)
|
||||||
|
{
|
||||||
|
this.uniformElementTypes.add(elementTypeEnum);
|
||||||
|
|
||||||
|
boolean createNewBuilder = (this.elementCount == 0);
|
||||||
|
this.elementCount++;
|
||||||
|
if (this.elementCount > this.previousElementCount)
|
||||||
|
{
|
||||||
|
this.recreateCpuBuffer();
|
||||||
|
createNewBuilder = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createNewBuilder)
|
||||||
|
{
|
||||||
|
this.uniformBufferBuilder = Std140Builder.intoBuffer(this.cpuBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void recreateCpuBuffer()
|
||||||
|
{
|
||||||
|
ByteBuffer oldBuffer = this.cpuBuffer;
|
||||||
|
|
||||||
|
int size = calcBufferSize(this.uniformElementTypes);
|
||||||
|
this.cpuBuffer = MemoryUtil.memAlloc(size);
|
||||||
this.cpuBuffer.order(ByteOrder.nativeOrder());
|
this.cpuBuffer.order(ByteOrder.nativeOrder());
|
||||||
|
|
||||||
this.cpuBufferSize = size;
|
if (oldBuffer != null)
|
||||||
}
|
|
||||||
|
|
||||||
return this.cpuBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void upload() throws IllegalStateException
|
|
||||||
{
|
{
|
||||||
if (this.cpuBuffer == null)
|
oldBuffer.position(0);
|
||||||
|
this.cpuBuffer.put(oldBuffer);
|
||||||
|
MemoryUtil.memFree(oldBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bufferSize = size;
|
||||||
|
this.previousElementCount = this.elementCount;
|
||||||
|
}
|
||||||
|
private static int calcBufferSize(ArrayList<EUniformElement> uniformElements)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Upload called before buffer was created");
|
Std140SizeCalculator calculator = new Std140SizeCalculator();
|
||||||
}
|
|
||||||
|
|
||||||
if (this.gpuBuffer == null
|
for (int i = 0; i < uniformElements.size(); i++)
|
||||||
|| this.gpuBufferSize != this.cpuBufferSize)
|
|
||||||
{
|
{
|
||||||
if (this.gpuBuffer != null)
|
EUniformElement element = uniformElements.get(i);
|
||||||
|
switch (element)
|
||||||
{
|
{
|
||||||
this.gpuBuffer.close();
|
case VEC2f -> calculator.putVec2();
|
||||||
|
case VEC3i -> calculator.putIVec3();
|
||||||
|
case VEC3f -> calculator.putVec3();
|
||||||
|
case VEC4f -> calculator.putVec4();
|
||||||
|
case MAT4f -> calculator.putMat4f();
|
||||||
|
case INT -> calculator.putInt();
|
||||||
|
case FLOAT -> calculator.putFloat();
|
||||||
|
|
||||||
|
default -> throw new UnsupportedOperationException("No definition for element type ["+element.name()+"]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
return calculator.get();
|
||||||
| GpuBuffer.USAGE_VERTEX
|
|
||||||
| GpuBuffer.USAGE_UNIFORM;
|
|
||||||
this.gpuBuffer = GPU_DEVICE.createBuffer(this::getBufferName, usage, this.cpuBufferSize);
|
|
||||||
|
|
||||||
this.gpuBufferSize = this.cpuBufferSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int byteSize = (this.cpuBuffer.limit() - this.cpuBuffer.position());
|
public void finishAndUpload()
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.gpuBuffer, /*offset*/0, byteSize);
|
|
||||||
if (!bufferSlice.buffer().isClosed())
|
|
||||||
{
|
{
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, this.cpuBuffer);
|
// re-create the GPU buffer if needed
|
||||||
}
|
GpuBuffer oldGpuBuffer = this.gpuBuffer;
|
||||||
else
|
this.gpuBuffer = BlazeUniformUtil.createBuffer(this.name, this.bufferSize, this.gpuBuffer);
|
||||||
|
|
||||||
|
boolean createNewBufferSlice = (this.bufferSlice == null || this.gpuBuffer != oldGpuBuffer);
|
||||||
|
if (createNewBufferSlice)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Uploading to buffer ["+this.name+"] failed due to already being closed");
|
this.bufferSlice = new GpuBufferSlice(this.gpuBuffer, 0, this.bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// upload to GPU
|
||||||
|
this.cpuBuffer.position(0);
|
||||||
|
COMMAND_ENCODER.writeToBuffer(this.bufferSlice, this.cpuBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
// clear the element tracking for next time
|
||||||
|
this.elementCount = 0;
|
||||||
|
this.uniformElementTypes.clear();
|
||||||
|
this.uniformBufferBuilder = null;
|
||||||
}
|
}
|
||||||
private String getBufferName() { return this.name; }
|
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@@ -120,11 +210,35 @@ public class BlazeUniformBufferWrapper implements IUniformBufferWrapper
|
|||||||
{
|
{
|
||||||
this.gpuBuffer.close();
|
this.gpuBuffer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.cpuBuffer != null)
|
||||||
|
{
|
||||||
|
MemoryUtil.memFree(this.cpuBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper classes //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
private enum EUniformElement
|
||||||
|
{
|
||||||
|
VEC2f,
|
||||||
|
VEC3f,
|
||||||
|
VEC3i,
|
||||||
|
VEC4f,
|
||||||
|
MAT4f,
|
||||||
|
INT,
|
||||||
|
FLOAT,
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+5
-8
@@ -10,10 +10,10 @@ import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
|||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GlDhFramebuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GlDhFramebuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.texture.*;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.texture.*;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.postProcessing.apply.GlDhApplyShader;
|
import com.seibel.distanthorizons.common.render.openGl.postProcessing.apply.GlDhApplyShader;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.terrain.GlDhTerrainShaderProgram;
|
|
||||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
@@ -21,7 +21,7 @@ import com.seibel.distanthorizons.core.render.DhApiRenderProxy;
|
|||||||
import com.seibel.distanthorizons.core.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
|
||||||
@@ -45,6 +45,8 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||||
|
|
||||||
|
private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
|
||||||
|
|
||||||
|
|
||||||
private int activeFramebufferId = -1;
|
private int activeFramebufferId = -1;
|
||||||
private int activeColorTextureId = -1;
|
private int activeColorTextureId = -1;
|
||||||
@@ -242,7 +244,7 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
|
|
||||||
// create or get the frame buffer
|
// create or get the frame buffer
|
||||||
if (AbstractOptifineAccessor.optifinePresent())
|
if (OPTIFINE_ACCESSOR != null)
|
||||||
{
|
{
|
||||||
// use MC/Optifine's default Framebuffer so shaders won't remove the LODs
|
// use MC/Optifine's default Framebuffer so shaders won't remove the LODs
|
||||||
int currentFramebufferId = MC_RENDER.getTargetFramebuffer();
|
int currentFramebufferId = MC_RENDER.getTargetFramebuffer();
|
||||||
@@ -383,10 +385,6 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// needs to be fired after all the textures have been created/bound
|
|
||||||
boolean clearTextures = !ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeTextureClearEvent.class, renderParams);
|
|
||||||
if (clearTextures)
|
|
||||||
{
|
|
||||||
GL32.glClearDepth(1.0);
|
GL32.glClearDepth(1.0);
|
||||||
|
|
||||||
float[] clearColorValues = new float[4];
|
float[] clearColorValues = new float[4];
|
||||||
@@ -408,7 +406,6 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
{
|
{
|
||||||
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
GL32.glClear(GL32.GL_COLOR_BUFFER_BIT | GL32.GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -1,5 +1,7 @@
|
|||||||
package com.seibel.distanthorizons.common.render.openGl;
|
package com.seibel.distanthorizons.common.render.openGl;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingApi;
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectRenderer;
|
import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectVertexContainer;
|
import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectVertexContainer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GlDummyUniformData;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GlDummyUniformData;
|
||||||
@@ -8,8 +10,8 @@ import com.seibel.distanthorizons.common.render.openGl.postProcessing.fade.GlDhF
|
|||||||
import com.seibel.distanthorizons.common.render.openGl.postProcessing.fade.GlVanillaFadeRenderer;
|
import com.seibel.distanthorizons.common.render.openGl.postProcessing.fade.GlVanillaFadeRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.postProcessing.fog.GlDhFogRenderer;
|
import com.seibel.distanthorizons.common.render.openGl.postProcessing.fog.GlDhFogRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.postProcessing.ssao.GlDhSSAORenderer;
|
import com.seibel.distanthorizons.common.render.openGl.postProcessing.ssao.GlDhSSAORenderer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.terrain.GlDhTerrainShaderProgram;
|
|
||||||
import com.seibel.distanthorizons.common.render.openGl.test.GlTestTriangleRenderer;
|
import com.seibel.distanthorizons.common.render.openGl.test.GlTestTriangleRenderer;
|
||||||
|
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||||
@@ -26,6 +28,16 @@ public class GlDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
|||||||
|
|
||||||
public String getApiName() { return "OpenGL"; }
|
public String getApiName() { return "OpenGL"; }
|
||||||
|
|
||||||
|
public EDhRenderDepth getRenderDepth()
|
||||||
|
{
|
||||||
|
// reversed Z shouldn't be supported on OpenGL due
|
||||||
|
// to that breaking Iris shaders
|
||||||
|
return EDhRenderDepth.FORWARD_Z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EDhApiRenderingApi getRenderApi() { return EDhApiRenderingApi.OPEN_GL; }
|
||||||
|
public boolean isNativeRenderer() { return true; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+40
-18
@@ -75,6 +75,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
private static final DhApiRenderableBoxGroupShading DEFAULT_SHADING = DhApiRenderableBoxGroupShading.getUnshaded();
|
private static final DhApiRenderableBoxGroupShading DEFAULT_SHADING = DhApiRenderableBoxGroupShading.getUnshaded();
|
||||||
|
|
||||||
|
private static final DhApiBeforeGenericObjectRenderEvent.EventParam EVENT_PARAM = new DhApiBeforeGenericObjectRenderEvent.EventParam();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to troubleshoot the renderer.
|
* Can be used to troubleshoot the renderer.
|
||||||
@@ -413,11 +414,12 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
|
|
||||||
// render setup //
|
// render setup //
|
||||||
profiler.push("setup");
|
try (IProfilerWrapper.IProfileBlock setup_profile = profiler.push("setup"))
|
||||||
|
{
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam.apiCopy);
|
||||||
|
|
||||||
|
|
||||||
boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
|
boolean renderWireframe = Config.Client.Advanced.Debugging.renderWireframe.get();
|
||||||
@@ -481,7 +483,8 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allow API users to cancel this object's rendering
|
// allow API users to cancel this object's rendering
|
||||||
boolean cancelRendering = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericObjectRenderEvent.class, new DhApiBeforeGenericObjectRenderEvent.EventParam(renderEventParam, boxGroup));
|
EVENT_PARAM.update(renderEventParam, boxGroup);
|
||||||
|
boolean cancelRendering = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericObjectRenderEvent.class, EVENT_PARAM);
|
||||||
if (cancelRendering)
|
if (cancelRendering)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -504,8 +507,9 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
// render //
|
// render //
|
||||||
|
|
||||||
profiler.popPush("rendering");
|
profiler.popPush("rendering");
|
||||||
profiler.push(boxGroup.getResourceLocationNamespace());
|
try (IProfilerWrapper.IProfileBlock namespace_profile = profiler.push(boxGroup.getResourceLocationNamespace());
|
||||||
profiler.push(boxGroup.getResourceLocationPath());
|
IProfilerWrapper.IProfileBlock location_profile = profiler.push(boxGroup.getResourceLocationPath()))
|
||||||
|
{
|
||||||
if (this.instancedRenderingAvailable)
|
if (this.instancedRenderingAvailable)
|
||||||
{
|
{
|
||||||
this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
||||||
@@ -514,8 +518,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
{
|
{
|
||||||
this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
||||||
}
|
}
|
||||||
profiler.pop(); // resource path
|
}
|
||||||
profiler.pop(); // resource namespace
|
|
||||||
|
|
||||||
boxGroup.postRender(renderEventParam);
|
boxGroup.postRender(renderEventParam);
|
||||||
}
|
}
|
||||||
@@ -528,7 +531,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
profiler.popPush("cleanup");
|
profiler.popPush("cleanup");
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderCleanupEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderCleanupEvent.class, renderEventParam.apiCopy);
|
||||||
|
|
||||||
if (renderWireframe)
|
if (renderWireframe)
|
||||||
{
|
{
|
||||||
@@ -538,8 +541,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
shaderProgram.unbind();
|
shaderProgram.unbind();
|
||||||
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -556,10 +558,10 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
RenderableBoxGroup boxGroup, Vec3d camPos,
|
RenderableBoxGroup boxGroup, Vec3d camPos,
|
||||||
IProfilerWrapper profiler)
|
IProfilerWrapper profiler)
|
||||||
{
|
{
|
||||||
|
try (IProfilerWrapper.IProfileBlock render_profile = profiler.push("vertex setup"))
|
||||||
|
{
|
||||||
|
|
||||||
// update instance data //
|
// update instance data //
|
||||||
|
|
||||||
profiler.push("vertex setup");
|
|
||||||
|
|
||||||
DhApiRenderableBoxGroupShading shading = boxGroup.shading;
|
DhApiRenderableBoxGroupShading shading = boxGroup.shading;
|
||||||
if (shading == null)
|
if (shading == null)
|
||||||
{
|
{
|
||||||
@@ -576,7 +578,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
// Bind instance data //
|
// Bind instance data //
|
||||||
profiler.popPush("binding");
|
profiler.popPush("binding");
|
||||||
|
|
||||||
GlGenericObjectVertexContainer container = (GlGenericObjectVertexContainer)(boxGroup.vertexBufferContainer);
|
GlGenericObjectVertexContainer container = (GlGenericObjectVertexContainer) (boxGroup.vertexBufferContainer);
|
||||||
|
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, container.color);
|
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, container.color);
|
||||||
GL32.glEnableVertexAttribArray(1);
|
GL32.glEnableVertexAttribArray(1);
|
||||||
@@ -620,8 +622,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
GL32.glDisableVertexAttribArray(3);
|
GL32.glDisableVertexAttribArray(3);
|
||||||
GL32.glDisableVertexAttribArray(4);
|
GL32.glDisableVertexAttribArray(4);
|
||||||
GL32.glDisableVertexAttribArray(5);
|
GL32.glDisableVertexAttribArray(5);
|
||||||
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Clean way to handle both {@link GL33#glVertexAttribDivisor} and {@link ARBInstancedArrays#glVertexAttribDivisorARB}
|
* Clean way to handle both {@link GL33#glVertexAttribDivisor} and {@link ARBInstancedArrays#glVertexAttribDivisorARB}
|
||||||
@@ -689,8 +690,6 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -751,4 +750,27 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
if (this.boxVertexBuffer != null)
|
||||||
|
{
|
||||||
|
this.boxVertexBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.boxIndexBuffer != null)
|
||||||
|
{
|
||||||
|
this.boxIndexBuffer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+55
-11
@@ -21,13 +21,18 @@ package com.seibel.distanthorizons.common.render.openGl.glObject;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGLErrorHandlingMode;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGLErrorHandlingMode;
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingApi;
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.jar.EPlatform;
|
import com.seibel.distanthorizons.core.jar.EPlatform;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.util.objects.GLMessages.*;
|
import com.seibel.distanthorizons.core.util.objects.GLMessages.*;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
@@ -46,10 +51,33 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class GLProxy
|
public class GLProxy
|
||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||||
.fileLevelConfig(Config.Common.Logging.logRendererGLEventToFile)
|
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||||
.chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat)
|
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
.build();
|
|
||||||
|
|
||||||
|
public static final DhLogger LOGGER;
|
||||||
|
static
|
||||||
|
{
|
||||||
|
DhLoggerBuilder loggerBuilder = new DhLoggerBuilder();
|
||||||
|
loggerBuilder.fileLevelConfig(Config.Common.Logging.logRendererGLEventToFile);
|
||||||
|
|
||||||
|
// don't send chat messages if Iris is present since
|
||||||
|
// Iris is known to cause (harmless) GL errors
|
||||||
|
// and this can confuse users
|
||||||
|
boolean irisPresent = (IRIS_ACCESSOR != null);
|
||||||
|
if (!irisPresent)
|
||||||
|
{
|
||||||
|
loggerBuilder.chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER = loggerBuilder.build();
|
||||||
|
|
||||||
|
if (irisPresent)
|
||||||
|
{
|
||||||
|
LOGGER.info("Iris detected, Distant Horizons OpenGL error logging won't be sent in the chat due to Iris throwing known (harmless) OpenGL errors. This is a bug with Iris, not Distant Horizons.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final Set<String> LOGGED_GL_MESSAGES = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
public static final Set<String> LOGGED_GL_MESSAGES = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
@@ -102,13 +130,22 @@ public class GLProxy
|
|||||||
|
|
||||||
private GLProxy() throws IllegalStateException
|
private GLProxy() throws IllegalStateException
|
||||||
{
|
{
|
||||||
|
if (RENDER_API_DEF.getRenderApi() != EDhApiRenderingApi.OPEN_GL)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("[" + GLProxy.class.getSimpleName() + "] was created with the wrong Rendering API ["+RENDER_API_DEF.getRenderApi()+"]!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// this must be created on minecraft's render context to work correctly
|
// this must be created on minecraft's render context to work correctly
|
||||||
if (GLFW.glfwGetCurrentContext() == 0L)
|
if (GLFW.glfwGetCurrentContext() == 0L)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(GLProxy.class.getSimpleName() + " was created outside the render thread!");
|
String message = "[" + GLProxy.class.getSimpleName() + "] was created outside the render thread!";
|
||||||
|
IllegalStateException exception = new IllegalStateException(message);
|
||||||
|
MC_CLIENT.crashMinecraft(message, exception);
|
||||||
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see there must have been an OpenGL error.");
|
LOGGER.info("Creating [" + GLProxy.class.getSimpleName() + "]... If this is the last message you see there must have been an OpenGL error.");
|
||||||
LOGGER.info("Lod Render OpenGL version [" + GL32.glGetString(GL32.GL_VERSION) + "].");
|
LOGGER.info("Lod Render OpenGL version [" + GL32.glGetString(GL32.GL_VERSION) + "].");
|
||||||
|
|
||||||
|
|
||||||
@@ -238,7 +275,7 @@ public class GLProxy
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
/** this method is called on the render thread at the point of the GL Error */
|
/** this method is called on the render thread at the point of the GL Error */
|
||||||
private static void logMessage(GLMessage msg)
|
private static void logMessage(GLMessage glMessage)
|
||||||
{
|
{
|
||||||
EDhApiGLErrorHandlingMode errorHandlingMode = Config.Client.Advanced.Debugging.OpenGl.glErrorHandlingMode.get();
|
EDhApiGLErrorHandlingMode errorHandlingMode = Config.Client.Advanced.Debugging.OpenGl.glErrorHandlingMode.get();
|
||||||
if (errorHandlingMode == EDhApiGLErrorHandlingMode.IGNORE)
|
if (errorHandlingMode == EDhApiGLErrorHandlingMode.IGNORE)
|
||||||
@@ -249,19 +286,26 @@ public class GLProxy
|
|||||||
|
|
||||||
|
|
||||||
boolean onlyLogOnce = Config.Client.Advanced.Debugging.OpenGl.onlyLogGlErrorsOnce.get();
|
boolean onlyLogOnce = Config.Client.Advanced.Debugging.OpenGl.onlyLogGlErrorsOnce.get();
|
||||||
String errorMessage = "GL ERROR [" + msg.id + "] from [" + msg.source + "]: [" + msg.message + "]"+(onlyLogOnce ? " this message will only be logged once" : "")+".";
|
|
||||||
if (onlyLogOnce
|
if (onlyLogOnce
|
||||||
&& !LOGGED_GL_MESSAGES.add(errorMessage))
|
&& !LOGGED_GL_MESSAGES.add(glMessage.message))
|
||||||
{
|
{
|
||||||
// this message has already been logged
|
// this message has already been logged
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String errorMessage = "GL ERROR [" + glMessage.id + "] from [" + glMessage.source + "]: [" + glMessage.message + "].";
|
||||||
|
if (onlyLogOnce)
|
||||||
|
{
|
||||||
|
errorMessage += " This message will only be logged once.";
|
||||||
|
errorMessage += " Note: Distant Horizons will catch and log OpenGL errors from other mods, not just DH itself; if everything is rendering correctly these errors can probably be ignored.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// create an exception so we get a stacktrace of where the message was triggered from
|
// create an exception so we get a stacktrace of where the message was triggered from
|
||||||
RuntimeException exception = new RuntimeException(errorMessage);
|
RuntimeException exception = new RuntimeException(errorMessage);
|
||||||
|
|
||||||
if (msg.type == EGLMessageType.ERROR || msg.type == EGLMessageType.UNDEFINED_BEHAVIOR)
|
if (glMessage.type == EGLMessageType.ERROR || glMessage.type == EGLMessageType.UNDEFINED_BEHAVIOR)
|
||||||
{
|
{
|
||||||
// critical error
|
// critical error
|
||||||
|
|
||||||
@@ -278,7 +322,7 @@ public class GLProxy
|
|||||||
{
|
{
|
||||||
// non-critical log
|
// non-critical log
|
||||||
|
|
||||||
EGLMessageSeverity severity = msg.severity;
|
EGLMessageSeverity severity = glMessage.severity;
|
||||||
if (severity == null)
|
if (severity == null)
|
||||||
{
|
{
|
||||||
// just in case the message was malformed
|
// just in case the message was malformed
|
||||||
|
|||||||
+15
-1
@@ -97,7 +97,9 @@ public class GLState implements AutoCloseable
|
|||||||
{
|
{
|
||||||
this.frameBufferTexture0 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
this.frameBufferTexture0 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
||||||
this.frameBufferTexture1 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
this.frameBufferTexture1 = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
||||||
this.frameBufferDepthTexture = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
|
|
||||||
|
int depthType = GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
|
||||||
|
this.frameBufferDepthTexture = (depthType == GL32.GL_TEXTURE) ? GL32.glGetFramebufferAttachmentParameteri(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) : 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -178,12 +180,24 @@ public class GLState implements AutoCloseable
|
|||||||
|
|
||||||
// attempting to set textures on the default frame buffer (ID 0) will throw errors
|
// attempting to set textures on the default frame buffer (ID 0) will throw errors
|
||||||
if (frameBufferSet)
|
if (frameBufferSet)
|
||||||
|
{
|
||||||
|
if (GL32.glIsTexture(this.frameBufferTexture0))
|
||||||
{
|
{
|
||||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.frameBufferTexture0, 0);
|
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.frameBufferTexture0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.frameBufferTexture1 != 0 && GL32.glIsTexture(this.frameBufferTexture1))
|
||||||
|
{
|
||||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_TEXTURE_2D, this.frameBufferTexture1, 0);
|
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT1, GL32.GL_TEXTURE_2D, this.frameBufferTexture1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GL32.glIsTexture(this.frameBufferDepthTexture))
|
||||||
|
{
|
||||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, this.frameBufferDepthTexture, 0);
|
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_DEPTH_ATTACHMENT, GL32.GL_TEXTURE_2D, this.frameBufferDepthTexture, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
GL32.glBindVertexArray(GL32.glIsVertexArray(this.vao) ? this.vao : 0);
|
GL32.glBindVertexArray(GL32.glIsVertexArray(this.vao) ? this.vao : 0);
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(this.vbo) ? this.vbo : 0);
|
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(this.vbo) ? this.vbo : 0);
|
||||||
GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, GL32.glIsBuffer(this.ebo) ? this.ebo: 0);
|
GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, GL32.glIsBuffer(this.ebo) ? this.ebo: 0);
|
||||||
|
|||||||
+1
-3
@@ -9,9 +9,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodCont
|
|||||||
*/
|
*/
|
||||||
public class GlDummyUniformData implements ILodContainerUniformBufferWrapper
|
public class GlDummyUniformData implements ILodContainerUniformBufferWrapper
|
||||||
{
|
{
|
||||||
@Override public void createUniformData(LodBufferContainer bufferContainer) { }
|
@Override public void tryUpload(LodBufferContainer bufferContainer) { }
|
||||||
@Override public void tryUpload() { }
|
|
||||||
@Override public void upload() { }
|
|
||||||
@Override public void close() { }
|
@Override public void close() { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+287
-41
@@ -21,14 +21,19 @@ package com.seibel.distanthorizons.common.render.openGl.glObject.buffer;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GLState;
|
|
||||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.jar.EPlatform;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||||
|
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||||
|
import com.seibel.distanthorizons.core.util.objects.pooling.PhantomLoggingHelper;
|
||||||
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
import org.lwjgl.opengl.GL44;
|
import org.lwjgl.opengl.GL44;
|
||||||
|
|
||||||
@@ -36,9 +41,12 @@ import java.lang.ref.PhantomReference;
|
|||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.ReferenceQueue;
|
import java.lang.ref.ReferenceQueue;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.locks.StampedLock;
|
||||||
|
|
||||||
public class GLBuffer implements AutoCloseable
|
public class GLBuffer implements AutoCloseable
|
||||||
{
|
{
|
||||||
@@ -50,26 +58,57 @@ public class GLBuffer implements AutoCloseable
|
|||||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO move to a shared location that can be handled by both GL and Blaze3D buffers
|
||||||
|
/** if enabled the number of GC'ed buffers will be logged */
|
||||||
|
private static final boolean LOG_PHANTOM_RECOVERY = ModInfo.IS_DEV_BUILD;
|
||||||
|
/** If enabled buffers allocation/upload stacks will be logged when GC'ed. */
|
||||||
|
private static final boolean LOG_PHANTOM_ALLOCATION_STACKS = false; // disabled by default due to the increased GC load
|
||||||
|
|
||||||
public static final double BUFFER_EXPANSION_MULTIPLIER = 1.3;
|
public static final double BUFFER_EXPANSION_MULTIPLIER = 1.3;
|
||||||
public static final double BUFFER_SHRINK_TRIGGER = BUFFER_EXPANSION_MULTIPLIER * BUFFER_EXPANSION_MULTIPLIER;
|
public static final double BUFFER_SHRINK_TRIGGER = BUFFER_EXPANSION_MULTIPLIER * BUFFER_EXPANSION_MULTIPLIER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On macOS the legacy OpenGL -> Metal bridge crashes with SIGBUS in
|
||||||
|
* {@code _platform_memmove} when {@code glBufferData} or {@code glBufferSubData}
|
||||||
|
* are called with a large ByteBuffer in one shot. To work around it, we split
|
||||||
|
* the upload into smaller sub-data calls that each fit comfortably inside the
|
||||||
|
* driver's internal staging path. <br>
|
||||||
|
* 256 KiB tuned empirically against macOS 26.5 — a 1 MiB chunk still
|
||||||
|
* tripped the same {@code _platform_memmove} crash inside
|
||||||
|
* {@code glBufferSubData_Exec}, but 256 KiB consistently survives.
|
||||||
|
*/
|
||||||
|
public static final int MAC_UPLOAD_CHUNK_BYTES = 256 * 1024;
|
||||||
|
/** Threshold above which the chunked path kicks in on macOS. */
|
||||||
|
public static final int MAC_UPLOAD_CHUNK_THRESHOLD = MAC_UPLOAD_CHUNK_BYTES;
|
||||||
/** the number of active buffers, can be used for debugging */
|
/** the number of active buffers, can be used for debugging */
|
||||||
public static AtomicInteger bufferCount = new AtomicInteger(0);
|
public static AtomicInteger bufferCount = new AtomicInteger(0);
|
||||||
|
|
||||||
private static final int PHANTOM_REF_CHECK_TIME_IN_MS = 5 * 1000;
|
private static final int PHANTOM_REF_CHECK_TIME_IN_MS = 5 * 1000;
|
||||||
private static final ConcurrentHashMap<PhantomReference<? extends GLBuffer>, Integer> PHANTOM_TO_BUFFER_ID = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<PhantomReference<? extends GLBuffer>, Integer> PHANTOM_TO_BUFFER_ID = new ConcurrentHashMap<>();
|
||||||
private static final ConcurrentHashMap<Integer, PhantomReference<? extends GLBuffer>> BUFFER_ID_TO_PHANTOM = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<Integer, PhantomReference<? extends GLBuffer>> BUFFER_ID_TO_PHANTOM = new ConcurrentHashMap<>();
|
||||||
|
private static final ConcurrentHashMap<Integer, String> BUFFER_ID_TO_ALLOCATION_STRING = new ConcurrentHashMap<>();
|
||||||
private static final ReferenceQueue<GLBuffer> PHANTOM_REFERENCE_QUEUE = new ReferenceQueue<>();
|
private static final ReferenceQueue<GLBuffer> PHANTOM_REFERENCE_QUEUE = new ReferenceQueue<>();
|
||||||
private static final ThreadPoolExecutor CLEANUP_THREAD = ThreadUtil.makeSingleDaemonThreadPool("GLBuffer Cleanup");
|
private static final ThreadPoolExecutor CLEANUP_THREAD = ThreadUtil.makeSingleDaemonThreadPool("GLBuffer Cleanup");
|
||||||
|
|
||||||
|
|
||||||
protected int id;
|
protected volatile int id = 0;
|
||||||
public final int getId() { return this.id; }
|
public final int getId() { return this.id; }
|
||||||
protected int size = 0;
|
protected int size = 0;
|
||||||
public int getSize() { return this.size; }
|
public int getSize() { return this.size; }
|
||||||
protected boolean bufferStorage;
|
protected boolean bufferStorage;
|
||||||
public final boolean isBufferStorage() { return this.bufferStorage; }
|
|
||||||
protected boolean isMapped = false;
|
protected boolean isMapped = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locking on the render thread isn't great, but is needed due to an inconsistent
|
||||||
|
* race condition where VBOs can be marked as deleted outside the render thread. <br><br>
|
||||||
|
*
|
||||||
|
* But, due to being a read-write lock the chance of freezing
|
||||||
|
* the render thread is very low
|
||||||
|
* and since this is a stamped lock, the optimistic read time is basically zero.
|
||||||
|
* (The optimistic lock time doesn't even appear in the profiler).
|
||||||
|
*/
|
||||||
|
public final StampedLock renderStampLock = new StampedLock();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============//
|
//==============//
|
||||||
@@ -112,13 +151,28 @@ public class GLBuffer implements AutoCloseable
|
|||||||
LodUtil.assertNotReach("Thread ["+Thread.currentThread()+"] tried to create a GLBuffer outside the MC render thread.");
|
LodUtil.assertNotReach("Thread ["+Thread.currentThread()+"] tried to create a GLBuffer outside the MC render thread.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroy the old buffer if one is present
|
|
||||||
if (this.id != 0)
|
// lock to prevent the render thread from accessing the buffer's ID
|
||||||
|
// while we are removing it
|
||||||
|
long writeStamp = renderStampLock.writeLock();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
destroyBufferIdNow(this.id);
|
final int oldId = this.id;
|
||||||
|
this.id = GLMC.glGenBuffers();
|
||||||
|
//LOGGER.info("created [" + newId + "].");
|
||||||
|
|
||||||
|
// destroy the old buffer
|
||||||
|
// after the new one has been created
|
||||||
|
// to hopefully prevent a rare race conditions where the old ID
|
||||||
|
// is still used somewhere
|
||||||
|
if (oldId != 0)
|
||||||
|
{
|
||||||
|
// this ID doesn't need to be tracked anymore
|
||||||
|
tryRemoveBufferIdFromPhantom(oldId);
|
||||||
|
destroyBufferIdNow(oldId, "destroyOldAndCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = GLMC.glGenBuffers();
|
|
||||||
this.bufferStorage = asBufferStorage;
|
this.bufferStorage = asBufferStorage;
|
||||||
bufferCount.getAndIncrement();
|
bufferCount.getAndIncrement();
|
||||||
|
|
||||||
@@ -126,9 +180,20 @@ public class GLBuffer implements AutoCloseable
|
|||||||
PHANTOM_TO_BUFFER_ID.put(phantom, this.id);
|
PHANTOM_TO_BUFFER_ID.put(phantom, this.id);
|
||||||
BUFFER_ID_TO_PHANTOM.put(this.id, phantom);
|
BUFFER_ID_TO_PHANTOM.put(this.id, phantom);
|
||||||
|
|
||||||
|
this.updateAllocationStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
renderStampLock.unlock(writeStamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void destroyAsync()
|
protected void destroyAsync()
|
||||||
|
{
|
||||||
|
// lock to prevent the render thread from accessing the buffer's ID
|
||||||
|
// while we are removing it
|
||||||
|
long writeStamp = renderStampLock.writeLock();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (this.id == 0)
|
if (this.id == 0)
|
||||||
{
|
{
|
||||||
@@ -137,47 +202,68 @@ public class GLBuffer implements AutoCloseable
|
|||||||
}
|
}
|
||||||
|
|
||||||
final int idToDelete = this.id; // saving the ID to a separate variable is necessary so it can be captured by the lambda
|
final int idToDelete = this.id; // saving the ID to a separate variable is necessary so it can be captured by the lambda
|
||||||
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("GLBuffer destroyAsync", () -> { destroyBufferIdNow(idToDelete); });
|
|
||||||
|
|
||||||
|
// remove the phantom tracking now so the phantom doesn't have the chance to
|
||||||
|
// get garbage collected before the render thread task runs
|
||||||
|
// (this can happen if MC is running at extremely low framerates like 1 fps via mods)
|
||||||
|
tryRemoveBufferIdFromPhantom(idToDelete);
|
||||||
|
|
||||||
|
// mark the old data is invalid before deleting to prevent a rare race condition
|
||||||
|
// where the queued on render thread task runs before the ID is cleared
|
||||||
this.id = 0;
|
this.id = 0;
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
|
|
||||||
|
//LOGGER.info("async destroy [" + idToDelete + "].");
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("GLBuffer destroyAsync", () -> { destroyBufferIdNow(idToDelete, "destroyAsync"); });
|
||||||
}
|
}
|
||||||
private static void destroyBufferIdNow(int id)
|
finally
|
||||||
|
{
|
||||||
|
renderStampLock.unlock(writeStamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void destroyBufferIdNow(int id, String cause)
|
||||||
{
|
{
|
||||||
// only delete valid buffers
|
// only delete valid buffers
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Attempted to destroy a buffer with ID 0, VRAM memory leaks may occur.");
|
LOGGER.warn("Attempted to destroy a buffer with ID 0, VRAM memory leaks may occur, cause: ["+cause+"].");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove and clear the phantom reference if present
|
bufferCount.decrementAndGet();
|
||||||
if (BUFFER_ID_TO_PHANTOM.containsKey(id))
|
GLMC.glDeleteBuffers(id);
|
||||||
{
|
|
||||||
Reference<? extends GLBuffer> phantom = BUFFER_ID_TO_PHANTOM.get(id);
|
|
||||||
|
|
||||||
|
if (Config.Client.Advanced.Debugging.logBufferGarbageCollection.get())
|
||||||
|
{
|
||||||
|
LOGGER.info("destroyed buffer [" + id + "], remaining: [" + BUFFER_ID_TO_PHANTOM.size() + "], cause: ["+cause+"].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** should be called before {@link GLBuffer#destroyBufferIdNow} */
|
||||||
|
private static void tryRemoveBufferIdFromPhantom(int id)
|
||||||
|
{
|
||||||
|
// will contain nothing if stack tracking isn't enabled
|
||||||
|
BUFFER_ID_TO_ALLOCATION_STRING.remove(id);
|
||||||
|
|
||||||
|
PhantomReference<? extends GLBuffer> phantom = BUFFER_ID_TO_PHANTOM.remove(id);
|
||||||
|
if (phantom != null)
|
||||||
|
{
|
||||||
// if we are manually closing this buffer, we don't want the phantom reference to accidentally close it again
|
// if we are manually closing this buffer, we don't want the phantom reference to accidentally close it again
|
||||||
// this can cause a race condition were we accidentally delete an in-use buffer and cause NVIDIA
|
// this can cause a race condition were we accidentally delete an in-use buffer and cause NVIDIA
|
||||||
// to throw an EXCEPTION_ACCESS_VIOLATION when we attempt to render it
|
// to throw an EXCEPTION_ACCESS_VIOLATION when we attempt to render it
|
||||||
phantom.clear();
|
phantom.clear();
|
||||||
|
|
||||||
PHANTOM_TO_BUFFER_ID.remove(phantom);
|
Integer phantomId = PHANTOM_TO_BUFFER_ID.remove(phantom);
|
||||||
BUFFER_ID_TO_PHANTOM.remove(id);
|
if (phantomId == null)
|
||||||
}
|
|
||||||
|
|
||||||
bufferCount.decrementAndGet();
|
|
||||||
|
|
||||||
// destroy the buffer if it exists,
|
|
||||||
// the buffer may not exist if the destroy method is called twice
|
|
||||||
if (GL32.glIsBuffer(id))
|
|
||||||
{
|
{
|
||||||
GLMC.glDeleteBuffers(id);
|
LOGGER.warn("No Phantom->ID binding stored for ID ["+id+"]");
|
||||||
|
|
||||||
if (Config.Client.Advanced.Debugging.logBufferGarbageCollection.get())
|
|
||||||
{
|
|
||||||
LOGGER.info("destroyed buffer [" + id + "], remaining: [" + BUFFER_ID_TO_PHANTOM.size() + "]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.warn("Unable to remove phantom GLBuffer with ID ["+id+"], buffer may have already been deleted.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -210,9 +296,12 @@ public class GLBuffer implements AutoCloseable
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// re-binding the old VBO is necessary for old MC versions (IE 1.16.5 and older)
|
// re-binding the old buffers is necessary for old MC versions for the following reasons:
|
||||||
// otherwise the screen may be black when on the home menu
|
// for 16.5 and older the screen may be black when on the home menu
|
||||||
int previousBoundVbo = GL32.glGetInteger(GL32.GL_ARRAY_BUFFER_BINDING);
|
// and for 1.19.2 - 1.21.4 the inventory/UI will render without a background
|
||||||
|
int vao = GL32.glGetInteger(GL32.GL_VERTEX_ARRAY_BINDING);
|
||||||
|
int vbo = GL32.glGetInteger(GL32.GL_ARRAY_BUFFER_BINDING);
|
||||||
|
int ebo = GL32.glGetInteger(GL32.GL_ELEMENT_ARRAY_BUFFER_BINDING);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -238,7 +327,9 @@ public class GLBuffer implements AutoCloseable
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(previousBoundVbo) ? previousBoundVbo : 0);
|
GL32.glBindVertexArray(GL32.glIsVertexArray(vao) ? vao : 0);
|
||||||
|
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(vbo) ? vbo : 0);
|
||||||
|
GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, GL32.glIsBuffer(ebo) ? ebo: 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Requires the buffer to be bound */
|
/** Requires the buffer to be bound */
|
||||||
@@ -258,8 +349,25 @@ public class GLBuffer implements AutoCloseable
|
|||||||
LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use bufferData upload method!");
|
LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use bufferData upload method!");
|
||||||
|
|
||||||
int bbSize = bb.limit() - bb.position();
|
int bbSize = bb.limit() - bb.position();
|
||||||
GL32.glBufferData(this.getBufferBindingTarget(), bb, bufferDataHint);
|
int target = this.getBufferBindingTarget();
|
||||||
|
|
||||||
|
if (shouldUploadToGpuInChunks(bbSize))
|
||||||
|
{
|
||||||
|
// Two-step path used on macOS to dodge the Apple OpenGL -> Metal
|
||||||
|
// memmove SIGBUS triggered by uploading a large ByteBuffer in one
|
||||||
|
// glBufferData call:
|
||||||
|
// 1) allocate-only with the size overload (no memcpy)
|
||||||
|
// 2) fill the buffer through chunked glBufferSubData calls
|
||||||
|
GL32.glBufferData(target, (long) bbSize, bufferDataHint);
|
||||||
|
subDataUploadInChunks(target, 0, bb, MAC_UPLOAD_CHUNK_BYTES);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL32.glBufferData(target, bb, bufferDataHint);
|
||||||
|
}
|
||||||
this.size = bbSize;
|
this.size = bbSize;
|
||||||
|
|
||||||
|
this.updateAllocationStackTrace();
|
||||||
}
|
}
|
||||||
/** Requires the buffer to be bound */
|
/** Requires the buffer to be bound */
|
||||||
protected void uploadSubData(ByteBuffer bb, int maxExpansionSize, int bufferDataHint)
|
protected void uploadSubData(ByteBuffer bb, int maxExpansionSize, int bufferDataHint)
|
||||||
@@ -267,14 +375,30 @@ public class GLBuffer implements AutoCloseable
|
|||||||
LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use subData upload method!");
|
LodUtil.assertTrue(!this.bufferStorage, "Buffer is bufferStorage but its trying to use subData upload method!");
|
||||||
|
|
||||||
int bbSize = bb.limit() - bb.position();
|
int bbSize = bb.limit() - bb.position();
|
||||||
|
int target = this.getBufferBindingTarget();
|
||||||
if (this.size < bbSize || this.size > bbSize * BUFFER_SHRINK_TRIGGER)
|
if (this.size < bbSize || this.size > bbSize * BUFFER_SHRINK_TRIGGER)
|
||||||
{
|
{
|
||||||
int newSize = (int) (bbSize * BUFFER_EXPANSION_MULTIPLIER);
|
int newSize = (int) (bbSize * BUFFER_EXPANSION_MULTIPLIER);
|
||||||
if (newSize > maxExpansionSize) newSize = maxExpansionSize;
|
if (newSize > maxExpansionSize)
|
||||||
GL32.glBufferData(this.getBufferBindingTarget(), newSize, bufferDataHint);
|
{
|
||||||
|
newSize = maxExpansionSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate-only — no memcpy, safe on macOS regardless of size
|
||||||
|
GL32.glBufferData(target, (long) newSize, bufferDataHint);
|
||||||
this.size = newSize;
|
this.size = newSize;
|
||||||
}
|
}
|
||||||
GL32.glBufferSubData(this.getBufferBindingTarget(), 0, bb);
|
|
||||||
|
if (shouldUploadToGpuInChunks(bbSize))
|
||||||
|
{
|
||||||
|
subDataUploadInChunks(target, 0, bb, MAC_UPLOAD_CHUNK_BYTES);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL32.glBufferSubData(target, 0, bb);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateAllocationStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -316,7 +440,6 @@ public class GLBuffer implements AutoCloseable
|
|||||||
{
|
{
|
||||||
// recreate if the buffer storage type changed
|
// recreate if the buffer storage type changed
|
||||||
this.bind();
|
this.bind();
|
||||||
destroyBufferIdNow(this.id);
|
|
||||||
this.destroyOldAndCreate(uploadMethod.useBufferStorage);
|
this.destroyOldAndCreate(uploadMethod.useBufferStorage);
|
||||||
this.bind();
|
this.bind();
|
||||||
}
|
}
|
||||||
@@ -333,6 +456,91 @@ public class GLBuffer implements AutoCloseable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* macOS-only mitigation for the SIGBUS in
|
||||||
|
* {@code libsystem_platform.dylib _platform_memmove} that happens when the
|
||||||
|
* Apple OpenGL -> Metal translation layer copies a single large ByteBuffer
|
||||||
|
* out of LWJGL into driver memory. Splitting the copy into
|
||||||
|
* {@link #MAC_UPLOAD_CHUNK_BYTES} slices keeps every memmove inside a size
|
||||||
|
* the bridge handles reliably.
|
||||||
|
*/
|
||||||
|
private static boolean shouldUploadToGpuInChunks(int byteCount)
|
||||||
|
{
|
||||||
|
return EPlatform.get() == EPlatform.MACOS
|
||||||
|
&& byteCount > MAC_UPLOAD_CHUNK_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads {@code bb} into the currently bound buffer at {@code baseOffset}
|
||||||
|
* using a sequence of {@link GL32#glBufferSubData(int, long, ByteBuffer)}
|
||||||
|
* calls of at most {@code chunkBytes} each. The buffer's position/limit are
|
||||||
|
* restored before returning.
|
||||||
|
*/
|
||||||
|
private static void subDataUploadInChunks(int target, int baseOffset, ByteBuffer bb, int chunkBytes)
|
||||||
|
{
|
||||||
|
final int origPos = bb.position();
|
||||||
|
final int origLimit = bb.limit();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final int total = origLimit - origPos;
|
||||||
|
int uploaded = 0;
|
||||||
|
while (uploaded < total)
|
||||||
|
{
|
||||||
|
int chunk = Math.min(chunkBytes, total - uploaded);
|
||||||
|
bb.position(origPos + uploaded);
|
||||||
|
bb.limit(origPos + uploaded + chunk);
|
||||||
|
GL32.glBufferSubData(target, (long) (baseOffset + uploaded), bb);
|
||||||
|
uploaded += chunk;
|
||||||
|
// Force the driver to drain its command queue between chunks
|
||||||
|
// so the OpenGL -> Metal bridge processes (and frees) each
|
||||||
|
// staging copy before the next sub-data call piles another
|
||||||
|
// memmove on top of it.
|
||||||
|
if (uploaded < total)
|
||||||
|
{
|
||||||
|
GL32.glFlush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
bb.limit(origLimit);
|
||||||
|
bb.position(origPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used to help track down leaks where the buffer isn't properly closed
|
||||||
|
* Note: this probably needs extending to accept a stack trace from outside where it's being called
|
||||||
|
* since it's often called on the render thread in an un-helpful location.
|
||||||
|
*/
|
||||||
|
public void updateAllocationStackTrace()
|
||||||
|
{
|
||||||
|
if (LOG_PHANTOM_ALLOCATION_STACKS)
|
||||||
|
{
|
||||||
|
String stack;
|
||||||
|
|
||||||
|
RenderThreadTaskHandler.QueuedRunnable parentQueuedRunnable;
|
||||||
|
// if this is running on the render thread, try getting the render task's stack trace instead
|
||||||
|
// since it's a lot more helpful than wherever the render thread tasks themselves are being run from
|
||||||
|
if (RenderThreadTaskHandler.INSTANCE.isCurrentThread()
|
||||||
|
&& (parentQueuedRunnable = RenderThreadTaskHandler.INSTANCE.getCurrentlyRunningTask()) != null
|
||||||
|
&& parentQueuedRunnable.stackTrace != null)
|
||||||
|
{
|
||||||
|
// trim off the getStacktrace() and queueRunningOnRenderThread() methods
|
||||||
|
StackTraceElement[] trimmedElements = Arrays.copyOfRange(parentQueuedRunnable.stackTrace, 2, parentQueuedRunnable.stackTrace.length);
|
||||||
|
stack = StringUtil.join("\n", trimmedElements).intern();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// not running on the render thread, use the normal stack trace
|
||||||
|
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
|
||||||
|
stack = StringUtil.join("\n", stackTraceElements).intern();
|
||||||
|
}
|
||||||
|
|
||||||
|
BUFFER_ID_TO_ALLOCATION_STRING.put(this.id, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -344,8 +552,13 @@ public class GLBuffer implements AutoCloseable
|
|||||||
|
|
||||||
private static void runPhantomReferenceCleanupLoop()
|
private static void runPhantomReferenceCleanupLoop()
|
||||||
{
|
{
|
||||||
|
// these arrays are stored here so they don't have to be re-allocated each loop
|
||||||
|
ArrayList<Pair<String, AtomicInteger>> allocationStackTraceCountPairList = new ArrayList<>();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
allocationStackTraceCountPairList.clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -354,20 +567,53 @@ public class GLBuffer implements AutoCloseable
|
|||||||
}
|
}
|
||||||
catch (InterruptedException ignore) { }
|
catch (InterruptedException ignore) { }
|
||||||
|
|
||||||
|
int collectedCount = 0;
|
||||||
|
|
||||||
Reference<? extends GLBuffer> phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
|
Reference<? extends GLBuffer> phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
|
||||||
while (phantomRef != null)
|
while (phantomRef != null)
|
||||||
{
|
{
|
||||||
// destroy the buffer if it hasn't been cleared yet
|
// destroy the buffer if it hasn't been cleared yet
|
||||||
if (PHANTOM_TO_BUFFER_ID.containsKey(phantomRef))
|
Integer idRef = PHANTOM_TO_BUFFER_ID.remove((PhantomReference<? extends GLBuffer>)phantomRef); // cast to make IntelliJ happy
|
||||||
|
if (idRef != null)
|
||||||
{
|
{
|
||||||
int id = PHANTOM_TO_BUFFER_ID.get(phantomRef);
|
BUFFER_ID_TO_PHANTOM.remove(idRef);
|
||||||
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("GLBuffer phantom destroy", () -> { destroyBufferIdNow(id); });
|
final int id = idRef;
|
||||||
//LOGGER.warn("Buffer Phantom collected, ID: ["+id+"]");
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("GLBuffer phantom destroy", () -> { destroyBufferIdNow(id, "runPhantomReferenceCleanupLoop"); });
|
||||||
|
//LOGGER.info("Buffer Phantom collected, ID: ["+id+"]");
|
||||||
|
|
||||||
|
if (LOG_PHANTOM_ALLOCATION_STACKS) // stack trace shouldn't be null, but just in case
|
||||||
|
{
|
||||||
|
String stack = BUFFER_ID_TO_ALLOCATION_STRING.get(idRef);
|
||||||
|
PhantomLoggingHelper.putAndIncrementTrackingString(stack, allocationStackTraceCountPairList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.warn("Failed to find Buffer ID for phantom reference: ["+phantomRef+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
collectedCount++;
|
||||||
phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
|
phantomRef = PHANTOM_REFERENCE_QUEUE.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (LOG_PHANTOM_RECOVERY)
|
||||||
|
{
|
||||||
|
// we only want to log when something has been returned
|
||||||
|
if (collectedCount != 0)
|
||||||
|
{
|
||||||
|
LOGGER.warn("GLBuffer phantom recovered: ["+ F3Screen.NUMBER_FORMAT.format(collectedCount)+"].");
|
||||||
|
|
||||||
|
// log stack traces if present
|
||||||
|
if (LOG_PHANTOM_ALLOCATION_STACKS)
|
||||||
|
{
|
||||||
|
PhantomLoggingHelper.LogAllocationStackTracePairCounts(LOGGER, allocationStackTraceCountPairList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-4
@@ -37,10 +37,11 @@ public class GLIndexBuffer extends GLBuffer
|
|||||||
protected int glType = GL32.GL_UNSIGNED_INT;
|
protected int glType = GL32.GL_UNSIGNED_INT;
|
||||||
public int getGlType() { return this.glType; }
|
public int getGlType() { return this.glType; }
|
||||||
|
|
||||||
public GLIndexBuffer(boolean isBufferStorage)
|
|
||||||
{
|
|
||||||
super(isBufferStorage);
|
public GLIndexBuffer(boolean isBufferStorage) { super(isBufferStorage); }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyAsync()
|
public void destroyAsync()
|
||||||
|
|||||||
+7
-3
@@ -22,15 +22,16 @@ package com.seibel.distanthorizons.common.render.openGl.glObject.buffer;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.IndexBufferBuilder;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.jar.EPlatform;
|
|
||||||
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IVertexBufferWrapper;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a container for a OpenGL
|
* This is a container for a OpenGL
|
||||||
@@ -83,7 +84,10 @@ public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
|||||||
int maxSize = LodQuadBuilder.getMaxBufferByteSize();
|
int maxSize = LodQuadBuilder.getMaxBufferByteSize();
|
||||||
int maxVertexCount = maxSize / LodQuadBuilder.BYTES_PER_VERTEX;
|
int maxVertexCount = maxSize / LodQuadBuilder.BYTES_PER_VERTEX;
|
||||||
int maxQuadCount = (maxVertexCount / 4);
|
int maxQuadCount = (maxVertexCount / 4);
|
||||||
GLOBAL_QUAD_IBO.upload(maxQuadCount);
|
|
||||||
|
ByteBuffer buffer = IndexBufferBuilder.createBuffer(maxQuadCount);
|
||||||
|
GLOBAL_QUAD_IBO.upload(buffer, maxQuadCount);
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,7 +162,7 @@ public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
|||||||
this.quadIBO = new GlQuadIndexBuffer();
|
this.quadIBO = new GlQuadIndexBuffer();
|
||||||
|
|
||||||
int quadCount = (vertexCount / 4);
|
int quadCount = (vertexCount / 4);
|
||||||
this.quadIBO.upload(quadCount);
|
this.quadIBO.upload(buffer, quadCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+1
-5
@@ -43,7 +43,7 @@ public class GlQuadIndexBuffer extends GLIndexBuffer
|
|||||||
|
|
||||||
public GlQuadIndexBuffer() { super(false); }
|
public GlQuadIndexBuffer() { super(false); }
|
||||||
|
|
||||||
public void upload(int quadCount)
|
public void upload(ByteBuffer buffer, int quadCount)
|
||||||
{
|
{
|
||||||
if (quadCount < 0)
|
if (quadCount < 0)
|
||||||
{
|
{
|
||||||
@@ -63,12 +63,8 @@ public class GlQuadIndexBuffer extends GLIndexBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.glType = GL32.GL_UNSIGNED_INT;
|
this.glType = GL32.GL_UNSIGNED_INT;
|
||||||
ByteBuffer buffer = IndexBufferBuilder.createBuffer(quadCount);
|
|
||||||
this.bind();
|
|
||||||
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.DATA,
|
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.DATA,
|
||||||
this.indicesCount * GLEnums.getTypeSize(this.glType), GL32.GL_STATIC_DRAW);
|
this.indicesCount * GLEnums.getTypeSize(this.glType), GL32.GL_STATIC_DRAW);
|
||||||
|
|
||||||
MemoryUtil.memFree(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+30
-5
@@ -22,6 +22,7 @@ package com.seibel.distanthorizons.common.render.openGl.glObject.shader;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3i;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3i;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
@@ -187,20 +188,44 @@ public class GlShaderProgram
|
|||||||
|
|
||||||
/** Requires a bound ShaderProgram. */
|
/** Requires a bound ShaderProgram. */
|
||||||
public void setUniform(int location, DhApiVec3i value) { GL32.glUniform3i(location, value.x, value.y, value.z); }
|
public void setUniform(int location, DhApiVec3i value) { GL32.glUniform3i(location, value.x, value.y, value.z); }
|
||||||
/** @see GlShaderProgram#setUniform(int, Mat4f) */
|
/** @see GlShaderProgram#setUniform(int, DhApiMat4f) */
|
||||||
public void trySetUniform(int location, DhApiVec3i value) { if (location != -1) { this.setUniform(location, value); } }
|
public void trySetUniform(int location, DhApiVec3i value) { if (location != -1) { this.setUniform(location, value); } }
|
||||||
|
|
||||||
/** Requires a bound ShaderProgram. */
|
/** Requires a bound ShaderProgram. */
|
||||||
public void setUniform(int location, Mat4f value)
|
public void setUniform(int location, DhApiMat4f value)
|
||||||
{
|
{
|
||||||
try (MemoryStack stack = MemoryStack.stackPush())
|
try (MemoryStack stack = MemoryStack.stackPush())
|
||||||
{
|
{
|
||||||
FloatBuffer buffer = stack.mallocFloat(4 * 4);
|
FloatBuffer buffer = stack.mallocFloat(16);
|
||||||
value.store(buffer);
|
storeMatrixInBuffer(value, buffer);
|
||||||
GL32.glUniformMatrix4fv(location, false, buffer);
|
GL32.glUniformMatrix4fv(location, false, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** @see GlShaderProgram#setUniform(int, Mat4f) */
|
private static void storeMatrixInBuffer(DhApiMat4f matrix, FloatBuffer floatBuffer)
|
||||||
|
{
|
||||||
|
floatBuffer.put(bufferIndex(0, 0), matrix.m00);
|
||||||
|
floatBuffer.put(bufferIndex(0, 1), matrix.m01);
|
||||||
|
floatBuffer.put(bufferIndex(0, 2), matrix.m02);
|
||||||
|
floatBuffer.put(bufferIndex(0, 3), matrix.m03);
|
||||||
|
|
||||||
|
floatBuffer.put(bufferIndex(1, 0), matrix.m10);
|
||||||
|
floatBuffer.put(bufferIndex(1, 1), matrix.m11);
|
||||||
|
floatBuffer.put(bufferIndex(1, 2), matrix.m12);
|
||||||
|
floatBuffer.put(bufferIndex(1, 3), matrix.m13);
|
||||||
|
|
||||||
|
floatBuffer.put(bufferIndex(2, 0), matrix.m20);
|
||||||
|
floatBuffer.put(bufferIndex(2, 1), matrix.m21);
|
||||||
|
floatBuffer.put(bufferIndex(2, 2), matrix.m22);
|
||||||
|
floatBuffer.put(bufferIndex(2, 3), matrix.m23);
|
||||||
|
|
||||||
|
floatBuffer.put(bufferIndex(3, 0), matrix.m30);
|
||||||
|
floatBuffer.put(bufferIndex(3, 1), matrix.m31);
|
||||||
|
floatBuffer.put(bufferIndex(3, 2), matrix.m32);
|
||||||
|
floatBuffer.put(bufferIndex(3, 3), matrix.m33);
|
||||||
|
}
|
||||||
|
private static int bufferIndex(int xIndex, int zIndex) { return (zIndex * 4) + xIndex; }
|
||||||
|
|
||||||
|
/** @see GlShaderProgram#setUniform(int, DhApiMat4f) */
|
||||||
public void trySetUniform(int location, Mat4f value) { if (location != -1) { this.setUniform(location, value); } }
|
public void trySetUniform(int location, Mat4f value) { if (location != -1) { this.setUniform(location, value); } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@ public class GlDhApplyShader extends GlAbstractShaderRenderer
|
|||||||
}
|
}
|
||||||
private void renderToMcTexture()
|
private void renderToMcTexture()
|
||||||
{
|
{
|
||||||
int targetColorTextureId = MC_RENDER.getColorTextureId();
|
int targetColorTextureId = MC_RENDER.getGlColorTextureId();
|
||||||
if (targetColorTextureId == -1)
|
if (targetColorTextureId == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-9
@@ -122,8 +122,6 @@ public class GlDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//profiler.push("Fade Generate");
|
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
// resize the framebuffer if necessary
|
// resize the framebuffer if necessary
|
||||||
@@ -138,11 +136,9 @@ public class GlDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
|
|
||||||
GlDhFarFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
|
GlDhFarFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
|
||||||
GlDhFarFadeShader.INSTANCE.setProjectionMatrix(renderParams.mcModelViewMatrix, renderParams.mcProjectionMatrix);
|
GlDhFarFadeShader.INSTANCE.setProjectionMatrix(renderParams);
|
||||||
GlDhFarFadeShader.INSTANCE.render(renderParams);
|
GlDhFarFadeShader.INSTANCE.render(renderParams);
|
||||||
|
|
||||||
//profiler.popPush("Fade Apply");
|
|
||||||
|
|
||||||
GlDhFarFadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
GlDhFarFadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
||||||
GlDhFarFadeApplyShader.INSTANCE.readFramebuffer = GlDhFarFadeShader.INSTANCE.frameBuffer;
|
GlDhFarFadeApplyShader.INSTANCE.readFramebuffer = GlDhFarFadeShader.INSTANCE.frameBuffer;
|
||||||
GlDhFarFadeApplyShader.INSTANCE.drawFramebuffer = GlDhMetaRenderer.INSTANCE.getActiveFramebufferId();
|
GlDhFarFadeApplyShader.INSTANCE.drawFramebuffer = GlDhMetaRenderer.INSTANCE.getActiveFramebufferId();
|
||||||
@@ -152,10 +148,6 @@ public class GlDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
{
|
{
|
||||||
LOGGER.error("Unexpected error during fade render, error: ["+e.getMessage()+"].", e);
|
LOGGER.error("Unexpected error during fade render, error: ["+e.getMessage()+"].", e);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
//profiler.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//emdregion
|
//emdregion
|
||||||
|
|||||||
+4
-10
@@ -42,7 +42,7 @@ public class GlDhFarFadeShader extends GlAbstractShaderRenderer
|
|||||||
|
|
||||||
public int frameBuffer = -1;
|
public int frameBuffer = -1;
|
||||||
|
|
||||||
private Mat4f inverseDhMvmProjMatrix;
|
private DhApiMat4f inverseDhMvmProjMatrix;
|
||||||
|
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
@@ -110,15 +110,9 @@ public class GlDhFarFadeShader extends GlAbstractShaderRenderer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjectionMatrix(DhApiMat4f mcModelViewMatrix, DhApiMat4f mcProjectionMatrix)
|
public void setProjectionMatrix(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(mcProjectionMatrix);
|
this.inverseDhMvmProjMatrix = renderParams.dhInverseMvmProjectionMatrix;
|
||||||
Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(mcModelViewMatrix);
|
|
||||||
|
|
||||||
Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(dhProjectionMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.multiply(dhModelViewMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.invert();
|
|
||||||
this.inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +147,7 @@ public class GlDhFarFadeShader extends GlAbstractShaderRenderer
|
|||||||
GL32.glUniform1i(this.uDhDepthTexture, 0);
|
GL32.glUniform1i(this.uDhDepthTexture, 0);
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||||
GLMC.glBindTexture(MC_RENDER.getColorTextureId());
|
GLMC.glBindTexture(MC_RENDER.getGlColorTextureId());
|
||||||
GL32.glUniform1i(this.uMcColorTexture, 1);
|
GL32.glUniform1i(this.uMcColorTexture, 1);
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
|
||||||
|
|||||||
+7
-18
@@ -43,8 +43,8 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
|
|||||||
|
|
||||||
public int frameBuffer = -1;
|
public int frameBuffer = -1;
|
||||||
|
|
||||||
private Mat4f inverseMcMvmProjMatrix;
|
private DhApiMat4f inverseMcMvmProjMatrix;
|
||||||
private Mat4f inverseDhMvmProjMatrix;
|
private DhApiMat4f inverseDhMvmProjMatrix;
|
||||||
private float levelMaxHeight;
|
private float levelMaxHeight;
|
||||||
|
|
||||||
|
|
||||||
@@ -136,21 +136,10 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
|
|||||||
this.shader.setUniform(this.uOnlyRenderLods, Config.Client.Advanced.Debugging.lodOnlyMode.get());
|
this.shader.setUniform(this.uOnlyRenderLods, Config.Client.Advanced.Debugging.lodOnlyMode.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjectionMatrix(DhApiMat4f mcModelViewMatrix, DhApiMat4f mcProjectionMatrix)
|
public void setProjectionMatrix(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
Mat4f inverseMcModelViewProjectionMatrix = new Mat4f(mcProjectionMatrix);
|
this.inverseMcMvmProjMatrix = renderParams.mcInverseMvmProjectionMatrix;
|
||||||
inverseMcModelViewProjectionMatrix.multiply(mcModelViewMatrix);
|
this.inverseDhMvmProjMatrix = renderParams.dhInverseMvmProjectionMatrix;
|
||||||
inverseMcModelViewProjectionMatrix.invert();
|
|
||||||
this.inverseMcMvmProjMatrix = inverseMcModelViewProjectionMatrix;
|
|
||||||
|
|
||||||
|
|
||||||
Mat4f dhProjectionMatrix = RenderUtil.createLodProjectionMatrix(mcProjectionMatrix);
|
|
||||||
Mat4f dhModelViewMatrix = RenderUtil.createLodModelViewMatrix(mcModelViewMatrix);
|
|
||||||
|
|
||||||
Mat4f inverseDhModelViewProjectionMatrix = new Mat4f(dhProjectionMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.multiply(dhModelViewMatrix);
|
|
||||||
inverseDhModelViewProjectionMatrix.invert();
|
|
||||||
this.inverseDhMvmProjMatrix = inverseDhModelViewProjectionMatrix;
|
|
||||||
}
|
}
|
||||||
public void setLevelMaxHeight(int levelMaxHeight) { this.levelMaxHeight = levelMaxHeight; }
|
public void setLevelMaxHeight(int levelMaxHeight) { this.levelMaxHeight = levelMaxHeight; }
|
||||||
|
|
||||||
@@ -185,7 +174,7 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
|
|||||||
GLMC.disableBlend();
|
GLMC.disableBlend();
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
|
||||||
GLMC.glBindTexture(MC_RENDER.getDepthTextureId());
|
GLMC.glBindTexture(MC_RENDER.getGlDepthTextureId());
|
||||||
GL32.glUniform1i(this.uMcDepthTexture, 0);
|
GL32.glUniform1i(this.uMcDepthTexture, 0);
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
|
||||||
@@ -193,7 +182,7 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
|
|||||||
GL32.glUniform1i(this.uDhDepthTexture, 1);
|
GL32.glUniform1i(this.uDhDepthTexture, 1);
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
|
||||||
GLMC.glBindTexture(MC_RENDER.getColorTextureId());
|
GLMC.glBindTexture(MC_RENDER.getGlColorTextureId());
|
||||||
GL32.glUniform1i(this.uCombinedMcDhColorTexture, 2);
|
GL32.glUniform1i(this.uCombinedMcDhColorTexture, 2);
|
||||||
|
|
||||||
GLMC.glActiveTexture(GL32.GL_TEXTURE3);
|
GLMC.glActiveTexture(GL32.GL_TEXTURE3);
|
||||||
|
|||||||
+5
-14
@@ -108,7 +108,7 @@ public class GlVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getColorTextureId(), 0);
|
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getGlColorTextureId(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,14 +135,9 @@ public class GlVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
|
|
||||||
IProfilerWrapper profiler = MC_CLIENT.getProfiler();
|
IProfilerWrapper profiler = MC_CLIENT.getProfiler();
|
||||||
profiler.pop(); // get out of "terrain"
|
try (IProfilerWrapper.IProfileBlock fade_profile = profiler.push("DH-Vanilla Fade");
|
||||||
profiler.push("DH-Vanilla Fade");
|
GLState mcState = new GLState())
|
||||||
|
|
||||||
|
|
||||||
try(GLState mcState = new GLState())
|
|
||||||
{
|
{
|
||||||
profiler.push("Vanilla Fade Generate");
|
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
// resize the framebuffer if necessary
|
// resize the framebuffer if necessary
|
||||||
@@ -157,7 +152,7 @@ public class GlVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
|
|
||||||
GlDhVanillaFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
|
GlDhVanillaFadeShader.INSTANCE.frameBuffer = this.fadeFramebuffer;
|
||||||
GlDhVanillaFadeShader.INSTANCE.setProjectionMatrix(renderParams.mcModelViewMatrix, renderParams.mcProjectionMatrix);
|
GlDhVanillaFadeShader.INSTANCE.setProjectionMatrix(renderParams);
|
||||||
GlDhVanillaFadeShader.INSTANCE.setLevelMaxHeight(renderParams.clientLevelWrapper.getMaxHeight());
|
GlDhVanillaFadeShader.INSTANCE.setLevelMaxHeight(renderParams.clientLevelWrapper.getMaxHeight());
|
||||||
GlDhVanillaFadeShader.INSTANCE.render(renderParams);
|
GlDhVanillaFadeShader.INSTANCE.render(renderParams);
|
||||||
|
|
||||||
@@ -165,19 +160,15 @@ public class GlVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
// otherwise we can directly render to their texture
|
// otherwise we can directly render to their texture
|
||||||
if (MC_RENDER.mcRendersToFrameBuffer())
|
if (MC_RENDER.mcRendersToFrameBuffer())
|
||||||
{
|
{
|
||||||
profiler.popPush("Vanilla Fade Apply");
|
|
||||||
|
|
||||||
GlDhFarFadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
GlDhFarFadeApplyShader.INSTANCE.fadeTexture = this.fadeTexture;
|
||||||
GlDhFarFadeApplyShader.INSTANCE.readFramebuffer = GlDhVanillaFadeShader.INSTANCE.frameBuffer;
|
GlDhFarFadeApplyShader.INSTANCE.readFramebuffer = GlDhVanillaFadeShader.INSTANCE.frameBuffer;
|
||||||
GlDhFarFadeApplyShader.INSTANCE.drawFramebuffer = MC_RENDER.getTargetFramebuffer();
|
GlDhFarFadeApplyShader.INSTANCE.drawFramebuffer = MC_RENDER.getTargetFramebuffer();
|
||||||
GlDhFarFadeApplyShader.INSTANCE.render(renderParams);
|
GlDhFarFadeApplyShader.INSTANCE.render(renderParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.error("Unexpected error during fade render, error: ["+e.getMessage()+"].", e);
|
LOGGER.error("Unexpected error during fade render, error: [" + e.getMessage() + "].", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog;
|
package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.GLState;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GLState;
|
||||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftGLWrapper;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
@@ -108,7 +109,7 @@ public class GlDhFogRenderer implements IDhFogRenderer
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderParams renderParams)
|
public void render(RenderParams renderParams, DhApiFogRenderParam fogRenderParams)
|
||||||
{
|
{
|
||||||
// GLState needed in MC 1.16.5 probably due to MC not manually setting each GL state they need before the next rendering step
|
// GLState needed in MC 1.16.5 probably due to MC not manually setting each GL state they need before the next rendering step
|
||||||
try (GLState state = new GLState())
|
try (GLState state = new GLState())
|
||||||
@@ -126,7 +127,7 @@ public class GlDhFogRenderer implements IDhFogRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
GlDhFogShader.INSTANCE.frameBuffer = this.fogFramebuffer;
|
GlDhFogShader.INSTANCE.frameBuffer = this.fogFramebuffer;
|
||||||
GlDhFogShader.INSTANCE.setProjectionMatrix(renderParams.dhMvmProjMatrix);
|
GlDhFogShader.INSTANCE.prepUniformObjects(renderParams.dhMvmProjMatrix, fogRenderParams);
|
||||||
GlDhFogShader.INSTANCE.render(renderParams);
|
GlDhFogShader.INSTANCE.render(renderParams);
|
||||||
|
|
||||||
GlDhFogApplyShader.INSTANCE.fogTexture = this.fogTexture;
|
GlDhFogApplyShader.INSTANCE.fogTexture = this.fogTexture;
|
||||||
|
|||||||
+28
-66
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog;
|
package com.seibel.distanthorizons.common.render.openGl.postProcessing.fog;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogColorMode;
|
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection;
|
||||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiFogRenderParam;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.GlDhMetaRenderer;
|
import com.seibel.distanthorizons.common.render.openGl.GlDhMetaRenderer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
||||||
@@ -37,8 +37,6 @@ import com.seibel.distanthorizons.core.util.math.Mat4f;
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class GlDhFogShader extends GlAbstractShaderRenderer
|
public class GlDhFogShader extends GlAbstractShaderRenderer
|
||||||
{
|
{
|
||||||
public static final GlDhFogShader INSTANCE = new GlDhFogShader();
|
public static final GlDhFogShader INSTANCE = new GlDhFogShader();
|
||||||
@@ -51,6 +49,7 @@ public class GlDhFogShader extends GlAbstractShaderRenderer
|
|||||||
|
|
||||||
public int frameBuffer;
|
public int frameBuffer;
|
||||||
private Mat4f inverseMvmProjMatrix;
|
private Mat4f inverseMvmProjMatrix;
|
||||||
|
private DhApiFogRenderParam fogRenderParams;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -167,95 +166,58 @@ public class GlDhFogShader extends GlAbstractShaderRenderer
|
|||||||
{
|
{
|
||||||
int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH;
|
int lodDrawDistance = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get() * LodUtil.CHUNK_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.inverseMvmProjMatrix != null)
|
|
||||||
{
|
|
||||||
this.shader.setUniform(this.uInvMvmProj, this.inverseMvmProjMatrix);
|
this.shader.setUniform(this.uInvMvmProj, this.inverseMvmProjMatrix);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Fog uniforms
|
// Fog uniforms
|
||||||
this.shader.setUniform(this.uFogColor, this.getFogColor(renderParams.partialTicks));
|
this.shader.setUniform(this.uFogColor, this.fogRenderParams.getFogColor());
|
||||||
this.shader.setUniform(this.uFogScale, 1.f / lodDrawDistance);
|
this.shader.setUniform(this.uFogScale, 1.f / lodDrawDistance);
|
||||||
this.shader.setUniform(this.uFogVerticalScale, 1.f / MC.getWrappedClientLevel().getMaxHeight());
|
this.shader.setUniform(this.uFogVerticalScale, 1.f / MC.getWrappedClientLevel().getMaxHeight());
|
||||||
// only used for debugging
|
this.shader.setUniform(this.uFogDebugMode, 0); // 0 = normal // 1 = render everything with fog color // 7 = use debug rendering
|
||||||
this.shader.setUniform(this.uFogDebugMode, 0); // 1 = render everything with fog color // 7 = use debug rendering
|
this.shader.setUniform(this.uFogFalloffType, this.fogRenderParams.getFarFogFalloff().value);
|
||||||
this.shader.setUniform(this.uFogFalloffType, Config.Client.Advanced.Graphics.Fog.farFogFalloff.get().value);
|
|
||||||
|
|
||||||
|
|
||||||
// fog config
|
// fog config
|
||||||
float farFogStart = Config.Client.Advanced.Graphics.Fog.farFogStart.get();
|
this.shader.setUniform(this.uFarFogStart, this.fogRenderParams.getFarFogStartPercent());
|
||||||
float farFogEnd = Config.Client.Advanced.Graphics.Fog.farFogEnd.get();
|
this.shader.setUniform(this.uFarFogLength, this.fogRenderParams.getFarFogEndPercent() - this.fogRenderParams.getFarFogStartPercent());
|
||||||
float farFogMin = Config.Client.Advanced.Graphics.Fog.farFogMin.get();
|
this.shader.setUniform(this.uFarFogMin, this.fogRenderParams.getFarFogMinThickness());
|
||||||
float farFogMax = Config.Client.Advanced.Graphics.Fog.farFogMax.get();
|
this.shader.setUniform(this.uFarFogRange, this.fogRenderParams.getFarFogMaxThickness() - this.fogRenderParams.getFarFogMinThickness());
|
||||||
float farFogDensity = Config.Client.Advanced.Graphics.Fog.farFogDensity.get();
|
this.shader.setUniform(this.uFarFogDensity, this.fogRenderParams.getFarFogDensity());
|
||||||
|
|
||||||
// override fog if underwater
|
|
||||||
if (MC_RENDER.isFogStateSpecial())
|
|
||||||
{
|
|
||||||
// hide everything behind fog
|
|
||||||
farFogStart = 0.0f;
|
|
||||||
farFogEnd = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.shader.setUniform(this.uFarFogStart, farFogStart);
|
|
||||||
this.shader.setUniform(this.uFarFogLength, farFogEnd - farFogStart);
|
|
||||||
this.shader.setUniform(this.uFarFogMin, farFogMin);
|
|
||||||
this.shader.setUniform(this.uFarFogRange, farFogMax - farFogMin);
|
|
||||||
this.shader.setUniform(this.uFarFogDensity, farFogDensity);
|
|
||||||
|
|
||||||
|
|
||||||
// height config
|
// height config
|
||||||
EDhApiHeightFogMixMode heightFogMixingMode = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMixMode.get();
|
EDhApiHeightFogMixMode heightFogMixingMode = this.fogRenderParams.getHeightFogMixingMode();
|
||||||
boolean heightFogEnabled = heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL && heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL;
|
boolean heightFogEnabled =
|
||||||
|
heightFogMixingMode != EDhApiHeightFogMixMode.SPHERICAL
|
||||||
|
&& heightFogMixingMode != EDhApiHeightFogMixMode.CYLINDRICAL;
|
||||||
boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL;
|
boolean useSphericalFog = heightFogMixingMode == EDhApiHeightFogMixMode.SPHERICAL;
|
||||||
EDhApiHeightFogDirection heightFogCameraDirection = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDirection.get();
|
EDhApiHeightFogDirection heightFogDirection = this.fogRenderParams.getHeightFogDirection();
|
||||||
|
|
||||||
float heightFogStart = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogStart.get();
|
this.shader.setUniform(this.uHeightFogStart, this.fogRenderParams.getHeightFogStartPercent());
|
||||||
float heightFogEnd = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogEnd.get();
|
this.shader.setUniform(this.uHeightFogLength, this.fogRenderParams.getHeightFogEndPercent() - this.fogRenderParams.getHeightFogStartPercent());
|
||||||
float heightFogMin = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMin.get();
|
this.shader.setUniform(this.uHeightFogMin, this.fogRenderParams.getFarFogMinThickness());
|
||||||
float heightFogMax = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogMax.get();
|
this.shader.setUniform(this.uHeightFogRange, this.fogRenderParams.getFarFogMaxThickness() - this.fogRenderParams.getFarFogMinThickness());
|
||||||
float heightFogDensity = Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogDensity.get();
|
this.shader.setUniform(this.uHeightFogDensity, this.fogRenderParams.getFarFogDensity());
|
||||||
|
|
||||||
this.shader.setUniform(this.uHeightFogStart, heightFogStart);
|
|
||||||
this.shader.setUniform(this.uHeightFogLength, heightFogEnd - heightFogStart);
|
|
||||||
this.shader.setUniform(this.uHeightFogMin, heightFogMin);
|
|
||||||
this.shader.setUniform(this.uHeightFogRange, heightFogMax - heightFogMin);
|
|
||||||
this.shader.setUniform(this.uHeightFogDensity, heightFogDensity);
|
|
||||||
|
|
||||||
|
|
||||||
this.shader.setUniform(this.uHeightFogEnabled, heightFogEnabled);
|
this.shader.setUniform(this.uHeightFogEnabled, heightFogEnabled);
|
||||||
this.shader.setUniform(this.uHeightFogFalloffType, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogFalloff.get().value);
|
this.shader.setUniform(this.uHeightFogFalloffType, this.fogRenderParams.getHeightFogFalloff().value);
|
||||||
this.shader.setUniform(this.uHeightFogBaseHeight, Config.Client.Advanced.Graphics.Fog.HeightFog.heightFogBaseHeight.get());
|
this.shader.setUniform(this.uHeightFogBaseHeight, this.fogRenderParams.getHeightFogBaseHeight());
|
||||||
this.shader.setUniform(this.uHeightBasedOnCamera, heightFogCameraDirection.basedOnCamera);
|
this.shader.setUniform(this.uHeightBasedOnCamera, heightFogDirection.basedOnCamera);
|
||||||
this.shader.setUniform(this.uHeightFogAppliesUp, heightFogCameraDirection.fogAppliesUp);
|
this.shader.setUniform(this.uHeightFogAppliesUp, heightFogDirection.fogAppliesUp);
|
||||||
this.shader.setUniform(this.uHeightFogAppliesDown, heightFogCameraDirection.fogAppliesDown);
|
this.shader.setUniform(this.uHeightFogAppliesDown, heightFogDirection.fogAppliesDown);
|
||||||
this.shader.setUniform(this.uUseSphericalFog, useSphericalFog);
|
this.shader.setUniform(this.uUseSphericalFog, useSphericalFog);
|
||||||
this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value);
|
this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value);
|
||||||
this.shader.setUniform(this.uCameraBlockYPos, (float)MC_RENDER.getCameraExactPosition().y);
|
this.shader.setUniform(this.uCameraBlockYPos, (float)MC_RENDER.getCameraExactPosition().y);
|
||||||
|
|
||||||
}
|
}
|
||||||
private Color getFogColor(float partialTicks)
|
|
||||||
{
|
|
||||||
Color fogColor;
|
|
||||||
|
|
||||||
if (Config.Client.Advanced.Graphics.Fog.colorMode.get() == EDhApiFogColorMode.USE_SKY_COLOR)
|
public void prepUniformObjects(DhApiMat4f modelViewProjectionMatrix, DhApiFogRenderParam fogRenderParams)
|
||||||
{
|
|
||||||
fogColor = MC_RENDER.getSkyColor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fogColor = MC_RENDER.getFogColor(partialTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fogColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProjectionMatrix(DhApiMat4f modelViewProjectionMatrix)
|
|
||||||
{
|
{
|
||||||
this.inverseMvmProjMatrix = new Mat4f(modelViewProjectionMatrix);
|
this.inverseMvmProjMatrix = new Mat4f(modelViewProjectionMatrix);
|
||||||
this.inverseMvmProjMatrix.invert();
|
this.inverseMvmProjMatrix.invert();
|
||||||
|
|
||||||
|
this.fogRenderParams = fogRenderParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+39
-6
@@ -46,6 +46,11 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
private static final MinecraftGLWrapper GLMC = MinecraftGLWrapper.INSTANCE;
|
||||||
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||||
|
|
||||||
|
private static final Vec3f MODEL_POS = new Vec3f();
|
||||||
|
/** single event object used to reduce GC pressure */
|
||||||
|
private static final DhApiBeforeBufferRenderEvent.EventParam BEFORE_BUFFER_RENDER_EVENT_PARAM = new DhApiBeforeBufferRenderEvent.EventParam();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
@@ -289,6 +294,9 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
GLMC.disableBlend();
|
GLMC.disableBlend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// needs to be triggered after DH attempts to set the GL state so that Iris
|
||||||
|
// can override it as needed
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam.apiCopy);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -296,8 +304,6 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
// rendering //
|
// rendering //
|
||||||
//===========//
|
//===========//
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
|
||||||
|
|
||||||
if (IRIS_ACCESSOR != null)
|
if (IRIS_ACCESSOR != null)
|
||||||
{
|
{
|
||||||
// done to fix a bug with Iris where face culling isn't properly set or reverted in the MC state manager
|
// done to fix a bug with Iris where face culling isn't properly set or reverted in the MC state manager
|
||||||
@@ -313,19 +319,26 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
for (int lodIndex = 0; lodIndex < bufferContainers.size(); lodIndex++)
|
||||||
{
|
{
|
||||||
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
LodBufferContainer bufferContainer = bufferContainers.get(lodIndex);
|
||||||
|
if (!bufferContainer.buffersUploaded)
|
||||||
|
{
|
||||||
|
// make sure we don't accidentally try
|
||||||
|
// rendering a buffer that is (or is going to be) freed
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// set uniforms and fire events
|
// set uniforms and fire events
|
||||||
{
|
{
|
||||||
Vec3d camPos = renderEventParam.exactCameraPosition;
|
Vec3d camPos = renderEventParam.exactCameraPosition;
|
||||||
Vec3f modelPos = new Vec3f(
|
MODEL_POS.set(
|
||||||
(float) (bufferContainer.minCornerBlockPos.getX() - camPos.x),
|
(float) (bufferContainer.minCornerBlockPos.getX() - camPos.x),
|
||||||
(float) (bufferContainer.minCornerBlockPos.getY() - camPos.y),
|
(float) (bufferContainer.minCornerBlockPos.getY() - camPos.y),
|
||||||
(float) (bufferContainer.minCornerBlockPos.getZ() - camPos.z));
|
(float) (bufferContainer.minCornerBlockPos.getZ() - camPos.z));
|
||||||
|
BEFORE_BUFFER_RENDER_EVENT_PARAM.update(renderEventParam, MODEL_POS);
|
||||||
|
|
||||||
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.bind();
|
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.bind();
|
||||||
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.setModelOffsetPos(modelPos);
|
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.setModelOffsetPos(MODEL_POS);
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, BEFORE_BUFFER_RENDER_EVENT_PARAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers);
|
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers);
|
||||||
@@ -337,13 +350,27 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for lock information please view the lock's javadocs
|
||||||
|
long vboReadStamp = vbo.renderStampLock.readLock();
|
||||||
|
long iboReadStamp = vbo.getQuadIBO().renderStampLock.readLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// don't render empty sections
|
||||||
if (vbo.getVertexCount() == 0)
|
if (vbo.getVertexCount() == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't render deleted VBOs (this will crash the driver/game)
|
||||||
|
if (vbo.getId() == 0
|
||||||
|
|| vbo.getQuadIBO().getId() == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 4 vertices per face, but 6 indices (IE 2 triangles) per face, aka need to multiply by 1.5
|
// 4 vertices per face, but 6 indices (IE 2 triangles) per face, aka need to multiply by 1.5
|
||||||
int indexCount = (int)(vbo.getVertexCount() * 1.5);
|
int indexCount = (int) (vbo.getVertexCount() * 1.5);
|
||||||
|
|
||||||
vbo.bind();
|
vbo.bind();
|
||||||
vbo.getQuadIBO().bind();
|
vbo.getQuadIBO().bind();
|
||||||
@@ -357,6 +384,12 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
vbo.unbind();
|
vbo.unbind();
|
||||||
vbo.getQuadIBO().unbind();
|
vbo.getQuadIBO().unbind();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
vbo.renderStampLock.unlock(vboReadStamp);
|
||||||
|
vbo.getQuadIBO().renderStampLock.unlock(iboReadStamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,23 +22,34 @@ package com.seibel.distanthorizons.common.util;
|
|||||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
#else
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
#endif
|
||||||
public class ProxyUtil
|
public class ProxyUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
public static ILevelWrapper getLevelWrapper(LevelAccessor level)
|
public static ILevelWrapper getLevelWrapper(
|
||||||
|
#if MC_VER <= MC_1_12_2 World #else LevelAccessor #endif level
|
||||||
|
)
|
||||||
{
|
{
|
||||||
ILevelWrapper levelWrapper;
|
ILevelWrapper levelWrapper;
|
||||||
if (level instanceof ServerLevel)
|
if (level instanceof #if MC_VER <= MC_1_12_2 WorldServer #else ServerLevel #endif)
|
||||||
{
|
{
|
||||||
levelWrapper = ServerLevelWrapper.getWrapper((ServerLevel) level);
|
levelWrapper = ServerLevelWrapper.getWrapper(
|
||||||
|
#if MC_VER <= MC_1_12_2 (WorldServer) #else (ServerLevel) #endif level
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
levelWrapper = ClientLevelWrapper.getWrapper((ClientLevel) level);
|
levelWrapper = ClientLevelWrapper.getWrapper(
|
||||||
|
#if MC_VER <= MC_1_12_2 (WorldClient) #else (ClientLevel) #endif level
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return levelWrapper;
|
return levelWrapper;
|
||||||
|
|||||||
+33
-11
@@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers;
|
package com.seibel.distanthorizons.common.wrappers;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderApi;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObjectFactory;
|
import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObjectFactory;
|
||||||
import com.seibel.distanthorizons.common.render.blaze.BlazeDhRenderApiDefinition;
|
import com.seibel.distanthorizons.common.render.blaze.BlazeDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.GlDhRenderApiDefinition;
|
import com.seibel.distanthorizons.common.render.openGl.GlDhRenderApiDefinition;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingApi;
|
||||||
import com.seibel.distanthorizons.core.render.renderer.GenericRenderObjectFactory;
|
import com.seibel.distanthorizons.core.render.renderer.GenericRenderObjectFactory;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.ClassicConfigGUI;
|
import com.seibel.distanthorizons.common.wrappers.gui.classicConfig.ClassicConfigGUI;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.LangWrapper;
|
import com.seibel.distanthorizons.common.wrappers.gui.LangWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.level.KeyedClientLevelManager;
|
import com.seibel.distanthorizons.common.wrappers.level.KeyedClientLevelManager;
|
||||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper;
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper;
|
||||||
@@ -80,28 +81,39 @@ public class DependencySetup
|
|||||||
SingletonInjector.INSTANCE.bind(IConfigGui.class, ClassicConfigGUI.CONFIG_CORE_INTERFACE);
|
SingletonInjector.INSTANCE.bind(IConfigGui.class, ClassicConfigGUI.CONFIG_CORE_INTERFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean renderingApiBindingsSet = false;
|
||||||
/** will be called from a DH thread, not the render thread */
|
/** will be called from a DH thread, not the render thread */
|
||||||
public static void setRenderingApiBindings()
|
public synchronized static void setRenderingApiBindings()
|
||||||
{
|
{
|
||||||
EDhApiRenderApi renderingApiEnum = Config.Client.Advanced.Graphics.Experimental.renderingApi.get();
|
// shouldn't happen, but there was a single report that this method was triggered twice
|
||||||
if (renderingApiEnum == EDhApiRenderApi.AUTO)
|
if (renderingApiBindingsSet)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Rendering bindings already set, skipping. How did this happen?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renderingApiBindingsSet = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EDhApiRenderingEngine renderingApiEnum = Config.Client.Advanced.Graphics.Experimental.renderingEngine.get();
|
||||||
|
if (renderingApiEnum == EDhApiRenderingEngine.AUTO)
|
||||||
{
|
{
|
||||||
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||||
renderingApiEnum = versionConstants.getDefaultRenderingApi();
|
renderingApiEnum = versionConstants.getDefaultRenderingEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Setting DH Rendering API to: ["+renderingApiEnum+"].");
|
LOGGER.info("Setting DH Rendering API to: ["+renderingApiEnum+"]...");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean validApi;
|
boolean validApi;
|
||||||
AbstractDhRenderApiDefinition renderDefinition;
|
AbstractDhRenderApiDefinition renderDefinition;
|
||||||
if (renderingApiEnum == EDhApiRenderApi.OPEN_GL)
|
if (renderingApiEnum == EDhApiRenderingEngine.OPEN_GL)
|
||||||
{
|
{
|
||||||
validApi = true;
|
validApi = true;
|
||||||
renderDefinition = new GlDhRenderApiDefinition();
|
renderDefinition = new GlDhRenderApiDefinition();
|
||||||
}
|
}
|
||||||
else if (renderingApiEnum == EDhApiRenderApi.BLAZE_3D)
|
else if (renderingApiEnum == EDhApiRenderingEngine.BLAZE_3D)
|
||||||
{
|
{
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
validApi = false;
|
validApi = false;
|
||||||
@@ -122,14 +134,24 @@ public class DependencySetup
|
|||||||
// crash if an invalid API is set
|
// crash if an invalid API is set
|
||||||
if (!validApi)
|
if (!validApi)
|
||||||
{
|
{
|
||||||
String message = "["+renderingApiEnum+"] is not supported on this version of Minecraft, reverting to ["+EDhApiRenderApi.AUTO+"].";
|
String message = "["+renderingApiEnum+"] is not supported on this version of Minecraft, reverting to ["+ EDhApiRenderingEngine.AUTO+"].";
|
||||||
|
LOGGER.fatal(message);
|
||||||
|
Config.Client.Advanced.Graphics.Experimental.renderingEngine.set(EDhApiRenderingEngine.AUTO);
|
||||||
|
throw new IllegalStateException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// crash if the rendering API set doesn't match Minecraft's
|
||||||
|
EDhApiRenderingApi mcRenderApi = MinecraftRenderWrapper.INSTANCE.getMcRenderingApi();
|
||||||
|
if (mcRenderApi != renderDefinition.getRenderApi())
|
||||||
|
{
|
||||||
|
String message = "["+renderDefinition.getApiName()+"] cannot be used due to it's API ["+renderDefinition.getRenderApi().name()+"] not matching what Minecraft is currently set to use. Please either change Minecraft's rendering API or Distant Horizons'.";
|
||||||
LOGGER.fatal(message);
|
LOGGER.fatal(message);
|
||||||
Config.Client.Advanced.Graphics.Experimental.renderingApi.set(EDhApiRenderApi.AUTO);
|
|
||||||
throw new IllegalStateException(message);
|
throw new IllegalStateException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
renderDefinition.bindRenderers();
|
renderDefinition.bindRenderers();
|
||||||
|
LOGGER.info("DH Rendering successfully bound to: ["+renderDefinition.getApiName()+"]...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+101
-17
@@ -26,9 +26,15 @@ import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
|||||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
#else
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class converts to and from Minecraft objects (Ex: Matrix4f)
|
* This class converts to and from Minecraft objects (Ex: Matrix4f)
|
||||||
@@ -39,15 +45,17 @@ import net.minecraft.world.level.ChunkPos;
|
|||||||
*/
|
*/
|
||||||
public class McObjectConverter
|
public class McObjectConverter
|
||||||
{
|
{
|
||||||
private static int bufferIndex(int x, int y)
|
|
||||||
{
|
|
||||||
return y * 4 + x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// matrix //
|
||||||
|
//========//
|
||||||
|
//region
|
||||||
|
|
||||||
/** 4x4 float matrix converter */
|
/** 4x4 float matrix converter */
|
||||||
public static Mat4f Convert(
|
public static Mat4f Convert(
|
||||||
#if MC_VER < MC_1_19_4 com.mojang.math.Matrix4f
|
#if MC_VER <= MC_1_12_2 org.joml.Matrix4f
|
||||||
|
#elif MC_VER < MC_1_19_4 com.mojang.math.Matrix4f
|
||||||
#elif MC_VER < MC_1_21_6 org.joml.Matrix4f
|
#elif MC_VER < MC_1_21_6 org.joml.Matrix4f
|
||||||
#else org.joml.Matrix4fc
|
#else org.joml.Matrix4fc
|
||||||
#endif
|
#endif
|
||||||
@@ -56,21 +64,24 @@ public class McObjectConverter
|
|||||||
FloatBuffer buffer = FloatBuffer.allocate(16);
|
FloatBuffer buffer = FloatBuffer.allocate(16);
|
||||||
storeMatrix(mcMatrix, buffer);
|
storeMatrix(mcMatrix, buffer);
|
||||||
Mat4f matrix = new Mat4f(buffer);
|
Mat4f matrix = new Mat4f(buffer);
|
||||||
#if MC_VER < MC_1_19_4
|
#if MC_VER > MC_1_12_2 && MC_VER < MC_1_19_4
|
||||||
matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it
|
matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it
|
||||||
#endif
|
#endif
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
/** Taken from Minecraft's com.mojang.math.Matrix4f class from 1.18.2 */
|
/** Taken from Minecraft's com.mojang.math.Matrix4f class from 1.18.2 */
|
||||||
private static void storeMatrix(
|
private static void storeMatrix(
|
||||||
#if MC_VER < MC_1_19_4 com.mojang.math.Matrix4f
|
#if MC_VER <= MC_1_12_2 org.joml.Matrix4f
|
||||||
|
#elif MC_VER < MC_1_19_4 com.mojang.math.Matrix4f
|
||||||
#elif MC_VER < MC_1_21_6 org.joml.Matrix4f
|
#elif MC_VER < MC_1_21_6 org.joml.Matrix4f
|
||||||
#else org.joml.Matrix4fc
|
#else org.joml.Matrix4fc
|
||||||
#endif
|
#endif
|
||||||
matrix,
|
matrix,
|
||||||
FloatBuffer buffer)
|
FloatBuffer buffer)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_19_4
|
#if MC_VER <= MC_1_12_2
|
||||||
|
matrix.get(buffer);
|
||||||
|
#elif MC_VER < MC_1_19_4
|
||||||
matrix.store(buffer);
|
matrix.store(buffer);
|
||||||
#else
|
#else
|
||||||
// Mojang starts to use joml's Matrix4f libary in 1.19.3 so we copy their store method and use it here if its newer than 1.19.3
|
// Mojang starts to use joml's Matrix4f libary in 1.19.3 so we copy their store method and use it here if its newer than 1.19.3
|
||||||
@@ -92,37 +103,85 @@ public class McObjectConverter
|
|||||||
buffer.put(bufferIndex(3, 3), matrix.m33());
|
buffer.put(bufferIndex(3, 3), matrix.m33());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
private static int bufferIndex(int x, int y) { return y * 4 + x; }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
static final Direction[] directions;
|
|
||||||
static final EDhDirection[] lodDirections;
|
//===========//
|
||||||
|
// direction //
|
||||||
|
//===========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static final EnumFacing[] mcDirections;
|
||||||
|
#else
|
||||||
|
private static final Direction[] mcDirections;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private static final EDhDirection[] dhDirections;
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
EDhDirection[] lodDirs = EDhDirection.values();
|
EDhDirection[] lodDirs = EDhDirection.values();
|
||||||
directions = new Direction[lodDirs.length];
|
|
||||||
lodDirections = new EDhDirection[lodDirs.length];
|
#if MC_VER <= MC_1_12_2
|
||||||
|
mcDirections = new EnumFacing[lodDirs.length];
|
||||||
|
#else
|
||||||
|
mcDirections = new Direction[lodDirs.length];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dhDirections = new EDhDirection[lodDirs.length];
|
||||||
for (EDhDirection lodDir : lodDirs)
|
for (EDhDirection lodDir : lodDirs)
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
EnumFacing dir;
|
||||||
|
#else
|
||||||
Direction dir;
|
Direction dir;
|
||||||
|
#endif
|
||||||
switch (lodDir.name().toUpperCase())
|
switch (lodDir.name().toUpperCase())
|
||||||
{
|
{
|
||||||
case "DOWN":
|
case "DOWN":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.DOWN;
|
||||||
|
#else
|
||||||
dir = Direction.DOWN;
|
dir = Direction.DOWN;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case "UP":
|
case "UP":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.UP;
|
||||||
|
#else
|
||||||
dir = Direction.UP;
|
dir = Direction.UP;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case "NORTH":
|
case "NORTH":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.NORTH;
|
||||||
|
#else
|
||||||
dir = Direction.NORTH;
|
dir = Direction.NORTH;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case "SOUTH":
|
case "SOUTH":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.SOUTH;
|
||||||
|
#else
|
||||||
dir = Direction.SOUTH;
|
dir = Direction.SOUTH;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case "WEST":
|
case "WEST":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.WEST;
|
||||||
|
#else
|
||||||
dir = Direction.WEST;
|
dir = Direction.WEST;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case "EAST":
|
case "EAST":
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
dir = EnumFacing.EAST;
|
||||||
|
#else
|
||||||
dir = Direction.EAST;
|
dir = Direction.EAST;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dir = null;
|
dir = null;
|
||||||
@@ -131,13 +190,37 @@ public class McObjectConverter
|
|||||||
|
|
||||||
if (dir == null)
|
if (dir == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Invalid direction on init mapping: " + lodDir);
|
throw new IllegalArgumentException("Invalid direction on init mapping: [" + lodDir + "].");
|
||||||
}
|
}
|
||||||
directions[lodDir.ordinal()] = dir;
|
mcDirections[lodDir.ordinal()] = dir;
|
||||||
lodDirections[dir.ordinal()] = lodDir;
|
dhDirections[dir.ordinal()] = lodDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static EnumFacing Convert(EDhDirection lodDirection)
|
||||||
|
#else
|
||||||
|
public static Direction Convert(EDhDirection lodDirection)
|
||||||
|
#endif
|
||||||
|
{ return mcDirections[lodDirection.ordinal()]; }
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static EDhDirection Convert(EnumFacing direction)
|
||||||
|
#else
|
||||||
|
public static EDhDirection Convert(Direction direction)
|
||||||
|
#endif
|
||||||
|
{ return dhDirections[direction.ordinal()]; }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==================//
|
||||||
|
// position objects //
|
||||||
|
//==================//
|
||||||
|
//region
|
||||||
|
|
||||||
public static BlockPos Convert(DhBlockPos wrappedPos) { return new BlockPos(wrappedPos.getX(), wrappedPos.getY(), wrappedPos.getZ()); }
|
public static BlockPos Convert(DhBlockPos wrappedPos) { return new BlockPos(wrappedPos.getX(), wrappedPos.getY(), wrappedPos.getZ()); }
|
||||||
|
|
||||||
public static ChunkPos Convert(DhChunkPos wrappedPos) { return new ChunkPos(wrappedPos.getX(), wrappedPos.getZ()); }
|
public static ChunkPos Convert(DhChunkPos wrappedPos) { return new ChunkPos(wrappedPos.getX(), wrappedPos.getZ()); }
|
||||||
@@ -150,7 +233,8 @@ public class McObjectConverter
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction Convert(EDhDirection lodDirection) { return directions[lodDirection.ordinal()]; }
|
//endregion
|
||||||
public static EDhDirection Convert(Direction direction) { return lodDirections[direction.ordinal()]; }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-8
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers;
|
package com.seibel.distanthorizons.common.wrappers;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderApi;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||||
|
|
||||||
public class VersionConstants implements IVersionConstants
|
public class VersionConstants implements IVersionConstants
|
||||||
@@ -51,7 +51,10 @@ public class VersionConstants implements IVersionConstants
|
|||||||
// it can't load client classes when running as a dedicated server,
|
// it can't load client classes when running as a dedicated server,
|
||||||
// which was how we were dynamically accessing the MC version string
|
// which was how we were dynamically accessing the MC version string
|
||||||
|
|
||||||
#if MC_VER == MC_1_16_5
|
#if MC_VER == MC_1_12_2
|
||||||
|
return "1.12.2";
|
||||||
|
|
||||||
|
#elif MC_VER == MC_1_16_5
|
||||||
return "1.16.5";
|
return "1.16.5";
|
||||||
|
|
||||||
#elif MC_VER == MC_1_17_1
|
#elif MC_VER == MC_1_17_1
|
||||||
@@ -93,8 +96,10 @@ public class VersionConstants implements IVersionConstants
|
|||||||
return "1.21.10";
|
return "1.21.10";
|
||||||
#elif MC_VER == MC_1_21_11
|
#elif MC_VER == MC_1_21_11
|
||||||
return "1.21.11";
|
return "1.21.11";
|
||||||
#elif MC_VER == MC_1_26_1
|
#elif MC_VER == MC_26_1_2
|
||||||
return "21.6";
|
return "26.1.2";
|
||||||
|
#elif MC_VER == MC_26_2_0
|
||||||
|
return "26.2.0";
|
||||||
#else
|
#else
|
||||||
ERROR MC version constant missing
|
ERROR MC version constant missing
|
||||||
#endif
|
#endif
|
||||||
@@ -102,12 +107,12 @@ public class VersionConstants implements IVersionConstants
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EDhApiRenderApi getDefaultRenderingApi()
|
public EDhApiRenderingEngine getDefaultRenderingEngine()
|
||||||
{
|
{
|
||||||
#if MC_VER <= MC_1_26_1
|
#if MC_VER <= MC_1_21_11
|
||||||
return EDhApiRenderApi.OPEN_GL;
|
return EDhApiRenderingEngine.OPEN_GL;
|
||||||
#else
|
#else
|
||||||
ERROR MC version constant missing
|
return EDhApiRenderingEngine.BLAZE_3D;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+119
-27
@@ -46,17 +46,30 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.IBatchGeneratorEnvironmentWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.IBatchGeneratorEnvironmentWrapper;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
|
||||||
#if MC_VER > MC_1_17_1
|
#if MC_VER > MC_1_17_1
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This handles creating abstract wrapper objects.
|
* This handles creating abstract wrapper objects.
|
||||||
@@ -172,7 +185,8 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
*/
|
*/
|
||||||
public IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException
|
public IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException
|
||||||
{
|
{
|
||||||
if (objectArray.length == 1 && objectArray[0] instanceof IChunkWrapper)
|
if (objectArray.length == 1
|
||||||
|
&& objectArray[0] instanceof IChunkWrapper)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -186,42 +200,103 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if MC_VER <= MC_1_XX_X
|
else if (objectArray.length != 2)
|
||||||
else if (objectArray.length == 2)
|
|
||||||
{
|
{
|
||||||
|
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// correct number of parameters from the API
|
// correct number of parameters from the API
|
||||||
|
|
||||||
// chunk
|
//=======//
|
||||||
if (!(objectArray[0] instanceof ChunkAccess))
|
// chunk //
|
||||||
|
//=======//
|
||||||
|
//region
|
||||||
|
|
||||||
|
boolean chunkClassCorrect;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
chunkClassCorrect = (objectArray[0] instanceof Chunk);
|
||||||
|
#else
|
||||||
|
chunkClassCorrect = (objectArray[0] instanceof ChunkAccess);
|
||||||
|
#endif
|
||||||
|
if (!chunkClassCorrect)
|
||||||
{
|
{
|
||||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
Chunk chunk = (Chunk) objectArray[0];
|
||||||
|
#else
|
||||||
ChunkAccess chunk = (ChunkAccess) objectArray[0];
|
ChunkAccess chunk = (ChunkAccess) objectArray[0];
|
||||||
|
#endif
|
||||||
|
|
||||||
// level / light source
|
//endregion
|
||||||
if (!(objectArray[1] instanceof Level))
|
|
||||||
|
|
||||||
|
|
||||||
|
//=======//
|
||||||
|
// level //
|
||||||
|
//=======//
|
||||||
|
//region
|
||||||
|
|
||||||
|
boolean levelClassCorrect;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
levelClassCorrect = (objectArray[1] instanceof World);
|
||||||
|
#else
|
||||||
|
levelClassCorrect = (objectArray[1] instanceof Level);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!levelClassCorrect)
|
||||||
{
|
{
|
||||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||||
}
|
}
|
||||||
// the level is needed for the DH level wrapper...
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
World level = (World) objectArray[1];
|
||||||
|
#else
|
||||||
Level level = (Level) objectArray[1];
|
Level level = (Level) objectArray[1];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
// level wrapper
|
|
||||||
ILevelWrapper levelWrapper = level.isClientSide()
|
//===============//
|
||||||
? ClientLevelWrapper.getWrapper((ClientLevel)level)
|
// level wrapper //
|
||||||
: ServerLevelWrapper.getWrapper((ServerLevel)level);
|
//===============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
boolean isClientSide;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
isClientSide = !level.isRemote;
|
||||||
|
#else
|
||||||
|
isClientSide = level.isClientSide();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ILevelWrapper levelWrapper;
|
||||||
|
if (isClientSide)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
levelWrapper = ClientLevelWrapper.getWrapper((WorldClient)level);
|
||||||
|
#else
|
||||||
|
levelWrapper = ClientLevelWrapper.getWrapper((ClientLevel)level);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
levelWrapper = ServerLevelWrapper.getWrapper((WorldServer)level);
|
||||||
|
#else
|
||||||
|
levelWrapper = ServerLevelWrapper.getWrapper((ServerLevel)level);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new ChunkWrapper(chunk, levelWrapper);
|
return new ChunkWrapper(chunk, levelWrapper);
|
||||||
}
|
}
|
||||||
// incorrect number of parameters from the API
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
|
||||||
}
|
|
||||||
//#endif
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Note: when this is updated for different MC versions,
|
* Note: when this is updated for different MC versions,
|
||||||
* make sure you also update the documentation in {@link IDhApiWorldGenerator#generateChunks}.
|
* make sure you also update the documentation in {@link IDhApiWorldGenerator#generateChunks}.
|
||||||
@@ -230,13 +305,19 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
{
|
{
|
||||||
String[] expectedClassNames;
|
String[] expectedClassNames;
|
||||||
|
|
||||||
//#if MC_VER <= MC_1_XX_X
|
#if MC_VER <= MC_1_12_2
|
||||||
|
expectedClassNames = new String[]
|
||||||
|
{
|
||||||
|
Chunk.class.getName(),
|
||||||
|
"[WorldClient] or [WorldServer]" // Classes are not referenced by names to avoid exception when one of them is missing
|
||||||
|
};
|
||||||
|
#else
|
||||||
expectedClassNames = new String[]
|
expectedClassNames = new String[]
|
||||||
{
|
{
|
||||||
ChunkAccess.class.getName(),
|
ChunkAccess.class.getName(),
|
||||||
"[ServerLevel] or [ClientLevel]" // Classes are not referenced by names to avoid exception when one of them is missing
|
"[ServerLevel] or [ClientLevel]" // Classes are not referenced by names to avoid exception when one of them is missing
|
||||||
};
|
};
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
return createWrapperErrorMessage("Chunk wrapper", expectedClassNames, objectArray);
|
return createWrapperErrorMessage("Chunk wrapper", expectedClassNames, objectArray);
|
||||||
}
|
}
|
||||||
@@ -322,19 +403,29 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#if MC_VER <= MC_1_XX_X
|
|
||||||
if (objectArray.length != 1)
|
if (objectArray.length != 1)
|
||||||
{
|
{
|
||||||
throw new ClassCastException(createBlockStateWrapperErrorMessage(objectArray));
|
throw new ClassCastException(createBlockStateWrapperErrorMessage(objectArray));
|
||||||
}
|
}
|
||||||
if (!(objectArray[0] instanceof BlockState))
|
|
||||||
|
boolean blockClassCorrect;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
blockClassCorrect = (objectArray[0] instanceof IBlockState);
|
||||||
|
#else
|
||||||
|
blockClassCorrect = (objectArray[0] instanceof BlockState);
|
||||||
|
#endif
|
||||||
|
if (!blockClassCorrect)
|
||||||
{
|
{
|
||||||
throw new ClassCastException(createBlockStateWrapperErrorMessage(objectArray));
|
throw new ClassCastException(createBlockStateWrapperErrorMessage(objectArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
IBlockState blockState = (IBlockState) objectArray[0];
|
||||||
|
return BlockStateWrapper.fromBlockState(blockState, coreLevelWrapper);
|
||||||
|
#else
|
||||||
BlockState blockState = (BlockState) objectArray[0];
|
BlockState blockState = (BlockState) objectArray[0];
|
||||||
return BlockStateWrapper.fromBlockState(blockState, coreLevelWrapper);
|
return BlockStateWrapper.fromBlockState(blockState, coreLevelWrapper);
|
||||||
//#endif
|
#endif
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Note: when this is updated for different MC versions,
|
* Note: when this is updated for different MC versions,
|
||||||
@@ -344,7 +435,9 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
{
|
{
|
||||||
String[] expectedClassNames;
|
String[] expectedClassNames;
|
||||||
|
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
expectedClassNames = new String[] { IBlockState.class.getName() };
|
||||||
|
#elif MC_VER <= MC_1_17_1
|
||||||
expectedClassNames = new String[] { Biome.class.getName() };
|
expectedClassNames = new String[] { Biome.class.getName() };
|
||||||
#else
|
#else
|
||||||
expectedClassNames = new String[] { Holder.class.getName()+"<"+Biome.class.getName()+">" };
|
expectedClassNames = new String[] { Holder.class.getName()+"<"+Biome.class.getName()+">" };
|
||||||
@@ -357,7 +450,6 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
// helper methods //
|
// helper methods //
|
||||||
//================//
|
//================//
|
||||||
|
|||||||
+42
-12
@@ -1,20 +1,24 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.BlockBiomeWrapperPair;
|
import com.seibel.distanthorizons.core.dataObjects.BlockBiomeWrapperPair;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
#else
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.ColorResolver;
|
import net.minecraft.world.level.ColorResolver;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -45,8 +49,6 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static final ConcurrentHashMap<BlockBiomeWrapperPair, Integer> COLOR_BY_BLOCK_BIOME_PAIR = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<BlockBiomeWrapperPair, Integer> COLOR_BY_BLOCK_BIOME_PAIR = new ConcurrentHashMap<>();
|
||||||
/** returned if the color cache is incomplete */
|
|
||||||
public static final int INVALID_COLOR = Integer.MIN_VALUE;
|
|
||||||
|
|
||||||
|
|
||||||
protected BiomeWrapper biomeWrapper;
|
protected BiomeWrapper biomeWrapper;
|
||||||
@@ -60,6 +62,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
public AbstractDhTintGetter() { }
|
public AbstractDhTintGetter() { }
|
||||||
|
|
||||||
@@ -76,11 +79,14 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
this.smoothingRadiusInBlocks = Config.Client.Advanced.Graphics.Quality.lodBiomeBlending.get();
|
this.smoothingRadiusInBlocks = Config.Client.Advanced.Graphics.Quality.lodBiomeBlending.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
//================//
|
|
||||||
// shared methods //
|
//===============//
|
||||||
//================//
|
// color getters //
|
||||||
|
//===============//
|
||||||
|
//region
|
||||||
|
|
||||||
/** Called by MC's tint getter */
|
/** Called by MC's tint getter */
|
||||||
@Override
|
@Override
|
||||||
@@ -94,7 +100,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
* Can be called by DH directly, skipping some of MC's logic
|
* Can be called by DH directly, skipping some of MC's logic
|
||||||
* to speed up tint getting slightly.
|
* to speed up tint getting slightly.
|
||||||
*
|
*
|
||||||
* @return {@link AbstractDhTintGetter#INVALID_COLOR} if any of the biomes needed for this position
|
* @return {@link ClientBlockStateColorCache#INVALID_COLOR} if any of the biomes needed for this position
|
||||||
* were not cached. In that case calling {@link AbstractDhTintGetter#getBlockTint(BlockPos, ColorResolver)}
|
* were not cached. In that case calling {@link AbstractDhTintGetter#getBlockTint(BlockPos, ColorResolver)}
|
||||||
* will need to be called by MC's ColorResolver so we can
|
* will need to be called by MC's ColorResolver so we can
|
||||||
* populate the color cache.
|
* populate the color cache.
|
||||||
@@ -155,9 +161,9 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
int id = FullDataPointUtil.getId(dataPoint);
|
int id = FullDataPointUtil.getId(dataPoint);
|
||||||
BiomeWrapper biomeWrapper = (BiomeWrapper) this.fullDataSource.mapping.getBiomeWrapper(id);
|
BiomeWrapper biomeWrapper = (BiomeWrapper) this.fullDataSource.mapping.getBiomeWrapper(id);
|
||||||
int color = this.tryGetClientBiomeColor(colorResolver, biomeWrapper);
|
int color = this.tryGetClientBiomeColor(colorResolver, biomeWrapper);
|
||||||
if (color == INVALID_COLOR)
|
if (color == ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
{
|
{
|
||||||
return INVALID_COLOR;
|
return ClientBlockStateColorCache.INVALID_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +201,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
BlockBiomeWrapperPair pair = BlockBiomeWrapperPair.get(this.blockStateWrapper, biomeWrapper);
|
BlockBiomeWrapperPair pair = BlockBiomeWrapperPair.get(this.blockStateWrapper, biomeWrapper);
|
||||||
|
|
||||||
// use the cached color if possible
|
// use the cached color if possible
|
||||||
Integer cachedColor = COLOR_BY_BLOCK_BIOME_PAIR.get(pair); // explicit Integer return here reduces unnecessary allocations
|
Integer cachedColor = COLOR_BY_BLOCK_BIOME_PAIR.get(pair);
|
||||||
if (cachedColor != null)
|
if (cachedColor != null)
|
||||||
{
|
{
|
||||||
return cachedColor;
|
return cachedColor;
|
||||||
@@ -206,7 +212,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
// no color resolver is present,
|
// no color resolver is present,
|
||||||
// the cache needs to be populated before
|
// the cache needs to be populated before
|
||||||
// we can use the fast path
|
// we can use the fast path
|
||||||
return INVALID_COLOR;
|
return ClientBlockStateColorCache.INVALID_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -335,6 +341,30 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=================//
|
||||||
|
// static handlers //
|
||||||
|
//=================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
/**
|
||||||
|
* can be used in newer MC versions
|
||||||
|
* where the color getting logic is a bit more manual
|
||||||
|
*/
|
||||||
|
public static void setStaticColor(BlockStateWrapper blockStateWrapper, BiomeWrapper biomeWrapper, Integer colorInt)
|
||||||
|
{
|
||||||
|
BlockBiomeWrapperPair pair = BlockBiomeWrapperPair.get(blockStateWrapper, biomeWrapper);
|
||||||
|
COLOR_BY_BLOCK_BIOME_PAIR.put(pair, colorInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear() { COLOR_BY_BLOCK_BIOME_PAIR.clear(); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+66
-12
@@ -28,12 +28,15 @@ import java.util.concurrent.ConcurrentMap;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||||
|
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER > MC_1_12_2
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
#elif MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
#elif MC_VER == MC_1_18_2 || MC_VER == MC_1_19_2
|
#elif MC_VER == MC_1_18_2 || MC_VER == MC_1_19_2
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
@@ -45,14 +48,21 @@ import net.minecraft.core.Holder;
|
|||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
#elif MC_VER <= MC_1_21_10
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
#else
|
#else
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.core.component.DataComponentMap;
|
import net.minecraft.core.component.DataComponentMap;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
#else
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if MC_VER >= MC_1_18_2
|
#if MC_VER >= MC_1_18_2
|
||||||
import net.minecraft.world.level.biome.Biomes;
|
import net.minecraft.world.level.biome.Biomes;
|
||||||
@@ -108,8 +118,13 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
//==============//
|
//==============//
|
||||||
// constructors //
|
// constructors //
|
||||||
//==============//
|
//==============//
|
||||||
|
//region
|
||||||
|
|
||||||
public static BiomeWrapper getBiomeWrapper(#if MC_VER < MC_1_18_2 Biome #else Holder<Biome> #endif biome, ILevelWrapper levelWrapper)
|
#if MC_VER < MC_1_18_2
|
||||||
|
public static BiomeWrapper getBiomeWrapper(Biome biome, ILevelWrapper levelWrapper)
|
||||||
|
#else
|
||||||
|
public static BiomeWrapper getBiomeWrapper(Holder<Biome> biome, ILevelWrapper levelWrapper)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (biome == null)
|
if (biome == null)
|
||||||
{
|
{
|
||||||
@@ -129,7 +144,12 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
return newWrapper;
|
return newWrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private BiomeWrapper(#if MC_VER < MC_1_18_2 Biome #else Holder<Biome> #endif biome, ILevelWrapper levelWrapper)
|
|
||||||
|
#if MC_VER < MC_1_18_2
|
||||||
|
private BiomeWrapper(Biome biome, ILevelWrapper levelWrapper)
|
||||||
|
#else
|
||||||
|
private BiomeWrapper(Holder<Biome> biome, ILevelWrapper levelWrapper)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
this.biome = biome;
|
this.biome = biome;
|
||||||
this.serialString = this.serialize(levelWrapper);
|
this.serialString = this.serialize(levelWrapper);
|
||||||
@@ -138,11 +158,14 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
//LOGGER.trace("Created BiomeWrapper ["+this.serialString+"] for ["+biome+"]");
|
//LOGGER.trace("Created BiomeWrapper ["+this.serialString+"] for ["+biome+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=========//
|
//=========//
|
||||||
// methods //
|
// methods //
|
||||||
//=========//
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName()
|
public String getName()
|
||||||
@@ -188,11 +211,14 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
@Override
|
@Override
|
||||||
public String toString() { return this.getSerialString(); }
|
public String toString() { return this.getSerialString(); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=======================//
|
//=======================//
|
||||||
// serialization methods //
|
// serialization methods //
|
||||||
//=======================//
|
//=======================//
|
||||||
|
//region
|
||||||
|
|
||||||
public String serialize(ILevelWrapper levelWrapper)
|
public String serialize(ILevelWrapper levelWrapper)
|
||||||
{
|
{
|
||||||
@@ -219,8 +245,10 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
|
|
||||||
// generate the serial string //
|
// generate the serial string //
|
||||||
|
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
Level level = (Level)levelWrapper.getWrappedMcObject();
|
Level level = (Level)levelWrapper.getWrappedMcObject();
|
||||||
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
ResourceLocation resourceLocation;
|
ResourceLocation resourceLocation;
|
||||||
@@ -228,16 +256,19 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
Identifier resourceLocation;
|
Identifier resourceLocation;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
resourceLocation = biome.getRegistryName();
|
||||||
|
#elif MC_VER <= MC_1_17_1
|
||||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
|
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
|
||||||
#elif MC_VER <= MC_1_19_2
|
#elif MC_VER <= MC_1_19_2
|
||||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome.value());
|
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome.value());
|
||||||
#elif MC_VER <= MC_1_21_4
|
#elif MC_VER <= MC_1_21_1
|
||||||
resourceLocation = registryAccess.registryOrThrow(Registries.BIOME).getKey(this.biome.value());
|
resourceLocation = registryAccess.registryOrThrow(Registries.BIOME).getKey(this.biome.value());
|
||||||
#else
|
#else
|
||||||
resourceLocation = registryAccess.lookupOrThrow(Registries.BIOME).getKey(this.biome.value());
|
resourceLocation = registryAccess.lookupOrThrow(Registries.BIOME).getKey(this.biome.value());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (resourceLocation == null)
|
if (resourceLocation == null)
|
||||||
{
|
{
|
||||||
String biomeName;
|
String biomeName;
|
||||||
@@ -292,11 +323,16 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
Level level = (Level) levelWrapper.getWrappedMcObject();
|
Level level = (Level) levelWrapper.getWrappedMcObject();
|
||||||
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
BiomeDeserializeResult deserializeResult = deserializeBiome(resourceLocationString);
|
||||||
|
#else
|
||||||
BiomeDeserializeResult deserializeResult = deserializeBiome(resourceLocationString, registryAccess);
|
BiomeDeserializeResult deserializeResult = deserializeBiome(resourceLocationString, registryAccess);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (!deserializeResult.success)
|
if (!deserializeResult.success)
|
||||||
@@ -324,7 +360,11 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static BiomeDeserializeResult deserializeBiome(String resourceLocationString) throws IOException
|
||||||
|
#else
|
||||||
public static BiomeDeserializeResult deserializeBiome(String resourceLocationString, net.minecraft.core.RegistryAccess registryAccess) throws IOException
|
public static BiomeDeserializeResult deserializeBiome(String resourceLocationString, net.minecraft.core.RegistryAccess registryAccess) throws IOException
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
// parse the resource location
|
// parse the resource location
|
||||||
int separatorIndex = resourceLocationString.indexOf(":");
|
int separatorIndex = resourceLocationString.indexOf(":");
|
||||||
@@ -355,14 +395,17 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
|
|
||||||
|
|
||||||
boolean success;
|
boolean success;
|
||||||
#if MC_VER <= MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
Biome biome = Biome.REGISTRY.getObject(resourceLocation);
|
||||||
|
success = (biome != null);
|
||||||
|
#elif MC_VER <= MC_1_17_1
|
||||||
Biome biome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
|
Biome biome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
|
||||||
success = (biome != null);
|
success = (biome != null);
|
||||||
#elif MC_VER <= MC_1_19_2
|
#elif MC_VER <= MC_1_19_2
|
||||||
Biome unwrappedBiome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
|
Biome unwrappedBiome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
|
||||||
success = (unwrappedBiome != null);
|
success = (unwrappedBiome != null);
|
||||||
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
||||||
#elif MC_VER <= MC_1_21_4
|
#elif MC_VER <= MC_1_21_1
|
||||||
Biome unwrappedBiome = registryAccess.registryOrThrow(Registries.BIOME).get(resourceLocation);
|
Biome unwrappedBiome = registryAccess.registryOrThrow(Registries.BIOME).get(resourceLocation);
|
||||||
success = (unwrappedBiome != null);
|
success = (unwrappedBiome != null);
|
||||||
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
||||||
@@ -399,10 +442,14 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
return new BiomeDeserializeResult(success, biome);
|
return new BiomeDeserializeResult(success, biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
// helper classes //
|
// helper classes //
|
||||||
//================//
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
public static class BiomeDeserializeResult
|
public static class BiomeDeserializeResult
|
||||||
{
|
{
|
||||||
@@ -414,12 +461,19 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
public final Holder<Biome> biome;
|
public final Holder<Biome> biome;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public BiomeDeserializeResult(boolean success, #if MC_VER < MC_1_18_2 Biome #else Holder<Biome> #endif biome)
|
#if MC_VER < MC_1_18_2
|
||||||
|
public BiomeDeserializeResult(boolean success, Biome biome)
|
||||||
|
#else
|
||||||
|
public BiomeDeserializeResult(boolean success, Holder<Biome> biome)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
this.success = success;
|
this.success = success;
|
||||||
this.biome = biome;
|
this.biome = biome;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+748
-314
File diff suppressed because it is too large
Load Diff
+405
-71
@@ -19,31 +19,45 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper;
|
||||||
|
import com.seibel.distanthorizons.api.interfaces.world.IDhApiLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBlockColorOverrideEvent;
|
||||||
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPosMutable;
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.EnumBlockRenderType;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.block.BlockRotatedPillar;
|
||||||
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
|
import net.minecraft.client.renderer.color.BlockColors;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
#else
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.block.*;
|
import net.minecraft.world.level.block.*;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||||
|
#endif
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
#if MC_VER >= MC_1_19_2
|
#if MC_VER >= MC_1_19_2
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
#else
|
#else
|
||||||
import java.util.Random;
|
|
||||||
#endif
|
#endif
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
|
||||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
#if MC_VER < MC_1_21_5
|
#if MC_VER < MC_1_21_5
|
||||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
@@ -53,11 +67,13 @@ import net.minecraft.client.renderer.block.model.BakedQuad;
|
|||||||
#else
|
#else
|
||||||
import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart;
|
import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart;
|
||||||
import net.minecraft.client.resources.model.geometry.BakedQuad;
|
import net.minecraft.client.resources.model.geometry.BakedQuad;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.client.color.block.BlockTintSource;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This stores and calculates the colors
|
* This stores and calculates the colors
|
||||||
* the given {@link BlockState} should have based
|
* the given BlockState should have based
|
||||||
* on the given {@link IClientLevelWrapper}.
|
* on the given {@link IClientLevelWrapper}.
|
||||||
*
|
*
|
||||||
* @see ColorUtil
|
* @see ColorUtil
|
||||||
@@ -66,10 +82,23 @@ public class ClientBlockStateColorCache
|
|||||||
{
|
{
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static final Minecraft MC = Minecraft.getMinecraft();
|
||||||
|
#else
|
||||||
private static final Minecraft MC = Minecraft.getInstance();
|
private static final Minecraft MC = Minecraft.getInstance();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
#else
|
||||||
private static final HashSet<BlockState> BLOCK_STATES_THAT_NEED_LEVEL = new HashSet<>();
|
private static final HashSet<BlockState> BLOCK_STATES_THAT_NEED_LEVEL = new HashSet<>();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static final HashSet<IBlockState> BROKEN_BLOCK_STATES = new HashSet<>();
|
||||||
|
#else
|
||||||
private static final HashSet<BlockState> BROKEN_BLOCK_STATES = new HashSet<>();
|
private static final HashSet<BlockState> BROKEN_BLOCK_STATES = new HashSet<>();
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods using MC's "RandomSource" object aren't thread safe <br>
|
* Methods using MC's "RandomSource" object aren't thread safe <br>
|
||||||
@@ -81,8 +110,22 @@ public class ClientBlockStateColorCache
|
|||||||
*/
|
*/
|
||||||
private static final ReentrantLock RESOLVE_LOCK = new ReentrantLock();
|
private static final ReentrantLock RESOLVE_LOCK = new ReentrantLock();
|
||||||
|
|
||||||
|
public static final int INVALID_COLOR = -1;
|
||||||
|
|
||||||
|
|
||||||
/** This is the order each direction on a block is processed when attempting to get the texture/color */
|
/** This is the order each direction on a block is processed when attempting to get the texture/color */
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static final @Nullable EnumFacing[] COLOR_RESOLUTION_DIRECTION_ORDER =
|
||||||
|
{
|
||||||
|
EnumFacing.UP,
|
||||||
|
null, // null represents "unculled" faces, IE the top of farmland
|
||||||
|
EnumFacing.NORTH,
|
||||||
|
EnumFacing.EAST,
|
||||||
|
EnumFacing.WEST,
|
||||||
|
EnumFacing.SOUTH,
|
||||||
|
EnumFacing.DOWN
|
||||||
|
};
|
||||||
|
#else
|
||||||
private static final @Nullable Direction[] COLOR_RESOLUTION_DIRECTION_ORDER =
|
private static final @Nullable Direction[] COLOR_RESOLUTION_DIRECTION_ORDER =
|
||||||
{
|
{
|
||||||
Direction.UP,
|
Direction.UP,
|
||||||
@@ -93,6 +136,7 @@ public class ClientBlockStateColorCache
|
|||||||
Direction.SOUTH,
|
Direction.SOUTH,
|
||||||
Direction.DOWN
|
Direction.DOWN
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
private static final int FLOWER_COLOR_SCALE = 5;
|
private static final int FLOWER_COLOR_SCALE = 5;
|
||||||
|
|
||||||
@@ -106,7 +150,11 @@ public class ClientBlockStateColorCache
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private final IClientLevelWrapper clientLevelWrapper;
|
private final IClientLevelWrapper clientLevelWrapper;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private final IBlockState blockState;
|
||||||
|
#else
|
||||||
private final BlockState blockState;
|
private final BlockState blockState;
|
||||||
|
#endif
|
||||||
private final BlockStateWrapper blockStateWrapper;
|
private final BlockStateWrapper blockStateWrapper;
|
||||||
|
|
||||||
private boolean isColorResolved = false;
|
private boolean isColorResolved = false;
|
||||||
@@ -119,6 +167,7 @@ public class ClientBlockStateColorCache
|
|||||||
//===========//
|
//===========//
|
||||||
// constants //
|
// constants //
|
||||||
//===========//
|
//===========//
|
||||||
|
//region
|
||||||
|
|
||||||
private static final int MIN_SRGB_BITS = 0x39000000; // 2^(-13)
|
private static final int MIN_SRGB_BITS = 0x39000000; // 2^(-13)
|
||||||
private static final int MAX_SRGB_BITS = 0x3f7fffff; // 1.0 - f32::EPSILON
|
private static final int MAX_SRGB_BITS = 0x3f7fffff; // 1.0 - f32::EPSILON
|
||||||
@@ -182,16 +231,27 @@ public class ClientBlockStateColorCache
|
|||||||
//endregion
|
//endregion
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final ThreadLocal<TintWithoutLevelOverrider> TintWithoutLevelOverrideGetter = ThreadLocal.withInitial(() -> new TintWithoutLevelOverrider());
|
// these are threadlocals since AbstractDhTintGetter use local variables to handle color queries
|
||||||
private static final ThreadLocal<TintGetterOverride> TintOverrideGetter = ThreadLocal.withInitial(() -> new TintGetterOverride());
|
#if MC_VER > MC_1_12_2
|
||||||
|
private static final ThreadLocal<TintWithoutLevelOverrider> TintWithoutLevelOverrideGetter = ThreadLocal.withInitial(TintWithoutLevelOverrider::new);
|
||||||
|
private static final ThreadLocal<TintGetterOverride> TintOverrideGetter = ThreadLocal.withInitial(TintGetterOverride::new);
|
||||||
|
#endif
|
||||||
|
private static final ThreadLocal<DhApiBlockColorOverrideEvent.EventParam> ColorOverrideEventParamGetter = ThreadLocal.withInitial(DhApiBlockColorOverrideEvent.EventParam::new);
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public ClientBlockStateColorCache(IBlockState blockState, IClientLevelWrapper clientLevelWrapper)
|
||||||
|
#else
|
||||||
public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper clientLevelWrapper)
|
public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper clientLevelWrapper)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
this.blockState = blockState;
|
this.blockState = blockState;
|
||||||
this.blockStateWrapper = BlockStateWrapper.fromBlockState(blockState, clientLevelWrapper);
|
this.blockStateWrapper = BlockStateWrapper.fromBlockState(blockState, clientLevelWrapper);
|
||||||
@@ -200,11 +260,14 @@ public class ClientBlockStateColorCache
|
|||||||
this.resolveColors();
|
this.resolveColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===================//
|
//===================//
|
||||||
// color calculation //
|
// color calculation //
|
||||||
//===================//
|
//===================//
|
||||||
|
//region
|
||||||
|
|
||||||
private void resolveColors()
|
private void resolveColors()
|
||||||
{
|
{
|
||||||
@@ -218,17 +281,54 @@ public class ClientBlockStateColorCache
|
|||||||
// getQuads() isn't thread safe so we need to put this logic in a lock
|
// getQuads() isn't thread safe so we need to put this logic in a lock
|
||||||
RESOLVE_LOCK.lock();
|
RESOLVE_LOCK.lock();
|
||||||
|
|
||||||
if (this.blockState.getFluidState().isEmpty())
|
#if MC_VER <= MC_1_12_2
|
||||||
|
if (this.blockState.getRenderType() == EnumBlockRenderType.ENTITYBLOCK_ANIMATED)
|
||||||
|
{
|
||||||
|
this.needPostTinting = false;
|
||||||
|
this.tintIndex = 0;
|
||||||
|
this.baseColor = ColorUtil.argbToInt(255,
|
||||||
|
this.blockStateWrapper.getMapColor().getRed(),
|
||||||
|
this.blockStateWrapper.getMapColor().getGreen(),
|
||||||
|
this.blockStateWrapper.getMapColor().getBlue());
|
||||||
|
this.isColorResolved = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!this.blockStateWrapper.isLiquid())
|
||||||
{
|
{
|
||||||
// look for the first non-empty direction
|
// look for the first non-empty direction
|
||||||
List<BakedQuad> quads = null;
|
List<BakedQuad> quads = null;
|
||||||
for (Direction direction : COLOR_RESOLUTION_DIRECTION_ORDER)
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
EnumFacing direction;
|
||||||
|
#else
|
||||||
|
Direction direction;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < COLOR_RESOLUTION_DIRECTION_ORDER.length; i++)
|
||||||
|
{
|
||||||
|
direction = COLOR_RESOLUTION_DIRECTION_ORDER[i];
|
||||||
|
try
|
||||||
{
|
{
|
||||||
quads = this.getQuadsForDirection(direction);
|
quads = this.getQuadsForDirection(direction);
|
||||||
if (quads != null && !quads.isEmpty()
|
}
|
||||||
|
catch (Exception ignore)
|
||||||
|
{
|
||||||
|
// failing to get quads can happen in the block is invalid
|
||||||
|
// (i.e. AIR is somehow passed in)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quads != null
|
||||||
|
&& !quads.isEmpty()
|
||||||
&& !(
|
&& !(
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
this.blockState.getBlock() instanceof BlockRotatedPillar
|
||||||
|
&& direction == EnumFacing.UP
|
||||||
|
#else
|
||||||
this.blockState.getBlock() instanceof RotatedPillarBlock
|
this.blockState.getBlock() instanceof RotatedPillarBlock
|
||||||
&& direction == Direction.UP
|
&& direction == Direction.UP
|
||||||
|
#endif
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -237,17 +337,29 @@ public class ClientBlockStateColorCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (quads == null || quads.isEmpty())
|
if (quads == null || quads.isEmpty())
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
quads = this.getUnculledQuads();
|
quads = this.getUnculledQuads();
|
||||||
}
|
}
|
||||||
|
catch (Exception ignore)
|
||||||
|
{
|
||||||
|
// failing to get quads can happen in the block is invalid
|
||||||
|
// (i.e. AIR is somehow passed in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (quads != null
|
if (quads != null
|
||||||
&& !quads.isEmpty()
|
&& !quads.isEmpty()
|
||||||
&& quads.get(0) != null)
|
&& quads.get(0) != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
BakedQuad firstQuad = quads.get(0);
|
BakedQuad firstQuad = quads.get(0);
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_11
|
#if MC_VER <= MC_1_12_2
|
||||||
|
this.needPostTinting = firstQuad.hasTintIndex();
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
this.needPostTinting = firstQuad.isTinted();
|
this.needPostTinting = firstQuad.isTinted();
|
||||||
#else
|
#else
|
||||||
this.needPostTinting = firstQuad.materialInfo().isTinted();
|
this.needPostTinting = firstQuad.materialInfo().isTinted();
|
||||||
@@ -261,7 +373,7 @@ public class ClientBlockStateColorCache
|
|||||||
this.tintIndex = firstQuad.materialInfo().tintIndex();
|
this.tintIndex = firstQuad.materialInfo().tintIndex();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1 && MC_VER > MC_1_12_2
|
||||||
this.baseColor = calculateColorFromTexture(
|
this.baseColor = calculateColorFromTexture(
|
||||||
firstQuad.sprite,
|
firstQuad.sprite,
|
||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
@@ -279,6 +391,20 @@ public class ClientBlockStateColorCache
|
|||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Shouldn't normally happen, but there was at least
|
||||||
|
// one report of MC's texture being un-loaded
|
||||||
|
// which prevented us from getting the texture.
|
||||||
|
// So we should have some basic backup logic.
|
||||||
|
|
||||||
|
LOGGER.warn("Failed to get texture color for block ["+this.blockStateWrapper.getSerialString()+"] due to: ["+e.getMessage()+"], falling back to particle color.");
|
||||||
|
|
||||||
|
this.needPostTinting = false;
|
||||||
|
this.tintIndex = 0;
|
||||||
|
this.baseColor = this.getParticleIconColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Backup method.
|
// Backup method.
|
||||||
@@ -298,6 +424,23 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
this.isColorResolved = true;
|
this.isColorResolved = true;
|
||||||
}
|
}
|
||||||
|
catch (Exception resolveError)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Failed to get color for block ["+this.blockStateWrapper.getSerialString()+"], error: ["+resolveError.getMessage()+"]. Attempting to use particle icon color...", resolveError);
|
||||||
|
|
||||||
|
this.needPostTinting = true;
|
||||||
|
this.tintIndex = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.baseColor = this.getParticleIconColor();
|
||||||
|
}
|
||||||
|
catch (Exception getParticleIconError)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Failed to get particle icon color for block ["+this.blockStateWrapper.getSerialString()+"], error: ["+getParticleIconError.getMessage()+"], block will render as hot pink.", getParticleIconError);
|
||||||
|
this.baseColor = ColorUtil.HOT_PINK;
|
||||||
|
}
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
RESOLVE_LOCK.unlock();
|
RESOLVE_LOCK.unlock();
|
||||||
@@ -305,22 +448,49 @@ public class ClientBlockStateColorCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<BakedQuad> getUnculledQuads() { return this.getQuadsForDirection(null); }
|
private List<BakedQuad> getUnculledQuads() throws Exception { return this.getQuadsForDirection(null); }
|
||||||
|
/**
|
||||||
|
* throws Exception is to document that rarely MC will throw errors if this method
|
||||||
|
* is called on the wrong block (even though in that case it should just return null).
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<BakedQuad> getQuadsForDirection(@Nullable Direction direction)
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private List<BakedQuad> getQuadsForDirection(@Nullable EnumFacing direction) throws Exception
|
||||||
|
#else
|
||||||
|
private List<BakedQuad> getQuadsForDirection(@Nullable Direction direction) throws Exception
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
IBlockState effectiveBlockState = this.blockState;
|
||||||
|
#else
|
||||||
BlockState effectiveBlockState = this.blockState;
|
BlockState effectiveBlockState = this.blockState;
|
||||||
|
#endif
|
||||||
|
|
||||||
// if this block is a slab, use it's double variant so we can get the top face,
|
// if this block is a slab, use it's double variant so we can get the top face,
|
||||||
// otherwise the color will use the side, which isn't as accurate
|
// otherwise the color will use the side, which isn't as accurate
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
if (this.blockState.getBlock() instanceof BlockSlab && !((BlockSlab) this.blockState.getBlock()).isDouble())
|
||||||
|
{
|
||||||
|
effectiveBlockState = this.blockState.withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (this.blockState.getBlock() instanceof SlabBlock)
|
if (this.blockState.getBlock() instanceof SlabBlock)
|
||||||
{
|
{
|
||||||
effectiveBlockState = this.blockState.setValue( SlabBlock.TYPE, SlabType.DOUBLE );
|
effectiveBlockState = this.blockState.setValue( SlabBlock.TYPE, SlabType.DOUBLE );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
List<BakedQuad> quads;
|
List<BakedQuad> quads;
|
||||||
|
|
||||||
#if MC_VER < MC_1_21_5
|
#if MC_VER <= MC_1_12_2
|
||||||
|
try {
|
||||||
|
quads = MC.getBlockRendererDispatcher().getModelForState(effectiveBlockState).getQuads(effectiveBlockState, direction, RANDOM.nextLong());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
quads = Collections.emptyList();
|
||||||
|
}
|
||||||
|
#elif MC_VER < MC_1_21_5
|
||||||
quads = MC.getModelManager().getBlockModelShaper().
|
quads = MC.getModelManager().getBlockModelShaper().
|
||||||
getBlockModel(effectiveBlockState).getQuads(effectiveBlockState, direction, RANDOM);
|
getBlockModel(effectiveBlockState).getQuads(effectiveBlockState, direction, RANDOM);
|
||||||
#elif MC_VER <= MC_1_21_11
|
#elif MC_VER <= MC_1_21_11
|
||||||
@@ -377,29 +547,29 @@ public class ClientBlockStateColorCache
|
|||||||
//_ OpenGL RGBA format Java Order: 0xAA BB GG RR
|
//_ OpenGL RGBA format Java Order: 0xAA BB GG RR
|
||||||
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
|
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
int b = (tempColor & 0x000000FF);
|
||||||
|
int g = (tempColor & 0x0000FF00) >>> 8;
|
||||||
|
int r = (tempColor & 0x00FF0000) >>> 16;
|
||||||
|
int a = (tempColor & 0xFF000000) >>> 24;
|
||||||
|
#else
|
||||||
int r = (tempColor & 0x000000FF);
|
int r = (tempColor & 0x000000FF);
|
||||||
int g = (tempColor & 0x0000FF00) >>> 8;
|
int g = (tempColor & 0x0000FF00) >>> 8;
|
||||||
int b = (tempColor & 0x00FF0000) >>> 16;
|
int b = (tempColor & 0x00FF0000) >>> 16;
|
||||||
int a = (tempColor & 0xFF000000) >>> 24;
|
int a = (tempColor & 0xFF000000) >>> 24;
|
||||||
|
#endif
|
||||||
|
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
if (colorMode == EColorMode.Leaves)
|
if (colorMode == EColorMode.Leaves)
|
||||||
{
|
{
|
||||||
//switch (//FIXME add config option)
|
if (a == 0)
|
||||||
// case BLACK:
|
{
|
||||||
// a = 255; //simulate black background of fast leaves
|
|
||||||
// break;
|
|
||||||
// case IGNORE:
|
|
||||||
if (a == 0) {
|
|
||||||
continue; //same long grass
|
continue; //same long grass
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a = 255; //just in case there are semi transparent pixels
|
a = 255; //just in case there are semi transparent pixels
|
||||||
}
|
}
|
||||||
// break;
|
|
||||||
// case TRANSPARENT:
|
|
||||||
// break; //do nothing, let it count towards transparency
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (a == 0 && colorMode != EColorMode.Glass)
|
else if (a == 0 && colorMode != EColorMode.Glass)
|
||||||
{
|
{
|
||||||
@@ -445,7 +615,9 @@ public class ClientBlockStateColorCache
|
|||||||
}
|
}
|
||||||
private static int getTextureWidth(TextureAtlasSprite texture)
|
private static int getTextureWidth(TextureAtlasSprite texture)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_19_4
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return texture.getIconWidth();
|
||||||
|
#elif MC_VER < MC_1_19_4
|
||||||
return texture.getWidth();
|
return texture.getWidth();
|
||||||
#else
|
#else
|
||||||
return texture.contents().width();
|
return texture.contents().width();
|
||||||
@@ -453,7 +625,9 @@ public class ClientBlockStateColorCache
|
|||||||
}
|
}
|
||||||
private static int getTextureHeight(TextureAtlasSprite texture)
|
private static int getTextureHeight(TextureAtlasSprite texture)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_19_4
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return texture.getIconHeight();
|
||||||
|
#elif MC_VER < MC_1_19_4
|
||||||
return texture.getHeight();
|
return texture.getHeight();
|
||||||
#else
|
#else
|
||||||
return texture.contents().height();
|
return texture.contents().height();
|
||||||
@@ -486,8 +660,19 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
private int getParticleIconColor()
|
private int getParticleIconColor()
|
||||||
{
|
{
|
||||||
|
// Air can be null which will cause issues below,
|
||||||
|
// just use a static color, it shouldn't be rendered anyway.
|
||||||
|
// This is just to capture a rare bug state where we attempt
|
||||||
|
// to get air's color.
|
||||||
|
if (BlockStateWrapper.isAir(this.blockState))
|
||||||
|
{
|
||||||
|
return ColorUtil.INVISIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
return calculateColorFromTexture(
|
return calculateColorFromTexture(
|
||||||
#if MC_VER <= MC_1_21_11
|
#if MC_VER <= MC_1_12_2
|
||||||
|
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(this.blockState),
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(this.blockState),
|
Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(this.blockState),
|
||||||
#else
|
#else
|
||||||
Minecraft.getInstance().getModelManager().getBlockStateModelSet().get(this.blockState).particleMaterial().sprite(),
|
Minecraft.getInstance().getModelManager().getBlockStateModelSet().get(this.blockState).particleMaterial().sprite(),
|
||||||
@@ -495,20 +680,24 @@ public class ClientBlockStateColorCache
|
|||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===============//
|
//===============//
|
||||||
// public getter //
|
// public getter //
|
||||||
//===============//
|
//===============//
|
||||||
|
//region
|
||||||
|
|
||||||
public int getColor(BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, DhBlockPos blockPos)
|
public int getColor(
|
||||||
|
BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, DhBlockPos blockPos,
|
||||||
|
boolean allowApiOverride)
|
||||||
{
|
{
|
||||||
// only get the tint if the block needs to be tinted
|
// only get the tint if the block needs to be tinted
|
||||||
if (!this.needPostTinting)
|
int tintColor = ClientBlockStateColorCache.INVALID_COLOR;
|
||||||
{
|
|
||||||
return this.baseColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (this.needPostTinting)
|
||||||
|
{
|
||||||
// don't try tinting blocks that don't support our method of tint getting
|
// don't try tinting blocks that don't support our method of tint getting
|
||||||
if (BROKEN_BLOCK_STATES.contains(this.blockState))
|
if (BROKEN_BLOCK_STATES.contains(this.blockState))
|
||||||
{
|
{
|
||||||
@@ -517,9 +706,42 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
|
|
||||||
// attempt to get the tint
|
// attempt to get the tint
|
||||||
int tintColor = -1;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
// 1.12.2 doesn't have BlockAndTintGetter -> get tintColor from biome
|
||||||
|
WorldClient world = (WorldClient) this.clientLevelWrapper.getWrappedMcObject();
|
||||||
|
BlockPos mcPos = new BlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||||
|
|
||||||
|
Block block = this.blockState.getBlock();
|
||||||
|
if (block instanceof BlockGrass
|
||||||
|
|| block instanceof BlockBush)
|
||||||
|
{
|
||||||
|
tintColor = biomeWrapper.biome.getGrassColorAtPos(mcPos);
|
||||||
|
}
|
||||||
|
else if (block instanceof BlockLeaves)
|
||||||
|
{
|
||||||
|
tintColor = biomeWrapper.biome.getFoliageColorAtPos(mcPos);
|
||||||
|
}
|
||||||
|
else if (block instanceof BlockLiquid) // We don't want lava to fall into the else block
|
||||||
|
{
|
||||||
|
if(block == Blocks.WATER
|
||||||
|
|| block == Blocks.FLOWING_WATER)
|
||||||
|
{
|
||||||
|
tintColor = biomeWrapper.biome.getWaterColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
|
||||||
|
tintColor = blockColors.colorMultiplier(blockState, world, mcPos, this.tintIndex);
|
||||||
|
|
||||||
|
if (tintColor == ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
|
{
|
||||||
|
tintColor = blockColors.getColor(blockState, world, mcPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
// try to use the fast tint getter logic first
|
// try to use the fast tint getter logic first
|
||||||
if (!BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
|
if (!BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
|
||||||
{
|
{
|
||||||
@@ -530,7 +752,7 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
// try using DH's cached tint values first if possible
|
// try using DH's cached tint values first if possible
|
||||||
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
|
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
|
||||||
if (tintColor == AbstractDhTintGetter.INVALID_COLOR)
|
if (tintColor == ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
{
|
{
|
||||||
// one or more tint values weren't calculated,
|
// one or more tint values weren't calculated,
|
||||||
// we need MC's color resolver
|
// we need MC's color resolver
|
||||||
@@ -538,26 +760,54 @@ public class ClientBlockStateColorCache
|
|||||||
tintColor = Minecraft.getInstance()
|
tintColor = Minecraft.getInstance()
|
||||||
.getBlockColors()
|
.getBlockColors()
|
||||||
.getColor(this.blockState,
|
.getColor(this.blockState,
|
||||||
tintOverride,
|
tintOverride, // tintOverride will save the result of this query to speed up future queries
|
||||||
McObjectConverter.Convert(blockPos),
|
McObjectConverter.Convert(blockPos),
|
||||||
this.tintIndex);
|
this.tintIndex);
|
||||||
#else
|
#else
|
||||||
tintColor = Minecraft.getInstance()
|
BlockTintSource tintSource = Minecraft.getInstance()
|
||||||
.getBlockColors()
|
.getBlockColors()
|
||||||
.getTintSources(this.blockState)
|
.getTintSource(this.blockState, this.tintIndex);
|
||||||
.get(this.tintIndex)
|
// a tint source may be null for blocks that don't actually need tinting
|
||||||
.color(this.blockState);
|
// in that case the base color should be sufficient
|
||||||
#endif
|
// Example: cherry blossom leaves
|
||||||
}
|
if (tintSource != null)
|
||||||
}
|
|
||||||
catch (UnsupportedOperationException e)
|
|
||||||
{
|
{
|
||||||
// this exception generally occurs if the tint requires other blocks besides itself
|
BlockPos mcPos = McObjectConverter.Convert(blockPos);
|
||||||
LOGGER.debug("Unable to use ["+ TintWithoutLevelOverrider.class.getSimpleName()+"] to get the block tint for block: [" + this.blockState + "] and biome: [" + biomeWrapper + "] at pos: " + blockPos + ". Error: [" + e.getMessage() + "]. Attempting to use backup method...", e);
|
tintColor = tintSource.colorInWorld(this.blockState, tintOverride, mcPos);
|
||||||
BLOCK_STATES_THAT_NEED_LEVEL.add(this.blockState);
|
if (tintColor == ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
|
{
|
||||||
|
tintColor = tintSource.colorAsTerrainParticle(this.blockState, tintOverride, mcPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save this color to speed up future queries
|
||||||
|
TintWithoutLevelOverrider.setStaticColor(this.blockStateWrapper, biomeWrapper, tintColor);
|
||||||
|
// try to get the blended color with this new information
|
||||||
|
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
// this exception generally occurs if the tint requires other blocks besides itself
|
||||||
|
LOGGER.debug("Unable to use ["+ TintWithoutLevelOverrider.class.getSimpleName()+"] to get the block tint for block: [" + this.blockState + "] and biome: [" + biomeWrapper + "] at pos: " + blockPos + ". Error: [" + e.getMessage() + "]. Attempting to use backup method...", e);
|
||||||
|
BLOCK_STATES_THAT_NEED_LEVEL.add(this.blockState);
|
||||||
|
#else
|
||||||
|
// only display the error once per block/biome type to reduce log spam
|
||||||
|
if (!BROKEN_BLOCK_STATES.contains(this.blockState))
|
||||||
|
{
|
||||||
|
LOGGER.warn("Failed to get block color for block: [" + this.blockState + "] and biome: [" + biomeWrapper + "] at pos: " + blockPos + ". Error: [" + e.getMessage() + "]. Note: future errors for this block/biome will be ignored.", e);
|
||||||
|
BROKEN_BLOCK_STATES.add(this.blockState);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// level-specific logic is only needed for MC 1.21.11 and older
|
||||||
|
#if MC_VER <= MC_1_21_11 && MC_VER > MC_1_12_2
|
||||||
// use the level logic only if requested
|
// use the level logic only if requested
|
||||||
if (BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
|
if (BLOCK_STATES_THAT_NEED_LEVEL.contains(this.blockState))
|
||||||
{
|
{
|
||||||
@@ -568,53 +818,90 @@ public class ClientBlockStateColorCache
|
|||||||
tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper);
|
tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper);
|
||||||
|
|
||||||
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
|
tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos));
|
||||||
if (tintColor == AbstractDhTintGetter.INVALID_COLOR)
|
if (tintColor == ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
{
|
{
|
||||||
#if MC_VER <= MC_1_21_11
|
|
||||||
tintColor = Minecraft.getInstance()
|
tintColor = Minecraft.getInstance()
|
||||||
.getBlockColors()
|
.getBlockColors()
|
||||||
.getColor(this.blockState,
|
.getColor(this.blockState,
|
||||||
tintOverride,
|
tintOverride,
|
||||||
McObjectConverter.Convert(blockPos),
|
McObjectConverter.Convert(blockPos),
|
||||||
this.tintIndex);
|
this.tintIndex);
|
||||||
#else
|
}
|
||||||
tintColor = Minecraft.getInstance()
|
}
|
||||||
.getBlockColors()
|
|
||||||
.getTintSources(this.blockState)
|
|
||||||
.get(this.tintIndex)
|
|
||||||
.color(this.blockState);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// only display the error once per block/biome type to reduce log spam
|
// only display the error once per block/biome type to reduce log spam
|
||||||
if (!BROKEN_BLOCK_STATES.contains(this.blockState))
|
if (!BROKEN_BLOCK_STATES.contains(this.blockState))
|
||||||
{
|
{
|
||||||
LOGGER.warn("Failed to get block color for block: [" + this.blockState + "] and biome: [" + biomeWrapper + "] at pos: " + blockPos + ". Error: ["+e.getMessage() + "]. Note: future errors for this block/biome will be ignored.", e);
|
LOGGER.warn("Failed to get block color for block: [" + this.blockState + "] and biome: [" + biomeWrapper + "] at pos: " + blockPos + ". Error: [" + e.getMessage() + "]. Note: future errors for this block/biome will be ignored.", e);
|
||||||
BROKEN_BLOCK_STATES.add(this.blockState);
|
BROKEN_BLOCK_STATES.add(this.blockState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int returnColor;
|
||||||
if (tintColor != -1)
|
if (tintColor != ClientBlockStateColorCache.INVALID_COLOR)
|
||||||
{
|
{
|
||||||
return ColorUtil.multiplyARGBwithRGB(this.baseColor, tintColor);
|
returnColor = ColorUtil.multiplyARGBwithRGB(this.baseColor, tintColor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// unable to get the tinted color, use the base color instead
|
// unable to get the tinted color, use the base color instead
|
||||||
return this.baseColor;
|
returnColor = this.baseColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// only fire the API event if allowed
|
||||||
|
// (done to prevent infinite loops if called during by another color resolution event)
|
||||||
|
if (allowApiOverride
|
||||||
|
// if the API event is requested
|
||||||
|
// (this is done to reduce GC pressure and speed up color getting)
|
||||||
|
&& this.blockStateWrapper.allowApiColorOverride())
|
||||||
|
{
|
||||||
|
DhApiBlockColorOverrideEvent.EventParam eventParam = ColorOverrideEventParamGetter.get();
|
||||||
|
eventParam.update(
|
||||||
|
this.clientLevelWrapper, fullDataSource,
|
||||||
|
this.blockStateWrapper, biomeWrapper, returnColor,
|
||||||
|
blockPos.getX(), blockPos.getY(), blockPos.getZ()
|
||||||
|
);
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBlockColorOverrideEvent.class, eventParam);
|
||||||
|
|
||||||
|
// let the API user override this color
|
||||||
|
returnColor = eventParam.getColorAsInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return returnColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// cleanup //
|
||||||
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public static void clearCachedTints()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
#else
|
||||||
|
AbstractDhTintGetter.clear();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
// helper classes //
|
// helper classes //
|
||||||
//================//
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
private enum EColorMode
|
private enum EColorMode
|
||||||
{
|
{
|
||||||
@@ -626,14 +913,54 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
static EColorMode getColorMode(Block block)
|
static EColorMode getColorMode(Block block)
|
||||||
{
|
{
|
||||||
if (block instanceof LeavesBlock)
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// leaves //
|
||||||
|
//========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
boolean isLeavesBlock;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
isLeavesBlock = block instanceof BlockLeaves;
|
||||||
|
#else
|
||||||
|
isLeavesBlock = block instanceof LeavesBlock;
|
||||||
|
#endif
|
||||||
|
if (isLeavesBlock)
|
||||||
{
|
{
|
||||||
return Leaves;
|
return Leaves;
|
||||||
}
|
}
|
||||||
if (block instanceof FlowerBlock)
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// flower //
|
||||||
|
//========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
boolean isFlowerBlock;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
isFlowerBlock = block instanceof BlockFlower;
|
||||||
|
#else
|
||||||
|
isFlowerBlock = block instanceof FlowerBlock;
|
||||||
|
#endif
|
||||||
|
if (isFlowerBlock)
|
||||||
{
|
{
|
||||||
return Flower;
|
return Flower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// misc/simple //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
if (block.toString().contains("glass"))
|
if (block.toString().contains("glass"))
|
||||||
{
|
{
|
||||||
return Glass;
|
return Glass;
|
||||||
@@ -642,10 +969,17 @@ public class ClientBlockStateColorCache
|
|||||||
{
|
{
|
||||||
return Chisel;
|
return Chisel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Default;
|
return Default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -25,7 +25,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1
|
||||||
#elif MC_VER < MC_1_21_3
|
#elif MC_VER < MC_1_21_3
|
||||||
#else
|
#else
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -38,7 +38,10 @@ public class TextureAtlasSpriteWrapper
|
|||||||
{
|
{
|
||||||
public static int getPixelRGBA(TextureAtlasSprite sprite, int frameIndex, int x, int y)
|
public static int getPixelRGBA(TextureAtlasSprite sprite, int frameIndex, int x, int y)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
int[][] frameData = sprite.getFrameTextureData(frameIndex);
|
||||||
|
return frameData[0][y * sprite.getIconWidth() + x];
|
||||||
|
#elif MC_VER < MC_1_17_1
|
||||||
return sprite.mainImage[0].getPixelRGBA(
|
return sprite.mainImage[0].getPixelRGBA(
|
||||||
x + sprite.framesX[frameIndex] * sprite.getWidth(),
|
x + sprite.framesX[frameIndex] * sprite.getWidth(),
|
||||||
y + sprite.framesY[frameIndex] * sprite.getHeight());
|
y + sprite.framesY[frameIndex] * sprite.getHeight());
|
||||||
|
|||||||
+2
-1
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -189,3 +189,4 @@ public class TintGetterOverride extends AbstractDhTintGetter
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+2
-1
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
@@ -109,3 +109,4 @@ public class TintWithoutLevelOverrider extends AbstractDhTintGetter
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+143
-21
@@ -31,12 +31,19 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.ChunkLightStorage
|
|||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IMutableBlockPosWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IMutableBlockPosWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
#else
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||||
import net.minecraft.world.level.levelgen.Heightmap;
|
import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
|
#endif
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
|
||||||
@@ -67,9 +74,10 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
|
|||||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_20_4
|
#if MC_VER <= MC_1_12_2
|
||||||
|
#elif MC_VER <= MC_1_20_4
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
#else
|
#elif MC_VER > MC_1_12_2
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -86,8 +94,12 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
private static boolean heightmapThreadWarningLogged = false;
|
private static boolean heightmapThreadWarningLogged = false;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private final Chunk chunk;
|
||||||
|
#else
|
||||||
private final ChunkAccess chunk;
|
private final ChunkAccess chunk;
|
||||||
|
#endif
|
||||||
|
|
||||||
private final DhChunkPos chunkPos;
|
private final DhChunkPos chunkPos;
|
||||||
private final ILevelWrapper wrappedLevel;
|
private final ILevelWrapper wrappedLevel;
|
||||||
|
|
||||||
@@ -112,13 +124,17 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
//region
|
||||||
/**
|
/**
|
||||||
* Note: this constructor should be very
|
* Note: this constructor should be very
|
||||||
* fast since it will be called frequently on the MC
|
* fast since it will be called frequently on the MC
|
||||||
* server thread and a slow method will cause server lag.
|
* server thread and a slow method will cause server lag.
|
||||||
*/
|
*/
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public ChunkWrapper(Chunk chunk, ILevelWrapper wrappedLevel)
|
||||||
|
#else
|
||||||
public ChunkWrapper(ChunkAccess chunk, ILevelWrapper wrappedLevel)
|
public ChunkWrapper(ChunkAccess chunk, ILevelWrapper wrappedLevel)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.wrappedLevel = wrappedLevel;
|
this.wrappedLevel = wrappedLevel;
|
||||||
@@ -133,15 +149,22 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
@Override
|
@Override
|
||||||
public ChunkWrapper copy() { return new ChunkWrapper(this.chunk, this.wrappedLevel); }
|
public ChunkWrapper copy() { return new ChunkWrapper(this.chunk, this.wrappedLevel); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=========//
|
//=========//
|
||||||
// getters //
|
// getters //
|
||||||
//=========//
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHeight() { return getHeight(this.chunk); }
|
public int getHeight() { return getHeight(this.chunk); }
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static int getHeight(Chunk chunk)
|
||||||
|
#else
|
||||||
public static int getHeight(ChunkAccess chunk)
|
public static int getHeight(ChunkAccess chunk)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1
|
||||||
return 255;
|
return 255;
|
||||||
@@ -152,7 +175,11 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInclusiveMinBuildHeight() { return getInclusiveMinBuildHeight(this.chunk); }
|
public int getInclusiveMinBuildHeight() { return getInclusiveMinBuildHeight(this.chunk); }
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static int getInclusiveMinBuildHeight(Chunk chunk)
|
||||||
|
#else
|
||||||
public static int getInclusiveMinBuildHeight(ChunkAccess chunk)
|
public static int getInclusiveMinBuildHeight(ChunkAccess chunk)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1
|
||||||
return 0;
|
return 0;
|
||||||
@@ -165,9 +192,15 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getExclusiveMaxBuildHeight() { return getExclusiveMaxBuildHeight(this.chunk); }
|
public int getExclusiveMaxBuildHeight() { return getExclusiveMaxBuildHeight(this.chunk); }
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public static int getExclusiveMaxBuildHeight(Chunk chunk)
|
||||||
|
#else
|
||||||
public static int getExclusiveMaxBuildHeight(ChunkAccess chunk)
|
public static int getExclusiveMaxBuildHeight(ChunkAccess chunk)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_21_3
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return 256;
|
||||||
|
#elif MC_VER < MC_1_21_3
|
||||||
return chunk.getMaxBuildHeight();
|
return chunk.getMaxBuildHeight();
|
||||||
#else
|
#else
|
||||||
// +1 since Minecraft made the max value inclusive
|
// +1 since Minecraft made the max value inclusive
|
||||||
@@ -188,7 +221,11 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
this.minNonEmptyHeight = this.getInclusiveMinBuildHeight();
|
this.minNonEmptyHeight = this.getInclusiveMinBuildHeight();
|
||||||
|
|
||||||
// determine the lowest empty section (bottom up)
|
// determine the lowest empty section (bottom up)
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
ExtendedBlockStorage[] sections = this.chunk.getBlockStorageArray();
|
||||||
|
#else
|
||||||
LevelChunkSection[] sections = this.chunk.getSections();
|
LevelChunkSection[] sections = this.chunk.getSections();
|
||||||
|
#endif
|
||||||
for (int index = 0; index < sections.length; index++)
|
for (int index = 0; index < sections.length; index++)
|
||||||
{
|
{
|
||||||
if (sections[index] == null)
|
if (sections[index] == null)
|
||||||
@@ -220,7 +257,11 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
this.maxNonEmptyHeight = this.getExclusiveMaxBuildHeight();
|
this.maxNonEmptyHeight = this.getExclusiveMaxBuildHeight();
|
||||||
|
|
||||||
// determine the highest empty section (top down)
|
// determine the highest empty section (top down)
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
ExtendedBlockStorage[] sections = this.chunk.getBlockStorageArray();
|
||||||
|
#else
|
||||||
LevelChunkSection[] sections = this.chunk.getSections();
|
LevelChunkSection[] sections = this.chunk.getSections();
|
||||||
|
#endif
|
||||||
for (int index = sections.length-1; index >= 0; index--)
|
for (int index = sections.length-1; index >= 0; index--)
|
||||||
{
|
{
|
||||||
// update at each position to fix using the max height if the chunk is empty
|
// update at each position to fix using the max height if the chunk is empty
|
||||||
@@ -240,11 +281,13 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
return this.maxNonEmptyHeight;
|
return this.maxNonEmptyHeight;
|
||||||
}
|
}
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
private static boolean isChunkSectionEmpty(ExtendedBlockStorage section)
|
||||||
|
#else
|
||||||
private static boolean isChunkSectionEmpty(LevelChunkSection section)
|
private static boolean isChunkSectionEmpty(LevelChunkSection section)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER == MC_1_16_5
|
#if MC_VER <= MC_1_17_1
|
||||||
return section.isEmpty();
|
|
||||||
#elif MC_VER == MC_1_17_1
|
|
||||||
return section.isEmpty();
|
return section.isEmpty();
|
||||||
#else
|
#else
|
||||||
return section.hasOnlyAir();
|
return section.hasOnlyAir();
|
||||||
@@ -322,7 +365,11 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
// will be null if we want to use MC heightmaps
|
// will be null if we want to use MC heightmaps
|
||||||
if (this.solidHeightMap == null)
|
if (this.solidHeightMap == null)
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getHeightValue(xRel, zRel);
|
||||||
|
#else
|
||||||
return this.chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE).getFirstAvailable(xRel, zRel);
|
return this.chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE).getFirstAvailable(xRel, zRel);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -337,7 +384,11 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
if (this.lightBlockingHeightMap == null)
|
if (this.lightBlockingHeightMap == null)
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getHeightValue(xRel, zRel);
|
||||||
|
#else
|
||||||
return this.chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.MOTION_BLOCKING).getFirstAvailable(xRel, zRel);
|
return this.chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.MOTION_BLOCKING).getFirstAvailable(xRel, zRel);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -349,7 +400,14 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
@Override
|
@Override
|
||||||
public IBiomeWrapper getBiome(int relX, int relY, int relZ)
|
public IBiomeWrapper getBiome(int relX, int relY, int relZ)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
BlockPos.MutableBlockPos blockPos = MUTABLE_BLOCK_POS_REF.get();
|
||||||
|
blockPos.setPos(relX, relY, relZ);
|
||||||
|
|
||||||
|
World world = (World) this.wrappedLevel.getWrappedMcObject();
|
||||||
|
|
||||||
|
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiome(blockPos, world.getBiomeProvider()), wrappedLevel);
|
||||||
|
#elif MC_VER < MC_1_17_1
|
||||||
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
|
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
|
||||||
relX >> 2, relY >> 2, relZ >> 2),
|
relX >> 2, relY >> 2, relZ >> 2),
|
||||||
this.wrappedLevel);
|
this.wrappedLevel);
|
||||||
@@ -357,10 +415,6 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
|
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
|
||||||
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)),
|
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)),
|
||||||
this.wrappedLevel);
|
this.wrappedLevel);
|
||||||
#elif MC_VER < MC_1_18_2
|
|
||||||
return BiomeWrapper.getBiomeWrapper(this.chunk.getNoiseBiome(
|
|
||||||
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)),
|
|
||||||
this.wrappedLevel);
|
|
||||||
#else
|
#else
|
||||||
//Now returns a Holder<Biome> instead of Biome
|
//Now returns a Holder<Biome> instead of Biome
|
||||||
return BiomeWrapper.getBiomeWrapper(this.chunk.getNoiseBiome(
|
return BiomeWrapper.getBiomeWrapper(this.chunk.getNoiseBiome(
|
||||||
@@ -376,9 +430,13 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
|
|
||||||
BlockPos.MutableBlockPos blockPos = MUTABLE_BLOCK_POS_REF.get();
|
BlockPos.MutableBlockPos blockPos = MUTABLE_BLOCK_POS_REF.get();
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
blockPos.setPos(relX, relY, relZ);
|
||||||
|
#else
|
||||||
blockPos.setX(relX);
|
blockPos.setX(relX);
|
||||||
blockPos.setY(relY);
|
blockPos.setY(relY);
|
||||||
blockPos.setZ(relZ);
|
blockPos.setZ(relZ);
|
||||||
|
#endif
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -401,9 +459,13 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ);
|
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ);
|
||||||
|
|
||||||
BlockPos.MutableBlockPos pos = (BlockPos.MutableBlockPos)mcBlockPos.getWrappedMcObject();
|
BlockPos.MutableBlockPos pos = (BlockPos.MutableBlockPos)mcBlockPos.getWrappedMcObject();
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
pos.setPos(relX, relY, relZ);
|
||||||
|
#else
|
||||||
pos.setX(relX);
|
pos.setX(relX);
|
||||||
pos.setY(relY);
|
pos.setY(relY);
|
||||||
pos.setZ(relZ);
|
pos.setZ(relZ);
|
||||||
|
#endif
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -513,8 +575,14 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
@Override
|
@Override
|
||||||
public DhChunkPos getChunkPos() { return this.chunkPos; }
|
public DhChunkPos getChunkPos() { return this.chunkPos; }
|
||||||
|
|
||||||
public ChunkAccess getChunk() { return this.chunk; }
|
#if MC_VER <= MC_1_12_2
|
||||||
|
public Chunk getChunk()
|
||||||
|
#else
|
||||||
|
public ChunkAccess getChunk()
|
||||||
|
#endif
|
||||||
|
{ return this.chunk; }
|
||||||
|
|
||||||
|
#if MC_VER > MC_1_12_2
|
||||||
public void trySetStatus(ChunkStatus status) { trySetStatus(this.getChunk(), status); }
|
public void trySetStatus(ChunkStatus status) { trySetStatus(this.getChunk(), status); }
|
||||||
/** does nothing if the chunk object doesn't support setting it's status */
|
/** does nothing if the chunk object doesn't support setting it's status */
|
||||||
public static void trySetStatus(ChunkAccess chunk, ChunkStatus status)
|
public static void trySetStatus(ChunkAccess chunk, ChunkStatus status)
|
||||||
@@ -538,21 +606,53 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
return chunk.getPersistedStatus();
|
return chunk.getPersistedStatus();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxBlockX() { return this.chunk.getPos().getMaxBlockX(); }
|
public int getMaxBlockX()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getPos().getXEnd();
|
||||||
|
#else
|
||||||
|
return this.chunk.getPos().getMaxBlockX();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getMaxBlockZ() { return this.chunk.getPos().getMaxBlockZ(); }
|
public int getMaxBlockZ()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getPos().getZEnd();
|
||||||
|
#else
|
||||||
|
return this.chunk.getPos().getMaxBlockZ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getMinBlockX() { return this.chunk.getPos().getMinBlockX(); }
|
public int getMinBlockX()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getPos().getXStart();
|
||||||
|
#else
|
||||||
|
return this.chunk.getPos().getMinBlockX();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getMinBlockZ() { return this.chunk.getPos().getMinBlockZ(); }
|
public int getMinBlockZ()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_12_2
|
||||||
|
return this.chunk.getPos().getZStart();
|
||||||
|
#else
|
||||||
|
return this.chunk.getPos().getMinBlockZ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==========//
|
//==========//
|
||||||
// lighting //
|
// lighting //
|
||||||
//==========//
|
//==========//
|
||||||
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setIsDhSkyLightCorrect(boolean isDhLightCorrect) { this.isDhSkyLightCorrect = isDhLightCorrect; }
|
public void setIsDhSkyLightCorrect(boolean isDhLightCorrect) { this.isDhSkyLightCorrect = isDhLightCorrect; }
|
||||||
@@ -629,8 +729,23 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
{
|
{
|
||||||
this.blockLightPosList = new ArrayList<>();
|
this.blockLightPosList = new ArrayList<>();
|
||||||
|
|
||||||
|
//1.12.2 doesn't store lights we must bruteforce it
|
||||||
#if MC_VER < MC_1_20_1
|
#if MC_VER <= MC_1_12_2
|
||||||
|
for (int x = 0; x < 16; x++)
|
||||||
|
{
|
||||||
|
for (int z = 0; z < 16; z++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 256; y++)
|
||||||
|
{
|
||||||
|
IBlockState blockState = this.chunk.getBlockState(x, y, z);
|
||||||
|
if (blockState.getLightValue() > 0)
|
||||||
|
{
|
||||||
|
this.blockLightPosList.add(new DhBlockPos(this.chunk.getPos().getXStart() + x, y, this.chunk.getPos().getZStart() + z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif MC_VER < MC_1_20_1
|
||||||
this.chunk.getLights().forEach((blockPos) ->
|
this.chunk.getLights().forEach((blockPos) ->
|
||||||
{
|
{
|
||||||
this.blockLightPosList.add(new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
|
this.blockLightPosList.add(new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
|
||||||
@@ -652,11 +767,14 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
return this.blockLightPosList;
|
return this.blockLightPosList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//================//
|
//================//
|
||||||
// base overrides //
|
// base overrides //
|
||||||
//================//
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return this.chunk.getClass().getSimpleName() + this.chunk.getPos(); }
|
public String toString() { return this.chunk.getClass().getSimpleName() + this.chunk.getPos(); }
|
||||||
@@ -672,4 +790,8 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
// return this.blockBiomeHashCode;
|
// return this.blockBiomeHashCode;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-1121
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user