Compare commits
225 Commits
blazeRender
...
Vulkan
| Author | SHA1 | Date | |
|---|---|---|---|
| 64d8f7ee2d | |||
| d8b3aee9dc | |||
| fce94fa4bf | |||
| 254d671629 | |||
| e66e7e627a | |||
| 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 | |||
| 3f16d67746 | |||
| 3a34dc8626 | |||
| c1766fb439 | |||
| cfd47adfda | |||
| 9b9e6b9179 | |||
| 49d1587a71 | |||
| b0f5e55744 | |||
| d9191534d5 | |||
| ff459621e6 | |||
| 64fb45d74d | |||
| 1590abb489 | |||
| a3c9b0654a | |||
| a9388321d9 | |||
| 877c824e58 | |||
| 80f30dfd74 | |||
| 9a087025fe | |||
| 29381bce7b | |||
| 21dc0f13c9 | |||
| 7794958804 | |||
| c245ed6598 | |||
| 6270b03005 | |||
| 2674b945bb | |||
| 0647bdbab3 | |||
| 528a12ac83 | |||
| 4ac9de05df | |||
| a0f1b72089 | |||
| 85c07b11c6 | |||
| 215e1d46d0 | |||
| 5f228f0567 | |||
| f597958e1e | |||
| 95921358f8 | |||
| a22d494797 | |||
| 666e917b8f | |||
| a26a97e7fb | |||
| cdbb9de933 | |||
| feccf12580 | |||
| d371d93c9d | |||
| 5f3e8d76b2 | |||
| a7bd72e35b | |||
| 0a5326d2b1 | |||
| dad2014c46 | |||
| 70dd0bda72 | |||
| 8213901229 | |||
| 668ba491e8 | |||
| d85589c41a | |||
| 7f5316108d | |||
| 9c1abbac2b | |||
| 1bb957a866 | |||
| 6ccba17baf | |||
| e4c5d8adab | |||
| 823f204424 | |||
| 505e9a77fd | |||
| 4c580fe4ff | |||
| efc1865f87 | |||
| ae08ad56c4 | |||
| 633544e0b0 | |||
| 2432028aa0 | |||
| eb6aa13815 | |||
| 55155103ec | |||
| 667dd85aef | |||
| 9bd946a41c | |||
| 241baef7af | |||
| b5890a4783 | |||
| e3b67ef500 | |||
| 5905fe3df2 | |||
| 9d35a70437 | |||
| f121860563 | |||
| 9715db3ac6 | |||
| 03a29fbacb | |||
| e91888934b | |||
| 030f814398 | |||
| 90ef8fd64d | |||
| 0ffefaa8c1 | |||
| 99703d65df | |||
| bd2f5a7836 | |||
| a44556f86a | |||
| 4597b7f647 | |||
| 0de80cfaa7 | |||
| 034aaddca3 | |||
| a1d493f25d | |||
| 4b5a4dda79 | |||
| ce528f3fd5 | |||
| e4c769e95e | |||
| 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__/
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
# use Eclipse's JDK
|
# use Eclipse's JDK
|
||||||
# The ci should always use a unix(-like) OS to work
|
# The ci should always use a unix(-like) OS to work
|
||||||
image: eclipse-temurin:21
|
image: eclipse-temurin:25
|
||||||
|
|
||||||
# all stages need to be defined here
|
# all stages need to be defined here
|
||||||
stages:
|
stages:
|
||||||
@@ -35,6 +35,7 @@ build:
|
|||||||
parallel:
|
parallel:
|
||||||
matrix:
|
matrix:
|
||||||
- MC_VER: [
|
- MC_VER: [
|
||||||
|
"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",
|
||||||
@@ -46,8 +47,7 @@ build:
|
|||||||
# this both runs the unit tests and assembles the code
|
# this both runs the unit tests and assembles the code
|
||||||
- ./gradlew clean -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
- ./gradlew clean -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
||||||
- ./gradlew build -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
- ./gradlew build -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
||||||
- ./gradlew mergeJars -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
- cp ./fabric/build/libs/* ./forge/build/libs/* ./neoforge/build/libs/* ./build/forgix/* . || true
|
||||||
- cp ./fabric/build/libs/* ./forge/build/libs/* ./neoforge/build/libs/* ./build/merged/* . || true
|
|
||||||
artifacts:
|
artifacts:
|
||||||
name: "NightlyBuild_${MC_VER}-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
name: "NightlyBuild_${MC_VER}-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# See mailmap docs: https://git-scm.com/docs/gitmailmap
|
||||||
|
# Test with git shortlog --summary --email
|
||||||
|
# Keep sorted for easier editing and smaller diffs
|
||||||
|
|
||||||
|
Ada Aster <an.ada.poirier@gmail.com>
|
||||||
|
CodeF53 <fseusb@gmail.com> <37855219+CodeF53@users.noreply.github.com>
|
||||||
|
coolGi <me@coolgi.dev> <sasanaps@hotmail.com>
|
||||||
|
James Seibel <jeseibel@gondtc.com> <jseibel@vertsys.com>
|
||||||
|
Morippi <leoleo97@libero.it> <leoloe97@libero.it>
|
||||||
|
Morippi <leoleo97@libero.it> <Morippi>
|
||||||
|
Ran <43445785+Ran-Mewo@users.noreply.github.com> <10044908-_Ran@users.noreply.gitlab.com>
|
||||||
|
Ran <43445785+Ran-Mewo@users.noreply.github.com> <43445785+Ran-Mewo@users.noreply.github.com>
|
||||||
|
Ran <43445785+Ran-Mewo@users.noreply.github.com> <43445785+RanCraftPlayz@users.noreply.github.com>
|
||||||
|
TomTheFurry <tomlee92502@yahoo.com>
|
||||||
|
TomTheFurry <tomlee92502@yahoo.com> <46843632+TomTheFurry@users.noreply.github.com>
|
||||||
|
Yeshi <yeshi@newengine.org>
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
FROM eclipse-temurin:17-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] =========="
|
|
||||||
@@ -14,89 +14,11 @@ Below is a video demonstrating the system:
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## 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
|
|
||||||
|
|
||||||
<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 +26,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 +44,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 +95,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>.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+19
-674
@@ -1,684 +1,29 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
|
|
||||||
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
|
|
||||||
import org.apache.tools.zip.ZipEntry
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
|
||||||
import org.apache.tools.zip.ZipOutputStream
|
|
||||||
|
|
||||||
import java.util.function.Function
|
|
||||||
import java.util.function.Predicate
|
|
||||||
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "java"
|
id 'root'
|
||||||
|
id 'io.github.pacifistmc.forgix' version '2.+'
|
||||||
// Plugin to put dependencies inside our final jar
|
|
||||||
id "com.github.johnrengelman.shadow" version '8.1.1' apply false
|
|
||||||
|
|
||||||
// Plugin to create merged jars
|
|
||||||
id "io.github.pacifistmc.forgix" version "1.3.4"
|
|
||||||
|
|
||||||
// Manifold preprocessor
|
|
||||||
id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha"
|
|
||||||
|
|
||||||
// Architectury is used here only as a replacement for forge's own loom
|
|
||||||
id "dev.architectury.loom" version "1.13-SNAPSHOT" apply false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false) // TODO vulkan don't run if there is only one mod loader
|
||||||
|
forgix {
|
||||||
|
autoRun = true
|
||||||
|
|
||||||
/**
|
// add the mod loaders to the end of the jar
|
||||||
* Creates the list of preprocessors to use.
|
// put together in the format: "a", "a-b", "a-b-c"
|
||||||
*
|
String modLoaders = "";
|
||||||
* @param mcVers array of all MC versions
|
((String) gradle.builds_for)
|
||||||
* @param mcIndex array index of the currently active MC version
|
.split(",")
|
||||||
*/
|
.each
|
||||||
def writeBuildGradlePredefine(List<String> mcVers, int mcIndex)
|
{ loader ->
|
||||||
{
|
def loaderName = loader.trim()
|
||||||
// Build the list of preprocessors to use
|
if (modLoaders != "")
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n");
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < mcVers.size(); i++)
|
|
||||||
{
|
{
|
||||||
String verStr = mcVers[i].replace(".", "_");
|
modLoaders += "-";
|
||||||
sb.append("MC_" + verStr + "=" + i.toString() + "\n");
|
|
||||||
|
|
||||||
if (mcIndex == i)
|
|
||||||
{
|
|
||||||
sb.append("MC_VER=" + i.toString() + "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modLoaders += loaderName;
|
||||||
// Check if this is a development build
|
|
||||||
if (mod_version.toLowerCase().contains("dev"))
|
|
||||||
{
|
|
||||||
// WARNING: only use this for logging, we don't want to have confusion
|
|
||||||
// when a method doesn't work correctly in the release build.
|
|
||||||
sb.append("DEV_BUILD=\n");
|
|
||||||
}
|
}
|
||||||
|
// merged jars are named in the format:
|
||||||
new File(projectDir, "build.properties").text = sb.toString()
|
// "DistantHorizons-3.0.1-b-dev-26.1-fabric-neoforge.jar"
|
||||||
|
archiveClassifier = modLoaders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Transfers the values set in settings.gradle to the rest of the project
|
|
||||||
project.gradle.ext.getProperties().each { prop ->
|
|
||||||
rootProject.ext.set(prop.key, prop.value)
|
|
||||||
//println "Added prop [key:" + prop.key + ", value:" + prop.value + "]"
|
|
||||||
}
|
|
||||||
// Sets up manifold stuff
|
|
||||||
writeBuildGradlePredefine(rootProject.mcVers, rootProject.mcIndex)
|
|
||||||
|
|
||||||
// Sets up the version string (the name we use for our jar)
|
|
||||||
rootProject.versionStr = rootProject.mod_version + "-" + rootProject.minecraft_version // + "-" + new Date().format("yyyy_MM_dd_HH_mm")
|
|
||||||
|
|
||||||
class NativeTransformer implements Transformer {
|
|
||||||
private Predicate<String> fileMatcher
|
|
||||||
private Function<String, String> filePathMapper
|
|
||||||
|
|
||||||
private final HashMap<String, String> replacements = new HashMap()
|
|
||||||
private final HashMap<String, byte[]> rewrittenFiles = new HashMap()
|
|
||||||
private var nativeRelocator
|
|
||||||
|
|
||||||
public File rootDir
|
|
||||||
|
|
||||||
void matchFiles(Predicate<String> matcher) {
|
|
||||||
fileMatcher = matcher
|
|
||||||
}
|
|
||||||
|
|
||||||
void mapPaths(Function<String, String> mapper) {
|
|
||||||
filePathMapper = mapper
|
|
||||||
}
|
|
||||||
|
|
||||||
void relocateNative(String target, String replacement) {
|
|
||||||
if (replacement.length() > target.length()) {
|
|
||||||
throw new GradleException("Length of value \"${replacement}\" exceeds the length of \"${target}\": ${replacement.length()} > ${target.length()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
replacements.put(target, replacement)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean canTransformResource(@Nonnull FileTreeElement element) {
|
|
||||||
return fileMatcher.test(element.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void transform(@Nonnull TransformerContext context) {
|
|
||||||
byte[] content = context.is.readAllBytes()
|
|
||||||
|
|
||||||
if (nativeRelocator == null) {
|
|
||||||
nativeRelocator = new NativeRelocator(rootDir.toPath().resolve("relocate_natives"))
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String path = filePathMapper != null
|
|
||||||
? filePathMapper.apply(context.path)
|
|
||||||
: context.path
|
|
||||||
content = nativeRelocator.processBinary(path, content, replacements)
|
|
||||||
|
|
||||||
rewrittenFiles.put(path, content)
|
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
throw new GradleException("Failed to relocate", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean hasTransformedResource() { return !rewrittenFiles.isEmpty() }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void modifyOutputStream(@Nonnull ZipOutputStream os, boolean preserveFileTimestamps) {
|
|
||||||
for (Map.Entry<String, byte[]> rewrittenFile : rewrittenFiles.entrySet()) {
|
|
||||||
os.putNextEntry(new ZipEntry(rewrittenFile.key))
|
|
||||||
os.write(rewrittenFile.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
subprojects { p ->
|
|
||||||
// Does the same as "p == project(":common") || p == project(":fabric") || p == project(":quilt") || p == project(":forge") || p == project("WhateverWeAddLaterOn")"
|
|
||||||
// Useful later on so we dont have duplicated code
|
|
||||||
def isMinecraftSubProject = p != project(":core") && p != project(":api")
|
|
||||||
|
|
||||||
|
|
||||||
// Apply plugins
|
|
||||||
apply plugin: "java"
|
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
|
||||||
if (isMinecraftSubProject)
|
|
||||||
apply plugin: "systems.manifold.manifold-gradle-plugin"
|
|
||||||
|
|
||||||
// Apply forge's loom
|
|
||||||
if ((findProject(":forge") && p == project(":forge")) ||
|
|
||||||
(findProject(":neoforge") && p == project(":neoforge"))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
apply plugin: "dev.architectury.loom"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set the manifold version (may not be required tough)
|
|
||||||
manifold {
|
|
||||||
manifoldVersion = rootProject.manifold_version
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// set up custom configurations (configurations are a way to handle dependencies)
|
|
||||||
configurations {
|
|
||||||
// extends the shadowJar configuration
|
|
||||||
shadowMe
|
|
||||||
// have implemented dependencies automatically embedded in the final jar
|
|
||||||
implementation.extendsFrom(shadowMe)
|
|
||||||
|
|
||||||
// Configuration fpr core & api
|
|
||||||
coreProjects
|
|
||||||
shadowMe.extendsFrom(coreProjects)
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME this additional configuration is necessary because forge
|
|
||||||
// needs forgeRuntimeLibrary, although adding it to shadowMe
|
|
||||||
// causes runtime issues where the libraries aren't properly added
|
|
||||||
forgeShadowMe
|
|
||||||
// this should match shadowMe pretty closely
|
|
||||||
implementation.extendsFrom(forgeShadowMe)
|
|
||||||
shadowMe.extendsFrom(forgeShadowMe)
|
|
||||||
forgeRuntimeLibrary.extendsFrom(forgeShadowMe)
|
|
||||||
|
|
||||||
|
|
||||||
if (isMinecraftSubProject && p != project(":common")) {
|
|
||||||
// Shadow common
|
|
||||||
common
|
|
||||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
|
||||||
compileClasspath.extendsFrom common
|
|
||||||
runtimeClasspath.extendsFrom common
|
|
||||||
if (findProject(":forge"))
|
|
||||||
developmentForge.extendsFrom common
|
|
||||||
if (findProject(":neoforge"))
|
|
||||||
developmentNeoForge.extendsFrom common
|
|
||||||
compileClasspath.extendsFrom coreProjects
|
|
||||||
runtimeClasspath.extendsFrom coreProjects
|
|
||||||
if (findProject(":forge"))
|
|
||||||
developmentForge.extendsFrom coreProjects
|
|
||||||
if (findProject(":neoforge"))
|
|
||||||
developmentNeoForge.extendsFrom coreProjects
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
//=====================//
|
|
||||||
// shared dependencies //
|
|
||||||
//=====================//
|
|
||||||
|
|
||||||
// Manifold
|
|
||||||
if (isMinecraftSubProject) {
|
|
||||||
annotationProcessor("systems.manifold:manifold-preprocessor:${rootProject.manifold_version}")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log4j
|
|
||||||
if (p == project(":core"))
|
|
||||||
{
|
|
||||||
// the standalone core jar needs logging shaded otherwise it won't run
|
|
||||||
forgeShadowMe("org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}")
|
|
||||||
forgeShadowMe("org.apache.logging.log4j:log4j-core:${rootProject.log4j_version}")
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// When running in MC, MC already includes logging
|
|
||||||
implementation("org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}")
|
|
||||||
implementation("org.apache.logging.log4j:log4j-core:${rootProject.log4j_version}")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// JOML
|
|
||||||
if (project.hasProperty("embed_joml") && embed_joml == "true")
|
|
||||||
forgeShadowMe("org.joml:joml:${rootProject.joml_version}")
|
|
||||||
else
|
|
||||||
implementation("org.joml:joml:${rootProject.joml_version}")
|
|
||||||
|
|
||||||
// JUnit tests
|
|
||||||
implementation("org.junit.jupiter:junit-jupiter:5.8.2")
|
|
||||||
implementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
|
||||||
implementation("junit:junit:4.13")
|
|
||||||
|
|
||||||
// FastUtil
|
|
||||||
// Note: MC 1.16 uses 8.2.1, and versions after use 8.5.12
|
|
||||||
// We cannot relocate this library since we call some MC classes that reference it
|
|
||||||
implementation("it.unimi.dsi:fastutil:${rootProject.fastutil_version}")
|
|
||||||
|
|
||||||
forgeShadowMe("com.github.luben:zstd-jni:${rootProject.zstd_version}")
|
|
||||||
|
|
||||||
// Compression
|
|
||||||
forgeShadowMe("org.lz4:lz4-java:${rootProject.lz4_version}") // LZ4
|
|
||||||
forgeShadowMe("org.tukaani:xz:${rootProject.xz_version}") // LZMA
|
|
||||||
|
|
||||||
// Sqlite Database
|
|
||||||
forgeShadowMe("org.xerial:sqlite-jdbc:${rootProject.sqlite_jdbc_version}")
|
|
||||||
|
|
||||||
// NightConfig (includes Toml & Json)
|
|
||||||
forgeShadowMe("com.electronwill.night-config:toml:${rootProject.nightconfig_version}")
|
|
||||||
forgeShadowMe("com.electronwill.night-config:json:${rootProject.nightconfig_version}")
|
|
||||||
|
|
||||||
// SVG (not needed atm)
|
|
||||||
// forgeShadowMe("com.formdev:svgSalamander:${rootProject.svgSalamander_version}")
|
|
||||||
|
|
||||||
// Netty
|
|
||||||
implementation("io.netty:netty-buffer:${rootProject.netty_version}")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==========================//
|
|
||||||
// conditional dependencies //
|
|
||||||
//==========================//
|
|
||||||
|
|
||||||
|
|
||||||
// Add core
|
|
||||||
if (isMinecraftSubProject) {
|
|
||||||
coreProjects(project(":core")) {
|
|
||||||
// Remove Junit test libraries
|
|
||||||
exclude group: "org.junit.jupiter", module: "junit-jupiter"
|
|
||||||
exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
|
|
||||||
exclude group: "junit", module: "junit"
|
|
||||||
// Removed dependencies
|
|
||||||
transitive false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the api
|
|
||||||
if (p != project(":api")) {
|
|
||||||
coreProjects(project(":api")) {
|
|
||||||
// Remove Junit test libraries
|
|
||||||
exclude group: "org.junit.jupiter", module: "junit-jupiter"
|
|
||||||
exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
|
|
||||||
exclude group: "junit", module: "junit"
|
|
||||||
// Removed dependencies
|
|
||||||
transitive false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add common
|
|
||||||
if (isMinecraftSubProject && p != project(":common")) {
|
|
||||||
// Common
|
|
||||||
common(project(":common")) { transitive false }
|
|
||||||
shadowCommon(project(":common")) { transitive false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
configurations = [project.configurations.shadowMe]
|
|
||||||
if (isMinecraftSubProject && p != project(":common")) {
|
|
||||||
configurations.push(project.configurations.shadowCommon) // Shadow the common subproject
|
|
||||||
relocate "com.seibel.distanthorizons.common", "loaderCommon.${p.name}.com.seibel.distanthorizons.common" // Move the loader files to a different location
|
|
||||||
}
|
|
||||||
def librariesLocation = "DistantHorizons.libraries"
|
|
||||||
|
|
||||||
// Compression (LZ4)
|
|
||||||
relocate "net.jpountz", "${librariesLocation}.jpountz"
|
|
||||||
|
|
||||||
// Logging
|
|
||||||
relocate "org.slf4j", "${librariesLocation}.slf4j"
|
|
||||||
|
|
||||||
// Sqlite Database
|
|
||||||
// librariesLocation isn't used because it's too long for replacing paths in native libraries
|
|
||||||
// Allowing strings larger than the original string would require shifting the entire binary's contents
|
|
||||||
relocate "org.sqlite", "dh_sqlite", {
|
|
||||||
exclude "org/sqlite/native/**"
|
|
||||||
}
|
|
||||||
relocate "jdbc:sqlite", "jdbc:dh_sqlite"
|
|
||||||
|
|
||||||
transform(NativeTransformer) {
|
|
||||||
rootDir = project.rootDir
|
|
||||||
|
|
||||||
matchFiles { it.startsWith("org/sqlite") }
|
|
||||||
mapPaths { it.replace("org/sqlite", "dh_sqlite") }
|
|
||||||
|
|
||||||
relocateNative "org/sqlite", "dh_sqlite"
|
|
||||||
relocateNative "org_sqlite", "dh_1sqlite"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ZStd
|
|
||||||
// librariesLocation isn't used because it's too long for replacing paths in native libraries
|
|
||||||
// Allowing strings larger than the original string would require shifting the entire binary's contents
|
|
||||||
relocate "com.github.luben", "dhcomgithubluben"
|
|
||||||
relocate "libzstd-jni", "libzstd-jni_dh"
|
|
||||||
relocate "zstd-jni", "zstd-jni_dh"
|
|
||||||
|
|
||||||
transform(NativeTransformer) {
|
|
||||||
rootDir = project.rootDir
|
|
||||||
|
|
||||||
matchFiles { it.contains("libzstd-jni") && !it.contains("aix/ppc64") }
|
|
||||||
mapPaths { it.replace("libzstd-jni", "libzstd-jni_dh") }
|
|
||||||
|
|
||||||
relocateNative "com/github/luben", "dhcomgithubluben"
|
|
||||||
relocateNative "com_github_luben", "dhcomgithubluben"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// JOML
|
|
||||||
if (project.hasProperty("embed_joml") && embed_joml == "true")
|
|
||||||
relocate "org.joml", "${librariesLocation}.joml"
|
|
||||||
|
|
||||||
// NightConfig (includes Toml & Json)
|
|
||||||
relocate "com.electronwill.nightconfig", "${librariesLocation}.electronwill.nightconfig"
|
|
||||||
|
|
||||||
// Netty
|
|
||||||
// Don't relocate, it causes problems with using MC's FriendlyByteBufs
|
|
||||||
// relocate "io.netty", "${librariesLocation}.netty"
|
|
||||||
|
|
||||||
mergeServiceFiles()
|
|
||||||
}
|
|
||||||
// Using jar.finalizedBy(shadowJar) causes issues so we do this scuffed bypass
|
|
||||||
jar.dependsOn(shadowJar)
|
|
||||||
|
|
||||||
|
|
||||||
// Put stuff from gradle.properties into the mod info
|
|
||||||
// Note: these resources are only included in the mod jars, the core and API jars don't include these files
|
|
||||||
processResources {
|
|
||||||
def resourceTargets = [ // Location of where to inject the properties
|
|
||||||
// Holds info like git commit
|
|
||||||
"build_info.json",
|
|
||||||
|
|
||||||
// Properties for each of the loaders
|
|
||||||
"fabric.mod.json",
|
|
||||||
"quilt.mod.json",
|
|
||||||
"META-INF/mods.toml",
|
|
||||||
"META-INF/neoforge.mods.toml",
|
|
||||||
|
|
||||||
// The mixins for each of the loaders
|
|
||||||
//"DistantHorizons."+ p.name +".fabricLike.mixins.json"
|
|
||||||
]
|
|
||||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
|
||||||
|
|
||||||
// Fix forge version numbering system as it is weird
|
|
||||||
// For whatever reason forge uses [1.18, 1.18.1, 1.18.2) instead of the standard ["1.18", "1.18.1", "1.18.2"]
|
|
||||||
def compatible_forgemc_versions = "${compatible_minecraft_versions}".replaceAll("\"", "").replaceAll("]", ",)")
|
|
||||||
// println compatible_forgemc_versions
|
|
||||||
|
|
||||||
// Quilt's custom contributors system
|
|
||||||
// This has to be like
|
|
||||||
// "Person": "Developer", "Another person": "Developer"
|
|
||||||
def quilt_contributors = []
|
|
||||||
def mod_author_list = mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
|
|
||||||
for (dev in mod_author_list) {
|
|
||||||
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
|
|
||||||
}
|
|
||||||
quilt_contributors.reverse()
|
|
||||||
//println quilt_contributors.join(", ")
|
|
||||||
|
|
||||||
|
|
||||||
// These "hasProperty"'s are so that they can be passed through the cli (ie in the CI)
|
|
||||||
try {
|
|
||||||
if (infoGitCommit == "null")
|
|
||||||
infoGitCommit = 'git rev-parse --verify HEAD'.execute().text.trim()
|
|
||||||
if (infoGitBranch == "null")
|
|
||||||
infoGitBranch = 'git symbolic-ref --short HEAD'.execute().text.trim()
|
|
||||||
} catch (Exception e) {
|
|
||||||
infoGitCommit = infoGitBranch = "Git not found"
|
|
||||||
println "Git or Git project not found"
|
|
||||||
}
|
|
||||||
|
|
||||||
// The left side is what gets replaced in the mod info and the right side is where to get it from in the gradle.properties
|
|
||||||
def replaceProperties = [
|
|
||||||
version : mod_version,
|
|
||||||
mod_name : mod_readable_name,
|
|
||||||
group : maven_group,
|
|
||||||
authors : mod_authors,
|
|
||||||
description : mod_description,
|
|
||||||
homepage : mod_homepage,
|
|
||||||
source : mod_source,
|
|
||||||
issues : mod_issues,
|
|
||||||
discord : mod_discord,
|
|
||||||
minecraft_version : minecraft_version,
|
|
||||||
compatible_minecraft_versions: compatible_minecraft_versions,
|
|
||||||
compatible_forgemc_versions : compatible_forgemc_versions,
|
|
||||||
java_version : java_version,
|
|
||||||
quilt_contributors : "{"+quilt_contributors.join(", ")+"}",
|
|
||||||
|
|
||||||
info_git_commit : infoGitBranch,
|
|
||||||
info_git_branch : infoGitCommit,
|
|
||||||
info_build_source : infoBuildSource,
|
|
||||||
|
|
||||||
fabric_incompatibility_list : fabric_incompatibility_list,
|
|
||||||
fabric_recommend_list : fabric_recommend_list,
|
|
||||||
|
|
||||||
neoforge_version_range : neoforge_version_range,
|
|
||||||
]
|
|
||||||
|
|
||||||
// replace any properties in the sub-projects with the values defined here
|
|
||||||
inputs.properties replaceProperties
|
|
||||||
replaceProperties.put "project", project
|
|
||||||
filesMatching(resourceTargets) {
|
|
||||||
expand replaceProperties
|
|
||||||
}
|
|
||||||
|
|
||||||
intoTargets.each { target ->
|
|
||||||
if (file(target).exists()) {
|
|
||||||
copy {
|
|
||||||
from(sourceSets.main.resources) {
|
|
||||||
include resourceTargets
|
|
||||||
expand replaceProperties
|
|
||||||
}
|
|
||||||
into target
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ==================== Delete un-needed files ====================
|
|
||||||
// Jank solution to remove all unused accesswideners
|
|
||||||
// (neo)forge (well, mainly architectury) requires the original accesswidener file, meaning we require this jank solution to keep it
|
|
||||||
exclude { file ->
|
|
||||||
if (file.name.contains(".distanthorizons.accesswidener") && file.name != "${accessWidenerVersion}.distanthorizons.accesswidener") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Adds the standalone jar's entrypoint
|
|
||||||
jar {
|
|
||||||
from "LICENSE.txt"
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
'Implementation-Title': rootProject.mod_name,
|
|
||||||
'Implementation-Version': rootProject.mod_version,
|
|
||||||
'Multi-Release': true, // needed for logging in the standalone core jar
|
|
||||||
'Main-Class': 'com.seibel.distanthorizons.core.jar.JarMain', // When changing the main of the jar change this line
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this can be un-commented if we ever wanted to make DH modular (AKA use a module-info.java file) again
|
|
||||||
/*
|
|
||||||
// Tells gradle where to look for other modules
|
|
||||||
// Why isn't the classpath added to the modules path by default?
|
|
||||||
if (p == project(":core")) {
|
|
||||||
compileJava {
|
|
||||||
inputs.property('moduleName', 'dhApi')
|
|
||||||
doFirst {
|
|
||||||
options.compilerArgs = [
|
|
||||||
'--module-path', classpath.asPath
|
|
||||||
]
|
|
||||||
classpath = files()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects { p ->
|
|
||||||
// Does the same as "p == project(":common") || p == project(":fabric") || p == project(":quilt") || p == project(":forge") || p == project("WhateverWeAddLaterOn")"
|
|
||||||
// Useful later on so we dont have duplicated code
|
|
||||||
def isMinecraftSubProject = p != project(":core") && p != project(":api")
|
|
||||||
|
|
||||||
|
|
||||||
apply plugin: "java"
|
|
||||||
apply plugin: "maven-publish"
|
|
||||||
|
|
||||||
// Sets the name of the jar, the version will contain the name of the project if it isn't the root project
|
|
||||||
archivesBaseName = rootProject.mod_name
|
|
||||||
version = (project == rootProject ? "" : project.name + "-") + rootProject.versionStr
|
|
||||||
group = rootProject.maven_group
|
|
||||||
|
|
||||||
// this is the text that appears at the top of the overview (home) page
|
|
||||||
// and is used when bookmarking a page
|
|
||||||
javadoc.title = rootProject.mod_name + "-" + project.name
|
|
||||||
|
|
||||||
// Some annotations arent "technically" part of the official java standard,
|
|
||||||
// so we define it ourself here
|
|
||||||
javadoc {
|
|
||||||
configure( options ) {
|
|
||||||
tags(
|
|
||||||
'todo:X"',
|
|
||||||
'apiNote:a:API Note:',
|
|
||||||
'implSpec:a:Implementation Requirements:',
|
|
||||||
'implNote:a:Implementation Note:'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
// Mojang overrides (added to fix downloading the wrong LWJGL libs on M1 Mac's and potentially other arm64 based machines)
|
|
||||||
maven { url "https://libraries.minecraft.net/" }
|
|
||||||
|
|
||||||
// The central repo
|
|
||||||
mavenCentral()
|
|
||||||
|
|
||||||
// Used for Google's Collect library
|
|
||||||
maven { url "https://repo.enonic.com/public/" }
|
|
||||||
|
|
||||||
// For parchment mappings
|
|
||||||
// versions can be found here: https://ldtteam.jfrog.io/ui/native/parchmentmc-public/org/parchmentmc/data/
|
|
||||||
maven { url "https://maven.parchmentmc.org" }
|
|
||||||
|
|
||||||
// For Architectury API
|
|
||||||
maven { url "https://maven.architectury.dev" }
|
|
||||||
|
|
||||||
// For Git repositories
|
|
||||||
maven { url "https://jitpack.io" }
|
|
||||||
|
|
||||||
// For Manifold Preprocessor
|
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
|
||||||
|
|
||||||
// Required for importing Modrinth mods
|
|
||||||
maven {
|
|
||||||
name = "Modrinth"
|
|
||||||
url = "https://api.modrinth.com/maven"
|
|
||||||
content {
|
|
||||||
includeGroup "maven.modrinth"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Required for importing CursedForge mods
|
|
||||||
maven {
|
|
||||||
url "https://www.cursemaven.com"
|
|
||||||
content {
|
|
||||||
includeGroup "curse.maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VanillaGradle and Mixins in common
|
|
||||||
maven { url "https://repo.spongepowered.org/maven/" }
|
|
||||||
|
|
||||||
// Canvas mod
|
|
||||||
maven { url "https://maven.vram.io/" }
|
|
||||||
// ModMenu mod
|
|
||||||
maven { url "https://maven.terraformersmc.com/" }
|
|
||||||
|
|
||||||
// neoforge
|
|
||||||
maven { url "https://maven.neoforged.net/releases/" }
|
|
||||||
|
|
||||||
// These 3 are for importing mods that arnt on CursedForge, Modrinth, GitHub, GitLab or anywhere opensource
|
|
||||||
flatDir {
|
|
||||||
dirs "${rootDir}/mods/fabric"
|
|
||||||
content {
|
|
||||||
includeGroup "fabric-mod"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
flatDir {
|
|
||||||
dirs "${rootDir}/mods/quilt"
|
|
||||||
content {
|
|
||||||
includeGroup "quilt-mod"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
flatDir {
|
|
||||||
dirs "${rootDir}/mods/forge"
|
|
||||||
content {
|
|
||||||
includeGroup "forge-mod"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds some dependencies that are in vanilla but not in core
|
|
||||||
if (p == project(":core")) {
|
|
||||||
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
|
|
||||||
|
|
||||||
// Set the OS lwjgl is using to the current os
|
|
||||||
project.ext.lwjglNatives = "natives-" + os.toFamilyName()
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// All of these dependencies are in Vanilla Minecraft, but we need to depend on them as we arent importing Minecraft in the core
|
|
||||||
|
|
||||||
// Imports most of lwjgl's libraries
|
|
||||||
implementation platform("org.lwjgl:lwjgl-bom:${rootProject.lwjgl_version}")
|
|
||||||
|
|
||||||
// REMEMBER: Don't shadow stuff here, these are just the libs that are included in Minecraft so that the core can use them
|
|
||||||
implementation "org.lwjgl:lwjgl"
|
|
||||||
implementation "org.lwjgl:lwjgl-assimp"
|
|
||||||
implementation "org.lwjgl:lwjgl-glfw"
|
|
||||||
// OpenGL is removed since DH now handles rendering in the "Common" project
|
|
||||||
// so we can use OpenGL for old MC versions and Blaze3D (IE Vulkan) for newer ones
|
|
||||||
// implementation "org.lwjgl:lwjgl-openal"
|
|
||||||
// implementation "org.lwjgl:lwjgl-opengl"
|
|
||||||
implementation "org.lwjgl:lwjgl-stb"
|
|
||||||
implementation "org.lwjgl:lwjgl-tinyfd"
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
|
||||||
// runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
|
|
||||||
// runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl-tinyfd::$lwjglNatives"
|
|
||||||
implementation "org.joml:joml:${rootProject.joml_version}"
|
|
||||||
|
|
||||||
|
|
||||||
// Some other dependencies
|
|
||||||
implementation("org.jetbrains:annotations:16.0.2")
|
|
||||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
|
||||||
implementation("com.google.common:google-collect:0.5")
|
|
||||||
implementation("com.google.guava:guava:31.1-jre")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
task copyCommonLoaderResources(type: Copy) {
|
|
||||||
from project(":common").file("src/main/resources/${accessWidenerVersion}.distanthorizons.accesswidener")
|
|
||||||
into(file(p.file("build/resources/main")))
|
|
||||||
rename "${accessWidenerVersion}.distanthorizons.accesswidener", "distanthorizons.accesswidener"
|
|
||||||
}
|
|
||||||
|
|
||||||
task copyCoreResources(type: Copy) {
|
|
||||||
from fileTree(project(":core").file("src/main/resources"))
|
|
||||||
into p.file("build/resources/main")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
if (isMinecraftSubProject) {
|
|
||||||
options.release = rootProject.java_version as Integer
|
|
||||||
} else {
|
|
||||||
options.release = 8; // Core & Api should use Java 8 no matter what
|
|
||||||
}
|
|
||||||
options.encoding = "UTF-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
plugins {
|
||||||
|
id 'groovy-gradle-plugin'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
mavenCentral()
|
||||||
|
maven { url = 'https://maven.wagyourtail.xyz/releases' } // Jvmdowngrader & unimined libs
|
||||||
|
maven { url = 'https://maven.outlands.top/releases' } // Hosts the kappa fork of unimined
|
||||||
|
maven { url = 'https://maven.wagyourtail.xyz/snapshots' } // The manifold gradle plugin we use
|
||||||
|
maven { url = 'https://maven.architectury.dev/' } // Minecraft mod libs
|
||||||
|
maven { url = 'https://maven.fabricmc.net/' } // Fabric
|
||||||
|
maven { url = 'https://maven.neoforged.net/releases/' } // NeoForge
|
||||||
|
maven { url = 'https://maven.minecraftforge.net/' } // Forge
|
||||||
|
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } // Hosts minecraft libs
|
||||||
|
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' } // Hosts a few dependencies we use
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.gradleup.shadow:shadow-gradle-plugin:9.0.0'
|
||||||
|
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.jvmdowngrader:xyz.wagyourtail.jvmdowngrader.gradle.plugin:1.3.4'
|
||||||
|
}
|
||||||
@@ -0,0 +1,516 @@
|
|||||||
|
import com.github.jengelman.gradle.plugins.shadow.transformers.ResourceTransformer
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
|
||||||
|
import org.apache.tools.zip.ZipEntry
|
||||||
|
import org.apache.tools.zip.ZipOutputStream
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
import java.util.function.Function
|
||||||
|
import java.util.function.Predicate
|
||||||
|
|
||||||
|
// Convention plugin for all MC-facing subprojects (common + loaders).
|
||||||
|
// Common uses this directly; loaders use it via unimined-fabric/forge/neoforge.
|
||||||
|
// IMPORTANT: unimined MUST be applied before shadow/jvmdowngrader
|
||||||
|
// so its afterEvaluate runs first and can modify configs.
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'xyz.wagyourtail.unimined'
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
id 'xyz.wagyourtail.manifold'
|
||||||
|
id 'xyz.wagyourtail.jvmdowngrader'
|
||||||
|
}
|
||||||
|
|
||||||
|
def isNotCommonProject = project.name != "common"
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Version Properties ====================
|
||||||
|
|
||||||
|
project.gradle.ext.getProperties().each { prop ->
|
||||||
|
rootProject.ext.set(prop.key, prop.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
manifold {
|
||||||
|
version = rootProject.manifold_version
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Repositories ====================
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://libraries.minecraft.net/" }
|
||||||
|
mavenCentral()
|
||||||
|
maven { url "https://repo.enonic.com/public/" }
|
||||||
|
maven { url "https://maven.parchmentmc.org" }
|
||||||
|
maven { url "https://maven.architectury.dev" }
|
||||||
|
maven { url "https://jitpack.io" }
|
||||||
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
|
maven {
|
||||||
|
name = "Modrinth"
|
||||||
|
url = "https://api.modrinth.com/maven"
|
||||||
|
content { includeGroup "maven.modrinth" }
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url "https://www.cursemaven.com"
|
||||||
|
content { includeGroup "curse.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.neoforged.net/releases/" }
|
||||||
|
flatDir {
|
||||||
|
dirs "${rootDir}/mods/fabric"
|
||||||
|
content { includeGroup "fabric-mod" }
|
||||||
|
}
|
||||||
|
flatDir {
|
||||||
|
dirs "${rootDir}/mods/quilt"
|
||||||
|
content { includeGroup "quilt-mod" }
|
||||||
|
}
|
||||||
|
flatDir {
|
||||||
|
dirs "${rootDir}/mods/forge"
|
||||||
|
content { includeGroup "forge-mod" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Java Config ====================
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.release = rootProject.java_version as Integer
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.toVersion(gradle.ext.java_version as Integer)
|
||||||
|
targetCompatibility = JavaVersion.toVersion(gradle.ext.java_version as Integer)
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Loader-Only Config ====================
|
||||||
|
|
||||||
|
if (isNotCommonProject) {
|
||||||
|
base { archivesName = rootProject.mod_name }
|
||||||
|
rootProject.ext.versionStr = rootProject.mod_version + "-" + rootProject.minecraft_version
|
||||||
|
version = project.name + "-" + rootProject.versionStr
|
||||||
|
group = rootProject.maven_group
|
||||||
|
|
||||||
|
javadoc.title = rootProject.mod_name + "-" + project.name
|
||||||
|
|
||||||
|
tasks.withType(GenerateModuleMetadata).configureEach {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
tasks.withType(Test).configureEach {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
compileTestJava.enabled = false
|
||||||
|
tasks.withType(Sign).configureEach {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from "LICENSE.txt"
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'Implementation-Title': rootProject.mod_name,
|
||||||
|
'Implementation-Version': rootProject.mod_version,
|
||||||
|
'Multi-Release': true,
|
||||||
|
'Main-Class': 'com.seibel.distanthorizons.core.jar.JarMain',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Unimined Minecraft Config ====================
|
||||||
|
|
||||||
|
unimined.minecraft(sourceSets.main, true) {
|
||||||
|
version gradle.ext.minecraft_version
|
||||||
|
|
||||||
|
if (gradle.ext.minecraft_version.startsWith("1.")) { // 26.1+ doesn't use obfuscation
|
||||||
|
mappings {
|
||||||
|
mojmap()
|
||||||
|
devNamespace "mojmap"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotCommonProject) {
|
||||||
|
// Mixin remapping and common project wiring
|
||||||
|
unimined.minecraft(sourceSets.main, true) {
|
||||||
|
mods.modImplementation {
|
||||||
|
mixinRemap {
|
||||||
|
reset()
|
||||||
|
enableBaseMixin()
|
||||||
|
enableMixinExtra()
|
||||||
|
}
|
||||||
|
// Some Fabric API modules ship AW in 'named' namespace instead of 'intermediary'
|
||||||
|
catchAWNamespaceAssertion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":common"))
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
from project(":common").sourceSets.main.resources
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
source(project(":common").sourceSets.main.allSource)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Common: fabric for compilation + access widener, no jar remapping or runs
|
||||||
|
unimined.minecraft {
|
||||||
|
fabric {
|
||||||
|
loader gradle.ext.fabric_loader_version
|
||||||
|
accessWidener project.file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
|
}
|
||||||
|
defaultRemapJar = false
|
||||||
|
runs.off = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Configurations ====================
|
||||||
|
|
||||||
|
evaluationDependsOn(":core")
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
shadowMe
|
||||||
|
coreProjects
|
||||||
|
shadowMe.extendsFrom(coreProjects)
|
||||||
|
implementation.extendsFrom(shadowMe)
|
||||||
|
|
||||||
|
common
|
||||||
|
implementation.extendsFrom(common)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Dependencies ====================
|
||||||
|
|
||||||
|
// Copy core's compileOnly deps so MC-provided deps are visible without redeclaring them.
|
||||||
|
project(":core").configurations.compileOnly.allDependencies.each { dep ->
|
||||||
|
if (!(dep instanceof ProjectDependency))
|
||||||
|
dependencies.add("compileOnly", dep)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Manifold preprocessor & strings
|
||||||
|
annotationProcessor(manifold.module("preprocessor"))
|
||||||
|
|
||||||
|
// NightConfig: implementation in core (bundled) but Unimined strips it from compile classpath
|
||||||
|
compileOnly("com.electronwill.night-config:toml:${rootProject.nightconfig_version}")
|
||||||
|
|
||||||
|
// Core & API projects — bundled into shadow jar
|
||||||
|
coreProjects(project(":core"))
|
||||||
|
coreProjects(project(":api"))
|
||||||
|
|
||||||
|
// JOML: shadow for old MC versions that don't bundle it (core has it compileOnly already)
|
||||||
|
if (project.hasProperty("embed_joml") && embed_joml == "true")
|
||||||
|
shadowMe("org.joml:joml:${rootProject.joml_version}")
|
||||||
|
|
||||||
|
// Common project dependency
|
||||||
|
if (isNotCommonProject)
|
||||||
|
common(project(":common")) { transitive false }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== NativeTransformer ====================
|
||||||
|
|
||||||
|
class NativeTransformer implements ResourceTransformer {
|
||||||
|
private Predicate<String> fileMatcher
|
||||||
|
private Function<String, String> filePathMapper
|
||||||
|
|
||||||
|
private final HashMap<String, String> replacements = new HashMap()
|
||||||
|
private final HashMap<String, byte[]> rewrittenFiles = new HashMap()
|
||||||
|
private nativeRelocator
|
||||||
|
|
||||||
|
public File rootDir
|
||||||
|
|
||||||
|
void matchFiles(Predicate<String> matcher) {
|
||||||
|
fileMatcher = matcher
|
||||||
|
}
|
||||||
|
|
||||||
|
void mapPaths(Function<String, String> mapper) {
|
||||||
|
filePathMapper = mapper
|
||||||
|
}
|
||||||
|
|
||||||
|
void relocateNative(String target, String replacement) {
|
||||||
|
if (replacement.length() > target.length()) {
|
||||||
|
throw new GradleException("Length of value \"${replacement}\" exceeds the length of \"${target}\": ${replacement.length()} > ${target.length()}")
|
||||||
|
}
|
||||||
|
replacements.put(target, replacement)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean canTransformResource(@Nonnull FileTreeElement element) {
|
||||||
|
return fileMatcher != null && fileMatcher.test(element.relativePath.pathString)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void transform(@Nonnull TransformerContext context) {
|
||||||
|
byte[] content = context.inputStream.readAllBytes()
|
||||||
|
|
||||||
|
if (nativeRelocator == null) {
|
||||||
|
nativeRelocator = new NativeRelocator(rootDir.toPath().resolve("relocate_natives"))
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String path = filePathMapper != null
|
||||||
|
? filePathMapper.apply(context.path)
|
||||||
|
: context.path
|
||||||
|
content = nativeRelocator.processBinary(path, content, replacements)
|
||||||
|
rewrittenFiles.put(path, content)
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
throw new GradleException("Failed to relocate", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean hasTransformedResource() { return !rewrittenFiles.isEmpty() }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void modifyOutputStream(@Nonnull ZipOutputStream os, boolean preserveFileTimestamps) {
|
||||||
|
for (Map.Entry<String, byte[]> rewrittenFile : rewrittenFiles.entrySet()) {
|
||||||
|
os.putNextEntry(new ZipEntry(rewrittenFile.key))
|
||||||
|
os.write(rewrittenFile.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Shadow JAR (loaders only) ====================
|
||||||
|
|
||||||
|
if (isNotCommonProject) {
|
||||||
|
shadowJar {
|
||||||
|
configurations = [project.configurations.shadowMe]
|
||||||
|
def librariesLocation = "DistantHorizons.libraries"
|
||||||
|
|
||||||
|
// LZ4
|
||||||
|
relocate "net.jpountz", "${librariesLocation}.jpountz"
|
||||||
|
|
||||||
|
// SLF4J
|
||||||
|
relocate "org.slf4j", "${librariesLocation}.slf4j"
|
||||||
|
|
||||||
|
// SQLite
|
||||||
|
relocate "org.sqlite", "dh_sqlite", { exclude "org/sqlite/native/**" }
|
||||||
|
relocate "jdbc:sqlite", "jdbc:dh_sqlite"
|
||||||
|
|
||||||
|
transform(NativeTransformer) {
|
||||||
|
rootDir = project.rootDir
|
||||||
|
matchFiles { it.startsWith("org/sqlite") }
|
||||||
|
mapPaths { it.replace("org/sqlite", "dh_sqlite") }
|
||||||
|
relocateNative "org/sqlite", "dh_sqlite"
|
||||||
|
relocateNative "org_sqlite", "dh_1sqlite"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZStd
|
||||||
|
relocate "com.github.luben", "dhcomgithubluben"
|
||||||
|
relocate "libzstd-jni", "libzstd-jni_dh"
|
||||||
|
relocate "zstd-jni", "zstd-jni_dh"
|
||||||
|
|
||||||
|
transform(NativeTransformer) {
|
||||||
|
rootDir = project.rootDir
|
||||||
|
matchFiles { it.contains("libzstd-jni") && !it.contains("aix/ppc64") }
|
||||||
|
mapPaths { it.replace("libzstd-jni", "libzstd-jni_dh") }
|
||||||
|
relocateNative "com/github/luben", "dhcomgithubluben"
|
||||||
|
relocateNative "com_github_luben", "dhcomgithubluben"
|
||||||
|
}
|
||||||
|
|
||||||
|
// JOML (conditional)
|
||||||
|
if (project.hasProperty("embed_joml") && embed_joml == "true")
|
||||||
|
relocate "org.joml", "${librariesLocation}.joml"
|
||||||
|
|
||||||
|
// NightConfig
|
||||||
|
relocate "com.electronwill.nightconfig", "${librariesLocation}.electronwill.nightconfig"
|
||||||
|
|
||||||
|
mergeServiceFiles()
|
||||||
|
}
|
||||||
|
afterEvaluate {
|
||||||
|
tasks.named("remapJar").configure {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
inputFile.set(shadowJar.archiveFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make run tasks use the shadow jar so relocated deps work in dev.
|
||||||
|
// Filter out jars bundled in the shadow jar, but keep jars that the loader also
|
||||||
|
// needs (e.g. NightConfig — DH relocates it, but NeoForge needs the original).
|
||||||
|
def shadowedPaths = configurations.shadowMe.resolve().collect { it.path }.toSet()
|
||||||
|
def loaderPaths = configurations.minecraftLibraries.resolve().collect { it.path }.toSet()
|
||||||
|
tasks.withType(JavaExec).configureEach { runTask ->
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
classpath = files(shadowJar.archiveFile) + 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
|
||||||
|
def isClient = runTask.name.toLowerCase().contains("client")
|
||||||
|
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
|
||||||
|
|
||||||
|
// fix (Neo)forge 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
|
||||||
|
runTask.jvmArgs(
|
||||||
|
"-Dio.netty.leakDetection.level=advanced",
|
||||||
|
// TODO only use for modern java versions
|
||||||
|
"-XX:+UseZGC",
|
||||||
|
// TODO don't use for even more modern-er java versions
|
||||||
|
//"-XX:+ZGenerational",
|
||||||
|
rootProject.minecraftMemoryJavaArg,
|
||||||
|
)
|
||||||
|
if (isClient)
|
||||||
|
{
|
||||||
|
runTask.jvmArgs(
|
||||||
|
"-Dminecraft.api.auth.host=https://nope.invalid",
|
||||||
|
"-Dminecraft.api.account.host=https://nope.invalid",
|
||||||
|
"-Dminecraft.api.session.host=https://nope.invalid",
|
||||||
|
"-Dminecraft.api.services.host=https://nope.invalid",
|
||||||
|
)
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Process Resources (loaders only) ====================
|
||||||
|
|
||||||
|
if (isNotCommonProject) {
|
||||||
|
processResources {
|
||||||
|
def resourceTargets = [
|
||||||
|
"build_info.json",
|
||||||
|
"fabric.mod.json",
|
||||||
|
"quilt.mod.json",
|
||||||
|
"META-INF/mods.toml",
|
||||||
|
"META-INF/neoforge.mods.toml",
|
||||||
|
]
|
||||||
|
|
||||||
|
def compatible_forgemc_versions = "${rootProject.compatible_minecraft_versions}".replaceAll("\"", "").replaceAll("]", ",)")
|
||||||
|
|
||||||
|
// Quilt contributors
|
||||||
|
def quilt_contributors = []
|
||||||
|
def mod_author_list = rootProject.mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
|
||||||
|
for (dev in mod_author_list) {
|
||||||
|
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
|
||||||
|
}
|
||||||
|
quilt_contributors.reverse()
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (rootProject.infoGitCommit == "null")
|
||||||
|
rootProject.ext.infoGitCommit = 'git rev-parse --verify HEAD'.execute().text.trim()
|
||||||
|
if (rootProject.infoGitBranch == "null")
|
||||||
|
rootProject.ext.infoGitBranch = 'git symbolic-ref --short HEAD'.execute().text.trim()
|
||||||
|
} catch (Exception e) {
|
||||||
|
rootProject.ext.infoGitCommit = "Git not found"
|
||||||
|
rootProject.ext.infoGitBranch = "Git not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
def replaceProperties = [
|
||||||
|
version : rootProject.mod_version,
|
||||||
|
mod_name : rootProject.mod_readable_name,
|
||||||
|
group : rootProject.maven_group,
|
||||||
|
authors : rootProject.mod_authors,
|
||||||
|
description : rootProject.mod_description,
|
||||||
|
homepage : rootProject.mod_homepage,
|
||||||
|
source : rootProject.mod_source,
|
||||||
|
issues : rootProject.mod_issues,
|
||||||
|
discord : rootProject.mod_discord,
|
||||||
|
minecraft_version : rootProject.minecraft_version,
|
||||||
|
accessWidenerVersion : rootProject.accessWidenerVersion,
|
||||||
|
compatible_minecraft_versions: rootProject.compatible_minecraft_versions,
|
||||||
|
compatible_forgemc_versions : compatible_forgemc_versions,
|
||||||
|
java_version : rootProject.java_version,
|
||||||
|
quilt_contributors : "{" + quilt_contributors.join(", ") + "}",
|
||||||
|
info_git_commit : rootProject.infoGitBranch,
|
||||||
|
info_git_branch : rootProject.infoGitCommit,
|
||||||
|
info_build_source : rootProject.infoBuildSource,
|
||||||
|
fabric_incompatibility_list : rootProject.fabric_incompatibility_list,
|
||||||
|
fabric_recommend_list : rootProject.fabric_recommend_list,
|
||||||
|
neoforge_version_range : rootProject.neoforge_version_range,
|
||||||
|
]
|
||||||
|
|
||||||
|
inputs.properties replaceProperties
|
||||||
|
replaceProperties.put "project", project
|
||||||
|
filesMatching(resourceTargets) {
|
||||||
|
expand replaceProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove unused access wideners
|
||||||
|
exclude { file ->
|
||||||
|
if (file.name.contains(".distanthorizons.accesswidener") && file.name != "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== Resource Copy Tasks ====================
|
||||||
|
|
||||||
|
// task copyCommonLoaderResources(type: Copy) {
|
||||||
|
// from project(":common").file("src/main/resources/${rootProject.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
|
// into(file(project.file("build/resources/main")))
|
||||||
|
// rename "${rootProject.accessWidenerVersion}.distanthorizons.accesswidener", "distanthorizons.accesswidener"
|
||||||
|
// }
|
||||||
|
|
||||||
|
task copyCoreResources(type: Copy) {
|
||||||
|
from fileTree(project(":core").file("src/main/resources"))
|
||||||
|
into project.file("build/resources/main")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== JVMDowngrader ====================
|
||||||
|
|
||||||
|
jvmdg.downgradeTo = JavaVersion.toVersion(rootProject.java_version)
|
||||||
|
downgradeJar.archiveClassifier.set(null)
|
||||||
|
shadeDowngradedApi.archiveClassifier.set(null)
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer version properties from settings.gradle to project
|
||||||
|
project.gradle.ext.getProperties().each { prop ->
|
||||||
|
rootProject.ext.set(prop.key, prop.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version string for archives
|
||||||
|
rootProject.ext.versionStr = rootProject.mod_version + "-" + rootProject.minecraft_version
|
||||||
|
rootProject.allprojects {
|
||||||
|
version = (it == rootProject ? "" : it.name + "-") + rootProject.versionStr
|
||||||
|
group = rootProject.maven_group
|
||||||
|
|
||||||
|
// Custom javadoc tags for all subprojects
|
||||||
|
plugins.withType(JavaPlugin) {
|
||||||
|
javadoc {
|
||||||
|
options.tags(
|
||||||
|
'todo:X"',
|
||||||
|
'apiNote:a:API Note:',
|
||||||
|
'implSpec:a:Implementation Requirements:',
|
||||||
|
'implNote:a:Implementation Note:'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create build.properties with preprocessor definitions
|
||||||
|
def writePreprocessorDefinitions() {
|
||||||
|
StringBuilder sb = new StringBuilder()
|
||||||
|
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n")
|
||||||
|
|
||||||
|
gradle.ext.mcVers.eachWithIndex { ver, idx ->
|
||||||
|
sb.append("MC_${ver.replace('.', '_')}=${idx}\n")
|
||||||
|
if (gradle.ext.mcIndex == idx)
|
||||||
|
sb.append("MC_VER=${idx}\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootProject.mod_version.toLowerCase().contains("dev")) {
|
||||||
|
sb.append("DEV_BUILD=\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
new File(rootDir, "build.properties").text = sb.toString()
|
||||||
|
}
|
||||||
|
writePreprocessorDefinitions()
|
||||||
|
|
||||||
|
// Wire JVMDowngrader to process remapped jars
|
||||||
|
gradle.projectsEvaluated {
|
||||||
|
rootProject.subprojects.each {
|
||||||
|
if (it.tasks.findByName('remapJar') == null) return
|
||||||
|
it.tasks.downgradeJar.inputFile = it.tasks.remapJar.archiveFile
|
||||||
|
it.tasks.jar.finalizedBy(it.tasks.remapJar)
|
||||||
|
it.tasks.remapJar.finalizedBy(it.tasks.shadeDowngradedApi)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
plugins {
|
||||||
|
id 'dh-loader'
|
||||||
|
}
|
||||||
|
|
||||||
|
unimined.minecraft {
|
||||||
|
fabric {
|
||||||
|
loader gradle.ext.fabric_loader_version
|
||||||
|
accessWidener project(":common").file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runClient.javaLauncher = null
|
||||||
|
runServer.javaLauncher = null
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id 'dh-loader'
|
||||||
|
}
|
||||||
|
|
||||||
|
def awFile = project(":common").file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
|
|
||||||
|
unimined.minecraft {
|
||||||
|
forge {
|
||||||
|
loader gradle.ext.forge_version
|
||||||
|
useToolchains = false
|
||||||
|
mixinConfig("DistantHorizons.forge.mixins.json")
|
||||||
|
accessTransformer aw2at(awFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runClient.javaLauncher = null
|
||||||
|
runServer.javaLauncher = null
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
id 'dh-loader'
|
||||||
|
}
|
||||||
|
|
||||||
|
def awFile = project(":common").file("src/main/resources/${gradle.ext.accessWidenerVersion}.distanthorizons.accesswidener")
|
||||||
|
|
||||||
|
unimined.minecraft {
|
||||||
|
neoForged {
|
||||||
|
loader gradle.ext.neoforge_version
|
||||||
|
useToolchains = false
|
||||||
|
accessTransformer aw2at(awFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runClient.javaLauncher = null
|
||||||
|
runServer.javaLauncher = null
|
||||||
@@ -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
|
||||||
+1
-39
@@ -1,41 +1,3 @@
|
|||||||
|
|
||||||
// temporary fix for broken spongepowered version
|
|
||||||
buildscript {
|
|
||||||
configurations.configureEach {
|
|
||||||
resolutionStrategy {
|
|
||||||
force 'org.spongepowered:vanillagradle:0.2.1-20240507.024226-82'
|
|
||||||
// newer versions can be found by going to the link:
|
|
||||||
// https://repo.spongepowered.org/#browse/browse:maven-public:org%2Fspongepowered%2Fvanillagradle%2F0.2.1-SNAPSHOT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "org.spongepowered.gradle.vanilla" version "0.2.1-SNAPSHOT"
|
id 'dh-loader'
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraft {
|
|
||||||
accessWideners(project(":common").file("src/main/resources/${accessWidenerVersion}.distanthorizons.accesswidener"))
|
|
||||||
version(rootProject.minecraft_version)
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// So mixins can be written in common
|
|
||||||
compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenCommon(MavenPublication) {
|
|
||||||
artifactId = rootProject.mod_readable_name
|
|
||||||
from components.java
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
|
||||||
repositories {
|
|
||||||
// Add repositories to publish to here.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+46
-11
@@ -8,8 +8,8 @@ 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;
|
||||||
@@ -19,7 +19,10 @@ import com.seibel.distanthorizons.core.enums.MinecraftTextFormat;
|
|||||||
import com.seibel.distanthorizons.core.jar.ModJarInfo;
|
import com.seibel.distanthorizons.core.jar.ModJarInfo;
|
||||||
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
|
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.util.NativeDialogUtil;
|
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||||
|
import com.seibel.distanthorizons.core.render.renderer.StubDebugWireframeRenderer;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.NativeDialogUtil;
|
||||||
|
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||||
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,6 +35,7 @@ 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -91,7 +95,8 @@ 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
|
||||||
|
Initializer.postConfigInit();
|
||||||
|
|
||||||
LOGGER.info(ModInfo.READABLE_NAME + " client Initialized.");
|
LOGGER.info(ModInfo.READABLE_NAME + " client Initialized.");
|
||||||
|
|
||||||
@@ -133,7 +138,9 @@ public abstract class AbstractModInitializer
|
|||||||
MinecraftServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
MinecraftServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
||||||
|
|
||||||
this.initConfig();
|
this.initConfig();
|
||||||
|
Initializer.postConfigInit();
|
||||||
this.postInit();
|
this.postInit();
|
||||||
|
this.postServerInit();
|
||||||
this.commandInitializer.onServerReady();
|
this.commandInitializer.onServerReady();
|
||||||
|
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
@@ -154,7 +161,7 @@ public abstract class AbstractModInitializer
|
|||||||
private void startup()
|
private void startup()
|
||||||
{
|
{
|
||||||
DependencySetup.createSharedBindings();
|
DependencySetup.createSharedBindings();
|
||||||
SharedApi.init();
|
Initializer.preConfigInit();
|
||||||
this.createInitialSharedBindings();
|
this.createInitialSharedBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,15 +229,43 @@ public abstract class AbstractModInitializer
|
|||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postClientInit() { DependencySetup.setRenderingApiBindings(); }
|
private void postClientInit()
|
||||||
|
{
|
||||||
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
// This method may be called from either the render thread,
|
||||||
|
// or some other random setup thread depending on the mod loader.
|
||||||
|
// In order to avoid confusion/inconsistent problems, we're always going
|
||||||
|
// to run setup on our own thread.
|
||||||
|
Thread dhSetupThread = new Thread(() ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DependencySetup.setRenderingApiBindings();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
future.completeExceptionally(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
future.complete(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dhSetupThread.setName(ThreadUtil.THREAD_NAME_PREFIX + "PostClientInit Thread");
|
||||||
|
dhSetupThread.start();
|
||||||
|
|
||||||
|
future.join();
|
||||||
|
}
|
||||||
|
private void postServerInit() { SingletonInjector.INSTANCE.bind(AbstractDebugWireframeRenderer.class, new StubDebugWireframeRenderer()); }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==================================//
|
//======================//
|
||||||
// mod partial compatibility checks //
|
// compatibility checks //
|
||||||
//==================================//
|
//======================//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,7 +274,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);
|
||||||
@@ -340,10 +375,10 @@ public abstract class AbstractModInitializer
|
|||||||
renderApi = versionConstants.getDefaultRenderingApi();
|
renderApi = versionConstants.getDefaultRenderingApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iris only supports nataive OpenGL
|
// Iris only supports native OpenGL
|
||||||
if (renderApi != EDhApiRenderApi.OPEN_GL)
|
if (renderApi != EDhApiRenderApi.OPEN_GL)
|
||||||
{
|
{
|
||||||
String irisUnsupportedMessage = "Iris doesn't support DH when using the ["+EDhApiRenderApi.BLAZE_3D+"] rendering API, please change it to ["+EDhApiRenderApi.OPEN_GL+"] in DH's config file.";
|
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 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");
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
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.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 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.CancellationException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@@ -22,7 +25,11 @@ import static net.minecraft.commands.Commands.literal;
|
|||||||
|
|
||||||
public class PregenCommand extends AbstractCommand
|
public class PregenCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
private final PregenManager pregenManager = new PregenManager();
|
private PregenManager getPregenManager()
|
||||||
|
{
|
||||||
|
DhServerWorld world = (DhServerWorld) Objects.requireNonNull(SharedApi.getAbstractDhWorld());
|
||||||
|
return world.getPregenManager();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||||
@@ -48,7 +55,7 @@ public class PregenCommand extends AbstractCommand
|
|||||||
|
|
||||||
private int pregenStatus(CommandContext<CommandSourceStack> c)
|
private int pregenStatus(CommandContext<CommandSourceStack> c)
|
||||||
{
|
{
|
||||||
String statusString = this.pregenManager.getStatusString();
|
String statusString = this.getPregenManager().getStatusString();
|
||||||
//noinspection ReplaceNullCheck
|
//noinspection ReplaceNullCheck
|
||||||
if (statusString != null)
|
if (statusString != null)
|
||||||
{
|
{
|
||||||
@@ -68,7 +75,7 @@ public class PregenCommand extends AbstractCommand
|
|||||||
ColumnPos origin = ColumnPosArgument.getColumnPos(c, "origin");
|
ColumnPos origin = ColumnPosArgument.getColumnPos(c, "origin");
|
||||||
int chunkRadius = getInteger(c, "chunkRadius");
|
int chunkRadius = getInteger(c, "chunkRadius");
|
||||||
|
|
||||||
CompletableFuture<Void> future = this.pregenManager.startPregen(
|
CompletableFuture<Void> future = this.getPregenManager().startPregen(
|
||||||
ServerLevelWrapper.getWrapper(level),
|
ServerLevelWrapper.getWrapper(level),
|
||||||
new DhBlockPos2D(#if MC_VER >= MC_1_19_2 origin.x(), origin.z() #else origin.x, origin.z #endif),
|
new DhBlockPos2D(#if MC_VER >= MC_1_19_2 origin.x(), origin.z() #else origin.x, origin.z #endif),
|
||||||
chunkRadius
|
chunkRadius
|
||||||
@@ -94,7 +101,7 @@ public class PregenCommand extends AbstractCommand
|
|||||||
|
|
||||||
private int pregenStop(CommandContext<CommandSourceStack> c)
|
private int pregenStop(CommandContext<CommandSourceStack> c)
|
||||||
{
|
{
|
||||||
CompletableFuture<Void> runningPregen = this.pregenManager.getRunningPregen();
|
CompletableFuture<Void> runningPregen = this.getPregenManager().getRunningPregen();
|
||||||
if (runningPregen == null)
|
if (runningPregen == null)
|
||||||
{
|
{
|
||||||
return this.sendFailureResponse(c, "Pregen is not running");
|
return this.sendFailureResponse(c, "Pregen is not running");
|
||||||
|
|||||||
+8
-2
@@ -70,10 +70,16 @@ public class DhUpdateScreenBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MC.setScreen(new UpdateModScreen(
|
UpdateModScreen updateScreen = new UpdateModScreen(
|
||||||
new TitleScreen(false),
|
new TitleScreen(false),
|
||||||
versionId
|
versionId
|
||||||
));
|
);
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
MC.setScreen(updateScreen);
|
||||||
|
#else
|
||||||
|
MC.setScreenAndShow(updateScreen);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-4
@@ -4,9 +4,11 @@ import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
|||||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
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.wrapperInterfaces.world.IServerLevelWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
public class MixinChunkMapCommon
|
public class MixinChunkMapCommon
|
||||||
@@ -16,8 +18,18 @@ public class MixinChunkMapCommon
|
|||||||
{
|
{
|
||||||
IServerLevelWrapper levelWrapper = ServerLevelWrapper.getWrapper(level);
|
IServerLevelWrapper levelWrapper = ServerLevelWrapper.getWrapper(level);
|
||||||
|
|
||||||
|
int chunkPosX;
|
||||||
|
int chunkPosZ;
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
chunkPosX = chunk.getPos().x;
|
||||||
|
chunkPosZ = chunk.getPos().z;
|
||||||
|
#else
|
||||||
|
chunkPosX = chunk.getPos().x();
|
||||||
|
chunkPosZ = chunk.getPos().z();
|
||||||
|
#endif
|
||||||
|
|
||||||
// is this position already being updated?
|
// is this position already being updated?
|
||||||
if (SharedApi.isChunkAtChunkPosAlreadyUpdating(levelWrapper, chunk.getPos().x, chunk.getPos().z))
|
if (SharedApi.isChunkAtChunkPosAlreadyUpdating(levelWrapper, chunkPosX, chunkPosZ))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -38,13 +50,13 @@ 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_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_17_1
|
||||||
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect())
|
if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect() || chunk instanceof ProtoChunk)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -55,7 +67,7 @@ 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_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_17_1
|
||||||
if (chunk.getBiomes() == null)
|
if (chunk.getBiomes() == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
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;
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
|
||||||
|
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
|
||||||
|
#if 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_21_6
|
||||||
|
public static boolean cancelFog(Camera camera, FogRenderer.FogMode fogMode)
|
||||||
|
#else
|
||||||
|
public static boolean cancelFog()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
#if 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
|
||||||
|
|
||||||
|
|
||||||
|
boolean cameraNotInFluid = cameraNotInFluid(camera);
|
||||||
|
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
|
||||||
|
|
||||||
|
boolean cancelFog = !isSpecialFog;
|
||||||
|
cancelFog = cancelFog && cameraNotInFluid;
|
||||||
|
#if 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean cameraNotInFluid(Camera camera)
|
||||||
|
{
|
||||||
|
#if 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+25
-24
@@ -29,7 +29,6 @@ import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
import com.mojang.blaze3d.buffers.Std140Builder;
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
|
||||||
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.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
@@ -39,6 +38,7 @@ 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.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.RenderPipelineBuilderWrapper;
|
||||||
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;
|
||||||
@@ -139,26 +139,27 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
}
|
}
|
||||||
private void createPipelines()
|
private void createPipelines()
|
||||||
{
|
{
|
||||||
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
|
{
|
||||||
|
pipelineBuilder.withFaceCulling(false);
|
||||||
|
pipelineBuilder.withDepthWrite(true);
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
pipelineBuilder.withColorWrite(true);
|
||||||
|
pipelineBuilder.withoutBlend();
|
||||||
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.WIREFRAME);
|
||||||
|
pipelineBuilder.withName("debug_wireframe_renderer");
|
||||||
|
|
||||||
|
pipelineBuilder.withVertexShader("debug/blaze/vert");
|
||||||
|
pipelineBuilder.withFragmentShader("debug/blaze/frag");
|
||||||
|
|
||||||
|
pipelineBuilder.withUniformBuffer("uniformBlock");
|
||||||
|
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = VertexFormat.builder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
||||||
.build();
|
.build();
|
||||||
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.LINES);
|
||||||
{
|
|
||||||
pipelineBuilder.withCull(false);
|
|
||||||
pipelineBuilder.withDepthWrite(false);
|
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.LESS_DEPTH_TEST);
|
|
||||||
pipelineBuilder.withColorWrite(true);
|
|
||||||
pipelineBuilder.withoutBlend();
|
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.WIREFRAME);
|
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:debug_wireframe_renderer"));
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "debug/blaze/vert"));
|
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "debug/blaze/frag"));
|
|
||||||
|
|
||||||
pipelineBuilder.withUniform("uniformBlock", UniformType.UNIFORM_BUFFER);
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat, VertexFormat.Mode.DEBUG_LINES);
|
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -225,15 +226,15 @@ public class BlazeDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Box box)
|
public void renderBox(Box box)
|
||||||
{
|
{
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
if (BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
//if (BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.isEmpty()
|
||||||
|| BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
// || BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.isEmpty())
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
// shouldn't happen, but just in case
|
// shouldn't happen, but just in case
|
||||||
if (box == null)
|
if (box == null)
|
||||||
|
|||||||
+73
-61
@@ -30,7 +30,6 @@ import com.mojang.blaze3d.buffers.Std140Builder;
|
|||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
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.DepthTestFunction;
|
|
||||||
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.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
@@ -49,6 +48,7 @@ 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.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.util.BlazeUniformUtil;
|
||||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||||
@@ -57,6 +57,7 @@ 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.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.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;
|
||||||
@@ -108,10 +109,7 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
// rendering setup
|
// rendering setup
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private VertexFormat vertexFormat;
|
private RenderPipeline pipeline;
|
||||||
|
|
||||||
private RenderPipeline opaquePipeline;
|
|
||||||
private RenderPipeline transparentPipeline;
|
|
||||||
|
|
||||||
private GpuBuffer vertUniformBuffer;
|
private GpuBuffer vertUniformBuffer;
|
||||||
|
|
||||||
@@ -132,12 +130,6 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
this.vertexFormat = VertexFormat.builder()
|
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
|
||||||
.add("aColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
|
||||||
.add("aMaterial", BlazeDhVertexFormatUtil.IRIS_MATERIAL)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.createPipelines();
|
this.createPipelines();
|
||||||
|
|
||||||
if (RENDER_DEBUG_OBJECTS)
|
if (RENDER_DEBUG_OBJECTS)
|
||||||
@@ -147,37 +139,36 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
private void createPipelines()
|
private void createPipelines()
|
||||||
{
|
{
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(true);
|
pipelineBuilder.withFaceCulling(true);
|
||||||
pipelineBuilder.withDepthWrite(true);
|
pipelineBuilder.withDepthWrite(true);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.LESS_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
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(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:generic"));
|
pipelineBuilder.withName("generic_objects");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "generic/blaze/vert"));
|
pipelineBuilder.withVertexShader("generic/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "generic/blaze/frag"));
|
pipelineBuilder.withFragmentShader("generic/blaze/frag");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uLightMap");
|
pipelineBuilder.withSampler("uLightMap");
|
||||||
|
|
||||||
pipelineBuilder.withUniform("vertUniformBlock", UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer("vertUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(this.vertexFormat, VertexFormat.Mode.TRIANGLES);
|
VertexFormat vertexFormat = VertexFormat.builder()
|
||||||
|
.add("vPosition", BlazeDhVertexFormatUtil.FLOAT_XYZ_POS)
|
||||||
|
.add("aColor", BlazeDhVertexFormatUtil.RGBA_UBYTE_COLOR)
|
||||||
|
.add("aMaterial", BlazeDhVertexFormatUtil.IRIS_MATERIAL)
|
||||||
|
|
||||||
|
.add("paddingOne", BlazeDhVertexFormatUtil.BYTE_PAD)
|
||||||
|
.add("paddingTwo", BlazeDhVertexFormatUtil.BYTE_PAD)
|
||||||
|
.add("paddingThree", BlazeDhVertexFormatUtil.BYTE_PAD)
|
||||||
|
.build();
|
||||||
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLES);
|
||||||
}
|
}
|
||||||
|
this.pipeline = pipelineBuilder.build();
|
||||||
// opaque
|
|
||||||
{
|
|
||||||
pipelineBuilder.withoutBlend();
|
|
||||||
this.opaquePipeline = pipelineBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// transparent
|
|
||||||
{
|
|
||||||
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT);
|
|
||||||
this.transparentPipeline = pipelineBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void addGenericDebugObjects()
|
private void addGenericDebugObjects()
|
||||||
{
|
{
|
||||||
@@ -303,7 +294,11 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"].");
|
throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"].");
|
||||||
}
|
}
|
||||||
RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup;
|
RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup;
|
||||||
|
if (boxGroup.size() != 0)
|
||||||
|
{
|
||||||
|
// trigger a box change to make sure the initial data is uploaded
|
||||||
|
boxGroup.triggerBoxChange();
|
||||||
|
}
|
||||||
|
|
||||||
long id = boxGroup.getId();
|
long id = boxGroup.getId();
|
||||||
if (this.boxGroupById.containsKey(id))
|
if (this.boxGroupById.containsKey(id))
|
||||||
@@ -336,13 +331,16 @@ 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);
|
||||||
@@ -497,22 +495,12 @@ 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()))
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
|
||||||
this::getRenderPassName,
|
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
|
||||||
{
|
{
|
||||||
this.renderBoxGroupInstanced(renderPass, renderEventParam, boxGroup, camPos, profiler);
|
this.renderBoxGroupInstanced(renderEventParam, boxGroup, profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.pop(); // resource path
|
|
||||||
profiler.pop(); // resource namespace
|
|
||||||
|
|
||||||
boxGroup.postRender(renderEventParam);
|
boxGroup.postRender(renderEventParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,10 +517,9 @@ 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:McGenericObjectRenderer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -545,13 +532,19 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
private void renderBoxGroupInstanced(
|
private void renderBoxGroupInstanced(
|
||||||
RenderPass renderPass, RenderParams renderEventParam,
|
RenderParams renderEventParam,
|
||||||
RenderableBoxGroup boxGroup, Vec3d camPos,
|
RenderableBoxGroup boxGroup,
|
||||||
IProfilerWrapper profiler)
|
IProfilerWrapper profiler)
|
||||||
{
|
{
|
||||||
// update instance data //
|
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
|
this::getRenderPassName,
|
||||||
|
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||||
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
|
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||||
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
|
{
|
||||||
|
|
||||||
profiler.push("vertex setup");
|
// update instance data //
|
||||||
|
|
||||||
BlazeGenericObjectVertexContainer container = (BlazeGenericObjectVertexContainer) boxGroup.vertexBufferContainer;
|
BlazeGenericObjectVertexContainer container = (BlazeGenericObjectVertexContainer) boxGroup.vertexBufferContainer;
|
||||||
|
|
||||||
@@ -562,30 +555,27 @@ public class BlazeDhGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
|
|
||||||
|
|
||||||
// Bind instance data //
|
// Bind instance data //
|
||||||
profiler.popPush("binding");
|
|
||||||
|
|
||||||
|
|
||||||
renderPass.setUniform("vertUniformBlock", this.vertUniformBuffer);
|
renderPass.setUniform("vertUniformBlock", this.vertUniformBuffer);
|
||||||
|
|
||||||
// set pipeline
|
// set pipeline
|
||||||
renderPass.setPipeline(this.opaquePipeline); // TODO
|
renderPass.setPipeline(this.pipeline);
|
||||||
renderPass.setIndexBuffer(container.indexGpuBuffer, VertexFormat.IndexType.INT);
|
renderPass.setIndexBuffer(container.indexGpuBuffer, VertexFormat.IndexType.INT);
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, container.vboGpuBuffer);
|
renderPass.setVertexBuffer(0, container.vboGpuBuffer);
|
||||||
|
|
||||||
// Draw instanced
|
// Draw instanced
|
||||||
profiler.popPush("render");
|
|
||||||
if (container.uploadedBoxCount > 0)
|
if (container.uploadedBoxCount > 0)
|
||||||
{
|
{
|
||||||
renderPass.drawIndexed(
|
renderPass.drawIndexed(
|
||||||
/*indexStart*/ 0,
|
/*indexStart*/ 0,
|
||||||
/*firstIndex*/0,
|
/*firstIndex*/0,
|
||||||
/*indexCount*/container.uploadedBoxCount * 24, // TODO?
|
/*indexCount*/container.uploadedBoxCount * 36, // 36 = 6 faces * 6 verticies per face
|
||||||
/*instanceCount*/1);
|
/*instanceCount*/1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -626,5 +616,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.vertUniformBuffer != null)
|
||||||
|
{
|
||||||
|
this.vertUniformBuffer.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+32
-10
@@ -6,18 +6,27 @@ 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.render.RenderParams;
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
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 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.*;
|
||||||
|
|
||||||
public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
||||||
{
|
{
|
||||||
public static final BlazeDhMetaRenderer INSTANCE = new BlazeDhMetaRenderer();
|
public static final BlazeDhMetaRenderer INSTANCE = new BlazeDhMetaRenderer();
|
||||||
|
|
||||||
|
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||||
|
|
||||||
|
|
||||||
private BlazeDhApplyRenderer applyRenderer;
|
private BlazeDhApplyRenderer applyRenderer;
|
||||||
|
|
||||||
@@ -52,9 +61,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
|
||||||
@@ -63,7 +87,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,12 +103,10 @@ public class BlazeDhMetaRenderer implements IDhMetaRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
public void clearDhDepthAndColorTextures(RenderParams renderParams)
|
||||||
{
|
{
|
||||||
// TODO use for clear color
|
|
||||||
//IMinecraftRenderWrapper r;
|
|
||||||
//r.getSkyColor()
|
|
||||||
|
|
||||||
this.dhDepthTextureWrapper.clearDepth(1.0f);
|
this.dhDepthTextureWrapper.clearDepth(1.0f);
|
||||||
this.dhColorTextureWrapper.clearColor(ColorUtil.argbToInt(1, 1, 1, 1));
|
|
||||||
|
Color color = MC_RENDER.getSkyColor();
|
||||||
|
this.dhColorTextureWrapper.clearColor(ColorUtil.toColorInt(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+50
-78
@@ -11,7 +11,6 @@ import com.mojang.blaze3d.buffers.Std140Builder;
|
|||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
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.DepthTestFunction;
|
|
||||||
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.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
@@ -20,20 +19,19 @@ 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.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.util.BlazeUniformUtil;
|
||||||
|
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.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.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
|
||||||
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.common.render.openGl.glObject.enums.GLEnums;
|
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GlQuadElementBuffer;
|
|
||||||
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;
|
||||||
@@ -45,7 +43,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhTe
|
|||||||
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 net.minecraft.resources.Identifier;
|
||||||
import org.lwjgl.opengl.GL32;
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -68,8 +65,6 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
private RenderPipeline transparentPipeline;
|
private RenderPipeline transparentPipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuBuffer indexBuffer;
|
|
||||||
|
|
||||||
private GpuBuffer fragUniformBuffer;
|
private GpuBuffer fragUniformBuffer;
|
||||||
private GpuBuffer vertSharedUniformBuffer;
|
private GpuBuffer vertSharedUniformBuffer;
|
||||||
|
|
||||||
@@ -88,9 +83,27 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.init = true; // todo only set when succeeded (in case of exception)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
|
{
|
||||||
|
pipelineBuilder.withFaceCulling(true);
|
||||||
|
pipelineBuilder.withDepthWrite(true);
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.LESS);
|
||||||
|
pipelineBuilder.withColorWrite(true);
|
||||||
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
|
pipelineBuilder.withName("terrain");
|
||||||
|
|
||||||
|
pipelineBuilder.withSampler("uLightMap");
|
||||||
|
|
||||||
|
pipelineBuilder.withVertexShader("lod/blaze/vert");
|
||||||
|
pipelineBuilder.withFragmentShader("lod/blaze/frag");
|
||||||
|
|
||||||
|
pipelineBuilder.withUniformBuffer("vertUniqueUniformBlock");
|
||||||
|
pipelineBuilder.withUniformBuffer("vertSharedUniformBlock");
|
||||||
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = VertexFormat.builder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SHORT_XYZ_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SHORT_XYZ_POS)
|
||||||
.add("meta", BlazeDhVertexFormatUtil.META)
|
.add("meta", BlazeDhVertexFormatUtil.META)
|
||||||
@@ -100,26 +113,9 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
.add("paddingTwo", BlazeDhVertexFormatUtil.BYTE_PAD)
|
.add("paddingTwo", BlazeDhVertexFormatUtil.BYTE_PAD)
|
||||||
.add("paddingThree", BlazeDhVertexFormatUtil.BYTE_PAD) // padding is to make sure the format is a multiple of 4
|
.add("paddingThree", BlazeDhVertexFormatUtil.BYTE_PAD) // padding is to make sure the format is a multiple of 4
|
||||||
.build();
|
.build();
|
||||||
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLES);
|
||||||
{
|
|
||||||
pipelineBuilder.withCull(true);
|
|
||||||
pipelineBuilder.withDepthWrite(true);
|
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.LESS_DEPTH_TEST);
|
|
||||||
pipelineBuilder.withColorWrite(true);
|
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:lod_render"));
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "lod/blaze/vert"));
|
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "lod/blaze/frag"));
|
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uLightMap");
|
|
||||||
|
|
||||||
pipelineBuilder.withUniform("vertUniqueUniformBlock", UniformType.UNIFORM_BUFFER);
|
|
||||||
pipelineBuilder.withUniform("vertSharedUniformBlock", UniformType.UNIFORM_BUFFER);
|
|
||||||
pipelineBuilder.withUniform("fragUniformBlock", UniformType.UNIFORM_BUFFER);
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat, VertexFormat.Mode.TRIANGLES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// opaque
|
// opaque
|
||||||
@@ -130,9 +126,12 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
// transparent
|
// transparent
|
||||||
{
|
{
|
||||||
|
// TRANSLUCENT = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT);
|
pipelineBuilder.withBlend(BlendFunction.TRANSLUCENT);
|
||||||
this.transparentPipeline = pipelineBuilder.build();
|
this.transparentPipeline = pipelineBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -153,8 +152,9 @@ 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 //
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
.putMat4f() // uCombinedMatrix
|
.putMat4f() // uCombinedMatrix
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
ByteBuffer buffer = MemoryUtil.memAlloc(uniformBufferSize);
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
buffer.order(ByteOrder.nativeOrder());
|
||||||
Std140Builder.intoBuffer(buffer)
|
Std140Builder.intoBuffer(buffer)
|
||||||
.putInt(0) // uIsWhiteWorld
|
.putInt(0) // uIsWhiteWorld
|
||||||
@@ -205,9 +205,9 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
.putFloat(earthCurveRatio) // uEarthRadius
|
.putFloat(earthCurveRatio) // uEarthRadius
|
||||||
|
|
||||||
.putVec3(
|
.putVec3(
|
||||||
(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.createJomlMatrix()) // uCombinedMatrix
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
@@ -215,6 +215,8 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vertSharedUniformBuffer, 0, uniformBufferSize);
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vertSharedUniformBuffer, 0, uniformBufferSize);
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
||||||
|
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.popPush("set frag uniforms");
|
profiler.popPush("set frag uniforms");
|
||||||
@@ -241,7 +243,7 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
// upload data //
|
// upload data //
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocateDirect(uniformBufferSize);
|
ByteBuffer buffer = MemoryUtil.memAlloc(uniformBufferSize);
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
buffer.order(ByteOrder.nativeOrder());
|
||||||
buffer = Std140Builder.intoBuffer(buffer)
|
buffer = Std140Builder.intoBuffer(buffer)
|
||||||
.putFloat(dhNearClipDistance) // uClipDistance
|
.putFloat(dhNearClipDistance) // uClipDistance
|
||||||
@@ -257,58 +259,32 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.fragUniformBuffer, 0, uniformBufferSize);
|
||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
||||||
}
|
MemoryUtil.memFree(buffer);
|
||||||
|
|
||||||
// create index buffer
|
|
||||||
{
|
|
||||||
if (this.indexBuffer == null)
|
|
||||||
{
|
|
||||||
ByteBuffer buffer = MemoryUtil.memAlloc(LodQuadBuilder.getMaxBufferByteSize() * GLEnums.getTypeSize(GL32.GL_UNSIGNED_INT) * 6);
|
|
||||||
GlQuadElementBuffer.buildBuffer(LodQuadBuilder.getMaxBufferByteSize(), buffer, GL32.GL_UNSIGNED_INT);
|
|
||||||
|
|
||||||
|
|
||||||
// create buffer if needed
|
|
||||||
if (this.indexBuffer == null
|
|
||||||
|| this.indexBuffer.size() < buffer.capacity())
|
|
||||||
{
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
|
||||||
| GpuBuffer.USAGE_VERTEX
|
|
||||||
| GpuBuffer.USAGE_INDEX
|
|
||||||
| GpuBuffer.USAGE_UNIFORM;
|
|
||||||
this.indexBuffer = GPU_DEVICE.createBuffer(this::getIndexBufferName, usage, buffer.capacity());
|
|
||||||
}
|
|
||||||
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.indexBuffer, /*offset*/ 0, buffer.capacity());
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render pass setup
|
// render pass setup
|
||||||
{
|
{
|
||||||
profiler.popPush("setup");
|
profiler.popPush("rendering");
|
||||||
|
|
||||||
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderPassEvent.class, renderEventParam);
|
||||||
|
|
||||||
// create a render pass
|
// create a render pass
|
||||||
OptionalInt optionalClearColorAsInt = OptionalInt.empty();
|
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
OptionalDouble optionalDepthValueAsDouble = OptionalDouble.empty();
|
|
||||||
|
|
||||||
try(RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
BlazeDhMetaRenderer.INSTANCE.dhColorTextureWrapper.textureView,
|
||||||
optionalClearColorAsInt,
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, optionalDepthValueAsDouble)
|
BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView,
|
||||||
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// bind MC Lightmap
|
|
||||||
//renderPass.bindTexture("uLightMap", this.mcLightTextureViewWrapper.textureView, this.mcLightTextureViewWrapper.textureSampler);
|
|
||||||
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);
|
renderPass.bindTexture("uLightMap", lightmapTextureViewWrapper.textureView, lightmapTextureViewWrapper.textureSampler);
|
||||||
|
|
||||||
// set pipeline
|
// set pipeline
|
||||||
renderPass.setPipeline(opaquePass ? this.opaquePipeline : this.transparentPipeline);
|
renderPass.setPipeline(opaquePass ? this.opaquePipeline : this.transparentPipeline);
|
||||||
renderPass.setIndexBuffer(this.indexBuffer, VertexFormat.IndexType.INT);
|
|
||||||
|
|
||||||
// shared uniforms
|
// shared uniforms
|
||||||
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
renderPass.setUniform("fragUniformBlock", this.fragUniformBuffer);
|
||||||
@@ -318,10 +294,8 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
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)
|
||||||
@@ -342,10 +316,8 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
profiler.popPush("rendering");
|
|
||||||
|
|
||||||
// render each buffer
|
// render each buffer
|
||||||
IVertexBufferWrapper[] bufferWrapperList = opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent;
|
IVertexBufferWrapper[] bufferWrapperList = opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers;
|
||||||
for (int i = 0; i < bufferWrapperList.length; i++)
|
for (int i = 0; i < bufferWrapperList.length; i++)
|
||||||
{
|
{
|
||||||
BlazeVertexBufferWrapper bufferWrapper = (BlazeVertexBufferWrapper) bufferWrapperList[i];
|
BlazeVertexBufferWrapper bufferWrapper = (BlazeVertexBufferWrapper) bufferWrapperList[i];
|
||||||
@@ -365,9 +337,10 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPass.setVertexBuffer(0, bufferWrapper.vboGpuBuffer); // vertex buffer can only be "0" lol
|
renderPass.setIndexBuffer(bufferWrapper.getIndexGpuBuffer(), VertexFormat.IndexType.INT);
|
||||||
|
renderPass.setVertexBuffer(0, bufferWrapper.vertexGpuBuffer); // vertex buffer can only be "0" lol
|
||||||
|
|
||||||
if (!bufferWrapper.vboGpuBuffer.isClosed())
|
if (!bufferWrapper.vertexGpuBuffer.isClosed())
|
||||||
{
|
{
|
||||||
renderPass.drawIndexed(
|
renderPass.drawIndexed(
|
||||||
/*indexStart*/ 0,
|
/*indexStart*/ 0,
|
||||||
@@ -380,8 +353,7 @@ public class BlazeDhTerrainRenderer implements IDhTerrainRenderer
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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:McLodRenderer"; }
|
||||||
|
|||||||
+26
-24
@@ -27,9 +27,6 @@ public class BlazeDhApplyRenderer {}
|
|||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
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.DepthTestFunction;
|
|
||||||
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.RenderPass;
|
||||||
@@ -37,12 +34,13 @@ 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.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.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.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -81,6 +79,10 @@ public class BlazeDhApplyRenderer
|
|||||||
private final BlazeTextureViewWrapper sourceDepthTextureViewWrapper = new BlazeTextureViewWrapper();
|
private final BlazeTextureViewWrapper sourceDepthTextureViewWrapper = new BlazeTextureViewWrapper();
|
||||||
|
|
||||||
private final BlazeTextureViewWrapper destinationColorTextureViewWrapper = new BlazeTextureViewWrapper();
|
private final BlazeTextureViewWrapper destinationColorTextureViewWrapper = new BlazeTextureViewWrapper();
|
||||||
|
/** We don't want to actually write any depth data, but blaze3D complains if we don't bind a depth texture. */
|
||||||
|
private final BlazeTextureWrapper dummyDepthTextureWrapper = BlazeTextureWrapper.createDepth("apply_dummy_depth");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be set for special application shaders that need
|
* Can be set for special application shaders that need
|
||||||
@@ -133,9 +135,13 @@ public class BlazeDhApplyRenderer
|
|||||||
GpuTexture sourceColorTexture,
|
GpuTexture sourceColorTexture,
|
||||||
GpuTexture sourceDepthTexture,
|
GpuTexture sourceDepthTexture,
|
||||||
GpuTexture destinationColorTexture)
|
GpuTexture destinationColorTexture)
|
||||||
|
{
|
||||||
|
// one-time setup
|
||||||
|
if (this.pipeline == null)
|
||||||
{
|
{
|
||||||
this.createPipeline();
|
this.createPipeline();
|
||||||
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData(this.name);
|
this.vboGpuBuffer = BlazePostProcessUtil.createAndUploadScreenVertexData(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
this.sourceColorTextureViewWrapper.tryWrap(sourceColorTexture);
|
this.sourceColorTextureViewWrapper.tryWrap(sourceColorTexture);
|
||||||
this.sourceDepthTextureViewWrapper.tryWrap(sourceDepthTexture);
|
this.sourceDepthTextureViewWrapper.tryWrap(sourceDepthTexture);
|
||||||
@@ -145,20 +151,11 @@ public class BlazeDhApplyRenderer
|
|||||||
}
|
}
|
||||||
private void createPipeline()
|
private void createPipeline()
|
||||||
{
|
{
|
||||||
if (this.pipeline != null)
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
return;
|
pipelineBuilder.withFaceCulling(false);
|
||||||
}
|
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
|
||||||
{
|
|
||||||
pipelineBuilder.withCull(false);
|
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
|
|
||||||
if (this.blendFunction != null)
|
if (this.blendFunction != null)
|
||||||
@@ -170,23 +167,26 @@ public class BlazeDhApplyRenderer
|
|||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
}
|
}
|
||||||
|
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse(this.identifierName)); // TODO will complain if capital letters are included
|
pipelineBuilder.withName(this.name);
|
||||||
|
|
||||||
// TODO manually validate paths to confirm they exist and end with ".fsh" or ".vsh", MC silently fails if the files are missing/improperly named
|
pipelineBuilder.withVertexShader(this.vertexShaderPath);
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", this.vertexShaderPath));
|
pipelineBuilder.withFragmentShader(this.fragmentShaderPath);
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", this.fragmentShaderPath));
|
|
||||||
|
|
||||||
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];
|
||||||
pipelineBuilder.withUniform(uniformName, UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer(uniformName);
|
||||||
}
|
}
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uSourceColorTexture");
|
pipelineBuilder.withSampler("uSourceColorTexture");
|
||||||
pipelineBuilder.withSampler("uSourceDepthTexture");
|
pipelineBuilder.withSampler("uSourceDepthTexture");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat, VertexFormat.Mode.TRIANGLE_FAN);
|
VertexFormat vertexFormat = VertexFormat.builder()
|
||||||
|
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
||||||
|
.build();
|
||||||
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
}
|
}
|
||||||
@@ -223,11 +223,13 @@ public class BlazeDhApplyRenderer
|
|||||||
{
|
{
|
||||||
this.tryInit(sourceColorTexture, sourceDepthTexture, destinationColorTexture);
|
this.tryInit(sourceColorTexture, sourceDepthTexture, destinationColorTexture);
|
||||||
|
|
||||||
|
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
this::getIdentifierName,
|
this::getIdentifierName,
|
||||||
this.destinationColorTextureViewWrapper.textureView,
|
this.destinationColorTextureViewWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.dummyDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uSourceColorTexture", this.sourceColorTextureViewWrapper.textureView, this.sourceColorTextureViewWrapper.textureSampler);
|
renderPass.bindTexture("uSourceColorTexture", this.sourceColorTextureViewWrapper.textureView, this.sourceColorTextureViewWrapper.textureSampler);
|
||||||
|
|||||||
+16
-13
@@ -26,20 +26,17 @@ public class BlazeDhCopyRenderer {}
|
|||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
import com.mojang.blaze3d.buffers.GpuBuffer;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
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.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.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.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 net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
@@ -63,6 +60,8 @@ public class BlazeDhCopyRenderer
|
|||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
|
private BlazeTextureWrapper dummyDepthTextureWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
@@ -81,23 +80,25 @@ public class BlazeDhCopyRenderer
|
|||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
|
|
||||||
|
this.dummyDepthTextureWrapper = BlazeTextureWrapper.createDepth("dh_copy_depth_texture");
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:copy_render"));
|
pipelineBuilder.withName("copy");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "copy/blaze/vert"));
|
pipelineBuilder.withVertexShader("copy/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "copy/blaze/frag"));
|
pipelineBuilder.withFragmentShader("copy/blaze/frag");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uCopyTexture");
|
pipelineBuilder.withSampler("uCopyTexture");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat(), VertexFormat.Mode.TRIANGLE_FAN);
|
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat());
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -139,11 +140,13 @@ public class BlazeDhCopyRenderer
|
|||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
|
this.dummyDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
destinationTextureView,
|
destinationTextureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.dummyDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uCopyTexture", sourceTextureView, sourceTextureSampler);
|
renderPass.bindTexture("uCopyTexture", sourceTextureView, sourceTextureSampler);
|
||||||
|
|||||||
+36
-22
@@ -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;
|
||||||
@@ -84,14 +84,10 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
//===========================//
|
//===========================//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
public void updateVertexData(List<DhApiRenderableBox> uploadBoxList)
|
public void updateVertexData(List<DhApiRenderableBox> uploadBoxList)
|
||||||
{
|
{
|
||||||
int boxCount = uploadBoxList.size();
|
int boxCount = uploadBoxList.size();
|
||||||
if (boxCount == 0)
|
|
||||||
{
|
|
||||||
return; // TODO done just to fix a buffer empty crash
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// recreate the data arrays if their size is different
|
// recreate the data arrays if their size is different
|
||||||
if (this.uploadedBoxCount != boxCount)
|
if (this.uploadedBoxCount != boxCount)
|
||||||
@@ -183,20 +179,24 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
this.vertexBuffer.put(a);
|
this.vertexBuffer.put(a);
|
||||||
|
|
||||||
this.vertexBuffer.put(box.material);
|
this.vertexBuffer.put(box.material);
|
||||||
// TODO make sure this all is a multiple of 4 like LodQuadBuilder (might cause issues with AMD/Mac otherwise)
|
|
||||||
|
// padding so the vertex format's byte count is a multiple of 4
|
||||||
|
this.vertexBuffer.put((byte)0);
|
||||||
|
this.vertexBuffer.put((byte)0);
|
||||||
|
this.vertexBuffer.put((byte)0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.vertexBuffer.flip();
|
this.vertexBuffer.flip();
|
||||||
this.indexBuffer.flip();
|
this.indexBuffer.flip();
|
||||||
|
|
||||||
|
|
||||||
this.state = BlazeGenericObjectVertexContainer.EState.READY_TO_UPLOAD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int vertexBufferSize()
|
private int vertexBufferSize()
|
||||||
{
|
{
|
||||||
int faceCount = this.uploadedBoxCount * 6;
|
// minimum of 1 box to prevent trying to create a buffer of size 0
|
||||||
int vertexCount = faceCount * 6;
|
int boxCount = Math.max(this.uploadedBoxCount, 1);
|
||||||
|
|
||||||
|
int faceCount = boxCount * 6; // 6 faces on a cube
|
||||||
|
int vertexCount = faceCount * 6; // 6 vertices per cube
|
||||||
|
|
||||||
int byteSize = vertexCount * 3 * Float.BYTES; // x,y,z
|
int byteSize = vertexCount * 3 * Float.BYTES; // x,y,z
|
||||||
byteSize += vertexCount * 4; // r,g,b,a
|
byteSize += vertexCount * 4; // r,g,b,a
|
||||||
@@ -205,19 +205,30 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
}
|
}
|
||||||
private int indexBufferSize()
|
private int indexBufferSize()
|
||||||
{
|
{
|
||||||
int quadCount = this.uploadedBoxCount * 36;
|
// minimum of 1 box to prevent trying to create a buffer of size 0
|
||||||
int byteSize = quadCount * GLEnums.getTypeSize(GL32.GL_UNSIGNED_INT) * 6;
|
int boxCount = Math.max(this.uploadedBoxCount, 1);
|
||||||
|
|
||||||
|
int quadCount = boxCount * 6 * 6; // 6 faces with 6 vertices each
|
||||||
|
int byteSize = quadCount * GLEnums.getTypeSize(GL32.GL_UNSIGNED_INT);
|
||||||
return byteSize;
|
return byteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void uploadDataToGpu()
|
public void uploadDataToGpu()
|
||||||
{
|
{
|
||||||
// vertex
|
// vertex
|
||||||
{
|
{
|
||||||
int totalVertexByteSize = this.vertexBufferSize();
|
int totalVertexByteSize = this.vertexBufferSize();
|
||||||
if (this.vboGpuBuffer == null
|
if (this.vboGpuBuffer == null
|
||||||
|| this.vboGpuBuffer.size() < totalVertexByteSize)
|
// recreating if the size changes is always necessary (even if we only need a smaller amount)
|
||||||
|
// due to a bug on Mac where it will attempt to render anything allocated in the buffer
|
||||||
|
|| this.vboGpuBuffer.size() != totalVertexByteSize)
|
||||||
{
|
{
|
||||||
|
if (this.vboGpuBuffer != null)
|
||||||
|
{
|
||||||
|
this.vboGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_VERTEX;
|
| GpuBuffer.USAGE_VERTEX;
|
||||||
this.vboGpuBuffer = GPU_DEVICE.createBuffer(this::getVertexBufferName, usage, totalVertexByteSize);
|
this.vboGpuBuffer = GPU_DEVICE.createBuffer(this::getVertexBufferName, usage, totalVertexByteSize);
|
||||||
@@ -231,12 +242,17 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
{
|
{
|
||||||
int totalVertexByteSize = this.indexBufferSize();
|
int totalVertexByteSize = this.indexBufferSize();
|
||||||
if (this.indexGpuBuffer == null
|
if (this.indexGpuBuffer == null
|
||||||
|| this.indexGpuBuffer.size() < totalVertexByteSize)
|
// recreating if the size changes is always necessary (even if we only need a smaller amount)
|
||||||
|
// due to a bug on Mac where it will attempt to render anything allocated in the buffer
|
||||||
|
|| this.indexGpuBuffer.size() != totalVertexByteSize)
|
||||||
{
|
{
|
||||||
|
if (this.indexGpuBuffer != null)
|
||||||
|
{
|
||||||
|
this.indexGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_VERTEX
|
| GpuBuffer.USAGE_INDEX;
|
||||||
| GpuBuffer.USAGE_INDEX
|
|
||||||
| GpuBuffer.USAGE_UNIFORM;
|
|
||||||
this.indexGpuBuffer = GPU_DEVICE.createBuffer(this::getIndexBufferName, usage, totalVertexByteSize);
|
this.indexGpuBuffer = GPU_DEVICE.createBuffer(this::getIndexBufferName, usage, totalVertexByteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,8 +261,6 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
|
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, this.indexBuffer);
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, this.indexBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = EState.RENDER;
|
|
||||||
}
|
}
|
||||||
private String getVertexBufferName() { return "distantHorizons:GenericVertexBuffer"; }
|
private String getVertexBufferName() { return "distantHorizons:GenericVertexBuffer"; }
|
||||||
private String getIndexBufferName() { return "distantHorizons:GenericIndexBuffer"; }
|
private String getIndexBufferName() { return "distantHorizons:GenericIndexBuffer"; }
|
||||||
@@ -263,7 +277,7 @@ public class BlazeGenericObjectVertexContainer implements IDhGenericObjectVertex
|
|||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread(() ->
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("BlazeGenericObjectVertexContainer close", () ->
|
||||||
{
|
{
|
||||||
if (this.vboGpuBuffer != null)
|
if (this.vboGpuBuffer != null)
|
||||||
{
|
{
|
||||||
|
|||||||
+21
-18
@@ -29,20 +29,18 @@ import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
import com.mojang.blaze3d.buffers.Std140Builder;
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
|
||||||
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.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.util.BlazeUniformUtil;
|
||||||
|
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.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;
|
||||||
@@ -50,7 +48,6 @@ 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.renderPass.IDhFarFadeRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFarFadeRenderer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@@ -76,8 +73,11 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
public final BlazeTextureWrapper dhFadeColorTextureWrapper = BlazeTextureWrapper.createColor("DhFadeColorTexture");
|
private final BlazeTextureWrapper dhFadeColorTextureWrapper = BlazeTextureWrapper.createColor("dh_far_fade_color_texture");
|
||||||
public final BlazeTextureViewWrapper mcColorTextureViewWrapper = new BlazeTextureViewWrapper();
|
/** We don't want to actually write any depth data, but blaze3D complains if we don't bind a depth texture. */
|
||||||
|
private final BlazeTextureWrapper dhFadeDepthTextureWrapper = BlazeTextureWrapper.createDepth("dh_far_fade_depth_texture");
|
||||||
|
|
||||||
|
private final BlazeTextureViewWrapper mcColorTextureViewWrapper = new BlazeTextureViewWrapper();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -98,27 +98,28 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:far_fade"));
|
pipelineBuilder.withName("far_fade");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "fade/blaze/vert"));
|
pipelineBuilder.withVertexShader("fade/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "fade/blaze/dh_fade"));
|
pipelineBuilder.withFragmentShader("fade/blaze/dh_fade");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uMcColorTexture");
|
pipelineBuilder.withSampler("uMcColorTexture");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uDhDepthTexture");
|
pipelineBuilder.withSampler("uDhDepthTexture");
|
||||||
pipelineBuilder.withSampler("uDhColorTexture");
|
pipelineBuilder.withSampler("uDhColorTexture");
|
||||||
|
|
||||||
pipelineBuilder.withUniform("fragUniformBlock", UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat(), VertexFormat.Mode.TRIANGLE_FAN);
|
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat());
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -151,7 +152,9 @@ 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();
|
||||||
|
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
int uniformBufferSize = new Std140SizeCalculator()
|
||||||
@@ -206,7 +209,7 @@ public class BlazeDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.dhFadeColorTextureWrapper.textureView,
|
this.dhFadeColorTextureWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.dhFadeDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
// MC texture
|
// MC texture
|
||||||
|
|||||||
+41
-31
@@ -24,27 +24,12 @@ 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.DepthTestFunction;
|
|
||||||
import com.mojang.blaze3d.platform.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.platform.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
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.api.enums.rendering.EDhApiFogColorMode;
|
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.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.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.util.BlazeUniformUtil;
|
||||||
@@ -58,7 +43,6 @@ 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.renderPass.IDhFogRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhFogRenderer;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -66,6 +50,24 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
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.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderPass;
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
@@ -91,7 +93,9 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
public BlazeTextureWrapper fogColorTextureWrapper = BlazeTextureWrapper.createColor("DhFogColorTexture");
|
private final BlazeTextureWrapper fogColorTextureWrapper = BlazeTextureWrapper.createColor("dh_fog_color_texture");
|
||||||
|
/** We don't want to actually write any depth data, but blaze3D complains if we don't bind a depth texture. */
|
||||||
|
private final BlazeTextureWrapper fogDepthTextureWrapper = BlazeTextureWrapper.createDepth("dh_fog_depth_texture");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -111,32 +115,38 @@ 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"
|
||||||
);
|
);
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:fog_render"));
|
pipelineBuilder.withName("fog_render");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "fog/blaze/vert"));
|
pipelineBuilder.withVertexShader("fog/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "fog/blaze/frag"));
|
pipelineBuilder.withFragmentShader("fog/blaze/frag");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uDhDepthTexture");
|
pipelineBuilder.withSampler("uDhDepthTexture");
|
||||||
|
|
||||||
pipelineBuilder.withUniform("fragUniformBlock", UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat(), VertexFormat.Mode.TRIANGLE_FAN);
|
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat());
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -168,7 +178,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
|
|
||||||
|
|
||||||
this.fogColorTextureWrapper.tryCreateOrResize();
|
this.fogColorTextureWrapper.tryCreateOrResize();
|
||||||
|
this.fogDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
{
|
{
|
||||||
int uniformBufferSize = new Std140SizeCalculator()
|
int uniformBufferSize = new Std140SizeCalculator()
|
||||||
@@ -339,7 +349,7 @@ public class BlazeDhFogRenderer implements IDhFogRenderer
|
|||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.fogColorTextureWrapper.textureView,
|
this.fogColorTextureWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.fogDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||||
|
|||||||
+44
-29
@@ -24,24 +24,9 @@ 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.DepthTestFunction;
|
|
||||||
import com.mojang.blaze3d.platform.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
|
||||||
import com.mojang.blaze3d.platform.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.shaders.UniformType;
|
|
||||||
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.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.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.util.BlazeUniformUtil;
|
||||||
@@ -53,13 +38,31 @@ 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.renderPass.IDhSsaoRenderer;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhSsaoRenderer;
|
||||||
import net.minecraft.resources.Identifier;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
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.BlendFactor;
|
||||||
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
|
import com.mojang.blaze3d.systems.RenderPass;
|
||||||
|
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
|
||||||
{
|
{
|
||||||
@@ -83,7 +86,9 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
public BlazeTextureWrapper ssaoColorTextureWrapper = BlazeTextureWrapper.createColor("DhSsaoTexture");
|
private final BlazeTextureWrapper ssaoColorTextureWrapper = BlazeTextureWrapper.createColor("dh_ssao_color_texture");
|
||||||
|
/** We don't want to actually write any depth data, but blaze3D complains if we don't bind a depth texture. */
|
||||||
|
private final BlazeTextureWrapper ssaoDepthTextureWrapper = BlazeTextureWrapper.createDepth("dh_ssao_depth_texture");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -103,31 +108,40 @@ 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" }
|
||||||
);
|
);
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:ssao_render"));
|
pipelineBuilder.withName("ssao_render");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "ssao/blaze/vert"));
|
pipelineBuilder.withVertexShader("ssao/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "ssao/blaze/frag"));
|
pipelineBuilder.withFragmentShader("ssao/blaze/frag");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uDhDepthTexture");
|
pipelineBuilder.withSampler("uDhDepthTexture");
|
||||||
|
|
||||||
pipelineBuilder.withUniform("fragUniformBlock", UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat(), VertexFormat.Mode.TRIANGLE_FAN);
|
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat());
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -160,6 +174,7 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
|
|
||||||
// textures
|
// textures
|
||||||
this.ssaoColorTextureWrapper.tryCreateOrResize();
|
this.ssaoColorTextureWrapper.tryCreateOrResize();
|
||||||
|
this.ssaoDepthTextureWrapper.tryCreateOrResize();
|
||||||
|
|
||||||
// frag uniforms
|
// frag uniforms
|
||||||
{
|
{
|
||||||
@@ -259,7 +274,7 @@ public class BlazeDhSsaoRenderer implements IDhSsaoRenderer
|
|||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.ssaoColorTextureWrapper.textureView,
|
this.ssaoColorTextureWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.ssaoDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
renderPass.bindTexture("uDhDepthTexture", BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureView, BlazeDhMetaRenderer.INSTANCE.dhDepthTextureWrapper.textureSampler);
|
||||||
|
|||||||
+22
-19
@@ -29,7 +29,6 @@ import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|||||||
import com.mojang.blaze3d.buffers.Std140Builder;
|
import com.mojang.blaze3d.buffers.Std140Builder;
|
||||||
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
import com.mojang.blaze3d.buffers.Std140SizeCalculator;
|
||||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
|
||||||
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.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
@@ -41,8 +40,10 @@ 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.util.BlazeUniformUtil;
|
||||||
|
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.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;
|
||||||
@@ -82,7 +83,10 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
public final BlazeTextureWrapper fadeColorTextureWrapper = BlazeTextureWrapper.createColor("DhVanillaFadeTexture");
|
public final BlazeTextureWrapper fadeColorTextureWrapper = BlazeTextureWrapper.createColor("DhVanillaFadeColorTexture");
|
||||||
|
/** We don't want to actually write any depth data, but blaze3D complains if we don't bind a depth texture. */
|
||||||
|
private final BlazeTextureWrapper fadeDepthTextureWrapper = BlazeTextureWrapper.createDepth("DhVanillaFadeDepthTexture");
|
||||||
|
|
||||||
|
|
||||||
public final BlazeTextureViewWrapper mcDepthTextureWrapper = new BlazeTextureViewWrapper();
|
public final BlazeTextureViewWrapper mcDepthTextureWrapper = new BlazeTextureViewWrapper();
|
||||||
public final BlazeTextureViewWrapper mcColorTextureWrapper = new BlazeTextureViewWrapper();
|
public final BlazeTextureViewWrapper mcColorTextureWrapper = new BlazeTextureViewWrapper();
|
||||||
@@ -106,18 +110,18 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
{
|
{
|
||||||
pipelineBuilder.withCull(false);
|
pipelineBuilder.withFaceCulling(false);
|
||||||
pipelineBuilder.withDepthWrite(false);
|
pipelineBuilder.withDepthWrite(false);
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
pipelineBuilder.withColorWrite(true);
|
pipelineBuilder.withColorWrite(true);
|
||||||
pipelineBuilder.withoutBlend();
|
pipelineBuilder.withoutBlend();
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
pipelineBuilder.withPolygonMode(RenderPipelineBuilderWrapper.EDhPolygonMode.FILL);
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:mc_vanilla_fade_render"));
|
pipelineBuilder.withName("vanilla_fade");
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "fade/blaze/vert"));
|
pipelineBuilder.withVertexShader("fade/blaze/vert");
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "fade/blaze/vanilla_fade"));
|
pipelineBuilder.withFragmentShader("fade/blaze/vanilla_fade");
|
||||||
|
|
||||||
pipelineBuilder.withSampler("uMcDepthTexture");
|
pipelineBuilder.withSampler("uMcDepthTexture");
|
||||||
pipelineBuilder.withSampler("uCombinedMcDhColorTexture");
|
pipelineBuilder.withSampler("uCombinedMcDhColorTexture");
|
||||||
@@ -125,9 +129,10 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
pipelineBuilder.withSampler("uDhDepthTexture");
|
pipelineBuilder.withSampler("uDhDepthTexture");
|
||||||
pipelineBuilder.withSampler("uDhColorTexture");
|
pipelineBuilder.withSampler("uDhColorTexture");
|
||||||
|
|
||||||
pipelineBuilder.withUniform("fragUniformBlock", UniformType.UNIFORM_BUFFER);
|
pipelineBuilder.withUniformBuffer("fragUniformBlock");
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat(), VertexFormat.Mode.TRIANGLE_FAN);
|
pipelineBuilder.withVertexFormat(BlazePostProcessUtil.createVertexFormat());
|
||||||
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLE_FAN);
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
@@ -158,9 +163,10 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
|
|
||||||
// textures
|
// textures
|
||||||
this.fadeColorTextureWrapper.tryCreateOrResize();
|
this.fadeColorTextureWrapper.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());
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -193,11 +199,8 @@ 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;
|
||||||
|
|
||||||
@@ -235,7 +238,7 @@ public class BlazeVanillaFadeRenderer implements IDhVanillaFadeRenderer
|
|||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.fadeColorTextureWrapper.textureView,
|
this.fadeColorTextureWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*depthTexture*/ null,
|
this.fadeDepthTextureWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.bindTexture("uMcDepthTexture", this.mcDepthTextureWrapper.textureView, this.mcDepthTextureWrapper.textureSampler);
|
renderPass.bindTexture("uMcDepthTexture", this.mcDepthTextureWrapper.textureView, this.mcDepthTextureWrapper.textureSampler);
|
||||||
|
|||||||
+28
-30
@@ -27,7 +27,6 @@ public class BlazeDhTestTriangleRenderer {}
|
|||||||
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.pipeline.RenderPipeline;
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.platform.DepthTestFunction;
|
|
||||||
import com.mojang.blaze3d.platform.PolygonMode;
|
import com.mojang.blaze3d.platform.PolygonMode;
|
||||||
import com.mojang.blaze3d.systems.CommandEncoder;
|
import com.mojang.blaze3d.systems.CommandEncoder;
|
||||||
import com.mojang.blaze3d.systems.GpuDevice;
|
import com.mojang.blaze3d.systems.GpuDevice;
|
||||||
@@ -36,6 +35,9 @@ 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.RenderPipelineBuilderWrapper;
|
||||||
|
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;
|
||||||
@@ -48,6 +50,12 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.pipeline.DepthStencilState;
|
||||||
|
import com.mojang.blaze3d.platform.CompareOp;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the OpenGL/Vulkan triangle
|
* Renders the OpenGL/Vulkan triangle
|
||||||
* to the center of the screen to confirm DH's
|
* to the center of the screen to confirm DH's
|
||||||
@@ -65,7 +73,8 @@ public class BlazeDhTestTriangleRenderer implements IDhTestTriangleRenderer
|
|||||||
private RenderPipeline pipeline;
|
private RenderPipeline pipeline;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
private GpuTextureView mcColorTextureView;
|
public final BlazeTextureViewWrapper mcColorTextureViewWrapper = new BlazeTextureViewWrapper();
|
||||||
|
public final BlazeTextureViewWrapper mcDepthTextureViewWrapper = new BlazeTextureViewWrapper();
|
||||||
|
|
||||||
private GpuBuffer vboGpuBuffer;
|
private GpuBuffer vboGpuBuffer;
|
||||||
|
|
||||||
@@ -86,42 +95,28 @@ public class BlazeDhTestTriangleRenderer implements IDhTestTriangleRenderer
|
|||||||
}
|
}
|
||||||
this.init = true;
|
this.init = true;
|
||||||
|
|
||||||
|
RenderPipelineBuilderWrapper pipelineBuilder = new RenderPipelineBuilderWrapper();
|
||||||
|
{
|
||||||
|
pipelineBuilder.withFaceCulling(false);
|
||||||
|
pipelineBuilder.withDepthWrite(false);
|
||||||
|
pipelineBuilder.withDepthTest(RenderPipelineBuilderWrapper.EDhDepthTest.NONE);
|
||||||
|
pipelineBuilder.withColorWrite(true);
|
||||||
|
pipelineBuilder.withoutBlend();
|
||||||
|
pipelineBuilder.withName("triangle_test");
|
||||||
|
|
||||||
|
pipelineBuilder.withVertexShader("test/blaze/vert");
|
||||||
|
pipelineBuilder.withFragmentShader("test/blaze/frag");
|
||||||
|
|
||||||
VertexFormat vertexFormat = VertexFormat.builder()
|
VertexFormat vertexFormat = VertexFormat.builder()
|
||||||
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
.add("vPosition", BlazeDhVertexFormatUtil.SCREEN_POS)
|
||||||
.add("vColor", BlazeDhVertexFormatUtil.RGBA_FLOAT_COLOR)
|
.add("vColor", BlazeDhVertexFormatUtil.RGBA_FLOAT_COLOR)
|
||||||
.build();
|
.build();
|
||||||
|
pipelineBuilder.withVertexFormat(vertexFormat);
|
||||||
|
|
||||||
//int breakpointOne = 0;
|
pipelineBuilder.withVertexMode(RenderPipelineBuilderWrapper.EDhVertexMode.TRIANGLES);
|
||||||
// needs to manually be set if the VertexFormatElement isn't registered
|
|
||||||
//this.vertexFormat.getOffsetsByElement()[this.posForm.id()] = 0;
|
|
||||||
//this.vertexFormat.getOffsetsByElement()[this.colForm.id()] = Float.BYTES * 2;
|
|
||||||
//
|
|
||||||
//int breakpointTwo = 0;
|
|
||||||
|
|
||||||
|
|
||||||
RenderPipeline.Builder pipelineBuilder = RenderPipeline.builder();
|
|
||||||
{
|
|
||||||
pipelineBuilder.withCull(false);
|
|
||||||
pipelineBuilder.withDepthWrite(false);
|
|
||||||
pipelineBuilder.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST);
|
|
||||||
pipelineBuilder.withColorWrite(true);
|
|
||||||
pipelineBuilder.withoutBlend();
|
|
||||||
pipelineBuilder.withPolygonMode(PolygonMode.FILL);
|
|
||||||
pipelineBuilder.withLocation(Identifier.parse("distanthorizons:test_render"));
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexShader(Identifier.fromNamespaceAndPath("distanthorizons", "test/blaze/vert"));
|
|
||||||
pipelineBuilder.withFragmentShader(Identifier.fromNamespaceAndPath("distanthorizons", "test/blaze/frag"));
|
|
||||||
|
|
||||||
pipelineBuilder.withVertexFormat(vertexFormat, VertexFormat.Mode.TRIANGLES);
|
|
||||||
}
|
}
|
||||||
this.pipeline = pipelineBuilder.build();
|
this.pipeline = pipelineBuilder.build();
|
||||||
|
|
||||||
|
|
||||||
this.mcColorTextureView = GPU_DEVICE.createTextureView(Minecraft.getInstance().getMainRenderTarget().getColorTexture());
|
|
||||||
|
|
||||||
|
|
||||||
this.uploadVertexData();
|
this.uploadVertexData();
|
||||||
}
|
}
|
||||||
private void uploadVertexData()
|
private void uploadVertexData()
|
||||||
@@ -170,11 +165,14 @@ public class BlazeDhTestTriangleRenderer implements IDhTestTriangleRenderer
|
|||||||
{
|
{
|
||||||
this.tryInit();
|
this.tryInit();
|
||||||
|
|
||||||
|
this.mcColorTextureViewWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getColorTexture());
|
||||||
|
this.mcDepthTextureViewWrapper.tryWrap(MinecraftRenderWrapper.INSTANCE.getRenderTarget().getDepthTexture());
|
||||||
|
|
||||||
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
try (RenderPass renderPass = COMMAND_ENCODER.createRenderPass(
|
||||||
this::getRenderPassName,
|
this::getRenderPassName,
|
||||||
this.mcColorTextureView,
|
this.mcColorTextureViewWrapper.textureView,
|
||||||
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
/*optionalClearColorAsInt*/ OptionalInt.empty(),
|
||||||
/*mcDepthTextureView*/ null,
|
this.mcDepthTextureViewWrapper.textureView,
|
||||||
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
/*optionalDepthValueAsDouble*/ OptionalDouble.empty()))
|
||||||
{
|
{
|
||||||
renderPass.setVertexBuffer(0, this.vboGpuBuffer);
|
renderPass.setVertexBuffer(0, this.vboGpuBuffer);
|
||||||
|
|||||||
+42
-10
@@ -5,6 +5,7 @@ public class BlazeDhVertexFormatUtil {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
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.EDhApiRenderApi;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
@@ -14,28 +15,29 @@ 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.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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see LodQuadBuilder
|
* @see LodQuadBuilder
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("DataFlowIssue") // ignore null setter warnings in the static constructor (those will only be null if the render API is GL and in that case we should never use these objects)
|
||||||
public class BlazeDhVertexFormatUtil
|
public class BlazeDhVertexFormatUtil
|
||||||
{
|
{
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull public static final VertexFormatElement SCREEN_POS;
|
||||||
|
@NotNull public static final VertexFormatElement RGBA_FLOAT_COLOR;
|
||||||
|
|
||||||
public static final VertexFormatElement SCREEN_POS;
|
@NotNull public static final VertexFormatElement SHORT_XYZ_POS;
|
||||||
public static final VertexFormatElement RGBA_FLOAT_COLOR;
|
@NotNull public static final VertexFormatElement BYTE_PAD;
|
||||||
|
|
||||||
public static final VertexFormatElement SHORT_XYZ_POS;
|
|
||||||
public static final VertexFormatElement BYTE_PAD;
|
|
||||||
/** contains light and micro-offset */
|
/** contains light and micro-offset */
|
||||||
public static final VertexFormatElement META;
|
@NotNull public static final VertexFormatElement META;
|
||||||
public static final VertexFormatElement RGBA_UBYTE_COLOR;
|
@NotNull public static final VertexFormatElement RGBA_UBYTE_COLOR;
|
||||||
public static final VertexFormatElement IRIS_MATERIAL;
|
@NotNull public static final VertexFormatElement IRIS_MATERIAL;
|
||||||
public static final VertexFormatElement IRIS_NORMAL;
|
@NotNull public static final VertexFormatElement IRIS_NORMAL;
|
||||||
|
|
||||||
public static final VertexFormatElement FLOAT_XYZ_POS;
|
@NotNull public static final VertexFormatElement FLOAT_XYZ_POS;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ public class BlazeDhVertexFormatUtil
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
SCREEN_POS = VertexFormatElement.register(/*id*/22, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, /*count*/ 2);
|
SCREEN_POS = VertexFormatElement.register(/*id*/22, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, /*count*/ 2);
|
||||||
RGBA_FLOAT_COLOR = VertexFormatElement.register(/*id*/23, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.COLOR, /*count*/ 4);
|
RGBA_FLOAT_COLOR = VertexFormatElement.register(/*id*/23, /*index*/0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.COLOR, /*count*/ 4);
|
||||||
|
|
||||||
@@ -68,6 +71,34 @@ 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);
|
||||||
|
#elif MC_VER <= MC_26_1_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);
|
||||||
|
|
||||||
|
SHORT_XYZ_POS = VertexFormatElement.register(/*id*/24, /*index*/0, VertexFormatElement.Type.USHORT, false, /*count*/ 3);
|
||||||
|
BYTE_PAD = VertexFormatElement.register(/*id*/25, /*index*/0, VertexFormatElement.Type.BYTE, false, /*count*/ 1);
|
||||||
|
|
||||||
|
META = VertexFormatElement.register(/*id*/26, /*index*/0, VertexFormatElement.Type.USHORT, false, /*count*/ 1);
|
||||||
|
RGBA_UBYTE_COLOR = VertexFormatElement.register(/*id*/27, /*index*/0, VertexFormatElement.Type.UBYTE, true, /*count*/ 4);
|
||||||
|
IRIS_MATERIAL = VertexFormatElement.register(/*id*/28, /*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);
|
||||||
|
#else
|
||||||
|
|
||||||
|
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
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -84,6 +115,7 @@ public class BlazeDhVertexFormatUtil
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// set to null so we can fail fast with a null pointer if we ever attempt to incorrectly use these
|
||||||
SCREEN_POS = null;
|
SCREEN_POS = null;
|
||||||
RGBA_FLOAT_COLOR = null;
|
RGBA_FLOAT_COLOR = null;
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -9,9 +9,13 @@ import com.mojang.blaze3d.buffers.GpuBuffer;
|
|||||||
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.core.logging.DhLogger;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
|
||||||
public class BlazeUniformUtil
|
public class BlazeUniformUtil
|
||||||
{
|
{
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
@@ -22,7 +26,11 @@ public class BlazeUniformUtil
|
|||||||
if (vboGpuBuffer == null
|
if (vboGpuBuffer == null
|
||||||
|| vboGpuBuffer.size() < size)
|
|| vboGpuBuffer.size() < size)
|
||||||
{
|
{
|
||||||
// GpuBuffer.USAGE_UNIFORM = 128
|
if (vboGpuBuffer != null)
|
||||||
|
{
|
||||||
|
vboGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_VERTEX
|
| GpuBuffer.USAGE_VERTEX
|
||||||
| GpuBuffer.USAGE_UNIFORM;
|
| GpuBuffer.USAGE_UNIFORM;
|
||||||
|
|||||||
+404
@@ -0,0 +1,404 @@
|
|||||||
|
package com.seibel.distanthorizons.common.render.blaze.wrappers;
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
public class RenderPipelineBuilderWrapper {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
|
import com.mojang.blaze3d.pipeline.*;
|
||||||
|
import com.mojang.blaze3d.platform.PolygonMode;
|
||||||
|
import com.mojang.blaze3d.shaders.UniformType;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
import com.mojang.blaze3d.platform.DepthTestFunction;
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.platform.CompareOp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class RenderPipelineBuilderWrapper
|
||||||
|
{
|
||||||
|
public static final String NAME_PREFIX = "distanthorizons:";
|
||||||
|
|
||||||
|
private static final String SHADER_RESOURCE_FOLDER = "assets/distanthorizons/shaders/";
|
||||||
|
|
||||||
|
private static final ClassLoader CLASS_LOADER = RenderPipelineBuilderWrapper.class.getClassLoader();
|
||||||
|
|
||||||
|
|
||||||
|
private final RenderPipeline.Builder blazePipelineBuilder;
|
||||||
|
|
||||||
|
// variables for specific builder options should be put next to their builder methods for simpler organization
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public RenderPipelineBuilderWrapper()
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder = RenderPipeline.builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==========//
|
||||||
|
// building //
|
||||||
|
//==========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
private boolean writeDepth = false;
|
||||||
|
public RenderPipelineBuilderWrapper withDepthWrite(boolean write)
|
||||||
|
{
|
||||||
|
this.writeDepth = write;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean writeColor = false;
|
||||||
|
public RenderPipelineBuilderWrapper withColorWrite(boolean write)
|
||||||
|
{
|
||||||
|
this.writeColor = write;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlendFunction blendFunction = null;
|
||||||
|
public RenderPipelineBuilderWrapper withBlend(BlendFunction blendFunction)
|
||||||
|
{
|
||||||
|
this.blendFunction = blendFunction;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public RenderPipelineBuilderWrapper withoutBlend()
|
||||||
|
{
|
||||||
|
this.blendFunction = null;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EDhDepthTest depthTest;
|
||||||
|
public RenderPipelineBuilderWrapper withDepthTest(EDhDepthTest depthTest)
|
||||||
|
{
|
||||||
|
this.depthTest = depthTest;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderPipelineBuilderWrapper withFaceCulling(boolean culling)
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder.withCull(culling);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderPipelineBuilderWrapper withPolygonMode(EDhPolygonMode dhMode)
|
||||||
|
{
|
||||||
|
PolygonMode blazeMode;
|
||||||
|
switch (dhMode)
|
||||||
|
{
|
||||||
|
case FILL:
|
||||||
|
blazeMode = PolygonMode.FILL;
|
||||||
|
break;
|
||||||
|
case WIREFRAME:
|
||||||
|
blazeMode = PolygonMode.WIREFRAME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No polygonMode defined for type ["+dhMode+"].");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withPolygonMode(blazeMode);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderPipelineBuilderWrapper withName(String name) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
// Identifiers must be of a specific format
|
||||||
|
if (!isValidIdentifier(name))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Non [a-z0-9/._-] character in name: ["+name+"].");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withLocation(Identifier.parse(NAME_PREFIX + name));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ArrayList<String> samplerNames = new ArrayList<>();
|
||||||
|
public RenderPipelineBuilderWrapper withSampler(String name) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.blazePipelineBuilder.withSampler(name);
|
||||||
|
#else
|
||||||
|
samplerNames.add(name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ArrayList<String> uniformBufferNames = new ArrayList<>();
|
||||||
|
public RenderPipelineBuilderWrapper withUniformBuffer(String name) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
this.blazePipelineBuilder.withUniform(name, UniformType.UNIFORM_BUFFER);
|
||||||
|
#else
|
||||||
|
uniformBufferNames.add(name);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private VertexFormat vertexFormat = null;
|
||||||
|
public RenderPipelineBuilderWrapper withVertexFormat(VertexFormat vertexFormat)
|
||||||
|
{
|
||||||
|
this.vertexFormat = vertexFormat;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EDhVertexMode vertexMode = null;
|
||||||
|
public RenderPipelineBuilderWrapper withVertexMode(EDhVertexMode vertexMode)
|
||||||
|
{
|
||||||
|
this.vertexMode = vertexMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderPipelineBuilderWrapper withVertexShader(String scriptResourcePath) { return this.withShader(EDhShaderType.VERTEX, scriptResourcePath); }
|
||||||
|
public RenderPipelineBuilderWrapper withFragmentShader(String scriptResourcePath) { return this.withShader(EDhShaderType.FRAGMENT, scriptResourcePath); }
|
||||||
|
private RenderPipelineBuilderWrapper withShader(EDhShaderType shaderType, String scriptResourcePath)
|
||||||
|
{
|
||||||
|
String fullShaderResourcePath = SHADER_RESOURCE_FOLDER + scriptResourcePath + shaderType.fileExtension;
|
||||||
|
|
||||||
|
// confirm the shader file exists
|
||||||
|
try (InputStream scriptListInputStream = CLASS_LOADER.getResourceAsStream(fullShaderResourcePath))
|
||||||
|
{
|
||||||
|
if (scriptListInputStream == null)
|
||||||
|
{
|
||||||
|
throw new NullPointerException("Failed to find the SQL Script list file [" + fullShaderResourcePath + "], no auto update scripts can be run.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
// shouldn't happen, but just in case
|
||||||
|
throw new RuntimeException("Unexpected issue closing resource stream for shader type: ["+shaderType+"] at: ["+fullShaderResourcePath+"], error: ["+e.getMessage()+"].", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (shaderType == EDhShaderType.VERTEX)
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder.withVertexShader(Identifier.parse(NAME_PREFIX + scriptResourcePath));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder.withFragmentShader(Identifier.parse(NAME_PREFIX + scriptResourcePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=====//
|
||||||
|
// end //
|
||||||
|
//=====//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public RenderPipeline build() throws UnsupportedOperationException
|
||||||
|
{
|
||||||
|
// depth/color
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withDepthWrite(this.writeDepth);
|
||||||
|
this.blazePipelineBuilder.withColorWrite(this.writeColor);
|
||||||
|
|
||||||
|
if (this.blendFunction != null)
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder.withBlend(this.blendFunction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.blazePipelineBuilder.withoutBlend();
|
||||||
|
}
|
||||||
|
|
||||||
|
DepthTestFunction depthTestFunction;
|
||||||
|
switch (this.depthTest)
|
||||||
|
{
|
||||||
|
case NONE:
|
||||||
|
depthTestFunction = DepthTestFunction.NO_DEPTH_TEST;
|
||||||
|
break;
|
||||||
|
case LESS:
|
||||||
|
depthTestFunction = DepthTestFunction.LESS_DEPTH_TEST;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No depth test defined for type ["+this.depthTest+"].");
|
||||||
|
}
|
||||||
|
this.blazePipelineBuilder.withDepthTestFunction(depthTestFunction);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
CompareOp compareOp;
|
||||||
|
switch (this.depthTest)
|
||||||
|
{
|
||||||
|
case NONE:
|
||||||
|
compareOp = CompareOp.ALWAYS_PASS;
|
||||||
|
break;
|
||||||
|
case LESS:
|
||||||
|
compareOp = CompareOp.LESS_THAN;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No depth test defined for type ["+this.depthTest+"].");
|
||||||
|
}
|
||||||
|
this.blazePipelineBuilder.withDepthStencilState(new DepthStencilState(compareOp, this.writeDepth));
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withColorTargetState(
|
||||||
|
new ColorTargetState(
|
||||||
|
Optional.ofNullable(this.blendFunction),
|
||||||
|
this.writeColor ? ColorTargetState.WRITE_ALL : ColorTargetState.WRITE_NONE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// vertex format
|
||||||
|
{
|
||||||
|
VertexFormat.Mode blazeVertexMode;
|
||||||
|
switch (this.vertexMode)
|
||||||
|
{
|
||||||
|
case TRIANGLES:
|
||||||
|
blazeVertexMode = VertexFormat.Mode.TRIANGLES;
|
||||||
|
break;
|
||||||
|
case TRIANGLE_FAN:
|
||||||
|
blazeVertexMode = VertexFormat.Mode.TRIANGLE_FAN;
|
||||||
|
break;
|
||||||
|
case LINES:
|
||||||
|
blazeVertexMode = VertexFormat.Mode.DEBUG_LINES;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("No vertex mode defined for type ["+this.vertexMode+"].");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.blazePipelineBuilder.withVertexFormat(vertexFormat, blazeVertexMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper methods //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
private static boolean isValidIdentifier(String identifier)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < identifier.length(); i++)
|
||||||
|
{
|
||||||
|
char ch = identifier.charAt(i);
|
||||||
|
if (!isValidNamespaceChar(ch))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private static boolean isValidNamespaceChar(final char ch)
|
||||||
|
{
|
||||||
|
return ch == '_'
|
||||||
|
|| ch == '-'
|
||||||
|
// only lower case characters
|
||||||
|
|| (ch >= 'a' && ch <= 'z')
|
||||||
|
|| (ch >= '0' && ch <= '9')
|
||||||
|
|| ch == '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper classes //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public enum EDhPolygonMode
|
||||||
|
{
|
||||||
|
FILL,
|
||||||
|
WIREFRAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum EDhVertexMode
|
||||||
|
{
|
||||||
|
TRIANGLES,
|
||||||
|
TRIANGLE_FAN,
|
||||||
|
LINES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum EDhDepthTest
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
LESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum EDhShaderType
|
||||||
|
{
|
||||||
|
FRAGMENT(".fsh"),
|
||||||
|
VERTEX(".vsh");
|
||||||
|
|
||||||
|
|
||||||
|
public final String fileExtension;
|
||||||
|
|
||||||
|
EDhShaderType(String fileExtension)
|
||||||
|
{
|
||||||
|
this.fileExtension = fileExtension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+132
-8
@@ -10,31 +10,86 @@ import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
|||||||
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.core.dataObjects.render.bufferBuilding.IndexBufferBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
||||||
|
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.render.RenderThreadTaskHandler;
|
||||||
|
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.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
||||||
{
|
{
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_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 static final AtomicInteger BUFFER_COUNT_REF = new AtomicInteger(0);
|
||||||
|
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public String getName() { return this.name; }
|
public String getName() { return this.name; }
|
||||||
|
|
||||||
public GpuBuffer vboGpuBuffer = null;
|
public GpuBuffer vertexGpuBuffer = null;
|
||||||
|
|
||||||
public int vertexCount = -1;
|
public int vertexCount = -1;
|
||||||
public int indexCount = -1;
|
public int indexCount = -1;
|
||||||
public boolean uploaded = false;
|
public boolean uploaded = false;
|
||||||
|
|
||||||
|
|
||||||
|
private GpuBuffer indexGpuBuffer = null;
|
||||||
|
private static GpuBuffer GLOBAL_INDEX_GPU_BUFFER = null;
|
||||||
|
public GpuBuffer getIndexGpuBuffer()
|
||||||
|
{
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
return GLOBAL_INDEX_GPU_BUFFER;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.indexGpuBuffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("Global IBO Creation", () ->
|
||||||
|
{
|
||||||
|
int maxSize = LodQuadBuilder.getMaxBufferByteSize();
|
||||||
|
int maxVertexCount = maxSize / LodQuadBuilder.BYTES_PER_VERTEX;
|
||||||
|
int maxQuadCount = (maxVertexCount / 4);
|
||||||
|
ByteBuffer indexBuffer = IndexBufferBuilder.createBuffer(maxQuadCount);
|
||||||
|
|
||||||
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
|
| GpuBuffer.USAGE_INDEX;
|
||||||
|
GLOBAL_INDEX_GPU_BUFFER = GPU_DEVICE.createBuffer(BlazeVertexBufferWrapper::getIndexBufferName, usage, indexBuffer.capacity());
|
||||||
|
|
||||||
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(GLOBAL_INDEX_GPU_BUFFER, /*offset*/ 0, indexBuffer.capacity());
|
||||||
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, indexBuffer);
|
||||||
|
|
||||||
|
MemoryUtil.memFree(indexBuffer);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BlazeVertexBufferWrapper(String name) { this.name = name; }
|
public BlazeVertexBufferWrapper(String name) { this.name = name; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -47,22 +102,82 @@ public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upload(ByteBuffer buffer, int vertexCount)
|
public void uploadVertexBuffer(ByteBuffer vertexBuffer, int vertexCount)
|
||||||
{
|
{
|
||||||
|
int oldVertexCount = this.vertexCount;
|
||||||
|
|
||||||
this.vertexCount = vertexCount;
|
this.vertexCount = vertexCount;
|
||||||
// 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
|
||||||
this.indexCount = (int)(vertexCount * 1.5);
|
this.indexCount = (int)(vertexCount * 1.5);
|
||||||
this.uploaded = true;
|
this.uploaded = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (this.vertexGpuBuffer == null
|
||||||
|
// recreating if the size changes is always necessary (even if we only need a smaller amount)
|
||||||
|
// due to a bug on Mac where it will attempt to render anything allocated in the buffer
|
||||||
|
|| oldVertexCount != vertexCount)
|
||||||
|
{
|
||||||
|
if (this.vertexGpuBuffer == null)
|
||||||
|
{
|
||||||
|
BUFFER_COUNT_REF.incrementAndGet();
|
||||||
|
//LOGGER.info("Create, count: ["+BUFFER_COUNT_REF.get()+"]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.vertexGpuBuffer != null)
|
||||||
|
{
|
||||||
|
this.vertexGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_COPY_DST
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_VERTEX;
|
| GpuBuffer.USAGE_VERTEX;
|
||||||
int byteSize = (buffer.limit() - buffer.position());
|
int byteSize = (vertexBuffer.limit() - vertexBuffer.position());
|
||||||
this.vboGpuBuffer = GPU_DEVICE.createBuffer(this::getName, usage, byteSize);
|
this.vertexGpuBuffer = GPU_DEVICE.createBuffer(this::getName, usage, byteSize);
|
||||||
|
|
||||||
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vboGpuBuffer, /*offset*/0, byteSize);
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.vertexGpuBuffer, /*offset*/0, byteSize);
|
||||||
COMMAND_ENCODER.writeToBuffer(bufferSlice, buffer);
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, vertexBuffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uploadIndexBuffer(ByteBuffer indexBuffer, int vertexCount)
|
||||||
|
{
|
||||||
|
int oldIndexCount = this.indexCount;
|
||||||
|
// 4 vertices per face, but 6 indices (IE 2 triangles) per face, aka need to multiply by 1.5
|
||||||
|
this.indexCount = (int)(vertexCount * 1.5);
|
||||||
|
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
// ignore index uploading when running a single IBO
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// recreating if the size changes is always necessary (even if we only need a smaller amount)
|
||||||
|
// due to a bug on Mac where it will attempt to render anything allocated in the buffer
|
||||||
|
if (this.indexGpuBuffer == null
|
||||||
|
|| oldIndexCount != this.indexCount)
|
||||||
|
{
|
||||||
|
if (this.indexGpuBuffer == null)
|
||||||
|
{
|
||||||
|
BUFFER_COUNT_REF.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.indexGpuBuffer != null)
|
||||||
|
{
|
||||||
|
this.indexGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int usage = GpuBuffer.USAGE_COPY_DST
|
||||||
|
| GpuBuffer.USAGE_INDEX;
|
||||||
|
this.indexGpuBuffer = GPU_DEVICE.createBuffer(BlazeVertexBufferWrapper::getIndexBufferName, usage, indexBuffer.capacity());
|
||||||
|
|
||||||
|
GpuBufferSlice bufferSlice = new GpuBufferSlice(this.indexGpuBuffer, /*offset*/ 0, indexBuffer.capacity());
|
||||||
|
COMMAND_ENCODER.writeToBuffer(bufferSlice, indexBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static String getIndexBufferName() { return "distantHorizons:LodIndexBuffer"; }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@@ -76,10 +191,19 @@ public class BlazeVertexBufferWrapper implements IVertexBufferWrapper
|
|||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
if (this.vboGpuBuffer != null)
|
if (this.vertexGpuBuffer != null)
|
||||||
{
|
{
|
||||||
this.vboGpuBuffer.close();
|
BUFFER_COUNT_REF.decrementAndGet();
|
||||||
|
this.vertexGpuBuffer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.indexGpuBuffer != null)
|
||||||
|
{
|
||||||
|
BUFFER_COUNT_REF.decrementAndGet();
|
||||||
|
this.indexGpuBuffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//LOGGER.info("Close, count: ["+BUFFER_COUNT_REF.get()+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
+62
-23
@@ -5,18 +5,24 @@ public class BlazeTextureWrapper {}
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.mojang.blaze3d.buffers.GpuBuffer;
|
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.coreapi.util.ColorUtil;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||||
|
|
||||||
|
import java.util.OptionalDouble;
|
||||||
|
|
||||||
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.mojang.blaze3d.textures.*;
|
import com.mojang.blaze3d.textures.*;
|
||||||
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.util.ColorUtil;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
|
||||||
|
|
||||||
import java.util.OptionalDouble;
|
#if MC_VER <= MC_26_1_2
|
||||||
|
|
||||||
|
#else
|
||||||
|
import com.mojang.blaze3d.GpuFormat;
|
||||||
|
#endif
|
||||||
|
|
||||||
public class BlazeTextureWrapper
|
public class BlazeTextureWrapper
|
||||||
{
|
{
|
||||||
@@ -29,7 +35,11 @@ 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 GpuTextureView textureView = null;
|
||||||
@@ -45,10 +55,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 +106,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();
|
||||||
@@ -103,18 +139,21 @@ public class BlazeTextureWrapper
|
|||||||
this.width = viewWidth;
|
this.width = viewWidth;
|
||||||
this.height = viewHeight;
|
this.height = viewHeight;
|
||||||
|
|
||||||
int usage = GpuBuffer.USAGE_HINT_CLIENT_STORAGE
|
int usage = GpuTexture.USAGE_COPY_DST
|
||||||
| GpuBuffer.USAGE_COPY_DST
|
| GpuTexture.USAGE_TEXTURE_BINDING
|
||||||
| GpuBuffer.USAGE_VERTEX
|
| GpuTexture.USAGE_COPY_SRC
|
||||||
| GpuBuffer.USAGE_UNIFORM;
|
| 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()
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-1
@@ -32,7 +32,7 @@ public class BlazeLodUniformBufferWrapper extends BlazeUniformBufferWrapper impl
|
|||||||
|
|
||||||
|
|
||||||
//========//
|
//========//
|
||||||
// ??? //
|
// upload //
|
||||||
//========//
|
//========//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
@@ -72,5 +72,7 @@ public class BlazeLodUniformBufferWrapper extends BlazeUniformBufferWrapper impl
|
|||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+3
-3
@@ -20,7 +20,7 @@
|
|||||||
package com.seibel.distanthorizons.common.render.openGl;
|
package com.seibel.distanthorizons.common.render.openGl;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLElementBuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLIndexBuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlAbstractVertexAttribute;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlAbstractVertexAttribute;
|
||||||
@@ -53,7 +53,7 @@ public class GlDhDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
// rendering setup
|
// rendering setup
|
||||||
private GlShaderProgram basicShader;
|
private GlShaderProgram basicShader;
|
||||||
private GLVertexBuffer vertexBuffer;
|
private GLVertexBuffer vertexBuffer;
|
||||||
private GLElementBuffer indexBuffer;
|
private GLIndexBuffer indexBuffer;
|
||||||
private GlAbstractVertexAttribute va;
|
private GlAbstractVertexAttribute va;
|
||||||
private boolean init = false;
|
private boolean init = false;
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ public class GlDhDebugWireframeRenderer extends AbstractDebugWireframeRenderer
|
|||||||
boxOutlineBuffer.order(ByteOrder.nativeOrder());
|
boxOutlineBuffer.order(ByteOrder.nativeOrder());
|
||||||
boxOutlineBuffer.asIntBuffer().put(BOX_OUTLINE_INDICES);
|
boxOutlineBuffer.asIntBuffer().put(BOX_OUTLINE_INDICES);
|
||||||
boxOutlineBuffer.rewind();
|
boxOutlineBuffer.rewind();
|
||||||
this.indexBuffer = new GLElementBuffer(false);
|
this.indexBuffer = new GLIndexBuffer(false);
|
||||||
this.indexBuffer.uploadBuffer(boxOutlineBuffer, EDhApiGpuUploadMethod.DATA, BOX_OUTLINE_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
this.indexBuffer.uploadBuffer(boxOutlineBuffer, EDhApiGpuUploadMethod.DATA, BOX_OUTLINE_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-15
@@ -8,13 +8,12 @@ import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhAp
|
|||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiTextureCreatedParam;
|
||||||
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.GlDhFramebuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GlDhFramebuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GlQuadElementBuffer;
|
|
||||||
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.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.dataObjects.render.bufferBuilding.LodQuadBuilder;
|
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;
|
||||||
@@ -22,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;
|
||||||
@@ -46,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;
|
||||||
@@ -96,7 +97,7 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
this.renderObjectsCreated = true;
|
this.renderObjectsCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.shaderProgramForThisFrame = GlDhTerrainShaderProgram.INSTANCE;
|
this.shaderProgramForThisFrame = GlDhTerrainRenderer.INSTANCE.getTerrainShaderProgram();
|
||||||
IDhApiShaderProgram lodShaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
IDhApiShaderProgram lodShaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiShaderProgram.class);
|
||||||
if (lodShaderProgramOverride != null && this.shaderProgramForThisFrame.overrideThisFrame())
|
if (lodShaderProgramOverride != null && this.shaderProgramForThisFrame.overrideThisFrame())
|
||||||
{
|
{
|
||||||
@@ -106,7 +107,6 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
this.setGLState(renderParams, firstPass);
|
this.setGLState(renderParams, firstPass);
|
||||||
|
|
||||||
GlDhTerrainShaderProgram.INSTANCE.quadIBO.bind();
|
|
||||||
this.bindLightmap(renderParams.lightmap);
|
this.bindLightmap(renderParams.lightmap);
|
||||||
}
|
}
|
||||||
private void setGLState(
|
private void setGLState(
|
||||||
@@ -242,12 +242,9 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
LOGGER.info("Setting up renderer");
|
LOGGER.info("Setting up renderer");
|
||||||
|
|
||||||
GlDhTerrainShaderProgram.INSTANCE.quadIBO = new GlQuadElementBuffer();
|
|
||||||
GlDhTerrainShaderProgram.INSTANCE.quadIBO.reserve(LodQuadBuilder.getMaxBufferByteSize());
|
|
||||||
|
|
||||||
|
|
||||||
// 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();
|
||||||
@@ -362,7 +359,6 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
|
|||||||
|
|
||||||
|
|
||||||
this.unbindLightmap();
|
this.unbindLightmap();
|
||||||
GlDhTerrainShaderProgram.INSTANCE.quadIBO.unbind();
|
|
||||||
this.shaderProgramForThisFrame.unbind();
|
this.shaderProgramForThisFrame.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,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];
|
||||||
@@ -414,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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -8,6 +8,7 @@ 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.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;
|
||||||
@@ -35,7 +36,7 @@ public class GlDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
|||||||
//region
|
//region
|
||||||
|
|
||||||
@Override public IDhMetaRenderer getMetaRenderer() { return GlDhMetaRenderer.INSTANCE; }
|
@Override public IDhMetaRenderer getMetaRenderer() { return GlDhMetaRenderer.INSTANCE; }
|
||||||
@Override public IDhTerrainRenderer getTerrainRenderer() { return GlDhTerrainShaderProgram.INSTANCE; }
|
@Override public IDhTerrainRenderer getTerrainRenderer() { return GlDhTerrainRenderer.INSTANCE; }
|
||||||
@Override public IDhSsaoRenderer getSsaoRenderer() { return GlDhSSAORenderer.INSTANCE; }
|
@Override public IDhSsaoRenderer getSsaoRenderer() { return GlDhSSAORenderer.INSTANCE; }
|
||||||
@Override public IDhFogRenderer getFogRenderer() { return GlDhFogRenderer.INSTANCE; }
|
@Override public IDhFogRenderer getFogRenderer() { return GlDhFogRenderer.INSTANCE; }
|
||||||
@Override public IDhFarFadeRenderer getFarFadeRenderer() { return GlDhFarFadeRenderer.INSTANCE; }
|
@Override public IDhFarFadeRenderer getFarFadeRenderer() { return GlDhFarFadeRenderer.INSTANCE; }
|
||||||
@@ -53,7 +54,7 @@ public class GlDhRenderApiDefinition extends AbstractDhRenderApiDefinition
|
|||||||
//===========//
|
//===========//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
@Override public IDhGenericRenderer createGenericRenderer() { return GlGenericObjectRenderer.INSTANCE; }
|
@Override public IDhGenericRenderer createGenericRenderer() { return new GlGenericObjectRenderer(); }
|
||||||
|
|
||||||
@Override public IVertexBufferWrapper createVboWrapper(String name) { return new GLVertexBuffer(); }
|
@Override public IVertexBufferWrapper createVboWrapper(String name) { return new GLVertexBuffer(); }
|
||||||
@Override public ILodContainerUniformBufferWrapper createLodContainerUniformWrapper() { return new GlDummyUniformData(); }
|
@Override public ILodContainerUniformBufferWrapper createLodContainerUniformWrapper() { return new GlDummyUniformData(); }
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package com.seibel.distanthorizons.common.render.openGl;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.render.openGl.terrain.GlDhTerrainShaderProgram;
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.LodBufferContainer;
|
||||||
|
import com.seibel.distanthorizons.core.render.RenderParams;
|
||||||
|
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.render.renderPass.IDhTerrainRenderer;
|
||||||
|
|
||||||
|
public class GlDhTerrainRenderer implements IDhTerrainRenderer
|
||||||
|
{
|
||||||
|
public static final GlDhTerrainRenderer INSTANCE = new GlDhTerrainRenderer();
|
||||||
|
|
||||||
|
private GlDhTerrainShaderProgram terrainShaderProgram = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
private GlDhTerrainRenderer() {}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// getters //
|
||||||
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
/** must be called on the render thread the first time so GL can run it's setup */
|
||||||
|
public GlDhTerrainShaderProgram getTerrainShaderProgram()
|
||||||
|
{
|
||||||
|
if (this.terrainShaderProgram == null)
|
||||||
|
{
|
||||||
|
this.terrainShaderProgram = new GlDhTerrainShaderProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.terrainShaderProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//========//
|
||||||
|
// render //
|
||||||
|
//========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(RenderParams renderEventParam, boolean opaquePass, SortedArraySet<LodBufferContainer> bufferContainers, IProfilerWrapper profiler)
|
||||||
|
{
|
||||||
|
this.getTerrainShaderProgram();
|
||||||
|
|
||||||
|
this.terrainShaderProgram.tryInit();
|
||||||
|
this.terrainShaderProgram.render(renderEventParam, opaquePass, bufferContainers, profiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+63
-27
@@ -30,7 +30,7 @@ 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.openGl.glObject.GLProxy;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.GLProxy;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLElementBuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLIndexBuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer;
|
||||||
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;
|
||||||
@@ -76,8 +76,6 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
private static final DhApiRenderableBoxGroupShading DEFAULT_SHADING = DhApiRenderableBoxGroupShading.getUnshaded();
|
private static final DhApiRenderableBoxGroupShading DEFAULT_SHADING = DhApiRenderableBoxGroupShading.getUnshaded();
|
||||||
|
|
||||||
|
|
||||||
public static final GlGenericObjectRenderer INSTANCE = new GlGenericObjectRenderer();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to troubleshoot the renderer.
|
* Can be used to troubleshoot the renderer.
|
||||||
* If enabled several debug objects will render around (0,150,0).
|
* If enabled several debug objects will render around (0,150,0).
|
||||||
@@ -91,7 +89,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
private IDhApiGenericObjectShaderProgram instancedShaderProgram;
|
private IDhApiGenericObjectShaderProgram instancedShaderProgram;
|
||||||
private IDhApiGenericObjectShaderProgram directShaderProgram;
|
private IDhApiGenericObjectShaderProgram directShaderProgram;
|
||||||
private GLVertexBuffer boxVertexBuffer;
|
private GLVertexBuffer boxVertexBuffer;
|
||||||
private GLElementBuffer boxIndexBuffer;
|
private GLIndexBuffer boxIndexBuffer;
|
||||||
|
|
||||||
private boolean instancedRenderingAvailable;
|
private boolean instancedRenderingAvailable;
|
||||||
private boolean vertexAttribDivisorSupported;
|
private boolean vertexAttribDivisorSupported;
|
||||||
@@ -176,7 +174,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
//=============//
|
//=============//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
private GlGenericObjectRenderer() { }
|
public GlGenericObjectRenderer() { }
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
@@ -195,6 +193,13 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
this.vertexAttribDivisorSupported = GLProxy.getInstance().vertexAttribDivisorSupported;
|
this.vertexAttribDivisorSupported = GLProxy.getInstance().vertexAttribDivisorSupported;
|
||||||
this.instancedArraysSupported = GLProxy.getInstance().instancedArraysSupported;
|
this.instancedArraysSupported = GLProxy.getInstance().instancedArraysSupported;
|
||||||
boolean isMac = (EPlatform.get() == EPlatform.MACOS);
|
boolean isMac = (EPlatform.get() == EPlatform.MACOS);
|
||||||
|
if (isMac)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Generic rendering not supported by Mac. Clouds, beacons, and some other effects will be disabled.");
|
||||||
|
Config.Client.Advanced.Graphics.GenericRendering.enableGenericRendering.setApiValue(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.instancedRenderingAvailable = (this.vertexAttribDivisorSupported || this.instancedArraysSupported) && !isMac;
|
this.instancedRenderingAvailable = (this.vertexAttribDivisorSupported || this.instancedArraysSupported) && !isMac;
|
||||||
if (!this.instancedRenderingAvailable)
|
if (!this.instancedRenderingAvailable)
|
||||||
{
|
{
|
||||||
@@ -232,7 +237,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
ByteBuffer solidIndexBuffer = MemoryUtil.memAlloc(BOX_INDICES.length * Integer.BYTES);
|
ByteBuffer solidIndexBuffer = MemoryUtil.memAlloc(BOX_INDICES.length * Integer.BYTES);
|
||||||
solidIndexBuffer.asIntBuffer().put(BOX_INDICES);
|
solidIndexBuffer.asIntBuffer().put(BOX_INDICES);
|
||||||
solidIndexBuffer.rewind();
|
solidIndexBuffer.rewind();
|
||||||
this.boxIndexBuffer = new GLElementBuffer(false);
|
this.boxIndexBuffer = new GLIndexBuffer(false);
|
||||||
this.boxIndexBuffer.uploadBuffer(solidIndexBuffer, EDhApiGpuUploadMethod.DATA, BOX_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
this.boxIndexBuffer.uploadBuffer(solidIndexBuffer, EDhApiGpuUploadMethod.DATA, BOX_INDICES.length * Integer.BYTES, GL32.GL_STATIC_DRAW);
|
||||||
this.boxIndexBuffer.bind();
|
this.boxIndexBuffer.bind();
|
||||||
MemoryUtil.memFree(solidIndexBuffer);
|
MemoryUtil.memFree(solidIndexBuffer);
|
||||||
@@ -361,6 +366,11 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"].");
|
throw new IllegalArgumentException("Box group must be of type ["+ RenderableBoxGroup.class.getSimpleName()+"], type received: ["+(iBoxGroup != null ? iBoxGroup.getClass() : "NULL")+"].");
|
||||||
}
|
}
|
||||||
RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup;
|
RenderableBoxGroup boxGroup = (RenderableBoxGroup) iBoxGroup;
|
||||||
|
if (boxGroup.size() != 0)
|
||||||
|
{
|
||||||
|
// trigger a box change to make sure the initial data is uploaded
|
||||||
|
boxGroup.triggerBoxChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
long id = boxGroup.getId();
|
long id = boxGroup.getId();
|
||||||
@@ -394,14 +404,20 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
@Override
|
@Override
|
||||||
public void render(RenderParams renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao)
|
public void render(RenderParams renderEventParam, IProfilerWrapper profiler, boolean renderingWithSsao)
|
||||||
{
|
{
|
||||||
|
// generic rendering (both instanced and direct) is extremely unstable on Mac, so don't render anything
|
||||||
|
if (EPlatform.get() == EPlatform.MACOS)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// render setup //
|
// render setup //
|
||||||
profiler.push("setup");
|
try (IProfilerWrapper.IProfileBlock setup_profile = profiler.push("setup"))
|
||||||
|
{
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|
||||||
boolean useInstancedRendering = this.instancedRenderingAvailable
|
|
||||||
&& Config.Client.Advanced.Graphics.GenericRendering.enableInstancedRendering.get();
|
|
||||||
|
|
||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam);
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeGenericRenderSetupEvent.class, renderEventParam);
|
||||||
|
|
||||||
|
|
||||||
@@ -421,7 +437,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
GL32.glBlendEquation(GL32.GL_FUNC_ADD);
|
||||||
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
GLMC.glBlendFuncSeparate(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA, GL32.GL_ONE, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
IDhApiGenericObjectShaderProgram shaderProgram = useInstancedRendering ? this.instancedShaderProgram : this.directShaderProgram;
|
IDhApiGenericObjectShaderProgram shaderProgram = this.instancedRenderingAvailable ? this.instancedShaderProgram : this.directShaderProgram;
|
||||||
IDhApiGenericObjectShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiGenericObjectShaderProgram.class);
|
IDhApiGenericObjectShaderProgram shaderProgramOverride = OverrideInjector.INSTANCE.get(IDhApiGenericObjectShaderProgram.class);
|
||||||
if (shaderProgramOverride != null && shaderProgram.overrideThisFrame())
|
if (shaderProgramOverride != null && shaderProgram.overrideThisFrame())
|
||||||
{
|
{
|
||||||
@@ -473,7 +489,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update instanced data if needed
|
// update instanced data if needed
|
||||||
if (useInstancedRendering)
|
if (this.instancedRenderingAvailable)
|
||||||
{
|
{
|
||||||
boxGroup.tryUpdateInstancedDataAsync();
|
boxGroup.tryUpdateInstancedDataAsync();
|
||||||
|
|
||||||
@@ -489,9 +505,10 @@ 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 (useInstancedRendering)
|
{
|
||||||
|
if (this.instancedRenderingAvailable)
|
||||||
{
|
{
|
||||||
this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler);
|
||||||
}
|
}
|
||||||
@@ -499,13 +516,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==========//
|
//==========//
|
||||||
// clean up //
|
// clean up //
|
||||||
//==========//
|
//==========//
|
||||||
@@ -522,8 +539,7 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
shaderProgram.unbind();
|
shaderProgram.unbind();
|
||||||
|
}
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -540,10 +556,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)
|
||||||
{
|
{
|
||||||
@@ -560,7 +576,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);
|
||||||
@@ -604,8 +620,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}
|
||||||
@@ -673,8 +688,6 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -735,4 +748,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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -105,10 +105,9 @@ public class GlGenericObjectVertexContainer implements IDhGenericObjectVertexBuf
|
|||||||
|
|
||||||
this.materialData[i] = box.material;
|
this.materialData[i] = box.material;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = GlGenericObjectVertexContainer.EState.READY_TO_UPLOAD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void uploadDataToGpu()
|
public void uploadDataToGpu()
|
||||||
{
|
{
|
||||||
this.tryCreateBuffers();
|
this.tryCreateBuffers();
|
||||||
@@ -128,8 +127,6 @@ public class GlGenericObjectVertexContainer implements IDhGenericObjectVertexBuf
|
|||||||
// Upload materials
|
// Upload materials
|
||||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.material);
|
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.material);
|
||||||
GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.materialData, GL32.GL_DYNAMIC_DRAW);
|
GL32.glBufferData(GL32.GL_ARRAY_BUFFER, this.materialData, GL32.GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
this.state = EState.RENDER;
|
|
||||||
}
|
}
|
||||||
/** needs to be done on the render thread */
|
/** needs to be done on the render thread */
|
||||||
private void tryCreateBuffers()
|
private void tryCreateBuffers()
|
||||||
|
|||||||
+43
-19
@@ -21,13 +21,17 @@ 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.EDhApiLoggerLevel;
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||||
|
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.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 +50,30 @@ 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)
|
|
||||||
.chatLevelConfig(Config.Common.Logging.logRendererGLEventToChat)
|
public static final DhLogger LOGGER;
|
||||||
.build();
|
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,6 +126,8 @@ public class GLProxy
|
|||||||
|
|
||||||
private GLProxy() throws IllegalStateException
|
private GLProxy() throws IllegalStateException
|
||||||
{
|
{
|
||||||
|
// TODO vulkan complain if created when MC is running on vulkan
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
@@ -220,16 +246,7 @@ public class GLProxy
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EDhApiGpuUploadMethod getGpuUploadMethod()
|
public EDhApiGpuUploadMethod getGpuUploadMethod() { return this.preferredUploadMethod; }
|
||||||
{
|
|
||||||
EDhApiGpuUploadMethod uploadOverride = Config.Client.Advanced.Debugging.OpenGl.glUploadMode.get();
|
|
||||||
if (uploadOverride == EDhApiGpuUploadMethod.AUTO)
|
|
||||||
{
|
|
||||||
return this.preferredUploadMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
return uploadOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean runningOnRenderThread()
|
public static boolean runningOnRenderThread()
|
||||||
{
|
{
|
||||||
@@ -247,7 +264,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)
|
||||||
@@ -258,19 +275,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
|
||||||
|
|
||||||
@@ -287,7 +311,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
|
||||||
|
|||||||
+312
-50
@@ -23,11 +23,17 @@ 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.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;
|
||||||
|
|
||||||
@@ -35,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
|
||||||
{
|
{
|
||||||
@@ -49,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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============//
|
//==============//
|
||||||
@@ -78,7 +118,7 @@ public class GLBuffer implements AutoCloseable
|
|||||||
|
|
||||||
static { CLEANUP_THREAD.execute(() -> runPhantomReferenceCleanupLoop()); }
|
static { CLEANUP_THREAD.execute(() -> runPhantomReferenceCleanupLoop()); }
|
||||||
|
|
||||||
public GLBuffer(boolean isBufferStorage) { this.create(isBufferStorage); }
|
public GLBuffer(boolean isBufferStorage) { this.destroyOldAndCreate(isBufferStorage); }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
@@ -104,21 +144,35 @@ public class GLBuffer implements AutoCloseable
|
|||||||
//====================//
|
//====================//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
protected void create(boolean asBufferStorage)
|
protected void destroyOldAndCreate(boolean asBufferStorage)
|
||||||
{
|
{
|
||||||
if (!GLProxy.runningOnRenderThread())
|
if (!GLProxy.runningOnRenderThread())
|
||||||
{
|
{
|
||||||
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
|
|
||||||
// (as of 2024-12-31 James didn't see this happen, but just in case)
|
// lock to prevent the render thread from accessing the buffer's ID
|
||||||
if (this.id != 0)
|
// while we are removing it
|
||||||
|
long writeStamp = renderStampLock.writeLock();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
destroyBufferIdAsync(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)
|
||||||
{
|
{
|
||||||
@@ -136,42 +201,69 @@ public class GLBuffer implements AutoCloseable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyBufferIdAsync(this.id);
|
final int idToDelete = this.id; // saving the ID to a separate variable is necessary so it can be captured by the lambda
|
||||||
|
|
||||||
|
// 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;
|
||||||
}
|
|
||||||
private static void destroyBufferIdAsync(int id)
|
|
||||||
{
|
|
||||||
// remove and clear the phantom reference if present
|
|
||||||
if (BUFFER_ID_TO_PHANTOM.containsKey(id))
|
|
||||||
{
|
|
||||||
Reference<? extends GLBuffer> phantom = BUFFER_ID_TO_PHANTOM.get(id);
|
|
||||||
|
|
||||||
|
//LOGGER.info("async destroy [" + idToDelete + "].");
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("GLBuffer destroyAsync", () -> { destroyBufferIdNow(idToDelete, "destroyAsync"); });
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
renderStampLock.unlock(writeStamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void destroyBufferIdNow(int id, String cause)
|
||||||
|
{
|
||||||
|
// only delete valid buffers
|
||||||
|
if (id == 0)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Attempted to destroy a buffer with ID 0, VRAM memory leaks may occur, cause: ["+cause+"].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferCount.decrementAndGet();
|
||||||
|
GLMC.glDeleteBuffers(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)
|
||||||
}
|
|
||||||
|
|
||||||
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread(() ->
|
|
||||||
{
|
{
|
||||||
// destroy the buffer if it exists,
|
LOGGER.warn("No Phantom->ID binding stored for ID ["+id+"]");
|
||||||
// the buffer may not exist if the destroy method is called twice
|
|
||||||
if (GL32.glIsBuffer(id))
|
|
||||||
{
|
|
||||||
GLMC.glDeleteBuffers(id);
|
|
||||||
bufferCount.decrementAndGet();
|
|
||||||
|
|
||||||
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
|
||||||
@@ -202,17 +294,26 @@ public class GLBuffer implements AutoCloseable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// re-binding the old buffers is necessary for old MC versions for the following reasons:
|
||||||
|
// for 16.5 and older the screen may be black when on the home menu
|
||||||
|
// 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
|
||||||
|
{
|
||||||
// make sure the buffer is ready for uploading
|
// make sure the buffer is ready for uploading
|
||||||
this.createOrChangeBufferTypeForUpload(uploadMethod);
|
this.createOrChangeBufferTypeForUpload(uploadMethod);
|
||||||
|
|
||||||
switch (uploadMethod)
|
switch (uploadMethod)
|
||||||
{
|
{
|
||||||
//case NONE:
|
|
||||||
// return;
|
|
||||||
case AUTO:
|
case AUTO:
|
||||||
LodUtil.assertNotReach("GpuUploadMethod AUTO must be resolved before call to uploadBuffer()!");
|
LodUtil.assertNotReach("GpuUploadMethod AUTO must be resolved before call to uploadBuffer()!");
|
||||||
case BUFFER_STORAGE:
|
case BUFFER_STORAGE:
|
||||||
this.uploadBufferStorage(bb, bufferHint);
|
this.uploadBufferStorage(bb);
|
||||||
break;
|
break;
|
||||||
case DATA:
|
case DATA:
|
||||||
this.uploadBufferData(bb, bufferHint);
|
this.uploadBufferData(bb, bufferHint);
|
||||||
@@ -224,14 +325,20 @@ public class GLBuffer implements AutoCloseable
|
|||||||
LodUtil.assertNotReach("Unknown GpuUploadMethod!");
|
LodUtil.assertNotReach("Unknown GpuUploadMethod!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
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 */
|
||||||
protected void uploadBufferStorage(ByteBuffer bb, int bufferStorageHint)
|
protected void uploadBufferStorage(ByteBuffer bb)
|
||||||
{
|
{
|
||||||
LodUtil.assertTrue(this.bufferStorage, "Buffer is not bufferStorage but its trying to use bufferStorage upload method!");
|
LodUtil.assertTrue(this.bufferStorage, "Buffer is not bufferStorage but its trying to use bufferStorage upload method!");
|
||||||
|
|
||||||
int bbSize = bb.limit() - bb.position();
|
int bbSize = bb.limit() - bb.position();
|
||||||
this.destroyAsync();
|
this.destroyOldAndCreate(true);
|
||||||
this.create(true);
|
|
||||||
this.bind();
|
this.bind();
|
||||||
GL44.glBufferStorage(this.getBufferBindingTarget(), bb, 0);
|
GL44.glBufferStorage(this.getBufferBindingTarget(), bb, 0);
|
||||||
this.size = bbSize;
|
this.size = bbSize;
|
||||||
@@ -242,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)
|
||||||
@@ -251,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
|
||||||
@@ -300,8 +440,7 @@ public class GLBuffer implements AutoCloseable
|
|||||||
{
|
{
|
||||||
// recreate if the buffer storage type changed
|
// recreate if the buffer storage type changed
|
||||||
this.bind();
|
this.bind();
|
||||||
this.destroyAsync();
|
this.destroyOldAndCreate(uploadMethod.useBufferStorage);
|
||||||
this.create(uploadMethod.useBufferStorage);
|
|
||||||
this.bind();
|
this.bind();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -310,13 +449,98 @@ public class GLBuffer implements AutoCloseable
|
|||||||
// This can happen if the buffer was deleted previously.
|
// This can happen if the buffer was deleted previously.
|
||||||
if (this.id == 0)
|
if (this.id == 0)
|
||||||
{
|
{
|
||||||
this.create(this.bufferStorage);
|
this.destroyOldAndCreate(this.bufferStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bind();
|
this.bind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
|
||||||
@@ -328,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
|
||||||
@@ -338,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);
|
||||||
destroyBufferIdAsync(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)
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-14
@@ -22,27 +22,26 @@ package com.seibel.distanthorizons.common.render.openGl.glObject.buffer;
|
|||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a container for a OpenGL
|
* AKA the GLElementBuffer
|
||||||
* VBO (Vertex Buffer Object).
|
|
||||||
*
|
*
|
||||||
* @author James Seibel
|
* @author James Seibel
|
||||||
* @version 11-20-2021
|
* @version 11-20-2021
|
||||||
*/
|
*/
|
||||||
public class GLElementBuffer extends GLBuffer
|
public class GLIndexBuffer extends GLBuffer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* When uploading to a buffer that is too small, recreate it this many times
|
* When uploading to a buffer that is too small, recreate it this many times
|
||||||
* bigger than the upload payload
|
* bigger than the upload payload
|
||||||
*/
|
*/
|
||||||
protected int indicesCount = 0;
|
protected int indicesCount = 0;
|
||||||
public int getIndicesCount() { return this.indicesCount; }
|
protected int glType = GL32.GL_UNSIGNED_INT;
|
||||||
protected int type = GL32.GL_UNSIGNED_INT;
|
public int getGlType() { return this.glType; }
|
||||||
public int getType() { return type; }
|
|
||||||
|
|
||||||
|
|
||||||
|
public GLIndexBuffer(boolean isBufferStorage) { super(isBufferStorage); }
|
||||||
|
|
||||||
|
|
||||||
public GLElementBuffer(boolean isBufferStorage)
|
|
||||||
{
|
|
||||||
super(isBufferStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyAsync()
|
public void destroyAsync()
|
||||||
@@ -52,9 +51,6 @@ public class GLElementBuffer extends GLBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBufferBindingTarget()
|
public int getBufferBindingTarget() { return GL32.GL_ELEMENT_ARRAY_BUFFER; }
|
||||||
{
|
|
||||||
return GL32.GL_ELEMENT_ARRAY_BUFFER;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+85
-3
@@ -22,11 +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.render.RenderThreadTaskHandler;
|
||||||
|
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
|
||||||
@@ -37,6 +42,8 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
|||||||
*/
|
*/
|
||||||
public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
||||||
{
|
{
|
||||||
|
private static final AbstractDhRenderApiDefinition RENDER_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When uploading to a buffer that is too small, recreate it this many times
|
* When uploading to a buffer that is too small, recreate it this many times
|
||||||
* bigger than the upload payload
|
* bigger than the upload payload
|
||||||
@@ -45,12 +52,46 @@ public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
|||||||
public int getVertexCount() { return this.vertexCount; }
|
public int getVertexCount() { return this.vertexCount; }
|
||||||
|
|
||||||
|
|
||||||
|
private GlQuadIndexBuffer quadIBO = null;
|
||||||
|
private static GlQuadIndexBuffer GLOBAL_QUAD_IBO = null;
|
||||||
|
public GlQuadIndexBuffer getQuadIBO()
|
||||||
|
{
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
return GLOBAL_QUAD_IBO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this.quadIBO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("Global IBO Creation", () ->
|
||||||
|
{
|
||||||
|
GLOBAL_QUAD_IBO = new GlQuadIndexBuffer();
|
||||||
|
|
||||||
|
int maxSize = LodQuadBuilder.getMaxBufferByteSize();
|
||||||
|
int maxVertexCount = maxSize / LodQuadBuilder.BYTES_PER_VERTEX;
|
||||||
|
int maxQuadCount = (maxVertexCount / 4);
|
||||||
|
|
||||||
|
ByteBuffer buffer = IndexBufferBuilder.createBuffer(maxQuadCount);
|
||||||
|
GLOBAL_QUAD_IBO.upload(buffer, maxQuadCount);
|
||||||
|
MemoryUtil.memFree(buffer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GLVertexBuffer() { this(GLProxy.getInstance().getGpuUploadMethod() == EDhApiGpuUploadMethod.BUFFER_STORAGE); }
|
public GLVertexBuffer() { this(GLProxy.getInstance().getGpuUploadMethod() == EDhApiGpuUploadMethod.BUFFER_STORAGE); }
|
||||||
public GLVertexBuffer(boolean isBufferStorage) { super(isBufferStorage); }
|
public GLVertexBuffer(boolean isBufferStorage) { super(isBufferStorage); }
|
||||||
|
|
||||||
@@ -67,7 +108,7 @@ public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
|||||||
public int getBufferBindingTarget() { return GL32.GL_ARRAY_BUFFER; }
|
public int getBufferBindingTarget() { return GL32.GL_ARRAY_BUFFER; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upload(ByteBuffer buffer, int vertexCount)
|
public void uploadVertexBuffer(ByteBuffer buffer, int vertexCount)
|
||||||
{
|
{
|
||||||
EDhApiGpuUploadMethod uploadMethod = GLProxy.getInstance().getGpuUploadMethod();
|
EDhApiGpuUploadMethod uploadMethod = GLProxy.getInstance().getGpuUploadMethod();
|
||||||
int maxBufferSize = LodQuadBuilder.getMaxBufferByteSize();
|
int maxBufferSize = LodQuadBuilder.getMaxBufferByteSize();
|
||||||
@@ -89,19 +130,60 @@ public class GLVertexBuffer extends GLBuffer implements IVertexBufferWrapper
|
|||||||
// If size is zero, just ignore it.
|
// If size is zero, just ignore it.
|
||||||
if (byteBuffer.limit() - byteBuffer.position() != 0)
|
if (byteBuffer.limit() - byteBuffer.position() != 0)
|
||||||
{
|
{
|
||||||
boolean useBuffStorage = uploadMethod.useBufferStorage;
|
super.uploadBuffer(byteBuffer, uploadMethod, maxExpansionSize, uploadMethod.useBufferStorage ? 0 : GL32.GL_STATIC_DRAW);
|
||||||
super.uploadBuffer(byteBuffer, uploadMethod, maxExpansionSize, useBuffStorage ? 0 : GL32.GL_STATIC_DRAW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vertexCount = vertexCount;
|
this.vertexCount = vertexCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uploadIndexBuffer(ByteBuffer buffer, int vertexCount)
|
||||||
|
{
|
||||||
|
if (RENDER_DEF.useSingleIbo())
|
||||||
|
{
|
||||||
|
// ignore index uploading when running a single IBO
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If size is zero, just ignore it.
|
||||||
|
if (vertexCount == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (this.quadIBO != null)
|
||||||
|
{
|
||||||
|
this.quadIBO.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.quadIBO = new GlQuadIndexBuffer();
|
||||||
|
|
||||||
|
int quadCount = (vertexCount / 4);
|
||||||
|
this.quadIBO.upload(buffer, quadCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// base overrides //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() { this.destroyAsync(); }
|
public void close() { this.destroyAsync(); }
|
||||||
@Override
|
@Override
|
||||||
public void destroyAsync()
|
public void destroyAsync()
|
||||||
{
|
{
|
||||||
super.destroyAsync();
|
super.destroyAsync();
|
||||||
|
if (this.quadIBO != null)
|
||||||
|
{
|
||||||
|
this.quadIBO.destroyAsync();
|
||||||
|
}
|
||||||
this.vertexCount = 0;
|
this.vertexCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-192
@@ -1,192 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.common.render.openGl.glObject.buffer;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.enums.GLEnums;
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
|
||||||
import org.lwjgl.opengl.GL32;
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
/** AKA Index Buffer TODO RENAME */
|
|
||||||
public class GlQuadElementBuffer extends GLElementBuffer
|
|
||||||
{
|
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
|
||||||
// constructor //
|
|
||||||
//=============//
|
|
||||||
//region
|
|
||||||
|
|
||||||
public GlQuadElementBuffer() { super(false); }
|
|
||||||
|
|
||||||
public void reserve(int quadCount)
|
|
||||||
{
|
|
||||||
if (quadCount < 0)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("quadCount must be greater than 0");
|
|
||||||
}
|
|
||||||
if (quadCount == 0)
|
|
||||||
{
|
|
||||||
// shouldn't happen, but just in case
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.indicesCount = quadCount * 6; // 2 triangles per quad
|
|
||||||
if (this.indicesCount >= this.getCapacity()
|
|
||||||
&& this.indicesCount < this.getCapacity() * BUFFER_SHRINK_TRIGGER)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int vertexCount = quadCount * 4; // 4 vertices per quad
|
|
||||||
|
|
||||||
if (vertexCount < 255)
|
|
||||||
{
|
|
||||||
// Reserve 1 for the reset index
|
|
||||||
this.type = GL32.GL_UNSIGNED_BYTE;
|
|
||||||
}
|
|
||||||
else if (vertexCount < 65535)
|
|
||||||
{
|
|
||||||
// Reserve 1 for the reset index
|
|
||||||
this.type = GL32.GL_UNSIGNED_SHORT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.type = GL32.GL_UNSIGNED_INT;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteBuffer buffer = MemoryUtil.memAlloc(this.indicesCount * GLEnums.getTypeSize(this.type));
|
|
||||||
buildBuffer(quadCount, buffer, this.type);
|
|
||||||
this.bind();
|
|
||||||
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.DATA,
|
|
||||||
this.indicesCount * GLEnums.getTypeSize(this.type), GL32.GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
MemoryUtil.memFree(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=========//
|
|
||||||
// getters //
|
|
||||||
//=========//
|
|
||||||
//region
|
|
||||||
|
|
||||||
public int getCapacity() { return super.getSize() / GLEnums.getTypeSize(this.getType()); }
|
|
||||||
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==========//
|
|
||||||
// building //
|
|
||||||
//==========//
|
|
||||||
//region
|
|
||||||
|
|
||||||
public static void buildBuffer(int quadCount, ByteBuffer buffer, int type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case GL32.GL_UNSIGNED_BYTE:
|
|
||||||
buildBufferByte(quadCount, buffer);
|
|
||||||
break;
|
|
||||||
case GL32.GL_UNSIGNED_SHORT:
|
|
||||||
buildBufferShort(quadCount, buffer);
|
|
||||||
break;
|
|
||||||
case GL32.GL_UNSIGNED_INT:
|
|
||||||
buildBufferInt(quadCount, buffer);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unknown buffer type: [" + type + "].");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void buildBufferByte(int quadCount, ByteBuffer buffer)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < quadCount; i++)
|
|
||||||
{
|
|
||||||
int vIndex = i * 4;
|
|
||||||
// First triangle
|
|
||||||
buffer.put((byte) (vIndex));
|
|
||||||
buffer.put((byte) (vIndex + 1));
|
|
||||||
buffer.put((byte) (vIndex + 2));
|
|
||||||
// Second triangle
|
|
||||||
buffer.put((byte) (vIndex + 2));
|
|
||||||
buffer.put((byte) (vIndex + 3));
|
|
||||||
buffer.put((byte) (vIndex));
|
|
||||||
}
|
|
||||||
if (buffer.hasRemaining())
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
|
|
||||||
}
|
|
||||||
buffer.rewind();
|
|
||||||
}
|
|
||||||
private static void buildBufferShort(int quadCount, ByteBuffer buffer)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < quadCount; i++)
|
|
||||||
{
|
|
||||||
int vIndex = i * 4;
|
|
||||||
// First triangle
|
|
||||||
buffer.putShort((short) (vIndex));
|
|
||||||
buffer.putShort((short) (vIndex + 1));
|
|
||||||
buffer.putShort((short) (vIndex + 2));
|
|
||||||
// Second triangle
|
|
||||||
buffer.putShort((short) (vIndex + 2));
|
|
||||||
buffer.putShort((short) (vIndex + 3));
|
|
||||||
buffer.putShort((short) (vIndex));
|
|
||||||
}
|
|
||||||
if (buffer.hasRemaining())
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
|
|
||||||
}
|
|
||||||
buffer.rewind();
|
|
||||||
}
|
|
||||||
private static void buildBufferInt(int quadCount, ByteBuffer buffer)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < quadCount; i++)
|
|
||||||
{
|
|
||||||
int vIndex = i * 4;
|
|
||||||
// First triangle
|
|
||||||
buffer.putInt(vIndex);
|
|
||||||
buffer.putInt(vIndex + 1);
|
|
||||||
buffer.putInt(vIndex + 2);
|
|
||||||
// Second triangle
|
|
||||||
buffer.putInt(vIndex + 2);
|
|
||||||
buffer.putInt(vIndex + 3);
|
|
||||||
buffer.putInt(vIndex);
|
|
||||||
}
|
|
||||||
if (buffer.hasRemaining())
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("QuadElementBuffer is not full somehow after building");
|
|
||||||
}
|
|
||||||
buffer.rewind();
|
|
||||||
}
|
|
||||||
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.render.openGl.glObject.buffer;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
|
||||||
|
import com.seibel.distanthorizons.common.render.openGl.glObject.enums.GLEnums;
|
||||||
|
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.IndexBufferBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import org.lwjgl.opengl.GL32;
|
||||||
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
/** aka GlQuadElementBuffer */
|
||||||
|
public class GlQuadIndexBuffer extends GLIndexBuffer
|
||||||
|
{
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public GlQuadIndexBuffer() { super(false); }
|
||||||
|
|
||||||
|
public void upload(ByteBuffer buffer, int quadCount)
|
||||||
|
{
|
||||||
|
if (quadCount < 0)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("quadCount must be greater than 0");
|
||||||
|
}
|
||||||
|
if (quadCount == 0)
|
||||||
|
{
|
||||||
|
// shouldn't happen, but just in case
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.indicesCount = quadCount * 6; // 2 triangles per quad
|
||||||
|
if (this.indicesCount >= this.getCapacity()
|
||||||
|
&& this.indicesCount < this.getCapacity() * BUFFER_SHRINK_TRIGGER)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.glType = GL32.GL_UNSIGNED_INT;
|
||||||
|
super.uploadBuffer(buffer, EDhApiGpuUploadMethod.DATA,
|
||||||
|
this.indicesCount * GLEnums.getTypeSize(this.glType), GL32.GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// getters //
|
||||||
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public int getCapacity() { return super.getSize() / GLEnums.getTypeSize(this.getGlType()); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -57,7 +57,7 @@ public class GlDhApplyShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/shared/gl/apply.frag",
|
"assets/distanthorizons/shaders/shared/gl/apply.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ public class GlDhFarFadeApplyShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/fade/gl/apply.frag",
|
"assets/distanthorizons/shaders/fade/gl/apply.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
-8
@@ -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
|
||||||
@@ -141,8 +139,6 @@ public class GlDhFarFadeRenderer implements IDhFarFadeRenderer
|
|||||||
GlDhFarFadeShader.INSTANCE.setProjectionMatrix(renderParams.mcModelViewMatrix, renderParams.mcProjectionMatrix);
|
GlDhFarFadeShader.INSTANCE.setProjectionMatrix(renderParams.mcModelViewMatrix, renderParams.mcProjectionMatrix);
|
||||||
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
|
||||||
|
|||||||
+2
-2
@@ -69,8 +69,8 @@ public class GlDhFarFadeShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/fade/gl/dhFade.frag",
|
"assets/distanthorizons/shaders/fade/gl/dh_fade.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -77,8 +77,8 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/fade/gl/vanillaFade.frag",
|
"assets/distanthorizons/shaders/fade/gl/vanilla_fade.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+4
-13
@@ -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
|
||||||
@@ -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 = GlDhFarFadeShader.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class GlDhFogApplyShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/fog/gl/apply.frag",
|
"assets/distanthorizons/shaders/fog/gl/apply.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ public class GlDhFogShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/fog/gl/fog.frag",
|
"assets/distanthorizons/shaders/fog/gl/fog.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ public class GlDhSSAOApplyShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/ssao/gl/apply.frag",
|
"assets/distanthorizons/shaders/ssao/gl/apply.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ public class GlDhSSAOShader extends GlAbstractShaderRenderer
|
|||||||
public void onInit()
|
public void onInit()
|
||||||
{
|
{
|
||||||
this.shader = new GlShaderProgram(
|
this.shader = new GlShaderProgram(
|
||||||
"assets/distanthorizons/shaders/shared/gl/quadApply.vert",
|
"assets/distanthorizons/shaders/shared/gl/quad_apply.vert",
|
||||||
"assets/distanthorizons/shaders/ssao/gl/ao.frag",
|
"assets/distanthorizons/shaders/ssao/gl/ao.frag",
|
||||||
"vPosition"
|
"vPosition"
|
||||||
);
|
);
|
||||||
|
|||||||
+56
-34
@@ -1,31 +1,12 @@
|
|||||||
/*
|
package com.seibel.distanthorizons.common.render.openGl.terrain;
|
||||||
* 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.common.render.openGl;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
|
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram;
|
||||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||||
|
import com.seibel.distanthorizons.common.render.openGl.GlDhMetaRenderer;
|
||||||
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.buffer.GLVertexBuffer;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GlQuadElementBuffer;
|
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.shader.GlShaderProgram;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlAbstractVertexAttribute;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlAbstractVertexAttribute;
|
||||||
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlVertexAttributePostGL43;
|
import com.seibel.distanthorizons.common.render.openGl.glObject.vertexAttribute.GlVertexAttributePostGL43;
|
||||||
@@ -49,7 +30,6 @@ 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.modAccessor.IIrisAccessor;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||||
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.IDhTerrainRenderer;
|
|
||||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||||
import org.lwjgl.opengl.GL32;
|
import org.lwjgl.opengl.GL32;
|
||||||
|
|
||||||
@@ -57,21 +37,19 @@ import org.lwjgl.opengl.GL32;
|
|||||||
* Handles rendering the normal LOD terrain.
|
* Handles rendering the normal LOD terrain.
|
||||||
* @see LodQuadBuilder
|
* @see LodQuadBuilder
|
||||||
*/
|
*/
|
||||||
public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiShaderProgram, IDhTerrainRenderer
|
public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiShaderProgram
|
||||||
{
|
{
|
||||||
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
public static final DhLogger LOGGER = new DhLoggerBuilder()
|
||||||
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
.fileLevelConfig(Config.Common.Logging.logRendererEventToFile)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final GlDhTerrainShaderProgram INSTANCE = new GlDhTerrainShaderProgram();
|
|
||||||
|
|
||||||
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 boolean init = false;
|
||||||
|
|
||||||
public GlQuadElementBuffer quadIBO = null;
|
public GlAbstractVertexAttribute vao;
|
||||||
public final GlAbstractVertexAttribute vao;
|
|
||||||
|
|
||||||
// uniforms //
|
// uniforms //
|
||||||
//region
|
//region
|
||||||
@@ -106,13 +84,22 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
//=============//
|
//=============//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
private GlDhTerrainShaderProgram()
|
public GlDhTerrainShaderProgram()
|
||||||
{
|
{
|
||||||
super(
|
super(
|
||||||
"assets/distanthorizons/shaders/shared/gl/standard.vert",
|
"assets/distanthorizons/shaders/shared/gl/standard.vert",
|
||||||
"assets/distanthorizons/shaders/shared/gl/flat_shaded.frag",
|
"assets/distanthorizons/shaders/shared/gl/flat_shaded.frag",
|
||||||
new String[]{"vPosition", "color"}
|
new String[]{"vPosition", "color"}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tryInit()
|
||||||
|
{
|
||||||
|
if (this.init)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.uCombinedMatrix = this.getUniformLocation("uCombinedMatrix");
|
this.uCombinedMatrix = this.getUniformLocation("uCombinedMatrix");
|
||||||
this.uModelOffset = this.getUniformLocation("uModelOffset");
|
this.uModelOffset = this.getUniformLocation("uModelOffset");
|
||||||
@@ -165,6 +152,10 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unbinding here is necessary to fix an issue when running on Legacy GL
|
||||||
|
this.vao.unbind();
|
||||||
|
|
||||||
|
this.init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -179,6 +170,7 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
@Override
|
@Override
|
||||||
public void bind()
|
public void bind()
|
||||||
{
|
{
|
||||||
|
this.tryInit();
|
||||||
super.bind();
|
super.bind();
|
||||||
this.vao.bind();
|
this.vao.bind();
|
||||||
}
|
}
|
||||||
@@ -267,7 +259,6 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
//===========//
|
//===========//
|
||||||
//region
|
//region
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(RenderParams renderEventParam, boolean opaquePass, SortedArraySet<LodBufferContainer> bufferContainers, IProfilerWrapper profiler)
|
public void render(RenderParams renderEventParam, boolean opaquePass, SortedArraySet<LodBufferContainer> bufferContainers, IProfilerWrapper profiler)
|
||||||
{
|
{
|
||||||
//=======================//
|
//=======================//
|
||||||
@@ -298,6 +289,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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -305,8 +299,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
|
||||||
@@ -322,6 +314,12 @@ 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
|
||||||
{
|
{
|
||||||
@@ -337,7 +335,7 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS
|
|||||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeBufferRenderEvent.class, new DhApiBeforeBufferRenderEvent.EventParam(renderEventParam, modelPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vbos : bufferContainer.vbosTransparent);
|
IVertexBufferWrapper[] vertexBuffers = (opaquePass ? bufferContainer.vboOpaqueWrappers : bufferContainer.vboTransparentWrappers);
|
||||||
for (int vboIndex = 0; vboIndex < vertexBuffers.length; vboIndex++)
|
for (int vboIndex = 0; vboIndex < vertexBuffers.length; vboIndex++)
|
||||||
{
|
{
|
||||||
GLVertexBuffer vbo = (GLVertexBuffer) vertexBuffers[vboIndex];
|
GLVertexBuffer vbo = (GLVertexBuffer) vertexBuffers[vboIndex];
|
||||||
@@ -346,21 +344,45 @@ 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();
|
||||||
|
|
||||||
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.bindVertexBuffer(vbo.getId());
|
GlDhMetaRenderer.INSTANCE.shaderProgramForThisFrame.bindVertexBuffer(vbo.getId());
|
||||||
GL32.glDrawElements(
|
GL32.glDrawElements(
|
||||||
GL32.GL_TRIANGLES,
|
GL32.GL_TRIANGLES,
|
||||||
indexCount,
|
indexCount,
|
||||||
this.quadIBO.getType(), 0);
|
vbo.getQuadIBO().getGlType(), 0);
|
||||||
|
|
||||||
vbo.unbind();
|
vbo.unbind();
|
||||||
|
vbo.getQuadIBO().unbind();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
vbo.renderStampLock.unlock(vboReadStamp);
|
||||||
|
vbo.getQuadIBO().renderStampLock.unlock(iboReadStamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+38
-9
@@ -25,7 +25,7 @@ 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.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,37 +80,66 @@ public class DependencySetup
|
|||||||
SingletonInjector.INSTANCE.bind(IConfigGui.class, ClassicConfigGUI.CONFIG_CORE_INTERFACE);
|
SingletonInjector.INSTANCE.bind(IConfigGui.class, ClassicConfigGUI.CONFIG_CORE_INTERFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRenderingApiBindings()
|
private static boolean renderingApiBindingsSet = false;
|
||||||
|
/** will be called from a DH thread, not the render thread */
|
||||||
|
public synchronized static void setRenderingApiBindings()
|
||||||
{
|
{
|
||||||
|
// shouldn't happen, but there was a single report that this method was triggered twice
|
||||||
|
if (renderingApiBindingsSet)
|
||||||
|
{
|
||||||
|
LOGGER.warn("Rendering bindings already set, skipping. How did this happen?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renderingApiBindingsSet = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EDhApiRenderApi renderingApiEnum = Config.Client.Advanced.Graphics.Experimental.renderingApi.get();
|
EDhApiRenderApi renderingApiEnum = Config.Client.Advanced.Graphics.Experimental.renderingApi.get();
|
||||||
if (renderingApiEnum == EDhApiRenderApi.AUTO)
|
if (renderingApiEnum == EDhApiRenderApi.AUTO)
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_21_11
|
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||||
renderingApiEnum = EDhApiRenderApi.OPEN_GL;
|
renderingApiEnum = versionConstants.getDefaultRenderingApi();
|
||||||
#else
|
|
||||||
renderingApiEnum = EDhApiRenderApi.BLAZE_3D;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Setting DH Rendering API to: ["+renderingApiEnum+"].");
|
LOGGER.info("Setting DH Rendering API to: ["+renderingApiEnum+"].");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
boolean validApi;
|
||||||
AbstractDhRenderApiDefinition renderDefinition;
|
AbstractDhRenderApiDefinition renderDefinition;
|
||||||
if (renderingApiEnum == EDhApiRenderApi.OPEN_GL)
|
if (renderingApiEnum == EDhApiRenderApi.OPEN_GL)
|
||||||
{
|
{
|
||||||
|
validApi = true;
|
||||||
renderDefinition = new GlDhRenderApiDefinition();
|
renderDefinition = new GlDhRenderApiDefinition();
|
||||||
}
|
}
|
||||||
else if (renderingApiEnum == EDhApiRenderApi.BLAZE_3D)
|
else if (renderingApiEnum == EDhApiRenderApi.BLAZE_3D)
|
||||||
{
|
{
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
throw new IllegalStateException("["+renderingApiEnum+"] is not supported on this version of Minecraft.");
|
validApi = false;
|
||||||
|
renderDefinition = null;
|
||||||
#else
|
#else
|
||||||
|
validApi = true;
|
||||||
renderDefinition = new BlazeDhRenderApiDefinition();
|
renderDefinition = new BlazeDhRenderApiDefinition();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("No ["+ AbstractDhRenderApiDefinition.class.getSimpleName()+"] concrete implementation found for the value: ["+renderingApiEnum+"].");
|
String message = "No ["+ AbstractDhRenderApiDefinition.class.getSimpleName()+"] concrete implementation found for the value: ["+renderingApiEnum+"].";
|
||||||
|
LOGGER.fatal(message);
|
||||||
|
throw new IllegalStateException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// crash if an invalid API is set
|
||||||
|
if (!validApi)
|
||||||
|
{
|
||||||
|
String message = "["+renderingApiEnum+"] is not supported on this version of Minecraft, reverting to ["+EDhApiRenderApi.AUTO+"].";
|
||||||
|
LOGGER.fatal(message);
|
||||||
|
Config.Client.Advanced.Graphics.Experimental.renderingApi.set(EDhApiRenderApi.AUTO);
|
||||||
|
throw new IllegalStateException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
renderDefinition.bindRenderers();
|
renderDefinition.bindRenderers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,16 @@ public class McObjectConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
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()); }
|
||||||
|
public static DhChunkPos Convert(ChunkPos mcPos)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
return new DhChunkPos(mcPos.x, mcPos.z);
|
||||||
|
#else
|
||||||
|
return new DhChunkPos(mcPos.x(), mcPos.z());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public static Direction Convert(EDhDirection lodDirection) { return directions[lodDirection.ordinal()]; }
|
public static Direction Convert(EDhDirection lodDirection) { return directions[lodDirection.ordinal()]; }
|
||||||
public static EDhDirection Convert(Direction direction) { return lodDirections[direction.ordinal()]; }
|
public static EDhDirection Convert(Direction direction) { return lodDirections[direction.ordinal()]; }
|
||||||
|
|||||||
+5
-1
@@ -93,6 +93,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_26_1_2
|
||||||
|
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
|
||||||
@@ -105,7 +109,7 @@ public class VersionConstants implements IVersionConstants
|
|||||||
#if MC_VER <= MC_1_21_11
|
#if MC_VER <= MC_1_21_11
|
||||||
return EDhApiRenderApi.OPEN_GL;
|
return EDhApiRenderApi.OPEN_GL;
|
||||||
#else
|
#else
|
||||||
ERROR MC version constant missing
|
return EDhApiRenderApi.BLAZE_3D;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,16 +147,19 @@ public class WrapperFactory implements IWrapperFactory
|
|||||||
public IBlockStateWrapper deserializeBlockStateWrapper(String str, ILevelWrapper levelWrapper) throws IOException { return BlockStateWrapper.deserialize(str, levelWrapper); }
|
public IBlockStateWrapper deserializeBlockStateWrapper(String str, ILevelWrapper levelWrapper) throws IOException { return BlockStateWrapper.deserialize(str, levelWrapper); }
|
||||||
@Override
|
@Override
|
||||||
public IBlockStateWrapper getAirBlockStateWrapper() { return BlockStateWrapper.AIR; }
|
public IBlockStateWrapper getAirBlockStateWrapper() { return BlockStateWrapper.AIR; }
|
||||||
|
@Override
|
||||||
|
public IBlockStateWrapper getWaterBlockStateWrapper(ILevelWrapper levelWrapper) { return BlockStateWrapper.getWaterBlockStateWrapper(levelWrapper); }
|
||||||
@Override
|
@Override
|
||||||
public ObjectOpenHashSet<IBlockStateWrapper> getRendererIgnoredBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getRendererIgnoredBlocks(levelWrapper); }
|
public ObjectOpenHashSet<IBlockStateWrapper> getRendererIgnoredBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getRendererIgnoredBlocks(levelWrapper); }
|
||||||
@Override
|
@Override
|
||||||
public ObjectOpenHashSet<IBlockStateWrapper> getRendererIgnoredCaveBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getRendererIgnoredCaveBlocks(levelWrapper); }
|
public ObjectOpenHashSet<IBlockStateWrapper> getRendererIgnoredCaveBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getRendererIgnoredCaveBlocks(levelWrapper); }
|
||||||
|
@Override
|
||||||
|
public ObjectOpenHashSet<IBlockStateWrapper> getWaterSubsurfaceReplacementBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getWaterSubsurfaceReplacementBlocks(levelWrapper); }
|
||||||
|
@Override
|
||||||
|
public ObjectOpenHashSet<IBlockStateWrapper> getWaterSurfaceReplacementBlocks(ILevelWrapper levelWrapper) { return BlockStateWrapper.getWaterSurfaceReplacementBlocks(levelWrapper); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetRendererIgnoredCaveBlocks() { BlockStateWrapper.clearRendererIgnoredCaveBlocks(); }
|
public void resetCachedIgnoredBlocksSets() { BlockStateWrapper.clearCachedIgnoreBlocks(); }
|
||||||
@Override
|
|
||||||
public void resetRendererIgnoredBlocksSet() { BlockStateWrapper.clearRendererIgnoredBlocks(); }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+36
-8
@@ -6,15 +6,13 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSour
|
|||||||
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 it.unimi.dsi.fastutil.longs.LongArrayList;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.BlockAndTintGetter;
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -30,6 +28,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
import net.minecraft.world.level.BlockAndTintGetter;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.renderer.block.BlockAndTintGetter;
|
||||||
|
#endif
|
||||||
|
|
||||||
public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
||||||
{
|
{
|
||||||
@@ -43,7 +46,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
|
|
||||||
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 */
|
/** returned if the color cache is incomplete */
|
||||||
public static final int INVALID_COLOR = Integer.MIN_VALUE;
|
public static final int INVALID_COLOR = -1;
|
||||||
|
|
||||||
|
|
||||||
protected BiomeWrapper biomeWrapper;
|
protected BiomeWrapper biomeWrapper;
|
||||||
@@ -57,6 +60,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
public AbstractDhTintGetter() { }
|
public AbstractDhTintGetter() { }
|
||||||
|
|
||||||
@@ -73,11 +77,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
|
||||||
@@ -192,7 +199,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;
|
||||||
@@ -332,6 +339,27 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===========//
|
||||||
|
// set color //
|
||||||
|
//===========//
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-9
@@ -49,6 +49,7 @@ import net.minecraft.core.registries.Registries;
|
|||||||
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;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
@@ -221,26 +222,27 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
Level level = (Level)levelWrapper.getWrappedMcObject();
|
Level level = (Level)levelWrapper.getWrappedMcObject();
|
||||||
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
net.minecraft.core.RegistryAccess registryAccess = level.registryAccess();
|
||||||
|
|
||||||
#if MC_VER < MC_1_21_11
|
#if MC_VER <= MC_1_21_10
|
||||||
ResourceLocation resourceLocation;
|
ResourceLocation resourceLocation;
|
||||||
#else
|
#else
|
||||||
Identifier resourceLocation;
|
Identifier resourceLocation;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if 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_18_2 || 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_3
|
#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;
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_17_1
|
||||||
biomeName = this.biome.toString();
|
biomeName = this.biome.toString();
|
||||||
#else
|
#else
|
||||||
biomeName = this.biome.value().toString();
|
biomeName = this.biome.value().toString();
|
||||||
@@ -354,18 +356,18 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
|
|
||||||
|
|
||||||
boolean success;
|
boolean success;
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if 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_18_2 || 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_3
|
#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);
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
Holder<Biome> biome;
|
Holder<Biome> biome;
|
||||||
Optional<Holder.Reference<Biome>> optionalBiomeHolder = registryAccess.lookupOrThrow(Registries.BIOME).get(resourceLocation);
|
Optional<Holder.Reference<Biome>> optionalBiomeHolder = registryAccess.lookupOrThrow(Registries.BIOME).get(resourceLocation);
|
||||||
if (optionalBiomeHolder.isPresent())
|
if (optionalBiomeHolder.isPresent())
|
||||||
@@ -379,6 +381,20 @@ public class BiomeWrapper implements IBiomeWrapper
|
|||||||
success = false;
|
success = false;
|
||||||
biome = null;
|
biome = null;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
Holder<Biome> biome;
|
||||||
|
Optional<Holder.Reference<Biome>> optionalBiomeHolder = registryAccess.lookupOrThrow(Registries.BIOME).get(resourceLocation);
|
||||||
|
if (optionalBiomeHolder.isPresent())
|
||||||
|
{
|
||||||
|
Biome unwrappedBiome = optionalBiomeHolder.get().value();
|
||||||
|
success = (unwrappedBiome != null);
|
||||||
|
biome = new Holder.Direct<>(unwrappedBiome, DataComponentMap.EMPTY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
biome = null;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return new BiomeDeserializeResult(success, biome);
|
return new BiomeDeserializeResult(success, biome);
|
||||||
|
|||||||
+448
-306
File diff suppressed because it is too large
Load Diff
+158
-40
@@ -19,23 +19,21 @@
|
|||||||
|
|
||||||
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.block.model.BakedQuad;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.block.*;
|
import net.minecraft.world.level.block.*;
|
||||||
#if MC_VER >= MC_1_19_2
|
|
||||||
import net.minecraft.util.RandomSource;
|
|
||||||
#else
|
|
||||||
import java.util.Random;
|
|
||||||
#endif
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||||
@@ -46,9 +44,22 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
#if MC_VER < MC_1_21_5
|
#if MC_VER >= MC_1_19_2
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
#else
|
#else
|
||||||
|
import java.util.Random;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_21_5
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
import net.minecraft.client.renderer.block.model.BlockModelPart;
|
import net.minecraft.client.renderer.block.model.BlockModelPart;
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.renderer.block.dispatch.BlockStateModelPart;
|
||||||
|
import net.minecraft.client.resources.model.geometry.BakedQuad;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.client.color.block.BlockTintSource;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,6 +126,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
|
||||||
@@ -123,6 +135,7 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
private static final int[] linearToSrgbTable = new int[]
|
private static final int[] linearToSrgbTable = new int[]
|
||||||
{
|
{
|
||||||
|
//region
|
||||||
0x0073000d, 0x007a000d, 0x0080000d, 0x0087000d, 0x008d000d, 0x0094000d, 0x009a000d, 0x00a1000d,
|
0x0073000d, 0x007a000d, 0x0080000d, 0x0087000d, 0x008d000d, 0x0094000d, 0x009a000d, 0x00a1000d,
|
||||||
0x00a7001a, 0x00b4001a, 0x00c1001a, 0x00ce001a, 0x00da001a, 0x00e7001a, 0x00f4001a, 0x0101001a,
|
0x00a7001a, 0x00b4001a, 0x00c1001a, 0x00ce001a, 0x00da001a, 0x00e7001a, 0x00f4001a, 0x0101001a,
|
||||||
0x010e0033, 0x01280033, 0x01410033, 0x015b0033, 0x01750033, 0x018f0033, 0x01a80033, 0x01c20033,
|
0x010e0033, 0x01280033, 0x01410033, 0x015b0033, 0x01750033, 0x018f0033, 0x01a80033, 0x01c20033,
|
||||||
@@ -136,9 +149,11 @@ public class ClientBlockStateColorCache
|
|||||||
0x31d105b0, 0x34a80555, 0x37520507, 0x39d504c5, 0x3c37048b, 0x3e7c0458, 0x40a8042a, 0x42bd0401,
|
0x31d105b0, 0x34a80555, 0x37520507, 0x39d504c5, 0x3c37048b, 0x3e7c0458, 0x40a8042a, 0x42bd0401,
|
||||||
0x44c20798, 0x488e071e, 0x4c1c06b6, 0x4f76065d, 0x52a50610, 0x55ac05cc, 0x5892058f, 0x5b590559,
|
0x44c20798, 0x488e071e, 0x4c1c06b6, 0x4f76065d, 0x52a50610, 0x55ac05cc, 0x5892058f, 0x5b590559,
|
||||||
0x5e0c0a23, 0x631c0980, 0x67db08f6, 0x6c55087f, 0x70940818, 0x74a007bd, 0x787d076c, 0x7c330723,
|
0x5e0c0a23, 0x631c0980, 0x67db08f6, 0x6c55087f, 0x70940818, 0x74a007bd, 0x787d076c, 0x7c330723,
|
||||||
|
//endregion
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final float[] srgbToLinearTable = new float[]
|
private static final float[] srgbToLinearTable = new float[]
|
||||||
|
//region
|
||||||
{
|
{
|
||||||
0.0f, 0.000303527f, 0.000607054f, 0.00091058103f, 0.001214108f, 0.001517635f, 0.0018211621f, 0.002124689f,
|
0.0f, 0.000303527f, 0.000607054f, 0.00091058103f, 0.001214108f, 0.001517635f, 0.0018211621f, 0.002124689f,
|
||||||
0.002428216f, 0.002731743f, 0.00303527f, 0.0033465356f, 0.003676507f, 0.004024717f, 0.004391442f,
|
0.002428216f, 0.002731743f, 0.00303527f, 0.0033465356f, 0.003676507f, 0.004024717f, 0.004391442f,
|
||||||
@@ -172,16 +187,22 @@ public class ClientBlockStateColorCache
|
|||||||
0.78353804f, 0.79129815f, 0.79910296f, 0.8069525f, 0.8148468f, 0.822786f, 0.8307701f, 0.83879924f, 0.84687346f,
|
0.78353804f, 0.79129815f, 0.79910296f, 0.8069525f, 0.8148468f, 0.822786f, 0.8307701f, 0.83879924f, 0.84687346f,
|
||||||
0.8549928f, 0.8631574f, 0.87136734f, 0.8796226f, 0.8879232f, 0.89626956f, 0.90466136f, 0.913099f, 0.92158204f,
|
0.8549928f, 0.8631574f, 0.87136734f, 0.8796226f, 0.8879232f, 0.89626956f, 0.90466136f, 0.913099f, 0.92158204f,
|
||||||
0.93011117f, 0.9386859f, 0.9473069f, 0.9559735f, 0.9646866f, 0.9734455f, 0.98225087f, 0.9911022f, 1.0f
|
0.93011117f, 0.9386859f, 0.9473069f, 0.9559735f, 0.9646866f, 0.9734455f, 0.98225087f, 0.9911022f, 1.0f
|
||||||
|
//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());
|
private static final ThreadLocal<TintWithoutLevelOverrider> TintWithoutLevelOverrideGetter = ThreadLocal.withInitial(TintWithoutLevelOverrider::new);
|
||||||
|
private static final ThreadLocal<TintGetterOverride> TintOverrideGetter = ThreadLocal.withInitial(TintGetterOverride::new);
|
||||||
|
private static final ThreadLocal<DhApiBlockColorOverrideEvent.EventParam> ColorOverrideEventParamGetter = ThreadLocal.withInitial(DhApiBlockColorOverrideEvent.EventParam::new);
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============//
|
//=============//
|
||||||
// constructor //
|
// constructor //
|
||||||
//=============//
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper clientLevelWrapper)
|
public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper clientLevelWrapper)
|
||||||
{
|
{
|
||||||
@@ -192,6 +213,8 @@ public class ClientBlockStateColorCache
|
|||||||
this.resolveColors();
|
this.resolveColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===================//
|
//===================//
|
||||||
@@ -236,14 +259,23 @@ public class ClientBlockStateColorCache
|
|||||||
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
|
||||||
this.needPostTinting = firstQuad.isTinted();
|
this.needPostTinting = firstQuad.isTinted();
|
||||||
|
#else
|
||||||
|
this.needPostTinting = firstQuad.materialInfo().isTinted();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_4
|
#if MC_VER <= MC_1_21_4
|
||||||
this.tintIndex = firstQuad.getTintIndex();
|
this.tintIndex = firstQuad.getTintIndex();
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
this.tintIndex = firstQuad.tintIndex();
|
this.tintIndex = firstQuad.tintIndex();
|
||||||
|
#else
|
||||||
|
this.tintIndex = firstQuad.materialInfo().tintIndex();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1
|
||||||
@@ -254,12 +286,30 @@ public class ClientBlockStateColorCache
|
|||||||
this.baseColor = calculateColorFromTexture(
|
this.baseColor = calculateColorFromTexture(
|
||||||
firstQuad.getSprite(),
|
firstQuad.getSprite(),
|
||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
this.baseColor = calculateColorFromTexture(
|
this.baseColor = calculateColorFromTexture(
|
||||||
firstQuad.sprite(),
|
firstQuad.sprite(),
|
||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
|
#else
|
||||||
|
this.baseColor = calculateColorFromTexture(
|
||||||
|
firstQuad.materialInfo().sprite(),
|
||||||
|
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.
|
||||||
@@ -304,7 +354,7 @@ public class ClientBlockStateColorCache
|
|||||||
#if MC_VER < MC_1_21_5
|
#if 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);
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
List<BlockModelPart> blockModelPartList = MC.getModelManager().getBlockModelShaper().
|
List<BlockModelPart> blockModelPartList = MC.getModelManager().getBlockModelShaper().
|
||||||
getBlockModel(effectiveBlockState).collectParts(RANDOM);
|
getBlockModel(effectiveBlockState).collectParts(RANDOM);
|
||||||
|
|
||||||
@@ -317,6 +367,17 @@ public class ClientBlockStateColorCache
|
|||||||
quads.addAll(blockModelPartList.get(i).getQuads(direction));
|
quads.addAll(blockModelPartList.get(i).getQuads(direction));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
List<BlockStateModelPart> blockModelPartList = new ArrayList<>();
|
||||||
|
MC.getModelManager().getBlockStateModelSet()
|
||||||
|
.get(effectiveBlockState).collectParts(RANDOM, blockModelPartList);
|
||||||
|
|
||||||
|
quads = new ArrayList<>();
|
||||||
|
for (int i = 0; i < blockModelPartList.size(); i++)
|
||||||
|
{
|
||||||
|
// if direction is null this will return the unculled quads
|
||||||
|
quads.addAll(blockModelPartList.get(i).getQuads(direction));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return quads;
|
return quads;
|
||||||
@@ -354,22 +415,14 @@ public class ClientBlockStateColorCache
|
|||||||
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)
|
||||||
{
|
{
|
||||||
@@ -457,7 +510,11 @@ public class ClientBlockStateColorCache
|
|||||||
private int getParticleIconColor()
|
private int getParticleIconColor()
|
||||||
{
|
{
|
||||||
return calculateColorFromTexture(
|
return calculateColorFromTexture(
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(this.blockState),
|
Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(this.blockState),
|
||||||
|
#else
|
||||||
|
Minecraft.getInstance().getModelManager().getBlockStateModelSet().get(this.blockState).particleMaterial().sprite(),
|
||||||
|
#endif
|
||||||
EColorMode.getColorMode(this.blockState.getBlock()));
|
EColorMode.getColorMode(this.blockState.getBlock()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,11 +527,9 @@ public class ClientBlockStateColorCache
|
|||||||
public int getColor(BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, DhBlockPos blockPos)
|
public int getColor(BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, DhBlockPos blockPos)
|
||||||
{
|
{
|
||||||
// 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 = AbstractDhTintGetter.INVALID_COLOR;
|
||||||
|
if (this.needPostTinting)
|
||||||
{
|
{
|
||||||
return this.baseColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
@@ -483,7 +538,6 @@ public class ClientBlockStateColorCache
|
|||||||
|
|
||||||
|
|
||||||
// attempt to get the tint
|
// attempt to get the tint
|
||||||
int tintColor = -1;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// try to use the fast tint getter logic first
|
// try to use the fast tint getter logic first
|
||||||
@@ -500,22 +554,62 @@ public class ClientBlockStateColorCache
|
|||||||
{
|
{
|
||||||
// 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
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
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
|
||||||
}
|
BlockTintSource tintSource = Minecraft.getInstance()
|
||||||
catch (UnsupportedOperationException e)
|
.getBlockColors()
|
||||||
|
.getTintSource(this.blockState, this.tintIndex);
|
||||||
|
// a tint source may be null for blocks that don't actually need tinting
|
||||||
|
// in that case the base color should be sufficient
|
||||||
|
// Example: cherry blossom leaves
|
||||||
|
if (tintSource != null)
|
||||||
{
|
{
|
||||||
// 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 == -1)
|
||||||
|
{
|
||||||
|
tintColor = tintSource.colorAsTerrainParticle(this.blockState, tintOverride, mcPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tintColor == -1)
|
||||||
|
{
|
||||||
|
// no color found, use the base color
|
||||||
|
tintColor = AbstractDhTintGetter.INVALID_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// level-specific logic is only needed for MC 1.21.11 and older
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
// 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))
|
||||||
{
|
{
|
||||||
@@ -536,28 +630,49 @@ public class ClientBlockStateColorCache
|
|||||||
this.tintIndex);
|
this.tintIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#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 != AbstractDhTintGetter.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 an API event if needed
|
||||||
|
// (this is done to reduce GC pressure and speed up color getting)
|
||||||
|
if (this.blockStateWrapper.allowApiColorOverride())
|
||||||
|
{
|
||||||
|
DhApiBlockColorOverrideEvent.EventParam eventParam = ColorOverrideEventParamGetter.get();
|
||||||
|
eventParam.update(
|
||||||
|
this.clientLevelWrapper,
|
||||||
|
this.blockStateWrapper, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -565,6 +680,7 @@ public class ClientBlockStateColorCache
|
|||||||
//================//
|
//================//
|
||||||
// helper classes //
|
// helper classes //
|
||||||
//================//
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
private enum EColorMode
|
private enum EColorMode
|
||||||
{
|
{
|
||||||
@@ -596,6 +712,8 @@ public class ClientBlockStateColorCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
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
|
||||||
|
|
||||||
|
|||||||
+9
@@ -63,8 +63,10 @@ public class TintGetterOverride extends AbstractDhTintGetter
|
|||||||
// methods //
|
// methods //
|
||||||
//=========//
|
//=========//
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
@Override
|
@Override
|
||||||
public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
|
public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
|
||||||
|
#endif
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LevelLightEngine getLightEngine() { return this.parent.getLightEngine(); }
|
public LevelLightEngine getLightEngine() { return this.parent.getLightEngine(); }
|
||||||
@@ -178,5 +180,12 @@ public class TintGetterOverride extends AbstractDhTintGetter
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public CardinalLighting cardinalLighting() { return CardinalLighting.DEFAULT; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-2
@@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package com.seibel.distanthorizons.common.wrappers.block;
|
package com.seibel.distanthorizons.common.wrappers.block;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
|
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
|
||||||
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;
|
||||||
@@ -30,6 +28,12 @@ import net.minecraft.world.level.lighting.LevelLightEngine;
|
|||||||
import net.minecraft.world.level.material.FluidState;
|
import net.minecraft.world.level.material.FluidState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
#else
|
||||||
|
import net.minecraft.world.level.CardinalLighting;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
public class TintWithoutLevelOverrider extends AbstractDhTintGetter
|
public class TintWithoutLevelOverrider extends AbstractDhTintGetter
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -46,9 +50,12 @@ public class TintWithoutLevelOverrider extends AbstractDhTintGetter
|
|||||||
// methods //
|
// methods //
|
||||||
//=========//
|
//=========//
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
@Override
|
@Override
|
||||||
public float getShade(Direction direction, boolean shade)
|
public float getShade(Direction direction, boolean shade)
|
||||||
{ throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only."); }
|
{ throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only."); }
|
||||||
|
#endif
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LevelLightEngine getLightEngine()
|
public LevelLightEngine getLightEngine()
|
||||||
{ throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only."); }
|
{ throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only."); }
|
||||||
@@ -87,4 +94,18 @@ public class TintWithoutLevelOverrider extends AbstractDhTintGetter
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//=================//
|
||||||
|
// post MC 1.21.11 //
|
||||||
|
//=================//
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public CardinalLighting cardinalLighting()
|
||||||
|
{ throw new UnsupportedOperationException("ERROR: cardinalLighting() called on TintWithoutLevelOverrider. Object is for tinting only."); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -122,7 +122,12 @@ public class ChunkWrapper implements IChunkWrapper
|
|||||||
{
|
{
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.wrappedLevel = wrappedLevel;
|
this.wrappedLevel = wrappedLevel;
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
this.chunkPos = new DhChunkPos(chunk.getPos().x, chunk.getPos().z);
|
this.chunkPos = new DhChunkPos(chunk.getPos().x, chunk.getPos().z);
|
||||||
|
#else
|
||||||
|
this.chunkPos = new DhChunkPos(chunk.getPos().x(), chunk.getPos().z());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
-1093
File diff suppressed because it is too large
Load Diff
+28
@@ -3,6 +3,7 @@ package com.seibel.distanthorizons.common.wrappers.gui;
|
|||||||
#if MC_VER < MC_1_21_9
|
#if MC_VER < MC_1_21_9
|
||||||
// not supported for older MC versions
|
// not supported for older MC versions
|
||||||
#else
|
#else
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
|
||||||
@@ -19,6 +20,8 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
#else
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -32,6 +35,7 @@ public class DhDebugScreenEntry implements net.minecraft.client.gui.components.d
|
|||||||
{
|
{
|
||||||
public static void register()
|
public static void register()
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
// This method is private, so its access will need to be widened
|
// This method is private, so its access will need to be widened
|
||||||
DebugScreenEntries.register(
|
DebugScreenEntries.register(
|
||||||
// The id, this will be displayed on the options screen
|
// The id, this will be displayed on the options screen
|
||||||
@@ -44,6 +48,23 @@ public class DhDebugScreenEntry implements net.minecraft.client.gui.components.d
|
|||||||
// The screen entry
|
// The screen entry
|
||||||
new DhDebugScreenEntry()
|
new DhDebugScreenEntry()
|
||||||
);
|
);
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
DebugScreenEntries.allEntries().put(
|
||||||
|
// The id, this will be displayed on the options screen
|
||||||
|
Identifier.fromNamespaceAndPath(ModInfo.RESOURCE_NAMESPACE, "distant_horizons"),
|
||||||
|
|
||||||
|
// The screen entry
|
||||||
|
new DhDebugScreenEntry()
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
DebugScreenEntries.register(
|
||||||
|
// The id, this will be displayed on the options screen
|
||||||
|
ModInfo.RESOURCE_NAMESPACE,
|
||||||
|
|
||||||
|
// The screen entry
|
||||||
|
new DhDebugScreenEntry()
|
||||||
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,6 +79,8 @@ public class DhDebugScreenEntry implements net.minecraft.client.gui.components.d
|
|||||||
displayer.addLine(message);
|
displayer.addLine(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region
|
||||||
|
|
||||||
//// The following will display like so if it is the only entry on the screen:
|
//// The following will display like so if it is the only entry on the screen:
|
||||||
//// First left! First Right!
|
//// First left! First Right!
|
||||||
////
|
////
|
||||||
@@ -86,6 +109,8 @@ public class DhDebugScreenEntry implements net.minecraft.client.gui.components.d
|
|||||||
//
|
//
|
||||||
//displayer.addToGroup(GROUP_TWO, "I am another group!");
|
//displayer.addToGroup(GROUP_TWO, "I am another group!");
|
||||||
//displayer.addToGroup(GROUP_TWO, "This will appear after with no line breaks!");
|
//displayer.addToGroup(GROUP_TWO, "This will appear after with no line breaks!");
|
||||||
|
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,5 +119,8 @@ public class DhDebugScreenEntry implements net.minecraft.client.gui.components.d
|
|||||||
// Always show regardless of accessibility option
|
// Always show regardless of accessibility option
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.gui;
|
package com.seibel.distanthorizons.common.wrappers.gui;
|
||||||
|
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
#if MC_VER < MC_1_20_1
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
#else
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
#endif
|
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DhScreen extends Screen
|
public class DhScreen extends Screen
|
||||||
@@ -73,7 +77,7 @@ public class DhScreen extends Screen
|
|||||||
{
|
{
|
||||||
guiStack.renderTooltip(font, text, x, y);
|
guiStack.renderTooltip(font, text, x, y);
|
||||||
}
|
}
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
protected void DhDrawCenteredString(GuiGraphics guiStack, Font font, Component text, int x, int y, int color)
|
protected void DhDrawCenteredString(GuiGraphics guiStack, Font font, Component text, int x, int y, int color)
|
||||||
{
|
{
|
||||||
guiStack.drawCenteredString(font, text, x, y, color);
|
guiStack.drawCenteredString(font, text, x, y, color);
|
||||||
@@ -82,10 +86,6 @@ public class DhScreen extends Screen
|
|||||||
{
|
{
|
||||||
guiStack.drawString(font, text, x, y, color);
|
guiStack.drawString(font, text, x, y, color);
|
||||||
}
|
}
|
||||||
//protected void DhRenderTooltip(GuiGraphics guiStack, Font font, List<? extends net.minecraft.util.FormattedCharSequence> text, int x, int y)
|
|
||||||
//{
|
|
||||||
// //guiStack.renderTooltip(font, text, x, y);
|
|
||||||
//}
|
|
||||||
protected void DhRenderComponentTooltip(GuiGraphics guiStack, Font font, List<Component> comp, int x, int y)
|
protected void DhRenderComponentTooltip(GuiGraphics guiStack, Font font, List<Component> comp, int x, int y)
|
||||||
{
|
{
|
||||||
guiStack.setComponentTooltipForNextFrame(font, comp, x, y);
|
guiStack.setComponentTooltipForNextFrame(font, comp, x, y);
|
||||||
@@ -94,6 +94,23 @@ public class DhScreen extends Screen
|
|||||||
{
|
{
|
||||||
guiStack.setTooltipForNextFrame(font, text, x, y);
|
guiStack.setTooltipForNextFrame(font, text, x, y);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
protected void DhDrawCenteredString(GuiGraphicsExtractor guiStack, Font font, Component text, int x, int y, int color)
|
||||||
|
{
|
||||||
|
guiStack.centeredText(font, text, x, y, color);
|
||||||
|
}
|
||||||
|
protected void DhDrawString(GuiGraphicsExtractor guiStack, Font font, Component text, int x, int y, int color)
|
||||||
|
{
|
||||||
|
guiStack.text(font, text, x, y, color);
|
||||||
|
}
|
||||||
|
protected void DhRenderComponentTooltip(GuiGraphicsExtractor guiStack, Font font, List<Component> comp, int x, int y)
|
||||||
|
{
|
||||||
|
guiStack.setComponentTooltipForNextFrame(font, comp, x, y);
|
||||||
|
}
|
||||||
|
protected void DhRenderTooltip(GuiGraphicsExtractor guiStack, Font font, Component text, int x, int y)
|
||||||
|
{
|
||||||
|
guiStack.setTooltipForNextFrame(font, text, x, y);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.seibel.distanthorizons.common.wrappers.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DhScreenUtil
|
||||||
|
{
|
||||||
|
//================//
|
||||||
|
// helper methods //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public static void showScreen(Screen screen)
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
Objects.requireNonNull(Minecraft.getInstance()).setScreen(screen);
|
||||||
|
#else
|
||||||
|
Objects.requireNonNull(Minecraft.getInstance()).setScreenAndShow(screen);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.gui;
|
package com.seibel.distanthorizons.common.wrappers.gui;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.classicConfig.ClassicConfigGUI;
|
||||||
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
|||||||
+40
-9
@@ -1,25 +1,42 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.gui;
|
package com.seibel.distanthorizons.common.wrappers.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.Window;
|
import com.mojang.blaze3d.platform.Window;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.config.gui.AbstractScreen;
|
import com.seibel.distanthorizons.core.config.gui.AbstractScreen;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
#if MC_VER >= MC_1_20_1
|
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
|
||||||
#endif
|
|
||||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
#endif
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class MinecraftScreen
|
public class MinecraftScreen
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// helper methods
|
||||||
|
//
|
||||||
|
|
||||||
public static Screen getScreen(Screen parent, AbstractScreen screen, String translationName)
|
public static Screen getScreen(Screen parent, AbstractScreen screen, String translationName)
|
||||||
{
|
{ return new ConfigScreenRenderer(parent, screen, translationName); }
|
||||||
return new ConfigScreenRenderer(parent, screen, translationName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//=========//
|
||||||
|
// screens //
|
||||||
|
//=========//
|
||||||
|
//region
|
||||||
|
|
||||||
private static class ConfigScreenRenderer extends DhScreen
|
private static class ConfigScreenRenderer extends DhScreen
|
||||||
{
|
{
|
||||||
@@ -74,8 +91,10 @@ public class MinecraftScreen
|
|||||||
@Override
|
@Override
|
||||||
#if MC_VER < MC_1_20_1
|
#if MC_VER < MC_1_20_1
|
||||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
public void extractRenderState(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_20_2
|
#if MC_VER < MC_1_20_2
|
||||||
@@ -86,13 +105,21 @@ public class MinecraftScreen
|
|||||||
// background blur is already being rendered, rendering again causes the game to crash
|
// background blur is already being rendered, rendering again causes the game to crash
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
this.configListWidget.render(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker)
|
this.configListWidget.render(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker)
|
||||||
|
#else
|
||||||
|
this.configListWidget.extractRenderState(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker)
|
||||||
|
#endif
|
||||||
|
|
||||||
this.screen.mouseX = mouseX;
|
this.screen.mouseX = mouseX;
|
||||||
this.screen.mouseY = mouseY;
|
this.screen.mouseY = mouseY;
|
||||||
this.screen.render(delta); // Render everything on the main screen
|
this.screen.render(delta); // Render everything on the main screen
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
super.render(matrices, mouseX, mouseY, delta); // Render the vanilla stuff (currently only used for the background and tint)
|
super.render(matrices, mouseX, mouseY, delta); // Render the vanilla stuff (currently only used for the background and tint)
|
||||||
|
#else
|
||||||
|
super.extractRenderState(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
@@ -134,7 +161,7 @@ public class MinecraftScreen
|
|||||||
public void onClose()
|
public void onClose()
|
||||||
{
|
{
|
||||||
this.screen.onClose(); // Close our screen
|
this.screen.onClose(); // Close our screen
|
||||||
Objects.requireNonNull(this.minecraft).setScreen(this.parent); // Goto the parent screen
|
DhScreenUtil.showScreen(this.parent); // Goto the parent screen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -162,4 +189,8 @@ public class MinecraftScreen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.seibel.distanthorizons.common.wrappers.gui;
|
||||||
|
|
||||||
|
import org.lwjgl.util.tinyfd.TinyFileDialogs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used instead of the direct call to {@link TinyFileDialogs}
|
||||||
|
* so we can run additional validation and/or string cleanup.
|
||||||
|
* Otherwise, we may get error messages back. <br><br>
|
||||||
|
*
|
||||||
|
* source:
|
||||||
|
* https://sourceforge.net/projects/tinyfiledialogs/
|
||||||
|
*
|
||||||
|
* @see TinyFileDialogs
|
||||||
|
*/
|
||||||
|
public class NativeDialogUtil
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param dialogType the dialog type. One of:<br><table><tr><td>"ok"</td><td>"okcancel"</td><td>"yesno"</td><td>"yesnocancel"</td></tr></table>
|
||||||
|
* @param iconType the icon type. One of:<br><table><tr><td>"info"</td><td>"warning"</td><td>"error"</td><td>"question"</td></tr></table>
|
||||||
|
*/
|
||||||
|
public static void showDialog(String title, String message, String dialogType, String iconType)
|
||||||
|
{
|
||||||
|
// Tinyfd doesn't support the following characters, attempting to display them will cause the message
|
||||||
|
// to be replaced with an error message
|
||||||
|
String unsafeCharsRegex = "['\"`]";
|
||||||
|
|
||||||
|
title = title.replaceAll(unsafeCharsRegex, "");
|
||||||
|
message = message.replaceAll(unsafeCharsRegex, "");
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
TinyFileDialogs.tinyfd_messageBox(title, message, dialogType, iconType, false);
|
||||||
|
#else
|
||||||
|
// https://mfbridge.github.io/tinyfiledialogs/reference/messageBox.html
|
||||||
|
TinyFileDialogs.tinyfd_messageBox(title, message, dialogType, iconType, 1 /* ok/yes */);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
-2
@@ -45,9 +45,12 @@ import net.minecraft.client.renderer.RenderType;
|
|||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.client.renderer.RenderPipelines;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.renderer.RenderPipelines;
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
@@ -63,8 +66,10 @@ import net.minecraft.resources.Identifier;
|
|||||||
* @version 2023-10-03
|
* @version 2023-10-03
|
||||||
*/
|
*/
|
||||||
#if MC_VER < MC_1_20_2
|
#if MC_VER < MC_1_20_2
|
||||||
|
@SuppressWarnings("deprecation") // we use a few deprecated Mojang functions (as expected when running on old MC versions)
|
||||||
public class TexturedButtonWidget extends ImageButton
|
public class TexturedButtonWidget extends ImageButton
|
||||||
#else
|
#else
|
||||||
|
@SuppressWarnings("deprecation") // we use a few deprecated Mojang functions (as expected when running on old MC versions)
|
||||||
public class TexturedButtonWidget extends Button
|
public class TexturedButtonWidget extends Button
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@@ -194,9 +199,12 @@ public class TexturedButtonWidget extends Button
|
|||||||
#if MC_VER < MC_1_21_11
|
#if MC_VER < MC_1_21_11
|
||||||
@Override
|
@Override
|
||||||
public void renderWidget(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
public void renderWidget(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
@Override
|
@Override
|
||||||
protected void renderContents(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
protected void renderContents(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
protected void extractContents(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (this.renderBackground)
|
if (this.renderBackground)
|
||||||
|
|||||||
+384
@@ -0,0 +1,384 @@
|
|||||||
|
package com.seibel.distanthorizons.common.wrappers.gui.classicConfig;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.config.types.*;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.config.types.enums.EConfigCommentTextPosition;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Font;
|
||||||
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
|
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||||
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER >= MC_1_17_1
|
||||||
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
#else
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Based upon TinyConfig but is highly modified
|
||||||
|
* https://github.com/Minenash/TinyConfig
|
||||||
|
*
|
||||||
|
* @author coolGi
|
||||||
|
* @author Motschen
|
||||||
|
* @author James Seibel
|
||||||
|
* @version 5-21-2022
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public class ClassicConfigGUI
|
||||||
|
{
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
public static final DhLogger RATE_LIMITED_LOGGER = new DhLoggerBuilder()
|
||||||
|
.maxCountPerSecond(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static final ConfigCoreInterface CONFIG_CORE_INTERFACE = new ConfigCoreInterface();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// Initializers //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
// Some regexes to check if an input is valid
|
||||||
|
public static final Pattern INTEGER_ONLY_REGEX = Pattern.compile("(-?[0-9]*)");
|
||||||
|
public static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||||
|
|
||||||
|
public static class ConfigScreenConfigs
|
||||||
|
{
|
||||||
|
// This contains all the configs for the configs
|
||||||
|
public static final int SPACE_FROM_RIGHT_SCREEN = 10;
|
||||||
|
public static final int SPACE_BETWEEN_TEXT_AND_OPTION_FIELD = 8;
|
||||||
|
public static final int BUTTON_WIDTH_SPACING = 5;
|
||||||
|
public static final int RESET_BUTTON_WIDTH = 60;
|
||||||
|
public static final int RESET_BUTTON_HEIGHT = 20;
|
||||||
|
public static final int OPTION_FIELD_WIDTH = 150;
|
||||||
|
public static final int OPTION_FIELD_HEIGHT = 20;
|
||||||
|
public static final int CATEGORY_BUTTON_WIDTH = 200;
|
||||||
|
public static final int CATEGORY_BUTTON_HEIGHT = 20;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// GUI handling //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
/** if you want to get this config gui's screen call this */
|
||||||
|
public static Screen getScreen(Screen parent, String category)
|
||||||
|
{ return new DhConfigScreen(parent, category); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper classes //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
public static class ConfigListWidget extends ContainerObjectSelectionList<DhButtonEntry>
|
||||||
|
{
|
||||||
|
Font textRenderer;
|
||||||
|
|
||||||
|
public ConfigListWidget(Minecraft minecraftClient, int canvasWidth, int canvasHeight, int topMargin, int botMargin, int itemSpacing)
|
||||||
|
{
|
||||||
|
#if MC_VER < MC_1_20_4
|
||||||
|
super(minecraftClient, canvasWidth, canvasHeight, topMargin, canvasHeight - botMargin, itemSpacing);
|
||||||
|
#else
|
||||||
|
super(minecraftClient, canvasWidth, canvasHeight - (topMargin + botMargin), topMargin, itemSpacing);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this.centerListVertically = false;
|
||||||
|
this.textRenderer = minecraftClient.font;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addButton(DhConfigScreen gui, AbstractConfigBase dhConfigType, AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text)
|
||||||
|
{ this.addEntry(new DhButtonEntry(gui, dhConfigType, button, text, resetButton, indexButton)); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowWidth() { return 10_000; }
|
||||||
|
|
||||||
|
public AbstractWidget getHoveredButton(double mouseX, double mouseY)
|
||||||
|
{
|
||||||
|
for (DhButtonEntry buttonEntry : this.children())
|
||||||
|
{
|
||||||
|
AbstractWidget button = buttonEntry.button;
|
||||||
|
if (button != null
|
||||||
|
&& button.visible)
|
||||||
|
{
|
||||||
|
#if MC_VER < MC_1_19_4
|
||||||
|
double minX = button.x;
|
||||||
|
double minY = button.y;
|
||||||
|
#else
|
||||||
|
double minX = button.getX();
|
||||||
|
double minY = button.getY();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
double maxX = minX + button.getWidth();
|
||||||
|
double maxY = minY + button.getHeight();
|
||||||
|
|
||||||
|
if (mouseX >= minX && mouseX < maxX
|
||||||
|
&& mouseY >= minY && mouseY < maxY)
|
||||||
|
{
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class DhButtonEntry extends ContainerObjectSelectionList.Entry<DhButtonEntry>
|
||||||
|
{
|
||||||
|
private static final Font textRenderer = Minecraft.getInstance().font;
|
||||||
|
|
||||||
|
private final AbstractWidget button;
|
||||||
|
|
||||||
|
private final DhConfigScreen gui;
|
||||||
|
|
||||||
|
private final AbstractWidget resetButton;
|
||||||
|
private final AbstractWidget indexButton;
|
||||||
|
private final Component text;
|
||||||
|
private final List<AbstractWidget> children = new ArrayList<>();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final EConfigCommentTextPosition textPosition;
|
||||||
|
public final AbstractConfigBase dhConfigType;
|
||||||
|
|
||||||
|
public static final Map<AbstractWidget, Component> TEXT_BY_WIDGET = new HashMap<>();
|
||||||
|
public static final Map<AbstractWidget, DhButtonEntry> BUTTON_BY_WIDGET = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public DhButtonEntry(
|
||||||
|
DhConfigScreen gui, AbstractConfigBase dhConfigType,
|
||||||
|
AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton)
|
||||||
|
{
|
||||||
|
TEXT_BY_WIDGET.put(button, text);
|
||||||
|
BUTTON_BY_WIDGET.put(button, this);
|
||||||
|
|
||||||
|
this.gui = gui;
|
||||||
|
this.dhConfigType = dhConfigType;
|
||||||
|
|
||||||
|
this.button = button;
|
||||||
|
this.resetButton = resetButton;
|
||||||
|
this.text = text;
|
||||||
|
this.indexButton = indexButton;
|
||||||
|
|
||||||
|
if (button != null) { this.children.add(button); }
|
||||||
|
if (resetButton != null) { this.children.add(resetButton); }
|
||||||
|
if (indexButton != null) { this.children.add(indexButton); }
|
||||||
|
|
||||||
|
|
||||||
|
EConfigCommentTextPosition textPosition = null;
|
||||||
|
if (this.dhConfigType instanceof ConfigUIComment)
|
||||||
|
{
|
||||||
|
textPosition = ((ConfigUIComment)this.dhConfigType).textPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textPosition == null)
|
||||||
|
{
|
||||||
|
if (this.button != null)
|
||||||
|
{
|
||||||
|
// if a button is present
|
||||||
|
textPosition = EConfigCommentTextPosition.RIGHT_JUSTIFIED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textPosition = EConfigCommentTextPosition.CENTERED_OVER_BUTTONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.textPosition = textPosition;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||||
|
#elif MC_VER < MC_1_21_9
|
||||||
|
public void render(GuiGraphics matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
public void renderContent(GuiGraphics matrices, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||||
|
#else
|
||||||
|
public void extractContent(GuiGraphicsExtractor matrices, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// setting the "y" variable is necessary so each child item
|
||||||
|
// renders at the correct height,
|
||||||
|
// if not set they will render off-screen.
|
||||||
|
#if MC_VER < MC_1_21_9
|
||||||
|
// Y value passed in from method args
|
||||||
|
#else
|
||||||
|
int y = this.getY();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (this.button != null)
|
||||||
|
{
|
||||||
|
SetY(this.button, y);
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
this.button.render(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#else
|
||||||
|
this.button.extractRenderState(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.resetButton != null)
|
||||||
|
{
|
||||||
|
SetY(this.resetButton, y);
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
this.resetButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#else
|
||||||
|
this.resetButton.extractRenderState(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.indexButton != null)
|
||||||
|
{
|
||||||
|
SetY(this.indexButton, y);
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
this.indexButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#else
|
||||||
|
this.indexButton.extractRenderState(matrices, mouseX, mouseY, tickDelta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.text != null)
|
||||||
|
{
|
||||||
|
int translatedLength = textRenderer.width(this.text);
|
||||||
|
|
||||||
|
int textXPos;
|
||||||
|
if (this.textPosition == EConfigCommentTextPosition.RIGHT_JUSTIFIED)
|
||||||
|
{
|
||||||
|
// text right justified aligned against the buttons
|
||||||
|
textXPos = this.gui.width
|
||||||
|
- translatedLength
|
||||||
|
- ConfigScreenConfigs.SPACE_BETWEEN_TEXT_AND_OPTION_FIELD
|
||||||
|
- ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN
|
||||||
|
- ConfigScreenConfigs.OPTION_FIELD_WIDTH
|
||||||
|
- ConfigScreenConfigs.BUTTON_WIDTH_SPACING
|
||||||
|
- ConfigScreenConfigs.RESET_BUTTON_WIDTH;
|
||||||
|
}
|
||||||
|
else if (this.textPosition == EConfigCommentTextPosition.CENTERED_OVER_BUTTONS)
|
||||||
|
{
|
||||||
|
// have button centered relative to a category button
|
||||||
|
textXPos = this.gui.width
|
||||||
|
- (translatedLength / 2)
|
||||||
|
- (ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH / 2)
|
||||||
|
- ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
|
||||||
|
}
|
||||||
|
else if (this.textPosition == EConfigCommentTextPosition.CENTER_OF_SCREEN)
|
||||||
|
{
|
||||||
|
// have button centered in the screen
|
||||||
|
textXPos = (this.gui.width / 2)
|
||||||
|
- (translatedLength / 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("No text position render defined for [" + this.textPosition + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
GuiComponent.drawString(matrices, textRenderer,
|
||||||
|
this.text,
|
||||||
|
textXPos, y + 5,
|
||||||
|
0xFFFFFF);
|
||||||
|
#elif MC_VER < MC_1_21_6
|
||||||
|
matrices.drawString(textRenderer,
|
||||||
|
this.text,
|
||||||
|
textXPos, y + 5,
|
||||||
|
0xFFFFFF);
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
matrices.drawString(textRenderer,
|
||||||
|
this.text,
|
||||||
|
textXPos, y + 5,
|
||||||
|
0xFFFFFFFF);
|
||||||
|
#else
|
||||||
|
matrices.text(textRenderer,
|
||||||
|
this.text,
|
||||||
|
textXPos, y + 5,
|
||||||
|
0xFFFFFFFF);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// should prevent crashing the game if there's an issue
|
||||||
|
RATE_LIMITED_LOGGER.error("Unexpected gui rendering issue: ["+e.getMessage()+"]", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<? extends GuiEventListener> children()
|
||||||
|
{ return this.children; }
|
||||||
|
|
||||||
|
#if MC_VER >= MC_1_17_1
|
||||||
|
@Override
|
||||||
|
public @NotNull List<? extends NarratableEntry> narratables()
|
||||||
|
{ return this.children; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// event handling //
|
||||||
|
//================//
|
||||||
|
|
||||||
|
public static class ConfigCoreInterface implements IConfigGui
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* in the future it would be good to pass in the current page and other variables,
|
||||||
|
* but for now just knowing when the page is closed is good enough
|
||||||
|
*/
|
||||||
|
public final ArrayList<Runnable> onScreenChangeListenerList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addOnScreenChangeListener(Runnable newListener) { this.onScreenChangeListenerList.add(newListener); }
|
||||||
|
@Override
|
||||||
|
public void removeOnScreenChangeListener(Runnable oldListener) { this.onScreenChangeListenerList.remove(oldListener); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+810
@@ -0,0 +1,810 @@
|
|||||||
|
package com.seibel.distanthorizons.common.wrappers.gui.classicConfig;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.api.enums.config.DisallowSelectingViaConfigGui;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.config.ConfigGuiInfo;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
|
||||||
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
|
import com.seibel.distanthorizons.core.config.ConfigHandler;
|
||||||
|
import com.seibel.distanthorizons.core.config.types.*;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.updater.ChangelogScreen;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.core.config.types.enums.EConfigValidity;
|
||||||
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
|
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.util.AnnotationUtil;
|
||||||
|
import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper;
|
||||||
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER >= MC_1_17_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_10
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
#else
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
|
||||||
|
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
|
||||||
|
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.Translatable;
|
||||||
|
|
||||||
|
class DhConfigScreen extends DhScreen
|
||||||
|
{
|
||||||
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
|
private static final ILangWrapper LANG_WRAPPER = SingletonInjector.INSTANCE.get(ILangWrapper.class);
|
||||||
|
|
||||||
|
private static final String TRANSLATION_PREFIX = ModInfo.ID + ".config.";
|
||||||
|
|
||||||
|
private static final MinecraftClientWrapper MC_CLIENT = MinecraftClientWrapper.INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
private final Screen parent;
|
||||||
|
private final String category;
|
||||||
|
private ClassicConfigGUI.ConfigListWidget configListWidget;
|
||||||
|
private boolean reload = false;
|
||||||
|
|
||||||
|
private Button doneButton;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// constructor //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
protected DhConfigScreen(Screen parent, String category)
|
||||||
|
{
|
||||||
|
super(Translatable(
|
||||||
|
LANG_WRAPPER.langExists(ModInfo.ID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
|
||||||
|
ModInfo.ID + ".config.title" :
|
||||||
|
ModInfo.ID + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
|
||||||
|
);
|
||||||
|
this.parent = parent;
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
//=============//
|
||||||
|
// tick update //
|
||||||
|
//=============//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() { super.tick(); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==================//
|
||||||
|
// menu UI creation //
|
||||||
|
//==================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init()
|
||||||
|
{
|
||||||
|
super.init();
|
||||||
|
if (!this.reload)
|
||||||
|
{
|
||||||
|
ConfigHandler.INSTANCE.configFileHandler.loadFromFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Changelog button
|
||||||
|
if (Config.Client.Advanced.AutoUpdater.enableAutoUpdater.get()
|
||||||
|
// we only have changelogs for stable builds
|
||||||
|
&& !ModInfo.IS_DEV_BUILD)
|
||||||
|
{
|
||||||
|
this.addBtn(new TexturedButtonWidget(
|
||||||
|
// Where the button is on the screen
|
||||||
|
this.width - 28, this.height - 28,
|
||||||
|
// Width and height of the button
|
||||||
|
20, 20,
|
||||||
|
// texture UV Offset
|
||||||
|
0, 0,
|
||||||
|
// Some texture stuff
|
||||||
|
0,
|
||||||
|
#if MC_VER < MC_1_21_1
|
||||||
|
new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"),
|
||||||
|
#elif MC_VER <= MC_1_21_10
|
||||||
|
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "textures/gui/changelog.png"),
|
||||||
|
#else
|
||||||
|
Identifier.fromNamespaceAndPath(ModInfo.ID, "textures/gui/changelog.png"),
|
||||||
|
#endif
|
||||||
|
20, 20,
|
||||||
|
// Create the button and tell it where to go
|
||||||
|
(buttonWidget) -> {
|
||||||
|
ChangelogScreen changelogScreen = new ChangelogScreen(this);
|
||||||
|
if (changelogScreen.usable)
|
||||||
|
{
|
||||||
|
DhScreenUtil.showScreen(changelogScreen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.warn("Changelog was not able to open");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Add a title to the button
|
||||||
|
Translatable(ModInfo.ID + ".updater.title")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// back button
|
||||||
|
this.addBtn(MakeBtn(Translatable("distanthorizons.general.back"),
|
||||||
|
(this.width / 2) - 154, this.height - 28,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_HEIGHT,
|
||||||
|
(button) ->
|
||||||
|
{
|
||||||
|
ConfigHandler.INSTANCE.configFileHandler.loadFromFile();
|
||||||
|
DhScreenUtil.showScreen(this.parent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// done/close button
|
||||||
|
this.doneButton = this.addBtn(
|
||||||
|
MakeBtn(Translatable("distanthorizons.general.done"),
|
||||||
|
(this.width / 2) + 4, this.height - 28,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_HEIGHT,
|
||||||
|
(button) ->
|
||||||
|
{
|
||||||
|
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
|
||||||
|
DhScreenUtil.showScreen(this.parent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.configListWidget = new ClassicConfigGUI.ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, 32, 25);
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_6 // no background is rendered in MC 1.20.6+
|
||||||
|
if (this.minecraft != null && this.minecraft.level != null)
|
||||||
|
{
|
||||||
|
this.configListWidget.setRenderBackground(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this.addWidget(this.configListWidget);
|
||||||
|
|
||||||
|
for (AbstractConfigBase<?> configEntry : ConfigHandler.INSTANCE.configBaseList)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (configEntry.getCategory().matches(this.category)
|
||||||
|
&& configEntry.getAppearance().showInGui)
|
||||||
|
{
|
||||||
|
this.addMenuItem(configEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
String message = "ERROR: Failed to show [" + configEntry.getNameAndCategory() + "], error: [" + e.getMessage() + "]";
|
||||||
|
if (configEntry.get() != null)
|
||||||
|
{
|
||||||
|
message += " with the value [" + configEntry.get() + "] with type [" + configEntry.getType() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.error(message, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassicConfigGUI.CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run());
|
||||||
|
}
|
||||||
|
private void addMenuItem(AbstractConfigBase<?> configEntry)
|
||||||
|
{
|
||||||
|
trySetupConfigEntry(configEntry);
|
||||||
|
|
||||||
|
if (this.tryCreateInputField(configEntry)) return;
|
||||||
|
if (this.tryCreateCategoryButton(configEntry)) return;
|
||||||
|
if (this.tryCreateButton(configEntry)) return;
|
||||||
|
if (this.tryCreateComment(configEntry)) return;
|
||||||
|
if (this.tryCreateSpacer(configEntry)) return;
|
||||||
|
if (this.tryCreateLinkedEntry(configEntry)) return;
|
||||||
|
|
||||||
|
LOGGER.warn("Config [" + configEntry.getNameAndCategory() + "] failed to show. Please try something like changing its type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void trySetupConfigEntry(AbstractConfigBase<?> configMenuOption)
|
||||||
|
{
|
||||||
|
configMenuOption.guiValue = new ConfigGuiInfo();
|
||||||
|
Class<?> configValueClass = configMenuOption.getType();
|
||||||
|
|
||||||
|
if (configMenuOption instanceof ConfigEntry)
|
||||||
|
{
|
||||||
|
ConfigEntry<?> configEntry = (ConfigEntry<?>) configMenuOption;
|
||||||
|
|
||||||
|
if (configValueClass == Integer.class)
|
||||||
|
{
|
||||||
|
setupTextMenuOption(configEntry, Integer::parseInt, ClassicConfigGUI.INTEGER_ONLY_REGEX, true);
|
||||||
|
}
|
||||||
|
else if (configValueClass == Double.class)
|
||||||
|
{
|
||||||
|
setupTextMenuOption(configEntry, Double::parseDouble, ClassicConfigGUI.DECIMAL_ONLY_REGEX, false);
|
||||||
|
}
|
||||||
|
else if (configValueClass == Float.class)
|
||||||
|
{
|
||||||
|
setupTextMenuOption(configEntry, Float::parseFloat, ClassicConfigGUI.DECIMAL_ONLY_REGEX, false);
|
||||||
|
}
|
||||||
|
else if (configValueClass == String.class || configValueClass == List.class)
|
||||||
|
{
|
||||||
|
// For string or list
|
||||||
|
setupTextMenuOption(configEntry, String::length, null, true);
|
||||||
|
}
|
||||||
|
else if (configValueClass == Boolean.class)
|
||||||
|
{
|
||||||
|
ConfigEntry<Boolean> booleanConfigEntry = (ConfigEntry<Boolean>) configEntry;
|
||||||
|
setupBooleanMenuOption(booleanConfigEntry);
|
||||||
|
}
|
||||||
|
else if (configValueClass.isEnum())
|
||||||
|
{
|
||||||
|
ConfigEntry<Enum<?>> enumConfigEntry = (ConfigEntry<Enum<?>>) configEntry;
|
||||||
|
Class<? extends Enum<?>> configEnumClass = (Class<? extends Enum<?>>) configValueClass;
|
||||||
|
setupEnumMenuOption(enumConfigEntry, configEnumClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGGER.error("No definition for config with type: [" + configValueClass.getName() + "], for config: [" + configMenuOption.name + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private static void setupTextMenuOption(AbstractConfigBase<?> configMenuOption, Function<String, Number> parsingFunc, @Nullable Pattern pattern, boolean cast)
|
||||||
|
{
|
||||||
|
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) configMenuOption.guiValue);
|
||||||
|
|
||||||
|
configGuiInfo.tooltipFunction =
|
||||||
|
(editBox, button) ->
|
||||||
|
(stringValue) ->
|
||||||
|
{
|
||||||
|
boolean isNumber = (pattern != null);
|
||||||
|
|
||||||
|
stringValue = stringValue.trim();
|
||||||
|
if (!(stringValue.isEmpty() || !isNumber || pattern.matcher(stringValue).matches()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Number numberValue = configMenuOption.typeIsFloatingPointNumber() ? 0.0 : 0; // different default values are needed so implicit casting works correctly (if not done casting from 0 (an int) to a double will cause an exception)
|
||||||
|
configGuiInfo.errorMessage = null;
|
||||||
|
if (isNumber
|
||||||
|
&& !stringValue.isEmpty()
|
||||||
|
&& !stringValue.equals("-")
|
||||||
|
&& !stringValue.equals("."))
|
||||||
|
{
|
||||||
|
ConfigEntry<Number> numberConfigEntry = (ConfigEntry<Number>) configMenuOption;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
numberValue = parsingFunc.apply(stringValue);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
numberValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
EConfigValidity validity = numberConfigEntry.getValidity(numberValue);
|
||||||
|
switch (validity)
|
||||||
|
{
|
||||||
|
case VALID:
|
||||||
|
configGuiInfo.errorMessage = null;
|
||||||
|
break;
|
||||||
|
case NUMBER_TOO_LOW:
|
||||||
|
configGuiInfo.errorMessage = TextOrTranslatable("§cMinimum length is " + numberConfigEntry.getMin());
|
||||||
|
break;
|
||||||
|
case NUMBER_TOO_HIGH:
|
||||||
|
configGuiInfo.errorMessage = TextOrTranslatable("§cMaximum length is " + numberConfigEntry.getMax());
|
||||||
|
break;
|
||||||
|
case INVALID:
|
||||||
|
configGuiInfo.errorMessage = TextOrTranslatable("§cValue is invalid");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
editBox.setTextColor(((ConfigEntry<Number>) configMenuOption).getValidity(numberValue) == EConfigValidity.VALID ? 0xFFFFFFFF : 0xFFFF7777); // white and red
|
||||||
|
|
||||||
|
|
||||||
|
if (configMenuOption.getType() == String.class
|
||||||
|
|| configMenuOption.getType() == List.class)
|
||||||
|
{
|
||||||
|
((ConfigEntry<String>) configMenuOption).uiSetWithoutSaving(stringValue);
|
||||||
|
}
|
||||||
|
else if (((ConfigEntry<Number>) configMenuOption).getValidity(numberValue) == EConfigValidity.VALID)
|
||||||
|
{
|
||||||
|
if (!cast)
|
||||||
|
{
|
||||||
|
((ConfigEntry<Number>) configMenuOption).uiSetWithoutSaving(numberValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((ConfigEntry<Number>) configMenuOption).uiSetWithoutSaving(numberValue != null ? numberValue.intValue() : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private static void setupBooleanMenuOption(ConfigEntry<Boolean> booleanConfigEntry)
|
||||||
|
{
|
||||||
|
// For boolean
|
||||||
|
Function<Object, Component> func = value -> Translatable("distanthorizons.general." + ((Boolean) value ? "true" : "false")).withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||||
|
|
||||||
|
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) booleanConfigEntry.guiValue);
|
||||||
|
|
||||||
|
configGuiInfo.buttonOptionMap =
|
||||||
|
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
|
||||||
|
(button) ->
|
||||||
|
{
|
||||||
|
button.active = !booleanConfigEntry.apiIsOverriding();
|
||||||
|
|
||||||
|
booleanConfigEntry.uiSetWithoutSaving(!booleanConfigEntry.get());
|
||||||
|
button.setMessage(func.apply(booleanConfigEntry.get()));
|
||||||
|
}, func);
|
||||||
|
}
|
||||||
|
private static void setupEnumMenuOption(ConfigEntry<Enum<?>> enumConfigEntry, Class<? extends Enum<?>> enumClass)
|
||||||
|
{
|
||||||
|
List<Enum<?>> enumList = Arrays.asList(enumClass.getEnumConstants());
|
||||||
|
|
||||||
|
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) enumConfigEntry.guiValue);
|
||||||
|
|
||||||
|
Function<Object, Component> getEnumTranslatableFunc = (value) -> Translatable(TRANSLATION_PREFIX + "enum." + enumClass.getSimpleName() + "." + enumConfigEntry.get().toString());
|
||||||
|
configGuiInfo.buttonOptionMap =
|
||||||
|
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
|
||||||
|
(button) ->
|
||||||
|
{
|
||||||
|
// get the currently selected enum and enum index
|
||||||
|
int startingIndex = enumList.indexOf(enumConfigEntry.get());
|
||||||
|
Enum<?> enumValue = enumList.get(startingIndex);
|
||||||
|
|
||||||
|
boolean shiftPressed =
|
||||||
|
InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_LEFT_SHIFT)
|
||||||
|
|| InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_RIGHT_SHIFT);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// move forward or backwards depending on if the shift key is pressed
|
||||||
|
int index = shiftPressed ? startingIndex - 1 : startingIndex + 1;
|
||||||
|
|
||||||
|
// wrap around to the other side of the array when necessary
|
||||||
|
if (index >= enumList.size())
|
||||||
|
{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
else if (index < 0)
|
||||||
|
{
|
||||||
|
index = enumList.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// walk through the enums to find the next selectable one
|
||||||
|
while (index != startingIndex)
|
||||||
|
{
|
||||||
|
enumValue = enumList.get(index);
|
||||||
|
if (!AnnotationUtil.doesEnumHaveAnnotation(enumValue, DisallowSelectingViaConfigGui.class))
|
||||||
|
{
|
||||||
|
// this enum shouldn't be selectable via the UI,
|
||||||
|
// skip it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// move forward or backwards depending on if the shift key is pressed
|
||||||
|
index = shiftPressed ? index - 1 : index + 1;
|
||||||
|
|
||||||
|
// wrap around to the other side of the array when necessary
|
||||||
|
if (index >= enumList.size())
|
||||||
|
{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
else if (index < 0)
|
||||||
|
{
|
||||||
|
index = enumList.size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (index == startingIndex)
|
||||||
|
{
|
||||||
|
// one of the enums should be selectable, this is a programmer error
|
||||||
|
enumValue = enumList.get(startingIndex);
|
||||||
|
LOGGER.warn("Enum [" + enumValue.getClass() + "] doesn't contain any values that should be selectable via the UI, sticking to the currently selected value [" + enumValue + "].");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enumConfigEntry.uiSetWithoutSaving(enumValue);
|
||||||
|
|
||||||
|
button.active = !enumConfigEntry.apiIsOverriding();
|
||||||
|
|
||||||
|
button.setMessage(getEnumTranslatableFunc.apply(enumConfigEntry.get()));
|
||||||
|
}, getEnumTranslatableFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean tryCreateInputField(AbstractConfigBase<?> configBase)
|
||||||
|
{
|
||||||
|
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) configBase.guiValue);
|
||||||
|
|
||||||
|
if (configBase instanceof ConfigEntry)
|
||||||
|
{
|
||||||
|
ConfigEntry configEntry = (ConfigEntry) configBase;
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// reset button //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
Button.OnPress btnAction = (button) ->
|
||||||
|
{
|
||||||
|
configEntry.uiSetWithoutSaving(configEntry.getDefaultValue());
|
||||||
|
this.reload = true;
|
||||||
|
DhScreenUtil.showScreen(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
int resetButtonPosX = this.width
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_WIDTH
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
|
||||||
|
int resetButtonPosZ = 0;
|
||||||
|
|
||||||
|
Button resetButton = MakeBtn(
|
||||||
|
Translatable("distanthorizons.general.reset").withStyle(ChatFormatting.RED),
|
||||||
|
resetButtonPosX, resetButtonPosZ,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_HEIGHT,
|
||||||
|
btnAction);
|
||||||
|
|
||||||
|
if (configEntry.apiIsOverriding())
|
||||||
|
{
|
||||||
|
resetButton.active = false;
|
||||||
|
resetButton.setMessage(Translatable("distanthorizons.general.apiOverride").withStyle(ChatFormatting.DARK_GRAY));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resetButton.active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==============//
|
||||||
|
// option field //
|
||||||
|
//==============//
|
||||||
|
|
||||||
|
Component textComponent = this.GetTranslatableTextComponentForConfig(configEntry);
|
||||||
|
|
||||||
|
int optionFieldPosX = this.width
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_WIDTH
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.BUTTON_WIDTH_SPACING
|
||||||
|
- ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH;
|
||||||
|
int optionFieldPosZ = 0;
|
||||||
|
|
||||||
|
if (configGuiInfo.buttonOptionMap != null)
|
||||||
|
{
|
||||||
|
// enum/multi option input button
|
||||||
|
|
||||||
|
Map.Entry<Button.OnPress, Function<Object, Component>> widget = configGuiInfo.buttonOptionMap;
|
||||||
|
if (configEntry.getType().isEnum())
|
||||||
|
{
|
||||||
|
widget.setValue((value) -> Translatable(TRANSLATION_PREFIX + "enum." + configEntry.getType().getSimpleName() + "." + configEntry.get().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Button button = MakeBtn(
|
||||||
|
widget.getValue().apply(configEntry.get()),
|
||||||
|
optionFieldPosX, optionFieldPosZ,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
|
||||||
|
widget.getKey());
|
||||||
|
|
||||||
|
// deactivate the button if the API is overriding it
|
||||||
|
button.active = !configEntry.apiIsOverriding();
|
||||||
|
|
||||||
|
|
||||||
|
this.configListWidget.addButton(this, configEntry,
|
||||||
|
button,
|
||||||
|
resetButton,
|
||||||
|
null,
|
||||||
|
textComponent);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// text box input
|
||||||
|
|
||||||
|
EditBox widget = new EditBox(this.font,
|
||||||
|
optionFieldPosX, optionFieldPosZ,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH - 4, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
|
||||||
|
Translatable(""));
|
||||||
|
widget.setMaxLength(3_000_000); // hopefully 3 million characters should be enough for any normal use-case, lol
|
||||||
|
widget.insertText(String.valueOf(configEntry.get()));
|
||||||
|
|
||||||
|
Predicate<String> processor = configGuiInfo.tooltipFunction.apply(widget, this.doneButton);
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
widget.setFilter(processor);
|
||||||
|
#else
|
||||||
|
widget.setResponder(processor::test);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this.configListWidget.addButton(this, configEntry, widget, resetButton, null, textComponent);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean tryCreateCategoryButton(AbstractConfigBase<?> configType)
|
||||||
|
{
|
||||||
|
if (configType instanceof ConfigCategory)
|
||||||
|
{
|
||||||
|
ConfigCategory configCategory = (ConfigCategory) configType;
|
||||||
|
|
||||||
|
Component textComponent = this.GetTranslatableTextComponentForConfig(configCategory);
|
||||||
|
|
||||||
|
int categoryPosX = this.width - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH - ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
|
||||||
|
int categoryPosZ = this.height - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT; // Note: the posZ value here seems to be ignored
|
||||||
|
|
||||||
|
Button widget = MakeBtn(textComponent,
|
||||||
|
categoryPosX, categoryPosZ,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
|
||||||
|
((button) ->
|
||||||
|
{
|
||||||
|
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
|
||||||
|
DhScreenUtil.showScreen(ClassicConfigGUI.getScreen(this, configCategory.getDestination()));
|
||||||
|
}));
|
||||||
|
this.configListWidget.addButton(this, configType, widget, null, null, null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean tryCreateButton(AbstractConfigBase<?> configType)
|
||||||
|
{
|
||||||
|
if (configType instanceof ConfigUIButton)
|
||||||
|
{
|
||||||
|
ConfigUIButton configUiButton = (ConfigUIButton) configType;
|
||||||
|
|
||||||
|
Component textComponent = this.GetTranslatableTextComponentForConfig(configUiButton);
|
||||||
|
|
||||||
|
int buttonPosX = this.width - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH - ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
|
||||||
|
|
||||||
|
Button widget = MakeBtn(textComponent,
|
||||||
|
buttonPosX, this.height - 28,
|
||||||
|
ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
|
||||||
|
(button) -> ((ConfigUIButton) configType).runAction());
|
||||||
|
this.configListWidget.addButton(this, configType, widget, null, null, null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean tryCreateComment(AbstractConfigBase<?> configType)
|
||||||
|
{
|
||||||
|
if (configType instanceof ConfigUIComment)
|
||||||
|
{
|
||||||
|
ConfigUIComment configUiComment = (ConfigUIComment) configType;
|
||||||
|
|
||||||
|
Component textComponent = this.GetTranslatableTextComponentForConfig(configUiComment);
|
||||||
|
if (configUiComment.parentConfigPath != null)
|
||||||
|
{
|
||||||
|
textComponent = Translatable(TRANSLATION_PREFIX + configUiComment.parentConfigPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.configListWidget.addButton(this, configType, null, null, null, textComponent);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean tryCreateSpacer(AbstractConfigBase<?> configType)
|
||||||
|
{
|
||||||
|
if (configType instanceof ConfigUISpacer)
|
||||||
|
{
|
||||||
|
Button spacerButton = MakeBtn(Translatable("distanthorizons.general.spacer"),
|
||||||
|
10, 10, // having too small of a size causes division by 0 errors in older MC versions (IE 1.20.1)
|
||||||
|
1, 1,
|
||||||
|
(button) -> { });
|
||||||
|
|
||||||
|
spacerButton.visible = false;
|
||||||
|
this.configListWidget.addButton(this, configType, spacerButton, null, null, null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean tryCreateLinkedEntry(AbstractConfigBase<?> configType)
|
||||||
|
{
|
||||||
|
if (configType instanceof ConfigUiLinkedEntry)
|
||||||
|
{
|
||||||
|
this.addMenuItem(((ConfigUiLinkedEntry) configType).get());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component GetTranslatableTextComponentForConfig(AbstractConfigBase<?> configType)
|
||||||
|
{ return Translatable(TRANSLATION_PREFIX + configType.getNameAndCategory()); }
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===========//
|
||||||
|
// rendering //
|
||||||
|
//===========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
@Override
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
public void extractRenderState(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#if MC_VER < MC_1_20_2 // 1.20.2 now enables this by default in the `this.list.render` function
|
||||||
|
this.renderBackground(matrices);
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
#else
|
||||||
|
super.extractRenderState(matrices, mouseX, mouseY, delta);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Render buttons
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
this.configListWidget.render(matrices, mouseX, mouseY, delta);
|
||||||
|
#else
|
||||||
|
this.configListWidget.extractRenderState(matrices, mouseX, mouseY, delta);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Render config title
|
||||||
|
this.DhDrawCenteredString(matrices, this.font, this.title,
|
||||||
|
this.width / 2, 15,
|
||||||
|
#if MC_VER < MC_1_21_6
|
||||||
|
0xFFFFFF // RGB white
|
||||||
|
#else
|
||||||
|
0xFFFFFFFF // ARGB white
|
||||||
|
#endif );
|
||||||
|
|
||||||
|
|
||||||
|
// render DH version
|
||||||
|
this.DhDrawString(matrices, this.font, TextOrLiteral(ModInfo.VERSION), 2, this.height - 10,
|
||||||
|
#if MC_VER < MC_1_21_6
|
||||||
|
0xAAAAAA // RGB white
|
||||||
|
#else
|
||||||
|
0xFFAAAAAA // ARGB white
|
||||||
|
#endif );
|
||||||
|
|
||||||
|
// If the update is pending, display this message to inform the user that it will apply when the game restarts
|
||||||
|
if (SelfUpdater.deleteOldJarOnJvmShutdown)
|
||||||
|
{
|
||||||
|
this.DhDrawString(matrices, this.font, Translatable(ModInfo.ID + ".updater.waitingForClose"), 4, this.height - 42,
|
||||||
|
#if MC_VER < MC_1_21_6
|
||||||
|
0xFFFFFF // RGB white
|
||||||
|
#else
|
||||||
|
0xFFFFFFFF // ARGB white
|
||||||
|
#endif );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.renderTooltip(matrices, mouseX, mouseY, delta);
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_2
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if MC_VER < MC_1_20_1
|
||||||
|
private void renderTooltip(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
|
private void renderTooltip(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
private void renderTooltip(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
AbstractWidget hoveredWidget = this.configListWidget.getHoveredButton(mouseX, mouseY);
|
||||||
|
if (hoveredWidget == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ClassicConfigGUI.DhButtonEntry button = ClassicConfigGUI.DhButtonEntry.BUTTON_BY_WIDGET.get(hoveredWidget);
|
||||||
|
|
||||||
|
|
||||||
|
// A quick fix for tooltips on linked entries
|
||||||
|
AbstractConfigBase<?> configBase = ConfigUiLinkedEntry.class.isAssignableFrom(button.dhConfigType.getClass()) ?
|
||||||
|
((ConfigUiLinkedEntry) button.dhConfigType).get() :
|
||||||
|
button.dhConfigType;
|
||||||
|
|
||||||
|
boolean apiOverrideActive = false;
|
||||||
|
if (configBase instanceof ConfigEntry)
|
||||||
|
{
|
||||||
|
apiOverrideActive = ((ConfigEntry<?>) configBase).apiIsOverriding();
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = TRANSLATION_PREFIX + (configBase.category.isEmpty() ? "" : configBase.category + ".") + configBase.getName() + ".@tooltip";
|
||||||
|
|
||||||
|
if (apiOverrideActive)
|
||||||
|
{
|
||||||
|
key = "distanthorizons.general.disabledByApi.@tooltip";
|
||||||
|
}
|
||||||
|
|
||||||
|
// display the validation error tooltip if present
|
||||||
|
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) configBase.guiValue);
|
||||||
|
if (configGuiInfo.errorMessage != null)
|
||||||
|
{
|
||||||
|
this.DhRenderTooltip(matrices, this.font, configGuiInfo.errorMessage, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
// display the tooltip if present
|
||||||
|
else if (LANG_WRAPPER.langExists(key))
|
||||||
|
{
|
||||||
|
List<Component> list = new ArrayList<>();
|
||||||
|
String lang = LANG_WRAPPER.getLang(key);
|
||||||
|
for (String langLine : lang.split("\n"))
|
||||||
|
{
|
||||||
|
list.add(TextOrTranslatable(langLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.DhRenderComponentTooltip(matrices, this.font, list, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==========//
|
||||||
|
// shutdown //
|
||||||
|
//==========//
|
||||||
|
//region
|
||||||
|
|
||||||
|
/** When you close it, it goes to the previous screen and saves */
|
||||||
|
@Override
|
||||||
|
public void onClose()
|
||||||
|
{
|
||||||
|
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
|
||||||
|
DhScreenUtil.showScreen(this.parent);
|
||||||
|
|
||||||
|
ClassicConfigGUI.CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run());
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+19
-7
@@ -1,6 +1,7 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.gui.updater;
|
package com.seibel.distanthorizons.common.wrappers.gui.updater;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil;
|
||||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||||
@@ -23,8 +24,10 @@ import net.minecraft.client.gui.narration.NarratableEntry;
|
|||||||
#if MC_VER < MC_1_20_1
|
#if MC_VER < MC_1_20_1
|
||||||
import net.minecraft.client.gui.GuiComponent;
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
#else
|
||||||
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -168,8 +171,10 @@ public class ChangelogScreen extends DhScreen
|
|||||||
@Override
|
@Override
|
||||||
#if MC_VER < MC_1_20_1
|
#if MC_VER < MC_1_20_1
|
||||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
public void extractRenderState(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_20_2
|
#if MC_VER < MC_1_20_2
|
||||||
@@ -206,16 +211,19 @@ public class ChangelogScreen extends DhScreen
|
|||||||
|
|
||||||
|
|
||||||
// render order matters, otherwise on 1.20.6+ the blurred background will render on top of the text
|
// render order matters, otherwise on 1.20.6+ the blurred background will render on top of the text
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
||||||
this.changelogArea.render(matrices, mouseX, mouseY, delta); // Render the changelog
|
this.changelogArea.render(matrices, mouseX, mouseY, delta); // Render the changelog
|
||||||
|
#else
|
||||||
|
super.extractRenderState(matrices, mouseX, mouseY, delta); // Render the buttons
|
||||||
|
this.changelogArea.extractRenderState(matrices, mouseX, mouseY, delta); // Render the changelog
|
||||||
|
#endif
|
||||||
|
|
||||||
this.DhDrawCenteredString(matrices, this.font, this.title, this.width / 2, 15, 0xFFFFFF); // Render title
|
this.DhDrawCenteredString(matrices, this.font, this.title, this.width / 2, 15, 0xFFFFFF); // Render title
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose()
|
public void onClose() { DhScreenUtil.showScreen(this.parent); }
|
||||||
{
|
|
||||||
Objects.requireNonNull(this.minecraft).setScreen(this.parent); // Goto the parent screen
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TextArea extends ContainerObjectSelectionList<ButtonEntry>
|
public static class TextArea extends ContainerObjectSelectionList<ButtonEntry>
|
||||||
{
|
{
|
||||||
@@ -264,10 +272,14 @@ public class ChangelogScreen extends DhScreen
|
|||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
public void render(GuiGraphics matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||||
{ matrices.drawString(textRenderer, this.text, 12, y + 5, 0xFFFFFF); }
|
{ matrices.drawString(textRenderer, this.text, 12, y + 5, 0xFFFFFF); }
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
@Override
|
@Override
|
||||||
public void renderContent(GuiGraphics matrices, int y, int x, boolean hovered, float tickDelta)
|
public void renderContent(GuiGraphics matrices, int y, int x, boolean hovered, float tickDelta)
|
||||||
{ matrices.drawString(textRenderer, this.text, 12, y + 5, 0xFFFFFF); }
|
{ matrices.drawString(textRenderer, this.text, 12, y + 5, 0xFFFFFF); }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void extractContent(GuiGraphicsExtractor matrices, int y, int x, boolean hovered, float tickDelta)
|
||||||
|
{ matrices.text(textRenderer, this.text, 12, y + 5, 0xFFFFFF); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+14
-5
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.common.wrappers.gui.updater;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil;
|
||||||
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
|
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
|
||||||
import com.seibel.distanthorizons.core.jar.ModJarInfo;
|
import com.seibel.distanthorizons.core.jar.ModJarInfo;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
@@ -13,10 +14,12 @@ import com.seibel.distanthorizons.core.logging.DhLogger;
|
|||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
|
||||||
#if MC_VER >= MC_1_20_1
|
#if MC_VER < MC_1_20_1
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
#elif MC_VER <= MC_1_21_11
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
#else
|
#else
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
@@ -135,7 +138,7 @@ public class UpdateModScreen extends DhScreen
|
|||||||
#endif
|
#endif
|
||||||
20, 20,
|
20, 20,
|
||||||
// Create the button and tell it where to go
|
// Create the button and tell it where to go
|
||||||
(buttonWidget) -> Objects.requireNonNull(this.minecraft).setScreen(new ChangelogScreen(this, this.newVersionID)),
|
(buttonWidget) -> DhScreenUtil.showScreen(new ChangelogScreen(this, this.newVersionID)),
|
||||||
// Add a title to the button
|
// Add a title to the button
|
||||||
Translatable(ModInfo.ID + ".updater.title")
|
Translatable(ModInfo.ID + ".updater.title")
|
||||||
));
|
));
|
||||||
@@ -172,8 +175,10 @@ public class UpdateModScreen extends DhScreen
|
|||||||
@Override
|
@Override
|
||||||
#if MC_VER < MC_1_20_1
|
#if MC_VER < MC_1_20_1
|
||||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
|
||||||
|
#else
|
||||||
|
public void extractRenderState(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if MC_VER < MC_1_20_2
|
#if MC_VER < MC_1_20_2
|
||||||
@@ -184,7 +189,11 @@ public class UpdateModScreen extends DhScreen
|
|||||||
// background blur is already being rendered, rendering again causes the game to crash
|
// background blur is already being rendered, rendering again causes the game to crash
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
||||||
|
#else
|
||||||
|
super.extractRenderState(matrices, mouseX, mouseY, delta);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Render the text's
|
// Render the text's
|
||||||
this.DhDrawCenteredString(matrices, this.font,
|
this.DhDrawCenteredString(matrices, this.font,
|
||||||
@@ -210,7 +219,7 @@ public class UpdateModScreen extends DhScreen
|
|||||||
@Override
|
@Override
|
||||||
public void onClose()
|
public void onClose()
|
||||||
{
|
{
|
||||||
Objects.requireNonNull(this.minecraft).setScreen(this.parent); // Go to the parent screen
|
DhScreenUtil.showScreen(this.parent); // Go to the parent screen
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+25
-2
@@ -22,6 +22,7 @@ package com.seibel.distanthorizons.common.wrappers.minecraft;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.Window;
|
import com.mojang.blaze3d.platform.Window;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.gui.NativeDialogUtil;
|
||||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||||
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
||||||
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
|
||||||
@@ -172,7 +173,12 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
|||||||
#else
|
#else
|
||||||
ChunkPos playerPos = player.chunkPosition();
|
ChunkPos playerPos = player.chunkPosition();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
return new DhChunkPos(playerPos.x, playerPos.z);
|
return new DhChunkPos(playerPos.x, playerPos.z);
|
||||||
|
#else
|
||||||
|
return new DhChunkPos(playerPos.x(), playerPos.z());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -225,9 +231,13 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
|||||||
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/false);
|
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/false);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread(() ->
|
RenderThreadTaskHandler.INSTANCE.queueRunningOnRenderThread("MinecraftClientWrapper sendChatMessage", () ->
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/false);
|
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/false);
|
||||||
|
#else
|
||||||
|
player.sendSystemMessage(net.minecraft.network.chat.Component.translatable(string));
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -243,8 +253,10 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
|||||||
|
|
||||||
#if MC_VER < MC_1_19_2
|
#if MC_VER < MC_1_19_2
|
||||||
player.displayClientMessage(new TextComponent(string), /*isOverlay*/true);
|
player.displayClientMessage(new TextComponent(string), /*isOverlay*/true);
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/true);
|
player.displayClientMessage(net.minecraft.network.chat.Component.translatable(string), /*isOverlay*/true);
|
||||||
|
#else
|
||||||
|
player.sendOverlayMessage(net.minecraft.network.chat.Component.translatable(string));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,17 +371,28 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
|||||||
public void crashMinecraft(String errorMessage, Throwable exception)
|
public void crashMinecraft(String errorMessage, Throwable exception)
|
||||||
{
|
{
|
||||||
LOGGER.fatal(ModInfo.READABLE_NAME + " had the following error: [" + errorMessage + "]. Crashing Minecraft...", exception);
|
LOGGER.fatal(ModInfo.READABLE_NAME + " had the following error: [" + errorMessage + "]. Crashing Minecraft...", exception);
|
||||||
|
|
||||||
|
// Only crash once the renderer has been set up.
|
||||||
|
// If the renderer hasn't been set up yet crashing MC will
|
||||||
|
// cause a Blaze3D/UI error instead of the error we're trying to send.
|
||||||
|
executeOnRenderThread(() ->
|
||||||
|
{
|
||||||
CrashReport report = new CrashReport(errorMessage, exception);
|
CrashReport report = new CrashReport(errorMessage, exception);
|
||||||
#if MC_VER < MC_1_20_4
|
#if MC_VER < MC_1_20_4
|
||||||
Minecraft.crash(report);
|
Minecraft.crash(report);
|
||||||
#else
|
#else
|
||||||
MINECRAFT.delayCrash(report);
|
MINECRAFT.delayCrash(report);
|
||||||
#endif
|
#endif
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeOnRenderThread(Runnable runnable) { MINECRAFT.execute(runnable); }
|
public void executeOnRenderThread(Runnable runnable) { MINECRAFT.execute(runnable); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showDialog(String title, String message, String dialogType, String iconType)
|
||||||
|
{ NativeDialogUtil.showDialog(title, message, dialogType, iconType); }
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
-15
@@ -176,21 +176,6 @@ public class MinecraftGLWrapper
|
|||||||
{
|
{
|
||||||
GL32.glDeleteBuffers(buffer);
|
GL32.glDeleteBuffers(buffer);
|
||||||
|
|
||||||
// attempt to fix a bug with Mac where de-allocated buffers
|
|
||||||
// are still being used, causing a SIGSEGV native crash
|
|
||||||
// and/or corrupting native memory
|
|
||||||
if (EPlatform.get() == EPlatform.MACOS)
|
|
||||||
{
|
|
||||||
// force the delete buffer (and any other in-flight) GL
|
|
||||||
// commands to finish before continuing
|
|
||||||
GL32.glFinish();
|
|
||||||
|
|
||||||
// James hates this idea.
|
|
||||||
// He kinda hopes it doesn't help,
|
|
||||||
// but maybe metal's API just doesn't finish correctly so we need to wait a moment longer before continuing.
|
|
||||||
try { Thread.sleep(1); } catch (InterruptedException ignore) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
// MC's implementation has a bug where it will throw:
|
// MC's implementation has a bug where it will throw:
|
||||||
// GL_INVALID_OPERATION in glBufferData(immutable)
|
// GL_INVALID_OPERATION in glBufferData(immutable)
|
||||||
// when attempting to delete Storage Buffers
|
// when attempting to delete Storage Buffers
|
||||||
|
|||||||
+65
-11
@@ -30,9 +30,10 @@ import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
|||||||
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.enums.EDhDirection;
|
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||||
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.misc.ILightMapWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||||
|
|
||||||
#if MC_VER < MC_1_17_1
|
#if MC_VER < MC_1_17_1
|
||||||
@@ -40,6 +41,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
|
|||||||
import net.minecraft.client.renderer.FogRenderer;
|
import net.minecraft.client.renderer.FogRenderer;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
#else
|
#else
|
||||||
|
import net.minecraft.client.renderer.fog.FogData;
|
||||||
import net.minecraft.client.renderer.fog.FogRenderer;
|
import net.minecraft.client.renderer.fog.FogRenderer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
|||||||
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 com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -96,6 +99,8 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
{
|
{
|
||||||
public static final MinecraftRenderWrapper INSTANCE = new MinecraftRenderWrapper();
|
public static final MinecraftRenderWrapper INSTANCE = new MinecraftRenderWrapper();
|
||||||
|
|
||||||
|
private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
|
||||||
|
|
||||||
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
|
||||||
private static final Minecraft MC = Minecraft.getInstance();
|
private static final Minecraft MC = Minecraft.getInstance();
|
||||||
|
|
||||||
@@ -131,9 +136,12 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
Camera camera = MC.gameRenderer.getMainCamera();
|
Camera camera = MC.gameRenderer.getMainCamera();
|
||||||
return new Vec3f(camera.getLookVector().x(), camera.getLookVector().y(), camera.getLookVector().z());
|
return new Vec3f(camera.getLookVector().x(), camera.getLookVector().y(), camera.getLookVector().z());
|
||||||
#else
|
#elif MC_VER <= MC_26_1_2
|
||||||
Camera camera = MC.gameRenderer.getMainCamera();
|
Camera camera = MC.gameRenderer.getMainCamera();
|
||||||
return new Vec3f(camera.forwardVector().x(), camera.forwardVector().y(), camera.forwardVector().z());
|
return new Vec3f(camera.forwardVector().x(), camera.forwardVector().y(), camera.forwardVector().z());
|
||||||
|
#else
|
||||||
|
Camera camera = MC.gameRenderer.mainCamera();
|
||||||
|
return new Vec3f(camera.forwardVector().x(), camera.forwardVector().y(), camera.forwardVector().z());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +173,12 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
@Override
|
@Override
|
||||||
public Vec3d getCameraExactPosition()
|
public Vec3d getCameraExactPosition()
|
||||||
{
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
Camera camera = MC.gameRenderer.getMainCamera();
|
Camera camera = MC.gameRenderer.getMainCamera();
|
||||||
|
#else
|
||||||
|
Camera camera = MC.gameRenderer.mainCamera();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
Vec3 projectedView = camera.getPosition();
|
Vec3 projectedView = camera.getPosition();
|
||||||
#else
|
#else
|
||||||
@@ -182,8 +195,10 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
return MC.getFrameTime();
|
return MC.getFrameTime();
|
||||||
#elif MC_VER < MC_1_21_3
|
#elif MC_VER < MC_1_21_3
|
||||||
return MC.getTimer().getRealtimeDeltaTicks();
|
return MC.getTimer().getRealtimeDeltaTicks();
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
return MC.deltaTracker.getRealtimeDeltaTicks();
|
return MC.deltaTracker.getRealtimeDeltaTicks();
|
||||||
|
#else
|
||||||
|
return MC.getDeltaTracker().getRealtimeDeltaTicks();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,12 +268,39 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
return Color.white;
|
return Color.white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float darkenAmount;
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
darkenAmount = MC.gameRenderer.getDarkenWorldAmount(MC.deltaTracker.getGameTimeDeltaPartialTick(true));
|
||||||
|
#elif MC_VER <= MC_26_1_2
|
||||||
|
darkenAmount = MC.gameRenderer.getBossOverlayWorldDarkening(MC.deltaTracker.getGameTimeDeltaPartialTick(true));
|
||||||
|
#else
|
||||||
|
darkenAmount = MC.gameRenderer.bossOverlayWorldDarkening(MC.deltaTracker.getGameTimeDeltaPartialTick(true));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
Camera camera = MC.gameRenderer.getMainCamera();
|
||||||
|
#else
|
||||||
|
Camera camera = MC.gameRenderer.mainCamera();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
Vector4f colorValues = mcFogRenderer.setupFog(
|
Vector4f colorValues = mcFogRenderer.setupFog(
|
||||||
MC.gameRenderer.getMainCamera(),
|
camera,
|
||||||
MC.options.getEffectiveRenderDistance(),
|
MC.options.getEffectiveRenderDistance(),
|
||||||
MC.deltaTracker,
|
MC.deltaTracker,
|
||||||
MC.gameRenderer.getDarkenWorldAmount(MC.deltaTracker.getGameTimeDeltaPartialTick(true)),
|
darkenAmount,
|
||||||
MC.level);
|
MC.level);
|
||||||
|
#else
|
||||||
|
FogData fogData = mcFogRenderer.setupFog(
|
||||||
|
camera,
|
||||||
|
MC.options.getEffectiveRenderDistance(),
|
||||||
|
MC.deltaTracker,
|
||||||
|
darkenAmount,
|
||||||
|
MC.level);
|
||||||
|
Vector4f colorValues = fogData.color;
|
||||||
|
#endif
|
||||||
|
|
||||||
return new Color(
|
return new Color(
|
||||||
Math.max(0f, Math.min(colorValues.x, 1f)), // r
|
Math.max(0f, Math.min(colorValues.x, 1f)), // r
|
||||||
Math.max(0f, Math.min(colorValues.y, 1f)), // g
|
Math.max(0f, Math.min(colorValues.y, 1f)), // g
|
||||||
@@ -296,9 +338,6 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getFov(float partialTicks) { return MC.gameRenderer.getFov(MC.gameRenderer.getMainCamera(), partialTicks, true); }
|
|
||||||
|
|
||||||
/** Measured in chunks */
|
/** Measured in chunks */
|
||||||
@Override
|
@Override
|
||||||
public int getRenderDistance()
|
public int getRenderDistance()
|
||||||
@@ -320,7 +359,14 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RenderTarget getRenderTarget() { return MC.getMainRenderTarget(); }
|
public RenderTarget getRenderTarget()
|
||||||
|
{
|
||||||
|
#if MC_VER <= MC_26_1_2
|
||||||
|
return MC.getMainRenderTarget();
|
||||||
|
#else
|
||||||
|
return MC.gameRenderer.mainRenderTarget();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mcRendersToFrameBuffer()
|
public boolean mcRendersToFrameBuffer()
|
||||||
@@ -346,7 +392,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
public int getTargetFramebuffer()
|
public int getTargetFramebuffer()
|
||||||
{
|
{
|
||||||
// used so we can access the framebuffer shaders end up rendering to
|
// used so we can access the framebuffer shaders end up rendering to
|
||||||
if (AbstractOptifineAccessor.optifinePresent())
|
if (OPTIFINE_ACCESSOR != null)
|
||||||
{
|
{
|
||||||
return this.finalLevelFrameBufferId;
|
return this.finalLevelFrameBufferId;
|
||||||
}
|
}
|
||||||
@@ -393,6 +439,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
// TODO vulkan deprecate(?) and add method to get color texture
|
||||||
@Override
|
@Override
|
||||||
public int getColorTextureId()
|
public int getColorTextureId()
|
||||||
{
|
{
|
||||||
@@ -457,9 +504,12 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
isBlind |= fluidState.is(FluidTags.WATER);
|
isBlind |= fluidState.is(FluidTags.WATER);
|
||||||
isBlind |= fluidState.is(FluidTags.LAVA);
|
isBlind |= fluidState.is(FluidTags.LAVA);
|
||||||
return isBlind;
|
return isBlind;
|
||||||
#else
|
#elif MC_VER <= MC_26_1_2
|
||||||
boolean isBlind = this.playerHasBlindingEffect();
|
boolean isBlind = this.playerHasBlindingEffect();
|
||||||
return MC.gameRenderer.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
|
return MC.gameRenderer.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
|
||||||
|
#else
|
||||||
|
boolean isBlind = this.playerHasBlindingEffect();
|
||||||
|
return MC.gameRenderer.mainCamera().getFluidInCamera() != FogType.NONE || isBlind;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +563,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
|||||||
if (MC.level != null)
|
if (MC.level != null)
|
||||||
{
|
{
|
||||||
Direction mcDir = McObjectConverter.Convert(lodDirection);
|
Direction mcDir = McObjectConverter.Convert(lodDirection);
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
return MC.level.getShade(mcDir, true);
|
return MC.level.getShade(mcDir, true);
|
||||||
|
#else
|
||||||
|
return MC.level.cardinalLighting().byFace(mcDir);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+31
-11
@@ -23,27 +23,47 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrap
|
|||||||
|
|
||||||
import net.minecraft.util.profiling.ProfilerFiller;
|
import net.minecraft.util.profiling.ProfilerFiller;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author James Seibel
|
|
||||||
* @version 11-20-2021
|
|
||||||
*/
|
|
||||||
public class ProfilerWrapper implements IProfilerWrapper
|
public class ProfilerWrapper implements IProfilerWrapper
|
||||||
{
|
{
|
||||||
public ProfilerFiller profiler;
|
public ProfilerFiller profiler;
|
||||||
|
|
||||||
public ProfilerWrapper(ProfilerFiller newProfiler) { this.profiler = newProfiler; }
|
public ProfilerWrapper(ProfilerFiller newProfiler) { this.profiler = newProfiler; }
|
||||||
|
|
||||||
|
|
||||||
/** starts a new section inside the currently running section */
|
|
||||||
@Override
|
@Override
|
||||||
public void push(String newSection) { this.profiler.push(newSection); }
|
public IProfileBlock push(String newSection)
|
||||||
|
{
|
||||||
|
this.profiler.push(newSection);
|
||||||
|
return new ProfileBlock(this.profiler);
|
||||||
|
}
|
||||||
|
|
||||||
/** ends the currently running section and starts a new one */
|
|
||||||
@Override
|
@Override
|
||||||
public void popPush(String newSection) { this.profiler.popPush(newSection); }
|
public void popPush(String newSection)
|
||||||
|
{
|
||||||
|
this.profiler.popPush(newSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//================//
|
||||||
|
// helper classes //
|
||||||
|
//================//
|
||||||
|
//region
|
||||||
|
|
||||||
|
public static class ProfileBlock implements IProfileBlock
|
||||||
|
{
|
||||||
|
private final ProfilerFiller profiler;
|
||||||
|
public ProfileBlock(ProfilerFiller newProfiler) { this.profiler = newProfiler; }
|
||||||
|
|
||||||
|
|
||||||
/** ends the currently running section */
|
|
||||||
@Override
|
@Override
|
||||||
public void pop() { this.profiler.pop(); }
|
public void close()
|
||||||
|
{
|
||||||
|
this.profiler.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ import net.minecraft.world.level.chunk.status.ChunkStatus;
|
|||||||
#if MC_VER < MC_1_21_3
|
#if MC_VER < MC_1_21_3
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
#else
|
#else
|
||||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER <= MC_1_21_10
|
#if MC_VER <= MC_1_21_10
|
||||||
|
|||||||
+22
-35
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import com.seibel.distanthorizons.api.DhApi;
|
import com.seibel.distanthorizons.api.DhApi;
|
||||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
|
||||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.chunkFileHandling.ChunkFileReader;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.chunkFileHandling.ChunkFileReader;
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject.*;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject.*;
|
||||||
@@ -54,6 +55,7 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepBiomes;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepBiomes;
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepFeatures;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepFeatures;
|
||||||
@@ -116,6 +118,8 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
|
|
||||||
|
|
||||||
private final IDhServerLevel dhServerLevel;
|
private final IDhServerLevel dhServerLevel;
|
||||||
|
@Nullable
|
||||||
|
private final ChunkUpdateQueueManager updateManager;
|
||||||
|
|
||||||
public final InternalServerGenerator internalServerGenerator;
|
public final InternalServerGenerator internalServerGenerator;
|
||||||
public final ChunkFileReader chunkFileReader;
|
public final ChunkFileReader chunkFileReader;
|
||||||
@@ -150,22 +154,12 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
boolean isTerraFirmaCraftPresent = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("net.dries007.tfc.world.TFCChunkGenerator");
|
|
||||||
isTerraFirmaCraftPresent = true;
|
|
||||||
LOGGER.info("TerraFirmaCraft detected.");
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException ignore) { }
|
|
||||||
|
|
||||||
|
|
||||||
ImmutableMap.Builder<EDhApiWorldGenerationStep, Integer> builder = ImmutableMap.builder();
|
ImmutableMap.Builder<EDhApiWorldGenerationStep, Integer> builder = ImmutableMap.builder();
|
||||||
builder.put(EDhApiWorldGenerationStep.EMPTY, 1);
|
builder.put(EDhApiWorldGenerationStep.EMPTY, 1);
|
||||||
builder.put(EDhApiWorldGenerationStep.STRUCTURE_START, 0);
|
builder.put(EDhApiWorldGenerationStep.STRUCTURE_START, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.STRUCTURE_REFERENCE, 0);
|
builder.put(EDhApiWorldGenerationStep.STRUCTURE_REFERENCE, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.BIOMES, isTerraFirmaCraftPresent ? 1 : 0);
|
builder.put(EDhApiWorldGenerationStep.BIOMES, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.NOISE, isTerraFirmaCraftPresent ? 1 : 0);
|
builder.put(EDhApiWorldGenerationStep.NOISE, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.SURFACE, 0);
|
builder.put(EDhApiWorldGenerationStep.SURFACE, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.CARVERS, 0);
|
builder.put(EDhApiWorldGenerationStep.CARVERS, 0);
|
||||||
builder.put(EDhApiWorldGenerationStep.LIQUID_CARVERS, 0);
|
builder.put(EDhApiWorldGenerationStep.LIQUID_CARVERS, 0);
|
||||||
@@ -184,6 +178,7 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
public BatchGenerationEnvironment(IDhServerLevel dhServerLevel)
|
public BatchGenerationEnvironment(IDhServerLevel dhServerLevel)
|
||||||
{
|
{
|
||||||
this.dhServerLevel = dhServerLevel;
|
this.dhServerLevel = dhServerLevel;
|
||||||
|
this.updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(this.dhServerLevel.getServerLevelWrapper());
|
||||||
this.globalParams = new GlobalWorldGenParams(dhServerLevel);
|
this.globalParams = new GlobalWorldGenParams(dhServerLevel);
|
||||||
this.internalServerGenerator = new InternalServerGenerator(this.globalParams, this.dhServerLevel);
|
this.internalServerGenerator = new InternalServerGenerator(this.globalParams, this.dhServerLevel);
|
||||||
this.chunkFileReader = new ChunkFileReader(this.globalParams);
|
this.chunkFileReader = new ChunkFileReader(this.globalParams);
|
||||||
@@ -200,11 +195,6 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
LOGGER.info("TerraForge Chunk Generator detected: [" + generator.getClass() + "], Distant Generation will try its best to support it.");
|
LOGGER.info("TerraForge Chunk Generator detected: [" + generator.getClass() + "], Distant Generation will try its best to support it.");
|
||||||
LOGGER.info("If it does crash, turn Distant Generation off or set it to to [" + EDhApiDistantGeneratorMode.PRE_EXISTING_ONLY + "].");
|
LOGGER.info("If it does crash, turn Distant Generation off or set it to to [" + EDhApiDistantGeneratorMode.PRE_EXISTING_ONLY + "].");
|
||||||
}
|
}
|
||||||
else if (generator.getClass().toString().equals("class net.dries007.tfc.world.TFCChunkGenerator"))
|
|
||||||
{
|
|
||||||
LOGGER.info("TerraFirmaCraft Chunk Generator detected: [" + generator.getClass() + "], Distant Generation will try its best to support it.");
|
|
||||||
LOGGER.info("If it does crash, turn Distant Generation off or set it to to [" + EDhApiDistantGeneratorMode.PRE_EXISTING_ONLY + "].");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGGER.warn("Unknown Chunk Generator detected: [" + generator.getClass() + "], Distant Generation May Fail!");
|
LOGGER.warn("Unknown Chunk Generator detected: [" + generator.getClass() + "], Distant Generation May Fail!");
|
||||||
@@ -349,12 +339,12 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
while (existingChunkPosIterator.hasNext())
|
while (existingChunkPosIterator.hasNext())
|
||||||
{
|
{
|
||||||
ChunkPos chunkPos = existingChunkPosIterator.next();
|
ChunkPos chunkPos = existingChunkPosIterator.next();
|
||||||
DhChunkPos dhChunkPos = new DhChunkPos(chunkPos.x, chunkPos.z);
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
|
|
||||||
CompletableFuture<ChunkWrapper> getExistingChunkFuture
|
CompletableFuture<ChunkWrapper> getExistingChunkFuture
|
||||||
// running async allows file IO to run in parallel when C2ME is present
|
// running async allows file IO to run in parallel when C2ME is present
|
||||||
= this.chunkFileReader.createEmptyOrPreExistingChunkWrapperAsync(
|
= this.chunkFileReader.createEmptyOrPreExistingChunkWrapperAsync(
|
||||||
chunkPos.x, chunkPos.z,
|
dhChunkPos.getX(), dhChunkPos.getZ(),
|
||||||
chunkSkyLightingByDhPos, chunkBlockLightingByDhPos, chunkWrappersByDhPos);
|
chunkSkyLightingByDhPos, chunkBlockLightingByDhPos, chunkWrappersByDhPos);
|
||||||
|
|
||||||
readFutureByDhChunkPos.put(dhChunkPos, getExistingChunkFuture);
|
readFutureByDhChunkPos.put(dhChunkPos, getExistingChunkFuture);
|
||||||
@@ -381,7 +371,7 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
while (emptyChunkPosIterator.hasNext())
|
while (emptyChunkPosIterator.hasNext())
|
||||||
{
|
{
|
||||||
ChunkPos chunkPos = emptyChunkPosIterator.next();
|
ChunkPos chunkPos = emptyChunkPosIterator.next();
|
||||||
DhChunkPos dhChunkPos = new DhChunkPos(chunkPos.x, chunkPos.z);
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
|
|
||||||
// create empty chunks outside the generation radius
|
// create empty chunks outside the generation radius
|
||||||
if (!readFutureByDhChunkPos.containsKey(dhChunkPos))
|
if (!readFutureByDhChunkPos.containsKey(dhChunkPos))
|
||||||
@@ -432,7 +422,11 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
relZ + refPosZ + zOffsetFinal));
|
relZ + refPosZ + zOffsetFinal));
|
||||||
|
|
||||||
ChunkAccess centerChunk = regionChunks.stream()
|
ChunkAccess centerChunk = regionChunks.stream()
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
.filter((chunk) -> chunk.getPos().x == centerX && chunk.getPos().z == centerZ)
|
.filter((chunk) -> chunk.getPos().x == centerX && chunk.getPos().z == centerZ)
|
||||||
|
#else
|
||||||
|
.filter((chunk) -> chunk.getPos().x() == centerX && chunk.getPos().z() == centerZ)
|
||||||
|
#endif
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> regionChunks.getFirst());
|
.orElseGet(() -> regionChunks.getFirst());
|
||||||
|
|
||||||
@@ -530,9 +524,9 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
Iterator<ChunkPos> iterator = ChunkPosGenStream.getIterator(genEvent.minPos.getX(), genEvent.minPos.getZ(), genEvent.widthInChunks, 0);
|
Iterator<ChunkPos> iterator = ChunkPosGenStream.getIterator(genEvent.minPos.getX(), genEvent.minPos.getZ(), genEvent.widthInChunks, 0);
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
ChunkPos pos = iterator.next();
|
ChunkPos chunkPos = iterator.next();
|
||||||
DhChunkPos dhPos = new DhChunkPos(pos.x, pos.z);
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
ChunkWrapper wrappedChunk = chunkWrappersByDhPos.get(dhPos);
|
ChunkWrapper wrappedChunk = chunkWrappersByDhPos.get(dhChunkPos);
|
||||||
|
|
||||||
// only pass along chunks that have been generated up to BIOMES
|
// only pass along chunks that have been generated up to BIOMES
|
||||||
// this is to prevent issues with generating existing
|
// this is to prevent issues with generating existing
|
||||||
@@ -546,7 +540,7 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
if (!this.generatedChunkWithoutBiomeWarningLogged)
|
if (!this.generatedChunkWithoutBiomeWarningLogged)
|
||||||
{
|
{
|
||||||
this.generatedChunkWithoutBiomeWarningLogged = true;
|
this.generatedChunkWithoutBiomeWarningLogged = true;
|
||||||
LOGGER.warn("Chunk [" + dhPos + "] wasn't generated up to BIOMES, world gen may appear empty.");
|
LOGGER.warn("Chunk [" + dhChunkPos + "] wasn't generated up to BIOMES, world gen may appear empty.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,10 +586,9 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
|
|
||||||
// usually ignoring the chunk's position is unnecessary,
|
// usually ignoring the chunk's position is unnecessary,
|
||||||
// but this improves performance if a chunk update event does sneak through
|
// but this improves performance if a chunk update event does sneak through
|
||||||
ChunkUpdateQueueManager updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(this.dhServerLevel.getServerLevelWrapper());
|
if (this.updateManager != null)
|
||||||
if (updateManager != null)
|
|
||||||
{
|
{
|
||||||
updateManager.addPosToIgnore(chunkWrapper.getChunkPos());
|
this.updateManager.addPosToIgnore(chunkWrapper.getChunkPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -724,15 +717,9 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ChunkUpdateQueueManager updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(BatchGenerationEnvironment.this.dhServerLevel.getServerLevelWrapper());
|
if (BatchGenerationEnvironment.this.updateManager != null)
|
||||||
if (updateManager != null)
|
|
||||||
{
|
{
|
||||||
updateManager.addPosToIgnore(chunkWrapper.getChunkPos());
|
BatchGenerationEnvironment.this.updateManager.removePosToIgnore(chunkWrapper.getChunkPos());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// shouldn't happen, but just in case
|
|
||||||
LOGGER.warn("Unable to find chunk update manager for server level ["+BatchGenerationEnvironment.this.dhServerLevel+"], chunk updates may fail.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, MS_TO_IGNORE_CHUNK_AFTER_COMPLETION);
|
}, MS_TO_IGNORE_CHUNK_AFTER_COMPLETION);
|
||||||
|
|||||||
+36
-17
@@ -1,6 +1,7 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.worldGeneration;
|
package com.seibel.distanthorizons.common.wrappers.worldGeneration;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.api.DhApi;
|
import com.seibel.distanthorizons.api.DhApi;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.params.GlobalWorldGenParams;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.params.GlobalWorldGenParams;
|
||||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||||
@@ -11,17 +12,18 @@ import com.seibel.distanthorizons.core.config.Config;
|
|||||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||||
import com.seibel.distanthorizons.core.enums.MinecraftTextFormat;
|
import com.seibel.distanthorizons.core.enums.MinecraftTextFormat;
|
||||||
import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
||||||
import com.seibel.distanthorizons.core.level.DhServerLevel;
|
|
||||||
import com.seibel.distanthorizons.core.level.IDhServerLevel;
|
import com.seibel.distanthorizons.core.level.IDhServerLevel;
|
||||||
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.DhChunkPos;
|
|
||||||
import com.seibel.distanthorizons.core.util.ExceptionUtil;
|
import com.seibel.distanthorizons.core.util.ExceptionUtil;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.util.TimerUtil;
|
import com.seibel.distanthorizons.core.util.TimerUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IC2meAccessor;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IC2meAccessor;
|
||||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import net.minecraft.server.level.ChunkHolder;
|
import net.minecraft.server.level.ChunkHolder;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.TicketType;
|
import net.minecraft.server.level.TicketType;
|
||||||
@@ -75,6 +77,8 @@ public class InternalServerGenerator
|
|||||||
|
|
||||||
private final GlobalWorldGenParams params;
|
private final GlobalWorldGenParams params;
|
||||||
private final IDhServerLevel dhServerLevel;
|
private final IDhServerLevel dhServerLevel;
|
||||||
|
@Nullable
|
||||||
|
private final ChunkUpdateQueueManager updateManager;
|
||||||
private final Timer chunkSaveIgnoreTimer = TimerUtil.CreateTimer("ChunkSaveIgnoreTimer");
|
private final Timer chunkSaveIgnoreTimer = TimerUtil.CreateTimer("ChunkSaveIgnoreTimer");
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +91,7 @@ public class InternalServerGenerator
|
|||||||
{
|
{
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.dhServerLevel = dhServerLevel;
|
this.dhServerLevel = dhServerLevel;
|
||||||
|
this.updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(this.dhServerLevel.getServerLevelWrapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -188,12 +193,22 @@ public class InternalServerGenerator
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
ArrayList<CompletableFuture<Void>> releaseFutures = new ArrayList<>();
|
||||||
|
|
||||||
// release all chunks from the server to prevent out of memory issues
|
// release all chunks from the server to prevent out of memory issues
|
||||||
Iterator<ChunkPos> chunkPosIterator = ChunkPosGenStream.getIterator(genEvent.minPos.getX(), genEvent.minPos.getZ(), genEvent.widthInChunks, 0);
|
Iterator<ChunkPos> chunkPosIterator = ChunkPosGenStream.getIterator(genEvent.minPos.getX(), genEvent.minPos.getZ(), genEvent.widthInChunks, 0);
|
||||||
while (chunkPosIterator.hasNext())
|
while (chunkPosIterator.hasNext())
|
||||||
{
|
{
|
||||||
ChunkPos chunkPos = chunkPosIterator.next();
|
ChunkPos chunkPos = chunkPosIterator.next();
|
||||||
this.releaseChunkFromServer(this.params.mcServerLevel, this.params.dhServerLevel, chunkPos);
|
releaseFutures.add(this.releaseChunkFromServerAsync(this.params.mcServerLevel, chunkPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait for all release futures to finish to prevent an issue where DH queues
|
||||||
|
// tickets faster than MC can clear them out
|
||||||
|
for (int i = 0; i < releaseFutures.size(); i++)
|
||||||
|
{
|
||||||
|
CompletableFuture<Void> releaseFuture = releaseFutures.get(i);
|
||||||
|
releaseFuture.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,10 +252,9 @@ public class InternalServerGenerator
|
|||||||
ServerLevel level = this.params.mcServerLevel;
|
ServerLevel level = this.params.mcServerLevel;
|
||||||
|
|
||||||
// ignore chunk update events for this position
|
// ignore chunk update events for this position
|
||||||
ChunkUpdateQueueManager updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(this.params.dhServerLevel.getServerLevelWrapper());
|
if (this.updateManager != null)
|
||||||
if (updateManager != null)
|
|
||||||
{
|
{
|
||||||
updateManager.addPosToIgnore(new DhChunkPos(chunkPos.x, chunkPos.z));
|
this.updateManager.addPosToIgnore(McObjectConverter.Convert(chunkPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MC_VER < MC_1_21_5
|
#if MC_VER < MC_1_21_5
|
||||||
@@ -253,7 +267,10 @@ public class InternalServerGenerator
|
|||||||
// probably not the most optimal to run updates here, but fast enough
|
// probably not the most optimal to run updates here, but fast enough
|
||||||
level.getChunkSource().distanceManager.runAllUpdates(level.getChunkSource().chunkMap);
|
level.getChunkSource().distanceManager.runAllUpdates(level.getChunkSource().chunkMap);
|
||||||
|
|
||||||
ChunkHolder chunkHolder = level.getChunkSource().chunkMap.getUpdatingChunkIfPresent(chunkPos.toLong());
|
ChunkHolder chunkHolder = level.getChunkSource().chunkMap
|
||||||
|
.getUpdatingChunkIfPresent(
|
||||||
|
#if MC_VER <= MC_1_21_11 chunkPos.toLong() #else chunkPos.pack() #endif
|
||||||
|
);
|
||||||
if (chunkHolder == null)
|
if (chunkHolder == null)
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("No chunk chunkHolder for pos ["+chunkPos+"] after ticket has been added.");
|
throw new IllegalStateException("No chunk chunkHolder for pos ["+chunkPos+"] after ticket has been added.");
|
||||||
@@ -277,8 +294,10 @@ public class InternalServerGenerator
|
|||||||
* mitigates out of memory issues in the vanilla chunk system. <br>
|
* mitigates out of memory issues in the vanilla chunk system. <br>
|
||||||
* See: https://github.com/pop4959/Chunky/pull/383
|
* See: https://github.com/pop4959/Chunky/pull/383
|
||||||
*/
|
*/
|
||||||
private void releaseChunkFromServer(ServerLevel level, IDhServerLevel dhLevel, ChunkPos chunkPos)
|
private CompletableFuture<Void> releaseChunkFromServerAsync(ServerLevel level, ChunkPos chunkPos)
|
||||||
{
|
{
|
||||||
|
CompletableFuture<Void> removeTicketFuture = new CompletableFuture<>();
|
||||||
|
|
||||||
level.getChunkSource().chunkMap.mainThreadExecutor.execute(() ->
|
level.getChunkSource().chunkMap.mainThreadExecutor.execute(() ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -304,15 +323,9 @@ public class InternalServerGenerator
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ChunkUpdateQueueManager updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(dhLevel.getServerLevelWrapper());
|
if (InternalServerGenerator.this.updateManager != null)
|
||||||
if (updateManager != null)
|
|
||||||
{
|
{
|
||||||
updateManager.addPosToIgnore(new DhChunkPos(chunkPos.x, chunkPos.z));
|
InternalServerGenerator.this.updateManager.removePosToIgnore(McObjectConverter.Convert(chunkPos));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// shouldn't happen, but just in case
|
|
||||||
LOGGER.warn("Unable to find chunk update manager for server level ["+dhLevel+"], chunk updates may fail.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, MS_TO_IGNORE_CHUNK_AFTER_COMPLETION);
|
}, MS_TO_IGNORE_CHUNK_AFTER_COMPLETION);
|
||||||
@@ -320,9 +333,15 @@ public class InternalServerGenerator
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOGGER.warn("Failed to release chunk back to internal server. Error: ["+e.getMessage()+"]", e);
|
LOGGER.warn("Failed to release chunk ["+chunkPos+"] back to internal server. Error: ["+e.getMessage()+"]", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
removeTicketFuture.complete(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return removeTicketFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -20,12 +20,14 @@
|
|||||||
package com.seibel.distanthorizons.common.wrappers.worldGeneration.chunkFileHandling;
|
package com.seibel.distanthorizons.common.wrappers.worldGeneration.chunkFileHandling;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
|
|
||||||
import com.seibel.distanthorizons.core.config.Config;
|
import com.seibel.distanthorizons.core.config.Config;
|
||||||
import com.seibel.distanthorizons.core.level.IDhServerLevel;
|
import com.seibel.distanthorizons.core.level.IDhServerLevel;
|
||||||
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.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.ChunkLightStorage;
|
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.ChunkLightStorage;
|
||||||
|
|
||||||
@@ -673,7 +675,9 @@ public class ChunkCompoundTagParser
|
|||||||
{
|
{
|
||||||
LOGGED_ERROR_MESSAGE_MAP.computeIfAbsent(message, (newMessage) ->
|
LOGGED_ERROR_MESSAGE_MAP.computeIfAbsent(message, (newMessage) ->
|
||||||
{
|
{
|
||||||
LOGGER.warn("Unable to deserialize blocks for chunk section [" + chunkPos.x + ", " + sectionYIndex + ", " + chunkPos.z + "], error: ["+newMessage+"]. " +
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
|
|
||||||
|
LOGGER.warn("Unable to deserialize blocks for chunk section [" + dhChunkPos.getX() + ", " + sectionYIndex + ", " + dhChunkPos.getZ() + "], error: ["+newMessage+"]. " +
|
||||||
"This can probably be ignored, although if your world looks wrong, optimizing it via the single player menu then deleting your DH database(s) should fix the problem.");
|
"This can probably be ignored, although if your world looks wrong, optimizing it via the single player menu then deleting your DH database(s) should fix the problem.");
|
||||||
|
|
||||||
return newMessage;
|
return newMessage;
|
||||||
@@ -683,7 +687,9 @@ public class ChunkCompoundTagParser
|
|||||||
{
|
{
|
||||||
LOGGED_ERROR_MESSAGE_MAP.computeIfAbsent(message, (newMessage) ->
|
LOGGED_ERROR_MESSAGE_MAP.computeIfAbsent(message, (newMessage) ->
|
||||||
{
|
{
|
||||||
LOGGER.warn("Unable to deserialize biomes for chunk section [" + chunkPos.x + ", " + sectionYIndex + ", " + chunkPos.z + "], error: ["+newMessage+"]. " +
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
|
|
||||||
|
LOGGER.warn("Unable to deserialize biomes for chunk section [" + dhChunkPos.getX() + ", " + sectionYIndex + ", " + dhChunkPos.getZ() + "], error: ["+newMessage+"]. " +
|
||||||
"This can probably be ignored, although if your world looks wrong, optimizing it via the single player menu then deleting your DH database(s) should fix the problem.");
|
"This can probably be ignored, although if your world looks wrong, optimizing it via the single player menu then deleting your DH database(s) should fix the problem.");
|
||||||
|
|
||||||
return newMessage;
|
return newMessage;
|
||||||
|
|||||||
+35
-17
@@ -22,9 +22,12 @@ package com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject;
|
|||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||||
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||||
import net.minecraft.world.level.block.EntityBlock;
|
import net.minecraft.world.level.block.EntityBlock;
|
||||||
import net.minecraft.world.level.block.SpawnerBlock;
|
import net.minecraft.world.level.block.SpawnerBlock;
|
||||||
@@ -89,7 +92,7 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
public final int writeRadius;
|
public final int writeRadius;
|
||||||
public final int size;
|
public final int size;
|
||||||
|
|
||||||
private final ChunkPos firstPos;
|
private final DhChunkPos firstPos;
|
||||||
private final List<ChunkAccess> cache;
|
private final List<ChunkAccess> cache;
|
||||||
private final Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
|
private final Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
|
||||||
|
|
||||||
@@ -149,7 +152,7 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
centerChunk);
|
centerChunk);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this.firstPos = chunkList.get(0).getPos();
|
this.firstPos = McObjectConverter.Convert(chunkList.get(0).getPos());
|
||||||
this.serverLevel = serverLevel;
|
this.serverLevel = serverLevel;
|
||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
this.lightEngine = lightEngine;
|
this.lightEngine = lightEngine;
|
||||||
@@ -165,17 +168,22 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
@Override
|
@Override
|
||||||
public boolean ensureCanWrite(BlockPos blockPos)
|
public boolean ensureCanWrite(BlockPos blockPos)
|
||||||
{
|
{
|
||||||
int i = SectionPos.blockToSectionCoord(blockPos.getX());
|
DhChunkPos chunkPos = McObjectConverter.Convert(this.getCenter());
|
||||||
int j = SectionPos.blockToSectionCoord(blockPos.getZ());
|
|
||||||
ChunkPos chunkPos = this.getCenter();
|
int sectionCoordX = SectionPos.blockToSectionCoord(blockPos.getX());
|
||||||
ChunkAccess center = this.getChunk(chunkPos.x, chunkPos.z);
|
int sectionCoordZ = SectionPos.blockToSectionCoord(blockPos.getZ());
|
||||||
int k = Math.abs(chunkPos.x - i);
|
|
||||||
int l = Math.abs(chunkPos.z - j);
|
// TODO what do these "abs" positions mean?
|
||||||
if (k > this.writeRadius || l > this.writeRadius)
|
int absX = Math.abs(chunkPos.getX() - sectionCoordX);
|
||||||
|
int absZ = Math.abs(chunkPos.getZ() - sectionCoordZ);
|
||||||
|
if (absX > this.writeRadius
|
||||||
|
|| absZ > this.writeRadius)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MC_VER >= MC_1_18_2
|
#if MC_VER >= MC_1_18_2
|
||||||
|
ChunkAccess center = this.getChunk(chunkPos.getX(), chunkPos.getZ());
|
||||||
if (center.isUpgrading())
|
if (center.isUpgrading())
|
||||||
{
|
{
|
||||||
LevelHeightAccessor levelHeightAccessor = center.getHeightAccessorForGeneration();
|
LevelHeightAccessor levelHeightAccessor = center.getHeightAccessorForGeneration();
|
||||||
@@ -196,6 +204,7 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -372,7 +381,15 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
if (chunk == null)
|
if (chunk == null)
|
||||||
{
|
{
|
||||||
// check memory
|
// check memory
|
||||||
chunk = this.chunkMap.get(ChunkPos.asLong(chunkX, chunkZ));
|
|
||||||
|
long chunkPosAsLong;
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
chunkPosAsLong = ChunkPos.asLong(chunkX, chunkZ);
|
||||||
|
#else
|
||||||
|
chunkPosAsLong = ChunkPos.pack(chunkX, chunkZ);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
chunk = this.chunkMap.get(chunkPosAsLong);
|
||||||
if (chunk == null)
|
if (chunk == null)
|
||||||
{
|
{
|
||||||
// chunk isn't in memory, generate a new one
|
// chunk isn't in memory, generate a new one
|
||||||
@@ -381,7 +398,7 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
{
|
{
|
||||||
throw new NullPointerException("The provided generator should not return null!");
|
throw new NullPointerException("The provided generator should not return null!");
|
||||||
}
|
}
|
||||||
this.chunkMap.put(ChunkPos.asLong(chunkX, chunkZ), chunk);
|
this.chunkMap.put(chunkPosAsLong, chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,17 +418,18 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
|||||||
/** Use this instead of super.hasChunk() to bypass C2ME concurrency checks */
|
/** Use this instead of super.hasChunk() to bypass C2ME concurrency checks */
|
||||||
public boolean superHasChunk(int x, int z)
|
public boolean superHasChunk(int x, int z)
|
||||||
{
|
{
|
||||||
int k = x - this.firstPos.x;
|
int xOffset = x - this.firstPos.getX();
|
||||||
int l = z - this.firstPos.z;
|
int zOffset = z - this.firstPos.getZ();
|
||||||
return l >= 0 && l < this.size && k >= 0 && k < this.size;
|
return zOffset >= 0 && zOffset < this.size
|
||||||
|
&& xOffset >= 0 && xOffset < this.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Use this instead of super.getChunk() to bypass C2ME concurrency checks */
|
/** Use this instead of super.getChunk() to bypass C2ME concurrency checks */
|
||||||
private ChunkAccess superGetChunk(int x, int z)
|
private ChunkAccess superGetChunk(int x, int z)
|
||||||
{
|
{
|
||||||
int k = x - this.firstPos.x;
|
int xOffset = x - this.firstPos.getX();
|
||||||
int l = z - this.firstPos.z;
|
int zOffset = z - this.firstPos.getZ();
|
||||||
return this.cache.get(k + l * this.size);
|
return this.cache.get(xOffset + zOffset * this.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -69,8 +69,13 @@ public class RegionFileStorageExternalCache implements AutoCloseable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long chunkPosLong;
|
||||||
|
#if MC_VER <= MC_1_21_11
|
||||||
|
chunkPosLong = ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ());
|
||||||
|
#else
|
||||||
|
chunkPosLong = ChunkPos.pack(chunkPos.getRegionX(), chunkPos.getRegionZ());
|
||||||
|
#endif
|
||||||
|
|
||||||
long chunkPosLong = ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ());
|
|
||||||
RegionFile regionFile = null;
|
RegionFile regionFile = null;
|
||||||
|
|
||||||
// Check vanilla cache
|
// Check vanilla cache
|
||||||
@@ -84,7 +89,7 @@ public class RegionFileStorageExternalCache implements AutoCloseable
|
|||||||
{
|
{
|
||||||
this.getRegionFileLock.lock();
|
this.getRegionFileLock.lock();
|
||||||
|
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_17_1
|
||||||
regionFile = this.storage.getRegionFile(chunkPos);
|
regionFile = this.storage.getRegionFile(chunkPos);
|
||||||
|
|
||||||
// keeping the region cache size low helps prevent concurrency issues
|
// keeping the region cache size low helps prevent concurrency issues
|
||||||
@@ -104,7 +109,7 @@ public class RegionFileStorageExternalCache implements AutoCloseable
|
|||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException e)
|
catch (ArrayIndexOutOfBoundsException e)
|
||||||
{
|
{
|
||||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
#if MC_VER <= MC_1_17_1
|
||||||
// the file just wasn't cached
|
// the file just wasn't cached
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
@@ -179,7 +184,7 @@ public class RegionFileStorageExternalCache implements AutoCloseable
|
|||||||
regionFile = new RegionFile(new RegionStorageInfo("level", null, "level type"), regionFilePath, storageFolderPath, false);
|
regionFile = new RegionFile(new RegionStorageInfo("level", null, "level type"), regionFilePath, storageFolderPath, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this.regionFileCache.add(new RegionFileCache(ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ()), regionFile));
|
this.regionFileCache.add(new RegionFileCache(chunkPosLong, regionFile));
|
||||||
while (this.regionFileCache.size() > MAX_CACHE_SIZE)
|
while (this.regionFileCache.size() > MAX_CACHE_SIZE)
|
||||||
{
|
{
|
||||||
this.regionFileCache.poll().file.close();
|
this.regionFileCache.poll().file.close();
|
||||||
|
|||||||
+5
-2
@@ -28,6 +28,8 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||||
|
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.SectionPos;
|
import net.minecraft.core.SectionPos;
|
||||||
@@ -222,9 +224,10 @@ public class WorldGenStructFeatManager extends #if MC_VER < MC_1_19_2 StructureF
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public List<StructureStart> startsForStructure(ChunkPos sectionPos, Predicate<Structure> predicate)
|
public List<StructureStart> startsForStructure(ChunkPos chunkPos, Predicate<Structure> predicate)
|
||||||
{
|
{
|
||||||
ChunkAccess chunk = _getChunk(sectionPos.x, sectionPos.z, ChunkStatus.STRUCTURE_REFERENCES);
|
DhChunkPos dhChunkPos = McObjectConverter.Convert(chunkPos);
|
||||||
|
ChunkAccess chunk = _getChunk(dhChunkPos.getX(), dhChunkPos.getZ(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||||
if (chunk == null) return List.of();
|
if (chunk == null) return List.of();
|
||||||
|
|
||||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||||
|
|||||||
+5
-1
@@ -113,10 +113,14 @@ public final class GlobalWorldGenParams
|
|||||||
this.worldOptions = worldData.worldGenOptions();
|
this.worldOptions = worldData.worldGenOptions();
|
||||||
this.biomes = registry.registryOrThrow(Registries.BIOME);
|
this.biomes = registry.registryOrThrow(Registries.BIOME);
|
||||||
this.worldSeed = worldOptions.seed();
|
this.worldSeed = worldOptions.seed();
|
||||||
#else
|
#elif MC_VER <= MC_1_21_11
|
||||||
this.worldOptions = worldData.worldGenOptions();
|
this.worldOptions = worldData.worldGenOptions();
|
||||||
this.biomes = this.registry.lookupOrThrow(Registries.BIOME);
|
this.biomes = this.registry.lookupOrThrow(Registries.BIOME);
|
||||||
this.worldSeed = this.worldOptions.seed();
|
this.worldSeed = this.worldOptions.seed();
|
||||||
|
#else
|
||||||
|
this.worldOptions = server.getWorldGenSettings().options();
|
||||||
|
this.biomes = this.registry.lookupOrThrow(Registries.BIOME);
|
||||||
|
this.worldSeed = this.worldOptions.seed();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MC_VER >= MC_1_18_2
|
#if MC_VER >= MC_1_18_2
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user