Compare commits
387 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 077e25d7a8 | |||
| ef84fe97d5 | |||
| fc3653e577 | |||
| d708867c74 | |||
| e6273fa6a4 | |||
| d517279ca2 | |||
| 71284c3e98 | |||
| 85c7dbaf99 | |||
| 7cc21a2b8e | |||
| 2c8d8e2b2e | |||
| d366da4947 | |||
| 02490440ec | |||
| 019ec0e55d | |||
| c8ef38da3c | |||
| b449072a69 | |||
| 35fde21098 | |||
| 10bad0bc84 | |||
| 27492ba093 | |||
| ed6576df4b | |||
| 1c89f9e88a | |||
| 9cdd7fc687 | |||
| 3a5485ea56 | |||
| 955d1df400 | |||
| d39000fa56 | |||
| 231e98efb8 | |||
| 87299de2ab | |||
| 33c9b48bc9 | |||
| 416208c33a | |||
| 7bba8d2862 | |||
| 8b22349d0f | |||
| cd156630a8 | |||
| 769d5739b8 | |||
| 6d29f58ebd | |||
| 2d8027cd28 | |||
| be9547612d | |||
| 67f8ff841d | |||
| 51a7ccc8d0 | |||
| 3fdaa42206 | |||
| 70c783194f | |||
| aec1d2bbe8 | |||
| cabcbef34b | |||
| d952e5400b | |||
| eba908c153 | |||
| 65feda4e04 | |||
| 81e636b1c6 | |||
| 4c4861b2e3 | |||
| 28972421ad | |||
| 3619acbd54 | |||
| c539f1eeef | |||
| 23cf213200 | |||
| a371c6b364 | |||
| d1e58ccf28 | |||
| 0062a28504 | |||
| 9d00a1eb67 | |||
| 7e75640263 | |||
| 32f1cfa634 | |||
| aed5f54710 | |||
| 267fa4acfa | |||
| a4f731da16 | |||
| 8ee9c42848 | |||
| a43335466c | |||
| 1a0b86d056 | |||
| d96cc5c74b | |||
| 54faa2cbdc | |||
| e7e25cb5b7 | |||
| b4afb2f495 | |||
| 2a5e67a461 | |||
| a71dd0b3b8 | |||
| b2d9c2eec6 | |||
| 518262c515 | |||
| 1de5983260 | |||
| 3c5b1eb423 | |||
| 4d195a6378 | |||
| cdbfad060b | |||
| e9eeba944a | |||
| 3c111cd8d6 | |||
| 68c5362024 | |||
| 40ea294663 | |||
| 1b2afcd02c | |||
| 6c5eb09486 | |||
| 221d011b48 | |||
| ad36204dfb | |||
| 70f8599a0e | |||
| 211ec7f3a6 | |||
| 43a75df119 | |||
| 679c6791c7 | |||
| 033616db7a | |||
| 1a09edd8bb | |||
| 0ff7a5cd11 | |||
| 4e0574af35 | |||
| 027dbf35f8 | |||
| a9dc1e232a | |||
| f50cfab3f7 | |||
| 981d9a095d | |||
| d1670673f2 | |||
| 82fa375afc | |||
| 95d0765ccb | |||
| 8f9524a319 | |||
| a680aa97d2 | |||
| 7ca0092501 | |||
| 4d7321941c | |||
| 8d1c5e4b5b | |||
| 1ebcd49601 | |||
| 9ac7753f04 | |||
| 7ca81fe281 | |||
| 1b5762a133 | |||
| e373969b34 | |||
| f16472c415 | |||
| 72169f271f | |||
| b1149bda39 | |||
| 8f838891cb | |||
| e4518cafeb | |||
| 6022161e0c | |||
| dd8b695cdf | |||
| e896be7324 | |||
| 06298418cb | |||
| fdcbbae3b1 | |||
| a719ec5a3e | |||
| 55bf0c04f4 | |||
| 666293f59d | |||
| 4442fda70a | |||
| cf976cef84 | |||
| e2dcbf48af | |||
| 79ba86d8c2 | |||
| 8de6ca33af | |||
| 89faf6e976 | |||
| bc5861ea95 | |||
| cc3a3c451c | |||
| f0956c0cdb | |||
| dcc143c9f8 | |||
| 56603e8076 | |||
| 06922458f1 | |||
| 17b7a6eb89 | |||
| 52b222de50 | |||
| 35d45057ba | |||
| 6a5ba1a607 | |||
| c01c77e11d | |||
| 27a01d4da3 | |||
| 76f3a3cfcb | |||
| 52005d0b19 | |||
| af6f477f15 | |||
| bf2ffd6dfb | |||
| dd6380d49d | |||
| d59fc82cc7 | |||
| 2f62dd2c49 | |||
| 379f8911b5 | |||
| 1a72c30684 | |||
| 6891bdc34e | |||
| c6a7e52a86 | |||
| 951ef5ed72 | |||
| 20f8e59f2b | |||
| 23b35282a9 | |||
| 27c3c0c404 | |||
| df7728707a | |||
| 6bd7f54a8e | |||
| 954175943d | |||
| a1e8af623d | |||
| af625d912a | |||
| 04d61e81ed | |||
| 78fc6be193 | |||
| 969dfa1dd0 | |||
| 19578f2104 | |||
| de60b15d2b | |||
| 7c5ffe3f10 | |||
| 2daf47f202 | |||
| ec8e54d31b | |||
| d538b5c12b | |||
| 4fe24abc51 | |||
| 4644121fe3 | |||
| f75c9ec06a | |||
| e174939cf5 | |||
| b8ecbdd27d | |||
| 100401e0ac | |||
| a5f2ce79e4 | |||
| 4358360362 | |||
| 889fc7d7fe | |||
| 8fec85d4cb | |||
| de744d1f10 | |||
| 4e50099308 | |||
| e17f201e6b | |||
| 14fb775212 | |||
| 9742a2146a | |||
| 270476f4d2 | |||
| b1205c73d5 | |||
| 760019aac6 | |||
| a89df000d0 | |||
| 3278d3518d | |||
| 0f8bf01d30 | |||
| e4132fe469 | |||
| f593df5d1d | |||
| a42153dc14 | |||
| 7dbb17b339 | |||
| 4e226130df | |||
| abf5ec313a | |||
| 2257ceae53 | |||
| e330a7cd3b | |||
| 9316575534 | |||
| 3046127b03 | |||
| 7a4e784701 | |||
| 96a2b406aa | |||
| e2db3cdc5c | |||
| 99fa754e91 | |||
| be28eaf122 | |||
| cd05d5d811 | |||
| f6f7c1702a | |||
| b593293c05 | |||
| 1f1f44766d | |||
| 6ebd768d97 | |||
| bd75c7454c | |||
| 1c2fab1528 | |||
| 92a096a708 | |||
| e331def140 | |||
| 31c1e40ec1 | |||
| 8ced3f838d | |||
| b37bf72eb2 | |||
| c6485f5e92 | |||
| 4d2132cc08 | |||
| cb3dfd6786 | |||
| 0af836f2f5 | |||
| 509184f5ce | |||
| d788ded283 | |||
| 131e257739 | |||
| 9333c006b7 | |||
| 59ca964231 | |||
| 293942b7de | |||
| fce9a94b96 | |||
| a344389500 | |||
| 000d87ccdd | |||
| f241d849b7 | |||
| a315b1190a | |||
| a35a268670 | |||
| dff898e228 | |||
| 9ab67716bc | |||
| cc554991fe | |||
| 7366b543bd | |||
| 480f3d9563 | |||
| 991e4b8b20 | |||
| 2f6551904a | |||
| dc1ee3faaf | |||
| f96196a421 | |||
| 678eeaa3bf | |||
| 87dbda685b | |||
| 954dc49932 | |||
| 0c031588aa | |||
| 6e419b3120 | |||
| de0ddee3fb | |||
| 59fac2fa11 | |||
| ef0d3b3957 | |||
| f34be62af4 | |||
| 151ee93842 | |||
| c89757aa5d | |||
| 2617fcfab1 | |||
| 0528a2d423 | |||
| aa62921986 | |||
| f39ae98a48 | |||
| e10e51ae26 | |||
| 758e941da9 | |||
| 34777b1672 | |||
| a8156d90d8 | |||
| 45527ada14 | |||
| b6b98b1c00 | |||
| d7b98c9762 | |||
| fc9faeb6e5 | |||
| c965fb41b9 | |||
| 379a09b9c9 | |||
| da0b34b2dc | |||
| 6153b68302 | |||
| 3fc60909d2 | |||
| a20ab505ef | |||
| 8f412d5dc7 | |||
| bb7e993d10 | |||
| 8aeceb717c | |||
| 1b2fc0e364 | |||
| 2bf6b59419 | |||
| 5e6080da78 | |||
| a4a23121c8 | |||
| fa6e36cb44 | |||
| 64eb773ab8 | |||
| 841e831ce0 | |||
| 427b54b1eb | |||
| 00e831c8f3 | |||
| a5d5168b07 | |||
| 521dfb83e4 | |||
| d414a27498 | |||
| 7e8ce1c695 | |||
| 302a894cb3 | |||
| 0c213aa860 | |||
| 142deb47cb | |||
| 4390b1c694 | |||
| c26f196318 | |||
| 4cae95a942 | |||
| d07219758f | |||
| 051b2e31b9 | |||
| 6e0ea18ca3 | |||
| 407d633a6c | |||
| a4ae25886a | |||
| ae02066093 | |||
| fd4f628618 | |||
| b389b144c1 | |||
| 95e929220a | |||
| 3d6d2a62f9 | |||
| 60d8d0be50 | |||
| 18f5c6aa95 | |||
| 13f28a9bd8 | |||
| 640c6b8a9c | |||
| 69202b86cd | |||
| 330bab0616 | |||
| c77d0bab6d | |||
| 7ef14602f5 | |||
| 762ef42a48 | |||
| ba07a4188b | |||
| 4a6387b383 | |||
| b7254c7d12 | |||
| 8873503853 | |||
| 430b23bb45 | |||
| 1c785fded8 | |||
| f2bfc50a31 | |||
| 17ffa3eaba | |||
| a6805eeb9a | |||
| b3d7623276 | |||
| df5e61f4bd | |||
| 8cd841220d | |||
| fd5fd05622 | |||
| 6769702d45 | |||
| 2ce16a0594 | |||
| cd2f2c4ae5 | |||
| 0f4e9792d2 | |||
| cf1be5f3ba | |||
| f2c919725a | |||
| 5e5b218e14 | |||
| 0d18b38434 | |||
| 3838f06723 | |||
| d255e08204 | |||
| c2feac4642 | |||
| 93f2605c6d | |||
| c1c80f1000 | |||
| 7555073c14 | |||
| fa607062fa | |||
| 8bfe624f97 | |||
| 32a5880c17 | |||
| d51d403906 | |||
| 1fb42f3c8e | |||
| 87fdfc5048 | |||
| 5f7de8ff5b | |||
| 3e6a2314bd | |||
| deebd9a8cf | |||
| 3e71f31f8e | |||
| f7d4642a44 | |||
| 59a6cae353 | |||
| ef53a299f9 | |||
| c5def9b663 | |||
| 71860612af | |||
| 354a3c6133 | |||
| bc49bfe2ba | |||
| c0e48a29a5 | |||
| 363f865168 | |||
| d6ceeee2a3 | |||
| f6dc7492f9 | |||
| 4b4b1f0ddc | |||
| e5524edc4a | |||
| 75de1e5fd1 | |||
| 9c1c6d3503 | |||
| ee55f066a9 | |||
| e06889a322 | |||
| 7dd26b110b | |||
| de7dbcb622 | |||
| 9678be05a8 | |||
| db8581da57 | |||
| f7423af5f4 | |||
| 518fcfca97 | |||
| ecdada10c0 | |||
| 7ffdf6f514 | |||
| 2b8aea39d7 | |||
| 502d3424b0 | |||
| 33748510fe | |||
| 9f55203d69 | |||
| 241dd14431 | |||
| bf5fded327 | |||
| 7423b9577d | |||
| 54a3c5750e | |||
| 1bf8317398 | |||
| 5a0d7b0d67 | |||
| 64b0e312f3 | |||
| d22aab08cb | |||
| 0368342336 | |||
| 0ccae5ebbc | |||
| e5a8464647 |
+3
-29
@@ -1,31 +1,3 @@
|
||||
# eclipse
|
||||
bin
|
||||
*.launch
|
||||
.settings
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# idea
|
||||
out
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# gradle
|
||||
build
|
||||
.gradle
|
||||
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
|
||||
# Files from Forge MDK
|
||||
logs
|
||||
forge*changelog.txt
|
||||
|
||||
.architectury-transformer/
|
||||
build/
|
||||
*.ipr
|
||||
run/
|
||||
@@ -36,6 +8,7 @@ out/
|
||||
output/
|
||||
bin/
|
||||
libs/
|
||||
.architectury-transformer/
|
||||
|
||||
.classpath
|
||||
.project
|
||||
@@ -45,6 +18,7 @@ classes/
|
||||
.vscode
|
||||
.settings
|
||||
*.launch
|
||||
hs_err_pid*
|
||||
|
||||
**/src/generated/
|
||||
Merged/
|
||||
@@ -53,4 +27,4 @@ Merged/
|
||||
*.bak
|
||||
|
||||
# file genearated via MC version switching using preprocessor
|
||||
build.properties
|
||||
build.properties
|
||||
|
||||
+193
-148
@@ -1,120 +1,39 @@
|
||||
# use Eclipse's JDK
|
||||
image: gradle:eclipse-temurin
|
||||
# The ci should always use an unix/unix-like OS to work
|
||||
|
||||
|
||||
# all stages need to be defined here
|
||||
stages:
|
||||
- build_19_1
|
||||
- build_19
|
||||
- build_18_2
|
||||
- build_18_1
|
||||
- build_17_1
|
||||
- build_16_5
|
||||
# TODO: Make stages depending on what is in versionProperties
|
||||
- build_1_18_2
|
||||
|
||||
variables:
|
||||
# Pull core when building
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
|
||||
|
||||
before_script:
|
||||
- echo $CI_JOB_ID
|
||||
# Writing GE_JOB_ID variable to environment file, will need the value in the next stage.
|
||||
- echo GE_JOB_ID=$CI_JOB_ID >> generate_jars.env
|
||||
|
||||
|
||||
|
||||
# 1.16.5 build
|
||||
build_16_5:
|
||||
stage: build_16_5
|
||||
script:
|
||||
- echo "Building 1.16.5..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
- ./gradlew clean -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
- ./gradlew build -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_16_5-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
- Merged
|
||||
expire_in: 1 day
|
||||
when: always
|
||||
cache:
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
# 1.17.1 build
|
||||
build_17_1:
|
||||
stage: build_17_1
|
||||
script:
|
||||
- echo "Building 1.17.1..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.17.1" --gradle-user-home cache/;
|
||||
- ./gradlew clean -PmcVer="1.17.1" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.17.7" --gradle-user-home cache/;
|
||||
- ./gradlew build -PmcVer="1.17.1" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.17.1" --gradle-user-home cache/;
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_17_1-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
- Merged
|
||||
expire_in: 1 day
|
||||
# even if one build fails, upload the successful jars
|
||||
when: always
|
||||
cache:
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
# 1.18.1 build
|
||||
build_18_1:
|
||||
stage: build_18_1
|
||||
script:
|
||||
- echo "Building 1.18.1..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.18.1" --gradle-user-home cache/; # make sure any previously merged jars are removed before running this job
|
||||
- ./gradlew clean -PmcVer="1.18.1" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.18.1" --gradle-user-home cache/;
|
||||
- ./gradlew build -PmcVer="1.18.1" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.18.1" --gradle-user-home cache/;
|
||||
# build using Java 17
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_18_1-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
# relative to the root directory
|
||||
- Merged
|
||||
expire_in: 1 day
|
||||
when: always
|
||||
cache:
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
# 1.18.2 build
|
||||
build_18_2:
|
||||
stage: build_18_2
|
||||
build_1_18_2:
|
||||
stage: build_1_18_2
|
||||
script:
|
||||
- echo "Building 1.18.2..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
- ./gradlew clean -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
# this both runs the unit tests and assembles the code
|
||||
- ./gradlew build -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_18_2-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
name: "NightlyBuild_1_18_2-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
- Merged
|
||||
- fabric/build/libs/*.jar
|
||||
- forge/build/libs/*.jar
|
||||
- quilt/build/libs/*.jar
|
||||
exclude:
|
||||
# TODO: There is a lot of duplicate stuff here, fix it later
|
||||
- fabric/build/libs/*-all.jar
|
||||
- fabric/build/libs/*-sources.jar
|
||||
- forge/build/libs/*-all.jar
|
||||
- forge/build/libs/*-sources.jar
|
||||
- quilt/build/libs/*-all.jar
|
||||
- quilt/build/libs/*-sources.jar
|
||||
expire_in: 1 day
|
||||
when: always
|
||||
cache:
|
||||
@@ -125,55 +44,181 @@ build_18_2:
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
# 1.19 build
|
||||
build_19:
|
||||
stage: build_19
|
||||
script:
|
||||
- echo "Building 1.19..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.19" --gradle-user-home cache/;
|
||||
- ./gradlew clean -PmcVer="1.19" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.19" --gradle-user-home cache/;
|
||||
- ./gradlew build -PmcVer="1.19" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.19" --gradle-user-home cache/;
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_19-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
- Merged
|
||||
expire_in: 1 day
|
||||
when: always
|
||||
cache:
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
# 1.19.1 build
|
||||
build_19_1:
|
||||
stage: build_19_1
|
||||
script:
|
||||
- echo "Building 1.19.1..."
|
||||
- ./gradlew deleteMerged -PmcVer="1.19.1" --gradle-user-home cache/;
|
||||
- ./gradlew clean -PmcVer="1.19.1" --gradle-user-home cache/;
|
||||
- ./gradlew core:build -PmcVer="1.19.1" --gradle-user-home cache/;
|
||||
- ./gradlew build -PmcVer="1.19.1" --gradle-user-home cache/;
|
||||
- ./gradlew mergeJars -PmcVer="1.19.1" --gradle-user-home cache/;
|
||||
image: eclipse-temurin:17
|
||||
artifacts:
|
||||
name: "Merged_NightlyBuild_1_19-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
paths:
|
||||
- Merged
|
||||
expire_in: 1 day
|
||||
when: always
|
||||
cache:
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ============================== Previos CI for future reference ============================== #
|
||||
## all stages need to be defined here
|
||||
# # Don't build the standalone jar yet because it isn't done yet
|
||||
# # - build_standalone
|
||||
#stages:
|
||||
# - build_19
|
||||
# - build_18_2
|
||||
# - build_18_1
|
||||
# - build_17_1
|
||||
# - build_16_5
|
||||
#
|
||||
#variables:
|
||||
# # Pull core when building
|
||||
# GIT_SUBMODULE_STRATEGY: recursive
|
||||
#
|
||||
#
|
||||
#before_script:
|
||||
# - echo $CI_JOB_ID
|
||||
# # Writing GE_JOB_ID variable to environment file, will need the value in the next stage.
|
||||
# - echo GE_JOB_ID=$CI_JOB_ID >> generate_jars.env
|
||||
#
|
||||
#
|
||||
## The standalone build
|
||||
##build_standalone:
|
||||
## stage: build_standalone
|
||||
## script:
|
||||
## # make sure any previously merged jars are removed before running this job.
|
||||
## # note: if the merged folder doesn't exist "rm -R Merged" will throw an error, which can be ignored
|
||||
## # the "|| true" makes that step always succeed.
|
||||
## - ./gradlew core:build --gradle-user-home cache/;
|
||||
##
|
||||
## # Copy the file with the shortest name to the root DistantHorizons.jar so it can be sent off
|
||||
## - cp $(find core/build/libs/ | awk 'function base(f){sub(".*/", "", f); return f;} {print length(base($0)), $0}'| sort -n | head -2 | grep -P "[0-9][0-9] core/build/libs/*" | #sed -r "s/([0-9][0-9] )//g") DistantHorizons.jar
|
||||
## # build using Java 16
|
||||
## image: eclipse-temurin:16
|
||||
## artifacts:
|
||||
## name: "NightlyBuild_standalone-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
## paths:
|
||||
## # Get the standalone jar
|
||||
## - DistantHorizons.jar
|
||||
## expire_in: 1 day
|
||||
## # even if one build fails, upload the successful jars
|
||||
## when: always
|
||||
## cache:
|
||||
## key: "gradleCache"
|
||||
## policy: pull-push
|
||||
## paths:
|
||||
## - .gradle
|
||||
## - cache/
|
||||
## allow_failure: true
|
||||
#
|
||||
#
|
||||
## 1.16.5 build
|
||||
#build_16_5:
|
||||
# stage: build_16_5
|
||||
# script:
|
||||
# # make sure any previously merged jars are removed before running this job.
|
||||
# # note: if the merged folder doesn't exist "rm -R Merged" will throw an error, which can be ignored
|
||||
# # the "|| true" makes that step always succeed.
|
||||
# - ./gradlew test --gradle-user-home cache/;
|
||||
# - ./gradlew build -PmcVer="1.16.5" --gradle-user-home cache/;
|
||||
# # build using Java 16
|
||||
# image: eclipse-temurin:16
|
||||
# artifacts:
|
||||
# name: "Merged_NightlyBuild_1_16_5-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
# paths:
|
||||
# # relative to the root directory
|
||||
# - Merged
|
||||
# expire_in: 1 day
|
||||
# # even if one build fails, upload the successful jars
|
||||
# when: always
|
||||
# cache:
|
||||
# key: "gradleCache"
|
||||
# policy: pull-push
|
||||
# paths:
|
||||
# - .gradle
|
||||
# - cache/
|
||||
# allow_failure: true
|
||||
#
|
||||
## 1.17.1 build
|
||||
#build_17_1:
|
||||
# stage: build_17_1
|
||||
# script:
|
||||
# - ./gradlew test --gradle-user-home cache/;
|
||||
# - ./gradlew build -PmcVer="1.17.1" --gradle-user-home cache/;
|
||||
# image: eclipse-temurin:16
|
||||
# artifacts:
|
||||
# name: "Merged_NightlyBuild_1_17_1-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
# paths:
|
||||
# - Merged
|
||||
# expire_in: 1 day
|
||||
# when: always
|
||||
# cache:
|
||||
# key: "gradleCache"
|
||||
# policy: pull-push
|
||||
# paths:
|
||||
# - .gradle
|
||||
# - cache/
|
||||
# allow_failure: true
|
||||
#
|
||||
## 1.18.1 build
|
||||
#build_18_1:
|
||||
# stage: build_18_1
|
||||
# script:
|
||||
# - ./gradlew test --gradle-user-home cache/;
|
||||
# - ./gradlew build -PmcVer="1.18.1" --gradle-user-home cache/;
|
||||
# # build using Java 17
|
||||
# image: eclipse-temurin:17
|
||||
# artifacts:
|
||||
# name: "Merged_NightlyBuild_1_18_1-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
# paths:
|
||||
# - Merged
|
||||
# expire_in: 1 day
|
||||
# when: always
|
||||
# cache:
|
||||
# key: "gradleCache"
|
||||
# policy: pull-push
|
||||
# paths:
|
||||
# - .gradle
|
||||
# - cache/
|
||||
# allow_failure: true
|
||||
#
|
||||
## 1.18.2 build
|
||||
#build_18_2:
|
||||
# stage: build_18_2
|
||||
# script:
|
||||
# - ./gradlew test --gradle-user-home cache/;
|
||||
# - ./gradlew build -PmcVer="1.18.2" --gradle-user-home cache/;
|
||||
# image: eclipse-temurin:17
|
||||
# artifacts:
|
||||
# name: "Merged_NightlyBuild_1_18_2-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
# paths:
|
||||
# - Merged
|
||||
# expire_in: 1 day
|
||||
# when: always
|
||||
# cache:
|
||||
# key: "gradleCache"
|
||||
# policy: pull-push
|
||||
# paths:
|
||||
# - .gradle
|
||||
# - cache/
|
||||
# allow_failure: true
|
||||
#
|
||||
## 1.19 build
|
||||
#build_19:
|
||||
# stage: build_19
|
||||
# script:
|
||||
# - ./gradlew test --gradle-user-home cache/;
|
||||
# - ./gradlew build -PmcVer="1.19" --gradle-user-home cache/;
|
||||
# image: eclipse-temurin:17
|
||||
# artifacts:
|
||||
# name: "Merged_NightlyBuild_1_19-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
|
||||
# paths:
|
||||
# - Merged
|
||||
# expire_in: 1 day
|
||||
# when: always
|
||||
# cache:
|
||||
# key: "gradleCache"
|
||||
# policy: pull-push
|
||||
# paths:
|
||||
# - .gradle
|
||||
# - cache/
|
||||
# allow_failure: true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# unused deployment stage
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
## Chcek off each item in this list before submitting:
|
||||
|
||||
<!--
|
||||
To mark a section as complete either put an "x" in between the square brackets, example: "[x]"
|
||||
Or click the checkbox once the issue has been created.
|
||||
-->
|
||||
|
||||
1. [ ] Check the FAQ to see if your issue has already been reported and has a solution:
|
||||
[Problems-and-solutions](https://gitlab.com/jeseibel/minecraft-lod-mod/-/wikis/2-frequently-asked-questions/2-problems-and-solutions/Problems-and-Solutions)
|
||||
|
||||
2. [ ] Make sure you are not using any mods on the incompatible list:
|
||||
[Mod support FAQ](https://gitlab.com/jeseibel/minecraft-lod-mod/-/wikis/2-frequently-asked-questions/4-mod-support/Mod-Support)
|
||||
|
||||
3. [ ] Check the existing issues to verify that your bug hasn't already been submitted:
|
||||
[Issues](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/)
|
||||
|
||||
4. [ ] Upload Minecraft's crash report and/or log. \
|
||||
Minecraft crash reports are located in: `.minecraft/crash-reports` \
|
||||
Minecraft logs are located in: `.minecraft/logs`
|
||||
|
||||
5. [ ] Upload your Distant Horizons Config. \
|
||||
The config is found in: `.minecraft/configs/DistantHorizons.toml`
|
||||
|
||||
6. [ ] Fill out the information below:
|
||||
|
||||
* **minecraft version**:
|
||||
|
||||
* **Distant Horizons version**:
|
||||
|
||||
* **Mod loader**:
|
||||
|
||||
* **Installed mods (list the smallest number of mods that you can use to re-create the bug)**:
|
||||
|
||||
* **Describe the bug**:
|
||||
|
||||
* **Steps to reproduce the bug**:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Before creating an issue, please select the appropriate template from the dropdown above.
|
||||
|
||||
The template will walk you through submitting a bug, feature, or improvement request.
|
||||
@@ -0,0 +1,5 @@
|
||||
- [ ] Check the existing [feature requests](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/?sort=updated_desc&state=opened&label_name%5B%5D=Feature) to verify that your feature hasn't already been suggested.
|
||||
|
||||
1. **Describe the feature**:
|
||||
|
||||
2. **Describe why this feature should be added**:
|
||||
@@ -0,0 +1,3 @@
|
||||
1. Check the existing [improvement requests](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/?sort=updated_desc&state=all&label_name%5B%5D=Improvement) to verify that your improvement hasn't already been suggested.
|
||||
|
||||
2. **Describe the improvement**:
|
||||
+2
-3
@@ -1,4 +1,3 @@
|
||||
[submodule "core"]
|
||||
path = core
|
||||
[submodule "coreSubProjects"]
|
||||
path = coreSubProjects
|
||||
url = https://gitlab.com/jeseibel/distant-horizons-core.git
|
||||
branch = main
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
# 1.18.2 version based stuff
|
||||
|
||||
java_version = 17
|
||||
minecraft_version=1.19.1
|
||||
parchment_version=2022.03.13
|
||||
compatible_minecraft_versions=["1.19.1"]
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.8
|
||||
fabric_api_version=0.58.5+1.19.1
|
||||
# Fabric mod versions
|
||||
modmenu_version=4.0.0
|
||||
starlight_version_fabric=0
|
||||
phosphor_version_fabric=0
|
||||
lithium_version=0
|
||||
sodium_version=3820973
|
||||
iris_version=1.19.x-v1.2.6
|
||||
immersive_portals_version = 0
|
||||
bclib_version=0
|
||||
|
||||
# Fabric mod run
|
||||
# 0 = Don't enable and don't run
|
||||
# 1 = Can be referenced in code but doesn't run
|
||||
# 2 = Can be referenced in code and runs in client
|
||||
enable_starlight=0
|
||||
enable_phosphor=0
|
||||
enable_sodium=1
|
||||
enable_lithium=0
|
||||
enable_iris=0
|
||||
enable_bclib=0
|
||||
|
||||
# Forge loader
|
||||
forge_version=42.0.0
|
||||
# Forge mod versions
|
||||
starlight_version_forge=0
|
||||
terraforged_version=
|
||||
|
||||
# Forge mod run
|
||||
# 0 = Don't enable and don't run
|
||||
# 1 = Can be referenced in code but doesn't run
|
||||
# 2 = Can be referenced in code and runs in client
|
||||
enable_starlight_forge=0
|
||||
enable_terraforged=0
|
||||
@@ -1,143 +1,134 @@
|
||||
# <img src="https://gitlab.com/jeseibel/distant-horizons-core/-/raw/main/_logo%20files/LOD%20logo%20flat%20-%20with%20boarder.png" width="32"> Distant Horizons
|
||||
# <img src="https://gitlab.com/jeseibel/distant-horizons-core/-/raw/main/_Misc%20Files/logo%20files/LOD%20logo%20flat%20-%20with%20boarder.png" width="32"> Distant Horizons
|
||||
|
||||
> A mod that adds a Level of Detail System to Minecraft
|
||||
|
||||
|
||||
# What is Distant Horizons?
|
||||
|
||||
This mod adds a Level Of Detail (LOD) system to Minecraft.\
|
||||
This implementation renders simplified chunks outside the normal render distance\
|
||||
Distant Horizons is a Minecraft mod that adds a Level Of Detail (LOD) system to\
|
||||
render simplified chunks outside the normal render distance\
|
||||
allowing for an increased view distance without harming performance.
|
||||
|
||||
Or in other words: this mod lets you see farther without turning your game into a slide show.\
|
||||
In other words: this mod lets you see farther without turning your game into a slide show.\
|
||||
If you want to see a quick demo, check out a video covering the mod here:
|
||||
|
||||
<a href="https://youtu.be/_04BZ8W2bDM" target="_blank"></a>
|
||||
|
||||
### Versions
|
||||
<br>
|
||||
|
||||
This branch is for these versions of Minecraft
|
||||
- 1.19.1
|
||||
- 1.19
|
||||
- 1.18.2
|
||||
- 1.18.1 & 1.18
|
||||
- 1.17.1 & 1.17
|
||||
- 1.16.5 & 1.16.4
|
||||
## Minecraft and Library Versions
|
||||
|
||||
Architectury version: 3.4-SNAPSHOT\
|
||||
Architectury loom version: 0.12.0-SNAPSHOT\
|
||||
This branch supports the following versions of Minecraft:
|
||||
|
||||
> **NOTE: At the moment only 1.18.2 fabric works/build/runs**
|
||||
|
||||
#### 1.19 (BROKE)
|
||||
Forge: 41.0.19\
|
||||
Fabric: 0.14.7\
|
||||
Fabric API: 0.55.3+1.19\
|
||||
Modmenu: 4.0.0
|
||||
|
||||
#### 1.18.2 (ONLY FABRIC WORKS)
|
||||
Fabric: 0.14.14\
|
||||
Fabric API: 0.67.1+1.18.2\
|
||||
Forge: 40.0.32\
|
||||
Parchment=2022.11.06\
|
||||
Modmenu: 3.2.5
|
||||
|
||||
#### 1.18.1, 1.18 (CEASING DEVELOPMENT SOON)
|
||||
Forge: 39.1.2\
|
||||
Fabric: 0.13.3\
|
||||
Fabric API: 0.42.6+1.18\
|
||||
Modmenu: 3.0.1
|
||||
|
||||
#### 1.17.1, 1.17 (BROKE)
|
||||
Forge: 37.1.1\
|
||||
Fabric: 0.13.2\
|
||||
Fabric API: 0.46.1+1.17\
|
||||
Modmenu: 2.0.14
|
||||
|
||||
#### 1.16.5, 1.16.5 (BROKE)
|
||||
Forge: 36.2.28\
|
||||
Fabric: 0.13.2\
|
||||
Fabric API: 0.42.0+1.16\
|
||||
Modmenu: 1.16.22
|
||||
<br><br>
|
||||
|
||||
### Plugin and Library versions
|
||||
|
||||
Fabric loom: 1.1-snapshot\
|
||||
Forge gradle: 5.1.67\
|
||||
Sponge vanilla gradle: 0.2.1-SNAPSHOT\
|
||||
Sponge mixin gradle: 0.7-SNAPSHOT\
|
||||
Java Compiler plugin: Manifold Preprocessor
|
||||
|
||||
#### 1.19.1 mods
|
||||
Forge version: 42.0.0\
|
||||
Fabric version: 0.14.8\
|
||||
Fabric API version: 0.58.5+1.19.1\
|
||||
Modmenu version: 4.0.0
|
||||
|
||||
#### 1.19 mods
|
||||
Forge version: 41.0.94\
|
||||
Fabric version: 0.14.8\
|
||||
Fabric API version: 0.57.0+1.19\
|
||||
Modmenu version: 4.0.0
|
||||
|
||||
#### 1.18.2 mods
|
||||
Forge version: 40.0.18\
|
||||
Fabric version: 0.13.3\
|
||||
Fabric API version: 0.48.0+1.18.2\
|
||||
Modmenu version: 3.1.0
|
||||
|
||||
#### 1.18.1 mods
|
||||
Forge version: 39.1.2\
|
||||
Fabric version: 0.13.3\
|
||||
Fabric API version: 0.42.6+1.18\
|
||||
Modmenu version: 3.0.1
|
||||
|
||||
#### 1.17.1 mods
|
||||
Forge version: 37.1.1\
|
||||
Fabric version: 0.13.2\
|
||||
Fabric API version: 0.46.1+1.17\
|
||||
Modmenu version: 2.0.14
|
||||
|
||||
#### 1.16.5 mods
|
||||
Forge version: 36.2.28\
|
||||
Fabric vetsion: 0.13.2\
|
||||
Fabric API version: 0.42.0+1.16\
|
||||
Modmenu version: 1.16.22
|
||||
|
||||
|
||||
|
||||
Notes:\
|
||||
This version has been confirmed to work in IDE and Retail Minecraft with ether the Fabric or Forge mod-loader.
|
||||
|
||||
<br>
|
||||
|
||||
## Source Code Installation
|
||||
|
||||
#### Nightlly builds
|
||||
This mod has an autobuild system to automatically build the mod on each commit
|
||||
- 1.19.1: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_19_1
|
||||
- 1.19: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_19
|
||||
- 1.18.2: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_18_2
|
||||
- 1.18.1: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_18_1
|
||||
- 1.17.1: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_17_1
|
||||
- 1.16.5: https://gitlab.com/jeseibel/minecraft-lod-mod/-/jobs/artifacts/1.6.4a_dev/download?job=build_16_5
|
||||
|
||||
See the Fabric Documentation online for more detailed instructions:\
|
||||
https://fabricmc.net/wiki/tutorial:setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* A Java Development Kit (JDK) for Java 17 (recommended) or newer. Visit https://www.oracle.com/java/technologies/downloads/ for installers.
|
||||
* Git or someway to clone git projects. Visit https://git-scm.com/ for installers.
|
||||
* A Java Development Kit (JDK) for Java 17 (recommended) or newer. <br>
|
||||
Visit https://www.oracle.com/java/technologies/downloads/ for installers.
|
||||
* Git or someway to clone git projects. <br>
|
||||
Visit https://git-scm.com/ for installers.
|
||||
* (Not required) Any Java IDE with plugins that support Manifold, for example Intellij IDEA.
|
||||
|
||||
**If using IntelliJ:**
|
||||
0. Install Manifold plugin
|
||||
1. open IDEA and import the build.gradle
|
||||
2. refresh the Gradle project in IDEA if required
|
||||
1. Install the Manifold plugin
|
||||
2. Open IDEA and import the build.gradle
|
||||
3. Refresh the Gradle project in IDEA if required
|
||||
|
||||
**If using Ecplise: (Note that Eclispe currently doesn't support Manifold's preprocessor!)**
|
||||
1. run the command: `./gradlew geneclipseruns`
|
||||
2. run the command: `./gradlew eclipse`
|
||||
**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
|
||||
|
||||
|
||||
|
||||
## Switching Versions
|
||||
This branch support 6 built versions:
|
||||
- 1.19.1
|
||||
- 1.19
|
||||
- 1.18.2
|
||||
- 1.18.1 (which also runs on 1.18)
|
||||
- 1.17.1 (which also runs on 1.17)
|
||||
- 1.16.5 (which also runs 1.16.4)
|
||||
|
||||
To switch between active versions, change `mcVer=1.?` in `gradle.properties` file.
|
||||
To switch between different Minecraft versions, change `mcVer=1.?` in the `gradle.properties` file.
|
||||
|
||||
If running on IDE, to ensure IDE pickup the changed versions, you will need to run a gradle command again to allow gradle to update all the libs. (In IntellJ you will also need to do a gradle sync again if it didn't start it automatically.)
|
||||
>Note: There may be a `java.nio.file.FileSystemException` thrown on running the command after switching versions. To fix it, either restart your IDE (as your IDE is locking up a file) or use tools like LockHunter to unlock the linked file. (Often a lib file under `common\build\lib` or `forge\build\lib` or `fabric\build\lib`). If anyone knows how to solve this issue please comment to this issue: https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/233
|
||||
If running in an IDE, to ensure the IDE noticed the version change, run any gradle command to refresh gradle. (In IntellJ you will also need to do a gradle sync if it didn't happen automatically.)
|
||||
>Note: There may be a `java.nio.file.FileSystemException` thrown when running the command after switching versions. To fix it, either restart your IDE (as your IDE is probably locking a file) or use a tool like LockHunter to unlock the linked file(s). (Generally it is a lib file under `common\build\lib`, `forge\build\lib`, or `fabric\build\lib`). \
|
||||
> If anyone knows how to solve this issue please let us know here: \
|
||||
> https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/233
|
||||
|
||||
<br>
|
||||
|
||||
## Compiling
|
||||
|
||||
**Using GUI**
|
||||
1. Download the zip of the project and extract it
|
||||
2. Download the core from https://gitlab.com/jeseibel/distant-horizons-core and extract into a folder called `core`
|
||||
3. Open a command line in the project folder
|
||||
4. Run the command: `./gradlew assemble`
|
||||
5. Then run command: `./gradlew mergeJars`
|
||||
6. The compiled jar file will be in the folder `Merged`
|
||||
Prerequisites:
|
||||
- JDK 17 or newer
|
||||
|
||||
**If in terminal:**
|
||||
1. `git clone -b 1.6.4a_dev --recurse-submodules https://gitlab.com/jeseibel/minecraft-lod-mod.git`
|
||||
From the File Explorer:
|
||||
1. Download and extract the project zip
|
||||
2. Download the core from https://gitlab.com/jeseibel/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`
|
||||
5. The compiled jar file will be in the folder `Merged`
|
||||
|
||||
From the command line:
|
||||
1. `git clone --recurse-submodules https://gitlab.com/jeseibel/minecraft-lod-mod.git`
|
||||
2. `cd minecraft-lod-mod`
|
||||
3. `./gradlew assemble`
|
||||
4. `./gradlew mergeJars`
|
||||
5. The compiled jar file will be in the folder `Merged`
|
||||
>Note: You can add the arg: `-PmcVer=1.?` to tell gradle to build a selected MC version instead of having to manually modify the `gradle.properties` file.
|
||||
4. The compiled jar file will be in the folder `Merged`
|
||||
|
||||
Run tests with: `./gradlew test`
|
||||
|
||||
>Note: You can add the arg: `-PmcVer=?` to tell gradle to build a selected MC version instead of having to modify the `gradle.properties` file. \
|
||||
> Example: `./gradlew assemble -PmcVer=1.18.2`
|
||||
|
||||
|
||||
<Br>
|
||||
|
||||
## Other commands
|
||||
|
||||
`./gradlew --refresh-dependencies` to refresh local dependencies.
|
||||
|
||||
`./gradlew clean` to reset everything (this does not affect your code) and then start the process again.
|
||||
`./gradlew clean` to delete any compiled code.
|
||||
|
||||
|
||||
## Note to self
|
||||
@@ -147,21 +138,37 @@ The Minecraft source code is NOT added to your workspace in an editable way. Min
|
||||
Source code uses Mojang mappings & [Parchment](https://parchmentmc.org/) mappings.
|
||||
|
||||
To generate the source code run `./gradlew genSources`\
|
||||
If your IDE fails to auto-detect the sources JAR when browsing Minecraft classes manually select the JAR file ending with -sources.jar when prompted by your IDE
|
||||
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)
|
||||
|
||||
In IntelliJ it's at the top where it says choose sources when browsing Minecraft classes
|
||||
<br>
|
||||
|
||||
## Useful commands
|
||||
## Other Useful commands
|
||||
|
||||
Build only Fabric: `./gradlew fabric:assemble` or `./gradlew fabric:build`\
|
||||
Build only Forge: `./gradlew fabric:assemble` or `./gradlew forge:build`\
|
||||
Run the standalone jar: `./gradlew run`\
|
||||
Build the standalone jar: `./gradlew core:build`\
|
||||
Only build Fabric: `./gradlew fabric:assemble` or `./gradlew fabric:build`\
|
||||
Only build Forge: `./gradlew fabric:assemble` or `./gradlew forge:build`\
|
||||
Run the Fabric client (for debugging): `./gradlew fabric:runClient`\
|
||||
Run the Forge client (for debugging): `./gradlew forge:runClient`
|
||||
|
||||
To build all versions: `./buildAll` (all builds will end up in the `Merged` folder)
|
||||
|
||||
<br>
|
||||
|
||||
## Open Source Acknowledgements
|
||||
|
||||
Forgix (To merge multiple mod versions into one jar) [_Used to be_ [_DHJarMerger_](https://github.com/Ran-helo/DHJarMerger)]\
|
||||
https://github.com/PacifistMC/Forgix
|
||||
|
||||
XZ for Java (data compression)\
|
||||
https://tukaani.org/xz/java.html
|
||||
|
||||
DHJarMerger (To merge multiple mod versions into one jar)\
|
||||
https://github.com/Ran-helo/DHJarMerger
|
||||
Json & Toml for Java (config handling)\
|
||||
https://github.com/TheElectronWill/night-config
|
||||
|
||||
SVG Salamander for SVG support\
|
||||
https://github.com/blackears/svgSalamander
|
||||
|
||||
FlatLaf for theming (for development testing, may remove later)\
|
||||
https://www.formdev.com/flatlaf/
|
||||
|
||||
+523
-377
@@ -1,404 +1,550 @@
|
||||
import io.github.ran.jarmerger.JarMergerPlugin
|
||||
|
||||
buildscript {
|
||||
dependencies{
|
||||
classpath files('plugins/DHJarMerger-1.0.jar')
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
|
||||
}
|
||||
|
||||
apply plugin: "java"
|
||||
apply plugin: "architectury-plugin"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: JarMergerPlugin
|
||||
|
||||
archivesBaseName = rootProject.archives_base_name
|
||||
version = rootProject.mod_version
|
||||
group = rootProject.maven_group
|
||||
|
||||
task printConfigurations {
|
||||
doLast {task ->
|
||||
println "Project Name: $name configurations:"
|
||||
configurations.each {
|
||||
println " $it.name"
|
||||
}
|
||||
}
|
||||
id "java"
|
||||
|
||||
// Plugin to handle dependencies
|
||||
id "com.github.johnrengelman.shadow" version '7.1.2' apply false
|
||||
|
||||
// Plugin to create merged jars
|
||||
id "io.github.pacifistmc.forgix" version "1.2.6"
|
||||
|
||||
// Manifold preprocessor
|
||||
id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha"
|
||||
|
||||
// Provides mc libraries to core
|
||||
// id "org.spongepowered.gradle.vanilla" version '0.2.1-SNAPSHOT' apply false
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the list of preprocessors to use.
|
||||
*
|
||||
* @param mcVers array of all MC versions
|
||||
* @param mcIndex array index of the currently active MC version
|
||||
*/
|
||||
def writeBuildGradlePredefine(List<String> mcVers, int mcIndex) {
|
||||
ArrayList<String> redefineList = new ArrayList<String>()
|
||||
for (int i=0; i<mcVers.size(); i++) {
|
||||
String mcStr = mcVers.get(i).replace(".", "_")
|
||||
if (mcIndex<i) {
|
||||
redefineList.add("PRE_MC_"+mcStr)
|
||||
|
||||
for (int i = 0; i < mcVers.size(); i++) {
|
||||
String mcStr = mcVers[i].replace(".", "_")
|
||||
if (mcIndex < i) {
|
||||
redefineList.add("PRE_MC_" + mcStr)
|
||||
}
|
||||
if (mcIndex==i) {
|
||||
redefineList.add("MC_"+mcStr)
|
||||
if (mcIndex == i) {
|
||||
redefineList.add("MC_" + mcStr)
|
||||
}
|
||||
if (mcIndex>=i) {
|
||||
redefineList.add("POST_MC_"+mcStr)
|
||||
if (mcIndex >= i) {
|
||||
redefineList.add("POST_MC_" + mcStr)
|
||||
}
|
||||
}
|
||||
|
||||
// Build the list of preprocessors to use
|
||||
StringBuilder sb = new StringBuilder()
|
||||
for (String s : redefineList) {
|
||||
sb.append(s)
|
||||
|
||||
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n")
|
||||
|
||||
// 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")
|
||||
sb.append("=\n")
|
||||
}
|
||||
|
||||
// Build the MC version preprocessors
|
||||
for (String redefinedVersion : redefineList) {
|
||||
sb.append(redefinedVersion)
|
||||
sb.append("=\n")
|
||||
}
|
||||
new File(projectDir, "build.properties").text = sb.toString()
|
||||
}
|
||||
|
||||
// Sets up the variables for Manifold in the code
|
||||
def loadProperties() {
|
||||
def defaultMcVersion = "1.19.2"
|
||||
def mcVersion = ""
|
||||
def mcVers = mcVersions.split(",")
|
||||
int mcIndex = -1
|
||||
println "Avalible MC versions: ${mcVersions}"
|
||||
if (project.hasProperty("mcVer")) {
|
||||
mcVersion = mcVer
|
||||
mcIndex = Arrays.asList(mcVers).indexOf(mcVer)
|
||||
}
|
||||
if (mcIndex == -1) {
|
||||
println "No mcVer set or the set mcVer is invalid! Defaulting to ${defaultMcVersion}."
|
||||
println "Tip: Use -PmcVer='${defaultMcVersion}' in cmd arg to set mcVer."
|
||||
mcVersion = defaultMcVersion
|
||||
mcIndex = Arrays.asList(mcVers).indexOf(defaultMcVersion)
|
||||
assert mcIndex != -1
|
||||
|
||||
// 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")
|
||||
// Forgix settings (used for merging jars)
|
||||
forgix {
|
||||
group = "com.seibel.lod"
|
||||
mergedJarName = "DistantHorizons-${rootProject.versionStr}.jar"
|
||||
|
||||
forge {
|
||||
jarLocation = "build/libs/DistantHorizons-forge-${rootProject.versionStr}.jar"
|
||||
}
|
||||
|
||||
println "Loading properties file at " + mcVersion + ".properties"
|
||||
def props = new Properties()
|
||||
props.load(new FileInputStream("$rootProject.rootDir/"+"$mcVersion"+".properties"))
|
||||
|
||||
props.each { prop ->
|
||||
rootProject.ext.set(prop.key, prop.value)
|
||||
// println "Added prop [key:" + prop.key + ", value:" + prop.value + "]"
|
||||
}
|
||||
writeBuildGradlePredefine(Arrays.asList(mcVers), mcIndex)
|
||||
|
||||
// Stuff for access wideners
|
||||
def mcVersionToAcsessWidenerVersion = [
|
||||
"1.16.5": "1_16",
|
||||
"1.17.1": "1_17",
|
||||
"1.18.1": "1_18",
|
||||
"1.18.2": "1_18",
|
||||
"1.19.1" : "1_19",
|
||||
"1.19.2" : "1_19"
|
||||
]
|
||||
// Use this as sometimes multiple versions use the same access wideners
|
||||
rootProject.ext.set("acsessWidenerVersion", mcVersionToAcsessWidenerVersion.get(mcVersion))
|
||||
}
|
||||
loadProperties()
|
||||
|
||||
architectury {
|
||||
minecraft = rootProject.minecraft_version
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
// For parchment mappings
|
||||
maven { url "https://maven.parchmentmc.org" }
|
||||
|
||||
// used to download and compile dependencies from git repos
|
||||
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"
|
||||
}
|
||||
fabric {
|
||||
jarLocation = "build/libs/DistantHorizons-fabric-${rootProject.versionStr}.jar"
|
||||
}
|
||||
|
||||
// Required for importing CursedForge mods
|
||||
maven {
|
||||
url "https://www.cursemaven.com"
|
||||
content {
|
||||
includeGroup "curse.maven"
|
||||
}
|
||||
}
|
||||
|
||||
// These 2 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/forge"
|
||||
content {
|
||||
includeGroup "forge-mod"
|
||||
}
|
||||
}
|
||||
removeDuplicate "com.seibel.lod.api"
|
||||
removeDuplicate "com.seibel.lod.core"
|
||||
}
|
||||
|
||||
processResources {
|
||||
def resourceTargets = ["fabric.mod.json", "META-INF/mods.toml"] // Location of where to put
|
||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
||||
def replaceProperties = [
|
||||
version : mod_version,
|
||||
mod_name : mod_name,
|
||||
authors : mod_authors,
|
||||
description : mod_description,
|
||||
homepage : mod_homepage,
|
||||
source : mod_source,
|
||||
issues : mod_issues,
|
||||
minecraft_version : minecraft_version,
|
||||
compatible_minecraft_versions: compatible_minecraft_versions,
|
||||
java_version : java_version
|
||||
]
|
||||
// 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
|
||||
//TODO: Make Forge loader version also be relaced with non hardcoded value instead of "[36,42)"
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copies the correct accesswidener and renames it
|
||||
task copyAccessWidener(type: Copy) {
|
||||
from project(":common").file("src/main/resources/${rootProject.acsessWidenerVersion}.lod.accesswidener")
|
||||
into(file("build/resources/main"))
|
||||
rename "${rootProject.acsessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
}
|
||||
|
||||
task copyCoreResources(type: Copy) {
|
||||
from fileTree(project(":core").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
task copyCommonResources(type: Copy) {
|
||||
from fileTree(project(":common").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
//runClient.enabled = false
|
||||
//runServer.enabled = false
|
||||
|
||||
// this deletes the merged folder so we don't carry over
|
||||
// the previous merges to each new build job in the CI/CD pipeline
|
||||
task deleteMerged(type: Delete) {
|
||||
delete files("./Merged")
|
||||
}
|
||||
|
||||
|
||||
// ===============================CORE Gradle basically================================
|
||||
subprojects { p ->
|
||||
if (p == project(":core")) {
|
||||
// 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: "architectury-plugin"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: "dev.architectury.loom"
|
||||
|
||||
p.archivesBaseName = rootProject.archives_base_name
|
||||
p.version = rootProject.mod_version
|
||||
p.group = rootProject.maven_group
|
||||
// Apply plugins
|
||||
apply plugin: "java"
|
||||
apply plugin: "com.github.johnrengelman.shadow"
|
||||
if (isMinecraftSubProject)
|
||||
apply plugin: "systems.manifold.manifold-gradle-plugin"
|
||||
if (p == project(":core"))
|
||||
apply plugin: "application"
|
||||
// apply plugin: "org.spongepowered.gradle.vanilla" // Provides minecraft libraries
|
||||
|
||||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowMe
|
||||
implementation.extendsFrom shadowMe
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
|
||||
// The following line declares the mojmap mappings & parchment mappings
|
||||
mappings loom.layered() {
|
||||
// Mojmap mappings
|
||||
officialMojangMappings()
|
||||
// Parchment mappings (it adds parameter mappings & javadoc)
|
||||
if (rootProject.minecraft_version != "1.19" && rootProject.minecraft_version != "1.19.1" && rootProject.minecraft_version != "1.19.2")
|
||||
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:${rootProject.parchment_version}@zip")
|
||||
else
|
||||
parchment("org.parchmentmc.data:parchment-1.18.2:${rootProject.parchment_version}@zip") // As 1.19.x or higher doesnt have parchment mappings yet, we use 1.18.2 mapping
|
||||
}
|
||||
|
||||
//Manifold
|
||||
annotationProcessor "systems.manifold:manifold-preprocessor:${rootProject.manifold_version}"
|
||||
|
||||
// Toml
|
||||
implementation("com.electronwill.night-config:toml:${rootProject.toml_version}")
|
||||
|
||||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
|
||||
// Do NOT use other classes from fabric loader unless working with fabric
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
}
|
||||
|
||||
// Allows the jar to run standalone
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Title': rootProject.archives_base_name,
|
||||
'Implementation-Version': rootProject.mod_version,
|
||||
'Main-Class': 'com.seibel.lod.core.JarMain'
|
||||
// When changing the main of the jar change this line
|
||||
}
|
||||
}
|
||||
|
||||
task printConfigurations {
|
||||
doLast {task ->
|
||||
println "Project Name: $p.name configurations:"
|
||||
configurations.each {
|
||||
println " $it.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
// For parchment mappings
|
||||
maven { url "https://maven.parchmentmc.org" }
|
||||
|
||||
// used to download and compile dependencies from git repos
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
// These 2 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/forge"
|
||||
content {
|
||||
includeGroup "forge-mod"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
def resourceTargets = ["fabric.mod.json", "META-INF/mods.toml"] // Location of where to put
|
||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
||||
def replaceProperties = [
|
||||
version : mod_version,
|
||||
mod_name : mod_name,
|
||||
authors : mod_authors,
|
||||
description : mod_description,
|
||||
homepage : mod_homepage,
|
||||
source : mod_source,
|
||||
issues : mod_issues,
|
||||
minecraft_version : minecraft_version,
|
||||
compatible_minecraft_versions: compatible_minecraft_versions,
|
||||
java_version : java_version
|
||||
]
|
||||
// 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
|
||||
//TODO: Make Forge loader version also be relaced with non hardcoded value instead of "[36,42)"
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copies the correct accesswidener and renames it
|
||||
task copyAccessWidener(type: Copy) {
|
||||
from project(":common").file("src/main/resources/${rootProject.acsessWidenerVersion}.lod.accesswidener")
|
||||
into(file(p.file("build/resources/main")))
|
||||
rename "${rootProject.acsessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
}
|
||||
|
||||
task copyCoreResources(type: Copy) {
|
||||
from fileTree(project(":core").file("src/main/resources"))
|
||||
into p.file("build/resources/main")
|
||||
}
|
||||
|
||||
task copyCommonResources(type: Copy) {
|
||||
from fileTree(project(":common").file("src/main/resources"))
|
||||
into p.file("build/resources/main")
|
||||
}
|
||||
|
||||
p.tasks.withType(JavaCompile) {
|
||||
// Add Manifold Preprocessor
|
||||
// def excapedMCVersion = rootProject.minecraft_version.replace(".", "_")
|
||||
// options.compilerArgs += ['-Xplugin:Manifold', "-AMC_VERSION_${excapedMCVersion}"]
|
||||
//
|
||||
//options.compilerArgs += ['-deprecation']
|
||||
//options.compilerArgs += ['-verbose']
|
||||
//options.compilerArgs += ['-Xlint:unchecked']
|
||||
//options.compilerArgs += ['-Xdiags:verbose']
|
||||
//options.compilerArgs += ['-Xprint']
|
||||
//options.compilerArgs += ['-XprintProcessorInfo']
|
||||
//options.compilerArgs += ['-XprintRounds']
|
||||
|
||||
// println options.compilerArgs
|
||||
|
||||
// Set the java version
|
||||
options.release = 8; // Core should use Java 8 no matter what
|
||||
// TODO: make everything use java 8
|
||||
// options.release = 8 // Use Java 8 for everything so back porting is easier
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
p.runClient.enabled = false
|
||||
p.runServer.enabled = false
|
||||
// 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)
|
||||
|
||||
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
|
||||
developmentForge.extendsFrom common
|
||||
|
||||
if (findProject(":fabricLike") && p != project(":fabricLike")) {
|
||||
// Shadow fabricLike
|
||||
fabricLike
|
||||
shadowFabricLike
|
||||
compileClasspath.extendsFrom fabricLike
|
||||
runtimeClasspath.extendsFrom fabricLike
|
||||
developmentForge.extendsFrom fabricLike
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Let the application plugin know where the main class is
|
||||
// (This will point to a non-existent class in all sub-projects except "Core")
|
||||
if (p == project(":core")) {
|
||||
application {
|
||||
mainClass.set("com.seibel.lod.core.jar.JarMain")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//=====================//
|
||||
// shared dependencies //
|
||||
//=====================//
|
||||
|
||||
|
||||
// Manifold
|
||||
if (isMinecraftSubProject)
|
||||
annotationProcessor("systems.manifold:manifold-preprocessor:${rootProject.manifold_version}")
|
||||
|
||||
// Log4j
|
||||
// TODO: Change to shadowMe later to work in the standalone jar
|
||||
implementation("org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}")
|
||||
implementation("org.apache.logging.log4j:log4j-core:${rootProject.log4j_version}")
|
||||
|
||||
// JOML
|
||||
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")
|
||||
|
||||
// Compression
|
||||
shadowMe("org.tukaani:xz:1.9")
|
||||
|
||||
// NightConfig (includes Toml & Json)
|
||||
shadowMe("com.electronwill.night-config:toml:${rootProject.nightconfig_version}")
|
||||
shadowMe("com.electronwill.night-config:json:${rootProject.nightconfig_version}")
|
||||
|
||||
// Theming
|
||||
shadowMe("com.formdev:flatlaf:${rootProject.flatlaf_version}")
|
||||
|
||||
// SVG
|
||||
shadowMe("com.formdev:svgSalamander:${rootProject.svgSalamander_version}")
|
||||
shadowMe("com.formdev:flatlaf-extras:${rootProject.flatlaf_version}")
|
||||
|
||||
|
||||
// Remember, for lwjgl dependancies that arent included in Minecraft, you need to also need to add it to the ShadowJar thing
|
||||
shadowMe("org.lwjgl:lwjgl-jawt:3.2.2") {
|
||||
exclude group: "org.lwjgl", module: "lwjgl" // This module is imported by Minecraft so exclude it
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==========================//
|
||||
// conditional dependencies //
|
||||
//==========================//
|
||||
|
||||
|
||||
// Add core
|
||||
if (isMinecraftSubProject) {
|
||||
shadowMe(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")) {
|
||||
shadowMe(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(path: ":common")) { transitive false }
|
||||
shadowCommon(project(path: ":common")) { transitive false }
|
||||
|
||||
// FabricLike
|
||||
if (findProject(":fabricLike") && p != project(":fabricLike")) {
|
||||
fabricLike(project(path: ":fabricLike")) { transitive false }
|
||||
shadowFabricLike(project(path: ":fabricLike")) { transitive false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadowMe]
|
||||
if (isMinecraftSubProject && p != project(":common")) {
|
||||
configurations.push(project.configurations.shadowCommon) // Shadow the common subproject
|
||||
relocate "com.seibel.lod.common", "loaderCommon.${p.name}.com.seibel.lod.common" // Move the loader files to a different location
|
||||
|
||||
if (findProject(":fabricLike") && p != project(":fabricLike")) {
|
||||
configurations.push(project.configurations.shadowFabricLike) // Shadow the fabricLike subproject
|
||||
relocate "com.seibel.lod.fabriclike", "loaderCommon.${p.name}.com.seibel.lod.fabriclike" // Move the loader files to a different location
|
||||
}
|
||||
}
|
||||
def librariesLocation = "distanthorizons.libraries"
|
||||
|
||||
// LWJGL
|
||||
// Only ever shadow the dependencies we use otherwise some stuff would break when running on an external client
|
||||
relocate "org.lwjgl.system.jawt", "${librariesLocation}.lwjgl.system.jawt"
|
||||
|
||||
// Compression
|
||||
relocate "org.tukaani", "${librariesLocation}.tukaani"
|
||||
|
||||
// NightConfig (includes Toml & Json)
|
||||
relocate "com.electronwill.nightconfig", "${librariesLocation}.electronwill.nightconfig"
|
||||
|
||||
// Theming
|
||||
relocate 'com.formdev.flatlaf', 'distanthorizons.libraries.formdev.flatlaf'
|
||||
|
||||
// SVG
|
||||
relocate "com.kitfox.svg", "${librariesLocation}.kitfox.svg"
|
||||
|
||||
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
|
||||
processResources {
|
||||
def resourceTargets = [ // Location of where to inject the properties
|
||||
// Properties for each of the loaders
|
||||
"fabric.mod.json",
|
||||
"quilt.mod.json",
|
||||
"META-INF/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"] which make more sense
|
||||
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(", ")
|
||||
|
||||
// TODOI: Find something we can use so we can basically re-map only when the jar is shadowed and relocated
|
||||
// println p.tasks.findByName('shadowJar')
|
||||
|
||||
|
||||
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(", ")+"}"
|
||||
]
|
||||
// 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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Adds the standalone jar's entrypoint
|
||||
jar {
|
||||
from "LICENSE.txt"
|
||||
manifest {
|
||||
attributes 'Implementation-Title': rootProject.mod_name,
|
||||
'Implementation-Version': rootProject.mod_version,
|
||||
'Main-Class': 'com.seibel.lod.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Run mergeJars when running build
|
||||
// TODO: Fix later
|
||||
// if (isMinecraftSubProject) {
|
||||
// build.finalizedBy(mergeJars)
|
||||
// assemble.finalizedBy(mergeJars)
|
||||
// }
|
||||
}
|
||||
|
||||
allprojects { p ->
|
||||
// Does the same as "p == project(":common") || p == project(":fabric") || p == project(":quilt") || p == project(":forge")"
|
||||
// Useful later on so we dont have duplicated code
|
||||
def isMinecraftSubProject = p != project(":core") && p != project(":api")
|
||||
|
||||
|
||||
apply plugin: "java"
|
||||
apply plugin: "maven-publish"
|
||||
|
||||
archivesBaseName = rootProject.mod_name
|
||||
version = project.name + "-" + rootProject.versionStr
|
||||
group = rootProject.maven_group
|
||||
|
||||
|
||||
repositories {
|
||||
// The central repo
|
||||
mavenCentral()
|
||||
|
||||
// Used for Google's Collect library
|
||||
maven { url "https://repo.enonic.com/public/" }
|
||||
|
||||
// For parchment mappings
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
// Required for ModMenu
|
||||
maven { url "https://maven.terraformersmc.com/" }
|
||||
|
||||
// Required for Mixins & VanillaGradle
|
||||
maven { url "https://repo.spongepowered.org/maven/" }
|
||||
|
||||
// Required for Canvas (mod)
|
||||
maven { url "https://maven.vram.io/" }
|
||||
|
||||
// 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 dependancies are in Vanilla Minecraft, but we need to depend on it as we arent importing Minecraft in the core
|
||||
// Imports most of lwjgl's libraries (well, only the ones that we need)
|
||||
implementation platform("org.lwjgl:lwjgl-bom:${rootProject.lwjgl_version}") // TODO: Use Minecraft's version for lwjgl_version (which changes each version) instead of a hard defined version for all versions
|
||||
|
||||
implementation "org.lwjgl:lwjgl"
|
||||
implementation "org.lwjgl:lwjgl-assimp"
|
||||
implementation "org.lwjgl:lwjgl-glfw"
|
||||
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")
|
||||
implementation("it.unimi.dsi:fastutil:8.5.11")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task copyCommonLoaderResources(type: Copy) {
|
||||
from project(":common").file("src/main/resources/${accessWidenerVersion}.lod.accesswidener")
|
||||
into(file(p.file("build/resources/main")))
|
||||
rename "${accessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
|
||||
// Move the fabricLike mixin to its different places for each subproject
|
||||
if (findProject(":fabricLike")) {
|
||||
from project(":fabricLike").file("src/main/resources/DistantHorizons.fabricLike.mixins.json")
|
||||
into(file(p.file("build/resources/main")))
|
||||
rename "DistantHorizons.fabricLike.mixins.json", "DistantHorizons." + p.name + ".fabricLike.mixins.json"
|
||||
}
|
||||
}
|
||||
|
||||
task copyCoreResources(type: Copy) {
|
||||
from fileTree(project(":core").file("src/main/resources"))
|
||||
into p.file("build/resources/main")
|
||||
}
|
||||
|
||||
// TODO: This method doesnt seem to actually remove it from the jar, probably called at incorrect spots
|
||||
task deleteDuplicatedCommonLoaderResources(type: Delete) {
|
||||
// Delete the duplicated fabricLike.mixins.json
|
||||
delete p.file("build/resources/main/DistantHorizons.fabricLike.mixins.json")
|
||||
|
||||
// Delete all the duplicated accesswideners
|
||||
delete fileTree(p.file("build/resources/main")) {
|
||||
include "*.lod.accesswidener"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
if (isMinecraftSubProject) {
|
||||
options.release = rootProject.java_version as Integer
|
||||
options.compilerArgs += ["-Xplugin:Manifold"]
|
||||
} else {
|
||||
options.release = 8; // Core & Api should use Java 8 no matter what
|
||||
//options.release = rootProject.java_version as Integer // But if you want to test some stuff, then this can be enabled
|
||||
}
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Delete the merged folder when running clean
|
||||
task cleanMergedJars() {
|
||||
def mergedFolder = file("Merged")
|
||||
if (mergedFolder.exists()) {
|
||||
delete(mergedFolder)
|
||||
}
|
||||
}
|
||||
// add cleanMergedJars to the end of the "clean" task
|
||||
tasks["clean"].finalizedBy(cleanMergedJars)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Loop trough everything in the version properties folder
|
||||
for d in versionProperties/*; do
|
||||
# Get the name of the version that is going to be compiled
|
||||
version=$(echo "$d" | sed "s/versionProperties\///" | sed "s/.properties//")
|
||||
|
||||
# Clean out the folders and build it
|
||||
# (We could use "./" to run gradlew, but as it is a shell script im going to be running it with the "sh" command)
|
||||
echo "Cleaning workspace to build $version"
|
||||
sh gradlew clean -PmcVer=$version --no-daemon | true
|
||||
echo "Building $version"
|
||||
sh gradlew build -PmcVer=$version --no-daemon | true
|
||||
# The "| true" at the end of those 2 are just to make sure the script continues even if a build fails
|
||||
done
|
||||
@@ -0,0 +1,25 @@
|
||||
@echo off
|
||||
|
||||
echo Windows build all script needs to be rewritten
|
||||
echo I dont use Windows so I cant really make this
|
||||
echo So if someone does use Windows and knows how to script stuff then can you please port the "buildall" script I made for Unix
|
||||
|
||||
|
||||
|
||||
|
||||
@REM Old BAT script if you need some help with this task
|
||||
|
||||
@REM SETLOCAL
|
||||
@REM CALL :buildVersion "1.19"
|
||||
@REM CALL :buildVersion "1.18.2"
|
||||
@REM CALL :buildVersion "1.18.1"
|
||||
@REM CALL :buildVersion "1.17.1"
|
||||
@REM CALL :buildVersion "1.16.5"
|
||||
@REM EXIT /B %ERRORLEVEL%
|
||||
@REM
|
||||
@REM :buildVersion
|
||||
@REM @echo on
|
||||
@REM call ./gradlew.bat clean -PmcVer="%~1" --no-daemon
|
||||
@REM call ./gradlew.bat build -PmcVer="%~1" --no-daemon
|
||||
@REM @echo off
|
||||
@REM EXIT /B 0
|
||||
@@ -0,0 +1,78 @@
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to make participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all project spaces, and it also applies when
|
||||
an individual is representing the project or its community in public spaces.
|
||||
Examples of representing a project or community include using an official
|
||||
project e-mail address, posting via an official social media account, or acting
|
||||
as an appointed representative at an online or offline event. Representation of
|
||||
a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the team lead James Seibel through Discord at `@BackSun#4157`. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
|
||||
+10
-196
@@ -1,71 +1,26 @@
|
||||
apply plugin: "java"
|
||||
apply plugin: "architectury-plugin"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: "dev.architectury.loom"
|
||||
|
||||
archivesBaseName = rootProject.archives_base_name
|
||||
version = rootProject.mod_version
|
||||
group = rootProject.maven_group
|
||||
|
||||
architectury {
|
||||
common(rootProject.enabled_platforms.split(","))
|
||||
plugins {
|
||||
id "org.spongepowered.gradle.vanilla" version "0.2.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
accessWidenerPath.set(project(":common").file("src/main/resources/${acsessWidenerVersion}.lod.accesswidener"))
|
||||
minecraft {
|
||||
accessWideners(project(":common").file("src/main/resources/${accessWidenerVersion}.lod.accesswidener"))
|
||||
version(rootProject.minecraft_version)
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowMe
|
||||
implementation.extendsFrom shadowMe
|
||||
}
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
|
||||
// The following line declares the mojmap mappings & parchment mappings
|
||||
mappings loom.layered() {
|
||||
// Mojmap mappings
|
||||
officialMojangMappings()
|
||||
// Parchment mappings (it adds parameter mappings & javadoc)
|
||||
if (rootProject.minecraft_version != "1.19" && rootProject.minecraft_version != "1.19.1" && rootProject.minecraft_version != "1.19.2")
|
||||
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:${rootProject.parchment_version}@zip")
|
||||
else
|
||||
parchment("org.parchmentmc.data:parchment-1.18.2:${rootProject.parchment_version}@zip") // As 1.19 dosnt have parchment mappings yet, we use 1.18.2 mapping
|
||||
}
|
||||
|
||||
//Manifold
|
||||
annotationProcessor "systems.manifold:manifold-preprocessor:${rootProject.manifold_version}"
|
||||
|
||||
// Toml
|
||||
implementation("com.electronwill.night-config:toml:${rootProject.toml_version}")
|
||||
|
||||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
|
||||
// Do NOT use other classes from fabric loader unless working with fabric
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"\
|
||||
// Do NOT use other classes from fabric loader
|
||||
// modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
|
||||
common(project(":core")) { transitive false }
|
||||
shadowMe(project(":core")) { transitive false }
|
||||
// So mixins can be written in common
|
||||
compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5'
|
||||
}
|
||||
|
||||
// Allows the jar to run standalone
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Title': rootProject.archives_base_name,
|
||||
'Implementation-Version': rootProject.mod_version,
|
||||
'Main-Class': 'com.seibel.lod.core.JarMain' // When changing the main of the jar change this line
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenCommon(MavenPublication) {
|
||||
artifactId = rootProject.archives_base_name
|
||||
artifactId = rootProject.mod_readable_name
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
@@ -75,144 +30,3 @@ publishing {
|
||||
// Add repositories to publish to here.
|
||||
}
|
||||
}
|
||||
|
||||
task printConfigurations {
|
||||
doLast {task ->
|
||||
println "Project Name: $name configurations:"
|
||||
configurations.each {
|
||||
println " $it.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
// For parchment mappings
|
||||
maven { url "https://maven.parchmentmc.org" }
|
||||
|
||||
// used to download and compile dependencies from git repos
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
// These 2 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/forge"
|
||||
content {
|
||||
includeGroup "forge-mod"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copies the correct accesswidener and renames it
|
||||
task copyAccessWidener(type: Copy) {
|
||||
from project(":common").file("src/main/resources/${rootProject.acsessWidenerVersion}.lod.accesswidener")
|
||||
into(file("build/resources/main"))
|
||||
rename "${rootProject.acsessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
}
|
||||
|
||||
task copyCoreResources(type: Copy) {
|
||||
from fileTree(project(":core").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
task copyCommonResources(type: Copy) {
|
||||
from fileTree(project(":common").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
processResources {
|
||||
def resourceTargets = ["fabric.mod.json", "META-INF/mods.toml"] // Location of where to put
|
||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
||||
def replaceProperties = [
|
||||
version : mod_version,
|
||||
mod_name : mod_name,
|
||||
authors : mod_authors,
|
||||
description : mod_description,
|
||||
homepage : mod_homepage,
|
||||
source : mod_source,
|
||||
issues : mod_issues,
|
||||
minecraft_version : minecraft_version,
|
||||
compatible_minecraft_versions: compatible_minecraft_versions,
|
||||
java_version : java_version
|
||||
]
|
||||
// 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
|
||||
//TODO: Make Forge loader version also be relaced with non hardcoded value instead of "[36,42)"
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println "Copying [common/src/main/resources/${acsessWidenerVersion}.lod.accesswidner] to [fabric/build/resources/main]."
|
||||
copy {
|
||||
from project(":common").file("src/main/resources/${acsessWidenerVersion}.lod.accesswidener")
|
||||
into project(":fabric").file("build/resources/main")
|
||||
rename "${acsessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
// Add Manifold Preprocessor
|
||||
// def excapedMCVersion = rootProject.minecraft_version.replace(".", "_")
|
||||
// options.compilerArgs += ['-Xplugin:Manifold', "-AMC_VERSION_${excapedMCVersion}"]
|
||||
//
|
||||
//options.compilerArgs += ['-deprecation']
|
||||
//options.compilerArgs += ['-verbose']
|
||||
//options.compilerArgs += ['-Xlint:unchecked']
|
||||
//options.compilerArgs += ['-Xdiags:verbose']
|
||||
//options.compilerArgs += ['-Xprint']
|
||||
//options.compilerArgs += ['-XprintProcessorInfo']
|
||||
//options.compilerArgs += ['-XprintRounds']
|
||||
|
||||
// println options.compilerArgs
|
||||
|
||||
// Set the java version
|
||||
options.compilerArgs += ['-Xplugin:Manifold']
|
||||
options.release = rootProject.java_version as Integer
|
||||
// TODO: make everything use java 8
|
||||
// options.release = 8 // Use Java 8 for everything so back porting is easier
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
}
|
||||
|
||||
runClient.enabled = false
|
||||
runServer.enabled = false
|
||||
@@ -1,482 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common;
|
||||
|
||||
import com.seibel.lod.core.config.*;
|
||||
import com.seibel.lod.core.enums.config.*;
|
||||
import com.seibel.lod.core.enums.rendering.*;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IAdvanced.*;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IGraphics.*;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IGraphics.IFogQuality.IAdvancedFog;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IGraphics.IFogQuality.IAdvancedFog.IHeightFog;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IMultiplayer;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IWorldGenerator;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IAdvanced;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IAdvanced.IDebugging.*;
|
||||
|
||||
|
||||
/**
|
||||
* This handles any configuration the user has access to.
|
||||
* @author coolGi
|
||||
* @version 12-12-2021
|
||||
*/
|
||||
|
||||
public class Config
|
||||
//public class Config extends TinyConfig
|
||||
{
|
||||
// CONFIG STRUCTURE
|
||||
// -> Client
|
||||
// |
|
||||
// |-> Graphics
|
||||
// | |-> Quality
|
||||
// | |-> FogQuality
|
||||
// | |-> AdvancedGraphics
|
||||
// |
|
||||
// |-> World Generation
|
||||
// |
|
||||
// |-> Advanced
|
||||
// |-> Threads
|
||||
// |-> Buffers
|
||||
// |-> Debugging
|
||||
|
||||
// Since the original config system uses forge stuff, that means we have to rewrite the whole config system
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Client client;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _optionsButton = ILodConfigWrapperSingleton.IClient.OPTIONS_BUTTON_DESC;
|
||||
// I know this option should be in Client
|
||||
// This is a hacky method to not show the button in the options screen but show it in the mod menu
|
||||
// Tough it is in client in the wrapper singleton
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean optionsButton = true;
|
||||
|
||||
public static class Client
|
||||
{
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Graphics graphics;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static WorldGenerator worldGenerator;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Multiplayer multiplayer;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Advanced advanced;
|
||||
|
||||
|
||||
public static class Graphics
|
||||
{
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Quality quality;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static FogQuality fogQuality;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static AdvancedGraphics advancedGraphics;
|
||||
|
||||
|
||||
public static class Quality
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _drawResolution = IQuality.DRAW_RESOLUTION_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static HorizontalResolution drawResolution = IQuality.DRAW_RESOLUTION_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _lodChunkRenderDistance = IQuality.LOD_CHUNK_RENDER_DISTANCE_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 32, maxValue = 2048)
|
||||
public static int lodChunkRenderDistance = IQuality.LOD_CHUNK_RENDER_DISTANCE_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _verticalQuality = IQuality.VERTICAL_QUALITY_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static VerticalQuality verticalQuality = IQuality.VERTICAL_QUALITY_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _horizontalScale = IQuality.HORIZONTAL_SCALE_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 2, maxValue = 64)
|
||||
public static int horizontalScale = IQuality.HORIZONTAL_SCALE_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _horizontalQuality = IQuality.HORIZONTAL_SCALE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static HorizontalQuality horizontalQuality = IQuality.HORIZONTAL_QUALITY_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _dropoffQuality = IQuality.DROPOFF_QUALITY_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static DropoffQuality dropoffQuality = IQuality.DROPOFF_QUALITY_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _lodBiomeBlending = IQuality.LOD_BIOME_BLENDING_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0, maxValue = 7)
|
||||
public static int lodBiomeBlending = IQuality.LOD_BIOME_BLENDING_MIN_DEFAULT_MAX.defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public static class FogQuality
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _fogDistance = IFogQuality.FOG_DISTANCE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static FogDistance fogDistance = IFogQuality.FOG_DISTANCE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _fogDrawMode = IFogQuality.FOG_DRAW_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static FogDrawMode fogDrawMode = IFogQuality.FOG_DRAW_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _fogColorMode = IFogQuality.FOG_COLOR_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static FogColorMode fogColorMode = IFogQuality.FOG_COLOR_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _disableVanillaFog = IFogQuality.DISABLE_VANILLA_FOG_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean disableVanillaFog = IFogQuality.DISABLE_VANILLA_FOG_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static AdvancedFog advancedFog;
|
||||
|
||||
public static class AdvancedFog {
|
||||
static final double SQRT2 = 1.4142135623730951;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogStart = IAdvancedFog.FAR_FOG_START_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = SQRT2)
|
||||
public static double farFogStart = IAdvancedFog.FAR_FOG_START_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogEnd = IAdvancedFog.FAR_FOG_END_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = SQRT2)
|
||||
public static double farFogEnd = IAdvancedFog.FAR_FOG_END_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogMin = IAdvancedFog.FAR_FOG_MIN_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = -5.0, maxValue = SQRT2)
|
||||
public static double farFogMin = IAdvancedFog.FAR_FOG_MIN_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogMax = IAdvancedFog.FAR_FOG_MAX_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = 5.0)
|
||||
public static double farFogMax = IAdvancedFog.FAR_FOG_MAX_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogType = IAdvancedFog.FAR_FOG_TYPE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static FogSetting.FogType farFogType = IAdvancedFog.FAR_FOG_TYPE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _farFogDensity = IAdvancedFog.FAR_FOG_DENSITY_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.01, maxValue = 50.0)
|
||||
public static double farFogDensity = IAdvancedFog.FAR_FOG_DENSITY_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static HeightFog heightFog;
|
||||
|
||||
public static class HeightFog {
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogMixMode = IHeightFog.HEIGHT_FOG_MIX_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static HeightFogMixMode heightFogMixMode = IHeightFog.HEIGHT_FOG_MIX_MODE_DEFAULT;
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogMode = IHeightFog.HEIGHT_FOG_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static HeightFogMode heightFogMode = IHeightFog.HEIGHT_FOG_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogHeight = IHeightFog.HEIGHT_FOG_HEIGHT_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = -4096.0, maxValue = 4096.0)
|
||||
public static double heightFogHeight = IHeightFog.HEIGHT_FOG_HEIGHT_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogStart = IHeightFog.HEIGHT_FOG_START_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = SQRT2)
|
||||
public static double heightFogStart = IHeightFog.HEIGHT_FOG_START_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogEnd = IHeightFog.HEIGHT_FOG_END_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = SQRT2)
|
||||
public static double heightFogEnd = IHeightFog.HEIGHT_FOG_END_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogMin = IHeightFog.HEIGHT_FOG_MIN_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = -5.0, maxValue = SQRT2)
|
||||
public static double heightFogMin = IHeightFog.HEIGHT_FOG_MIN_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogMax = IHeightFog.HEIGHT_FOG_MAX_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = 5.0)
|
||||
public static double heightFogMax = IHeightFog.HEIGHT_FOG_MAX_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogType = IHeightFog.HEIGHT_FOG_TYPE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static FogSetting.FogType heightFogType = IHeightFog.HEIGHT_FOG_TYPE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _heightFogDensity = IHeightFog.HEIGHT_FOG_DENSITY_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.01, maxValue = 50.0)
|
||||
public static double heightFogDensity = IHeightFog.HEIGHT_FOG_DENSITY_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AdvancedGraphics
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _disableDirectionalCulling = IAdvancedGraphics.DISABLE_DIRECTIONAL_CULLING_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean disableDirectionalCulling = IAdvancedGraphics.DISABLE_DIRECTIONAL_CULLING_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _vanillaOverdraw = IAdvancedGraphics.VANILLA_OVERDRAW_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static VanillaOverdraw vanillaOverdraw = IAdvancedGraphics.VANILLA_OVERDRAW_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _overdrawOffset = IAdvancedGraphics.OVERDRAW_OFFSET_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = -16, maxValue = 16)
|
||||
public static int overdrawOffset = IAdvancedGraphics.OVERDRAW_OFFSET_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _useExtendedNearClipPlane = IAdvancedGraphics.USE_EXTENDED_NEAR_CLIP_PLANE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean useExtendedNearClipPlane = IAdvancedGraphics.USE_EXTENDED_NEAR_CLIP_PLANE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _brightnessMultiplier = IAdvancedGraphics.BRIGHTNESS_MULTIPLIER_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static double brightnessMultiplier = IAdvancedGraphics.BRIGHTNESS_MULTIPLIER_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _saturationMultiplier = IAdvancedGraphics.SATURATION_MULTIPLIER_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static double saturationMultiplier = IAdvancedGraphics.SATURATION_MULTIPLIER_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _enableCaveCulling = IAdvancedGraphics.ENABLE_CAVE_CULLING_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean enableCaveCulling = IAdvancedGraphics.ENABLE_CAVE_CULLING_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _caveCullingHeight = IAdvancedGraphics.CAVE_CULLING_HEIGHT_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = -4096, maxValue = 4096)
|
||||
public static int caveCullingHeight = IAdvancedGraphics.CAVE_CULLING_HEIGHT_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _earthCurveRatio = IAdvancedGraphics.EARTH_CURVE_RATIO_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0, maxValue = 5000)
|
||||
public static int earthCurveRatio = IAdvancedGraphics.EARTH_CURVE_RATIO_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
/*
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _backsideCullingRange = IAdvancedGraphics.VANILLA_CULLING_RANGE_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0, maxValue = 512)
|
||||
public static int backsideCullingRange = IAdvancedGraphics.VANILLA_CULLING_RANGE_MIN_DEFAULT_MAX.defaultValue;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class WorldGenerator
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _enableDistantGeneration = IWorldGenerator.ENABLE_DISTANT_GENERATION_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean enableDistantGeneration = IWorldGenerator.ENABLE_DISTANT_GENERATION_DEFAULT;
|
||||
|
||||
// @ConfigAnnotations.FileComment
|
||||
// public static String _distanceGenerationMode = IWorldGenerator.getDistanceGenerationModeDesc();
|
||||
@ConfigAnnotations.Entry
|
||||
public static DistanceGenerationMode distanceGenerationMode = IWorldGenerator.DISTANCE_GENERATION_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _lightGenerationMode = IWorldGenerator.LIGHT_GENERATION_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LightGenerationMode lightGenerationMode = IWorldGenerator.LIGHT_GENERATION_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _generationPriority = IWorldGenerator.GENERATION_PRIORITY_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static GenerationPriority generationPriority = IWorldGenerator.GENERATION_PRIORITY_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _blocksToAvoid = IWorldGenerator.BLOCKS_TO_AVOID_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static BlocksToAvoid blocksToAvoid = IWorldGenerator.BLOCKS_TO_AVOID_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
public static class Multiplayer
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _serverFolderNameMode = IMultiplayer.SERVER_FOLDER_NAME_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static ServerFolderNameMode serverFolderNameMode = IMultiplayer.SERVER_FOLDER_NAME_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _multiDimensionRequiredSimilarity = IMultiplayer.MULTI_DIMENSION_REQUIRED_SIMILARITY_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.0, maxValue = 1.0)
|
||||
public static double multiDimensionRequiredSimilarity = IMultiplayer.MULTI_DIMENSION_REQUIRED_SIMILARITY_MIN_DEFAULT_MAX.defaultValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class Advanced
|
||||
{
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Threading threading;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Debugging debugging;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static Buffers buffers;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _lodOnlyMode = IAdvanced.LOD_ONLY_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean lodOnlyMode = IAdvanced.LOD_ONLY_MODE_DEFAULT;
|
||||
|
||||
|
||||
public static class Threading
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _numberOfWorldGenerationThreads = IThreading.NUMBER_OF_WORLD_GENERATION_THREADS_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0.1, maxValue = 50.0)
|
||||
public static double numberOfWorldGenerationThreads = IThreading.NUMBER_OF_WORLD_GENERATION_THREADS_DEFAULT.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _numberOfBufferBuilderThreads = IThreading.NUMBER_OF_BUFFER_BUILDER_THREADS_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 1, maxValue = 50)
|
||||
public static int numberOfBufferBuilderThreads = IThreading.NUMBER_OF_BUFFER_BUILDER_THREADS_MIN_DEFAULT_MAX.defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public static class Debugging
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _rendererType = IDebugging.RENDERER_TYPE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static RendererType rendererType = IDebugging.RENDERER_TYPE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _debugMode = IDebugging.DEBUG_MODE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static DebugMode debugMode = IDebugging.DEBUG_MODE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _enableDebugKeybindings = IDebugging.DEBUG_KEYBINDINGS_ENABLED_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static boolean enableDebugKeybindings = IDebugging.DEBUG_KEYBINDINGS_ENABLED_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.ScreenEntry
|
||||
public static DebugSwitch debugSwitch;
|
||||
|
||||
public static class DebugSwitch {
|
||||
/* The logging switches available:
|
||||
* WorldGenEvent
|
||||
* WorldGenPerformance
|
||||
* WorldGenLoadEvent
|
||||
* LodBuilderEvent
|
||||
* RendererBufferEvent
|
||||
* RendererGLEvent
|
||||
* FileReadWriteEvent
|
||||
* FileSubDimEvent
|
||||
* NetworkEvent //NOT IMPL YET
|
||||
*/
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logWorldGenEvent = IDebugSwitch.LOG_WORLDGEN_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logWorldGenEvent = IDebugSwitch.LOG_WORLDGEN_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logWorldGenPerformance = IDebugSwitch.LOG_WORLDGEN_PERFORMANCE_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logWorldGenPerformance = IDebugSwitch.LOG_WORLDGEN_PERFORMANCE_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logWorldGenLoadEvent = IDebugSwitch.LOG_WORLDGEN_LOAD_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logWorldGenLoadEvent = IDebugSwitch.LOG_WORLDGEN_LOAD_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logLodBuilderEvent = IDebugSwitch.LOG_LODBUILDER_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logLodBuilderEvent = IDebugSwitch.LOG_LODBUILDER_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logRendererBufferEvent = IDebugSwitch.LOG_RENDERER_BUFFER_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logRendererBufferEvent = IDebugSwitch.LOG_RENDERER_BUFFER_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logRendererGLEvent = IDebugSwitch.LOG_RENDERER_GL_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logRendererGLEvent = IDebugSwitch.LOG_RENDERER_GL_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logFileReadWriteEvent = IDebugSwitch.LOG_FILE_READWRITE_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logFileReadWriteEvent = IDebugSwitch.LOG_FILE_READWRITE_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logFileSubDimEvent = IDebugSwitch.LOG_FILE_SUB_DIM_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logFileSubDimEvent = IDebugSwitch.LOG_FILE_SUB_DIM_EVENT_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _logNetworkEvent = IDebugSwitch.LOG_NETWORK_EVENT_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static LoggerMode logNetworkEvent = IDebugSwitch.LOG_NETWORK_EVENT_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Buffers
|
||||
{
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _gpuUploadMethod = IBuffers.GPU_UPLOAD_METHOD_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static GpuUploadMethod gpuUploadMethod = IBuffers.GPU_UPLOAD_METHOD_DEFAULT;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _gpuUploadPerMegabyteInMilliseconds = IBuffers.GPU_UPLOAD_PER_MEGABYTE_IN_MILLISECONDS_DESC;
|
||||
@ConfigAnnotations.Entry(minValue = 0, maxValue = 50)
|
||||
public static int gpuUploadPerMegabyteInMilliseconds = IBuffers.GPU_UPLOAD_PER_MEGABYTE_IN_MILLISECONDS_DEFAULT.defaultValue;
|
||||
|
||||
@ConfigAnnotations.FileComment
|
||||
public static String _rebuildTimes = IBuffers.REBUILD_TIMES_DESC;
|
||||
@ConfigAnnotations.Entry
|
||||
public static BufferRebuildTimes rebuildTimes = IBuffers.REBUILD_TIMES_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,30 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common;
|
||||
|
||||
import com.seibel.lod.common.forge.LodForgeMethodCaller;
|
||||
import com.seibel.lod.common.networking.NetworkInterface;
|
||||
import com.seibel.lod.common.wrappers.DependencySetup;
|
||||
import com.seibel.lod.common.wrappers.config.ConfigGui;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.api.internal.SharedApi;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.config.ConfigBase;
|
||||
|
||||
/**
|
||||
* This is the common main class
|
||||
@@ -30,21 +32,23 @@ import com.seibel.lod.common.wrappers.config.ConfigGui;
|
||||
*/
|
||||
public class LodCommonMain {
|
||||
public static boolean forge = false;
|
||||
public static boolean serverSided;
|
||||
public static LodForgeMethodCaller forgeMethodCaller;
|
||||
|
||||
public static void startup(LodForgeMethodCaller caller, boolean serverSided) {
|
||||
LodCommonMain.serverSided = serverSided;
|
||||
public static void startup(LodForgeMethodCaller caller) {
|
||||
if (caller != null) {
|
||||
LodCommonMain.forge = true;
|
||||
forgeMethodCaller = caller;
|
||||
}
|
||||
|
||||
DependencySetup.createInitialBindings();
|
||||
DependencySetup.createSharedBindings();
|
||||
SharedApi.init();
|
||||
// if (!serverSided) {
|
||||
// new NetworkReceiver().register_Client();
|
||||
// } else {
|
||||
// new NetworkReceiver().register_Server();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public static void initConfig() {
|
||||
ConfigGui.init(Config.class);
|
||||
ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class,1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.networking;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
/**
|
||||
* This is packet handler for our mod
|
||||
@@ -32,18 +29,15 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
*
|
||||
* @author Ran
|
||||
*/
|
||||
|
||||
// TODO: Server sided stuff here
|
||||
public class NetworkHandler {
|
||||
// If you need the response sender then tell me
|
||||
// I'll add extra code to get the response sender
|
||||
public static void receivePacketClient(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf) {
|
||||
// TODO: Server sided stuff here
|
||||
// You can make client execute something by using client.execute(Runnable)
|
||||
// In the fabric docs it says that client.execute is ran on the render thread?
|
||||
public static void receivePacketClient(Minecraft client, FriendlyByteBuf buf, Player player) {
|
||||
// This just exists here for testing purposes, it'll be removed in the future
|
||||
System.out.println("Received int " + buf.readInt());
|
||||
}
|
||||
|
||||
// If you need the response sender then tell me
|
||||
// I'll add extra code to get the response sender
|
||||
public static void receivePacketServer(MinecraftServer server, ServerPlayer client, ServerGamePacketListenerImpl handler, FriendlyByteBuf buf) {
|
||||
// TODO: Server sided stuff here
|
||||
public static void receivePacketServer(FriendlyByteBuf buf, Player player) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.networking;
|
||||
|
||||
/**
|
||||
* @author Ran
|
||||
*/
|
||||
public interface NetworkInterface {
|
||||
void register_Client();
|
||||
void register_Server();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.networking;
|
||||
|
||||
/*
|
||||
#if MC_1_16_5
|
||||
import me.shedaniel.architectury.networking.NetworkManager;
|
||||
#else
|
||||
import dev.architectury.networking.NetworkManager;
|
||||
#endif
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Ran
|
||||
*/
|
||||
// Comment: What does the 'server' side mean? Dedicated server? Or does it include the internal server?
|
||||
// (I removed the hookup that calls the register method, since I'm not sure what it is doing yet)
|
||||
public class NetworkReceiver {
|
||||
/*
|
||||
public void register_Client() {
|
||||
NetworkManager.registerReceiver(NetworkManager.serverToClient(), Networking.RESOURCE_LOCATION, new ClientReceiver());
|
||||
}
|
||||
|
||||
public void register_Server() {
|
||||
NetworkManager.registerReceiver(NetworkManager.clientToServer(), Networking.RESOURCE_LOCATION, new ServerReceiver());
|
||||
}
|
||||
|
||||
static class ServerReceiver implements NetworkManager.NetworkReceiver {
|
||||
@Override
|
||||
public void receive(FriendlyByteBuf buf, NetworkManager.PacketContext context) {
|
||||
com.seibel.lod.common.networking.NetworkHandler.receivePacketServer(buf, context.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
static class ClientReceiver implements NetworkManager.NetworkReceiver {
|
||||
@Override
|
||||
public void receive(FriendlyByteBuf buf, NetworkManager.PacketContext context) {
|
||||
com.seibel.lod.common.networking.NetworkHandler.receivePacketClient(Minecraft.getInstance(), buf, context.getPlayer());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,25 +1,30 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.networking;
|
||||
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
//#if MC_1_16_5
|
||||
//import me.shedaniel.architectury.networking.NetworkManager;
|
||||
//#else
|
||||
//import dev.architectury.networking.NetworkManager;
|
||||
//#endif
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
@@ -36,7 +41,7 @@ import java.util.Objects;
|
||||
* @author Ran
|
||||
*/
|
||||
public class Networking {
|
||||
public static final ResourceLocation resourceLocation_meow = new ResourceLocation("lod", "meow");
|
||||
public static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation("lod", "data");
|
||||
|
||||
public static FriendlyByteBuf createNew() {
|
||||
// TODO: Probably replace the Unpooled.buffer()
|
||||
@@ -45,11 +50,6 @@ public class Networking {
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* All code below is from the fabric api and might have been modified to work with Distant Horizons
|
||||
* Which is licensed under the Apache License 2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sends a packet to a player.
|
||||
*
|
||||
@@ -57,11 +57,7 @@ public class Networking {
|
||||
* @param buf the payload of the packet.
|
||||
*/
|
||||
public static void send(ServerPlayer player, FriendlyByteBuf buf) {
|
||||
Objects.requireNonNull(player, "Server player entity cannot be null");
|
||||
Objects.requireNonNull(resourceLocation_meow, "Channel name cannot be null");
|
||||
Objects.requireNonNull(buf, "Packet byte buf cannot be null");
|
||||
|
||||
player.connection.send(createS2CPacket(resourceLocation_meow, buf));
|
||||
// NetworkManager.sendToPlayer(player, RESOURCE_LOCATION, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,49 +67,7 @@ public class Networking {
|
||||
* @throws IllegalStateException if the client is not connected to a server
|
||||
*/
|
||||
public static void send(FriendlyByteBuf buf) throws IllegalStateException {
|
||||
// You cant send without a client player, so this is fine
|
||||
if (Minecraft.getInstance().getConnection() != null) {
|
||||
Minecraft.getInstance().getConnection().send(createC2SPacket(resourceLocation_meow, buf));
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Cannot send packets when not in game!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet which may be sent to the connected client.
|
||||
*
|
||||
* @param channelName the channel name
|
||||
* @param buf the packet byte buf which represents the payload of the packet
|
||||
* @return a new packet
|
||||
*/
|
||||
public static Packet<?> createS2CPacket(ResourceLocation channelName, FriendlyByteBuf buf) {
|
||||
Objects.requireNonNull(channelName, "Channel cannot be null");
|
||||
Objects.requireNonNull(buf, "Buf cannot be null");
|
||||
|
||||
return createPlayS2CPacket(channelName, buf);
|
||||
}
|
||||
|
||||
public static Packet<?> createPlayS2CPacket(ResourceLocation channel, FriendlyByteBuf buf) {
|
||||
return new ClientboundCustomPayloadPacket(channel, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a packet which may be sent to a the connected server.
|
||||
*
|
||||
* @param channelName the channel name
|
||||
* @param buf the packet byte buf which represents the payload of the packet
|
||||
* @return a new packet
|
||||
*/
|
||||
public static Packet<?> createC2SPacket(ResourceLocation channelName, FriendlyByteBuf buf) {
|
||||
Objects.requireNonNull(channelName, "Channel name cannot be null");
|
||||
Objects.requireNonNull(buf, "Buf cannot be null");
|
||||
|
||||
return createPlayC2SPacket(channelName, buf);
|
||||
}
|
||||
|
||||
public static Packet<?> createPlayC2SPacket(ResourceLocation channelName, FriendlyByteBuf buf) {
|
||||
return new ServerboundCustomPayloadPacket(channelName, buf);
|
||||
// NetworkManager.sendToServer(RESOURCE_LOCATION, buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,37 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers;
|
||||
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import com.seibel.lod.common.wrappers.gui.LangWrapper;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILangWrapper;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.handlers.IReflectionHandler;
|
||||
import com.seibel.lod.core.handlers.ReflectionHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.IReflectionHandler;
|
||||
import com.seibel.lod.core.ReflectionHandler;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IVersionConstants;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
|
||||
/**
|
||||
* Binds all necessary dependencies, so we
|
||||
@@ -41,17 +44,24 @@ import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
* @version 12-1-2021
|
||||
*/
|
||||
public class DependencySetup {
|
||||
public static void createInitialBindings()
|
||||
public static void createSharedBindings()
|
||||
{
|
||||
SingletonHandler.bind(IVersionConstants.class, VersionConstants.INSTANCE);
|
||||
if (!LodCommonMain.serverSided)
|
||||
{
|
||||
SingletonHandler.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE);
|
||||
SingletonHandler.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE);
|
||||
SingletonHandler.bind(IReflectionHandler.class, ReflectionHandler.createSingleton(MinecraftClientWrapper.INSTANCE.getOptions().getClass().getDeclaredFields(), MinecraftClientWrapper.INSTANCE.getOptions()));
|
||||
}
|
||||
|
||||
SingletonHandler.bind(IWrapperFactory.class, WrapperFactory.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(ILangWrapper.class, LangWrapper.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IVersionConstants.class, VersionConstants.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IWrapperFactory.class, WrapperFactory.INSTANCE);
|
||||
DependencySetupDoneCheck.isDone = true;
|
||||
}
|
||||
|
||||
//@Environment(EnvType.SERVER)
|
||||
public static void createServerBindings() {
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftDedicatedServerWrapper.INSTANCE);
|
||||
}
|
||||
|
||||
//@Environment(EnvType.CLIENT)
|
||||
public static void createClientBindings() {
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftClientWrapper.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,34 +1,37 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.core.enums.LodDirection;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.enums.ELodDirection;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.util.math.Mat4f;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
/**
|
||||
* This class converts to and from Minecraft objects (Ex: Matrix4f)
|
||||
@@ -51,32 +54,79 @@ public class McObjectConverter
|
||||
|
||||
|
||||
static final Direction[] directions;
|
||||
static final LodDirection[] lodDirections;
|
||||
static final ELodDirection[] lodDirections;
|
||||
static {
|
||||
LodDirection[] lodDirs = LodDirection.values();
|
||||
ELodDirection[] lodDirs = ELodDirection.values();
|
||||
directions = new Direction[lodDirs.length];
|
||||
lodDirections = new LodDirection[lodDirs.length];
|
||||
for (LodDirection lodDir : lodDirs) {
|
||||
Direction dir = Enum.valueOf(Direction.class, lodDir.name());
|
||||
if (dir == null) {
|
||||
throw new IllegalArgumentException("Invalid direction on init mapping: " + lodDir);
|
||||
}
|
||||
directions[lodDir.ordinal()] = dir;
|
||||
lodDirections[dir.ordinal()] = lodDir;
|
||||
}
|
||||
lodDirections = new ELodDirection[lodDirs.length];
|
||||
for (ELodDirection lodDir : lodDirs)
|
||||
{
|
||||
Direction dir;
|
||||
switch (lodDir.name().toUpperCase())
|
||||
{
|
||||
case "DOWN":
|
||||
dir = Direction.DOWN;
|
||||
break;
|
||||
case "UP":
|
||||
dir = Direction.UP;
|
||||
break;
|
||||
case "NORTH":
|
||||
dir = Direction.NORTH;
|
||||
break;
|
||||
case "SOUTH":
|
||||
dir = Direction.SOUTH;
|
||||
break;
|
||||
case "WEST":
|
||||
dir = Direction.WEST;
|
||||
break;
|
||||
case "EAST":
|
||||
dir = Direction.EAST;
|
||||
break;
|
||||
default:
|
||||
dir = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dir == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid direction on init mapping: " + lodDir);
|
||||
}
|
||||
directions[lodDir.ordinal()] = dir;
|
||||
lodDirections[dir.ordinal()] = lodDir;
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockPos Convert(AbstractBlockPosWrapper wrappedPos) {
|
||||
return new BlockPos(wrappedPos.getX(),wrappedPos.getY(), wrappedPos.getZ());
|
||||
|
||||
public static BlockPos Convert(DhBlockPos wrappedPos) {
|
||||
return new BlockPos(wrappedPos.x, wrappedPos.y, wrappedPos.z);
|
||||
}
|
||||
|
||||
|
||||
public static Direction Convert(LodDirection lodDirection)
|
||||
public static ChunkPos Convert(DhChunkPos wrappedPos) {
|
||||
return new ChunkPos(wrappedPos.x, wrappedPos.z);
|
||||
}
|
||||
|
||||
public static Direction Convert(ELodDirection lodDirection)
|
||||
{
|
||||
return directions[lodDirection.ordinal()];
|
||||
}
|
||||
public static LodDirection Convert(Direction direction)
|
||||
public static ELodDirection Convert(Direction direction)
|
||||
{
|
||||
return lodDirections[direction.ordinal()];
|
||||
}
|
||||
public static void DebugCheckAllPackers() {
|
||||
BiConsumer<Integer, Integer> func = (x, z) -> DhChunkPos._DebugCheckPacker(x,z,ChunkPos.asLong(x,z));
|
||||
func.accept(0,0);
|
||||
func.accept(12345,134);
|
||||
func.accept(-12345,-134);
|
||||
func.accept(-30000000/16,30000000/16);
|
||||
func.accept(30000000/16,-30000000/16);
|
||||
func.accept(30000000/16,30000000/16);
|
||||
func.accept(-30000000/16,-30000000/16);
|
||||
Consumer<BlockPos> func2 = (p) -> DhBlockPos._DebugCheckPacker(p.getX(),p.getY(),p.getZ(),p.asLong());
|
||||
func2.accept(new BlockPos(0,0,0));
|
||||
func2.accept(new BlockPos(12345,134,123));
|
||||
func2.accept(new BlockPos(-12345,-134,-80));
|
||||
func2.accept(new BlockPos(-30000000, 2047, 30000000));
|
||||
func2.accept(new BlockPos(30000000, -2048, -30000000));
|
||||
func2.accept(new BlockPos(30000000, 2047, 30000000));
|
||||
func2.accept(new BlockPos(-30000000, -2048, -30000000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers;
|
||||
|
||||
import com.seibel.lod.core.enums.config.DistanceGenerationMode;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IVersionConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
@@ -54,4 +54,9 @@ public class VersionConstants implements IVersionConstants
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMinecraftVersion() {
|
||||
return Minecraft.getInstance().getGame().getVersion().getId();
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,148 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers;
|
||||
|
||||
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
|
||||
import com.seibel.lod.core.objects.lod.LodDimension;
|
||||
import com.seibel.lod.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.core.level.IDhLevel;
|
||||
import com.seibel.lod.core.level.IDhServerLevel;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This handles creating abstract wrapper objects.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 11-20-2021
|
||||
* @version 2022-12-5
|
||||
*/
|
||||
public class WrapperFactory implements IWrapperFactory
|
||||
{
|
||||
public static final WrapperFactory INSTANCE = new WrapperFactory();
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractBlockPosWrapper createBlockPos()
|
||||
{
|
||||
return new BlockPosWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlockPosWrapper createBlockPos(int x, int y, int z)
|
||||
{
|
||||
return new BlockPosWrapper(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractChunkPosWrapper createChunkPos()
|
||||
public AbstractBatchGenerationEnvironmentWrapper createBatchGenerator(IDhLevel targetLevel)
|
||||
{
|
||||
return new ChunkPosWrapper();
|
||||
if (targetLevel instanceof IDhServerLevel)
|
||||
{
|
||||
return new BatchGenerationEnvironment((IDhServerLevel) targetLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("The target level must be a server-side level.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractChunkPosWrapper createChunkPos(long xAndZPositionCombined)
|
||||
{
|
||||
return new ChunkPosWrapper(xAndZPositionCombined);
|
||||
}
|
||||
public IBiomeWrapper deserializeBiomeWrapper(String str) throws IOException { return BiomeWrapper.deserialize(str); }
|
||||
|
||||
@Override
|
||||
public AbstractChunkPosWrapper createChunkPos(int x, int z)
|
||||
{
|
||||
return new ChunkPosWrapper(x, z);
|
||||
}
|
||||
public IBlockStateWrapper deserializeBlockStateWrapper(String str) throws IOException { return BlockStateWrapper.deserialize(str); }
|
||||
|
||||
@Override
|
||||
public AbstractChunkPosWrapper createChunkPos(AbstractChunkPosWrapper newChunkPos)
|
||||
public IBlockStateWrapper getAirBlockStateWrapper() { return BlockStateWrapper.AIR; }
|
||||
|
||||
|
||||
/**
|
||||
* Note: when this is updated for different MC versions, make sure you also update the documentation in
|
||||
* {@link IDhApiWorldGenerator#generateChunks} and the type list in {@link WrapperFactory#createChunkWrapperErrorMessage}. <br><br>
|
||||
*
|
||||
* For full method documentation please see: {@link IWrapperFactory#createChunkWrapper}
|
||||
* @see IWrapperFactory#createChunkWrapper
|
||||
*/
|
||||
public IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException
|
||||
{
|
||||
return new ChunkPosWrapper(newChunkPos);
|
||||
if (objectArray.length == 1 && objectArray[0] instanceof IChunkWrapper) // alternate option if "instanceof" can't be compiled down to older JRE versions "IChunkWrapper.class.isInstance(objectArray[0])" Feel free to delete this comment if we've compiled the mod for 1.16 or earlier - James
|
||||
{
|
||||
try
|
||||
{
|
||||
// this path should only happen when called by Distant Horizons code
|
||||
// API implementors should never hit this path
|
||||
return (IChunkWrapper) objectArray[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
}
|
||||
// correct number of parameters from the API
|
||||
else if (objectArray.length == 2)
|
||||
{
|
||||
// chunk
|
||||
if (!(objectArray[0] instanceof ChunkAccess))
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
ChunkAccess chunk = (ChunkAccess) objectArray[0];
|
||||
|
||||
// light source
|
||||
if (!(objectArray[1] instanceof LevelReader))
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
LevelReader lightSource = (LevelReader) objectArray[1];
|
||||
|
||||
|
||||
return new ChunkWrapper(chunk, lightSource, /*A DH wrapped level isn't necessary*/null);
|
||||
}
|
||||
// incorrect number of parameters from the API
|
||||
else
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
}
|
||||
/** Note: when this is updated for different MC versions, make sure you also update the documentation in {@link IDhApiWorldGenerator#generateChunks}. */
|
||||
private static String createChunkWrapperErrorMessage(Object[] objectArray)
|
||||
{
|
||||
StringBuilder message = new StringBuilder(
|
||||
"Chunk wrapper creation failed. \n" +
|
||||
"Expected parameters: " +
|
||||
"[" + ChunkAccess.class.getName() + "], " +
|
||||
"[" + LevelReader.class.getName() + "]. \n");
|
||||
|
||||
if (objectArray.length != 0)
|
||||
{
|
||||
message.append("Given parameters: ");
|
||||
for (Object obj : objectArray)
|
||||
{
|
||||
message.append("[").append(obj.getClass().getName()).append("], ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message.append(" No parameters given.");
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractChunkPosWrapper createChunkPos(AbstractBlockPosWrapper blockPos)
|
||||
{
|
||||
return new ChunkPosWrapper(blockPos);
|
||||
}
|
||||
|
||||
public AbstractBatchGenerationEnvionmentWrapper createBatchGenerator(LodBuilder newLodBuilder,
|
||||
LodDimension newLodDimension, IWorldWrapper worldWrapper)
|
||||
{
|
||||
return new BatchGenerationEnvironment(worldWrapper, newLodBuilder, newLodDimension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.wrappers.block;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.Holder;
|
||||
#if POST_MC_1_19
|
||||
import net.minecraft.data.worldgen.biome.EndBiomes;
|
||||
import net.minecraft.data.worldgen.biome.NetherBiomes;
|
||||
#endif
|
||||
import net.minecraft.resources.RegistryFixedCodec;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
|
||||
|
||||
/** This class wraps the minecraft BlockPos.Mutable (and BlockPos) class */
|
||||
public class BiomeWrapper implements IBiomeWrapper
|
||||
{
|
||||
#if PRE_MC_1_18_2
|
||||
public static final ConcurrentMap<Biome, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
|
||||
public final Biome biome;
|
||||
#else
|
||||
public static final ConcurrentMap<Holder<Biome>, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
|
||||
public final Holder<Biome> biome;
|
||||
#endif
|
||||
|
||||
static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome)
|
||||
{
|
||||
return biomeWrapperMap.computeIfAbsent(biome, BiomeWrapper::new);
|
||||
}
|
||||
|
||||
private BiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome)
|
||||
{
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
#if PRE_MC_1_18_2
|
||||
return biome.toString();
|
||||
#else
|
||||
return biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
//FIXME: Pass in a level obj
|
||||
String data = Biome.CODEC.encodeStart(RegistryOps.create(JsonOps.INSTANCE, Minecraft.getInstance().level.registryAccess()),
|
||||
biome).get().orThrow().toString();
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BiomeWrapper that = (BiomeWrapper) o;
|
||||
return Objects.equals(biome, that.biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(biome);
|
||||
}
|
||||
|
||||
public static IBiomeWrapper deserialize(String str) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
#if PRE_MC_1_18_2 Biome #else
|
||||
Holder<Biome> #endif
|
||||
biome = Biome.CODEC.decode(RegistryOps.create(JsonOps.INSTANCE, Minecraft.getInstance().level.registryAccess()),
|
||||
JsonParser.parseString(str)).get().orThrow().getFirst();
|
||||
return getBiomeWrapper(biome);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IOException("Failed to deserialize biome wrapper", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE() { return this.biome; }
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.block;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockDetailMap
|
||||
{
|
||||
|
||||
private static ConcurrentHashMap<BlockState, BlockDetailWrapper> map = new ConcurrentHashMap<BlockState, BlockDetailWrapper>();
|
||||
|
||||
private BlockDetailMap() {}
|
||||
|
||||
public static BlockDetailWrapper getOrMakeBlockDetailCache(BlockState bs, BlockPos pos, LevelReader getter) {
|
||||
if (!bs.getFluidState().isEmpty()) {
|
||||
bs = bs.getFluidState().createLegacyBlock();
|
||||
}
|
||||
BlockDetailWrapper cache = map.get(bs);
|
||||
if (cache != null) return cache;
|
||||
cache = BlockDetailWrapper.make(bs, pos, getter);
|
||||
//ApiShared.LOGGER.info("New blockDetail cache for {} to {} ", bs, cache);
|
||||
BlockDetailWrapper cacheCAS = map.putIfAbsent(bs, cache);
|
||||
return cacheCAS==null ? cache : cacheCAS;
|
||||
}
|
||||
}
|
||||
@@ -1,350 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.block;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.seibel.lod.common.Config;
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.enums.LodDirection;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.util.ColorUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockDetailWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockTintCache;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Cursor3D;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.*;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.FlowerBlock;
|
||||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.RotatedPillarBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
#if POST_MC_1_19
|
||||
import net.minecraft.util.RandomSource;
|
||||
#endif
|
||||
|
||||
/*-- WARN: This class should NEVER hold reference to anything large,
|
||||
as this is never dealloc until the end of runtime!! --*/
|
||||
public class BlockDetailWrapper extends IBlockDetailWrapper
|
||||
{
|
||||
private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
|
||||
public static final int FLOWER_COLOR_SCALE = 5;
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static final Random random = new Random(0);
|
||||
#else
|
||||
public static final RandomSource random = RandomSource.create();
|
||||
#endif
|
||||
|
||||
enum ColorMode {
|
||||
Default,
|
||||
Flower,
|
||||
Leaves;
|
||||
static ColorMode getColorMode(Block b) {
|
||||
if (b instanceof LeavesBlock) return Leaves;
|
||||
if (b instanceof FlowerBlock) return Flower;
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
//TODO: Perhaps make this not just use the first frame?
|
||||
private static int calculateColorFromTexture(TextureAtlasSprite texture, ColorMode colorMode) {
|
||||
|
||||
int count = 0;
|
||||
double alpha = 0;
|
||||
double red = 0;
|
||||
double green = 0;
|
||||
double blue = 0;
|
||||
int tempColor;
|
||||
|
||||
{
|
||||
// textures normally use u and v instead of x and y
|
||||
for (int u = 0; u < texture.getWidth(); u++)
|
||||
{
|
||||
for (int v = 0; v < texture.getHeight(); v++)
|
||||
{
|
||||
//note: Minecraft color format is: 0xAA BB GG RR
|
||||
//________ DH mod color format is: 0xAA RR GG BB
|
||||
//OpenGL RGBA format native order: 0xRR GG BB AA
|
||||
//_ OpenGL RGBA format Java Order: 0xAA BB GG RR
|
||||
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
|
||||
|
||||
double r = ((tempColor & 0x000000FF) )/255.;
|
||||
double g = ((tempColor & 0x0000FF00) >>> 8)/255.;
|
||||
double b = ((tempColor & 0x00FF0000) >>> 16)/255.;
|
||||
double a = ((tempColor & 0xFF000000) >>> 24)/255.;
|
||||
int scale = 1;
|
||||
|
||||
if (colorMode == ColorMode.Leaves) {
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
a = 1.;
|
||||
} else if (a==0.) {
|
||||
continue;
|
||||
} else if (colorMode == ColorMode.Flower && (g+0.1<b || g+0.1<r)) {
|
||||
scale = FLOWER_COLOR_SCALE;
|
||||
}
|
||||
|
||||
count += scale;
|
||||
alpha += a*a*scale;
|
||||
red += r*r*scale;
|
||||
green += g*g*scale;
|
||||
blue += b*b*scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
// this block is entirely transparent
|
||||
tempColor = ColorUtil.rgbToInt(255,255,0,255);
|
||||
else
|
||||
{
|
||||
// determine the average color
|
||||
tempColor = ColorUtil.rgbToInt(
|
||||
(int) (Math.sqrt(alpha/count)*255.),
|
||||
(int) (Math.sqrt(red / count)*255.),
|
||||
(int) (Math.sqrt(green / count)*255.),
|
||||
(int) (Math.sqrt(blue / count)*255.));
|
||||
}
|
||||
// TODO: Remove this when transparency is added!
|
||||
double colorAlpha = ColorUtil.getAlpha(tempColor)/255.;
|
||||
tempColor = ColorUtil.rgbToInt(
|
||||
ColorUtil.getAlpha(tempColor),
|
||||
(int)(ColorUtil.getRed(tempColor) * colorAlpha),
|
||||
(int)(ColorUtil.getGreen(tempColor) * colorAlpha),
|
||||
(int)(ColorUtil.getBlue(tempColor) * colorAlpha)
|
||||
);
|
||||
return tempColor;
|
||||
}
|
||||
|
||||
private static final Block[] BLOCK_TO_AVOID = {Blocks.AIR, Blocks.CAVE_AIR, Blocks.BARRIER};
|
||||
|
||||
private static final Direction[] DIRECTION_ORDER = {Direction.UP, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.SOUTH, Direction.DOWN};
|
||||
|
||||
private static boolean isBlockToBeAvoid(Block b) {
|
||||
for (Block bta : BLOCK_TO_AVOID)
|
||||
if (bta==b) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
final BlockState state;
|
||||
|
||||
//boolean isShapeResolved = false;
|
||||
//^ Shapes no longer lazy resolved due to memory leaks from needing
|
||||
// to keep a reference to the block getter
|
||||
|
||||
boolean[] dontOccludeFaces = null;
|
||||
boolean noCollision = false;
|
||||
boolean noFullFace = false;
|
||||
|
||||
boolean isColorResolved = false;
|
||||
int baseColor = 0; //TODO: Impl per-face color
|
||||
boolean needShade = true;
|
||||
boolean needPostTinting = false;
|
||||
int tintIndex = 0;
|
||||
|
||||
public static BlockDetailWrapper NULL_BLOCK_DETAIL = new BlockDetailWrapper();
|
||||
|
||||
public BlockDetailWrapper(BlockState state, BlockPos pos, LevelReader getter) {
|
||||
this.state = state;
|
||||
resolveShapes(getter, pos);
|
||||
//ApiShared.LOGGER.info("Created BlockDetailWrapper for blockstate {} at {}", state, pos);
|
||||
}
|
||||
|
||||
private BlockDetailWrapper() {
|
||||
this.state = null;
|
||||
}
|
||||
|
||||
static BlockDetailWrapper make(BlockState bs, BlockPos pos, LevelReader getter) {
|
||||
if(!bs.getFluidState().isEmpty()) { // Is a fluidBlock
|
||||
if (isBlockToBeAvoid(bs.getBlock())) return NULL_BLOCK_DETAIL;
|
||||
if (bs.isAir()) return NULL_BLOCK_DETAIL;
|
||||
return new BlockDetailWrapper(bs, pos, getter);
|
||||
} else {
|
||||
if (bs.getRenderShape() != RenderShape.MODEL) return NULL_BLOCK_DETAIL;
|
||||
if (isBlockToBeAvoid(bs.getBlock())) return NULL_BLOCK_DETAIL;
|
||||
return new BlockDetailWrapper(bs, pos, getter);
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveShapes(LevelReader sampleGetter, BlockPos samplePos) {
|
||||
//if (isShapeResolved) return;
|
||||
if (state.getFluidState().isEmpty()) {
|
||||
noCollision = state.getCollisionShape(sampleGetter, samplePos).isEmpty();
|
||||
dontOccludeFaces = new boolean[6];
|
||||
if (state.canOcclude()) {
|
||||
/* FIXME: Figure out how or if needed to impl per-face culling?
|
||||
for (Direction dir : Direction.values()) {
|
||||
dontOccludeFaces[McObjectConverter.Convert(dir).ordinal()]
|
||||
= state.getFaceOcclusionShape(sampleGetter, samplePos, dir).isEmpty();
|
||||
}*/
|
||||
} else {
|
||||
Arrays.fill(dontOccludeFaces, true);
|
||||
}
|
||||
|
||||
VoxelShape voxelShape = state.getShape(sampleGetter, samplePos);
|
||||
if (voxelShape.isEmpty()) {
|
||||
noFullFace = true;
|
||||
} else {
|
||||
AABB bbox = voxelShape.bounds();
|
||||
double xWidth = (bbox.maxX - bbox.minX);
|
||||
double yWidth = (bbox.maxY - bbox.minY);
|
||||
double zWidth = (bbox.maxZ - bbox.minZ);
|
||||
noFullFace = xWidth < 1 && zWidth < 1 && yWidth < 1;
|
||||
}
|
||||
} else { // Liquid Block
|
||||
dontOccludeFaces = new boolean[6];
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveColors() {
|
||||
if (isColorResolved) return;
|
||||
if (state.getFluidState().isEmpty()) {
|
||||
List<BakedQuad> quads = null;
|
||||
for (Direction direction : DIRECTION_ORDER)
|
||||
{
|
||||
quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
|
||||
getBlockModel(state).getQuads(state, direction, random);
|
||||
if (!quads.isEmpty() &&
|
||||
!(state.getBlock() instanceof RotatedPillarBlock && direction == Direction.UP))
|
||||
break;
|
||||
};
|
||||
if (quads == null || quads.isEmpty()) {
|
||||
quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
|
||||
getBlockModel(state).getQuads(state, null, random);
|
||||
}
|
||||
if (quads != null && !quads.isEmpty()) {
|
||||
needPostTinting = quads.get(0).isTinted();
|
||||
needShade = quads.get(0).isShade();
|
||||
tintIndex = quads.get(0).getTintIndex();
|
||||
baseColor = calculateColorFromTexture(
|
||||
#if PRE_MC_1_17_1 quads.get(0).sprite,
|
||||
#else quads.get(0).getSprite(), #endif
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
} else { // Backup method.
|
||||
needPostTinting = false;
|
||||
needShade = false;
|
||||
tintIndex = 0;
|
||||
baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
}
|
||||
} else { // Liquid Block
|
||||
needPostTinting = true;
|
||||
needShade = false;
|
||||
tintIndex = 0;
|
||||
baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
}
|
||||
isColorResolved = true;
|
||||
}
|
||||
|
||||
private BlockAndTintGetter wrapColorResolver(LevelReader level) {
|
||||
int blendDistance = CONFIG.client().graphics().quality().getLodBiomeBlending();
|
||||
if (blendDistance == 0) {
|
||||
return new TintGetterOverrideFast(level);
|
||||
} else {
|
||||
return new TintGetterOverrideSmooth(level, blendDistance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAndResolveFaceColor(LodDirection dir, IChunkWrapper chunk, AbstractBlockPosWrapper blockPos)
|
||||
{
|
||||
// FIXME: impl per-face colors
|
||||
resolveColors();
|
||||
if (!needPostTinting) return baseColor;
|
||||
int tintColor = Minecraft.getInstance().getBlockColors()
|
||||
.getColor(state, wrapColorResolver(((ChunkWrapper)chunk).getColorResolver()),
|
||||
McObjectConverter.Convert(blockPos), tintIndex);
|
||||
if (tintColor == -1) return baseColor;
|
||||
return ColorUtil.multiplyARGBwithRGB(baseColor, tintColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFaceCullingFor(LodDirection dir)
|
||||
{
|
||||
//resolveShapes();
|
||||
return !dontOccludeFaces[dir.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNoCollision()
|
||||
{
|
||||
//resolveShapes();
|
||||
return noCollision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noFaceIsFullFace()
|
||||
{
|
||||
//resolveShapes();
|
||||
return noFullFace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize()
|
||||
{
|
||||
// FIXME: Impl this for the blockState Storage stuff
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSame(IBlockDetailWrapper iBlockDetail)
|
||||
{
|
||||
return ((BlockDetailWrapper)iBlockDetail).state.getBlock().equals(state.getBlock());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BlockDetail{" + state + "}";
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.block;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.seibel.lod.core.enums.LodDirection;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 11-21-2021
|
||||
*/
|
||||
public class BlockPosWrapper extends AbstractBlockPosWrapper
|
||||
{
|
||||
private final BlockPos.MutableBlockPos blockPos;
|
||||
|
||||
|
||||
public BlockPosWrapper()
|
||||
{
|
||||
this.blockPos = new BlockPos.MutableBlockPos(0,0,0);
|
||||
}
|
||||
|
||||
public BlockPosWrapper(int x, int y, int z)
|
||||
{
|
||||
this.blockPos = new BlockPos.MutableBlockPos(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z)
|
||||
{
|
||||
blockPos.set(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX()
|
||||
{
|
||||
return blockPos.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY()
|
||||
{
|
||||
return blockPos.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ()
|
||||
{
|
||||
return blockPos.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(LodDirection.Axis axis)
|
||||
{
|
||||
return axis.choose(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public BlockPos.MutableBlockPos getBlockPos()
|
||||
{
|
||||
return blockPos;
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o)
|
||||
{
|
||||
return blockPos.equals(o);
|
||||
}
|
||||
|
||||
@Override public int hashCode()
|
||||
{
|
||||
return Objects.hash(blockPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosWrapper offset(int x, int y, int z)
|
||||
{
|
||||
blockPos.set(blockPos.getX() + x, blockPos.getY() + y, blockPos.getZ() + z);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.seibel.lod.common.wrappers.block;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BlockStateWrapper implements IBlockStateWrapper
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
public static final BlockStateWrapper AIR = new BlockStateWrapper(null);
|
||||
|
||||
public static ConcurrentHashMap<BlockState, BlockStateWrapper> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public static BlockStateWrapper fromBlockState(BlockState blockState)
|
||||
{
|
||||
if (blockState == null || blockState.isAir())
|
||||
return AIR;
|
||||
|
||||
if (blockState.getFluidState().isEmpty())
|
||||
return cache.computeIfAbsent(blockState, BlockStateWrapper::new);
|
||||
else
|
||||
return cache.computeIfAbsent(blockState.getFluidState().createLegacyBlock(), BlockStateWrapper::new);
|
||||
}
|
||||
|
||||
public final BlockState blockState;
|
||||
BlockStateWrapper(BlockState blockState) {
|
||||
this.blockState = blockState;
|
||||
//LOGGER.info("Created BlockStateWrapper for {}", blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize()
|
||||
{
|
||||
if (this.blockState == null)
|
||||
{
|
||||
return "AIR";
|
||||
}
|
||||
|
||||
return BlockState.CODEC.encodeStart(JsonOps.COMPRESSED, this.blockState).get().orThrow().toString();
|
||||
}
|
||||
|
||||
public static BlockStateWrapper deserialize(String str) throws IOException {
|
||||
if (str.equals("AIR")) {
|
||||
return AIR;
|
||||
}
|
||||
try {
|
||||
return new BlockStateWrapper(
|
||||
BlockState.CODEC.decode(JsonOps.COMPRESSED, JsonParser.parseString(str)).get().orThrow().getFirst()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Failed to deserialize BlockStateWrapper", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BlockStateWrapper that = (BlockStateWrapper) o;
|
||||
return Objects.equals(blockState, that.blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(blockState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE() { return this.blockState; }
|
||||
|
||||
@Override
|
||||
public boolean isAir() { return this.isAir(this.blockState); }
|
||||
public boolean isAir(BlockState blockState) { return blockState == null || blockState.isAir(); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.wrappers.block;
|
||||
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.*;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class TintWithoutLevelOverrider implements BlockAndTintGetter {
|
||||
final BiomeWrapper biome;
|
||||
|
||||
public TintWithoutLevelOverrider(BiomeWrapper biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
@Override
|
||||
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
|
||||
return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
|
||||
}
|
||||
private Biome _unwrap(#if POST_MC_1_18_2 Holder<Biome> #else Biome #endif biome) {
|
||||
#if POST_MC_1_18_2
|
||||
return biome.value();
|
||||
#else
|
||||
return biome;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShade(Direction direction, boolean shade) {
|
||||
throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public LevelLightEngine getLightEngine() {
|
||||
throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public FluidState getFluidState(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public int getHeight() {
|
||||
throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public int getMinBuildHeight() {
|
||||
throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.wrappers.block;
|
||||
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Cursor3D;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.ColorResolver;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TintWithoutLevelSmoothOverrider implements BlockAndTintGetter {
|
||||
final BiomeWrapper biome;
|
||||
public int smoothingRange;
|
||||
|
||||
public TintWithoutLevelSmoothOverrider(BiomeWrapper biome, int smoothingRange) {
|
||||
this.biome = biome;
|
||||
this.smoothingRange = smoothingRange;
|
||||
}
|
||||
@Override
|
||||
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
|
||||
return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
|
||||
}
|
||||
private Biome _unwrap(#if POST_MC_1_18_2 Holder<Biome> #else Biome #endif biome) {
|
||||
#if POST_MC_1_18_2
|
||||
return biome.value();
|
||||
#else
|
||||
return biome;
|
||||
#endif
|
||||
}
|
||||
//
|
||||
// public int calculateBlockTint(BlockPos blockPos, ColorResolver colorResolver)
|
||||
// {
|
||||
// int i = smoothingRange;
|
||||
// if (i == 0)
|
||||
// return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
|
||||
// int j = (i * 2 + 1) * (i * 2 + 1);
|
||||
// int k = 0;
|
||||
// int l = 0;
|
||||
// int m = 0;
|
||||
// Cursor3D cursor3D = new Cursor3D(blockPos.getX() - i, blockPos.getY(), blockPos.getZ() - i, blockPos.getX() + i, blockPos.getY(), blockPos.getZ() + i);
|
||||
// BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
||||
// while (cursor3D.advance())
|
||||
// {
|
||||
// mutableBlockPos.set(cursor3D.nextX(), cursor3D.nextY(), cursor3D.nextZ());
|
||||
// int n;
|
||||
// if (LodCommonMain.forgeMethodCaller != null) {
|
||||
// n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos),
|
||||
// mutableBlockPos.getX(), mutableBlockPos.getZ());
|
||||
// } else {
|
||||
// n = colorResolver.getColor(_getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ());
|
||||
// }
|
||||
//
|
||||
// k += (n & 0xFF0000) >> 16;
|
||||
// l += (n & 0xFF00) >> 8;
|
||||
// m += n & 0xFF;
|
||||
// }
|
||||
// return (k / j & 0xFF) << 16 | (l / j & 0xFF) << 8 | m / j & 0xFF;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public float getShade(Direction direction, boolean shade) {
|
||||
throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public LevelLightEngine getLightEngine() {
|
||||
throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public FluidState getFluidState(BlockPos pos) {
|
||||
throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public int getHeight() {
|
||||
throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
@Override
|
||||
public int getMinBuildHeight() {
|
||||
throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.seibel.lod.common.wrappers.block.cache;
|
||||
|
||||
import com.seibel.lod.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ClientBlockDetailMap {
|
||||
private final ConcurrentHashMap<BlockState, ClientBlockStateCache> blockCache = new ConcurrentHashMap<>();
|
||||
//private final ConcurrentHashMap<#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif, Biome> biomeMap = new ConcurrentHashMap<>();
|
||||
private final ClientLevelWrapper level;
|
||||
public ClientBlockDetailMap(ClientLevelWrapper level) { this.level = level; }
|
||||
|
||||
public ClientBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos) { //TODO: Allow a per pos unique setting
|
||||
return blockCache.computeIfAbsent(state, (s) -> new ClientBlockStateCache(s, level, new DhBlockPos(0,0,0)));
|
||||
}
|
||||
|
||||
public void clear() { blockCache.clear(); }
|
||||
|
||||
public int getColor(BlockState state, BiomeWrapper biome, DhBlockPos pos) {
|
||||
return getBlockStateData(state, pos).getAndResolveFaceColor(biome);
|
||||
}
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
package com.seibel.lod.common.wrappers.block.cache;
|
||||
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.block.*;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.util.ColorUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.FlowerBlock;
|
||||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.RotatedPillarBlock;
|
||||
#if POST_MC_1_19
|
||||
import net.minecraft.util.RandomSource;
|
||||
#endif
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class ClientBlockStateCache
|
||||
{
|
||||
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static final Random random = new Random(0);
|
||||
#else
|
||||
public static final RandomSource random = RandomSource.create();
|
||||
#endif
|
||||
|
||||
public final BlockState state;
|
||||
public final LevelReader level;
|
||||
public final BlockPos pos;
|
||||
public ClientBlockStateCache(BlockState blockState, IClientLevelWrapper samplingLevel, DhBlockPos samplingPos) {
|
||||
state = blockState;
|
||||
level = (LevelReader) samplingLevel.getWrappedMcObject_UNSAFE();
|
||||
pos = McObjectConverter.Convert(samplingPos);
|
||||
resolveColors();
|
||||
//LOGGER.info("ClientBlocKCache created for {}", blockState);
|
||||
}
|
||||
|
||||
boolean isColorResolved = false;
|
||||
int baseColor = 0; //TODO: Impl per-face color
|
||||
boolean needShade = true;
|
||||
boolean needPostTinting = false;
|
||||
int tintIndex = 0;
|
||||
|
||||
|
||||
public static final int FLOWER_COLOR_SCALE = 5;
|
||||
|
||||
enum ColorMode {
|
||||
Default,
|
||||
Flower,
|
||||
Leaves;
|
||||
static ColorMode getColorMode(Block b) {
|
||||
if (b instanceof LeavesBlock) return Leaves;
|
||||
if (b instanceof FlowerBlock) return Flower;
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
//TODO: Perhaps make this not just use the first frame?
|
||||
private static int calculateColorFromTexture(TextureAtlasSprite texture, ColorMode colorMode) {
|
||||
int count = 0;
|
||||
double alpha = 0;
|
||||
double red = 0;
|
||||
double green = 0;
|
||||
double blue = 0;
|
||||
int tempColor;
|
||||
{
|
||||
// textures normally use u and v instead of x and y
|
||||
for (int u = 0; u < texture.getWidth(); u++)
|
||||
{
|
||||
for (int v = 0; v < texture.getHeight(); v++)
|
||||
{
|
||||
//note: Minecraft color format is: 0xAA BB GG RR
|
||||
//________ DH mod color format is: 0xAA RR GG BB
|
||||
//OpenGL RGBA format native order: 0xRR GG BB AA
|
||||
//_ OpenGL RGBA format Java Order: 0xAA BB GG RR
|
||||
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
|
||||
|
||||
double r = ((tempColor & 0x000000FF) )/255.;
|
||||
double g = ((tempColor & 0x0000FF00) >>> 8)/255.;
|
||||
double b = ((tempColor & 0x00FF0000) >>> 16)/255.;
|
||||
double a = ((tempColor & 0xFF000000) >>> 24)/255.;
|
||||
int scale = 1;
|
||||
|
||||
if (colorMode == ColorMode.Leaves) {
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
a = 1.;
|
||||
} else if (a==0.) {
|
||||
continue;
|
||||
} else if (colorMode == ColorMode.Flower && (g+0.1<b || g+0.1<r)) {
|
||||
scale = FLOWER_COLOR_SCALE;
|
||||
}
|
||||
|
||||
count += scale;
|
||||
alpha += a*a*scale;
|
||||
red += r*r*scale;
|
||||
green += g*g*scale;
|
||||
blue += b*b*scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
// this block is entirely transparent
|
||||
tempColor = ColorUtil.rgbToInt(0,255,255,255);
|
||||
else
|
||||
{
|
||||
// determine the average color
|
||||
tempColor = ColorUtil.rgbToInt(
|
||||
(int) (Math.sqrt(alpha/count)*255.),
|
||||
(int) (Math.sqrt(red / count)*255.),
|
||||
(int) (Math.sqrt(green / count)*255.),
|
||||
(int) (Math.sqrt(blue / count)*255.));
|
||||
}
|
||||
return tempColor;
|
||||
}
|
||||
private static final Direction[] DIRECTION_ORDER = {Direction.UP, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.SOUTH, Direction.DOWN};
|
||||
|
||||
private void resolveColors() {
|
||||
if (isColorResolved) return;
|
||||
if (state.getFluidState().isEmpty()) {
|
||||
List<BakedQuad> quads = null;
|
||||
for (Direction direction : DIRECTION_ORDER)
|
||||
{
|
||||
quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
|
||||
getBlockModel(state).getQuads(state, direction, random);
|
||||
if (quads != null && !quads.isEmpty() &&
|
||||
!(state.getBlock() instanceof RotatedPillarBlock && direction == Direction.UP))
|
||||
break;
|
||||
};
|
||||
if (quads == null || quads.isEmpty()) {
|
||||
quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
|
||||
getBlockModel(state).getQuads(state, null, random);
|
||||
}
|
||||
if (quads != null && !quads.isEmpty()) {
|
||||
needPostTinting = quads.get(0).isTinted();
|
||||
needShade = quads.get(0).isShade();
|
||||
tintIndex = quads.get(0).getTintIndex();
|
||||
baseColor = calculateColorFromTexture(
|
||||
#if PRE_MC_1_17_1 quads.get(0).sprite,
|
||||
#else quads.get(0).getSprite(), #endif
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
} else { // Backup method.
|
||||
needPostTinting = false;
|
||||
needShade = false;
|
||||
tintIndex = 0;
|
||||
baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
}
|
||||
} else { // Liquid Block
|
||||
needPostTinting = true;
|
||||
needShade = false;
|
||||
tintIndex = 0;
|
||||
baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
|
||||
ColorMode.getColorMode(state.getBlock()));
|
||||
}
|
||||
isColorResolved = true;
|
||||
}
|
||||
|
||||
public int getAndResolveFaceColor(BiomeWrapper biome)
|
||||
{
|
||||
// FIXME: impl per-face colors
|
||||
if (!needPostTinting) return baseColor;
|
||||
int tintColor = Minecraft.getInstance().getBlockColors()
|
||||
.getColor(state, new TintWithoutLevelOverrider(biome), pos, tintIndex);
|
||||
if (tintColor == -1) return baseColor;
|
||||
return ColorUtil.multiplyARGBwithRGB(baseColor, tintColor);
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.wrappers.block.cache;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.seibel.lod.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
|
||||
public class ServerBlockDetailMap
|
||||
{
|
||||
private final ConcurrentHashMap<BlockState, ServerBlockStateCache> blockCache = new ConcurrentHashMap<>();
|
||||
//private final ConcurrentHashMap<#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif, Biome> biomeMap = new ConcurrentHashMap<>();
|
||||
private final ServerLevelWrapper level;
|
||||
public ServerBlockDetailMap(ServerLevelWrapper level) { this.level = level; }
|
||||
|
||||
public ServerBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos) { //TODO: Allow a per pos unique setting
|
||||
return blockCache.computeIfAbsent(state, (s) -> new ServerBlockStateCache(s, level, new DhBlockPos(0,0,0)));
|
||||
}
|
||||
|
||||
public void clear() { blockCache.clear(); }
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.seibel.lod.common.wrappers.block.cache;
|
||||
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class ServerBlockStateCache
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public final BlockState state;
|
||||
public final LevelReader level;
|
||||
public final BlockPos pos;
|
||||
|
||||
public ServerBlockStateCache(BlockState blockState, ILevelWrapper samplingLevel, DhBlockPos samplingPos) {
|
||||
state = blockState;
|
||||
level = (LevelReader) samplingLevel.getWrappedMcObject_UNSAFE();
|
||||
pos = McObjectConverter.Convert(samplingPos);
|
||||
resolveShapes();
|
||||
//LOGGER.info("ServerBlockState created for {}", blockState);
|
||||
}
|
||||
|
||||
boolean noCollision = false;
|
||||
boolean[] occludeFaces = null;
|
||||
boolean[] fullFaces = null;
|
||||
boolean isShapeResolved = false;
|
||||
public void resolveShapes() {
|
||||
if (isShapeResolved) return;
|
||||
if (state.getFluidState().isEmpty()) {
|
||||
noCollision = state.getCollisionShape(level, pos).isEmpty();
|
||||
occludeFaces = new boolean[6];
|
||||
if (state.canOcclude()) {
|
||||
for (Direction dir : Direction.values()) {
|
||||
// Note: isEmpty() isn't quite correct... best would be a isFull() or something...
|
||||
occludeFaces[McObjectConverter.Convert(dir).ordinal()]
|
||||
= !state.getFaceOcclusionShape(level, pos, dir).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
VoxelShape voxelShape = state.getShape(level, pos);
|
||||
fullFaces = new boolean[6];
|
||||
if (!voxelShape.isEmpty()) {
|
||||
for (Direction dir : Direction.values()) {
|
||||
VoxelShape faceShape = voxelShape.getFaceShape(dir);
|
||||
AABB aabb = faceShape.bounds();
|
||||
boolean xFull = aabb.minX <= 0.01 && aabb.maxX >= 0.99;
|
||||
boolean yFull = aabb.minY <= 0.01 && aabb.maxY >= 0.99;
|
||||
boolean zFull = aabb.minZ <= 0.01 && aabb.maxZ >= 0.99;
|
||||
fullFaces[McObjectConverter.Convert(dir).ordinal()] =
|
||||
(xFull || dir.getAxis().equals(Direction.Axis.X))
|
||||
&& (yFull || dir.getAxis().equals(Direction.Axis.Y))
|
||||
&& (zFull || dir.getAxis().equals(Direction.Axis.Z));
|
||||
}
|
||||
}
|
||||
} else { // Liquid Block. Treat as full block
|
||||
occludeFaces = new boolean[6];
|
||||
Arrays.fill(occludeFaces, true);
|
||||
fullFaces = new boolean[6];
|
||||
Arrays.fill(fullFaces, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.chunk;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.seibel.lod.core.util.LevelPosUtil;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 11-21-2021
|
||||
*/
|
||||
public class ChunkPosWrapper extends AbstractChunkPosWrapper
|
||||
{
|
||||
private final net.minecraft.world.level.ChunkPos chunkPos;
|
||||
|
||||
public ChunkPosWrapper()
|
||||
{
|
||||
this.chunkPos = new ChunkPos(0, 0);
|
||||
}
|
||||
|
||||
public ChunkPosWrapper(BlockPos blockPos)
|
||||
{
|
||||
this.chunkPos = new ChunkPos(blockPos);
|
||||
}
|
||||
|
||||
public ChunkPosWrapper(AbstractChunkPosWrapper newChunkPos)
|
||||
{
|
||||
this.chunkPos = ((ChunkPosWrapper) newChunkPos).chunkPos;
|
||||
}
|
||||
|
||||
public ChunkPosWrapper(AbstractBlockPosWrapper blockPos)
|
||||
{
|
||||
this.chunkPos = new ChunkPos(((BlockPosWrapper) blockPos).getBlockPos());
|
||||
}
|
||||
|
||||
public ChunkPosWrapper(int chunkX, int chunkZ)
|
||||
{
|
||||
this.chunkPos = new ChunkPos(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public ChunkPosWrapper(long l) {
|
||||
this.chunkPos = new ChunkPos(l);
|
||||
}
|
||||
|
||||
|
||||
public ChunkPosWrapper(ChunkPos pos)
|
||||
{
|
||||
this.chunkPos = pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getX()
|
||||
{
|
||||
return chunkPos.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ()
|
||||
{
|
||||
return chunkPos.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinBlockX()
|
||||
{
|
||||
return chunkPos.getMinBlockX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinBlockZ()
|
||||
{
|
||||
return chunkPos.getMinBlockZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegionX()
|
||||
{
|
||||
return LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, chunkPos.x, LodUtil.REGION_DETAIL_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegionZ()
|
||||
{
|
||||
return LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, chunkPos.z, LodUtil.REGION_DETAIL_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong() {
|
||||
return chunkPos.toLong();
|
||||
}
|
||||
|
||||
public ChunkPos getChunkPos()
|
||||
{
|
||||
return chunkPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
// If the object is compared with itself then return true
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
// Check if o is an instance of RegionPos or not
|
||||
if (!(o instanceof ChunkPosWrapper)) {
|
||||
return false;
|
||||
}
|
||||
ChunkPosWrapper c = (ChunkPosWrapper) o;
|
||||
return c.chunkPos.equals(chunkPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(chunkPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlockPosWrapper getWorldPosition()
|
||||
{
|
||||
// the parameter here is the y position
|
||||
#if PRE_MC_1_17_1
|
||||
BlockPos blockPos = chunkPos.getWorldPosition();
|
||||
#else
|
||||
BlockPos blockPos = chunkPos.getMiddleBlockPosition(0);
|
||||
#endif
|
||||
return new BlockPosWrapper(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +1,50 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.chunk;
|
||||
|
||||
import com.seibel.lod.common.wrappers.block.BlockDetailWrapper;
|
||||
import com.seibel.lod.core.enums.LodDirection;
|
||||
import com.seibel.lod.core.util.LevelPosUtil;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockDetailWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
import com.seibel.lod.common.wrappers.WrapperUtil;
|
||||
import com.seibel.lod.common.wrappers.block.BlockDetailMap;
|
||||
import com.seibel.lod.common.wrappers.world.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion;
|
||||
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
#if POST_MC_1_17_1
|
||||
import net.minecraft.core.QuartPos;
|
||||
#endif
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.LiquidBlockContainer;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
|
||||
// Which nullable should be used???
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
//import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author James Seibel
|
||||
@@ -55,13 +53,17 @@ import net.minecraft.world.level.levelgen.Heightmap;
|
||||
public class ChunkWrapper implements IChunkWrapper
|
||||
{
|
||||
private final ChunkAccess chunk;
|
||||
private final DhChunkPos chunkPos;
|
||||
private final LevelReader lightSource;
|
||||
private final ILevelWrapper wrappedLevel;
|
||||
|
||||
|
||||
public ChunkWrapper(ChunkAccess chunk, LevelReader lightSource)
|
||||
public ChunkWrapper(ChunkAccess chunk, LevelReader lightSource, @Nullable ILevelWrapper wrappedLevel)
|
||||
{
|
||||
this.chunk = chunk;
|
||||
this.lightSource = lightSource;
|
||||
this.wrappedLevel = wrappedLevel;
|
||||
chunkPos = new DhChunkPos(chunk.getPos().x, chunk.getPos().z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,6 +99,8 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
@Override
|
||||
public IBiomeWrapper getBiome(int x, int y, int z)
|
||||
{
|
||||
//if (wrappedLevel != null) return wrappedLevel.getBiome(new DhBlockPos(x + getMinX(), y, z + getMinZ()));
|
||||
|
||||
#if PRE_MC_1_17_1
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
|
||||
x >> 2, y >> 2, z >> 2));
|
||||
@@ -106,60 +110,21 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
#elif PRE_MC_1_18_2
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
|
||||
#else
|
||||
#else //Now returns a Holder<Biome> instead of Biome
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)).value());
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBlockDetailWrapper getBlockDetail(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x,y,z);
|
||||
BlockState blockState = chunk.getBlockState(pos);
|
||||
IBlockDetailWrapper blockDetail = BlockDetailMap.getOrMakeBlockDetailCache(blockState, pos, lightSource);
|
||||
return blockDetail == BlockDetailWrapper.NULL_BLOCK_DETAIL ? null : blockDetail;
|
||||
public DhChunkPos getChunkPos() {
|
||||
return chunkPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDetailWrapper getBlockDetailAtFace(int x, int y, int z, LodDirection dir) {
|
||||
int fy = y+dir.getNormal().y;
|
||||
if (fy < getMinBuildHeight() || fy > getMaxBuildHeight()) return null;
|
||||
BlockPos pos = new BlockPos(x+dir.getNormal().x,fy,z+dir.getNormal().z);
|
||||
BlockState blockState;
|
||||
if (blockPosInsideChunk(x,y,z))
|
||||
blockState = chunk.getBlockState(pos);
|
||||
else {
|
||||
blockState = lightSource.getBlockState(pos);
|
||||
}
|
||||
if (blockState == null || blockState.isAir()) return null;
|
||||
IBlockDetailWrapper blockDetail = BlockDetailMap.getOrMakeBlockDetailCache(blockState, pos, lightSource);
|
||||
return blockDetail == BlockDetailWrapper.NULL_BLOCK_DETAIL ? null : blockDetail;
|
||||
}
|
||||
|
||||
public ChunkAccess getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChunkPosX(){
|
||||
return chunk.getPos().x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChunkPosZ(){
|
||||
return chunk.getPos().z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegionPosX(){
|
||||
return LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, LodUtil.REGION_DETAIL_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegionPosZ(){
|
||||
return LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().z, LodUtil.REGION_DETAIL_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxY(int x, int z) {
|
||||
return chunk.getHeight(Heightmap.Types.WORLD_SURFACE, Math.floorMod(x, 16), Math.floorMod(z, 16));
|
||||
@@ -192,38 +157,29 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
#if PRE_MC_1_18_1
|
||||
return true;
|
||||
#else
|
||||
if (chunk instanceof LevelChunk) {
|
||||
return ((LevelChunk) chunk).isClientLightReady();
|
||||
if (chunk instanceof LevelChunk)
|
||||
{
|
||||
// called when connected to a server (and sometimes when in a singleplayer world)
|
||||
return ((LevelChunk) chunk).isClientLightReady() || chunk.isLightCorrect();
|
||||
}
|
||||
else
|
||||
{
|
||||
// called when in a single player world
|
||||
return chunk.isLightCorrect();
|
||||
}
|
||||
return chunk.isLightCorrect();
|
||||
#endif
|
||||
}
|
||||
|
||||
public boolean isWaterLogged(int x, int y, int z)
|
||||
{
|
||||
BlockState blockState = chunk.getBlockState(new BlockPos(x,y,z));
|
||||
|
||||
//This type of block is always in water
|
||||
return (!(blockState.getBlock() instanceof LiquidBlockContainer) && (blockState.getBlock() instanceof SimpleWaterloggedBlock))
|
||||
&& (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmittedBrightness(int x, int y, int z)
|
||||
{
|
||||
return chunk.getLightEmission(new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z) {
|
||||
if (lightSource == null) return -1;
|
||||
return lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z));
|
||||
return lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(x + getMinX(),y,z + getMinZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
if (lightSource == null) return -1;
|
||||
return lightSource.getBrightness(LightLayer.SKY, new BlockPos(x,y,z));
|
||||
return lightSource.getBrightness(LightLayer.SKY, new BlockPos(x + getMinX(),y,z + getMinZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +188,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
if (dx==0 && dz==0) continue;
|
||||
if (lightSource.getChunk(dx+getChunkPosX(), dz+getChunkPosZ(), ChunkStatus.BIOMES, false) == null) return false;
|
||||
if (lightSource.getChunk(dx+chunk.getPos().x, dz+chunk.getPos().z, ChunkStatus.BIOMES, false) == null) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -247,5 +203,15 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
public String toString() {
|
||||
return chunk.getClass().getSimpleName() + chunk.getPos();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(int x, int y, int z) {
|
||||
//if (wrappedLevel != null) return wrappedLevel.getBlockState(new DhBlockPos(x + getMinX(), y, z + getMinZ()));
|
||||
return BlockStateWrapper.fromBlockState(chunk.getBlockState(new BlockPos(x,y,z)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStillValid() {
|
||||
return wrappedLevel == null || wrappedLevel.tryGetChunk(chunkPos) == this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,817 +0,0 @@
|
||||
package com.seibel.lod.common.wrappers.config;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// Logger (for debug stuff)
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
// Uses https://github.com/TheElectronWill/night-config for toml (only for Fabric since Forge already includes this)
|
||||
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
|
||||
// Gets info from our own mod
|
||||
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.*;
|
||||
|
||||
// Minecraft imports
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
#endif
|
||||
import net.minecraft.client.resources.language.I18n; // translation
|
||||
#if POST_MC_1_17_1
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Based upon TinyConfig
|
||||
* https://github.com/Minenash/TinyConfig
|
||||
*
|
||||
* This config should work for both Fabric and Forge as long as you use Mojang mappings
|
||||
*
|
||||
* Credits to Motschen
|
||||
*
|
||||
* REMOVED IN a1.7
|
||||
*
|
||||
* @author coolGi
|
||||
* @version 1-14-2022
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class ConfigGui
|
||||
{
|
||||
private static final Pattern INTEGER_ONLY_REGEX = Pattern.compile("(-?[0-9]*)");
|
||||
private static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||
|
||||
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||
public static final Map<String,EntryInfo> entryMap = new HashMap<>();
|
||||
|
||||
// Change these to your own mod
|
||||
private static final String MOD_NAME = ModInfo.NAME; // For file saving and identifying
|
||||
private static final String MOD_NAME_READABLE = ModInfo.READABLE_NAME; // For logs
|
||||
// private static final Logger LOGGER = ApiShared.LOGGER; // For logs
|
||||
private static final Logger LOGGER = LogManager.getLogger(ModInfo.NAME); // For logs (this inits before ClientAPI so this is a temp fix)
|
||||
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// Initializers //
|
||||
//==============//
|
||||
|
||||
private static class ConfigScreenConfigs
|
||||
{
|
||||
// This contains all the configs for the configs
|
||||
public static final int SpaceFromRightScreen = 10;
|
||||
public static final int ButtonWidthSpacing = 5;
|
||||
public static final int ResetButtonWidth = 40;
|
||||
}
|
||||
|
||||
public static class EntryInfo<T>
|
||||
{
|
||||
Field field;
|
||||
Object widget;
|
||||
int width = 0;
|
||||
int max;
|
||||
Map.Entry<EditBox, Component> error;
|
||||
Object defaultValue;
|
||||
Object value;
|
||||
String tempValue;
|
||||
boolean inLimits = true;
|
||||
#if PRE_MC_1_19
|
||||
TranslatableComponent name;
|
||||
#else
|
||||
Component name;
|
||||
#endif
|
||||
int index;
|
||||
/** Hides the button */
|
||||
boolean hideOption = false;
|
||||
/** This asks if it is a button to goto a new screen */
|
||||
boolean screenButton = false;
|
||||
/** This is only called if button is true */
|
||||
String gotoScreen = "";
|
||||
String category;
|
||||
Class<T> varClass;
|
||||
|
||||
|
||||
@Deprecated
|
||||
boolean fileComment = false;
|
||||
}
|
||||
|
||||
private static Path configFilePath;
|
||||
|
||||
|
||||
|
||||
public static void init(Class<?> config)
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
configFilePath = mc.gameDirectory.toPath().resolve("config").resolve(MOD_NAME + ".toml");
|
||||
|
||||
initNestedClass(config, "");
|
||||
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.field.isAnnotationPresent(ConfigAnnotations.Entry.class)) {
|
||||
try {
|
||||
info.value = info.field.get(null);
|
||||
info.tempValue = info.value.toString();
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadFromFile();
|
||||
}
|
||||
|
||||
private static void initNestedClass(Class<?> config, String category)
|
||||
{
|
||||
for (Field field : config.getFields())
|
||||
{
|
||||
EntryInfo info = new EntryInfo();
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.Entry.class) || field.isAnnotationPresent(ConfigAnnotations.Comment.class) || field.isAnnotationPresent(ConfigAnnotations.ScreenEntry.class))
|
||||
{
|
||||
// If putting in your own mod then put your own check for server sided
|
||||
info.category = category;
|
||||
if (!LodCommonMain.serverSided)
|
||||
initClient(field, info, category);
|
||||
}
|
||||
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.Entry.class))
|
||||
{
|
||||
entryMap.put((!category.isEmpty() ? category + "." : "") + field.getName(), info);
|
||||
info.varClass = field.getType();
|
||||
try
|
||||
{
|
||||
info.defaultValue = field.get(null);
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.ScreenEntry.class))
|
||||
initNestedClass(field.getType(), (!category.isEmpty() ? category + "." : "") + field.getName());
|
||||
|
||||
// File comment (WILL BE REMOVED SOON)
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.FileComment.class)) {
|
||||
entryMap.put((!category.isEmpty() ? category + "." : "") + field.getName(), info);
|
||||
info.fileComment = true;
|
||||
try
|
||||
{
|
||||
info.value = info.defaultValue = field.get(null);
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
|
||||
info.field = field;
|
||||
}
|
||||
}
|
||||
|
||||
/** This adds the buttons to the queue to be rendered */
|
||||
private static void initClient(Field field, EntryInfo info, String category)
|
||||
{
|
||||
Class<?> fieldClass = field.getType();
|
||||
ConfigAnnotations.Entry entry = field.getAnnotation(ConfigAnnotations.Entry.class);
|
||||
ConfigAnnotations.ScreenEntry screenEntry = field.getAnnotation(ConfigAnnotations.ScreenEntry.class);
|
||||
|
||||
if (entry != null)
|
||||
info.width = entry.width();
|
||||
else if (screenEntry != null)
|
||||
info.width = screenEntry.width();
|
||||
|
||||
if (entry != null)
|
||||
{
|
||||
if (!entry.name().equals(""))
|
||||
#if PRE_MC_1_19
|
||||
info.name = new TranslatableComponent(entry.name());
|
||||
#else
|
||||
info.name = Component.translatable(entry.name());
|
||||
#endif
|
||||
|
||||
if (fieldClass == int.class)
|
||||
{
|
||||
// For int
|
||||
textField(info, Integer::parseInt, INTEGER_ONLY_REGEX, entry.minValue(), entry.maxValue(), true);
|
||||
}
|
||||
else if (fieldClass == double.class)
|
||||
{
|
||||
// For double
|
||||
textField(info, Double::parseDouble, DECIMAL_ONLY_REGEX, entry.minValue(), entry.maxValue(), false);
|
||||
}
|
||||
else if (fieldClass == String.class || fieldClass == List.class)
|
||||
{
|
||||
// For string or list
|
||||
info.max = entry.maxValue() == Double.MAX_VALUE ? Integer.MAX_VALUE : (int) entry.maxValue();
|
||||
textField(info, String::length, null, Math.min(entry.minValue(), 0), Math.max(entry.maxValue(), 1), true);
|
||||
}
|
||||
else if (fieldClass == boolean.class)
|
||||
{
|
||||
// For boolean
|
||||
#if PRE_MC_1_19
|
||||
Function<Object, Component> func = value -> new TextComponent((Boolean) value ? "True" : "False").withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
#else
|
||||
Function<Object, Component> func = value -> Component.translatable((Boolean) value ? "True" : "False").withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
#endif
|
||||
info.widget = new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(button -> {
|
||||
info.value = !(Boolean) info.value;
|
||||
button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
}
|
||||
else if (fieldClass.isEnum())
|
||||
{
|
||||
// For enum
|
||||
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||
#if PRE_MC_1_19
|
||||
Function<Object, Component> func = value -> new TranslatableComponent(MOD_NAME + ".config." + "enum." + fieldClass.getSimpleName() + "." + info.value.toString());
|
||||
#else
|
||||
Function<Object, Component> func = value -> Component.translatable(MOD_NAME + ".config." + "enum." + fieldClass.getSimpleName() + "." + info.value.toString());
|
||||
#endif
|
||||
info.widget = new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(button -> {
|
||||
int index = values.indexOf(info.value) + 1;
|
||||
info.value = values.get(index >= values.size() ? 0 : index);
|
||||
button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
}
|
||||
}
|
||||
else if (screenEntry != null)
|
||||
{
|
||||
if (!screenEntry.name().equals(""))
|
||||
#if PRE_MC_1_19
|
||||
info.name = new TranslatableComponent(screenEntry.name());
|
||||
#else
|
||||
info.name = Component.translatable(screenEntry.name());
|
||||
#endif
|
||||
|
||||
|
||||
info.screenButton = true;
|
||||
info.gotoScreen = (!info.category.isEmpty() ? info.category + "." : "") + field.getName();
|
||||
}
|
||||
entries.add(info);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** creates a text field */
|
||||
private static void textField(EntryInfo info, Function<String, Number> func, Pattern pattern, double minValue, double maxValue, boolean cast)
|
||||
{
|
||||
boolean isNumber = pattern != null;
|
||||
info.widget = (BiFunction<EditBox, Button, Predicate<String>>) (editBox, button) -> stringValue ->
|
||||
{
|
||||
stringValue = stringValue.trim();
|
||||
if (!(stringValue.isEmpty() || !isNumber || pattern.matcher(stringValue).matches()))
|
||||
return false;
|
||||
|
||||
Number value = 0;
|
||||
boolean inLimits = false;
|
||||
info.error = null;
|
||||
if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals("."))
|
||||
{
|
||||
value = func.apply(stringValue);
|
||||
inLimits = value.doubleValue() >= minValue && value.doubleValue() <= maxValue;
|
||||
#if PRE_MC_1_19
|
||||
info.error = inLimits ? null : new AbstractMap.SimpleEntry<>(editBox, new TextComponent(value.doubleValue() < minValue ?
|
||||
#else
|
||||
info.error = inLimits ? null : new AbstractMap.SimpleEntry<>(editBox, Component.translatable(value.doubleValue() < minValue ?
|
||||
#endif
|
||||
"§cMinimum " + "length" + (cast ? " is " + (int) minValue : " is " + minValue) :
|
||||
"§cMaximum " + "length" + (cast ? " is " + (int) maxValue : " is " + maxValue)));
|
||||
}
|
||||
|
||||
info.tempValue = stringValue;
|
||||
editBox.setTextColor(inLimits ? 0xFFFFFFFF : 0xFFFF7777);
|
||||
info.inLimits = inLimits;
|
||||
button.active = entries.stream().allMatch(e -> e.inLimits);
|
||||
|
||||
|
||||
if (inLimits && info.field.getType() != List.class)
|
||||
{
|
||||
info.value = value;
|
||||
}
|
||||
else if (inLimits)
|
||||
{
|
||||
if (((List<String>) info.value).size() == info.index)
|
||||
((List<String>) info.value).add("");
|
||||
((List<String>) info.value).set(info.index, Arrays.stream(info.tempValue.replace("[", "").replace("]", "").split(", ")).collect(Collectors.toList()).get(0));
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// File Handling //
|
||||
//===============//
|
||||
|
||||
/** Grabs what is in the config and puts it in modid.toml */
|
||||
public static void saveToFile()
|
||||
{
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configFilePath.toFile()).build();
|
||||
|
||||
// First try to create a config file
|
||||
try {
|
||||
if (!configFilePath.getParent().toFile().exists())
|
||||
Files.createDirectory(configFilePath.getParent());
|
||||
if (!Files.exists(configFilePath))
|
||||
Files.createFile(configFilePath);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.info("Failed creating config file for " + MOD_NAME_READABLE + " at the path [" + configFilePath.toString() + "].");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
loadFileWithErrorCheck(config);
|
||||
|
||||
|
||||
// Just put this here for the future
|
||||
config.set("_version", 1);
|
||||
|
||||
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.field.isAnnotationPresent(ConfigAnnotations.Entry.class)) {
|
||||
editSingleOption.saveOption(info, config);
|
||||
|
||||
if (editSingleOption.getEntry((info.category.isEmpty() ? "" : info.category + ".") + "_" + info.field.getName()) != null)
|
||||
config.setComment((info.category.isEmpty() ? "" : info.category + ".") + info.field.getName(), String.valueOf(editSingleOption.getEntry((info.category.isEmpty() ? "" : info.category + ".") + "_" + info.field.getName()).defaultValue));
|
||||
}
|
||||
}
|
||||
|
||||
config.save();
|
||||
config.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs what is in modid.toml and puts it into the config
|
||||
* If the file doesn't exist then it runs saveToFile
|
||||
*/
|
||||
public static void loadFromFile()
|
||||
{
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configFilePath.toFile()).autosave().build();
|
||||
|
||||
// First checks if the config file was already made
|
||||
if (!Files.exists(configFilePath)) {
|
||||
LOGGER.info("Config file not found for " + MOD_NAME_READABLE + ". Creating config...");
|
||||
saveToFile();
|
||||
return;
|
||||
}
|
||||
|
||||
loadFileWithErrorCheck(config);
|
||||
|
||||
|
||||
// Just put this here for the future
|
||||
config.set("_version", 1);
|
||||
|
||||
|
||||
// Puts everything into its variable
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.field.isAnnotationPresent(ConfigAnnotations.Entry.class)) {
|
||||
editSingleOption.loadOption(info, config);
|
||||
|
||||
// File comments (WILL REMOVE SOON)
|
||||
if (editSingleOption.getEntry((info.category.isEmpty() ? "" : info.category + ".") + "_" + info.field.getName()) != null)
|
||||
config.setComment((info.category.isEmpty() ? "" : info.category + ".") + info.field.getName(), String.valueOf(editSingleOption.getEntry((info.category.isEmpty() ? "" : info.category + ".") + "_" + info.field.getName()).defaultValue));
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
}
|
||||
|
||||
public static class editSingleOption {
|
||||
/** Get the entry info of an item using its string name */
|
||||
public static EntryInfo getEntry(String name)
|
||||
{
|
||||
return entryMap.get(name);
|
||||
}
|
||||
|
||||
/** Save a single item using its string name */
|
||||
public static void saveOption(String name)
|
||||
{
|
||||
saveOption(entryMap.get(name));
|
||||
}
|
||||
|
||||
/** Saves a single item using entry info */
|
||||
public static void saveOption(EntryInfo info)
|
||||
{
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configFilePath.toFile()).autosave().build();
|
||||
|
||||
loadFileWithErrorCheck(config);
|
||||
|
||||
saveOption(info, config);
|
||||
|
||||
config.close();
|
||||
}
|
||||
|
||||
/** Saves a single item using its entry info and its config builder */
|
||||
public static void saveOption(EntryInfo info, CommentedFileConfig config)
|
||||
{
|
||||
config.set((info.category.isEmpty() ? "" : info.category + ".") + info.field.getName(), info.value);
|
||||
}
|
||||
|
||||
/** Load a single item using its string name */
|
||||
public static void loadOption(String name)
|
||||
{
|
||||
loadOption(entryMap.get(name));
|
||||
}
|
||||
|
||||
/** Load a single item using entry info */
|
||||
public static void loadOption(EntryInfo info)
|
||||
{
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configFilePath.toFile()).autosave().build();
|
||||
|
||||
loadFileWithErrorCheck(config);
|
||||
|
||||
loadOption(info, config);
|
||||
|
||||
config.close();
|
||||
}
|
||||
|
||||
/** Loads a single item using its entry info and its config builder */
|
||||
public static void loadOption(EntryInfo info, CommentedFileConfig config)
|
||||
{
|
||||
String itemPath = (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName();
|
||||
if (config.contains(itemPath)) {
|
||||
if (info.field.getType().isEnum()) {
|
||||
try {
|
||||
info.value = config.getEnum(itemPath, info.varClass);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
info.value = config.get(itemPath);
|
||||
} else
|
||||
config.set(itemPath, info.value);
|
||||
|
||||
try {
|
||||
info.field.set(null, info.value);
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Dose config.load(); but with error checking to avoid crashes */
|
||||
public static void loadFileWithErrorCheck(CommentedFileConfig config) {
|
||||
try {
|
||||
config.load();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("Error loading config for " + MOD_NAME_READABLE + " at the path [" + configFilePath.toString() + "].");
|
||||
LOGGER.info("Creating a new config...");
|
||||
try {
|
||||
Files.deleteIfExists(configFilePath);
|
||||
saveToFile();
|
||||
} catch (Exception f) {
|
||||
LOGGER.info("Failed creating config file for " + MOD_NAME_READABLE + " at the path [" + configFilePath.toString() + "].");
|
||||
f.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// GUI handling //
|
||||
//==============//
|
||||
|
||||
public static Screen getScreen(Screen parent, String category)
|
||||
{
|
||||
return new ConfigScreen(parent, category);
|
||||
}
|
||||
|
||||
private static class ConfigScreen extends Screen
|
||||
{
|
||||
protected ConfigScreen(Screen parent, String category)
|
||||
{
|
||||
#if PRE_MC_1_19
|
||||
super(new TranslatableComponent(
|
||||
#else
|
||||
super(Component.translatable(
|
||||
#endif
|
||||
I18n.exists(MOD_NAME + ".config" + (category.isEmpty()? "." + category : "") + ".title") ?
|
||||
MOD_NAME + ".config.title" :
|
||||
MOD_NAME + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
|
||||
);
|
||||
this.parent = parent;
|
||||
this.category = category;
|
||||
this.translationPrefix = MOD_NAME + ".config.";
|
||||
}
|
||||
|
||||
private final String translationPrefix;
|
||||
private final Screen parent;
|
||||
private final String category;
|
||||
private ConfigListWidget list;
|
||||
private boolean reload = false;
|
||||
|
||||
// Real Time config update //
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
super.tick();
|
||||
}
|
||||
|
||||
|
||||
/** When you close it, it goes to the previous screen and saves */
|
||||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent);
|
||||
}
|
||||
|
||||
// addRenderableWidget in 1.17 and over
|
||||
// addButton in 1.16 and below
|
||||
private Button addBtn(Button button) {
|
||||
#if PRE_MC_1_17_1
|
||||
this.addButton(button);
|
||||
#else
|
||||
this.addRenderableWidget(button);
|
||||
#endif
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
super.init();
|
||||
if (!reload)
|
||||
loadFromFile();
|
||||
|
||||
addBtn(new Button(this.width / 2 - 154, this.height - 28, 150, 20, CommonComponents.GUI_CANCEL, button -> {
|
||||
loadFromFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(parent);
|
||||
}));
|
||||
Button done = addBtn(new Button(this.width / 2 + 4, this.height - 28, 150, 20, CommonComponents.GUI_DONE, (button) -> {
|
||||
saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(parent);
|
||||
}));
|
||||
|
||||
this.list = new ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, this.height - 32, 25);
|
||||
if (this.minecraft != null && this.minecraft.level != null)
|
||||
this.list.setRenderBackground(false);
|
||||
this.addWidget(this.list);
|
||||
for (EntryInfo info : entries)
|
||||
{
|
||||
if (info.category.matches(category) && !info.hideOption)
|
||||
{
|
||||
#if PRE_MC_1_19
|
||||
TranslatableComponent name = (info.name == null ? new TranslatableComponent(translationPrefix + (!info.category.isEmpty() ? info.category + "." : "") + info.field.getName()) : info.name);
|
||||
Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - info.width - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, new TextComponent("Reset").withStyle(ChatFormatting.RED), (button -> {
|
||||
#else
|
||||
Component name = (info.name == null ? Component.translatable(translationPrefix + (!info.category.isEmpty() ? info.category + "." : "") + info.field.getName()) : info.name);
|
||||
Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - info.width - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, Component.translatable("Reset").withStyle(ChatFormatting.RED), (button -> {
|
||||
#endif
|
||||
info.value = info.defaultValue;
|
||||
info.tempValue = info.defaultValue.toString();
|
||||
info.index = 0;
|
||||
this.reload = true;
|
||||
Objects.requireNonNull(minecraft).setScreen(this);
|
||||
}));
|
||||
|
||||
if (info.widget instanceof Map.Entry)
|
||||
{
|
||||
Map.Entry<Button.OnPress, Function<Object, Component>> widget = (Map.Entry<Button.OnPress, Function<Object, Component>>) info.widget;
|
||||
if (info.field.getType().isEnum())
|
||||
#if PRE_MC_1_19
|
||||
widget.setValue(value -> new TranslatableComponent(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString()));
|
||||
#else
|
||||
widget.setValue(value -> Component.translatable(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString()));
|
||||
#endif
|
||||
this.list.addButton(new Button(this.width - info.width - ConfigScreenConfigs.SpaceFromRightScreen, 0, info.width, 20, widget.getValue().apply(info.value), widget.getKey()), resetButton, null, name);
|
||||
}
|
||||
else if (info.field.getType() == List.class)
|
||||
{
|
||||
if (!reload)
|
||||
info.index = 0;
|
||||
EditBox widget = new EditBox(font, this.width - info.width - ConfigScreenConfigs.SpaceFromRightScreen, 0, info.width, 20, null);
|
||||
widget.setMaxLength(info.width);
|
||||
if (info.index < ((List<String>) info.value).size())
|
||||
widget.insertText((String.valueOf(((List<String>) info.value).get(info.index))));
|
||||
else
|
||||
widget.insertText("");
|
||||
Predicate<String> processor = ((BiFunction<EditBox, Button, Predicate<String>>) info.widget).apply(widget, done);
|
||||
widget.setFilter(processor);
|
||||
resetButton.setWidth(20);
|
||||
#if PRE_MC_1_19
|
||||
resetButton.setMessage(new TextComponent("R").withStyle(ChatFormatting.RED));
|
||||
Button cycleButton = new Button(this.width - 185, 0, 20, 20, new TextComponent(String.valueOf(info.index)).withStyle(ChatFormatting.GOLD), (button -> {
|
||||
#else
|
||||
resetButton.setMessage(Component.translatable("R").withStyle(ChatFormatting.RED));
|
||||
Button cycleButton = new Button(this.width - 185, 0, 20, 20, Component.translatable(String.valueOf(info.index)).withStyle(ChatFormatting.GOLD), (button -> {
|
||||
#endif
|
||||
((List<String>) info.value).remove("");
|
||||
this.reload = true;
|
||||
info.index = info.index + 1;
|
||||
if (info.index > ((List<String>) info.value).size())
|
||||
info.index = 0;
|
||||
Objects.requireNonNull(minecraft).setScreen(this);
|
||||
}));
|
||||
this.list.addButton(widget, resetButton, cycleButton, name);
|
||||
}
|
||||
else if (info.widget != null)
|
||||
{
|
||||
EditBox widget = new EditBox(font, this.width - info.width - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, info.width - 4, 20, null);
|
||||
widget.setMaxLength(info.width);
|
||||
widget.insertText(String.valueOf(info.value));
|
||||
Predicate<String> processor = ((BiFunction<EditBox, Button, Predicate<String>>) info.widget).apply(widget, done);
|
||||
widget.setFilter(processor);
|
||||
this.list.addButton(widget, resetButton, null, name);
|
||||
}
|
||||
else if (info.screenButton)
|
||||
{
|
||||
Button widget = new Button(this.width / 2 - info.width, this.height - 28, info.width * 2, 20, name, (button -> {
|
||||
saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(ConfigGui.getScreen(this, info.gotoScreen));
|
||||
}));
|
||||
this.list.addButton(widget, null, null, null);
|
||||
}
|
||||
else if (!info.fileComment)
|
||||
{
|
||||
this.list.addButton(null, null, null, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
|
||||
{
|
||||
this.renderBackground(matrices); // Renders background
|
||||
this.list.render(matrices, mouseX, mouseY, delta); // Render buttons
|
||||
drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title
|
||||
|
||||
// Render the tooltip only if it can find a tooltip in the language file
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.category.matches(category) && !info.hideOption) {
|
||||
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
|
||||
AbstractWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
|
||||
Component text = ButtonEntry.buttonsWithText.get(buttonWidget);
|
||||
#if PRE_MC_1_19
|
||||
TranslatableComponent name = new TranslatableComponent(this.translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName());
|
||||
#else
|
||||
Component name = Component.translatable(this.translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName());
|
||||
#endif
|
||||
String key = translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.field.getName() + ".@tooltip";
|
||||
|
||||
if (info.error != null && text.equals(name)) renderTooltip(matrices, (Component) info.error.getValue(), mouseX, mouseY);
|
||||
else if (I18n.exists(key) && (text != null && text.equals(name))) {
|
||||
List<Component> list = new ArrayList<>();
|
||||
for (String str : I18n.get(key).split("\n"))
|
||||
#if PRE_MC_1_19
|
||||
list.add(new TextComponent(str));
|
||||
#else
|
||||
list.add(Component.translatable(str));
|
||||
#endif
|
||||
renderComponentTooltip(matrices, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class ConfigListWidget extends ContainerObjectSelectionList<ButtonEntry>
|
||||
{
|
||||
Font textRenderer;
|
||||
|
||||
public ConfigListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m)
|
||||
{
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
textRenderer = minecraftClient.font;
|
||||
}
|
||||
|
||||
public void addButton(AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text)
|
||||
{
|
||||
this.addEntry(ButtonEntry.create(button, text, resetButton, indexButton));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowWidth()
|
||||
{
|
||||
return 10000;
|
||||
}
|
||||
|
||||
public Optional<AbstractWidget> getHoveredButton(double mouseX, double mouseY)
|
||||
{
|
||||
for (ButtonEntry buttonEntry : this.children())
|
||||
{
|
||||
if (buttonEntry.button != null && buttonEntry.button.isMouseOver(mouseX, mouseY))
|
||||
{
|
||||
return Optional.of(buttonEntry.button);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
|
||||
{
|
||||
private static final Font textRenderer = Minecraft.getInstance().font;
|
||||
public final AbstractWidget button;
|
||||
private final AbstractWidget resetButton;
|
||||
private final AbstractWidget indexButton;
|
||||
private final Component text;
|
||||
private final List<AbstractWidget> children = new ArrayList<>();
|
||||
public static final Map<AbstractWidget, Component> buttonsWithText = new HashMap<>();
|
||||
|
||||
private ButtonEntry(AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton)
|
||||
{
|
||||
buttonsWithText.put(button, text);
|
||||
this.button = button;
|
||||
this.resetButton = resetButton;
|
||||
this.text = text;
|
||||
this.indexButton = indexButton;
|
||||
if (button != null)
|
||||
children.add(button);
|
||||
if (resetButton != null)
|
||||
children.add(resetButton);
|
||||
if (indexButton != null)
|
||||
children.add(indexButton);
|
||||
}
|
||||
|
||||
public static ButtonEntry create(AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton)
|
||||
{
|
||||
return new ButtonEntry(button, text, resetButton, indexButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta)
|
||||
{
|
||||
if (button != null)
|
||||
{
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (resetButton != null)
|
||||
{
|
||||
resetButton.y = y;
|
||||
resetButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (indexButton != null)
|
||||
{
|
||||
indexButton.y = y;
|
||||
indexButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (text != null && (!text.getString().contains("spacer") || button != null))
|
||||
GuiComponent.drawString(matrices, textRenderer, text, 12, y + 5, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GuiEventListener> children()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
|
||||
// Only for 1.17 and over
|
||||
// Remove in 1.16 and below
|
||||
#if POST_MC_1_17_1
|
||||
@Override
|
||||
public List<? extends NarratableEntry> narratables()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
-966
@@ -1,966 +0,0 @@
|
||||
package com.seibel.lod.common.wrappers.config;
|
||||
|
||||
import com.seibel.lod.core.enums.config.*;
|
||||
import com.seibel.lod.core.enums.rendering.*;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.common.Config;
|
||||
|
||||
/**
|
||||
* This holds the config defaults and setters/getters
|
||||
* that should be hooked into the host mod loader (Fabric, Forge, etc.).
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 11-16-2021
|
||||
*/
|
||||
public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
|
||||
{
|
||||
public static final LodConfigWrapperSingleton INSTANCE = new LodConfigWrapperSingleton();
|
||||
|
||||
|
||||
private static final Client client = new Client();
|
||||
@Override
|
||||
public IClient client()
|
||||
{
|
||||
return client;
|
||||
}
|
||||
|
||||
public static class Client implements IClient
|
||||
{
|
||||
public final IGraphics graphics;
|
||||
public final IWorldGenerator worldGenerator;
|
||||
public final IMultiplayer multiplayer;
|
||||
public final IAdvanced advanced;
|
||||
|
||||
|
||||
@Override
|
||||
public IGraphics graphics()
|
||||
{
|
||||
return graphics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldGenerator worldGenerator()
|
||||
{
|
||||
return worldGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMultiplayer multiplayer() {
|
||||
return multiplayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAdvanced advanced()
|
||||
{
|
||||
return advanced;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getOptionsButton()
|
||||
{
|
||||
return Config.optionsButton;
|
||||
}
|
||||
@Override
|
||||
public void setOptionsButton(boolean newOptionsButton)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("optionsButton").value = newOptionsButton;
|
||||
ConfigGui.editSingleOption.saveOption("optionsButton");
|
||||
}
|
||||
|
||||
|
||||
//================//
|
||||
// Client Configs //
|
||||
//================//
|
||||
public Client()
|
||||
{
|
||||
graphics = new Graphics();
|
||||
worldGenerator = new WorldGenerator();
|
||||
multiplayer = new Multiplayer();
|
||||
advanced = new Advanced();
|
||||
}
|
||||
|
||||
|
||||
//==================//
|
||||
// Graphics Configs //
|
||||
//==================//
|
||||
public static class Graphics implements IGraphics
|
||||
{
|
||||
public final IQuality quality;
|
||||
public final IFogQuality fogQuality;
|
||||
public final IAdvancedGraphics advancedGraphics;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public IQuality quality()
|
||||
{
|
||||
return quality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFogQuality fogQuality()
|
||||
{
|
||||
return fogQuality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAdvancedGraphics advancedGraphics()
|
||||
{
|
||||
return advancedGraphics;
|
||||
}
|
||||
|
||||
|
||||
Graphics()
|
||||
{
|
||||
quality = new Quality();
|
||||
fogQuality = new FogQuality();
|
||||
advancedGraphics = new AdvancedGraphics();
|
||||
}
|
||||
|
||||
|
||||
public static class Quality implements IQuality
|
||||
{
|
||||
@Override
|
||||
public HorizontalResolution getDrawResolution()
|
||||
{
|
||||
return Config.Client.Graphics.Quality.drawResolution;
|
||||
}
|
||||
@Override
|
||||
public void setDrawResolution(HorizontalResolution newHorizontalResolution)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.drawResolution").value = newHorizontalResolution;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.drawResolution");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLodChunkRenderDistance()
|
||||
{
|
||||
return Config.Client.Graphics.Quality.lodChunkRenderDistance;
|
||||
}
|
||||
@Override
|
||||
public void setLodChunkRenderDistance(int newLodChunkRenderDistance)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.lodChunkRenderDistance").value = newLodChunkRenderDistance;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.lodChunkRenderDistance");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VerticalQuality getVerticalQuality()
|
||||
{
|
||||
return Config.Client.Graphics.Quality.verticalQuality;
|
||||
}
|
||||
@Override
|
||||
public void setVerticalQuality(VerticalQuality newVerticalQuality)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.verticalQuality").value = newVerticalQuality;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.verticalQuality");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHorizontalScale()
|
||||
{
|
||||
return Config.Client.Graphics.Quality.horizontalScale;
|
||||
}
|
||||
@Override
|
||||
public void setHorizontalScale(int newHorizontalScale)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.horizontalScale").value = newHorizontalScale;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.horizontalScale");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HorizontalQuality getHorizontalQuality()
|
||||
{
|
||||
return Config.Client.Graphics.Quality.horizontalQuality;
|
||||
}
|
||||
@Override
|
||||
public void setHorizontalQuality(HorizontalQuality newHorizontalQuality)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.horizontalQuality").value = newHorizontalQuality;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.horizontalQuality");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropoffQuality getDropoffQuality() {
|
||||
return Config.Client.Graphics.Quality.dropoffQuality;
|
||||
}
|
||||
@Override
|
||||
public void setDropoffQuality(DropoffQuality newDropoffQuality) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.dropoffQuality").value = newDropoffQuality;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.dropoffQuality");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLodBiomeBlending() {
|
||||
return Config.Client.Graphics.Quality.lodBiomeBlending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLodBiomeBlending(int newLodBiomeBlending) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.quality.lodBiomeBlending").value = newLodBiomeBlending;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.quality.lodBiomeBlending");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class FogQuality implements IFogQuality
|
||||
{
|
||||
public final IAdvancedFog advancedFog;
|
||||
|
||||
FogQuality()
|
||||
{
|
||||
advancedFog = new AdvancedFog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FogDistance getFogDistance()
|
||||
{
|
||||
return Config.Client.Graphics.FogQuality.fogDistance;
|
||||
}
|
||||
@Override
|
||||
public void setFogDistance(FogDistance newFogDistance)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.fogDistance").value = newFogDistance;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.fogDistance");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FogDrawMode getFogDrawMode()
|
||||
{
|
||||
return Config.Client.Graphics.FogQuality.fogDrawMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFogDrawMode(FogDrawMode setFogDrawMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.fogDrawMode").value = setFogDrawMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.fogDrawMode");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FogColorMode getFogColorMode()
|
||||
{
|
||||
return Config.Client.Graphics.FogQuality.fogColorMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFogColorMode(FogColorMode newFogColorMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.fogColorMode").value = newFogColorMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.fogColorMode");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getDisableVanillaFog()
|
||||
{
|
||||
return Config.Client.Graphics.FogQuality.disableVanillaFog;
|
||||
}
|
||||
@Override
|
||||
public void setDisableVanillaFog(boolean newDisableVanillaFog)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.disableVanillaFog").value = newDisableVanillaFog;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.disableVanillaFog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAdvancedFog advancedFog() {
|
||||
return advancedFog;
|
||||
}
|
||||
|
||||
public static class AdvancedFog implements IAdvancedFog {
|
||||
public final IHeightFog heightFog;
|
||||
|
||||
public AdvancedFog() {
|
||||
heightFog = new HeightFog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getFarFogStart() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogStart;
|
||||
}
|
||||
@Override
|
||||
public double getFarFogEnd() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogEnd;
|
||||
}
|
||||
@Override
|
||||
public double getFarFogMin() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogMin;
|
||||
}
|
||||
@Override
|
||||
public double getFarFogMax() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogMax;
|
||||
}
|
||||
@Override
|
||||
public FogSetting.FogType getFarFogType() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogType;
|
||||
}
|
||||
@Override
|
||||
public double getFarFogDensity() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.farFogDensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFarFogStart(double newFarFogStart) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogStart").value = newFarFogStart;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogStart");
|
||||
}
|
||||
@Override
|
||||
public void setFarFogEnd(double newFarFogEnd) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogEnd").value = newFarFogEnd;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogEnd");
|
||||
}
|
||||
@Override
|
||||
public void setFarFogMin(double newFarFogMin) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogMin").value = newFarFogMin;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogMin");
|
||||
}
|
||||
@Override
|
||||
public void setFarFogMax(double newFarFogMax) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogMax").value = newFarFogMax;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogMax");
|
||||
}
|
||||
@Override
|
||||
public void setFarFogType(FogSetting.FogType newFarFogType) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogType").value = newFarFogType;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogType");
|
||||
}
|
||||
@Override
|
||||
public void setFarFogDensity(double newFarFogDensity) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.farFogDensity").value = newFarFogDensity;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.farFogDensity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHeightFog heightFog() {
|
||||
return heightFog;
|
||||
}
|
||||
|
||||
public static class HeightFog implements IHeightFog {
|
||||
|
||||
@Override
|
||||
public HeightFogMixMode getHeightFogMixMode() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogMixMode;
|
||||
}
|
||||
@Override
|
||||
public HeightFogMode getHeightFogMode() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogMode;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogHeight() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogHeight;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogStart() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogStart;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogEnd() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogEnd;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogMin() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogMin;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogMax() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogMax;
|
||||
}
|
||||
@Override
|
||||
public FogSetting.FogType getHeightFogType() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogType;
|
||||
}
|
||||
@Override
|
||||
public double getHeightFogDensity() {
|
||||
return Config.Client.Graphics.FogQuality.AdvancedFog.heightFog.heightFogDensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeightFogMixMode(HeightFogMixMode newHeightFogMixMode) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogMixMode").value = newHeightFogMixMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogMixMode");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogMode(HeightFogMode newHeightFogMode) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogMode").value = newHeightFogMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogMode");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogHeight(double newHeightFogHeight) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogHeight").value = newHeightFogHeight;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogHeight");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogStart(double newHeightFogStart) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogStart").value = newHeightFogStart;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogStart");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogEnd(double newHeightFogEnd) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogEnd").value = newHeightFogEnd;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogEnd");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogMin(double newHeightFogMin) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogMin").value = newHeightFogMin;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogMin");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogMax(double newHeightFogMax) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogMax").value = newHeightFogMax;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogMax");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogType(FogSetting.FogType newHeightFogType) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogType").value = newHeightFogType;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogType");
|
||||
}
|
||||
@Override
|
||||
public void setHeightFogDensity(double newHeightFogDensity) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.fogQuality.advancedFog.heightFog.heightFogDensity").value = newHeightFogDensity;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.fogQuality.advancedFog.heightFog.heightFogDensity");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class AdvancedGraphics implements IAdvancedGraphics
|
||||
{
|
||||
@Override
|
||||
public boolean getDisableDirectionalCulling()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.disableDirectionalCulling;
|
||||
}
|
||||
@Override
|
||||
public void setDisableDirectionalCulling(boolean newDisableDirectionalCulling)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.disableDirectionalCulling").value = newDisableDirectionalCulling;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.disableDirectionalCulling");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VanillaOverdraw getVanillaOverdraw()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.vanillaOverdraw;
|
||||
}
|
||||
@Override
|
||||
public void setVanillaOverdraw(VanillaOverdraw newVanillaOverdraw)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.vanillaOverdraw").value = newVanillaOverdraw;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.vanillaOverdraw");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOverdrawOffset() {
|
||||
return Config.Client.Graphics.AdvancedGraphics.overdrawOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverdrawOffset(int newOverdrawOffset) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.overdrawOffset").value = newOverdrawOffset;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.overdrawOffset");
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public int getBacksideCullingRange()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.backsideCullingRange;
|
||||
}
|
||||
@Override
|
||||
public void setBacksideCullingRange(int newBacksideCullingRange)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.backsideCullingRange").value = newBacksideCullingRange;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.backsideCullingRange");
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean getUseExtendedNearClipPlane()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.useExtendedNearClipPlane;
|
||||
}
|
||||
@Override
|
||||
public void setUseExtendedNearClipPlane(boolean newUseExtendedNearClipPlane)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.useExtendedNearClipPlane").value = newUseExtendedNearClipPlane;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.useExtendedNearClipPlane");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBrightnessMultiplier()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.brightnessMultiplier;
|
||||
}
|
||||
@Override
|
||||
public void setBrightnessMultiplier(double newBrightnessMultiplier)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.brightnessMultiplier").value = newBrightnessMultiplier;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.brightnessMultiplier");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSaturationMultiplier()
|
||||
{
|
||||
return Config.Client.Graphics.AdvancedGraphics.saturationMultiplier;
|
||||
}
|
||||
@Override
|
||||
public void setSaturationMultiplier(double newSaturationMultiplier)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.saturationMultiplier").value = newSaturationMultiplier;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.saturationMultiplier");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnableCaveCulling() {
|
||||
return Config.Client.Graphics.AdvancedGraphics.enableCaveCulling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnableCaveCulling(boolean newEnableCaveCulling) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.enableCaveCulling").value = newEnableCaveCulling;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.enableCaveCulling");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCaveCullingHeight() {
|
||||
return Config.Client.Graphics.AdvancedGraphics.caveCullingHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaveCullingHeight(int newCaveCullingHeight) {
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.caveCullingHeight").value = newCaveCullingHeight;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.caveCullingHeight");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEarthCurveRatio()
|
||||
{
|
||||
return (int) ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.earthCurveRatio").value;
|
||||
}
|
||||
@Override
|
||||
public void setEarthCurveRatio(int newEarthCurveRatio)
|
||||
{
|
||||
if (newEarthCurveRatio < 50) newEarthCurveRatio = 0;
|
||||
ConfigGui.editSingleOption.getEntry("client.graphics.advancedGraphics.earthCurveRatio").value = newEarthCurveRatio;
|
||||
ConfigGui.editSingleOption.saveOption("client.graphics.advancedGraphics.earthCurveRatio");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//========================//
|
||||
// WorldGenerator Configs //
|
||||
//========================//
|
||||
public static class WorldGenerator implements IWorldGenerator
|
||||
{
|
||||
@Override
|
||||
public GenerationPriority getGenerationPriority()
|
||||
{
|
||||
return Config.Client.WorldGenerator.generationPriority;
|
||||
}
|
||||
@Override
|
||||
public void setGenerationPriority(GenerationPriority newGenerationPriority)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.generationPriority").value = newGenerationPriority;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.generationPriority");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DistanceGenerationMode getDistanceGenerationMode()
|
||||
{
|
||||
return Config.Client.WorldGenerator.distanceGenerationMode;
|
||||
}
|
||||
@Override
|
||||
public void setDistanceGenerationMode(DistanceGenerationMode newDistanceGenerationMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.distanceGenerationMode").value = newDistanceGenerationMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.distanceGenerationMode");
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean getAllowUnstableFeatureGeneration()
|
||||
{
|
||||
return Config.Client.WorldGenerator.allowUnstableFeatureGeneration;
|
||||
}
|
||||
@Override
|
||||
public void setAllowUnstableFeatureGeneration(boolean newAllowUnstableFeatureGeneration)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.allowUnstableFeatureGeneration").value = newAllowUnstableFeatureGeneration;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.allowUnstableFeatureGeneration");
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public BlocksToAvoid getBlocksToAvoid()
|
||||
{
|
||||
return Config.Client.WorldGenerator.blocksToAvoid;
|
||||
}
|
||||
@Override
|
||||
public void setBlockToAvoid(BlocksToAvoid newBlockToAvoid)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.blocksToAvoid").value = newBlockToAvoid;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.blocksToAvoid");
|
||||
}
|
||||
@Override
|
||||
public boolean getEnableDistantGeneration()
|
||||
{
|
||||
return (boolean) ConfigGui.editSingleOption.getEntry("client.worldGenerator.enableDistantGeneration").value;
|
||||
}
|
||||
@Override
|
||||
public void setEnableDistantGeneration(boolean newEnableDistantGeneration)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.enableDistantGeneration").value = newEnableDistantGeneration;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.enableDistantGeneration");
|
||||
}
|
||||
@Override
|
||||
public LightGenerationMode getLightGenerationMode()
|
||||
{
|
||||
return Config.Client.WorldGenerator.lightGenerationMode;
|
||||
}
|
||||
@Override
|
||||
public void setLightGenerationMode(LightGenerationMode newLightGenerationMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.worldGenerator.lightGenerationMode").value = newLightGenerationMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.worldGenerator.lightGenerationMode");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=====================//
|
||||
// Multiplayer Configs //
|
||||
//=====================//
|
||||
public static class Multiplayer implements IMultiplayer
|
||||
{
|
||||
@Override
|
||||
public ServerFolderNameMode getServerFolderNameMode()
|
||||
{
|
||||
return Config.Client.Multiplayer.serverFolderNameMode;
|
||||
}
|
||||
@Override
|
||||
public void setServerFolderNameMode(ServerFolderNameMode newServerFolderNameMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.multiplayer.serverFolderNameMode").value = newServerFolderNameMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.multiplayer.serverFolderNameMode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMultiDimensionRequiredSimilarity()
|
||||
{
|
||||
return Config.Client.Multiplayer.multiDimensionRequiredSimilarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiDimensionRequiredSimilarity(double newMultiDimensionMinimumSimilarityPercent)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.multiplayer.multiDimensionMinimumSimilarityPercent").value = newMultiDimensionMinimumSimilarityPercent;
|
||||
ConfigGui.editSingleOption.saveOption("client.multiplayer.multiDimensionMinimumSimilarityPercent");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================//
|
||||
// AdvancedModOptions Configs //
|
||||
//============================//
|
||||
public static class Advanced implements IAdvanced
|
||||
{
|
||||
public final IThreading threading;
|
||||
public final IDebugging debugging;
|
||||
public final IBuffers buffers;
|
||||
|
||||
|
||||
@Override
|
||||
public IThreading threading()
|
||||
{
|
||||
return threading;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IDebugging debugging()
|
||||
{
|
||||
return debugging;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBuffers buffers()
|
||||
{
|
||||
return buffers;
|
||||
}
|
||||
|
||||
|
||||
public Advanced()
|
||||
{
|
||||
threading = new Threading();
|
||||
debugging = new Debugging();
|
||||
buffers = new Buffers();
|
||||
}
|
||||
|
||||
public static class Threading implements IThreading
|
||||
{
|
||||
@Override
|
||||
public double getNumberOfWorldGenerationThreads()
|
||||
{
|
||||
return Config.Client.Advanced.Threading.numberOfWorldGenerationThreads;
|
||||
}
|
||||
@Override
|
||||
public void setNumberOfWorldGenerationThreads(double newNumberOfWorldGenerationThreads)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.threading.numberOfWorldGenerationThreads").value = newNumberOfWorldGenerationThreads;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.threading.numberOfWorldGenerationThreads");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNumberOfBufferBuilderThreads()
|
||||
{
|
||||
return Config.Client.Advanced.Threading.numberOfBufferBuilderThreads;
|
||||
}
|
||||
@Override
|
||||
public void setNumberOfBufferBuilderThreads(int newNumberOfWorldBuilderThreads)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.threading.numberOfBufferBuilderThreads").value = newNumberOfWorldBuilderThreads;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.threading.numberOfBufferBuilderThreads");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// Debug Options //
|
||||
//===============//
|
||||
public static class Debugging implements IDebugging
|
||||
{
|
||||
public final IDebugSwitch debugSwitch;
|
||||
|
||||
@Override
|
||||
public IDebugSwitch debugSwitch()
|
||||
{
|
||||
return debugSwitch;
|
||||
}
|
||||
|
||||
/* RendererType:
|
||||
* DEFAULT
|
||||
* DEBUG
|
||||
* DISABLED
|
||||
* */
|
||||
@Override
|
||||
public RendererType getRendererType() {
|
||||
return (RendererType) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.rendererType").value;
|
||||
}
|
||||
@Override
|
||||
public void setRendererType(RendererType newRenderType) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.rendererType").value = newRenderType;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.rendererType");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DebugMode getDebugMode()
|
||||
{
|
||||
return (DebugMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugMode").value;
|
||||
}
|
||||
@Override
|
||||
public void setDebugMode(DebugMode newDebugMode)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugMode").value = newDebugMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugMode");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getDebugKeybindingsEnabled()
|
||||
{
|
||||
return (boolean) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.enableDebugKeybindings").value;
|
||||
}
|
||||
@Override
|
||||
public void setDebugKeybindingsEnabled(boolean newEnableDebugKeybindings)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.enableDebugKeybindings").value = newEnableDebugKeybindings;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.enableDebugKeybindings");
|
||||
}
|
||||
|
||||
public Debugging()
|
||||
{
|
||||
debugSwitch = new DebugSwitch();
|
||||
}
|
||||
|
||||
public static class DebugSwitch implements IDebugSwitch {
|
||||
|
||||
/* The logging switches available:
|
||||
* WorldGenEvent
|
||||
* WorldGenPerformance
|
||||
* WorldGenLoadEvent
|
||||
* LodBuilderEvent
|
||||
* RendererBufferEvent
|
||||
* RendererGLEvent
|
||||
* FileReadWriteEvent
|
||||
* FileSubDimEvent
|
||||
* NetworkEvent //NOT IMPL YET
|
||||
*/
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogWorldGenEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogWorldGenEvent(LoggerMode newLogWorldGenEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenEvent").value = newLogWorldGenEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logWorldGenEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogWorldGenPerformance() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenPerformance").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogWorldGenPerformance(LoggerMode newLogWorldGenPerformance) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenPerformance").value = newLogWorldGenPerformance;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logWorldGenPerformance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogWorldGenLoadEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenLoadEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogWorldGenLoadEvent(LoggerMode newLogWorldGenLoadEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logWorldGenLoadEvent").value = newLogWorldGenLoadEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logWorldGenLoadEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogLodBuilderEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logLodBuilderEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogLodBuilderEvent(LoggerMode newLogLodBuilderEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logLodBuilderEvent").value = newLogLodBuilderEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logLodBuilderEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogRendererBufferEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logRendererBufferEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogRendererBufferEvent(LoggerMode newLogRendererBufferEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logRendererBufferEvent").value = newLogRendererBufferEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logRendererBufferEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogRendererGLEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logRendererGLEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogRendererGLEvent(LoggerMode newLogRendererGLEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logRendererGLEvent").value = newLogRendererGLEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logRendererGLEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogFileReadWriteEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logFileReadWriteEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogFileReadWriteEvent(LoggerMode newLogFileReadWriteEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logFileReadWriteEvent").value = newLogFileReadWriteEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logFileReadWriteEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogFileSubDimEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logFileSubDimEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogFileSubDimEvent(LoggerMode newLogFileSubDimEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logFileSubDimEvent").value = newLogFileSubDimEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logFileSubDimEvent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggerMode getLogNetworkEvent() {
|
||||
return (LoggerMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logNetworkEvent").value;
|
||||
}
|
||||
@Override
|
||||
public void setLogNetworkEvent(LoggerMode newLogNetworkEvent) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugSwitch.logNetworkEvent").value = newLogNetworkEvent;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.debugging.debugSwitch.logNetworkEvent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Buffers implements IBuffers
|
||||
{
|
||||
|
||||
@Override
|
||||
public GpuUploadMethod getGpuUploadMethod()
|
||||
{
|
||||
return Config.Client.Advanced.Buffers.gpuUploadMethod;
|
||||
}
|
||||
@Override
|
||||
public void setGpuUploadMethod(GpuUploadMethod newDisableVanillaFog)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.buffers.gpuUploadMethod").value = newDisableVanillaFog;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.buffers.gpuUploadMethod");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getGpuUploadPerMegabyteInMilliseconds()
|
||||
{
|
||||
return Config.Client.Advanced.Buffers.gpuUploadPerMegabyteInMilliseconds;
|
||||
}
|
||||
@Override
|
||||
public void setGpuUploadPerMegabyteInMilliseconds(int newMilliseconds) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.buffers.gpuUploadPerMegabyteInMilliseconds").value = newMilliseconds;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.buffers.gpuUploadPerMegabyteInMilliseconds");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BufferRebuildTimes getRebuildTimes()
|
||||
{
|
||||
return Config.Client.Advanced.Buffers.rebuildTimes;
|
||||
}
|
||||
@Override
|
||||
public void setRebuildTimes(BufferRebuildTimes newBufferRebuildTimes)
|
||||
{
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.buffers.newBufferRebuildTimes").value = newBufferRebuildTimes;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.buffers.newBufferRebuildTimes");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getLodOnlyMode() {
|
||||
return Config.Client.Advanced.lodOnlyMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLodOnlyMode(boolean newLodOnlyMode) {
|
||||
ConfigGui.editSingleOption.getEntry("client.advanced.buffers.lodOnlyMode").value = newLodOnlyMode;
|
||||
ConfigGui.editSingleOption.saveOption("client.advanced.buffers.lodOnlyMode");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// Logger (for debug stuff)
|
||||
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.file.ConfigFileHandling;
|
||||
import com.seibel.lod.core.config.types.AbstractConfigType;
|
||||
import com.seibel.lod.core.config.types.ConfigCategory;
|
||||
import com.seibel.lod.core.config.types.ConfigEntry;
|
||||
|
||||
// Uses https://github.com/TheElectronWill/night-config for toml (only for Fabric since Forge already includes this)
|
||||
|
||||
// Gets info from our own mod
|
||||
|
||||
import com.seibel.lod.core.config.*;
|
||||
|
||||
// Minecraft imports
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.seibel.lod.core.jar.updater.SelfUpdater;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.client.resources.language.I18n; // translation
|
||||
#if POST_MC_1_17_1
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
#endif
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Based upon TinyConfig but is highly modified
|
||||
* https://github.com/Minenash/TinyConfig
|
||||
*
|
||||
* Credits to Motschen
|
||||
*
|
||||
* @author coolGi
|
||||
* @version 4-28-2022
|
||||
*/
|
||||
// FLOATS DONT WORK WITH THIS
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class ClassicConfigGUI {
|
||||
/*
|
||||
This would be removed later on
|
||||
*/
|
||||
|
||||
|
||||
//==============//
|
||||
// Initializers //
|
||||
//==============//
|
||||
|
||||
// Some regexes to check if an input is valid
|
||||
private static final Pattern INTEGER_ONLY_REGEX = Pattern.compile("(-?[0-9]*)");
|
||||
private static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||
|
||||
private static class ConfigScreenConfigs {
|
||||
// This contains all the configs for the configs
|
||||
public static final int SpaceFromRightScreen = 10;
|
||||
public static final int ButtonWidthSpacing = 5;
|
||||
public static final int ResetButtonWidth = 40;
|
||||
}
|
||||
|
||||
/**
|
||||
* The terribly coded old stuff
|
||||
*/
|
||||
public static class EntryInfo {
|
||||
Object widget;
|
||||
Map.Entry<EditBox, Component> error;
|
||||
String tempValue;
|
||||
int index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* creates a text field
|
||||
*/
|
||||
private static void textField(AbstractConfigType info, Function<String, Number> func, Pattern pattern, boolean cast) {
|
||||
boolean isNumber = pattern != null;
|
||||
((EntryInfo) info.guiValue).widget = (BiFunction<EditBox, Button, Predicate<String>>) (editBox, button) -> stringValue ->
|
||||
{
|
||||
stringValue = stringValue.trim();
|
||||
if (!(stringValue.isEmpty() || !isNumber || pattern.matcher(stringValue).matches()))
|
||||
return false;
|
||||
|
||||
Number value = 0;
|
||||
((EntryInfo) info.guiValue).error = null;
|
||||
if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals(".")) {
|
||||
value = func.apply(stringValue);
|
||||
#if PRE_MC_1_19
|
||||
((EntryInfo) info.guiValue).error = ((ConfigEntry) info).isValid(value) == 0 ? null : new AbstractMap.SimpleEntry<>(editBox, new TextComponent(((ConfigEntry) info).isValid(value) == -1 ?
|
||||
#else
|
||||
((EntryInfo) info.guiValue).error = ((ConfigEntry) info).isValidMemoryAddress(value) == 0 ? null : new AbstractMap.SimpleEntry<>(editBox, Component.translatable(((ConfigEntry) info).isValidMemoryAddress(value) == -1 ?
|
||||
#endif
|
||||
"§cMinimum " + "length" + (cast ? " is " + (int) ((ConfigEntry) info).getMin() : " is " + ((ConfigEntry) info).getMin()) :
|
||||
"§cMaximum " + "length" + (cast ? " is " + (int) ((ConfigEntry) info).getMax() : " is " + ((ConfigEntry) info).getMax())));
|
||||
}
|
||||
|
||||
((EntryInfo) info.guiValue).tempValue = stringValue;
|
||||
editBox.setTextColor(((ConfigEntry) info).isValid(value) == 0 ? 0xFFFFFFFF : 0xFFFF7777);
|
||||
// button.active = entries.stream().allMatch(e -> e.inLimits);
|
||||
|
||||
|
||||
if (((ConfigEntry) info).isValid(value) == 0 && info.getType() != List.class) {
|
||||
if (!cast)
|
||||
((ConfigEntry) info).setWithoutSaving(value);
|
||||
else
|
||||
((ConfigEntry) info).setWithoutSaving(value.intValue());
|
||||
}
|
||||
// else if (((ConfigEntry) info).isValidMemoryAddress() == 0)
|
||||
// {
|
||||
// if (((List<String>) info.get()).size() == ((EntryInfo) info.guiValue).index)
|
||||
// info.set(((List<String>) info.get()).add(""));
|
||||
// info.set(((List<String>) info.get()).set(((EntryInfo) info.guiValue).index, Arrays.stream(((EntryInfo) info.guiValue).tempValue.replace("[", "").replace("]", "").split(", ")).collect(Collectors.toList()).get(0)));
|
||||
// }
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
//==============//
|
||||
// GUI handling //
|
||||
//==============//
|
||||
|
||||
/**
|
||||
* if you want to get this config gui's screen call this
|
||||
*/
|
||||
public static Screen getScreen(ConfigBase configBase, Screen parent, String category) {
|
||||
return new ConfigScreen(configBase, parent, category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pain
|
||||
*/
|
||||
private static class ConfigScreen extends Screen {
|
||||
protected ConfigScreen(ConfigBase configBase, Screen parent, String category) {
|
||||
#if PRE_MC_1_19
|
||||
super(new TranslatableComponent(
|
||||
#else
|
||||
super(Component.translatable(
|
||||
#endif
|
||||
I18n.exists(configBase.modID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
|
||||
configBase.modID + ".config.title" :
|
||||
configBase.modID + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
|
||||
);
|
||||
this.configBase = configBase;
|
||||
this.parent = parent;
|
||||
this.category = category;
|
||||
this.translationPrefix = configBase.modID + ".config.";
|
||||
}
|
||||
private final ConfigBase configBase;
|
||||
|
||||
private final String translationPrefix;
|
||||
private final Screen parent;
|
||||
private final String category;
|
||||
private ConfigListWidget list;
|
||||
private boolean reload = false;
|
||||
|
||||
// Real Time config update //
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When you close it, it goes to the previous screen and saves
|
||||
*/
|
||||
@Override
|
||||
public void onClose() {
|
||||
ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent);
|
||||
}
|
||||
|
||||
// addRenderableWidget in 1.17 and over
|
||||
// addButton in 1.16 and below
|
||||
private Button addBtn(Button button) {
|
||||
#if PRE_MC_1_17_1
|
||||
this.addButton(button);
|
||||
#else
|
||||
this.addRenderableWidget(button);
|
||||
#endif
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
if (!reload)
|
||||
ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
|
||||
|
||||
addBtn(new Button(this.width / 2 - 154, this.height - 28, 150, 20, CommonComponents.GUI_CANCEL, button -> {
|
||||
ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(parent);
|
||||
}));
|
||||
Button done = addBtn(new Button(this.width / 2 + 4, this.height - 28, 150, 20, CommonComponents.GUI_DONE, (button) -> {
|
||||
ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(parent);
|
||||
}));
|
||||
|
||||
this.list = new ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, this.height - 32, 25);
|
||||
if (this.minecraft != null && this.minecraft.level != null)
|
||||
this.list.setRenderBackground(false);
|
||||
this.addWidget(this.list);
|
||||
for (AbstractConfigType info : ConfigBase.INSTANCE.entries) {
|
||||
if (info.getCategory().matches(category) && info.getAppearance().showInGui) {
|
||||
initEntry(info, this.translationPrefix);
|
||||
#if PRE_MC_1_19
|
||||
TranslatableComponent name = new TranslatableComponent(translationPrefix + info.getNameWCategory());
|
||||
#else
|
||||
Component name = Component.translatable(translationPrefix + info.getNameWCategory());
|
||||
#endif
|
||||
if (ConfigEntry.class.isAssignableFrom(info.getClass())) {
|
||||
#if PRE_MC_1_19
|
||||
Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, new TextComponent("Reset").withStyle(ChatFormatting.RED), (button -> {
|
||||
#else
|
||||
Button resetButton = new Button(this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth, 0, ConfigScreenConfigs.ResetButtonWidth, 20, Component.translatable("Reset").withStyle(ChatFormatting.RED), (button -> {
|
||||
#endif
|
||||
((ConfigEntry) info).setWithoutSaving(((ConfigEntry) info).getDefaultValue());
|
||||
((EntryInfo) info.guiValue).index = 0;
|
||||
this.reload = true;
|
||||
Objects.requireNonNull(minecraft).setScreen(this);
|
||||
}));
|
||||
|
||||
if (((EntryInfo) info.guiValue).widget instanceof Map.Entry) {
|
||||
Map.Entry<Button.OnPress, Function<Object, Component>> widget = (Map.Entry<Button.OnPress, Function<Object, Component>>) ((EntryInfo) info.guiValue).widget;
|
||||
if (info.getType().isEnum())
|
||||
#if PRE_MC_1_19
|
||||
widget.setValue(value -> new TranslatableComponent(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString()));
|
||||
#else
|
||||
widget.setValue(value -> Component.translatable(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString()));
|
||||
#endif
|
||||
this.list.addButton(new Button(this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen, 0, 150, 20, widget.getValue().apply(info.get()), widget.getKey()), resetButton, null, name);
|
||||
} else if (((EntryInfo) info.guiValue).widget != null) {
|
||||
EditBox widget = new EditBox(font, this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, 150 - 4, 20, null);
|
||||
widget.setMaxLength(150);
|
||||
widget.insertText(String.valueOf(info.get()));
|
||||
Predicate<String> processor = ((BiFunction<EditBox, Button, Predicate<String>>) ((EntryInfo) info.guiValue).widget).apply(widget, done);
|
||||
widget.setFilter(processor);
|
||||
this.list.addButton(widget, resetButton, null, name);
|
||||
}
|
||||
} else if (ConfigCategory.class.isAssignableFrom(info.getClass())) {
|
||||
Button widget = new Button(this.width / 2 - 100, this.height - 28, 100 * 2, 20, name, (button -> {
|
||||
ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
|
||||
Objects.requireNonNull(minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, ((ConfigCategory) info).getDestination()));
|
||||
}));
|
||||
this.list.addButton(widget, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices); // Renders background
|
||||
this.list.render(matrices, mouseX, mouseY, delta); // Render buttons
|
||||
drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title
|
||||
if (SelfUpdater.deleteOldOnClose)
|
||||
drawString(matrices, font, new TranslatableComponent("lod.updater.waitingForClose"), 4, height-38, 0xFFFFFF);
|
||||
|
||||
// Render the tooltip only if it can find a tooltip in the language file
|
||||
for (AbstractConfigType info : ConfigBase.INSTANCE.entries) {
|
||||
if (info.getCategory().matches(category) && info.getAppearance().showInGui) {
|
||||
if (list.getHoveredButton(mouseX, mouseY).isPresent()) {
|
||||
AbstractWidget buttonWidget = list.getHoveredButton(mouseX, mouseY).get();
|
||||
Component text = ButtonEntry.buttonsWithText.get(buttonWidget);
|
||||
#if PRE_MC_1_19
|
||||
TranslatableComponent name = new TranslatableComponent(this.translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.getName());
|
||||
#else
|
||||
Component name = Component.translatable(this.translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.getName());
|
||||
#endif
|
||||
String key = translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.getName() + ".@tooltip";
|
||||
|
||||
if (((EntryInfo) info.guiValue).error != null && text.equals(name))
|
||||
renderTooltip(matrices, (Component) ((EntryInfo) info.guiValue).error.getValue(), mouseX, mouseY);
|
||||
else if (I18n.exists(key) && (text != null && text.equals(name))) {
|
||||
List<Component> list = new ArrayList<>();
|
||||
for (String str : I18n.get(key).split("\n"))
|
||||
#if PRE_MC_1_19
|
||||
list.add(new TextComponent(str));
|
||||
#else
|
||||
list.add(Component.translatable(str));
|
||||
#endif
|
||||
renderComponentTooltip(matrices, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static void initEntry(AbstractConfigType info, String translationPrefix) {
|
||||
info.guiValue = new EntryInfo();
|
||||
Class<?> fieldClass = info.getType();
|
||||
|
||||
if (ConfigEntry.class.isAssignableFrom(info.getClass())) {
|
||||
if (fieldClass == Integer.class) {
|
||||
// For int
|
||||
textField(info, Integer::parseInt, INTEGER_ONLY_REGEX, true);
|
||||
} else if (fieldClass == Double.class) {
|
||||
// For double
|
||||
textField(info, Double::parseDouble, DECIMAL_ONLY_REGEX, false);
|
||||
} else if (fieldClass == String.class || fieldClass == List.class) {
|
||||
// For string or list
|
||||
textField(info, String::length, null, true);
|
||||
} else if (fieldClass == Boolean.class) {
|
||||
// For boolean
|
||||
#if PRE_MC_1_19
|
||||
Function<Object, Component> func = value -> new TextComponent((Boolean) value ? "True" : "False").withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
#else
|
||||
Function<Object, Component> func = value -> Component.translatable((Boolean) value ? "True" : "False").withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
|
||||
#endif
|
||||
((EntryInfo) info.guiValue).widget = new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(button -> {
|
||||
((ConfigEntry) info).setWithoutSaving(!(Boolean) info.get());
|
||||
button.setMessage(func.apply(info.get()));
|
||||
}, func);
|
||||
}
|
||||
else if (fieldClass.isEnum())
|
||||
{
|
||||
// For enum
|
||||
List<?> values = Arrays.asList(info.getType().getEnumConstants());
|
||||
#if PRE_MC_1_19
|
||||
Function<Object, Component> func = value -> new TranslatableComponent(translationPrefix + "enum." + fieldClass.getSimpleName() + "." + info.get().toString());
|
||||
#else
|
||||
Function<Object, Component> func = value -> Component.translatable(translationPrefix + "enum." + fieldClass.getSimpleName() + "." + info.get().toString());
|
||||
#endif
|
||||
((EntryInfo) info.guiValue).widget = new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(button -> {
|
||||
int index = values.indexOf(info.get()) + 1;
|
||||
info.set(values.get(index >= values.size() ? 0 : index));
|
||||
button.setMessage(func.apply(info.get()));
|
||||
}, func);
|
||||
}
|
||||
} else if (ConfigCategory.class.isAssignableFrom(info.getClass())) {
|
||||
// if (!info.info.getName().equals(""))
|
||||
// info.name = new TranslatableComponent(info.info.getName());
|
||||
}
|
||||
// return info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class ConfigListWidget extends ContainerObjectSelectionList<ButtonEntry> {
|
||||
Font textRenderer;
|
||||
|
||||
public ConfigListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
textRenderer = minecraftClient.font;
|
||||
}
|
||||
|
||||
public void addButton(AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text) {
|
||||
this.addEntry(ButtonEntry.create(button, text, resetButton, indexButton));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowWidth() {
|
||||
return 10000;
|
||||
}
|
||||
|
||||
public Optional<AbstractWidget> getHoveredButton(double mouseX, double mouseY) {
|
||||
for (ButtonEntry buttonEntry : this.children()) {
|
||||
if (buttonEntry.button != null && buttonEntry.button.isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(buttonEntry.button);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry> {
|
||||
private static final Font textRenderer = Minecraft.getInstance().font;
|
||||
public final AbstractWidget button;
|
||||
private final AbstractWidget resetButton;
|
||||
private final AbstractWidget indexButton;
|
||||
private final Component text;
|
||||
private final List<AbstractWidget> children = new ArrayList<>();
|
||||
public static final Map<AbstractWidget, Component> buttonsWithText = new HashMap<>();
|
||||
|
||||
private ButtonEntry(AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton) {
|
||||
buttonsWithText.put(button, text);
|
||||
this.button = button;
|
||||
this.resetButton = resetButton;
|
||||
this.text = text;
|
||||
this.indexButton = indexButton;
|
||||
if (button != null)
|
||||
children.add(button);
|
||||
if (resetButton != null)
|
||||
children.add(resetButton);
|
||||
if (indexButton != null)
|
||||
children.add(indexButton);
|
||||
}
|
||||
|
||||
public static ButtonEntry create(AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton) {
|
||||
return new ButtonEntry(button, text, resetButton, indexButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
if (button != null) {
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (resetButton != null) {
|
||||
resetButton.y = y;
|
||||
resetButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (indexButton != null) {
|
||||
indexButton.y = y;
|
||||
indexButton.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
if (text != null && (!text.getString().contains("spacer") || button != null))
|
||||
GuiComponent.drawString(matrices, textRenderer, text, 12, y + 5, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GuiEventListener> children() {
|
||||
return children;
|
||||
}
|
||||
|
||||
// Only for 1.17 and over
|
||||
// Remove in 1.16 and below
|
||||
#if POST_MC_1_17_1
|
||||
@Override
|
||||
public List<? extends NarratableEntry> narratables() {
|
||||
return children;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.ConfigBase;
|
||||
import com.seibel.lod.core.config.gui.ConfigScreen;
|
||||
import com.seibel.lod.core.config.gui.JavaScreenHandlerScreen;
|
||||
import com.seibel.lod.core.config.gui.OpenGLConfigScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
public class GetConfigScreen {
|
||||
public static type useScreen = type.Classic;
|
||||
public static enum type {
|
||||
Classic,
|
||||
@Deprecated
|
||||
OpenGL, // This was jsut an attempt, it didn't work out, and we are going to change to javafx soon (as soon as that works)
|
||||
JavaFX;
|
||||
}
|
||||
|
||||
public static Screen getScreen(Screen parent) {
|
||||
return switch (useScreen) {
|
||||
case Classic -> ClassicConfigGUI.getScreen(ConfigBase.INSTANCE, parent, "client");
|
||||
case OpenGL -> MinecraftScreen.getScreen(parent, new OpenGLConfigScreen(), ModInfo.ID + ".title");
|
||||
// case JavaFX -> MinecraftScreen.getScreen(parent, new JavaScreenHandlerScreen(new JavaScreenHandlerScreen.ExampleScreen()), ModInfo.ID + ".title");
|
||||
case JavaFX -> MinecraftScreen.getScreen(parent, new JavaScreenHandlerScreen(new ConfigScreen()), ModInfo.ID + ".title");
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILangWrapper;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
|
||||
public class LangWrapper implements ILangWrapper {
|
||||
public static final LangWrapper INSTANCE = new LangWrapper();
|
||||
@Override
|
||||
public boolean langExists(String str) {
|
||||
return I18n.exists(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLang(String str) {
|
||||
return I18n.get(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.seibel.lod.core.config.gui.AbstractScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public class MinecraftScreen {
|
||||
public static Screen getScreen(Screen parent, AbstractScreen screen, String translationName) {
|
||||
return new ConfigScreenRenderer(parent, screen, translationName);
|
||||
}
|
||||
|
||||
private static class ConfigScreenRenderer extends Screen {
|
||||
private final Screen parent;
|
||||
private ConfigListWidget list;
|
||||
private AbstractScreen screen;
|
||||
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
|
||||
return new net.minecraft.network.chat.TranslatableComponent(str, args);
|
||||
}
|
||||
#else
|
||||
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
|
||||
return net.minecraft.network.chat.Component.translatable(str, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected ConfigScreenRenderer(Screen parent, AbstractScreen screen, String translationName) {
|
||||
super(translate(translationName));
|
||||
screen.minecraftWindow = Minecraft.getInstance().getWindow().getWindow();
|
||||
this.parent = parent;
|
||||
this.screen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init(); // Init Minecraft's screen
|
||||
Window mcWindow = this.minecraft.getWindow();
|
||||
screen.width = mcWindow.getWidth();
|
||||
screen.height = mcWindow.getHeight();
|
||||
screen.scaledWidth = this.width;
|
||||
screen.scaledHeight = this.height;
|
||||
screen.init(); // Init our own config screen
|
||||
|
||||
this.list = new ConfigListWidget(this.minecraft, this.width, this.height, 0, this.height, 25); // Select the area to tint
|
||||
if (this.minecraft != null && this.minecraft.level != null) // Check if in game
|
||||
this.list.setRenderBackground(false); // Disable from rendering
|
||||
this.addWidget(this.list); // Add the tint to the things to be rendered
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices); // Render background
|
||||
this.list.render(matrices, mouseX, mouseY, delta); // Renders the items in the render list (currently only used to tint background darker)
|
||||
|
||||
screen.mouseX = mouseX;
|
||||
screen.mouseY = mouseY;
|
||||
screen.render(delta); // Render everything on the main screen
|
||||
|
||||
super.render(matrices, mouseX, mouseY, delta); // Render the vanilla stuff (currently only used for the background and tint)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(Minecraft mc, int width, int height) {
|
||||
super.resize(mc, width, height); // Resize Minecraft's screen
|
||||
Window mcWindow = this.minecraft.getWindow();
|
||||
screen.width = mcWindow.getWidth();
|
||||
screen.height = mcWindow.getHeight();
|
||||
screen.scaledWidth = this.width;
|
||||
screen.scaledHeight = this.height;
|
||||
screen.onResize(); // Resize our screen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick(); // Tick Minecraft's screen
|
||||
screen.tick(); // Tick our screen
|
||||
if (screen.close) // If we decide to close the screen, then actually close the screen
|
||||
onClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
screen.onClose(); // Close our screen
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilesDrop(@NotNull List<Path> files) {
|
||||
screen.onFilesDrop(files);
|
||||
}
|
||||
|
||||
// For checking if it should close when you press the escape key
|
||||
@Override
|
||||
public boolean shouldCloseOnEsc() {
|
||||
return screen.shouldCloseOnEsc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigListWidget extends ContainerObjectSelectionList {
|
||||
public ConfigListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
-6
@@ -1,27 +1,26 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.config;
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.seibel.lod.common.wrappers.gui.updater;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.seibel.lod.common.wrappers.gui.ClassicConfigGUI;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.jar.JarUtils;
|
||||
import com.seibel.lod.core.jar.installer.MarkdownFormatter;
|
||||
import com.seibel.lod.core.jar.installer.ModrinthGetter;
|
||||
import com.seibel.lod.core.jar.updater.SelfUpdater;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.StringSplitter;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The screen that pops up if the mod has an update.
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
// TODO: After finishing the config, rewrite this in openGL as well
|
||||
// TODO: Make this
|
||||
public class ChangelogScreen extends Screen {
|
||||
private Screen parent;
|
||||
private String versionID;
|
||||
private List<String> changelog;
|
||||
private TextArea changelogArea;
|
||||
|
||||
|
||||
public ChangelogScreen(Screen parent, String versionID) {
|
||||
super(translate(ModInfo.ID + ".updater.title"));
|
||||
this.parent = parent;
|
||||
this.versionID = versionID;
|
||||
|
||||
this.changelog = new ArrayList<>();
|
||||
// Get the release changelog and split it by the new lines
|
||||
List<String> unwrappedChangelog =
|
||||
List.of(new MarkdownFormatter.MinecraftFormat().convertTo( // This formats markdown to minecraft's "§" characters
|
||||
ModrinthGetter.changeLogs.get(versionID)
|
||||
).split("\\n"));
|
||||
// Makes the words wrap around to not go off the screen
|
||||
for (String str: unwrappedChangelog) {
|
||||
this.changelog.addAll(
|
||||
MarkdownFormatter.splitString(str, 75)
|
||||
);
|
||||
}
|
||||
// Debugging
|
||||
// System.out.println(this.changelog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
|
||||
this.addBtn( // Close
|
||||
new Button(5, this.height - 25, 100, 20, translate(ModInfo.ID + ".general.back"), (btn) -> {
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
this.changelogArea = new TextArea(this.minecraft, this.width*2, this.height, 32, this.height - 32, 10);
|
||||
for (int i = 0; i < changelog.size(); i++) {
|
||||
this.changelogArea.addButton(new TextComponent(changelog.get(i)));
|
||||
// drawString(matrices, this.font, changelog.get(i), this.width / 2 - 175, this.height / 2 - 100 + i*10, 0xFFFFFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices); // Render background
|
||||
|
||||
// Set the scroll position to the mouse height relative to the screen
|
||||
this.changelogArea.setScrollAmount(
|
||||
((double) mouseY)/((double) this.height) * this.changelogArea.getMaxScroll()
|
||||
);
|
||||
|
||||
this.changelogArea.render(matrices, mouseX, mouseY, delta); // Render the changelog
|
||||
|
||||
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
||||
|
||||
drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
|
||||
}
|
||||
|
||||
|
||||
// addRenderableWidget in 1.17 and over
|
||||
// addButton in 1.16 and below
|
||||
private void addBtn(Button button) {
|
||||
#if PRE_MC_1_17_1
|
||||
this.addButton(button);
|
||||
#else
|
||||
this.addRenderableWidget(button);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
|
||||
return new net.minecraft.network.chat.TranslatableComponent(str, args);
|
||||
}
|
||||
#else
|
||||
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
|
||||
return net.minecraft.network.chat.Component.translatable(str, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static class TextArea extends ContainerObjectSelectionList<ButtonEntry> {
|
||||
Font textRenderer;
|
||||
|
||||
public TextArea(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
textRenderer = minecraftClient.font;
|
||||
}
|
||||
|
||||
public void addButton(Component text) {
|
||||
this.addEntry(ButtonEntry.create(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowWidth() {
|
||||
return 10000;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry> {
|
||||
private static final Font textRenderer = Minecraft.getInstance().font;
|
||||
private final Component text;
|
||||
private final List<AbstractWidget> children = new ArrayList<>();
|
||||
|
||||
private ButtonEntry(Component text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static ButtonEntry create(Component text) {
|
||||
return new ButtonEntry(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
GuiComponent.drawString(matrices, textRenderer, text, 12, y + 5, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GuiEventListener> children() {
|
||||
return children;
|
||||
}
|
||||
#if POST_MC_1_17_1
|
||||
@Override
|
||||
public List<? extends NarratableEntry> narratables() {
|
||||
return children;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.seibel.lod.common.wrappers.gui.updater;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.seibel.lod.common.wrappers.gui.TexturedButtonWidget;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.jar.JarUtils;
|
||||
import com.seibel.lod.core.jar.installer.ModrinthGetter;
|
||||
import com.seibel.lod.core.jar.updater.SelfUpdater;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ImageButton;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The screen that pops up if the mod has an update.
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
// TODO: After finishing the config, rewrite this in openGL as well
|
||||
// and also maybe add this suggestion https://discord.com/channels/881614130614767666/1035863487110467625/1035949054485594192
|
||||
public class UpdateModScreen extends Screen {
|
||||
private Screen parent;
|
||||
private String newVersionID;
|
||||
|
||||
|
||||
public UpdateModScreen(Screen parent, String newVersionID) {
|
||||
super(translate(ModInfo.ID + ".updater.title"));
|
||||
this.parent = parent;
|
||||
this.newVersionID = newVersionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
|
||||
try {
|
||||
// We cannot get assets from the root of the mod so we use this hack
|
||||
// TODO: Load the icon.png and logo.png in the mod initialise rather than here
|
||||
ResourceLocation logoLocation = new ResourceLocation(ModInfo.ID, "logo.png");
|
||||
Minecraft.getInstance().getTextureManager().register(
|
||||
logoLocation,
|
||||
new DynamicTexture(NativeImage.read(JarUtils.accessFile("logo.png")))
|
||||
);
|
||||
|
||||
|
||||
// Logo image
|
||||
this.addBtn(new ImageButton(
|
||||
// Where the button is on the screen
|
||||
this.width / 2 - 65, this.height / 2 - 110,
|
||||
// Width and height of the button
|
||||
130, 65,
|
||||
// Offset
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0, logoLocation, 130, 65,
|
||||
// Create the button and tell it where to go
|
||||
// For now it goes to the client option by default
|
||||
(buttonWidget) -> System.out.println("Nice, you found an easter egg :)"), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti)
|
||||
// Add a title to the button
|
||||
translate(ModInfo.ID + ".updater.title")
|
||||
));
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
|
||||
|
||||
this.addBtn(new TexturedButtonWidget(
|
||||
// Where the button is on the screen
|
||||
this.width / 2 - 97, this.height / 2 + 8,
|
||||
// Width and height of the button
|
||||
20, 20,
|
||||
// Offset
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0, new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"), 20, 20,
|
||||
// Create the button and tell it where to go
|
||||
// For now it goes to the client option by default
|
||||
(buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this, this.newVersionID)), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti)
|
||||
// Add a title to the button
|
||||
translate(ModInfo.ID + ".updater.title")
|
||||
));
|
||||
|
||||
|
||||
this.addBtn( // Update
|
||||
new Button(this.width / 2 - 75, this.height / 2 + 8, 150, 20, translate(ModInfo.ID + ".updater.update"), (btn) -> {
|
||||
SelfUpdater.deleteOldOnClose = true;
|
||||
SelfUpdater.updateMod();
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn( // Silent update
|
||||
new Button(this.width / 2 - 75, this.height / 2 + 30, 150, 20, translate(ModInfo.ID + ".updater.silent"), (btn) -> {
|
||||
Config.Client.AutoUpdater.promptForUpdate.set(false);
|
||||
SelfUpdater.updateMod();
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn( // Later (not now)
|
||||
new Button(this.width / 2 + 2, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.later"), (btn) -> {
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn( // Never
|
||||
new Button(this.width / 2 - 102, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.never"), (btn) -> {
|
||||
Config.Client.AutoUpdater.enableAutoUpdater.set(false);
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices); // Render background
|
||||
|
||||
|
||||
// Render the text's
|
||||
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text1"), this.width / 2, this.height / 2 - 35, 0xFFFFFF);
|
||||
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text2", ModInfo.VERSION, ModrinthGetter.releaseNames.get(this.newVersionID)), this.width / 2, this.height / 2 -20, 0x52FD52);
|
||||
|
||||
// TODO: add the tooltips for the buttons
|
||||
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
|
||||
|
||||
// TODO: Add tooltips
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// addRenderableWidget in 1.17 and over
|
||||
// addButton in 1.16 and below
|
||||
private void addBtn(Button button) {
|
||||
#if PRE_MC_1_17_1
|
||||
this.addButton(button);
|
||||
#else
|
||||
this.addRenderableWidget(button);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
|
||||
return new net.minecraft.network.chat.TranslatableComponent(str, args);
|
||||
}
|
||||
#else
|
||||
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
|
||||
return net.minecraft.network.chat.Component.translatable(str, args);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+57
-193
@@ -1,69 +1,54 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.minecraft;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.seibel.lod.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.enums.LodDirection;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.enums.ELodDirection;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkPosWrapper;
|
||||
import com.seibel.lod.common.wrappers.misc.LightMapWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.WorldWrapper;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.server.IntegratedServer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
#endif
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -72,8 +57,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author James Seibel
|
||||
* @version 3-5-2022
|
||||
*/
|
||||
public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
//@Environment(EnvType.CLIENT)
|
||||
public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecraftSharedWrapper
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
|
||||
|
||||
public static final MinecraftClientWrapper INSTANCE = new MinecraftClientWrapper();
|
||||
|
||||
public final Minecraft mc = Minecraft.getInstance();
|
||||
@@ -119,7 +107,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
//=================//
|
||||
|
||||
@Override
|
||||
public float getShade(LodDirection lodDirection) {
|
||||
public float getShade(ELodDirection lodDirection) {
|
||||
if (mc.level != null)
|
||||
{
|
||||
Direction mcDir = McObjectConverter.Convert(lodDirection);
|
||||
@@ -129,22 +117,15 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSinglePlayerServer()
|
||||
{
|
||||
return mc.hasSingleplayerServer();
|
||||
}
|
||||
public boolean hasSinglePlayerServer() { return mc.hasSingleplayerServer(); }
|
||||
@Override
|
||||
public boolean clientConnectedToDedicatedServer() { return mc.getCurrentServer() != null && !this.hasSinglePlayerServer(); }
|
||||
|
||||
@Override
|
||||
public String getCurrentServerName()
|
||||
{
|
||||
return mc.getCurrentServer().name;
|
||||
}
|
||||
public String getCurrentServerName() { return mc.getCurrentServer().name; }
|
||||
|
||||
@Override
|
||||
public String getCurrentServerIp()
|
||||
{
|
||||
return mc.getCurrentServer().ip;
|
||||
}
|
||||
public String getCurrentServerIp() { return mc.getCurrentServer().ip; }
|
||||
|
||||
@Override
|
||||
public String getCurrentServerVersion()
|
||||
@@ -152,21 +133,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
return mc.getCurrentServer().version.getString();
|
||||
}
|
||||
|
||||
/** Returns the dimension the player is currently in */
|
||||
@Override
|
||||
public IDimensionTypeWrapper getCurrentDimension()
|
||||
{
|
||||
if (mc.player != null)
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(mc.player.level.dimensionType());
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentDimensionId()
|
||||
{
|
||||
return LodUtil.getDimensionIDFromWorld(WorldWrapper.getWorldWrapper(mc.level));
|
||||
}
|
||||
|
||||
//=============//
|
||||
// Simple gets //
|
||||
//=============//
|
||||
@@ -183,26 +149,21 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosWrapper getPlayerBlockPos()
|
||||
public DhBlockPos getPlayerBlockPos()
|
||||
{
|
||||
BlockPos playerPos = getPlayer().blockPosition();
|
||||
return new BlockPosWrapper(playerPos.getX(), playerPos.getY(), playerPos.getZ());
|
||||
return new DhBlockPos(playerPos.getX(), playerPos.getY(), playerPos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkPosWrapper getPlayerChunkPos()
|
||||
public DhChunkPos getPlayerChunkPos()
|
||||
{
|
||||
#if PRE_MC_1_17_1
|
||||
ChunkPos playerPos = new ChunkPos(getPlayer().blockPosition());
|
||||
#else
|
||||
ChunkPos playerPos = getPlayer().chunkPosition();
|
||||
#endif
|
||||
return new ChunkPosWrapper(playerPos.x, playerPos.z);
|
||||
}
|
||||
|
||||
public Options getOptions()
|
||||
{
|
||||
return mc.options;
|
||||
return new DhChunkPos(playerPos.x, playerPos.z);
|
||||
}
|
||||
|
||||
public ModelManager getModelManager()
|
||||
@@ -210,77 +171,24 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
return mc.getModelManager();
|
||||
}
|
||||
|
||||
public ClientLevel getClientLevel()
|
||||
{
|
||||
return mc.level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldWrapper getWrappedServerWorld()
|
||||
{
|
||||
if (mc.level == null)
|
||||
return null;
|
||||
|
||||
DimensionType dimension = mc.level.dimensionType();
|
||||
IntegratedServer server = mc.getSingleplayerServer();
|
||||
|
||||
if (server == null)
|
||||
return null;
|
||||
|
||||
ServerLevel serverWorld = null;
|
||||
Iterable<ServerLevel> worlds = server.getAllLevels();
|
||||
for (ServerLevel world : worlds)
|
||||
{
|
||||
if (world.dimensionType() == dimension)
|
||||
{
|
||||
serverWorld = world;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return WorldWrapper.getWorldWrapper(serverWorld);
|
||||
}
|
||||
|
||||
public WorldWrapper getWrappedClientLevel()
|
||||
{
|
||||
return WorldWrapper.getWorldWrapper(mc.level);
|
||||
}
|
||||
|
||||
public WorldWrapper getWrappedServerLevel()
|
||||
{
|
||||
|
||||
if (mc.level == null)
|
||||
return null;
|
||||
DimensionType dimension = mc.level.dimensionType();
|
||||
IntegratedServer server = mc.getSingleplayerServer();
|
||||
if (server == null)
|
||||
return null;
|
||||
|
||||
Iterable<ServerLevel> worlds = server.getAllLevels();
|
||||
ServerLevel returnWorld = null;
|
||||
|
||||
for (ServerLevel world : worlds)
|
||||
{
|
||||
if (world.dimensionType() == dimension)
|
||||
{
|
||||
returnWorld = world;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return WorldWrapper.getWorldWrapper(returnWorld);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IWorldWrapper getWrappedClientWorld()
|
||||
public ILevelWrapper getWrappedClientWorld()
|
||||
{
|
||||
return WorldWrapper.getWorldWrapper(mc.level);
|
||||
if (mc.level == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ClientLevelWrapper.getWrapper(mc.level);
|
||||
}
|
||||
|
||||
/** Please move over to getInstallationDirectory() */
|
||||
@Deprecated
|
||||
@Override
|
||||
public File getGameDirectory()
|
||||
{
|
||||
return mc.gameDirectory;
|
||||
return getInstallationDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -290,74 +198,19 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
profilerWrapper = new ProfilerWrapper(mc.getProfiler());
|
||||
else if (mc.getProfiler() != profilerWrapper.profiler)
|
||||
profilerWrapper.profiler = mc.getProfiler();
|
||||
|
||||
return profilerWrapper; }
|
||||
|
||||
public ClientPacketListener getConnection()
|
||||
{
|
||||
return mc.getConnection();
|
||||
}
|
||||
|
||||
public GameRenderer getGameRenderer()
|
||||
{
|
||||
return mc.gameRenderer;
|
||||
}
|
||||
|
||||
public Entity getCameraEntity()
|
||||
{
|
||||
return mc.cameraEntity;
|
||||
}
|
||||
|
||||
public Window getWindow()
|
||||
{
|
||||
return mc.getWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSkyDarken(float partialTicks)
|
||||
{
|
||||
return mc.level.getSkyDarken(partialTicks);
|
||||
}
|
||||
|
||||
public IntegratedServer getSinglePlayerServer()
|
||||
{
|
||||
return mc.getSingleplayerServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean connectedToServer()
|
||||
{
|
||||
return mc.getCurrentServer() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerSkylight() {
|
||||
if (mc.level == null) return -1;
|
||||
if (mc.player == null) return -1;
|
||||
if (mc.player.blockPosition() == null) return -1;
|
||||
return mc.level.getBrightness(LightLayer.SKY, mc.player.blockPosition());
|
||||
}
|
||||
|
||||
public ServerData getCurrentServer()
|
||||
{
|
||||
return mc.getCurrentServer();
|
||||
}
|
||||
|
||||
public LevelRenderer getLevelRenderer()
|
||||
{
|
||||
return mc.levelRenderer;
|
||||
return profilerWrapper;
|
||||
}
|
||||
|
||||
/** Returns all worlds available to the server */
|
||||
@Override
|
||||
public ArrayList<IWorldWrapper> getAllServerWorlds()
|
||||
public ArrayList<ILevelWrapper> getAllServerWorlds()
|
||||
{
|
||||
ArrayList<IWorldWrapper> worlds = new ArrayList<IWorldWrapper>();
|
||||
ArrayList<ILevelWrapper> worlds = new ArrayList<ILevelWrapper>();
|
||||
|
||||
Iterable<ServerLevel> serverWorlds = mc.getSingleplayerServer().getAllLevels();
|
||||
for (ServerLevel world : serverWorlds)
|
||||
{
|
||||
worlds.add(WorldWrapper.getWorldWrapper(world));
|
||||
worlds.add(ServerLevelWrapper.getWrapper(world));
|
||||
}
|
||||
|
||||
return worlds;
|
||||
@@ -371,7 +224,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
#if PRE_MC_1_19
|
||||
getPlayer().sendMessage(new TextComponent(string), getPlayer().getUUID());
|
||||
#else
|
||||
getPlayer().sendSystemMessage(Component.translatable(string));
|
||||
getPlayer().sendSystemMessage(net.minecraft.network.chat.Component.translatable(string));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -386,13 +239,24 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
@Override
|
||||
public void crashMinecraft(String errorMessage, Throwable exception)
|
||||
{
|
||||
ApiShared.LOGGER.error(ModInfo.READABLE_NAME + " had the following error: [" + errorMessage + "]. Crashing Minecraft...");
|
||||
LOGGER.error(ModInfo.READABLE_NAME + " had the following error: [" + errorMessage + "]. Crashing Minecraft...");
|
||||
CrashReport report = new CrashReport(errorMessage, exception);
|
||||
Minecraft.crash(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOptionsObject()
|
||||
{
|
||||
return mc.options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDedicatedServer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public File getInstallationDirectory() {
|
||||
return mc.gameDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.seibel.lod.common.wrappers.minecraft;
|
||||
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
//@Environment(EnvType.SERVER)
|
||||
public class MinecraftDedicatedServerWrapper implements IMinecraftSharedWrapper {
|
||||
public static final MinecraftDedicatedServerWrapper INSTANCE = new MinecraftDedicatedServerWrapper();
|
||||
private MinecraftDedicatedServerWrapper() {}
|
||||
public DedicatedServer dedicatedServer = null;
|
||||
@Override
|
||||
public boolean isDedicatedServer() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public File getInstallationDirectory() {
|
||||
if (dedicatedServer == null)
|
||||
throw new IllegalStateException("Trying to get Installation Direction before Dedicated server complete initialization!");
|
||||
return dedicatedServer.getServerDirectory();
|
||||
}
|
||||
}
|
||||
+71
-40
@@ -1,61 +1,59 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.minecraft;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.common.wrappers.misc.LightMapWrapper;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.api.ClientApi;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.render.glObject.GLProxy;
|
||||
import com.seibel.lod.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
|
||||
import com.mojang.math.Vector3f;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
import com.seibel.lod.core.objects.math.Vec3d;
|
||||
import com.seibel.lod.core.objects.math.Vec3f;
|
||||
import com.seibel.lod.core.util.math.Mat4f;
|
||||
import com.seibel.lod.core.util.math.Vec3d;
|
||||
import com.seibel.lod.core.util.math.Vec3f;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IBCLibAccessor;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.WrapperFactory;
|
||||
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
@@ -64,12 +62,14 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
#if PRE_MC_1_17_1
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
#else
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
#endif
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
||||
/**
|
||||
@@ -79,30 +79,35 @@ import org.lwjgl.opengl.GL15;
|
||||
* @author James Seibel
|
||||
* @version 12-12-2021
|
||||
*/
|
||||
//@Environment(EnvType.CLIENT)
|
||||
public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
{
|
||||
public static final MinecraftRenderWrapper INSTANCE = new MinecraftRenderWrapper();
|
||||
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
|
||||
private static final Minecraft MC = Minecraft.getInstance();
|
||||
private static final GameRenderer GAME_RENDERER = MC.gameRenderer;
|
||||
private static final IWrapperFactory FACTORY = WrapperFactory.INSTANCE;
|
||||
|
||||
private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
|
||||
|
||||
public LightMapWrapper lightmap = null;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vec3f getLookAtVector()
|
||||
{
|
||||
Camera camera = GAME_RENDERER.getMainCamera();
|
||||
Camera camera = MC.gameRenderer.getMainCamera();
|
||||
Vector3f cameraDir = camera.getLookVector();
|
||||
return new Vec3f(cameraDir.x(), cameraDir.y(), cameraDir.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlockPosWrapper getCameraBlockPosition()
|
||||
public DhBlockPos getCameraBlockPosition()
|
||||
{
|
||||
Camera camera = GAME_RENDERER.getMainCamera();
|
||||
Camera camera = MC.gameRenderer.getMainCamera();
|
||||
BlockPos blockPos = camera.getBlockPosition();
|
||||
return new BlockPosWrapper(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
return new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,7 +119,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
@Override
|
||||
public Vec3d getCameraExactPosition()
|
||||
{
|
||||
Camera camera = GAME_RENDERER.getMainCamera();
|
||||
Camera camera = MC.gameRenderer.getMainCamera();
|
||||
Vec3 projectedView = camera.getPosition();
|
||||
|
||||
return new Vec3d(projectedView.x, projectedView.y, projectedView.z);
|
||||
@@ -124,9 +129,9 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
public Mat4f getDefaultProjectionMatrix(float partialTicks)
|
||||
{
|
||||
#if PRE_MC_1_17_1
|
||||
return McObjectConverter.Convert(GAME_RENDERER.getProjectionMatrix(GAME_RENDERER.getMainCamera(), partialTicks, true));
|
||||
return McObjectConverter.Convert(Minecraft.getInstance().gameRenderer.getProjectionMatrix(Minecraft.getInstance().gameRenderer.getMainCamera(), partialTicks, true));
|
||||
#else
|
||||
return McObjectConverter.Convert(GAME_RENDERER.getProjectionMatrix(GAME_RENDERER.getFov(GAME_RENDERER.getMainCamera(), partialTicks, true)));
|
||||
return McObjectConverter.Convert(MC.gameRenderer.getProjectionMatrix(MC.gameRenderer.getFov(MC.gameRenderer.getMainCamera(), partialTicks, true)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -142,12 +147,14 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
|
||||
@Override
|
||||
public Color getFogColor(float partialTicks) {
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib"))
|
||||
return ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).getFogColor(); // BCLib uses a different fog method so we need to use that instead if they are loaded
|
||||
|
||||
#if PRE_MC_1_17_1
|
||||
float[] colorValues = new float[4];
|
||||
GL15.glGetFloatv(GL15.GL_FOG_COLOR, colorValues);
|
||||
#else
|
||||
FogRenderer.setupColor(GAME_RENDERER.getMainCamera(), partialTicks, MC.level, 1, GAME_RENDERER.getDarkenWorldAmount(partialTicks));
|
||||
FogRenderer.setupColor(MC.gameRenderer.getMainCamera(), partialTicks, MC.level, 1, MC.gameRenderer.getDarkenWorldAmount(partialTicks));
|
||||
float[] colorValues = RenderSystem.getShaderFogColor();
|
||||
#endif
|
||||
return new Color(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
|
||||
@@ -170,7 +177,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
@Override
|
||||
public double getFov(float partialTicks)
|
||||
{
|
||||
return GAME_RENDERER.getFov(GAME_RENDERER.getMainCamera(), partialTicks, true);
|
||||
return MC.gameRenderer.getFov(MC.gameRenderer.getMainCamera(), partialTicks, true);
|
||||
}
|
||||
|
||||
/** Measured in chunks */
|
||||
@@ -188,12 +195,36 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
@Override
|
||||
public int getScreenWidth()
|
||||
{
|
||||
return MC.getWindow().getWidth();
|
||||
// alternate ways of getting the window's resolution,
|
||||
// using one of these methods may fix the optifine render resolution bug
|
||||
// TODO: test these once we can run with Optifine again
|
||||
// int[] heightArray = new int[1];
|
||||
// int[] widthArray = new int[1];
|
||||
//
|
||||
// long window = GLProxy.getInstance().minecraftGlContext;
|
||||
// GLFW.glfwGetWindowSize(window, widthArray, heightArray); // option 1
|
||||
// GLFW.glfwGetFramebufferSize(window, widthArray, heightArray); // option 2
|
||||
|
||||
|
||||
|
||||
int width = MC.getWindow().getWidth();
|
||||
if (OPTIFINE_ACCESSOR != null)
|
||||
{
|
||||
// TODO remove comment after testing:
|
||||
// this should fix the issue where different optifine render resolutions screw up the LOD rendering
|
||||
width *= OPTIFINE_ACCESSOR.getRenderResolutionMultiplier();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
@Override
|
||||
public int getScreenHeight()
|
||||
{
|
||||
return MC.getWindow().getHeight();
|
||||
int height = MC.getWindow().getHeight();
|
||||
if (OPTIFINE_ACCESSOR != null)
|
||||
{
|
||||
height *= OPTIFINE_ACCESSOR.getRenderResolutionMultiplier();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
private RenderTarget getRenderTarget() {
|
||||
@@ -224,14 +255,14 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
|
||||
public boolean usingBackupGetVanillaRenderedChunks = false;
|
||||
@Override
|
||||
public HashSet<AbstractChunkPosWrapper> getVanillaRenderedChunks() {
|
||||
ISodiumAccessor sodium = ModAccessorHandler.get(ISodiumAccessor.class);
|
||||
public HashSet<DhChunkPos> getVanillaRenderedChunks() {
|
||||
ISodiumAccessor sodium = ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
|
||||
if (sodium != null) {
|
||||
return sodium.getNormalRenderedChunks();
|
||||
}
|
||||
IOptifineAccessor optifine = ModAccessorHandler.get(IOptifineAccessor.class);
|
||||
IOptifineAccessor optifine = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
|
||||
if (optifine != null) {
|
||||
HashSet<AbstractChunkPosWrapper> pos = optifine.getNormalRenderedChunks();
|
||||
HashSet<DhChunkPos> pos = optifine.getNormalRenderedChunks();
|
||||
if (pos == null)
|
||||
pos = getMaximumRenderedChunks();
|
||||
return pos;
|
||||
@@ -247,7 +278,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
AABB chunkBoundingBox =
|
||||
#if PRE_MC_1_18_2 chunk.chunk.bb;
|
||||
#else chunk.chunk.getBoundingBox(); #endif
|
||||
return FACTORY.createChunkPos(Math.floorDiv((int) chunkBoundingBox.minX, 16),
|
||||
return new DhChunkPos(Math.floorDiv((int) chunkBoundingBox.minX, 16),
|
||||
Math.floorDiv((int) chunkBoundingBox.minZ, 16));
|
||||
}).collect(Collectors.toCollection(HashSet::new)));
|
||||
} catch (LinkageError e) {
|
||||
@@ -259,7 +290,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
"\u00A7eOverdraw prevention will be worse than normal.");
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
ApiShared.LOGGER.error("getVanillaRenderedChunks Error: ", e);
|
||||
LOGGER.error("getVanillaRenderedChunks Error: ", e);
|
||||
usingBackupGetVanillaRenderedChunks = true;
|
||||
}
|
||||
}
|
||||
@@ -274,7 +305,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
@Override
|
||||
public boolean isFogStateSpecial() {
|
||||
#if PRE_MC_1_17_1
|
||||
Camera camera = GAME_RENDERER.getMainCamera();
|
||||
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
|
||||
FluidState fluidState = camera.getFluidInCamera();
|
||||
Entity entity = camera.getEntity();
|
||||
boolean isUnderWater = (entity instanceof LivingEntity) && ((LivingEntity)entity).hasEffect(MobEffects.BLINDNESS);
|
||||
@@ -282,9 +313,9 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
isUnderWater |= fluidState.is(FluidTags.LAVA);
|
||||
return isUnderWater;
|
||||
#else
|
||||
Entity entity = GAME_RENDERER.getMainCamera().getEntity();
|
||||
Entity entity = MC.gameRenderer.getMainCamera().getEntity();
|
||||
boolean isBlind = (entity instanceof LivingEntity) && ((LivingEntity)entity).hasEffect(MobEffects.BLINDNESS);
|
||||
return GAME_RENDERER.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
|
||||
return MC.gameRenderer.getMainCamera().getFluidInCamera() != FogType.NONE || isBlind;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,308 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.world;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
#if POST_MC_1_19
|
||||
import net.minecraft.data.worldgen.biome.EndBiomes;
|
||||
import net.minecraft.data.worldgen.biome.NetherBiomes;
|
||||
#endif
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
|
||||
//This class wraps the minecraft BlockPos.Mutable (and BlockPos) class
|
||||
public class BiomeWrapper implements IBiomeWrapper
|
||||
{
|
||||
|
||||
public static final ConcurrentMap<Biome, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
|
||||
private final Biome biome;
|
||||
|
||||
public BiomeWrapper(Biome biome)
|
||||
{
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
static public IBiomeWrapper getBiomeWrapper(Biome biome)
|
||||
{
|
||||
//first we check if the biome has already been wrapped
|
||||
if(biomeWrapperMap.containsKey(biome) && biomeWrapperMap.get(biome) != null)
|
||||
return biomeWrapperMap.get(biome);
|
||||
|
||||
|
||||
//if it hasn't been created yet, we create it and save it in the map
|
||||
BiomeWrapper biomeWrapper = new BiomeWrapper(biome);
|
||||
biomeWrapperMap.put(biome, biomeWrapper);
|
||||
|
||||
//we return the newly created wrapper
|
||||
return biomeWrapper;
|
||||
}
|
||||
|
||||
/** Returns a color int for the given biome. */
|
||||
#if PRE_MC_1_19
|
||||
@Override
|
||||
public int getColorForBiome(int x, int z)
|
||||
{
|
||||
int colorInt;
|
||||
switch (biome.biomeCategory)
|
||||
{
|
||||
|
||||
case NETHER:
|
||||
colorInt = Blocks.NETHERRACK.defaultBlockState().getMaterial().getColor().col;
|
||||
break;
|
||||
|
||||
case THEEND:
|
||||
colorInt = Blocks.END_STONE.defaultBlockState().getMaterial().getColor().col;
|
||||
break;
|
||||
|
||||
case BEACH:
|
||||
case DESERT:
|
||||
colorInt = Blocks.SAND.defaultBlockState().getMaterial().getColor().col;
|
||||
break;
|
||||
|
||||
case EXTREME_HILLS:
|
||||
colorInt = Blocks.STONE.defaultMaterialColor().col;
|
||||
break;
|
||||
|
||||
case MUSHROOM:
|
||||
colorInt = MaterialColor.COLOR_LIGHT_GRAY.col;
|
||||
break;
|
||||
|
||||
case ICY:
|
||||
colorInt = Blocks.SNOW.defaultMaterialColor().col;
|
||||
break;
|
||||
|
||||
case MESA:
|
||||
colorInt = Blocks.RED_SAND.defaultMaterialColor().col;
|
||||
break;
|
||||
|
||||
case OCEAN:
|
||||
case RIVER:
|
||||
colorInt = biome.getWaterColor();
|
||||
break;
|
||||
|
||||
case NONE:
|
||||
case FOREST:
|
||||
case TAIGA:
|
||||
case JUNGLE:
|
||||
case PLAINS:
|
||||
case SAVANNA:
|
||||
case SWAMP:
|
||||
default:
|
||||
colorInt = biome.getGrassColor(x,z);
|
||||
//FIXME: Repair what James did - LeeTom
|
||||
// Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
|
||||
// tmp = tmp.darker();
|
||||
// colorInt = LodUtil.colorToInt(tmp);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return colorInt;
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
private static int _colorEnd(Biome b) {
|
||||
return Blocks.END_STONE.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorNether(Biome b) {
|
||||
return Blocks.NETHERRACK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorSand(Biome b) {
|
||||
return Blocks.SAND.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorStone(Biome b) {
|
||||
return Blocks.STONE.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorGravel(Biome b) {
|
||||
return Blocks.GRAVEL.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorDripStone(Biome b) {
|
||||
return Blocks.DRIPSTONE_BLOCK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorMoss(Biome b) {
|
||||
return Blocks.MOSS_BLOCK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorSculk(Biome b) {
|
||||
return Blocks.SCULK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorMushoom(Biome b) {
|
||||
return Blocks.MYCELIUM.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorBamboo(Biome b) {
|
||||
return Blocks.BAMBOO.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorSnow(Biome b) {
|
||||
return Blocks.SNOW.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorIce(Biome b) {
|
||||
return Blocks.ICE.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorRedSand(Biome b) {
|
||||
return Blocks.RED_SAND.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorSoulSand(Biome b) {
|
||||
return Blocks.SOUL_SAND.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorBasalt(Biome b) {
|
||||
return Blocks.BASALT.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorWater(Biome b) {
|
||||
return b.getWaterColor();
|
||||
}
|
||||
private static int _colorFoliage(Biome b) {
|
||||
return b.getFoliageColor();
|
||||
}
|
||||
|
||||
private static Biome _get(ResourceKey<Biome> r) {
|
||||
return BuiltinRegistries.BIOME.getOrThrow(r);
|
||||
}
|
||||
|
||||
//FIXME: THIS IS HELL!
|
||||
private static final ImmutableBiMap<Biome, Function<Biome, Integer>> BIOME_COLOR_MAP =
|
||||
ImmutableBiMap.<Biome, Function<Biome, Integer>>builder()
|
||||
.put(_get(Biomes.SNOWY_PLAINS), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.ICE_SPIKES), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.DESERT), BiomeWrapper::_colorSand)
|
||||
.put(_get(Biomes.SWAMP), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.MANGROVE_SWAMP), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.FLOWER_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.BIRCH_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.DARK_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.OLD_GROWTH_BIRCH_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.OLD_GROWTH_PINE_TAIGA), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.OLD_GROWTH_SPRUCE_TAIGA), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.TAIGA), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.SNOWY_TAIGA), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.WINDSWEPT_GRAVELLY_HILLS), BiomeWrapper::_colorGravel)
|
||||
.put(_get(Biomes.WINDSWEPT_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.JUNGLE), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.BAMBOO_JUNGLE), BiomeWrapper::_colorBamboo)
|
||||
.put(_get(Biomes.BADLANDS), BiomeWrapper::_colorRedSand)
|
||||
.put(_get(Biomes.ERODED_BADLANDS), BiomeWrapper::_colorRedSand)
|
||||
.put(_get(Biomes.WOODED_BADLANDS), BiomeWrapper::_colorStone)
|
||||
.put(_get(Biomes.GROVE), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.SNOWY_SLOPES), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.FROZEN_PEAKS), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.JAGGED_PEAKS), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.STONY_PEAKS), BiomeWrapper::_colorStone)
|
||||
.put(_get(Biomes.RIVER), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.FROZEN_RIVER), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.BEACH), BiomeWrapper::_colorSand)
|
||||
.put(_get(Biomes.SNOWY_BEACH), BiomeWrapper::_colorSnow)
|
||||
.put(_get(Biomes.STONY_SHORE), BiomeWrapper::_colorStone)
|
||||
.put(_get(Biomes.WARM_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.LUKEWARM_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.DEEP_LUKEWARM_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.DEEP_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.COLD_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.DEEP_COLD_OCEAN), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.FROZEN_OCEAN), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.DEEP_FROZEN_OCEAN), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.MUSHROOM_FIELDS), BiomeWrapper::_colorMushoom)
|
||||
.put(_get(Biomes.DRIPSTONE_CAVES), BiomeWrapper::_colorDripStone)
|
||||
.put(_get(Biomes.LUSH_CAVES), BiomeWrapper::_colorMoss)
|
||||
.put(_get(Biomes.DEEP_DARK), BiomeWrapper::_colorSculk)
|
||||
.put(_get(Biomes.NETHER_WASTES), BiomeWrapper::_colorNether)
|
||||
.put(_get(Biomes.WARPED_FOREST), BiomeWrapper::_colorNether)
|
||||
.put(_get(Biomes.CRIMSON_FOREST), BiomeWrapper::_colorNether)
|
||||
.put(_get(Biomes.SOUL_SAND_VALLEY), BiomeWrapper::_colorSoulSand)
|
||||
.put(_get(Biomes.BASALT_DELTAS), BiomeWrapper::_colorBasalt)
|
||||
.put(_get(Biomes.THE_END), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.END_HIGHLANDS), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.END_MIDLANDS), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.SMALL_END_ISLANDS), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.END_BARRENS), BiomeWrapper::_colorEnd)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public int getColorForBiome(int x, int z)
|
||||
{
|
||||
int colorInt;
|
||||
Function<Biome, Integer> colorFunction = BIOME_COLOR_MAP.get(biome);
|
||||
if (colorFunction != null)
|
||||
{
|
||||
colorInt = colorFunction.apply(biome);
|
||||
}
|
||||
else
|
||||
{
|
||||
colorInt = biome.getGrassColor(x, z);
|
||||
}
|
||||
return colorInt;
|
||||
}
|
||||
#endif
|
||||
@Override public String getName()
|
||||
{
|
||||
return biome.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGrassTint(int x, int z)
|
||||
{
|
||||
return biome.getGrassColor(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFolliageTint()
|
||||
{
|
||||
return biome.getFoliageColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaterTint()
|
||||
{
|
||||
return biome.getWaterColor();
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof BiomeWrapper))
|
||||
return false;
|
||||
BiomeWrapper that = (BiomeWrapper) obj;
|
||||
return Objects.equals(biome, that.biome);
|
||||
}
|
||||
|
||||
@Override public int hashCode()
|
||||
{
|
||||
return Objects.hash(biome);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.seibel.lod.common.wrappers.world;
|
||||
|
||||
import com.seibel.lod.api.enums.worldGeneration.EDhApiLevelType;
|
||||
import com.seibel.lod.api.interfaces.world.IDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.cache.ClientBlockDetailMap;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger(ClientLevelWrapper.class.getSimpleName());
|
||||
private static final ConcurrentHashMap<ClientLevel, ClientLevelWrapper>
|
||||
levelWrapperMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static ClientLevelWrapper getWrapper(ClientLevel level) {
|
||||
return levelWrapperMap.computeIfAbsent(level, ClientLevelWrapper::new);
|
||||
}
|
||||
public static void closeWrapper(ClientLevel level)
|
||||
{
|
||||
levelWrapperMap.remove(level);
|
||||
}
|
||||
|
||||
private ClientLevelWrapper(ClientLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
final ClientLevel level;
|
||||
ClientBlockDetailMap blockMap = new ClientBlockDetailMap(this);
|
||||
@Nullable
|
||||
@Override
|
||||
public IServerLevelWrapper tryGetServerSideWrapper()
|
||||
{
|
||||
try
|
||||
{
|
||||
// commented out because this breaks when traveling between dimensions,
|
||||
// serverPlayer.getLevel() will return the previously loaded level, which causes issues
|
||||
// PlayerList serverPlayerList = MinecraftClientWrapper.INSTANCE.mc.getSingleplayerServer().getPlayerList();
|
||||
// ServerPlayer serverPlayer = serverPlayerList.getPlayer(MinecraftClientWrapper.INSTANCE.mc.player.getUUID());
|
||||
// return ServerLevelWrapper.getWrapper(serverPlayer.getLevel());
|
||||
|
||||
|
||||
Iterable<ServerLevel> serverLevels = MinecraftClientWrapper.INSTANCE.mc.getSingleplayerServer().getAllLevels();
|
||||
|
||||
// attempt to find the server level with the same dimension type
|
||||
// TODO this assumes only one level per dimension type, the SubDimensionLevelMatcher will need to be added for supporting multiple levels per dimension
|
||||
ServerLevelWrapper foundLevelWrapper = null;
|
||||
for (ServerLevel serverLevel : serverLevels)
|
||||
{
|
||||
if (foundLevelWrapper != null)
|
||||
{
|
||||
LOGGER.warn("More than 1 level exists for a given dimension. Defaulting to the first level.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (serverLevel.dimensionType() == this.level.dimensionType())
|
||||
{
|
||||
foundLevelWrapper = ServerLevelWrapper.getWrapper(serverLevel);
|
||||
}
|
||||
}
|
||||
|
||||
return foundLevelWrapper;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Failed to get server side wrapper for client level: "+level);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static void cleanCheck() {
|
||||
if (!levelWrapperMap.isEmpty()) {
|
||||
LOGGER.warn("{} client levels havn't been freed!", levelWrapperMap.size());
|
||||
levelWrapperMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeBaseColor(DhBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper blockState) {
|
||||
return blockMap.getColor(((BlockStateWrapper)blockState).blockState,
|
||||
(BiomeWrapper)biome, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDhApiDimensionTypeWrapper getDimensionType()
|
||||
{
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType() { return EDhApiLevelType.CLIENT_LEVEL; }
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z)
|
||||
{
|
||||
return level.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z)
|
||||
{
|
||||
return level.getBrightness(LightLayer.SKY, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
public ClientLevel getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling() {
|
||||
return level.dimensionType().hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight() {
|
||||
return level.dimensionType().hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return level.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight()
|
||||
{
|
||||
#if PRE_MC_1_17_1
|
||||
return 0;
|
||||
#else
|
||||
return level.getMinBuildHeight();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkWrapper tryGetChunk(DhChunkPos pos) {
|
||||
if (!level.hasChunk(pos.x, pos.z)) return null;
|
||||
ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false);
|
||||
if (chunk == null) return null;
|
||||
return new ChunkWrapper(chunk, level, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChunkLoaded(int chunkX, int chunkZ) {
|
||||
ChunkSource source = level.getChunkSource();
|
||||
return source.hasChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(DhBlockPos pos) {
|
||||
return BlockStateWrapper.fromBlockState(level.getBlockState(McObjectConverter.Convert(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBiomeWrapper getBiome(DhBlockPos pos) {
|
||||
return BiomeWrapper.getBiomeWrapper(level.getBiome(McObjectConverter.Convert(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientLevel getWrappedMcObject_UNSAFE()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wrapped{" + level.toString() + "@" + getDimensionType().getDimensionName() + "}";
|
||||
}
|
||||
|
||||
}
|
||||
+31
-6
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
@@ -22,14 +22,15 @@ package com.seibel.lod.common.wrappers.world;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.seibel.lod.api.interfaces.world.IDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 11-21-2021
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
{
|
||||
@@ -79,4 +80,28 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
{
|
||||
return dimensionType.hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE()
|
||||
{
|
||||
return this.dimensionType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj.getClass() != DimensionTypeWrapper.class)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DimensionTypeWrapper other = (DimensionTypeWrapper) obj;
|
||||
return other.getDimensionName().equals(this.getDimensionName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.common.wrappers.world;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.seibel.lod.api.enums.worldGeneration.EDhApiLevelType;
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.cache.ServerBlockDetailMap;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final ConcurrentHashMap<ServerLevel, ServerLevelWrapper>
|
||||
levelWrapperMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static ServerLevelWrapper getWrapper(ServerLevel level)
|
||||
{
|
||||
return levelWrapperMap.computeIfAbsent(level, ServerLevelWrapper::new);
|
||||
}
|
||||
public static void closeWrapper(ServerLevel level)
|
||||
{
|
||||
levelWrapperMap.remove(level);
|
||||
}
|
||||
public static void cleanCheck()
|
||||
{
|
||||
if (!levelWrapperMap.isEmpty())
|
||||
{
|
||||
LOGGER.warn(levelWrapperMap.size()+" server levels haven't been freed!");
|
||||
levelWrapperMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
final ServerLevel level;
|
||||
ServerBlockDetailMap blockMap = new ServerBlockDetailMap(this);
|
||||
|
||||
public ServerLevelWrapper(ServerLevel level)
|
||||
{
|
||||
this.level = level;
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public IClientLevelWrapper tryGetClientLevelWrapper()
|
||||
{
|
||||
try
|
||||
{
|
||||
MinecraftClientWrapper client = MinecraftClientWrapper.INSTANCE;
|
||||
return ClientLevelWrapper.getWrapper(client.mc.level);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Failed to get client side wrapper for server level "+level+".");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getSaveFolder()
|
||||
{
|
||||
return level.getChunkSource().getDataStorage().dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionTypeWrapper getDimensionType()
|
||||
{
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType() { return EDhApiLevelType.CLIENT_LEVEL; }
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z)
|
||||
{
|
||||
return level.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z)
|
||||
{
|
||||
return level.getBrightness(LightLayer.SKY, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
public ServerLevel getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling()
|
||||
{
|
||||
return level.dimensionType().hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight()
|
||||
{
|
||||
return level.dimensionType().hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return level.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight()
|
||||
{
|
||||
#if PRE_MC_1_17_1
|
||||
return 0;
|
||||
#else
|
||||
return level.getMinBuildHeight();
|
||||
#endif
|
||||
}
|
||||
@Override
|
||||
public IChunkWrapper tryGetChunk(DhChunkPos pos) {
|
||||
if (!level.hasChunk(pos.x, pos.z)) return null;
|
||||
ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false);
|
||||
if (chunk == null) return null;
|
||||
return new ChunkWrapper(chunk, level, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChunkLoaded(int chunkX, int chunkZ) {
|
||||
// world.hasChunk(chunkX, chunkZ); THIS DOES NOT WORK FOR CLIENT LEVEL CAUSE MOJANG ALWAYS RETURN TRUE FOR THAT!
|
||||
ChunkSource source = level.getChunkSource();
|
||||
return source.hasChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(DhBlockPos pos) {
|
||||
return BlockStateWrapper.fromBlockState(level.getBlockState(McObjectConverter.Convert(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBiomeWrapper getBiome(DhBlockPos pos) {
|
||||
return BiomeWrapper.getBiomeWrapper(level.getBiome(McObjectConverter.Convert(pos)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerLevel getWrappedMcObject_UNSAFE()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wrapped{" + level.toString() + "@" + getDimensionType().getDimensionName() + "}";
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.common.wrappers.world;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.seibel.lod.core.enums.WorldType;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @author ??
|
||||
* @version 11-21-2021
|
||||
*/
|
||||
public class WorldWrapper implements IWorldWrapper
|
||||
{
|
||||
private static final ConcurrentMap<LevelAccessor, WorldWrapper> worldWrapperMap = new ConcurrentHashMap<>();
|
||||
private final LevelAccessor world;
|
||||
public final WorldType worldType;
|
||||
|
||||
|
||||
public WorldWrapper(LevelAccessor newWorld)
|
||||
{
|
||||
world = newWorld;
|
||||
|
||||
if (world.getClass() == ServerLevel.class)
|
||||
worldType = WorldType.ServerWorld;
|
||||
else if (world.getClass() == ClientLevel.class)
|
||||
worldType = WorldType.ClientWorld;
|
||||
else
|
||||
worldType = WorldType.Unknown;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static WorldWrapper getWorldWrapper(LevelAccessor world)
|
||||
{
|
||||
if (world == null) return null;
|
||||
//first we check if the biome has already been wrapped
|
||||
if(worldWrapperMap.containsKey(world) && worldWrapperMap.get(world) != null)
|
||||
return worldWrapperMap.get(world);
|
||||
|
||||
|
||||
//if it hasn't been created yet, we create it and save it in the map
|
||||
WorldWrapper worldWrapper = new WorldWrapper(world);
|
||||
worldWrapperMap.put(world, worldWrapper);
|
||||
|
||||
//we return the newly created wrapper
|
||||
return worldWrapper;
|
||||
}
|
||||
|
||||
public static void clearMap()
|
||||
{
|
||||
worldWrapperMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getWorldType()
|
||||
{
|
||||
return worldType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionTypeWrapper getDimensionType()
|
||||
{
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(world.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int x, int y, int z)
|
||||
{
|
||||
return world.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z)
|
||||
{
|
||||
return world.getBrightness(LightLayer.SKY, new BlockPos(x,y,z));
|
||||
}
|
||||
|
||||
public LevelAccessor getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling()
|
||||
{
|
||||
return world.dimensionType().hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight()
|
||||
{
|
||||
return world.dimensionType().hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return world.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getMinHeight()
|
||||
{
|
||||
#if PRE_MC_1_17_1
|
||||
return (short) 0;
|
||||
#else
|
||||
return (short) world.getMinBuildHeight();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @throws UnsupportedOperationException if the WorldWrapper isn't for a ServerWorld */
|
||||
@Override
|
||||
public File getSaveFolder() throws UnsupportedOperationException
|
||||
{
|
||||
if (worldType != WorldType.ServerWorld)
|
||||
throw new UnsupportedOperationException("getSaveFolder can only be called for ServerWorlds.");
|
||||
|
||||
ServerChunkCache chunkSource = ((ServerLevel) world).getChunkSource();
|
||||
return chunkSource.getDataStorage().dataFolder;
|
||||
}
|
||||
|
||||
|
||||
/** @throws UnsupportedOperationException if the WorldWrapper isn't for a ServerWorld */
|
||||
public ServerLevel getServerWorld() throws UnsupportedOperationException
|
||||
{
|
||||
if (worldType != WorldType.ServerWorld)
|
||||
throw new UnsupportedOperationException("getSaveFolder can only be called for ServerWorlds.");
|
||||
|
||||
return (ServerLevel) world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel()
|
||||
{
|
||||
// TODO this is depreciated, what should we use instead?
|
||||
return world.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkWrapper tryGetChunk(AbstractChunkPosWrapper pos) {
|
||||
ChunkAccess chunk = world.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false);
|
||||
if (chunk == null) return null;
|
||||
return new ChunkWrapper(chunk, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChunkLoaded(int chunkX, int chunkZ) {
|
||||
// world.hasChunk(chunkX, chunkZ); THIS DOES NOT WORK FOR CLIENT LEVEL CAUSE MOJANG ALWAYS RETURN TRUE FOR THAT!
|
||||
ChunkSource source = world.getChunkSource();
|
||||
return source.hasChunk(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
+302
-330
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2021 Tom Lee (TomTheFurry)
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration;
|
||||
|
||||
import com.seibel.lod.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.lod.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.lod.core.level.IDhServerLevel;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.api.enums.config.ELightGenerationMode;
|
||||
import com.seibel.lod.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.lod.core.logging.ConfigBasedSpamLogger;
|
||||
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
|
||||
import com.seibel.lod.core.builders.lodBuilding.LodBuilderConfig;
|
||||
import com.seibel.lod.core.enums.config.DistanceGenerationMode;
|
||||
import com.seibel.lod.core.enums.config.LightGenerationMode;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.objects.lod.LodDimension;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.util.objects.EventTimer;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.util.gridList.ArrayGridList;
|
||||
import com.seibel.lod.core.util.LodThreadFactory;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper;
|
||||
import com.seibel.lod.core.util.objects.LodThreadFactory;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.seibel.lod.common.wrappers.DependencySetupDoneCheck;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.WorldWrapper;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.ChunkLoader;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightGetterAdaptor;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion;
|
||||
@@ -88,136 +88,69 @@ Carver Step: 0.000009923s
|
||||
Feature Step: 0.389072425s
|
||||
Lod Generation: 0.269023348s
|
||||
*/
|
||||
|
||||
public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnvionmentWrapper
|
||||
public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnvironmentWrapper
|
||||
{
|
||||
private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
public static final ConfigBasedSpamLogger PREF_LOGGER =
|
||||
new ConfigBasedSpamLogger(LogManager.getLogger("LodWorldGen"),
|
||||
() -> CONFIG.client().advanced().debugging().debugSwitch().getLogWorldGenPerformance(),1);
|
||||
() -> Config.Client.Advanced.Debugging.DebugSwitch.logWorldGenPerformance.get(),1);
|
||||
public static final ConfigBasedLogger EVENT_LOGGER =
|
||||
new ConfigBasedLogger(LogManager.getLogger("LodWorldGen"),
|
||||
() -> CONFIG.client().advanced().debugging().debugSwitch().getLogWorldGenEvent());
|
||||
() -> Config.Client.Advanced.Debugging.DebugSwitch.logWorldGenEvent.get());
|
||||
public static final ConfigBasedLogger LOAD_LOGGER =
|
||||
new ConfigBasedLogger(LogManager.getLogger("LodWorldGen"),
|
||||
() -> CONFIG.client().advanced().debugging().debugSwitch().getLogWorldGenLoadEvent());
|
||||
|
||||
//TODO: Make actual proper support for StarLight
|
||||
() -> Config.Client.Advanced.Debugging.DebugSwitch.logWorldGenLoadEvent.get());
|
||||
|
||||
public static class PrefEvent
|
||||
{
|
||||
long beginNano = 0;
|
||||
long emptyNano = 0;
|
||||
long structStartNano = 0;
|
||||
long structRefNano = 0;
|
||||
long biomeNano = 0;
|
||||
long noiseNano = 0;
|
||||
long surfaceNano = 0;
|
||||
long carverNano = 0;
|
||||
long featureNano = 0;
|
||||
long lightNano = 0;
|
||||
long endNano = 0;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "beginNano: " + beginNano + ",\n" +
|
||||
"emptyNano: " + emptyNano + ",\n" +
|
||||
"structStartNano: " + structStartNano + ",\n" +
|
||||
"structRefNano: " + structRefNano + ",\n" +
|
||||
"biomeNano: " + biomeNano + ",\n" +
|
||||
"noiseNano: " + noiseNano + ",\n" +
|
||||
"surfaceNano: " + surfaceNano + ",\n" +
|
||||
"carverNano: " + carverNano + ",\n" +
|
||||
"featureNano: " + featureNano + ",\n" +
|
||||
"lightNano: " + lightNano + ",\n" +
|
||||
"endNano: " + endNano + "\n";
|
||||
}
|
||||
}
|
||||
//TODO: Make actual proper support for StarLight
|
||||
|
||||
public static class PerfCalculator
|
||||
{
|
||||
public static final int SIZE = 50;
|
||||
Rolling totalTime = new Rolling(SIZE);
|
||||
Rolling emptyTime = new Rolling(SIZE);
|
||||
Rolling structStartTime = new Rolling(SIZE);
|
||||
Rolling structRefTime = new Rolling(SIZE);
|
||||
Rolling biomeTime = new Rolling(SIZE);
|
||||
Rolling noiseTime = new Rolling(SIZE);
|
||||
Rolling surfaceTime = new Rolling(SIZE);
|
||||
Rolling carverTime = new Rolling(SIZE);
|
||||
Rolling featureTime = new Rolling(SIZE);
|
||||
Rolling lightTime = new Rolling(SIZE);
|
||||
Rolling lodTime = new Rolling(SIZE);
|
||||
private static final String[] TIME_NAMES = {
|
||||
"total",
|
||||
"setup",
|
||||
"structStart",
|
||||
"structRef",
|
||||
"biome",
|
||||
"noise",
|
||||
"surface",
|
||||
"carver",
|
||||
"feature",
|
||||
"light",
|
||||
"cleanup",
|
||||
//"lodCreation" (No longer used)
|
||||
};
|
||||
|
||||
public void recordEvent(PrefEvent e)
|
||||
public static final int SIZE = 50;
|
||||
ArrayList<Rolling> times = new ArrayList<>();
|
||||
|
||||
public PerfCalculator()
|
||||
{
|
||||
long preTime = e.beginNano;
|
||||
totalTime.add(e.endNano - preTime);
|
||||
if (e.emptyNano != 0)
|
||||
for(int i = 0; i < 11; i++)
|
||||
{
|
||||
emptyTime.add(e.emptyNano - preTime);
|
||||
preTime = e.emptyNano;
|
||||
times.add(new Rolling(SIZE));
|
||||
}
|
||||
if (e.structStartNano != 0)
|
||||
}
|
||||
|
||||
public void recordEvent(EventTimer event)
|
||||
{
|
||||
for (EventTimer.Event e : event.events)
|
||||
{
|
||||
structStartTime.add(e.structStartNano - preTime);
|
||||
preTime = e.structStartNano;
|
||||
}
|
||||
if (e.structRefNano != 0)
|
||||
{
|
||||
structRefTime.add(e.structRefNano - preTime);
|
||||
preTime = e.structRefNano;
|
||||
}
|
||||
if (e.biomeNano != 0)
|
||||
{
|
||||
biomeTime.add(e.biomeNano - preTime);
|
||||
preTime = e.biomeNano;
|
||||
}
|
||||
if (e.noiseNano != 0)
|
||||
{
|
||||
noiseTime.add(e.noiseNano - preTime);
|
||||
preTime = e.noiseNano;
|
||||
}
|
||||
if (e.surfaceNano != 0)
|
||||
{
|
||||
surfaceTime.add(e.surfaceNano - preTime);
|
||||
preTime = e.surfaceNano;
|
||||
}
|
||||
if (e.carverNano != 0)
|
||||
{
|
||||
carverTime.add(e.carverNano - preTime);
|
||||
preTime = e.carverNano;
|
||||
}
|
||||
if (e.featureNano != 0)
|
||||
{
|
||||
featureTime.add(e.featureNano - preTime);
|
||||
preTime = e.featureNano;
|
||||
}
|
||||
if (e.lightNano != 0)
|
||||
{
|
||||
lightTime.add(e.lightNano - preTime);
|
||||
preTime = e.lightNano;
|
||||
}
|
||||
if (e.endNano != 0)
|
||||
{
|
||||
lodTime.add(e.endNano - preTime);
|
||||
String name = e.name;
|
||||
int index = Arrays.asList(TIME_NAMES).indexOf(name);
|
||||
if(index == -1) continue;
|
||||
times.get(index).add(e.timeNs);
|
||||
}
|
||||
times.get(0).add(event.getTotalTimeNs());
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Total: " + Duration.ofNanos((long) totalTime.getAverage()) + ", Empty/LoadChunk: "
|
||||
+ Duration.ofNanos((long) emptyTime.getAverage()) + ", StructStart: "
|
||||
+ Duration.ofNanos((long) structStartTime.getAverage()) + ", StructRef: "
|
||||
+ Duration.ofNanos((long) structRefTime.getAverage()) + ", Biome: "
|
||||
+ Duration.ofNanos((long) biomeTime.getAverage()) + ", Noise: "
|
||||
+ Duration.ofNanos((long) noiseTime.getAverage()) + ", Surface: "
|
||||
+ Duration.ofNanos((long) surfaceTime.getAverage()) + ", Carver: "
|
||||
+ Duration.ofNanos((long) carverTime.getAverage()) + ", Feature: "
|
||||
+ Duration.ofNanos((long) featureTime.getAverage()) + ", Light: "
|
||||
+ Duration.ofNanos((long) lightTime.getAverage()) + ", Lod: "
|
||||
+ Duration.ofNanos((long) lodTime.getAverage());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < times.size(); i++)
|
||||
{
|
||||
if (times.get(i).getAverage() == 0) continue;
|
||||
sb.append(TIME_NAMES[i]).append(": ").append(times.get(i).getAverage()).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +158,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
|
||||
//=================Generation Step===================
|
||||
|
||||
public final LinkedList<GenerationEvent> events = new LinkedList<>();
|
||||
public final LinkedList<GenerationEvent> generationEventList = new LinkedList<>();
|
||||
public final GlobalParameters params;
|
||||
public final StepStructureStart stepStructureStart = new StepStructureStart(this);
|
||||
public final StepStructureReference stepStructureReference = new StepStructureReference(this);
|
||||
@@ -236,98 +169,121 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
public final StepLight stepLight = new StepLight(this);
|
||||
public boolean unsafeThreadingRecorded = false;
|
||||
//public boolean safeMode = false;
|
||||
private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class);
|
||||
//private static final IMinecraftClientWrapper MC = SingletonHandler.get(IMinecraftClientWrapper.class);
|
||||
public static final long EXCEPTION_TIMER_RESET_TIME = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
|
||||
public static final int EXCEPTION_COUNTER_TRIGGER = 20;
|
||||
public static final int RANGE_TO_RANGE_EMPTY_EXTENSION = 1;
|
||||
public int unknownExceptionCount = 0;
|
||||
public long lastExceptionTriggerTime = 0;
|
||||
|
||||
public static final LodThreadFactory threadFactory = new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY);
|
||||
public static final LodThreadFactory threadFactory = new LodThreadFactory("DH-Gen-Worker-Thread", Thread.MIN_PRIORITY);
|
||||
|
||||
public static ThreadLocal<Boolean> isDistantGeneratorThread = new ThreadLocal<>();
|
||||
|
||||
public static boolean isCurrentThreadDistantGeneratorThread() {
|
||||
return (isDistantGeneratorThread.get() != null);
|
||||
}
|
||||
public static boolean isCurrentThreadDistantGeneratorThread() { return (isDistantGeneratorThread.get() != null); }
|
||||
|
||||
static {
|
||||
public ExecutorService executors = Executors.newFixedThreadPool(
|
||||
Math.max(Config.Client.Advanced.Threading.numberOfWorldGenerationThreads.get().intValue(), 1),
|
||||
threadFactory);
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
static
|
||||
{
|
||||
DependencySetupDoneCheck.getIsCurrentThreadDistantGeneratorThread = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread;
|
||||
}
|
||||
|
||||
public ExecutorService executors = Executors.newFixedThreadPool(
|
||||
CONFIG.client().advanced().threading()._getWorldGenerationThreadPoolSize(), threadFactory);
|
||||
|
||||
public <T> T joinSync(CompletableFuture<T> f) {
|
||||
if (!unsafeThreadingRecorded && !f.isDone()) {
|
||||
public BatchGenerationEnvironment(IDhServerLevel serverlevel)
|
||||
{
|
||||
super(serverlevel);
|
||||
EVENT_LOGGER.info("================WORLD_GEN_STEP_INITING=============");
|
||||
|
||||
ChunkGenerator generator = ((ServerLevelWrapper) (serverlevel.getServerLevelWrapper())).getLevel().getChunkSource().getGenerator();
|
||||
if (!(generator instanceof NoiseBasedChunkGenerator ||
|
||||
generator instanceof DebugLevelSource ||
|
||||
generator instanceof FlatLevelSource))
|
||||
{
|
||||
if (generator.getClass().toString().equals("class com.terraforged.mod.chunk.TFChunkGenerator"))
|
||||
{
|
||||
EVENT_LOGGER.info("TerraForge Chunk Generator detected: ["+generator.getClass()+"], Distant Generation will try its best to support it.");
|
||||
EVENT_LOGGER.info("If it does crash, turn Distant Generation off or set it to to "+EDhApiWorldGenerationStep.EMPTY+".");
|
||||
}
|
||||
else
|
||||
{
|
||||
EVENT_LOGGER.warn("Unknown Chunk Generator detected: ["+generator.getClass()+"], Distant Generation May Fail!");
|
||||
EVENT_LOGGER.warn("If it does crash, set Distant Generation to OFF or Generation Mode to None.");
|
||||
}
|
||||
}
|
||||
|
||||
params = new GlobalParameters(serverlevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public <T> T joinSync(CompletableFuture<T> future)
|
||||
{
|
||||
if (!unsafeThreadingRecorded && !future.isDone())
|
||||
{
|
||||
EVENT_LOGGER.error("Unsafe Threading in Chunk Generator: ", new RuntimeException("Concurrent future"));
|
||||
EVENT_LOGGER.error("To increase stability, it is recommended to set world generation threads count to 1.");
|
||||
unsafeThreadingRecorded = true;
|
||||
}
|
||||
return f.join();
|
||||
}
|
||||
|
||||
public void resizeThreadPool(int newThreadCount)
|
||||
{
|
||||
executors = Executors.newFixedThreadPool(newThreadCount,
|
||||
new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY));
|
||||
}
|
||||
|
||||
public boolean tryAddPoint(int px, int pz, int range, Steps target, boolean genAllDetails, double runTimeRatio)
|
||||
{
|
||||
int boxSize = range * 2 + 1;
|
||||
int x = Math.floorDiv(px, boxSize) * boxSize + range;
|
||||
int z = Math.floorDiv(pz, boxSize) * boxSize + range;
|
||||
|
||||
for (GenerationEvent event : events)
|
||||
{
|
||||
if (event.tooClose(x, z, range))
|
||||
return false;
|
||||
}
|
||||
// System.out.println(x + ", "+z);
|
||||
events.add(new GenerationEvent(new ChunkPos(x, z), range, this, target, genAllDetails, runTimeRatio));
|
||||
return true;
|
||||
return future.join();
|
||||
}
|
||||
|
||||
public void resizeThreadPool(int newThreadCount) { executors = Executors.newFixedThreadPool(newThreadCount, new LodThreadFactory("DH-Gen-Worker-Thread", Thread.MIN_PRIORITY)); }
|
||||
|
||||
public void updateAllFutures()
|
||||
{
|
||||
if (unknownExceptionCount > 0) {
|
||||
if (System.nanoTime() - lastExceptionTriggerTime >= EXCEPTION_TIMER_RESET_TIME) {
|
||||
if (unknownExceptionCount > 0)
|
||||
{
|
||||
if (System.nanoTime() - lastExceptionTriggerTime >= EXCEPTION_TIMER_RESET_TIME)
|
||||
{
|
||||
unknownExceptionCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Update all current out standing jobs
|
||||
Iterator<GenerationEvent> iter = events.iterator();
|
||||
Iterator<GenerationEvent> iter = generationEventList.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
GenerationEvent event = iter.next();
|
||||
if (event.isCompleted())
|
||||
if (event.future.isDone())
|
||||
{
|
||||
try
|
||||
if (event.future.isCompletedExceptionally() && !event.future.isCancelled())
|
||||
{
|
||||
event.join();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
EVENT_LOGGER.error("Batching World Generator: Event {} gotten an exception", event);
|
||||
EVENT_LOGGER.error("Exception: ", e);
|
||||
unknownExceptionCount++;
|
||||
lastExceptionTriggerTime = System.nanoTime();
|
||||
}
|
||||
finally
|
||||
{
|
||||
iter.remove();
|
||||
try
|
||||
{
|
||||
event.future.get(); // Should throw exception
|
||||
LodUtil.assertNotReach();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
unknownExceptionCount++;
|
||||
lastExceptionTriggerTime = System.nanoTime();
|
||||
EVENT_LOGGER.error("Batching World Generator: Event {} gotten an exception", event);
|
||||
EVENT_LOGGER.error("Exception: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
iter.remove();
|
||||
}
|
||||
else if (event.hasTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS))
|
||||
{
|
||||
EVENT_LOGGER.error("Batching World Generator: " + event + " timed out and terminated!");
|
||||
EVENT_LOGGER.info("Dump PrefEvent: " + event.pEvent);
|
||||
EVENT_LOGGER.info("Dump PrefEvent: " + event.timer);
|
||||
try
|
||||
{
|
||||
if (!event.terminate())
|
||||
{
|
||||
EVENT_LOGGER.error("Failed to terminate the stuck generation event!");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -335,33 +291,14 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unknownExceptionCount > EXCEPTION_COUNTER_TRIGGER) {
|
||||
EVENT_LOGGER.error("Too many exceptions in Batching World Generator! Disabling the generator.");
|
||||
unknownExceptionCount = 0;
|
||||
CONFIG.client().worldGenerator().setEnableDistantGeneration(false);
|
||||
Config.Client.WorldGenerator.enableDistantGeneration.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public BatchGenerationEnvironment(IWorldWrapper serverlevel, LodBuilder lodBuilder, LodDimension lodDim)
|
||||
{
|
||||
super(serverlevel, lodBuilder, lodDim);
|
||||
EVENT_LOGGER.info("================WORLD_GEN_STEP_INITING=============");
|
||||
ChunkGenerator generator = ((WorldWrapper) serverlevel).getServerWorld().getChunkSource().getGenerator();
|
||||
if (!(generator instanceof NoiseBasedChunkGenerator ||
|
||||
generator instanceof DebugLevelSource ||
|
||||
generator instanceof FlatLevelSource)) {
|
||||
if (generator.getClass().toString().equals("class com.terraforged.mod.chunk.TFChunkGenerator")) {
|
||||
EVENT_LOGGER.info("TerraForge Chunk Generator detected: [{}], Distant Generation will try its best to support it.", generator.getClass());
|
||||
EVENT_LOGGER.info("If it does crash, set Distant Generation to OFF or Generation Mode to None.");
|
||||
} else {
|
||||
EVENT_LOGGER.warn("Unknown Chunk Generator detected: [{}], Distant Generation May Fail!", generator.getClass());
|
||||
EVENT_LOGGER.warn("If it does crash, set Distant Generation to OFF or Generation Mode to None.");
|
||||
}
|
||||
}
|
||||
params = new GlobalParameters((ServerLevel) ((WorldWrapper) serverlevel).getWorld(), lodBuilder, lodDim);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static ChunkAccess loadOrMakeChunk(ChunkPos chunkPos, ServerLevel level, LevelLightEngine lightEngine)
|
||||
{
|
||||
CompoundTag chunkData = null;
|
||||
@@ -377,6 +314,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
{
|
||||
LOAD_LOGGER.error("DistantHorizons: Couldn't load chunk {}", chunkPos, e);
|
||||
}
|
||||
|
||||
if (chunkData == null)
|
||||
{
|
||||
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
|
||||
@@ -386,38 +324,40 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
return ChunkLoader.read(level, lightEngine, chunkPos, chunkData);
|
||||
} catch (Exception e) {
|
||||
try
|
||||
{
|
||||
return ChunkLoader.read(level, lightEngine, chunkPos, chunkData);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOAD_LOGGER.error("DistantHorizons: Couldn't load chunk {}", chunkPos, e);
|
||||
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
|
||||
#if POST_MC_1_17_1, level #endif
|
||||
#if POST_MC_1_18_1, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
|
||||
#if POST_MC_1_17_1 , level #endif
|
||||
#if POST_MC_1_18_1 , level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void generateLodFromList(GenerationEvent e)
|
||||
public void generateLodFromList(GenerationEvent genEvent)
|
||||
{
|
||||
EVENT_LOGGER.debug("Lod Generate Event: " + e.pos);
|
||||
e.pEvent.beginNano = System.nanoTime();
|
||||
EVENT_LOGGER.debug("Lod Generate Event: "+genEvent.minPos);
|
||||
|
||||
ArrayGridList<ChunkAccess> referencedChunks;
|
||||
ArrayGridList<ChunkAccess> genChunks;
|
||||
DistanceGenerationMode generationMode;
|
||||
LightedWorldGenRegion region;
|
||||
WorldGenLevelLightEngine lightEngine;
|
||||
LightGetterAdaptor adaptor;
|
||||
int refRange = e.range + RANGE_TO_RANGE_EMPTY_EXTENSION;
|
||||
int refOffsetX = e.pos.x - refRange;
|
||||
int refOffsetZ = e.pos.z - refRange;
|
||||
|
||||
int refSize = genEvent.size+2; // +2 for the border referenced chunks
|
||||
int refPosX = genEvent.minPos.x - 1; // -1 for the border referenced chunks
|
||||
int refPosZ = genEvent.minPos.z - 1; // -1 for the border referenced chunks
|
||||
|
||||
try
|
||||
{
|
||||
adaptor = new LightGetterAdaptor(params.level);
|
||||
lightEngine = new WorldGenLevelLightEngine(adaptor);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
|
||||
EmptyChunkGenerator generator = (int x, int z) ->
|
||||
{
|
||||
ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
@@ -430,65 +370,43 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
{
|
||||
// Continue...
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
target = new ProtoChunk(chunkPos, UpgradeData.EMPTY
|
||||
#if POST_MC_1_17_1, params.level #endif
|
||||
#if POST_MC_1_18_1, params.biomes, null #endif
|
||||
#if POST_MC_1_17_1 , params.level #endif
|
||||
#if POST_MC_1_18_1 , params.biomes, null #endif
|
||||
);
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
referencedChunks = new ArrayGridList<>(refRange*2+1,
|
||||
(x,z) -> generator.generate(x + refOffsetX,z + refOffsetZ)
|
||||
);
|
||||
e.pEvent.emptyNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
|
||||
referencedChunks = new ArrayGridList<>(refSize, (x,z) -> generator.generate(x + refPosX,z + refPosZ));
|
||||
|
||||
genEvent.refreshTimeout();
|
||||
region = new LightedWorldGenRegion(params.level, lightEngine, referencedChunks,
|
||||
ChunkStatus.STRUCTURE_STARTS, refRange, e.lightMode, generator);
|
||||
ChunkStatus.STRUCTURE_STARTS, refSize/2, genEvent.lightMode, generator);
|
||||
adaptor.setRegion(region);
|
||||
e.tParam.makeStructFeat(region, params);
|
||||
genEvent.threadedParam.makeStructFeat(region, params);
|
||||
genChunks = new ArrayGridList<>(referencedChunks, RANGE_TO_RANGE_EMPTY_EXTENSION,
|
||||
referencedChunks.gridSize - RANGE_TO_RANGE_EMPTY_EXTENSION);
|
||||
generateDirect(e, genChunks, e.target, region);
|
||||
generateDirect(genEvent, genChunks, genEvent.targetGenerationStep, region);
|
||||
genEvent.timer.nextEvent("cleanup");
|
||||
}
|
||||
catch (StepStructureStart.StructStartCorruptedException f)
|
||||
{
|
||||
e.tParam.markAsInvalid();
|
||||
return;
|
||||
genEvent.threadedParam.markAsInvalid();
|
||||
throw (RuntimeException)f.getCause();
|
||||
}
|
||||
|
||||
switch (e.target)
|
||||
for (int offsetY = 0; offsetY < genChunks.gridSize; offsetY++)
|
||||
{
|
||||
case Empty:
|
||||
case StructureStart:
|
||||
case StructureReference:
|
||||
generationMode = DistanceGenerationMode.NONE;
|
||||
break;
|
||||
case Biomes:
|
||||
generationMode = DistanceGenerationMode.BIOME_ONLY;
|
||||
case Noise:
|
||||
generationMode = DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT;
|
||||
break;
|
||||
case Surface:
|
||||
case Carvers:
|
||||
generationMode = DistanceGenerationMode.SURFACE;
|
||||
break;
|
||||
case Features:
|
||||
generationMode = DistanceGenerationMode.FEATURES;
|
||||
break;
|
||||
case Light:
|
||||
case LiquidCarvers:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
for (int oy = 0; oy < genChunks.gridSize; oy++)
|
||||
{
|
||||
for (int ox = 0; ox < genChunks.gridSize; ox++)
|
||||
for (int offsetX = 0; offsetX < genChunks.gridSize; offsetX++)
|
||||
{
|
||||
ChunkAccess target = genChunks.get(ox, oy);
|
||||
ChunkWrapper wrappedChunk = new ChunkWrapper(target, region);
|
||||
if (!wrappedChunk.isLightCorrect()) {
|
||||
ChunkAccess target = genChunks.get(offsetX, offsetY);
|
||||
ChunkWrapper wrappedChunk = new ChunkWrapper(target, region, null);
|
||||
if (!wrappedChunk.isLightCorrect())
|
||||
{
|
||||
throw new RuntimeException("The generated chunk somehow has isLightCorrect() returning false");
|
||||
}
|
||||
|
||||
@@ -499,135 +417,189 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
if (isFull)
|
||||
{
|
||||
LOAD_LOGGER.info("Detected full existing chunk at {}", target.getPos());
|
||||
params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk,
|
||||
new LodBuilderConfig(DistanceGenerationMode.FULL), true, e.genAllDetails);
|
||||
genEvent.resultConsumer.accept(wrappedChunk);
|
||||
}
|
||||
#if POST_MC_1_18_1
|
||||
else if (isPartial)
|
||||
{
|
||||
LOAD_LOGGER.info("Detected old existing chunk at {}", target.getPos());
|
||||
params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk,
|
||||
new LodBuilderConfig(generationMode), true, e.genAllDetails);
|
||||
genEvent.resultConsumer.accept(wrappedChunk);
|
||||
}
|
||||
#endif
|
||||
else if (target.getStatus() == ChunkStatus.EMPTY && generationMode == DistanceGenerationMode.NONE)
|
||||
else if (target.getStatus() == ChunkStatus.EMPTY)
|
||||
{
|
||||
params.lodBuilder.generateLodNodeFromChunk(params.lodDim,wrappedChunk,
|
||||
LodBuilderConfig.getFillVoidConfig(), true, e.genAllDetails);
|
||||
genEvent.resultConsumer.accept(wrappedChunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk,
|
||||
new LodBuilderConfig(generationMode), true, e.genAllDetails);
|
||||
genEvent.resultConsumer.accept(wrappedChunk);
|
||||
}
|
||||
if (e.lightMode == LightGenerationMode.FANCY || isFull)
|
||||
if (genEvent.lightMode == ELightGenerationMode.FANCY || isFull)
|
||||
{
|
||||
lightEngine.retainData(target.getPos(), false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
e.pEvent.endNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
|
||||
genEvent.timer.complete();
|
||||
genEvent.refreshTimeout();
|
||||
if (PREF_LOGGER.canMaybeLog())
|
||||
{
|
||||
e.tParam.perf.recordEvent(e.pEvent);
|
||||
PREF_LOGGER.infoInc("{}", e.tParam.perf);
|
||||
genEvent.threadedParam.perf.recordEvent(genEvent.timer);
|
||||
PREF_LOGGER.infoInc("{}", genEvent.timer);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateDirect(GenerationEvent e, ArrayGridList<ChunkAccess> subRange, Steps step,
|
||||
LightedWorldGenRegion region)
|
||||
public void generateDirect(GenerationEvent genEvent, ArrayGridList<ChunkAccess> chunksToGenerate,
|
||||
EDhApiWorldGenerationStep step, LightedWorldGenRegion region)
|
||||
{
|
||||
try
|
||||
{
|
||||
subRange.forEach((chunk) ->
|
||||
chunksToGenerate.forEach((chunk) ->
|
||||
{
|
||||
if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
((ProtoChunk) chunk).setLightEngine(region.getLightEngine());
|
||||
region.getLightEngine().retainData(chunk.getPos(), true);
|
||||
ProtoChunk protoChunk = ((ProtoChunk) chunk);
|
||||
|
||||
protoChunk.setLightEngine(region.getLightEngine());
|
||||
region.getLightEngine().retainData(protoChunk.getPos(), true);
|
||||
}
|
||||
});
|
||||
if (step == Steps.Empty)
|
||||
|
||||
if (step == EDhApiWorldGenerationStep.EMPTY)
|
||||
{
|
||||
return;
|
||||
stepStructureStart.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.structStartNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
if (step == Steps.StructureStart)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("structStart");
|
||||
stepStructureStart.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
if (step == EDhApiWorldGenerationStep.STRUCTURE_START)
|
||||
{
|
||||
return;
|
||||
stepStructureReference.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.structRefNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
if (step == Steps.StructureReference)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("structRef");
|
||||
stepStructureReference.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
if (step == EDhApiWorldGenerationStep.STRUCTURE_REFERENCE)
|
||||
{
|
||||
return;
|
||||
stepBiomes.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.biomeNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
if (step == Steps.Biomes)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("biome");
|
||||
stepBiomes.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
if (step == EDhApiWorldGenerationStep.BIOMES)
|
||||
{
|
||||
return;
|
||||
stepNoise.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.noiseNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
if (step == Steps.Noise)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("noise");
|
||||
stepNoise.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
if (step == EDhApiWorldGenerationStep.NOISE)
|
||||
{
|
||||
return;
|
||||
stepSurface.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.surfaceNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
if (step == Steps.Surface)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("surface");
|
||||
stepSurface.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
if (step == EDhApiWorldGenerationStep.SURFACE)
|
||||
{
|
||||
return;
|
||||
if (step == Steps.Carvers)
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("carver");
|
||||
if (step == EDhApiWorldGenerationStep.CARVERS)
|
||||
{
|
||||
return;
|
||||
stepFeatures.generateGroup(e.tParam, region, subRange);
|
||||
e.pEvent.featureNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
}
|
||||
|
||||
genEvent.timer.nextEvent("feature");
|
||||
stepFeatures.generateGroup(genEvent.threadedParam, region, chunksToGenerate);
|
||||
genEvent.refreshTimeout();
|
||||
}
|
||||
finally
|
||||
{
|
||||
genEvent.timer.nextEvent("light");
|
||||
switch (region.lightMode)
|
||||
{
|
||||
case FANCY:
|
||||
stepLight.generateGroup(region.getLightEngine(), subRange);
|
||||
stepLight.generateGroup(region.getLightEngine(), chunksToGenerate);
|
||||
break;
|
||||
case FAST:
|
||||
subRange.forEach((p) ->
|
||||
chunksToGenerate.forEach((chunk) ->
|
||||
{
|
||||
if (p instanceof ProtoChunk)
|
||||
((ProtoChunk) p).setLightCorrect(true);
|
||||
if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
chunk.setLightCorrect(true); // TODO why are we checking instanceof ProtoChunk?
|
||||
}
|
||||
|
||||
#if POST_MC_1_18_1
|
||||
if (p instanceof LevelChunk) {
|
||||
((LevelChunk) p).setLightCorrect(true);
|
||||
((LevelChunk) p).setClientLightReady(true);
|
||||
if (chunk instanceof LevelChunk)
|
||||
{
|
||||
LevelChunk levelChunk = (LevelChunk) chunk;
|
||||
levelChunk.setLightCorrect(true);
|
||||
levelChunk.setClientLightReady(true);
|
||||
}
|
||||
#endif
|
||||
});
|
||||
break;
|
||||
}
|
||||
e.pEvent.lightNano = System.nanoTime();
|
||||
e.refreshTimeout();
|
||||
genEvent.refreshTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
public interface EmptyChunkGenerator
|
||||
public interface EmptyChunkGenerator { ChunkAccess generate(int x, int z); }
|
||||
|
||||
@Override
|
||||
public int getEventCount() { return this.generationEventList.size(); }
|
||||
|
||||
@Override
|
||||
public void stop(boolean blocking)
|
||||
{
|
||||
ChunkAccess generate(int x, int z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEventCount() {
|
||||
return events.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(boolean blocking) {
|
||||
EVENT_LOGGER.info("Batch Chunk Generator shutting down...");
|
||||
EVENT_LOGGER.info(BatchGenerationEnvironment.class.getSimpleName()+" shutting down...");
|
||||
|
||||
EVENT_LOGGER.info("Canceling futures...");
|
||||
executors.shutdownNow();
|
||||
if (blocking) try {
|
||||
if (!executors.awaitTermination(10, TimeUnit.SECONDS)) {
|
||||
EVENT_LOGGER.error("Batch Chunk Generator shutdown failed! Ignoring child threads...");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
EVENT_LOGGER.error("Batch Chunk Generator shutdown failed! Ignoring child threads...", e);
|
||||
Iterator<GenerationEvent> iter = this.generationEventList.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
GenerationEvent event = iter.next();
|
||||
event.future.cancel(true);
|
||||
iter.remove();
|
||||
}
|
||||
|
||||
EVENT_LOGGER.info("Awaiting termination...");
|
||||
if (blocking)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!executors.awaitTermination(3, TimeUnit.SECONDS))
|
||||
{
|
||||
EVENT_LOGGER.error("Batch Chunk Generator shutdown failed! Ignoring child threads...");
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
EVENT_LOGGER.error("Batch Chunk Generator shutdown failed! Ignoring child threads...", e);
|
||||
}
|
||||
}
|
||||
|
||||
EVENT_LOGGER.info(BatchGenerationEnvironment.class.getSimpleName()+" shutdown complete.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> generateChunks(int minX, int minZ, int genSize, EDhApiWorldGenerationStep targetStep, double runTimeRatio, Consumer<IChunkWrapper> resultConsumer)
|
||||
{
|
||||
//System.out.println("GenerationEvent: "+genSize+"@"+minX+","+minZ+" "+targetStep);
|
||||
|
||||
// TODO: Check event overlap via e.tooClose()
|
||||
GenerationEvent genEvent = GenerationEvent.startEvent(new DhChunkPos(minX, minZ), genSize, this, targetStep, runTimeRatio, resultConsumer);
|
||||
generationEventList.add(genEvent);
|
||||
return genEvent.future;
|
||||
}
|
||||
|
||||
}
|
||||
+105
-86
@@ -1,142 +1,161 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment.PrefEvent;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.enums.config.LightGenerationMode;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper.Steps;
|
||||
import com.seibel.lod.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.lod.core.util.objects.UncheckedInterruptedException;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.api.enums.config.ELightGenerationMode;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.pos.DhChunkPos;
|
||||
import com.seibel.lod.core.util.objects.EventTimer;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
//======================= Main Event class======================
|
||||
public final class GenerationEvent
|
||||
{
|
||||
static private final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
|
||||
private static int generationFutureDebugIDs = 0;
|
||||
final ThreadedParameters tParam;
|
||||
final ChunkPos pos;
|
||||
final int range;
|
||||
final Future<?> future;
|
||||
long creationNanotime;
|
||||
final int id;
|
||||
final Steps target;
|
||||
final LightGenerationMode lightMode;
|
||||
final PrefEvent pEvent = new PrefEvent();
|
||||
final boolean genAllDetails;
|
||||
|
||||
final double runTimeRatio;
|
||||
|
||||
public GenerationEvent(ChunkPos pos, int range, BatchGenerationEnvironment generationGroup,
|
||||
Steps target, boolean genAllDetails, double runTimeRatio)
|
||||
final int id;
|
||||
final ThreadedParameters threadedParam;
|
||||
final DhChunkPos minPos;
|
||||
final int size;
|
||||
final EDhApiWorldGenerationStep targetGenerationStep;
|
||||
final ELightGenerationMode lightMode;
|
||||
final double runTimeRatio;
|
||||
EventTimer timer = null;
|
||||
long inQueueTime;
|
||||
long timeoutTime = -1;
|
||||
public CompletableFuture<Void> future = null;
|
||||
final Consumer<IChunkWrapper> resultConsumer;
|
||||
|
||||
|
||||
|
||||
public GenerationEvent(DhChunkPos minPos, int size, BatchGenerationEnvironment generationGroup,
|
||||
EDhApiWorldGenerationStep targetGenerationStep, double runTimeRatio, Consumer<IChunkWrapper> resultConsumer)
|
||||
{
|
||||
creationNanotime = System.nanoTime();
|
||||
this.pos = pos;
|
||||
this.range = range;
|
||||
id = generationFutureDebugIDs++;
|
||||
this.target = target;
|
||||
this.tParam = ThreadedParameters.getOrMake(generationGroup.params);
|
||||
LightGenerationMode mode = CONFIG.client().worldGenerator().getLightGenerationMode();
|
||||
|
||||
this.lightMode = mode;
|
||||
this.genAllDetails = genAllDetails;
|
||||
this.inQueueTime = System.nanoTime();
|
||||
this.id = generationFutureDebugIDs++;
|
||||
this.minPos = minPos;
|
||||
this.size = size;
|
||||
this.targetGenerationStep = targetGenerationStep;
|
||||
this.threadedParam = ThreadedParameters.getOrMake(generationGroup.params);
|
||||
this.lightMode = Config.Client.WorldGenerator.lightGenerationMode.get();
|
||||
this.runTimeRatio = runTimeRatio;
|
||||
|
||||
future = generationGroup.executors.submit(() ->
|
||||
this.resultConsumer = resultConsumer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static GenerationEvent startEvent(DhChunkPos minPos, int size, BatchGenerationEnvironment generationGroup,
|
||||
EDhApiWorldGenerationStep target, double runTimeRatio, Consumer<IChunkWrapper> resultConsumer)
|
||||
{
|
||||
if (size % 2 == 0)
|
||||
{
|
||||
long startTime = System.nanoTime();
|
||||
size += 1; // size must be odd for vanilla world gen regions to work
|
||||
}
|
||||
|
||||
GenerationEvent generationEvent = new GenerationEvent(minPos, size, generationGroup, target, runTimeRatio, resultConsumer);
|
||||
generationEvent.future = CompletableFuture.runAsync(() ->
|
||||
{
|
||||
long runStartTime = System.nanoTime();
|
||||
generationEvent.timeoutTime = runStartTime;
|
||||
generationEvent.inQueueTime = runStartTime - generationEvent.inQueueTime;
|
||||
generationEvent.timer = new EventTimer("setup");
|
||||
BatchGenerationEnvironment.isDistantGeneratorThread.set(true);
|
||||
try {
|
||||
generationGroup.generateLodFromList(this);
|
||||
} finally {
|
||||
try
|
||||
{
|
||||
//LOGGER.info("generating [{}]", event.minPos);
|
||||
generationGroup.generateLodFromList(generationEvent);
|
||||
}
|
||||
finally
|
||||
{
|
||||
BatchGenerationEnvironment.isDistantGeneratorThread.remove();
|
||||
if (!Thread.interrupted() && runTimeRatio < 1.0) {
|
||||
if (!Thread.interrupted() && runTimeRatio < 1.0)
|
||||
{
|
||||
long endTime = System.nanoTime();
|
||||
try {
|
||||
long deltaMs = TimeUnit.NANOSECONDS.toMillis(endTime - startTime);
|
||||
Thread.sleep((long) (deltaMs/runTimeRatio - deltaMs));
|
||||
} catch (InterruptedException ignored) {
|
||||
try
|
||||
{
|
||||
long deltaMs = TimeUnit.NANOSECONDS.toMillis(endTime - runStartTime);
|
||||
Thread.sleep((long) (deltaMs / runTimeRatio - deltaMs));
|
||||
}
|
||||
catch (InterruptedException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}, generationGroup.executors);
|
||||
return generationEvent;
|
||||
}
|
||||
|
||||
public boolean isCompleted()
|
||||
{
|
||||
return future.isDone();
|
||||
}
|
||||
public boolean isComplete() { return this.future.isDone(); }
|
||||
|
||||
public boolean hasTimeout(int duration, TimeUnit unit)
|
||||
{
|
||||
if (this.timeoutTime == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
long currentTime = System.nanoTime();
|
||||
long delta = currentTime - creationNanotime;
|
||||
long delta = currentTime - this.timeoutTime;
|
||||
return (delta > TimeUnit.NANOSECONDS.convert(duration, unit));
|
||||
}
|
||||
|
||||
public boolean terminate()
|
||||
{
|
||||
ApiShared.LOGGER.info("======================DUMPING ALL THREADS FOR WORLD GEN=======================");
|
||||
LOGGER.info("======================DUMPING ALL THREADS FOR WORLD GEN=======================");
|
||||
BatchGenerationEnvironment.threadFactory.dumpAllThreadStacks();
|
||||
future.cancel(true);
|
||||
return future.isCancelled();
|
||||
this.future.cancel(true);
|
||||
return this.future.isCancelled();
|
||||
}
|
||||
|
||||
public void join()
|
||||
public boolean tooClose(int minX, int minZ, int width)
|
||||
{
|
||||
try
|
||||
{
|
||||
future.get();
|
||||
}
|
||||
catch (InterruptedException | ExecutionException e)
|
||||
{
|
||||
throw new RuntimeException(e.getCause()==null? e : e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tooClose(int cx, int cz, int cr)
|
||||
{
|
||||
int distX = Math.abs(cx - pos.x);
|
||||
int distZ = Math.abs(cz - pos.z);
|
||||
int minRange = cr + range + 1; // Need one to account for the center
|
||||
minRange += 1 + 1; // Account for required empty chunks
|
||||
return distX < minRange && distZ < minRange;
|
||||
int aMinX = this.minPos.x;
|
||||
int aMinZ = this.minPos.z;
|
||||
int aSize = this.size;
|
||||
// Account for required empty chunks in the border
|
||||
aSize += 1;
|
||||
width += 1;
|
||||
// Do a AABB to AABB intersection test
|
||||
return (aMinX + aSize >= minX &&
|
||||
aMinX <= minX + width &&
|
||||
aMinZ + aSize >= minZ &&
|
||||
aMinZ <= minZ + width);
|
||||
}
|
||||
|
||||
public void refreshTimeout()
|
||||
{
|
||||
creationNanotime = System.nanoTime();
|
||||
LodUtil.checkInterruptsUnchecked();
|
||||
this.timeoutTime = System.nanoTime();
|
||||
UncheckedInterruptedException.throwIfInterrupted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return id + ":" + range + "@" + pos + "(" + target + ")";
|
||||
}
|
||||
public String toString() { return this.id+":"+this.size+"@"+this.minPos+"("+this.targetGenerationStep +")"; }
|
||||
|
||||
}
|
||||
+12
-13
@@ -1,27 +1,27 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
|
||||
import com.seibel.lod.core.objects.lod.LodDimension;
|
||||
import com.seibel.lod.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.lod.core.level.IDhServerLevel;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
@@ -54,23 +54,22 @@ public final class GlobalParameters
|
||||
#endif
|
||||
public final WorldGenSettings worldGenSettings;
|
||||
public final ThreadedLevelLightEngine lightEngine;
|
||||
public final LodBuilder lodBuilder;
|
||||
public final LodDimension lodDim;
|
||||
public final IDhServerLevel lodLevel;
|
||||
public final ServerLevel level;
|
||||
public final Registry<Biome> biomes;
|
||||
public final RegistryAccess registry;
|
||||
public final long worldSeed;
|
||||
public final ServerLevel level; // TODO: Figure out a way to remove this. Maybe ClientLevel also works?
|
||||
public final DataFixer fixerUpper;
|
||||
#if POST_MC_1_18_1
|
||||
public final BiomeManager biomeManager;
|
||||
public final ChunkScanAccess chunkScanner; // FIXME: Figure out if this is actually needed
|
||||
#endif
|
||||
|
||||
public GlobalParameters(ServerLevel level, LodBuilder lodBuilder, LodDimension lodDim)
|
||||
public GlobalParameters(IDhServerLevel lodLevel)
|
||||
{
|
||||
this.lodBuilder = lodBuilder;
|
||||
this.lodDim = lodDim;
|
||||
this.level = level;
|
||||
this.lodLevel = lodLevel;
|
||||
|
||||
level = ((ServerLevelWrapper)lodLevel.getServerLevelWrapper()).getWrappedMcObject_UNSAFE();
|
||||
lightEngine = (ThreadedLevelLightEngine) level.getLightEngine();
|
||||
MinecraftServer server = level.getServer();
|
||||
WorldData worldData = server.getWorldData();
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,6 @@ public class Rolling
|
||||
|
||||
public double getAverage()
|
||||
{
|
||||
return total / size;
|
||||
return size==0 ? 0 : total / size;
|
||||
}
|
||||
}
|
||||
+46
-19
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
@@ -31,48 +31,75 @@ import net.minecraft.world.level.levelgen.structure.StructureCheck;
|
||||
|
||||
public final class ThreadedParameters
|
||||
{
|
||||
private static final ThreadLocal<ThreadedParameters> localParam = new ThreadLocal<ThreadedParameters>();
|
||||
private static final ThreadLocal<ThreadedParameters> LOCAL_PARAM = new ThreadLocal<>();
|
||||
|
||||
final ServerLevel level;
|
||||
public WorldGenStructFeatManager structFeat = null;
|
||||
#if POST_MC_1_18_1
|
||||
public final StructureCheck structCheck;
|
||||
public StructureCheck structCheck;
|
||||
#endif
|
||||
boolean isValid = true;
|
||||
public final PerfCalculator perf = new PerfCalculator();
|
||||
|
||||
private static GlobalParameters previousGlobalParameters = null;
|
||||
|
||||
|
||||
|
||||
public static ThreadedParameters getOrMake(GlobalParameters param)
|
||||
{
|
||||
ThreadedParameters tParam = localParam.get();
|
||||
ThreadedParameters tParam = LOCAL_PARAM.get();
|
||||
if (tParam != null && tParam.isValid && tParam.level == param.level)
|
||||
{
|
||||
return tParam;
|
||||
}
|
||||
|
||||
tParam = new ThreadedParameters(param);
|
||||
localParam.set(tParam);
|
||||
LOCAL_PARAM.set(tParam);
|
||||
return tParam;
|
||||
}
|
||||
|
||||
public void markAsInvalid()
|
||||
{
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
private ThreadedParameters(GlobalParameters param)
|
||||
{
|
||||
level = param.level;
|
||||
previousGlobalParameters = param;
|
||||
|
||||
this.level = param.level;
|
||||
#if PRE_MC_1_18_1
|
||||
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, level);
|
||||
this.structFeat = new WorldGenStructFeatManager(param.worldGenSettings, level);
|
||||
#elif PRE_MC_1_19
|
||||
structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures,
|
||||
param.level.dimension(), param.generator, level, param.generator.getBiomeSource(), param.worldSeed,
|
||||
param.fixerUpper);
|
||||
this.structCheck = this.createStructureCheck(param);
|
||||
#else
|
||||
structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures,
|
||||
this.structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures,
|
||||
param.level.dimension(), param.generator, param.randomState, level, param.generator.getBiomeSource(), param.worldSeed,
|
||||
param.fixerUpper);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void markAsInvalid() { isValid = false; }
|
||||
|
||||
public void makeStructFeat(WorldGenLevel genLevel, GlobalParameters param)
|
||||
{
|
||||
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel #if POST_MC_1_18_1, structCheck #endif);
|
||||
}
|
||||
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public void recreateStructureCheck()
|
||||
{
|
||||
if (previousGlobalParameters != null)
|
||||
{
|
||||
this.structCheck = createStructureCheck(previousGlobalParameters);
|
||||
}
|
||||
}
|
||||
private StructureCheck createStructureCheck(GlobalParameters param)
|
||||
{
|
||||
return new StructureCheck(param.chunkScanner, param.registry, param.structures,
|
||||
param.level.dimension(), param.generator, this.level, param.generator.getBiomeSource(), param.worldSeed,
|
||||
param.fixerUpper);
|
||||
}
|
||||
#else
|
||||
public void recreateStructureCheck() { /* do nothing */ }
|
||||
#endif
|
||||
|
||||
}
|
||||
+6
-24
@@ -1,37 +1,30 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration.mimicObject;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
|
||||
import com.seibel.lod.core.logging.ConfigBasedLogger;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@@ -48,29 +41,18 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.*;
|
||||
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
#if POST_MC_1_18_1
|
||||
import net.minecraft.world.level.levelgen.blending.BlendingData;
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
#endif
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
||||
import net.minecraft.world.ticks.LevelChunkTicks;
|
||||
#endif
|
||||
#if POST_MC_1_18_2
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ChunkLoader
|
||||
{
|
||||
@@ -112,7 +94,7 @@ public class ChunkLoader
|
||||
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
|
||||
#else
|
||||
Codec<PalettedContainer<Holder<Biome>>> biomeCodec = PalettedContainer.codecRW(
|
||||
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
|
||||
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
|
||||
#endif
|
||||
#endif
|
||||
int i = #if PRE_MC_1_17_1 16; #else level.getSectionsCount(); #endif
|
||||
|
||||
+6
-6
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration.mimicObject;
|
||||
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler;
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor;
|
||||
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
@@ -36,7 +36,7 @@ public class LightGetterAdaptor implements LightChunkGetter {
|
||||
|
||||
public LightGetterAdaptor(BlockGetter heightAccessor) {
|
||||
this.heightGetter = heightAccessor;
|
||||
shouldReturnNull = ModAccessorHandler.get(IStarlightAccessor.class) != null;
|
||||
shouldReturnNull = ModAccessorInjector.INSTANCE.get(IStarlightAccessor.class) != null;
|
||||
}
|
||||
|
||||
public void setRegion(LightedWorldGenRegion region) {
|
||||
|
||||
+36
-23
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration.mimicObject;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.List;
|
||||
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.SpawnerBlock;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment.EmptyChunkGenerator;
|
||||
import com.seibel.lod.core.enums.config.LightGenerationMode;
|
||||
import com.seibel.lod.api.enums.config.ELightGenerationMode;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.block.BlockTintCache;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Cursor3D;
|
||||
import net.minecraft.core.SectionPos;
|
||||
@@ -46,10 +46,6 @@ import net.minecraft.world.level.ColorResolver;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
#endif
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.world.level.StructureFeatureManager;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
#endif
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -59,20 +55,24 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.ImposterProtoChunk;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
|
||||
public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
public class LightedWorldGenRegion extends WorldGenRegion
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
|
||||
|
||||
public final WorldGenLevelLightEngine light;
|
||||
public final LightGenerationMode lightMode;
|
||||
public final ELightGenerationMode lightMode;
|
||||
public final EmptyChunkGenerator generator;
|
||||
public final int writeRadius;
|
||||
public final int size;
|
||||
private final ChunkPos firstPos;
|
||||
private final List<ChunkAccess> cache;
|
||||
Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
|
||||
|
||||
#if PRE_MC_1_18_1
|
||||
private ChunkPos overrideCenterPos = null;
|
||||
|
||||
public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;}
|
||||
#if PRE_MC_1_17_1
|
||||
@Override
|
||||
@@ -93,7 +93,8 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
|
||||
public LightedWorldGenRegion(ServerLevel serverLevel, WorldGenLevelLightEngine lightEngine,
|
||||
List<ChunkAccess> list, ChunkStatus chunkStatus, int i,
|
||||
LightGenerationMode lightMode, EmptyChunkGenerator generator) {
|
||||
ELightGenerationMode lightMode, EmptyChunkGenerator generator)
|
||||
{
|
||||
super(serverLevel, list #if POST_MC_1_17_1, chunkStatus, i #endif);
|
||||
this.lightMode = lightMode;
|
||||
this.firstPos = list.get(0).getPos();
|
||||
@@ -107,7 +108,8 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
#if POST_MC_1_17_1
|
||||
// Bypass BCLib mixin overrides.
|
||||
@Override
|
||||
public boolean ensureCanWrite(BlockPos blockPos) {
|
||||
public boolean ensureCanWrite(BlockPos blockPos)
|
||||
{
|
||||
int i = SectionPos.blockToSectionCoord(blockPos.getX());
|
||||
int j = SectionPos.blockToSectionCoord(blockPos.getZ());
|
||||
ChunkPos chunkPos = this.getCenter();
|
||||
@@ -163,7 +165,18 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
// Skip BlockEntity stuff. It aren't really needed
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(BlockPos blockPos) {
|
||||
return null;
|
||||
BlockState blockState = this.getBlockState(blockPos);
|
||||
|
||||
// This is a bypass for the spawner block since MC complains about not having it
|
||||
#if POST_MC_1_17_1
|
||||
if (blockState.getBlock() instanceof SpawnerBlock) {
|
||||
return ((EntityBlock) blockState.getBlock()).newBlockEntity(blockPos, blockState);
|
||||
} else return null;
|
||||
#else
|
||||
if (blockState.getBlock() instanceof SpawnerBlock) {
|
||||
return ((EntityBlock) blockState.getBlock()).newBlockEntity(this);
|
||||
} else return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Skip BlockEntity stuff. It aren't really needed
|
||||
@@ -236,7 +249,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
}
|
||||
}
|
||||
if (chunkStatus != ChunkStatus.EMPTY && chunkStatus != debugTriggeredForStatus) {
|
||||
ApiShared.LOGGER.info("WorldGen requiring " + chunkStatus
|
||||
LOGGER.info("WorldGen requiring " + chunkStatus
|
||||
+ " outside expected range detected. Force passing EMPTY chunk and seeing if it works.");
|
||||
debugTriggeredForStatus = chunkStatus;
|
||||
}
|
||||
@@ -252,7 +265,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
// Override force use of my own light engine
|
||||
@Override
|
||||
public int getBrightness(LightLayer lightLayer, BlockPos blockPos) {
|
||||
if (lightMode != LightGenerationMode.FAST) {
|
||||
if (lightMode != ELightGenerationMode.FAST) {
|
||||
return light.getLayerListener(lightLayer).getLightValue(blockPos);
|
||||
}
|
||||
if (lightLayer == LightLayer.BLOCK)
|
||||
@@ -264,7 +277,7 @@ public class LightedWorldGenRegion extends WorldGenRegion {
|
||||
// Override force use of my own light engine
|
||||
@Override
|
||||
public int getRawBrightness(BlockPos blockPos, int i) {
|
||||
if (lightMode != LightGenerationMode.FAST) {
|
||||
if (lightMode != ELightGenerationMode.FAST) {
|
||||
return light.getRawBrightness(blockPos, i);
|
||||
}
|
||||
BlockPos p = super.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, blockPos);
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+110
-109
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
@@ -49,7 +49,6 @@ import net.minecraft.world.level.StructureFeatureManager;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
#endif
|
||||
|
||||
#if POST_MC_1_18_1
|
||||
import net.minecraft.world.level.levelgen.structure.StructureCheck;
|
||||
#endif
|
||||
@@ -59,16 +58,17 @@ import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
public class WorldGenStructFeatManager extends StructureFeatureManager {
|
||||
#else
|
||||
public class WorldGenStructFeatManager extends StructureManager {
|
||||
#endif
|
||||
#endif
|
||||
final WorldGenLevel genLevel;
|
||||
WorldGenSettings worldGenSettings;
|
||||
#if POST_MC_1_18_1
|
||||
StructureCheck structureCheck;
|
||||
|
||||
#endif
|
||||
public WorldGenStructFeatManager(WorldGenSettings worldGenSettings,
|
||||
WorldGenLevel genLevel #if POST_MC_1_18_1, StructureCheck structureCheck #endif) {
|
||||
WorldGenLevel genLevel #if POST_MC_1_18_1 , StructureCheck structureCheck #endif ) {
|
||||
|
||||
super(genLevel, worldGenSettings #if POST_MC_1_18_1, structureCheck #endif);
|
||||
super(genLevel, worldGenSettings #if POST_MC_1_18_1 , structureCheck #endif );
|
||||
this.genLevel = genLevel;
|
||||
this.worldGenSettings = worldGenSettings;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class WorldGenStructFeatManager extends StructureManager {
|
||||
public WorldGenStructFeatManager forWorldGenRegion(WorldGenRegion worldGenRegion) {
|
||||
if (worldGenRegion == genLevel)
|
||||
return this;
|
||||
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion #if POST_MC_1_18_1, structureCheck #endif);
|
||||
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion #if POST_MC_1_18_1 , structureCheck #endif );
|
||||
}
|
||||
|
||||
private ChunkAccess _getChunk(int x, int z, ChunkStatus status) {
|
||||
@@ -107,122 +107,123 @@ public class WorldGenStructFeatManager extends StructureManager {
|
||||
if (chunk == null) return false;
|
||||
return chunk.hasAnyStructureReferences();
|
||||
}
|
||||
#if MC_1_18_1
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public List<? extends StructureStart<?>> startsForFeature(SectionPos sectionPos,
|
||||
StructureFeature<?> structureFeature) {
|
||||
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
#if MC_1_18_1
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public List<? extends StructureStart<?>> startsForFeature(SectionPos sectionPos,
|
||||
StructureFeature<?> structureFeature) {
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...) with slight tweaks
|
||||
LongSet longSet = chunk.getReferencesForFeature(structureFeature);
|
||||
ImmutableList.Builder builder = ImmutableList.builder();
|
||||
LongIterator longIterator = longSet.iterator();
|
||||
while (longIterator.hasNext()) {
|
||||
long l = (Long)longIterator.next();
|
||||
SectionPos sectPos = SectionPos.of(new ChunkPos(l), genLevel.getMinSection());
|
||||
ChunkAccess startChunk = _getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS);
|
||||
if (startChunk == null) continue;
|
||||
StructureStart<?> structureStart = this.getStartForFeature(sectPos, structureFeature, startChunk);
|
||||
if (structureStart == null || !structureStart.isValid()) continue;
|
||||
builder.add(structureStart);
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...) with slight tweaks
|
||||
LongSet longSet = chunk.getReferencesForFeature(structureFeature);
|
||||
ImmutableList.Builder builder = ImmutableList.builder();
|
||||
LongIterator longIterator = longSet.iterator();
|
||||
while (longIterator.hasNext()) {
|
||||
long l = (Long)longIterator.next();
|
||||
SectionPos sectPos = SectionPos.of(new ChunkPos(l), genLevel.getMinSection());
|
||||
ChunkAccess startChunk = _getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS);
|
||||
if (startChunk == null) continue;
|
||||
StructureStart<?> structureStart = this.getStartForFeature(sectPos, structureFeature, startChunk);
|
||||
if (structureStart == null || !structureStart.isValid()) continue;
|
||||
builder.add(structureStart);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
#else
|
||||
#if PRE_MC_1_19
|
||||
@Override
|
||||
public List<StructureStart> startsForFeature(SectionPos sectionPos, Predicate<ConfiguredStructureFeature<?, ?>> predicate) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
Map<ConfiguredStructureFeature<?, ?>, LongSet> map = chunk.getAllReferences();
|
||||
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Iterator<Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet>> var5 = map.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet> entry = var5.next();
|
||||
ConfiguredStructureFeature<?, ?> configuredStructureFeature = entry.getKey();
|
||||
if (predicate.test(configuredStructureFeature)) {
|
||||
LongSet var10002 = (LongSet)entry.getValue();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForFeature(configuredStructureFeature, var10002, builder::add);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
#else
|
||||
#if PRE_MC_1_19
|
||||
@Override
|
||||
public List<StructureStart> startsForFeature(SectionPos sectionPos, Predicate<ConfiguredStructureFeature<?, ?>> predicate) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
Map<ConfiguredStructureFeature<?, ?>, LongSet> map = chunk.getAllReferences();
|
||||
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Iterator<Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet>> var5 = map.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<ConfiguredStructureFeature<?, ?>, LongSet> entry = var5.next();
|
||||
ConfiguredStructureFeature<?, ?> configuredStructureFeature = entry.getKey();
|
||||
if (predicate.test(configuredStructureFeature)) {
|
||||
LongSet var10002 = (LongSet)entry.getValue();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForFeature(configuredStructureFeature, var10002, builder::add);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructureStart> startsForFeature(SectionPos sectionPos, ConfiguredStructureFeature<?, ?> configuredStructureFeature) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (List<StructureStart>) Stream.empty();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
LongSet longSet = chunk.getReferencesForFeature(configuredStructureFeature);
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForFeature(configuredStructureFeature, longSet, builder::add);
|
||||
return builder.build();
|
||||
}
|
||||
@Override
|
||||
public List<StructureStart> startsForFeature(SectionPos sectionPos, ConfiguredStructureFeature<?, ?> configuredStructureFeature) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (List<StructureStart>) Stream.empty();
|
||||
|
||||
@Override
|
||||
public Map<ConfiguredStructureFeature<?, ?>, LongSet> getAllStructuresAt(BlockPos blockPos) {
|
||||
SectionPos sectionPos = SectionPos.of(blockPos);
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (Map<ConfiguredStructureFeature<?, ?>, LongSet>) Stream.empty();
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
LongSet longSet = chunk.getReferencesForFeature(configuredStructureFeature);
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForFeature(configuredStructureFeature, longSet, builder::add);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ConfiguredStructureFeature<?, ?>, LongSet> getAllStructuresAt(BlockPos blockPos) {
|
||||
SectionPos sectionPos = SectionPos.of(blockPos);
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (Map<ConfiguredStructureFeature<?, ?>, LongSet>) Stream.empty();
|
||||
return chunk.getAllReferences();
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public List<StructureStart> startsForStructure(ChunkPos sectionPos, Predicate<Structure> predicate) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x, sectionPos.z, ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public List<StructureStart> startsForStructure(ChunkPos sectionPos, Predicate<Structure> predicate) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x, sectionPos.z, ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return List.of();
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
Map<Structure, LongSet> map = chunk.getAllReferences();
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
Map<Structure, LongSet> map = chunk.getAllReferences();
|
||||
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Iterator<Map.Entry<Structure, LongSet>> var5 = map.entrySet().iterator();
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Iterator<Map.Entry<Structure, LongSet>> var5 = map.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<Structure, LongSet> entry = var5.next();
|
||||
Structure configuredStructureFeature = entry.getKey();
|
||||
if (predicate.test(configuredStructureFeature)) {
|
||||
LongSet var10002 = (LongSet)entry.getValue();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForStructure(configuredStructureFeature, var10002, builder::add);
|
||||
}
|
||||
while (var5.hasNext()) {
|
||||
Map.Entry<Structure, LongSet> entry = var5.next();
|
||||
Structure configuredStructureFeature = entry.getKey();
|
||||
if (predicate.test(configuredStructureFeature)) {
|
||||
LongSet var10002 = (LongSet) entry.getValue();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForStructure(configuredStructureFeature, var10002, builder::add);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructureStart> startsForStructure(SectionPos sectionPos, Structure structure) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (List<StructureStart>) Stream.empty();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
LongSet longSet = chunk.getReferencesForStructure(structure);
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForStructure(structure, longSet, builder::add);
|
||||
return builder.build();
|
||||
}
|
||||
@Override
|
||||
public List<StructureStart> startsForStructure(SectionPos sectionPos, Structure structure) {
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (List<StructureStart>) Stream.empty();
|
||||
|
||||
@Override
|
||||
public Map<Structure, LongSet> getAllStructuresAt(BlockPos blockPos) {
|
||||
SectionPos sectionPos = SectionPos.of(blockPos);
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (Map<Structure, LongSet>) Stream.empty();
|
||||
return chunk.getAllReferences();
|
||||
}
|
||||
#endif
|
||||
// Copied from StructureFeatureManager::startsForFeature(...)
|
||||
LongSet longSet = chunk.getReferencesForStructure(structure);
|
||||
ImmutableList.Builder<StructureStart> builder = ImmutableList.builder();
|
||||
Objects.requireNonNull(builder);
|
||||
this.fillStartsForStructure(structure, longSet, builder::add);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Structure, LongSet> getAllStructuresAt(BlockPos blockPos) {
|
||||
SectionPos sectionPos = SectionPos.of(blockPos);
|
||||
ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES);
|
||||
if (chunk == null) return (Map<Structure, LongSet>) Stream.empty();
|
||||
return chunk.getAllReferences();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+6
-15
@@ -1,48 +1,39 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.ThreadedParameters;
|
||||
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.util.objects.UncheckedInterruptedException;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.util.Mth;
|
||||
#if POST_MC_1_17_1
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
#endif
|
||||
#if PRE_MC_1_19
|
||||
import net.minecraft.world.level.StructureFeatureManager;
|
||||
#endif
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseSettings;
|
||||
#if POST_MC_1_18_1
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
#endif
|
||||
@@ -88,7 +79,7 @@ public final class StepNoise {
|
||||
chunk = environment.joinSync(environment.params.generator.fillFromNoise(Runnable::run, Blender.of(worldGenRegion), environment.params.randomState,
|
||||
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
|
||||
#endif
|
||||
LodUtil.checkInterruptsUnchecked(); // Speed up termination responsiveness
|
||||
UncheckedInterruptedException.throwIfInterrupted();
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
+46
-21
@@ -1,39 +1,42 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.common.wrappers.worldGeneration.step;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.ThreadedParameters;
|
||||
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class StepStructureStart {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class StepStructureStart
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private final BatchGenerationEnvironment environment;
|
||||
|
||||
/**
|
||||
@@ -57,22 +60,26 @@ public final class StepStructureStart {
|
||||
}
|
||||
|
||||
public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion,
|
||||
List<ChunkAccess> chunks) {
|
||||
|
||||
ArrayList<ChunkAccess> chunksToDo = new ArrayList<ChunkAccess>();
|
||||
List<ChunkAccess> chunks)
|
||||
{
|
||||
ArrayList<ChunkAccess> chunksToDo = new ArrayList<>();
|
||||
|
||||
for (ChunkAccess chunk : chunks) {
|
||||
if (chunk.getStatus().isOrAfter(STATUS)) continue;
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
chunksToDo.add(chunk);
|
||||
for (ChunkAccess chunk : chunks)
|
||||
{
|
||||
if (!chunk.getStatus().isOrAfter(STATUS))
|
||||
{
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
chunksToDo.add(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if PRE_MC_1_19
|
||||
if (environment.params.worldGenSettings.generateFeatures()) {
|
||||
#elif POST_MC_1_19
|
||||
if (environment.params.worldGenSettings.generateStructures()) {
|
||||
#endif
|
||||
for (ChunkAccess chunk : chunksToDo) {
|
||||
for (ChunkAccess chunk : chunksToDo)
|
||||
{
|
||||
// System.out.println("StepStructureStart: "+chunk.getPos());
|
||||
#if PRE_MC_1_19
|
||||
environment.params.generator.createStructures(environment.params.registry, tParams.structFeat, chunk, environment.params.structures,
|
||||
@@ -82,13 +89,31 @@ public final class StepStructureStart {
|
||||
environment.params.worldSeed);
|
||||
#endif
|
||||
#if POST_MC_1_18_1
|
||||
try {
|
||||
try
|
||||
{
|
||||
tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts());
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException firstEx)
|
||||
{
|
||||
// There's a rare issue with StructStart where it throws ArrayIndexOutOfBounds
|
||||
// This means the structFeat is corrupted (For some reason) and I need to reset it.
|
||||
// TODO: Figure out in the future why this happens even though I am using new structFeat
|
||||
throw new StepStructureStart.StructStartCorruptedException(e);
|
||||
// TODO: Figure out in the future why this happens even though I am using new structFeat - OLD
|
||||
|
||||
// reset the structureStart
|
||||
tParams.recreateStructureCheck();
|
||||
|
||||
try
|
||||
{
|
||||
// try running the structure logic again
|
||||
tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts());
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException secondEx)
|
||||
{
|
||||
// the structure logic failed again, log it and move on
|
||||
LOGGER.error("Unable to create structure starts for "+chunk.getPos()+". This is an error with MC's world generation. Ignoring and continuing generation. Error: "+secondEx.getMessage()); // don't log the full stack trace since it is long and will generally end up in MC's code
|
||||
|
||||
//throw new StepStructureStart.StructStartCorruptedException(secondEx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class StepSurface {
|
||||
|
||||
public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion,
|
||||
List<ChunkAccess> chunks) {
|
||||
ArrayList<ChunkAccess> chunksToDo = new ArrayList<ChunkAccess>();
|
||||
ArrayList<ChunkAccess> chunksToDo = new ArrayList<>();
|
||||
|
||||
for (ChunkAccess chunk : chunks) {
|
||||
if (chunk.getStatus().isOrAfter(STATUS)) continue;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
## Contributing
|
||||
|
||||
Thanks for your interest in contributing to Distant Horizons!
|
||||
|
||||
Check out the [Core Wiki](https://gitlab.com/jeseibel/distant-horizons-core/-/wikis/home) for a rough overview of Distant Horizon's project structure.
|
||||
|
||||
|
||||
|
||||
## Submitting a merge request
|
||||
|
||||
We love merge requests from everyone.
|
||||
|
||||
By sending a merge request, you agree to abide by the Distant Horizons [Contributor Code of Conduct](code_of_conduct.md). \
|
||||
Contributions to this project are under the [lesser GPL v3 license](LICENSE.txt) Copyright James Seibel, so please include the [license header](license_header.txt) at the top of any new code files.
|
||||
|
||||
1. Fork, then clone the repo: \
|
||||
`git clone --recurse-submodules https://gitlab.com/jeseibel/minecraft-lod-mod.git`
|
||||
|
||||
2. Set up your dev environment: \
|
||||
`./gradlew build`
|
||||
|
||||
3. (Optional) Confirm the tests pass: \
|
||||
`./gradlew test`
|
||||
|
||||
4. (Optional) Confirm the game runs with either Forge or Fabric: \
|
||||
`./gradlew forge:runClient` \
|
||||
`./gradlew fabric:runClient`
|
||||
|
||||
5. Make your change(s).
|
||||
6. Add tests (if appropriate).
|
||||
|
||||
7. Confirm the tests pass \
|
||||
`./gradlew test`
|
||||
|
||||
8. Confirm the game runs with both Forge **and** Fabric: \
|
||||
`./gradlew forge:runClient` \
|
||||
`./gradlew fabric:runClient` \
|
||||
When running the game, load or generate a world to confirm Distant Horizons initializes correctly.
|
||||
|
||||
9. Push to your fork, make sure to include the Core submodule, and submit a [new merge request](https://gitlab.com/jeseibel/minecraft-lod-mod/-/merge_requests/new).
|
||||
|
||||
|
||||
|
||||
## General Guidelines
|
||||
|
||||
* Check the existing issue list to verify that a given [bug](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/?sort=created_date&state=opened&label_name%5B%5D=Bug&first_page_size=100), [feature](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/?sort=created_date&state=opened&label_name%5B%5D=Feature&first_page_size=100), or [improvement](https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues/?sort=created_date&state=opened&label_name%5B%5D=Improvement&first_page_size=100) hasn't already been submitted.
|
||||
* Please open an issue if things aren't working as expected.
|
||||
* Open a merge request to: fix bugs, fix documentations, improve an existing system, or complete a feature.
|
||||
* When contributing:
|
||||
* Put any Minecraft independent code in the [Core](https://gitlab.com/jeseibel/distant-horizons-core) repo when possible.
|
||||
* Comment and format your code so other people can easily understand it.
|
||||
|
||||
-1
Submodule core deleted from 5f116f0ea7
Submodule
+1
Submodule coreSubProjects added at 64a1120be2
+58
-239
@@ -1,98 +1,39 @@
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
id "fabric-loom" version "1.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
// From parent
|
||||
apply plugin: "java"
|
||||
apply plugin: "architectury-plugin"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: "dev.architectury.loom"
|
||||
|
||||
archivesBaseName = rootProject.archives_base_name
|
||||
version = rootProject.mod_version //FIXME: Redef
|
||||
group = rootProject.maven_group
|
||||
|
||||
version = rootProject.mod_version+"-"+rootProject.minecraft_version+"-"+new Date().format("yyyy_MM_dd_HH_mm")
|
||||
|
||||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
accessWidenerPath.set(project(":common").file("src/main/resources/${acsessWidenerVersion}.lod.accesswidener"))
|
||||
accessWidenerPath = project(":common").file("src/main/resources/${accessWidenerVersion}.lod.accesswidener")
|
||||
|
||||
// "runs" isn't required, but when we do need it then it can be useful
|
||||
runs {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("Fabric Server")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
architectury {
|
||||
platformSetupLoomIde()
|
||||
fabric()
|
||||
remapJar {
|
||||
// Set the input jar for the task, also valid for remapSourcesJar
|
||||
inputFile = project(":fabric").file("build/libs/DistantHorizons-fabric-${rootProject.versionStr}-all.jar")
|
||||
}
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowMe
|
||||
implementation.extendsFrom shadowMe
|
||||
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentFabric.extendsFrom common
|
||||
|
||||
// The addModJar basically embeds the mod to the built jar
|
||||
addModJar
|
||||
include.extendsFrom addModJar
|
||||
modImplementation.extendsFrom addModJar
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
jar.dependsOn(project(":core").remapJar)
|
||||
remapSourcesJar.dependsOn(project(":core").remapJar)
|
||||
|
||||
repositories {
|
||||
// Required for ModMenu
|
||||
maven { url "https://maven.terraformersmc.com/" }
|
||||
|
||||
mavenCentral()
|
||||
|
||||
// For parchment mappings
|
||||
maven { url "https://maven.parchmentmc.org" }
|
||||
|
||||
// used to download and compile dependencies from git repos
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
// These 2 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/forge"
|
||||
content {
|
||||
includeGroup "forge-mod"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def addMod(path, enabled) {
|
||||
if (enabled == "2")
|
||||
dependencies { modImplementation(path) }
|
||||
@@ -101,43 +42,29 @@ def addMod(path, enabled) {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
|
||||
// The following line declares the mojmap mappings & parchment mappings
|
||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||
mappings loom.layered() {
|
||||
// Mojmap mappings
|
||||
officialMojangMappings()
|
||||
// Parchment mappings (it adds parameter mappings & javadoc)
|
||||
if (rootProject.minecraft_version != "1.19" && rootProject.minecraft_version != "1.19.1" && rootProject.minecraft_version != "1.19.2")
|
||||
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:${rootProject.parchment_version}@zip")
|
||||
else
|
||||
parchment("org.parchmentmc.data:parchment-1.18.2:${rootProject.parchment_version}@zip") // As 1.19 dosnt have parchment mappings yet, we use 1.18.2 mapping
|
||||
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:${rootProject.parchment_version}@zip")
|
||||
}
|
||||
|
||||
//Manifold
|
||||
annotationProcessor "systems.manifold:manifold-preprocessor:${rootProject.manifold_version}"
|
||||
|
||||
// Toml
|
||||
implementation("com.electronwill.night-config:toml:${rootProject.toml_version}")
|
||||
|
||||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
|
||||
// Do NOT use other classes from fabric loader unless working with fabric
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
|
||||
common(project(":core"))
|
||||
|
||||
// Fabric loader
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
|
||||
// Fabric API
|
||||
addModJar(fabricApi.module("fabric-events-interaction-v0", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-key-binding-api-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-rendering-v1", rootProject.fabric_api_version)) // TODO: Remove this as it is only needed in 1 line (FabricClientProxy)
|
||||
addModJar(fabricApi.module("fabric-api-base", rootProject.fabric_api_version))
|
||||
|
||||
// Mod Menu
|
||||
modImplementation("com.terraformersmc:modmenu:${rootProject.modmenu_version}")
|
||||
|
||||
|
||||
|
||||
// Starlight
|
||||
addMod("curse.maven:starlight-521783:${rootProject.starlight_version_fabric}", rootProject.enable_starlight)
|
||||
|
||||
@@ -145,10 +72,12 @@ dependencies {
|
||||
addMod("curse.maven:phosphor-372124:${rootProject.phosphor_version_fabric}", rootProject.enable_phosphor)
|
||||
|
||||
// Sodium
|
||||
addMod("curse.maven:sodium-394468:${rootProject.sodium_version}", rootProject.enable_sodium)
|
||||
implementation "org.joml:joml:1.10.2"
|
||||
modImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", rootProject.fabric_api_version))
|
||||
modImplementation(fabricApi.module("fabric-rendering-fluids-v1", rootProject.fabric_api_version))
|
||||
addMod("maven.modrinth:sodium:${rootProject.sodium_version}", rootProject.enable_sodium)
|
||||
// if (rootProject.enable_sodium != "0") {
|
||||
// implementation "org.joml:joml:1.10.2"
|
||||
// modImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", rootProject.fabric_api_version))
|
||||
// modImplementation(fabricApi.module("fabric-rendering-fluids-v1", rootProject.fabric_api_version))
|
||||
// }
|
||||
|
||||
// Lithium
|
||||
addMod("maven.modrinth:lithium:${rootProject.lithium_version}", rootProject.enable_lithium)
|
||||
@@ -159,6 +88,9 @@ dependencies {
|
||||
// BCLib
|
||||
addMod("com.github.paulevsGitch:BCLib:${rootProject.bclib_version}", rootProject.enable_bclib)
|
||||
|
||||
// Canvas
|
||||
addMod("io.vram:canvas-fabric-${project.canvas_version}", rootProject.enable_canvas)
|
||||
|
||||
// Immersive Portals
|
||||
/*
|
||||
modImplementation("com.github.qouteall.ImmersivePortalsMod:build:${rootProject.immersive_portals_version}") {
|
||||
@@ -173,133 +105,52 @@ dependencies {
|
||||
exclude(group: "net.fabricmc.fabric-api")
|
||||
transitive(false)
|
||||
}
|
||||
*/
|
||||
|
||||
// Toml
|
||||
shadowMe("com.electronwill.night-config:toml:${rootProject.toml_version}") {}
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowMe(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||
shadowMe files(project(":core").file("build/libs/DistantHorizons-${rootProject.mod_version}.jar"))
|
||||
|
||||
// Compression
|
||||
common 'org.tukaani:xz:1.9'
|
||||
common 'org.apache.commons:commons-compress:1.21'
|
||||
shadowMe 'org.tukaani:xz:1.9'
|
||||
shadowMe 'org.apache.commons:commons-compress:1.21'
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
task deleteResources(type: Delete) {
|
||||
delete file("build/resources/main")
|
||||
}
|
||||
// Copies the correct accesswidener and renames it
|
||||
task copyAccessWidener(type: Copy) {
|
||||
from project(":common").file("src/main/resources/${rootProject.acsessWidenerVersion}.lod.accesswidener")
|
||||
into(file("build/resources/main"))
|
||||
rename "${rootProject.acsessWidenerVersion}.lod.accesswidener", "lod.accesswidener"
|
||||
}
|
||||
|
||||
task copyCoreResources(type: Copy) {
|
||||
from fileTree(project(":core").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
task copyCommonResources(type: Copy) {
|
||||
from fileTree(project(":common").file("src/main/resources"))
|
||||
into file("build/resources/main")
|
||||
}
|
||||
|
||||
processResources {
|
||||
dependsOn(copyCoreResources)
|
||||
dependsOn(copyCommonResources)
|
||||
dependsOn(copyAccessWidener)
|
||||
|
||||
def resourceTargets = ["fabric.mod.json", "META-INF/mods.toml"] // Location of where to put
|
||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
||||
def replaceProperties = [
|
||||
version : mod_version,
|
||||
mod_name : mod_name,
|
||||
authors : mod_authors,
|
||||
description : mod_description,
|
||||
homepage : mod_homepage,
|
||||
source : mod_source,
|
||||
issues : mod_issues,
|
||||
minecraft_version : minecraft_version,
|
||||
compatible_minecraft_versions: compatible_minecraft_versions,
|
||||
java_version : java_version
|
||||
]
|
||||
// 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
|
||||
//TODO: Make Forge loader version also be relaced with non hardcoded value instead of "[36,42)"
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
dependsOn(copyCommonLoaderResources)
|
||||
dependsOn(deleteDuplicatedCommonLoaderResources)
|
||||
}
|
||||
|
||||
runClient {
|
||||
dependsOn(copyCoreResources)
|
||||
dependsOn(copyCommonResources)
|
||||
dependsOn(copyAccessWidener)
|
||||
dependsOn(copyCommonLoaderResources)
|
||||
dependsOn(deleteDuplicatedCommonLoaderResources)
|
||||
jvmArgs "-XX:-OmitStackTraceInFastThrow"
|
||||
finalizedBy(deleteResources)
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadowMe]
|
||||
relocate 'org.tukaani', 'shaded.tukaani'
|
||||
relocate 'org.apache.commons.compress', 'shaded.apache.commons.compress'
|
||||
relocate 'com.electronwill.nightconfig', 'shaded.electronwill.nightconfig'
|
||||
|
||||
relocate 'com.seibel.lod.common', 'fabric.com.seibel.lod.common'
|
||||
|
||||
classifier "dev-shadow"
|
||||
}
|
||||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
classifier null
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Title': rootProject.archives_base_name,
|
||||
'Implementation-Version': rootProject.mod_version,
|
||||
'Main-Class': 'com.seibel.lod.core.JarMain' // When changing the main of the jar change this line
|
||||
}
|
||||
classifier "dev"
|
||||
}
|
||||
//jar {
|
||||
// classifier "dev"
|
||||
//}
|
||||
|
||||
sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
from commonSources.archiveFile.map { zipTree(it) }
|
||||
|
||||
def fabricLikeSources = project(":fabricLike").sourcesJar
|
||||
dependsOn fabricLikeSources
|
||||
from fabricLikeSources.archiveFile.map { zipTree(it) }
|
||||
}
|
||||
|
||||
components.java {
|
||||
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
//components.java {
|
||||
// withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
// skip()
|
||||
// }
|
||||
//}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenFabric(MavenPublication) {
|
||||
artifactId = rootProject.archives_base_name + "-" + project.name
|
||||
artifactId = rootProject.mod_name + "-" + project.name
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
@@ -308,36 +159,4 @@ publishing {
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
}
|
||||
}
|
||||
|
||||
task printConfigurations {
|
||||
doLast {task ->
|
||||
println "Project Name: $name configurations:"
|
||||
configurations.each {
|
||||
println " $it.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
// Add Manifold Preprocessor
|
||||
// def excapedMCVersion = rootProject.minecraft_version.replace(".", "_")
|
||||
// options.compilerArgs += ['-Xplugin:Manifold', "-AMC_VERSION_${excapedMCVersion}"]
|
||||
//
|
||||
//options.compilerArgs += ['-deprecation']
|
||||
//options.compilerArgs += ['-verbose']
|
||||
//options.compilerArgs += ['-Xlint:unchecked']
|
||||
//options.compilerArgs += ['-Xdiags:verbose']
|
||||
//options.compilerArgs += ['-Xprint']
|
||||
//options.compilerArgs += ['-XprintProcessorInfo']
|
||||
//options.compilerArgs += ['-XprintRounds']
|
||||
|
||||
// println options.compilerArgs
|
||||
|
||||
// Set the java version
|
||||
options.compilerArgs += ['-Xplugin:Manifold']
|
||||
options.release = rootProject.java_version as Integer
|
||||
// TODO: make everything use java 8
|
||||
// options.release = 8 // Use Java 8 for everything so back porting is easier
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.lod.core.api.ClientApi;
|
||||
import com.seibel.lod.core.api.EventApi;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.WorldWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
|
||||
import com.seibel.lod.fabric.mixins.MixinUtilBackgroudThread;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/**
|
||||
* This handles all events sent to the client,
|
||||
* and is the starting point for most of the mod.
|
||||
*
|
||||
* @author coolGi
|
||||
* @author Ran
|
||||
* @version 11-23-2021
|
||||
*/
|
||||
public class ClientProxy
|
||||
{
|
||||
private final EventApi eventApi = EventApi.INSTANCE;
|
||||
private final ClientApi clientApi = ClientApi.INSTANCE;
|
||||
|
||||
public static Supplier<Boolean> isGenerationThreadChecker = null;
|
||||
|
||||
/**
|
||||
* Registers Fabric Events
|
||||
* @author Ran
|
||||
*/
|
||||
public void registerEvents() {
|
||||
/* Registor the mod accessor*/
|
||||
|
||||
/* World Events */
|
||||
//ServerTickEvents.START_SERVER_TICK.register(this::serverTickEvent);
|
||||
ServerTickEvents.END_SERVER_TICK.register(this::serverTickEvent);
|
||||
|
||||
/* World Events */
|
||||
//ServerChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent);
|
||||
#if PRE_MC_1_18_1 // in 1.18+, we use mixin hook in setClientLightReady(true)
|
||||
ClientChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent);
|
||||
#endif
|
||||
|
||||
/* World Events */
|
||||
ServerWorldEvents.LOAD.register((server, level) -> this.worldLoadEvent(level));
|
||||
ServerWorldEvents.UNLOAD.register((server, level) -> this.worldUnloadEvent(level));
|
||||
|
||||
/* The Client World Events are in the mixins
|
||||
Client world load event is in MixinClientLevel
|
||||
Client world unload event is in MixinMinecraft */
|
||||
/* The save events are in MixinServerLevel */
|
||||
|
||||
/* Keyboard Events */
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (client.player != null) onKeyInput();
|
||||
});
|
||||
isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void serverTickEvent(MinecraftServer server)
|
||||
{
|
||||
eventApi.serverTickEvent();
|
||||
}
|
||||
|
||||
public void chunkLoadEvent(LevelAccessor level, LevelChunk chunk)
|
||||
{
|
||||
clientApi.clientChunkLoadEvent(new ChunkWrapper(chunk, level),
|
||||
WorldWrapper.getWorldWrapper(level));
|
||||
}
|
||||
|
||||
public void worldSaveEvent()
|
||||
{
|
||||
eventApi.worldSaveEvent();
|
||||
}
|
||||
|
||||
/** This is also called when a new dimension loads */
|
||||
public void worldLoadEvent(Level level)
|
||||
{
|
||||
if (Minecraft.getInstance().screen instanceof TitleScreen) return;
|
||||
if (level != null) {
|
||||
eventApi.worldLoadEvent(WorldWrapper.getWorldWrapper(level));
|
||||
}
|
||||
}
|
||||
|
||||
public void worldUnloadEvent(Level level)
|
||||
{
|
||||
if (level != null) {
|
||||
eventApi.worldUnloadEvent(WorldWrapper.getWorldWrapper(level));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can someone tell me how to make this better
|
||||
* @author Ran
|
||||
*
|
||||
* public void blockChangeEvent(BlockEventData event) {
|
||||
* // we only care about certain block events
|
||||
* if (event.getClass() == BlockEventData.BreakEvent.class ||
|
||||
* event.getClass() == BlockEventData.EntityPlaceEvent.class ||
|
||||
* event.getClass() == BlockEventData.EntityMultiPlaceEvent.class ||
|
||||
* event.getClass() == BlockEventData.FluidPlaceBlockEvent.class ||
|
||||
* event.getClass() == BlockEventData.PortalSpawnEvent.class)
|
||||
* {
|
||||
* IChunkWrapper chunk = new ChunkWrapper(event.getWorld().getChunk(event.getPos()));
|
||||
* DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(event.getWorld().dimensionType());
|
||||
*
|
||||
* // recreate the LOD where the blocks were changed
|
||||
* eventApi.blockChangeEvent(chunk, dimType);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public void blockChangeEvent(LevelAccessor world, BlockPos pos) {
|
||||
IChunkWrapper chunk = new ChunkWrapper(world.getChunk(pos), world);
|
||||
DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(world.dimensionType());
|
||||
|
||||
// recreate the LOD where the blocks were changed
|
||||
eventApi.blockChangeEvent(chunk, dimType);
|
||||
}
|
||||
|
||||
private static final int[] KEY_TO_CHECK_FOR = {GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8};
|
||||
|
||||
HashSet<Integer> previousKeyDown = new HashSet<Integer>();
|
||||
|
||||
public void onKeyInput() {
|
||||
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
if (CONFIG.client().advanced().debugging().getDebugKeybindingsEnabled())
|
||||
{
|
||||
HashSet<Integer> currectKeyDown = new HashSet<Integer>();
|
||||
|
||||
// Note: Minecraft's InputConstants is same as GLFW Key values
|
||||
//TODO: Use mixin to hook directly into the GLFW Keyboard event in minecraft KeyboardHandler
|
||||
// Check all keys we need
|
||||
for (int i = GLFW.GLFW_KEY_A; i <= GLFW.GLFW_KEY_Z; i++) {
|
||||
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) {
|
||||
currectKeyDown.add(i);
|
||||
}
|
||||
}
|
||||
for (int i : KEY_TO_CHECK_FOR) {
|
||||
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) {
|
||||
currectKeyDown.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Diff and trigger events
|
||||
for (int c : currectKeyDown) {
|
||||
if (!previousKeyDown.contains(c)) {
|
||||
ClientApi.INSTANCE.keyPressedEvent(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the set
|
||||
previousKeyDown = currectKeyDown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.seibel.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.wrappers.DependencySetup;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class FabricClientMain implements ClientModInitializer
|
||||
{
|
||||
public static FabricClientProxy client_proxy;
|
||||
public static FabricServerProxy server_proxy;
|
||||
|
||||
|
||||
// Do if implements ClientModInitializer
|
||||
// This loads the mod before minecraft loads which causes a lot of issues
|
||||
@Override
|
||||
public void onInitializeClient()
|
||||
{
|
||||
DependencySetup.createClientBindings();
|
||||
FabricMain.init();
|
||||
|
||||
server_proxy = new FabricServerProxy(false);
|
||||
server_proxy.registerEvents();
|
||||
|
||||
client_proxy = new FabricClientProxy();
|
||||
client_proxy.registerEvents();
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> FabricMain.postInit());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.wrappers.McObjectConverter;
|
||||
import com.seibel.lod.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.lod.core.api.internal.ClientApi;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/**
|
||||
* This handles all events sent to the client,
|
||||
* and is the starting point for most of the mod.
|
||||
*
|
||||
* @author coolGi
|
||||
* @author Ran
|
||||
* @version 11-23-2021
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class FabricClientProxy
|
||||
{
|
||||
private final ClientApi clientApi = ClientApi.INSTANCE;
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
// TODO we shouldn't be filtering keys on the Forge/Fabric side, only in ClientApi
|
||||
private static final int[] KEY_TO_CHECK_FOR = { GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8, GLFW.GLFW_KEY_P};
|
||||
|
||||
HashSet<Integer> previouslyPressKeyCodes = new HashSet<>();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Registers Fabric Events
|
||||
* @author Ran
|
||||
*/
|
||||
public void registerEvents()
|
||||
{
|
||||
LOGGER.info("Registering Fabric Client Events");
|
||||
|
||||
|
||||
/* Register the mod needed event callbacks */
|
||||
|
||||
// ClientTickEvent
|
||||
ClientTickEvents.START_CLIENT_TICK.register((client) ->
|
||||
{
|
||||
//LOGGER.info("ClientTickEvent.START_CLIENT_TICK");
|
||||
ClientApi.INSTANCE.clientTickEvent();
|
||||
});
|
||||
|
||||
// ClientLevelLoadEvent - Done in MixinClientPacketListener
|
||||
// ClientLevelUnloadEvent - Done in MixinClientPacketListener
|
||||
|
||||
// ClientChunkLoadEvent
|
||||
// TODO: Is using setClientLightReady one still better?
|
||||
//#if PRE_MC_1_18_1 // in 1.18+, we use mixin hook in setClientLightReady(true)
|
||||
ClientChunkEvents.CHUNK_LOAD.register((level, chunk) ->
|
||||
{
|
||||
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper(level);
|
||||
ClientApi.INSTANCE.clientChunkLoadEvent(
|
||||
new ChunkWrapper(chunk, level, wrappedLevel),
|
||||
wrappedLevel
|
||||
);
|
||||
});
|
||||
|
||||
// (kinda) block break event
|
||||
AttackBlockCallback.EVENT.register((player, level, interactionHand, blockPos, direction) ->
|
||||
{
|
||||
// if we have access to the server, use the chunk save event instead
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
{
|
||||
// Since fabric doesn't have a client-side break-block API event, this is the next best thing
|
||||
ChunkAccess chunk = level.getChunk(blockPos);
|
||||
if (chunk != null)
|
||||
{
|
||||
// LOGGER.info("attack block at blockpos: " + blockPos);
|
||||
|
||||
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) level);
|
||||
ClientApi.INSTANCE.clientChunkLoadEvent(
|
||||
new ChunkWrapper(chunk, level, wrappedLevel),
|
||||
wrappedLevel
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// don't stop the callback
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
// (kinda) block place event
|
||||
UseBlockCallback.EVENT.register((player, level, hand, hitResult) ->
|
||||
{
|
||||
// if we have access to the server, use the chunk save event instead
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
{
|
||||
// Since fabric doesn't have a client-side place-block API event, this is the next best thing
|
||||
if (hitResult.getType() == HitResult.Type.BLOCK
|
||||
&& !hitResult.isInside())
|
||||
{
|
||||
ChunkAccess chunk = level.getChunk(hitResult.getBlockPos());
|
||||
if (chunk != null)
|
||||
{
|
||||
// LOGGER.info("use block at blockpos: " + hitResult.getBlockPos());
|
||||
|
||||
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) level);
|
||||
ClientApi.INSTANCE.clientChunkLoadEvent(
|
||||
new ChunkWrapper(chunk, level, wrappedLevel),
|
||||
wrappedLevel
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't stop the callback
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
//#endif
|
||||
// ClientChunkSaveEvent
|
||||
ClientChunkEvents.CHUNK_UNLOAD.register((level, chunk) ->
|
||||
{
|
||||
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper(level);
|
||||
ClientApi.INSTANCE.clientChunkSaveEvent(
|
||||
new ChunkWrapper(chunk, level, wrappedLevel),
|
||||
wrappedLevel
|
||||
);
|
||||
});
|
||||
|
||||
// RendererStartupEvent - Done in MixinGameRenderer
|
||||
// RendererShutdownEvent - Done in MixinGameRenderer
|
||||
|
||||
SodiumAccessor sodiumAccessor = (SodiumAccessor) ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
|
||||
|
||||
// ClientRenderLevelTerrainEvent
|
||||
WorldRenderEvents.AFTER_SETUP.register((renderContext) ->
|
||||
{
|
||||
if (sodiumAccessor != null)
|
||||
{
|
||||
sodiumAccessor.levelWrapper = ClientLevelWrapper.getWrapper(renderContext.world());
|
||||
sodiumAccessor.mcModelViewMatrix = McObjectConverter.Convert(renderContext.matrixStack().last().pose());
|
||||
sodiumAccessor.mcProjectionMatrix = McObjectConverter.Convert(renderContext.projectionMatrix());
|
||||
sodiumAccessor.partialTicks = renderContext.tickDelta();
|
||||
}
|
||||
else
|
||||
{
|
||||
clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()),
|
||||
McObjectConverter.Convert(renderContext.matrixStack().last().pose()),
|
||||
McObjectConverter.Convert(renderContext.projectionMatrix()),
|
||||
renderContext.tickDelta());
|
||||
}
|
||||
});
|
||||
|
||||
// Debug keyboard event
|
||||
// FIXME: Use better hooks so it doesn't trigger even in text boxes
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client ->
|
||||
{
|
||||
if (client.player != null && isValidTime())
|
||||
{
|
||||
onKeyInput();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isValidTime() { return !(Minecraft.getInstance().screen instanceof TitleScreen); }
|
||||
|
||||
// public void blockChangeEvent(LevelAccessor world, BlockPos pos) {
|
||||
// if (!isValidTime()) return;
|
||||
// IChunkWrapper chunk = new ChunkWrapper(world.getChunk(pos), world);
|
||||
// DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(world.dimensionType());
|
||||
//
|
||||
// // recreate the LOD where the blocks were changed
|
||||
// // TODO: serverApi.blockChangeEvent(chunk, dimType);
|
||||
// }
|
||||
|
||||
public void onKeyInput()
|
||||
{
|
||||
HashSet<Integer> currentKeyDown = new HashSet<>();
|
||||
|
||||
// Note: Minecraft's InputConstants is same as GLFW Key values
|
||||
//TODO: Use mixin to hook directly into the GLFW Keyboard event in minecraft KeyboardHandler
|
||||
// Check all keys we need
|
||||
for (int keyCode = GLFW.GLFW_KEY_A; keyCode <= GLFW.GLFW_KEY_Z; keyCode++)
|
||||
{
|
||||
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), keyCode))
|
||||
{
|
||||
currentKeyDown.add(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
for (int keyCode : KEY_TO_CHECK_FOR)
|
||||
{
|
||||
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), keyCode))
|
||||
{
|
||||
currentKeyDown.add(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Diff and trigger events
|
||||
for (int keyCode : currentKeyDown)
|
||||
{
|
||||
if (!previouslyPressKeyCodes.contains(keyCode))
|
||||
{
|
||||
ClientApi.INSTANCE.keyPressedEvent(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the set
|
||||
previouslyPressKeyCodes = currentKeyDown;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.seibel.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.wrappers.DependencySetup;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Environment(EnvType.SERVER)
|
||||
public class FabricDedicatedServerMain implements DedicatedServerModInitializer
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger(FabricDedicatedServerMain.class.getSimpleName());
|
||||
|
||||
public static FabricServerProxy server_proxy;
|
||||
public boolean hasPostSetupDone = false;
|
||||
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
DependencySetup.createServerBindings();
|
||||
FabricMain.init();
|
||||
|
||||
server_proxy = new FabricServerProxy(true);
|
||||
server_proxy.registerEvents();
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register((server) -> {
|
||||
if (hasPostSetupDone) return;
|
||||
hasPostSetupDone = true;
|
||||
LodUtil.assertTrue(server instanceof DedicatedServer);
|
||||
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer) server;
|
||||
FabricMain.postInit();
|
||||
LOGGER.info("Dedicated server inited at {}", server.getServerDirectory());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.fabric;
|
||||
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.DependencyInjection.ApiEventInjector;
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.*;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.BCLibAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.OptifineAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.StarlightAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.FabricDependencySetup;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Initialize and setup the Mod. <br>
|
||||
* If you are looking for the real start of the mod
|
||||
* check out the ClientProxy.
|
||||
*
|
||||
* @author coolGi
|
||||
* @author Ran
|
||||
* @version 9-2-2022
|
||||
*/
|
||||
public class FabricMain
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public static void postInit() {
|
||||
LOGGER.info("Post-Initializing Mod");
|
||||
FabricDependencySetup.runDelayedSetup();
|
||||
|
||||
if (Config.Client.Graphics.FogQuality.disableVanillaFog.get() && SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib"))
|
||||
ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).setRenderCustomFog(false); // Remove BCLib's fog
|
||||
|
||||
LOGGER.info("Mod Post-Initialized");
|
||||
}
|
||||
|
||||
|
||||
// This loads the mod after minecraft loads which doesn't causes a lot of issues
|
||||
public static void init()
|
||||
{
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
|
||||
|
||||
LOGGER.info("Initializing Mod");
|
||||
LodCommonMain.startup(null);
|
||||
FabricDependencySetup.createInitialBindings();
|
||||
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("sodium")) {
|
||||
ModAccessorInjector.INSTANCE.bind(ISodiumAccessor.class, new SodiumAccessor());
|
||||
}
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("starlight")) {
|
||||
ModAccessorInjector.INSTANCE.bind(IStarlightAccessor.class, new StarlightAccessor());
|
||||
}
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("optifine")) {
|
||||
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
|
||||
}
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib")) {
|
||||
ModAccessorInjector.INSTANCE.bind(IBCLibAccessor.class, new BCLibAccessor());
|
||||
}
|
||||
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
|
||||
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
|
||||
|
||||
// Init config
|
||||
// The reason im initialising in this rather than the post init process is cus im using this for the auto updater
|
||||
LodCommonMain.initConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.seibel.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.networking.Networking;
|
||||
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.lod.core.api.internal.ServerApi;
|
||||
import com.seibel.lod.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* This handles all events sent to the server,
|
||||
* and is the starting point for most of the mod.
|
||||
*
|
||||
* @author Ran
|
||||
* @author Tomlee
|
||||
* @version 5-11-2022
|
||||
*/
|
||||
public class FabricServerProxy
|
||||
{
|
||||
private static final ServerApi SERVER_API = ServerApi.INSTANCE;
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private final boolean isDedicated;
|
||||
public static Supplier<Boolean> isGenerationThreadChecker = null;
|
||||
|
||||
|
||||
|
||||
public FabricServerProxy(boolean isDedicated)
|
||||
{
|
||||
this.isDedicated = isDedicated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean isValidTime()
|
||||
{
|
||||
if (isDedicated)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//FIXME: This may cause init issue...
|
||||
return !(Minecraft.getInstance().screen instanceof TitleScreen);
|
||||
}
|
||||
|
||||
private ClientLevelWrapper getClientLevelWrapper(ClientLevel level) { return ClientLevelWrapper.getWrapper(level); }
|
||||
private ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); }
|
||||
|
||||
/** Registers Fabric Events */
|
||||
public void registerEvents()
|
||||
{
|
||||
LOGGER.info("Registering Fabric Server Events");
|
||||
isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread;
|
||||
|
||||
/* Register the mod needed event callbacks */
|
||||
|
||||
// TEST EVENT
|
||||
//ServerTickEvents.END_SERVER_TICK.register(this::tester);
|
||||
|
||||
// ServerTickEvent
|
||||
ServerTickEvents.END_SERVER_TICK.register((server) -> SERVER_API.serverTickEvent());
|
||||
|
||||
// ServerWorldLoadEvent
|
||||
//TODO: Check if both of these use the correct timed events. (i.e. is it 'ed' or 'ing' one?)
|
||||
ServerLifecycleEvents.SERVER_STARTING.register((server) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLoadEvent(isDedicated);
|
||||
}
|
||||
});
|
||||
// ServerWorldUnloadEvent
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register((server) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverUnloadEvent();
|
||||
}
|
||||
});
|
||||
|
||||
// ServerLevelLoadEvent
|
||||
ServerWorldEvents.LOAD.register((server, level) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLevelLoadEvent(getServerLevelWrapper(level));
|
||||
}
|
||||
});
|
||||
// ServerLevelUnloadEvent
|
||||
ServerWorldEvents.UNLOAD.register((server, level) ->
|
||||
{
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLevelUnloadEvent(getServerLevelWrapper(level));
|
||||
}
|
||||
});
|
||||
|
||||
// ServerChunkLoadEvent
|
||||
ServerChunkEvents.CHUNK_LOAD.register((server, chunk) ->
|
||||
{
|
||||
ILevelWrapper level = getServerLevelWrapper((ServerLevel) chunk.getLevel());
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverChunkLoadEvent(
|
||||
new ChunkWrapper(chunk, chunk.getLevel(), level),
|
||||
level);
|
||||
}
|
||||
});
|
||||
// ServerChunkSaveEvent - Done in MixinChunkMap
|
||||
}
|
||||
|
||||
// This just exists here for testing purposes, it'll be removed in the future
|
||||
public void tester(MinecraftServer server)
|
||||
{ // I disabled the Networking functions for now so this will not work atm - coolGi
|
||||
for (ServerPlayer player : server.getPlayerList().getPlayers())
|
||||
{
|
||||
FriendlyByteBuf payload = Networking.createNew();
|
||||
payload.writeInt(1);
|
||||
System.out.println("Sending int 1");
|
||||
Networking.send(player, payload);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric;
|
||||
|
||||
import com.seibel.lod.common.LodCommonMain;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import com.seibel.lod.core.api.ClientApi;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.ModChecker;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.OptifineAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.StarlightAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.FabricDependencySetup;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
/**
|
||||
* Initialize and setup the Mod. <br>
|
||||
* If you are looking for the real start of the mod
|
||||
* check out the ClientProxy.
|
||||
*
|
||||
* @author coolGi
|
||||
* @author Ran
|
||||
* @version 12-1-2021
|
||||
*/
|
||||
public class Main implements ClientModInitializer
|
||||
{
|
||||
// This is a client mod so it should implement ClientModInitializer and in fabric.mod.json it should have "environment": "client"
|
||||
// Once it works on servers change the implement to ModInitializer and in fabric.mod.json it should be "environment": "*"
|
||||
|
||||
public static ClientProxy client_proxy;
|
||||
|
||||
|
||||
// Do if implements ClientModInitializer
|
||||
// This loads the mod before minecraft loads which causes a lot of issues
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// no.
|
||||
}
|
||||
|
||||
// This loads the mod after minecraft loads which doesn't causes a lot of issues
|
||||
public static void init() {
|
||||
LodCommonMain.initConfig();
|
||||
LodCommonMain.startup(null, false);
|
||||
FabricDependencySetup.createInitialBindings();
|
||||
FabricDependencySetup.finishBinding();
|
||||
ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
// Check if this works
|
||||
client_proxy = new ClientProxy();
|
||||
client_proxy.registerEvents();
|
||||
if (SingletonHandler.get(IModChecker.class).isModLoaded("sodium")) {
|
||||
ModAccessorHandler.bind(ISodiumAccessor.class, new SodiumAccessor());
|
||||
}
|
||||
if (SingletonHandler.get(IModChecker.class).isModLoaded("starlight")) {
|
||||
ModAccessorHandler.bind(IStarlightAccessor.class, new StarlightAccessor());
|
||||
}
|
||||
if (SingletonHandler.get(IModChecker.class).isModLoaded("optifine")) {
|
||||
ModAccessorHandler.bind(IOptifineAccessor.class, new OptifineAccessor());
|
||||
}
|
||||
|
||||
ModAccessorHandler.finishBinding();
|
||||
}
|
||||
|
||||
public static void initServer() {
|
||||
LodCommonMain.initConfig();
|
||||
LodCommonMain.startup(null, true);
|
||||
FabricDependencySetup.createInitialBindings();
|
||||
FabricDependencySetup.finishBinding();
|
||||
ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.seibel.lod.fabric.mixins;
|
||||
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author coolGi
|
||||
* @author cortex
|
||||
*/
|
||||
// TODO: Move to common if possible
|
||||
public class FabricMixinPlugin implements IMixinConfigPlugin {
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if (mixinClassName.contains(".mods.")) { // If the mixin wants to go into a mod then we check if that mod is loaded or not
|
||||
return FabricLoader.getInstance().isModLoaded(
|
||||
mixinClassName
|
||||
// What these 2 regex's do is get the mod name that we are checking out of the mixinClassName
|
||||
// Eg. "com.seibel.lod.mixins.mods.sodium.MixinSodiumChunkRenderer" turns into "sodium"
|
||||
.replaceAll("^.*mods.", "") // Replaces everything before the mods
|
||||
.replaceAll("\\..*$", "") // Replaces everything after the mod name
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric.mixins;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(DedicatedServer.class)
|
||||
public class MixinDedicatedServer {
|
||||
@Inject(method = "initServer", at = @At("TAIL"))
|
||||
public void initServer(CallbackInfoReturnable<Boolean> cir) {
|
||||
Main.initServer();
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric.mixins;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.main.GameConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Loads the mod after minecraft loads.
|
||||
* @author Ran
|
||||
*/
|
||||
@Mixin(value = Minecraft.class)
|
||||
public class MixinMinecraft {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void startMod(GameConfig gameConfig, CallbackInfo ci) {
|
||||
Main.init();
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
#if POST_MC_1_18_2
|
||||
import net.minecraft.core.Holder;
|
||||
#endif
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* This class is used for world loading events
|
||||
* @author Ran
|
||||
*
|
||||
* FIXME: Why does forge not have the 1.18+ onChunkLightReady mixin?
|
||||
*/
|
||||
|
||||
@Mixin(ClientLevel.class)
|
||||
public class MixinClientLevel {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey resourceKey,
|
||||
#if POST_MC_1_18_2 Holder holder, #else DimensionType dimensionType, #endif int i,
|
||||
#if POST_MC_1_18_1 int j, #endif Supplier supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
|
||||
Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this);
|
||||
}
|
||||
|
||||
#if POST_MC_1_18_1
|
||||
@Inject(method = "setLightReady", at = @At("HEAD"))
|
||||
private void onChunkLightReady(int x, int z, CallbackInfo ci) {
|
||||
ClientLevel l = (ClientLevel) (Object) this;
|
||||
LevelChunk chunk = l.getChunkSource().getChunk(x, z, false);
|
||||
if (chunk!=null&& !chunk.isClientLightReady())
|
||||
Main.client_proxy.chunkLoadEvent(l, chunk);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* This class is used for world unloading events
|
||||
* @author Ran
|
||||
*/
|
||||
@Mixin(Minecraft.class)
|
||||
public class MixinMinecraft {
|
||||
@Shadow @Nullable public ClientLevel level;
|
||||
|
||||
@Inject(method = "setLevel", at = @At("HEAD"))
|
||||
private void unloadWorldEvent_sL(ClientLevel clientLevel, CallbackInfo ci) {
|
||||
if (level != null) Main.client_proxy.worldUnloadEvent(level);
|
||||
}
|
||||
|
||||
@Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"))
|
||||
private void unloadWorldEvent_cL(Screen screen, CallbackInfo ci) {
|
||||
if (this.level != null) Main.client_proxy.worldUnloadEvent(this.level);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
import com.seibel.lod.fabric.Main;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.ProgressListener;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* This class is used for world saving events
|
||||
* @author Ran
|
||||
*/
|
||||
@Mixin(ServerLevel.class)
|
||||
public class MixinServerLevel {
|
||||
#if PRE_MC_1_17_1
|
||||
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;save(Z)V", shift = At.Shift.AFTER))
|
||||
private void saveWorldEvent(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
|
||||
Main.client_proxy.worldSaveEvent();
|
||||
}
|
||||
#else
|
||||
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;saveAll()V", shift = At.Shift.AFTER))
|
||||
private void saveWorldEvent_sA(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
|
||||
Main.client_proxy.worldSaveEvent();
|
||||
}
|
||||
@Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;autoSave()V", shift = At.Shift.AFTER))
|
||||
private void saveWorldEvent_aS(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
|
||||
Main.client_proxy.worldSaveEvent();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.seibel.lod.fabric.mixins.mods.sodium;
|
||||
|
||||
import com.seibel.lod.core.api.internal.ClientApi;
|
||||
import com.seibel.lod.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.ChunkCameraContext;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderList;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.RegionChunkRenderer;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RegionChunkRenderer.class)
|
||||
public class MixinSodiumChunkRenderer {
|
||||
@Unique SodiumAccessor accessor = null;
|
||||
@Inject(remap = false, method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ShaderChunkRenderer;begin(Lme/jellysquid/mods/sodium/client/render/chunk/passes/BlockRenderPass;)V", shift = At.Shift.AFTER))
|
||||
private void injectDHLoDRendering(ChunkRenderMatrices matrices, CommandList commandList, ChunkRenderList list, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfo ci) {
|
||||
if (accessor == null) {
|
||||
accessor = (SodiumAccessor)ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class);
|
||||
}
|
||||
if (pass.equals(BlockRenderPass.SOLID)) {
|
||||
//TODO: use matrices.modelView() and matrices.projection() instead of
|
||||
// SodiumAccessor.mcModelViewMatrix,
|
||||
// SodiumAccessor.mcProjectionMatrix,
|
||||
ClientApi.INSTANCE.renderLods(accessor.levelWrapper,
|
||||
accessor.mcModelViewMatrix,
|
||||
accessor.mcProjectionMatrix,
|
||||
accessor.partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 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.lod.fabric.mixins.server;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seibel.lod.fabric.FabricServerProxy;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.seibel.lod.core.util.objects.DummyRunExecutorService;
|
||||
|
||||
import net.minecraft.Util;
|
||||
|
||||
@Mixin(Util.class)
|
||||
public class MixinUtilBackgroundThread
|
||||
{
|
||||
@Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true)
|
||||
private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable<ExecutorService> ci)
|
||||
{
|
||||
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
|
||||
{
|
||||
//ApiShared.LOGGER.info("util backgroundExecutor triggered");
|
||||
ci.setReturnValue(new DummyRunExecutorService());
|
||||
}
|
||||
}
|
||||
|
||||
#if POST_MC_1_17_1
|
||||
@Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Runnable;",
|
||||
at = @At("HEAD"), cancellable = true)
|
||||
private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable<Runnable> ci)
|
||||
{
|
||||
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
|
||||
{
|
||||
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered");
|
||||
ci.setReturnValue(r);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if POST_MC_1_18_1
|
||||
@Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/util/function/Supplier;)Ljava/util/function/Supplier;",
|
||||
at = @At("HEAD"), cancellable = true)
|
||||
private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier<?> r, CallbackInfoReturnable<Supplier<?>> ci)
|
||||
{
|
||||
if (FabricServerProxy.isGenerationThreadChecker != null && FabricServerProxy.isGenerationThreadChecker.get())
|
||||
{
|
||||
//ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered");
|
||||
ci.setReturnValue(r);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,29 +1,28 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.fabric.wrappers;
|
||||
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.common.wrappers.config.LodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.lod.fabric.wrappers.modAccessor.ModChecker;
|
||||
import com.seibel.lod.fabriclike.wrappers.FabricLikeDependencySetup;
|
||||
|
||||
/**
|
||||
* Binds all necessary dependencies, so we
|
||||
@@ -37,14 +36,13 @@ import com.seibel.lod.fabric.wrappers.modAccessor.ModChecker;
|
||||
*/
|
||||
public class FabricDependencySetup
|
||||
{
|
||||
public static void createInitialBindings()
|
||||
{
|
||||
SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
|
||||
SingletonHandler.bind(ILodConfigWrapperSingleton.class, LodConfigWrapperSingleton.INSTANCE);
|
||||
public static void createInitialBindings() {
|
||||
SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
FabricLikeDependencySetup.createInitialBindings();
|
||||
}
|
||||
|
||||
public static void finishBinding() {
|
||||
SingletonHandler.finishBinding();
|
||||
|
||||
public static void runDelayedSetup() {
|
||||
FabricLikeDependencySetup.runDelayedSetup();
|
||||
SingletonInjector.INSTANCE.runDelayedSetup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.lod.fabric.wrappers.config;
|
||||
|
||||
import com.seibel.lod.common.wrappers.config.ConfigGui;
|
||||
import com.seibel.lod.common.wrappers.gui.GetConfigScreen;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* For making the config show up in modmenu
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModMenuIntegration implements ModMenuApi {
|
||||
// For the custom config code
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return parent -> ConfigGui.getScreen(parent, "");
|
||||
return parent -> GetConfigScreen.getScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user