From 32973e2630cce2bd8e31cf10dfa61109b5e020f4 Mon Sep 17 00:00:00 2001 From: NaoCraftLab Date: Sun, 22 Dec 2024 19:37:34 +0400 Subject: [PATCH] Fix game crash when spectating a mob in spectator mode --- .github/workflows/pipeline.yml | 150 --------------- .gitignore | 1 + CHANGELOG.md | 6 + README.md | 2 +- build.gradle | 116 ++++++++++++ build.gradle.kts | 175 ------------------ buildPluginSrc/build.gradle | 29 +++ .../ApplyExtPropertiesPlugin.groovy | 37 ++++ .../LoadPropertiesSettingsPlugin.groovy | 31 ++++ common/build.gradle | 23 +++ .../foggypalegarden/FoggyPaleGarden.java | 9 + .../foggypalegarden/command/FpgCommand.java | 1 + .../foggypalegarden/config/ConfigFacade.java | 31 +++- .../config/ConfigMigrator.java | 0 .../config/main/MainConfig.java | 0 .../config/main/MainConfigV1.java | 0 .../main/MainConfigV1ToV2Converter.java | 2 +- .../config/main/MainConfigV2.java | 8 +- .../main/MainConfigV2ToV3Converter.java | 2 +- .../config/main/MainConfigV3.java | 8 +- .../config/preset/FogPreset.java | 0 .../config/preset/FogPresetV2.java | 2 +- .../preset/FogPresetV2ToV3Converter.java | 2 +- .../config/preset/FogPresetV3.java | 2 +- .../MainConfigV1ToFogPresetsV2Converter.java | 2 +- .../foggypalegarden/domain/model/Color.java | 0 .../domain/model/Environment.java | 0 .../domain/model/FogCharacteristics.java | 2 +- .../foggypalegarden/domain/model/Weather.java | 0 .../domain/service/FogService.java | 0 ...FoggyPaleGardenConfigurationException.java | 2 +- .../FoggyPaleGardenEnvironmentException.java | 2 +- .../exception/FoggyPaleGardenException.java | 0 .../gui/ClothConfigScreen.java | 38 ++-- .../gui/NoClothConfigScreen.java | 30 +++ .../mixin/PaleGardenFogMixin.java | 91 +++++---- .../foggypalegarden/util/Converter.java | 0 .../foggypalegarden/util/FpgCollections.java | 0 .../foggypalegarden/util/FpgFiles.java | 0 .../foggypalegarden/util/Pair.java | 0 .../resources/assets/foggypalegarden/icon.png | Bin .../assets/foggypalegarden/lang/ar_sa.json | 0 .../assets/foggypalegarden/lang/be_by.json | 0 .../assets/foggypalegarden/lang/de_de.json | 0 .../assets/foggypalegarden/lang/en_us.json | 0 .../assets/foggypalegarden/lang/es_mx.json | 0 .../assets/foggypalegarden/lang/fr_fr.json | 0 .../assets/foggypalegarden/lang/it_it.json | 0 .../assets/foggypalegarden/lang/ja_jp.json | 0 .../assets/foggypalegarden/lang/ka_ge.json | 0 .../assets/foggypalegarden/lang/kk_kz.json | 0 .../assets/foggypalegarden/lang/ko_kr.json | 0 .../assets/foggypalegarden/lang/pt_br.json | 0 .../assets/foggypalegarden/lang/ru_ru.json | 0 .../assets/foggypalegarden/lang/sv_se.json | 0 .../assets/foggypalegarden/lang/uk_ua.json | 0 .../assets/foggypalegarden/lang/zh_cn.json | 0 .../foggypalegarden-common.mixins.json | 8 +- fabric/build.gradle | 56 ++++++ .../fabric/FoggyPaleGardenClientMod.java | 29 +++ .../command/FpgNoFogGameModeCommand.java | 71 +++++++ .../fabric/command/FpgPresetCommand.java | 70 +++++++ .../command/FpgReloadConfigCommand.java | 43 +++++ .../integration/ModMenuIntegration.java | 4 +- .../src}/main/resources/fabric.mod.json | 20 +- forge/build.gradle | 58 ++++++ forge/gradle.properties | 1 + .../forge/FoggyPaleGardenClientMod.java | 39 ++++ .../command/FpgNoFogGameModeCommand.java | 93 ++++++++++ .../forge/command/FpgPresetCommand.java | 78 ++++++++ .../forge/command/FpgReloadConfigCommand.java | 49 +++++ forge/src/main/resources/META-INF/mods.toml | 34 ++++ forge/src/main/resources/pack.mcmeta | 6 + gradle.properties | 55 ++++-- mcVersions/1.21.2-snapshot.properties | 18 ++ mcVersions/1.21.2.properties | 19 ++ mcVersions/1.21.3.properties | 20 ++ neoforge/build.gradle | 48 +++++ neoforge/gradle.properties | 1 + .../neoforge/FoggyPaleGardenClientMod.java | 47 +++++ .../command/FpgNoFogGameModeCommand.java | 93 ++++++++++ .../neoforge/command/FpgPresetCommand.java | 78 ++++++++ .../command/FpgReloadConfigCommand.java | 49 +++++ .../resources/META-INF/neoforge.mods.toml | 30 +++ settings.gradle | 57 ++++++ settings.gradle.kts | 19 -- .../FoggyPaleGardenClientMod.java | 57 ------ .../command/FpgNoFogGameModeCommand.java | 70 ------- .../command/FpgPresetCommand.java | 60 ------ .../command/FpgReloadConfigCommand.java | 37 ---- .../gui/NoClothConfigScreen.java | 33 ---- .../foggypalegarden/TestUtils.java | 18 -- 92 files changed, 1540 insertions(+), 732 deletions(-) delete mode 100644 .github/workflows/pipeline.yml create mode 100644 build.gradle delete mode 100644 build.gradle.kts create mode 100644 buildPluginSrc/build.gradle create mode 100644 buildPluginSrc/src/main/groovy/com/naocraftlab/ApplyExtPropertiesPlugin.groovy create mode 100644 buildPluginSrc/src/main/groovy/com/naocraftlab/LoadPropertiesSettingsPlugin.groovy create mode 100644 common/build.gradle create mode 100644 common/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGarden.java rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java (87%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java (83%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/ConfigMigrator.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfig.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java (90%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java (73%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java (84%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java (73%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPreset.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java (99%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java (98%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java (99%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java (98%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/domain/model/Color.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/domain/model/Environment.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java (84%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/domain/model/Weather.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/domain/service/FogService.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java (74%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java (75%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenException.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java (62%) create mode 100644 common/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java (64%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/util/Converter.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/util/FpgCollections.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/util/FpgFiles.java (100%) rename {src => common/src}/main/java/com/naocraftlab/foggypalegarden/util/Pair.java (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/icon.png (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/ar_sa.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/be_by.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/de_de.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/en_us.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/es_mx.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/fr_fr.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/it_it.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/ja_jp.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/ka_ge.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/kk_kz.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/ko_kr.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/pt_br.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/ru_ru.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/sv_se.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/uk_ua.json (100%) rename {src => common/src}/main/resources/assets/foggypalegarden/lang/zh_cn.json (100%) rename src/main/resources/foggypalegarden.mixins.json => common/src/main/resources/foggypalegarden-common.mixins.json (57%) create mode 100644 fabric/build.gradle create mode 100644 fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/FoggyPaleGardenClientMod.java create mode 100644 fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgNoFogGameModeCommand.java create mode 100644 fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgPresetCommand.java create mode 100644 fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgReloadConfigCommand.java rename {src/main/java/com/naocraftlab/foggypalegarden => fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric}/integration/ModMenuIntegration.java (87%) rename {src => fabric/src}/main/resources/fabric.mod.json (71%) create mode 100644 forge/build.gradle create mode 100644 forge/gradle.properties create mode 100755 forge/src/main/java/com/naocraftlab/foggypalegarden/forge/FoggyPaleGardenClientMod.java create mode 100644 forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgNoFogGameModeCommand.java create mode 100644 forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgPresetCommand.java create mode 100644 forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgReloadConfigCommand.java create mode 100644 forge/src/main/resources/META-INF/mods.toml create mode 100644 forge/src/main/resources/pack.mcmeta create mode 100644 mcVersions/1.21.2-snapshot.properties create mode 100644 mcVersions/1.21.2.properties create mode 100644 mcVersions/1.21.3.properties create mode 100644 neoforge/build.gradle create mode 100644 neoforge/gradle.properties create mode 100644 neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/FoggyPaleGardenClientMod.java create mode 100644 neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgNoFogGameModeCommand.java create mode 100644 neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgPresetCommand.java create mode 100644 neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgReloadConfigCommand.java create mode 100644 neoforge/src/main/resources/META-INF/neoforge.mods.toml create mode 100644 settings.gradle delete mode 100644 settings.gradle.kts delete mode 100644 src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGardenClientMod.java delete mode 100644 src/main/java/com/naocraftlab/foggypalegarden/command/FpgNoFogGameModeCommand.java delete mode 100644 src/main/java/com/naocraftlab/foggypalegarden/command/FpgPresetCommand.java delete mode 100644 src/main/java/com/naocraftlab/foggypalegarden/command/FpgReloadConfigCommand.java delete mode 100644 src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java delete mode 100644 src/test/java/com/naocraftlab/foggypalegarden/TestUtils.java diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml deleted file mode 100644 index d51eb32..0000000 --- a/.github/workflows/pipeline.yml +++ /dev/null @@ -1,150 +0,0 @@ -name: Build and Release Mod - -on: - push: - branches: - - '**' - create: - tags: - - '*' - -permissions: - contents: write - checks: write - -jobs: - - test: - runs-on: ubuntu-latest - if: github.event_name == 'push' - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '21' - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Run unit tests - run: ./gradlew test - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v3 - with: - name: test-results - path: build/test-results/test - - - name: Upload test report - if: always() - uses: mikepenz/action-junit-report@v3 - with: - report_paths: '**/build/test-results/test/TEST-*.xml' - - release: - runs-on: ubuntu-latest - if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/') - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '21' - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Run unit tests - run: ./gradlew test - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v3 - with: - name: test-results - path: build/test-results/test - - - name: Upload test report - if: always() - uses: mikepenz/action-junit-report@v3 - with: - report_paths: '**/build/test-results/test/TEST-*.xml' - - - name: Build project - run: ./gradlew build - - - name: Extract properties from gradle.properties - id: properties - run: | - modId=$(grep 'modId' gradle.properties | cut -d'=' -f2 | xargs) - modVersion=$(grep 'modVersion' gradle.properties | cut -d'=' -f2 | xargs) - minecraftFirstSnapshotVersion=$(grep 'minecraftFirstSnapshotVersion' gradle.properties | cut -d'=' -f2 | xargs) - minecraftReleaseVersion=$(grep 'minecraftReleaseVersion' gradle.properties | cut -d'=' -f2 | xargs) - fabricSupportedLoaders=$(grep 'fabricSupportedLoaders' gradle.properties | cut -d'=' -f2 | xargs) - echo "MOD_ID=$modId" >> $GITHUB_ENV - echo "MOD_VERSION=$minecraftReleaseVersion-$modVersion" >> $GITHUB_ENV - echo "MINECRAFT_VERSIONS=Minecraft: $minecraftFirstSnapshotVersion+" >> $GITHUB_ENV - echo "LOADERS=Loaders: $fabricSupportedLoaders" >> $GITHUB_ENV - echo "MINECRAFT_FIRST_SNAPSHOT_VERSION=$minecraftFirstSnapshotVersion" >> $GITHUB_ENV - echo "MINECRAFT_RELEASE_VERSION=$minecraftReleaseVersion" >> $GITHUB_ENV - - - name: Get version changelog - id: changelog - run: | - VERSION=${{ env.MOD_VERSION }} - CHANGELOG=$(sed -n "/^## $VERSION$/,/^## [0-9]/p" CHANGELOG.md | sed '$d' | tail -n +2) - echo "CHANGELOG<> $GITHUB_ENV - echo "$CHANGELOG" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - shell: bash - - - name: Combine release notes - id: combine - run: | - echo "${{ env.MINECRAFT_VERSIONS }}" > combined_changelog.txt - echo "${{ env.LOADERS }}" >> combined_changelog.txt - echo "" >> combined_changelog.txt - echo "## Changes" >> combined_changelog.txt - echo "" >> combined_changelog.txt - echo "${{ env.CHANGELOG }}" >> combined_changelog.txt - cat combined_changelog.txt - echo "FINAL_CHANGELOG<> $GITHUB_ENV - cat combined_changelog.txt >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - name: "Foggy Pale Garden ${{ env.MOD_VERSION }}" - files: build/libs/*.jar - body: ${{ env.FINAL_CHANGELOG }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish to Modrinth - run: ./gradlew modrinth - env: - MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} - - - name: Publish to CurseForge - run: ./gradlew curseforge - env: - CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 99d2caf..519a1db 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ replay_*.log ### Gradle ### .gradle/ build/ +lib/ out/ classes/ diff --git a/CHANGELOG.md b/CHANGELOG.md index e25b66c..a022d06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.8.1 + +### Fixed + +- Game crash when spectating a mob in spectator mode + ## 1.21.2-2.8.0 ### Added diff --git a/README.md b/README.md index ed0e7ff..04aecb5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + # Foggy Pale Garden diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..9941cc9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,116 @@ +plugins { + id 'com.naocraftlab.apply-ext-properties-plugin' + id 'architectury-plugin' + id 'dev.architectury.loom' apply false + id 'com.github.johnrengelman.shadow' apply false + id 'com.modrinth.minotaur' apply false + id 'com.matthewprenger.cursegradle' apply false +} + +architectury { + minecraft = rootProject.extensions.extraProperties.minecraftVersion +} + +subprojects { + apply plugin: 'dev.architectury.loom' + apply plugin: 'com.github.johnrengelman.shadow' + + archivesBaseName = rootProject.ext.modId + + loom { + silentMojangMappingsLicense() + } + + dependencies { + minecraft "com.mojang:minecraft:${rootProject.ext.minecraftMappingsVersion}" + mappings loom.officialMojangMappings() + + compileOnly "org.projectlombok:lombok:${rootProject.ext.commonLombokVersion}" + annotationProcessor "org.projectlombok:lombok:${rootProject.ext.commonLombokVersion}" + + testCompileOnly "org.projectlombok:lombok:${rootProject.ext.commonLombokVersion}" + testAnnotationProcessor "org.projectlombok:lombok:${rootProject.ext.commonLombokVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-api:${rootProject.ext.commonJunitVersion}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${rootProject.ext.commonJunitVersion}" + testImplementation "org.mockito:mockito-core:${rootProject.ext.commonMockitoVersion}" + testImplementation "org.assertj:assertj-core:${rootProject.ext.commonAssertJVersion}" + testImplementation "org.skyscreamer:jsonassert:${rootProject.ext.commonJsonAssertVersion}" + } + + processResources { + filesMatching([ + "${rootProject.extensions.extraProperties.modId}-common.mixins.json".toString(), + 'fabric.mod.json', + 'META-INF/neoforge.mods.toml', + 'META-INF/mods.toml', + 'pack.mcmeta' + ]) { + expand( + modId: rootProject.extensions.extraProperties.modId, + modVersion: project.version, + modName: rootProject.extensions.extraProperties.modName, + modDescription: rootProject.extensions.extraProperties.modDescription, + modLicense: rootProject.extensions.extraProperties.modLicense, + modHomepage: rootProject.extensions.extraProperties.modHomepage, + modSources: rootProject.extensions.extraProperties.modSources, + modIssueTracker: rootProject.extensions.extraProperties.modIssueTracker, + modGitHubReleases: rootProject.extensions.extraProperties.modGitHubReleases, + modModrinth: rootProject.extensions.extraProperties.modModrinth, + modCurseForge: rootProject.extensions.extraProperties.modCurseForge, + modDiscord: rootProject.extensions.extraProperties.modDiscord, + modKoFi: rootProject.extensions.extraProperties.modKoFi, + modAuthorYouTube: rootProject.extensions.extraProperties.modAuthorYouTube, + minecraftJavaVersion: rootProject.extensions.extraProperties.minecraftJavaVersion, + commonFabricLoaderVersion: rootProject.extensions.extraProperties.commonFabricLoaderVersion, + commonClothConfigVersion: rootProject.extensions.extraProperties.commonClothConfigVersion, + fabricApiVersion: rootProject.extensions.extraProperties.fabricApiVersion, + fabricMinMinecraftVersion: rootProject.extensions.extraProperties.fabricMinMinecraftVersion, + fabricModMenuVersion: rootProject.extensions.extraProperties.fabricModMenuVersion, + neoforgeMinVersion: rootProject.extensions.extraProperties.neoforgeMinVersion, + neoforgeMinLoaderVersion: rootProject.extensions.extraProperties.neoforgeMinLoaderVersion, + neoforgeMinMinecraftVersion: rootProject.extensions.extraProperties.neoforgeMinMinecraftVersion, + forgeMinVersion: rootProject.extensions.extraProperties.forgeMinVersion, + forgeMinLoaderVersion: rootProject.extensions.extraProperties.forgeMinLoaderVersion, + forgeMinMinecraftVersion: rootProject.extensions.extraProperties.forgeMinMinecraftVersion, + ) + } + } +} + +allprojects { + apply plugin: "java" + apply plugin: "architectury-plugin" + + group = rootProject.extensions.extraProperties.modGroup + version = "${rootProject.extensions.extraProperties.modVersion}+${rootProject.extensions.extraProperties.minecraftVersion}-${project.name}" + + repositories { + maven { + name = 'NeoForge' + url = 'https://maven.neoforged.net/releases' + } + maven { + name = 'CurseForge' + url = 'https://minecraft.curseforge.com/api/maven' + } + maven { + name = 'Shedaniel Maven' + url = 'https://maven.shedaniel.me' + } + maven { + name = 'TerraformersMC' + url = 'https://maven.terraformersmc.com/releases' + } + mavenLocal() + mavenCentral() + } + + tasks.withType(JavaCompile) { + options.encoding = "UTF-8" + options.release = rootProject.extensions.extraProperties.minecraftJavaVersion.toInteger() + } + + java { + withSourcesJar() + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index bc10c17..0000000 --- a/build.gradle.kts +++ /dev/null @@ -1,175 +0,0 @@ -plugins { - id("fabric-loom") - id("com.modrinth.minotaur") version "2.+" - id("com.matthewprenger.cursegradle") version "1.4.0" -} - -version = project.property("modVersion").toString() -group = project.property("group").toString() - -base { - archivesName.set("${project.property("modId")}-${project.property("minecraftReleaseVersion")}") -} - -repositories { - mavenCentral() - maven { url = uri("https://maven.terraformersmc.com/") } - maven { url = uri("https://maven.shedaniel.me/") } - maven { url = uri("https://maven.terraformersmc.com/releases/") } -} - -dependencies { - compileOnly("org.projectlombok:lombok:1.18.34") - annotationProcessor("org.projectlombok:lombok:1.18.34") - minecraft("com.mojang:minecraft:${project.property("minecraftFirstSnapshotVersion")}") - mappings("net.fabricmc:yarn:${project.property("fabricYarnMappingsVersion")}:v2") - modImplementation("net.fabricmc:fabric-loader:${project.property("fabricLoaderMinVersion")}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabricApiVersion")}") - modApi("me.shedaniel.cloth:cloth-config-fabric:${project.property("clothConfigVersion")}") { - exclude(group = "net.fabricmc.fabric-api") - } - modImplementation("com.terraformersmc:modmenu:${project.property("fabricModMenuVersion")}") - - testCompileOnly("org.projectlombok:lombok:1.18.34") - testAnnotationProcessor("org.projectlombok:lombok:1.18.34") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") - testImplementation("org.mockito:mockito-core:4.0.0") - testImplementation("org.assertj:assertj-core:3.21.0") - testImplementation("org.skyscreamer:jsonassert:1.5.0") -} - -tasks.processResources { - inputs.property("version", project.version) - - filesMatching("fabric.mod.json") { - expand( - "modId" to project.property("modId"), - "modVersion" to project.property("modVersion"), - "modName" to project.property("modName"), - "modDescription" to project.property("modDescription"), - "modLicense" to project.property("modLicense"), - "modHomepage" to project.property("modHomepage"), - "modSources" to project.property("modSources"), - "modIssueTracker" to project.property("modIssueTracker"), - "modGitHubReleases" to project.property("modGitHubReleases"), - "modModrinth" to project.property("modModrinth"), - "modCurseForge" to project.property("modCurseForge"), - "modDiscord" to project.property("modDiscord"), - "modKoFi" to project.property("modKoFi"), - "modAuthorYouTube" to project.property("modAuthorYouTube"), - "fabricLoaderMinVersion" to project.property("fabricLoaderMinVersion"), - "fabricApiVersion" to project.property("fabricApiVersion"), - "clothConfigVersion" to project.property("clothConfigVersion"), - "fabricModMenuVersion" to project.property("fabricModMenuVersion"), - "minecraftJavaVersion" to project.property("minecraftJavaVersion"), - "minecraftFirstSnapshotFullVersion" to project.property("minecraftFirstSnapshotFullVersion") - ) - } -} - -java { - withSourcesJar() -} - -tasks.withType().configureEach { - options.release.set(project.property("minecraftJavaVersion").toString().toInt()) - options.annotationProcessorPath = configurations.annotationProcessor.get() -} - -tasks.test { - useJUnitPlatform() -} - -tasks.jar { - from("LICENSE") { - rename { "${it}_${project.base.archivesName.get()}" } - } -} - -fun getChangelogForVersion(version: String): String { - val changelogFile = File("CHANGELOG.md") - if (!changelogFile.exists()) { - return "Файл CHANGELOG.md не найден" - } - - val content = changelogFile.readText() - val lines = content.lines() - - var isVersionFound = false - var versionContent = StringBuilder() - for (line in lines) { - if (!isVersionFound) { - if (line.trim() == "## $version") { - isVersionFound = true - continue - } - } else { - if (line.trim().startsWith("## ")) { - break - } - versionContent.appendLine(line) - } - } - - return if (isVersionFound) { - versionContent.toString().trim() - } else { - throw GradleException("Version $version information was not found in CHANGELOG.md") - } -} - -val modrinthToken = project.findProperty("modrinthToken")?.toString() ?: System.getenv("MODRINTH_TOKEN") -if (modrinthToken != null) { - modrinth { - token.set(modrinthToken) - projectId.set(project.property("modId").toString()) - versionNumber.set(project.version.toString()) - versionName.set("${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}") - versionType.set("release") - uploadFile.set(File("build/libs/${project.base.archivesName.get()}-${project.version}.jar")) - changelog.set(getChangelogForVersion("${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}")) - gameVersions.set(project.property("fabricModrinthGameVersions").toString().split(',').map { it.trim() }) - loaders.set(project.property("fabricSupportedLoaders").toString().split(',').map { it.trim().lowercase() }.toSet()) - additionalFiles.set(listOf(File("build/libs/${project.base.archivesName.get()}-${project.version}-sources.jar"))) - - dependencies { - required.project("fabric-api") - optional.project("cloth-config") - optional.project("modmenu") - } - } -} - -val curseForgeApiKey = project.findProperty("curseforgeApiKey")?.toString() ?: System.getenv("CURSEFORGE_API_KEY") -if (curseForgeApiKey != null) { - curseforge { - apiKey = curseForgeApiKey - project(closureOf { - id = project.property("modCurseForgeId") - releaseType = "release" - changelogType = "markdown" - changelog = getChangelogForVersion("${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}") - gameVersionStrings.addAll(project.property("fabricCurseForgeGameVersions").toString().split(',').map { it.trim() }.toSet()) - gameVersionStrings.addAll(project.property("fabricSupportedLoaders").toString().split(',').map { it.trim() }) - // TODO side - // gameVersionStrings.add("Client") - gameVersionStrings.add("Java ${project.property("minecraftJavaVersion")}") - mainArtifact( - File("build/libs/${project.base.archivesName.get()}-${project.version}.jar"), - closureOf { - displayName = "${project.property("minecraftReleaseVersion")}-${project.property("modVersion")}" - } - ) - addArtifact( - File("build/libs/${project.base.archivesName.get()}-${project.version}-sources.jar"), - closureOf {} - ) - relations(closureOf { - requiredDependency("fabric-api") - optionalDependency("cloth-config") - optionalDependency("modmenu") - }) - }) - } -} diff --git a/buildPluginSrc/build.gradle b/buildPluginSrc/build.gradle new file mode 100644 index 0000000..3ec8ab8 --- /dev/null +++ b/buildPluginSrc/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'groovy' + id 'java-gradle-plugin' +} + +group = 'com.naocraftlab' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation localGroovy() +} + +gradlePlugin { + plugins { + loadPropertiesSettingsPlugin { + id = 'com.naocraftlab.load-properties-settings-plugin' + implementationClass = 'com.naocraftlab.LoadPropertiesSettingsPlugin' + } + applyExtPropertiesPlugin { + id = 'com.naocraftlab.apply-ext-properties-plugin' + implementationClass = 'com.naocraftlab.ApplyExtPropertiesPlugin' + } + } +} diff --git a/buildPluginSrc/src/main/groovy/com/naocraftlab/ApplyExtPropertiesPlugin.groovy b/buildPluginSrc/src/main/groovy/com/naocraftlab/ApplyExtPropertiesPlugin.groovy new file mode 100644 index 0000000..a20ba12 --- /dev/null +++ b/buildPluginSrc/src/main/groovy/com/naocraftlab/ApplyExtPropertiesPlugin.groovy @@ -0,0 +1,37 @@ +package com.naocraftlab + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class ApplyExtPropertiesPlugin implements Plugin { + + @Override + void apply(Project project) { + if (project != project.rootProject) { + return + } + + def envMcVersion = System.getenv("mcVersion") ?: "local" + def mergedProps = new Properties() + def rootPropsFile = project.file("gradle.properties") + if (rootPropsFile.exists()) { + rootPropsFile.withInputStream { mergedProps.load(it) } + } + + def mcVersionPropsFile = project.file("mcVersions/${envMcVersion}.properties") + if (mcVersionPropsFile.exists()) { + def mcProps = new Properties() + mcVersionPropsFile.withInputStream { mcProps.load(it) } + + mcProps.each { k, v -> + mergedProps.setProperty(k.toString(), v.toString()) + } + } + + mergedProps.each { k, v -> project.ext.set(k.toString(), v) } + + project.subprojects { subprj -> + mergedProps.each { k, v -> subprj.ext.set(k.toString(), v) } + } + } +} diff --git a/buildPluginSrc/src/main/groovy/com/naocraftlab/LoadPropertiesSettingsPlugin.groovy b/buildPluginSrc/src/main/groovy/com/naocraftlab/LoadPropertiesSettingsPlugin.groovy new file mode 100644 index 0000000..400cecb --- /dev/null +++ b/buildPluginSrc/src/main/groovy/com/naocraftlab/LoadPropertiesSettingsPlugin.groovy @@ -0,0 +1,31 @@ +package com.naocraftlab + +import org.gradle.api.Plugin +import org.gradle.api.initialization.Settings + +class LoadPropertiesSettingsPlugin implements Plugin { + + @Override + void apply(Settings settings) { + def mcVersion = System.getenv("mcVersion") ?: "1.21" + + def rootPropsFile = new File(settings.rootDir, "gradle.properties") + def rootProps = new Properties() + if (rootPropsFile.exists()) { + rootProps.load(rootPropsFile.newDataInputStream()) + } + + def mcVersionPropsFile = new File(settings.rootDir, "mcVersions/${mcVersion}.properties") + if (mcVersionPropsFile.exists()) { + def mcProps = new Properties() + mcVersionPropsFile.withInputStream { mcProps.load(it) } + mcProps.each { key, value -> + rootProps[key] = value + } + } + + rootProps.each { key, value -> + settings.extensions.extraProperties.set(key.toString(), value.toString()) + } + } +} diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..fa52bf6 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,23 @@ +architectury { + common(project.extensions.extraProperties.architecturyPlatforms.split(',')) +} + +configurations { + shadowCommon +} + +dependencies { + modImplementation "net.fabricmc:fabric-loader:${project.ext.commonFabricLoaderVersion}" + modImplementation "me.shedaniel.cloth:cloth-config:${project.ext.commonClothConfigVersion}" +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + archiveClassifier.set('dev-shadow') +} + +remapJar { + inputFile = shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} \ No newline at end of file diff --git a/common/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGarden.java b/common/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGarden.java new file mode 100644 index 0000000..015b008 --- /dev/null +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGarden.java @@ -0,0 +1,9 @@ +package com.naocraftlab.foggypalegarden; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class FoggyPaleGarden { + + public static final String MOD_ID = "foggypalegarden"; +} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java b/common/src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java similarity index 87% rename from src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java index 002c043..ea10bb4 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/command/FpgCommand.java @@ -8,6 +8,7 @@ public interface FpgCommand { String PRESET_ARGUMENT = "preset"; String RELOAD_CONFIG_ARGUMENT = "reloadConfig"; String NO_FOG_GAME_MODE_ARGUMENT = "noFogGameMode"; + String NO_FOG_GAME_MODE_ARGUMENT_FIRST_ARG = "gameMode"; List ALL_ARGUMENTS = List.of( PRESET_ARGUMENT, RELOAD_CONFIG_ARGUMENT, diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java similarity index 83% rename from src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java index 9734482..6e22760 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigFacade.java @@ -6,16 +6,18 @@ import com.naocraftlab.foggypalegarden.config.main.MainConfigV3; import com.naocraftlab.foggypalegarden.config.preset.FogPreset; import com.naocraftlab.foggypalegarden.config.preset.FogPresetV3; +import com.naocraftlab.foggypalegarden.domain.service.FogService; import com.naocraftlab.foggypalegarden.exception.FoggyPaleGardenEnvironmentException; import com.naocraftlab.foggypalegarden.util.FpgFiles; import com.naocraftlab.foggypalegarden.util.Pair; import lombok.RequiredArgsConstructor; import lombok.val; -import net.minecraft.world.GameMode; +import net.minecraft.world.level.GameType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -23,6 +25,7 @@ import java.util.Set; import java.util.function.Consumer; +import static com.naocraftlab.foggypalegarden.FoggyPaleGarden.MOD_ID; import static java.nio.file.Files.exists; import static java.nio.file.Files.isRegularFile; import static java.nio.file.Files.list; @@ -42,6 +45,24 @@ public final class ConfigFacade { private MainConfigV3 mainConfig; private Map> presets; + private static ConfigFacade instance = null; + + private static void init() { + val configDir = Paths.get("./config"); + val configFilePtah = configDir.resolve(MOD_ID + ".json"); + val presetDirectoryPath = configDir.resolve(Paths.get(MOD_ID)); + instance = new ConfigFacade(configFilePtah, presetDirectoryPath, new ConfigMigrator(presetDirectoryPath)); + instance.registerCurrentPresetListener(FogService::onCurrentPresetChange); + instance.load(); + } + + public static ConfigFacade configFacade() { + if (instance == null) { + init(); + } + return instance; + } + public void registerCurrentPresetListener(Consumer listener) { listeners.add(listener); } @@ -61,19 +82,19 @@ public Path presetDirectoryPath() { // config @NotNull - public List noFogGameModes() { + public List noFogGameModes() { return mainConfig.getNoFogGameModes().stream().sorted().toList(); } - public void noFogGameModes(Set gameModes) { + public void noFogGameModes(Set gameModes) { mainConfig = mainConfig.withNoFogGameModes(gameModes); } - public boolean isNoFogGameMode(@NotNull GameMode gameMode) { + public boolean isNoFogGameMode(@NotNull GameType gameMode) { return mainConfig.getNoFogGameModes().contains(gameMode); } - public boolean toggleNoFogGameMode(@NotNull GameMode gameMode) { + public boolean toggleNoFogGameMode(@NotNull GameType gameMode) { val noFogGameModes = new HashSet<>(mainConfig.getNoFogGameModes()); if (!noFogGameModes.contains(gameMode)) { noFogGameModes.add(gameMode); diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigMigrator.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigMigrator.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/config/ConfigMigrator.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/ConfigMigrator.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfig.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfig.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfig.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfig.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java similarity index 90% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java index 8527c9c..0fd22d9 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV1ToV2Converter.java @@ -9,7 +9,7 @@ import static com.naocraftlab.foggypalegarden.config.main.MainConfigV1.FogPreset.CUSTOM; -public class MainConfigV1ToV2Converter implements Converter { +public final class MainConfigV1ToV2Converter implements Converter { @Override public @NotNull MainConfig convert(@NotNull MainConfig source) { diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java similarity index 73% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java index d66c680..adca2ae 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2.java @@ -5,7 +5,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.With; -import net.minecraft.world.GameMode; +import net.minecraft.world.level.GameType; import java.util.Set; @@ -18,15 +18,15 @@ public final class MainConfigV2 extends MainConfig { private final String preset; - private final Set noFogGameModes; + private final Set noFogGameModes; - public MainConfigV2(String preset, Set noFogGameModes) { + public MainConfigV2(String preset, Set noFogGameModes) { super(2); this.preset = preset; this.noFogGameModes = noFogGameModes; } - public Set getNoFogGameModes() { + public Set getNoFogGameModes() { return noFogGameModes == null ? Set.of() : noFogGameModes; } } diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java similarity index 84% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java index 729546a..e969e24 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV2ToV3Converter.java @@ -4,7 +4,7 @@ import lombok.val; import org.jetbrains.annotations.NotNull; -public class MainConfigV2ToV3Converter implements Converter { +public final class MainConfigV2ToV3Converter implements Converter { @Override public @NotNull MainConfig convert(@NotNull MainConfig source) { diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java similarity index 73% rename from src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java index 91c17b1..ae8d90c 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/main/MainConfigV3.java @@ -5,7 +5,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.With; -import net.minecraft.world.GameMode; +import net.minecraft.world.level.GameType; import java.util.Set; @@ -18,15 +18,15 @@ public final class MainConfigV3 extends MainConfig { private final String preset; - private final Set noFogGameModes; + private final Set noFogGameModes; - public MainConfigV3(String preset, Set noFogGameModes) { + public MainConfigV3(String preset, Set noFogGameModes) { super(3); this.preset = preset; this.noFogGameModes = noFogGameModes; } - public Set getNoFogGameModes() { + public Set getNoFogGameModes() { return noFogGameModes == null ? Set.of() : noFogGameModes; } } diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPreset.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPreset.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPreset.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPreset.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java similarity index 99% rename from src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java index bf2cfae..bda471f 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2.java @@ -1,5 +1,6 @@ package com.naocraftlab.foggypalegarden.config.preset; +import com.mojang.blaze3d.shaders.FogShape; import com.naocraftlab.foggypalegarden.config.preset.FogPresetV2.Binding.Brightness.BrightnessMode; import com.naocraftlab.foggypalegarden.config.preset.FogPresetV2.Binding.Color.ColorMode; import com.naocraftlab.foggypalegarden.domain.model.Environment; @@ -9,7 +10,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.val; -import net.minecraft.client.render.FogShape; import net.minecraft.world.Difficulty; import java.util.List; diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java similarity index 98% rename from src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java index 548b528..78d1b70 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV2ToV3Converter.java @@ -21,7 +21,7 @@ import static java.util.stream.Collectors.toSet; -public class FogPresetV2ToV3Converter implements Converter { +public final class FogPresetV2ToV3Converter implements Converter { @Override public @NotNull FogPreset convert(@NotNull FogPreset source) { diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java similarity index 99% rename from src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java index f3fd2ed..1cb4beb 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/FogPresetV3.java @@ -1,5 +1,6 @@ package com.naocraftlab.foggypalegarden.config.preset; +import com.mojang.blaze3d.shaders.FogShape; import com.naocraftlab.foggypalegarden.config.preset.FogPresetV3.Binding.Brightness.BrightnessMode; import com.naocraftlab.foggypalegarden.config.preset.FogPresetV3.Binding.Color.ColorMode; import com.naocraftlab.foggypalegarden.domain.model.Environment; @@ -9,7 +10,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.val; -import net.minecraft.client.render.FogShape; import net.minecraft.world.Difficulty; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java similarity index 98% rename from src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java index b9b774a..437b84d 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/config/preset/MainConfigV1ToFogPresetsV2Converter.java @@ -27,7 +27,7 @@ import static net.minecraft.world.Difficulty.PEACEFUL; @RequiredArgsConstructor -public class MainConfigV1ToFogPresetsV2Converter implements Converter> { +public final class MainConfigV1ToFogPresetsV2Converter implements Converter> { private static final List DEFAULT_PRESETS = List.of( FogPresetV2.builder() diff --git a/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Color.java b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Color.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/domain/model/Color.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Color.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Environment.java b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Environment.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/domain/model/Environment.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Environment.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java similarity index 84% rename from src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java index 841285a..538641e 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/FogCharacteristics.java @@ -1,7 +1,7 @@ package com.naocraftlab.foggypalegarden.domain.model; +import com.mojang.blaze3d.shaders.FogShape; import lombok.Builder; -import net.minecraft.client.render.FogShape; @Builder public record FogCharacteristics( diff --git a/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Weather.java b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Weather.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/domain/model/Weather.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/domain/model/Weather.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/domain/service/FogService.java b/common/src/main/java/com/naocraftlab/foggypalegarden/domain/service/FogService.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/domain/service/FogService.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/domain/service/FogService.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java b/common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java similarity index 74% rename from src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java index a2965b5..219fa7c 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenConfigurationException.java @@ -1,6 +1,6 @@ package com.naocraftlab.foggypalegarden.exception; -public class FoggyPaleGardenConfigurationException extends FoggyPaleGardenException { +public final class FoggyPaleGardenConfigurationException extends FoggyPaleGardenException { public FoggyPaleGardenConfigurationException(String message) { super(message); diff --git a/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java b/common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java similarity index 75% rename from src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java index 3780dff..380eba5 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenEnvironmentException.java @@ -1,6 +1,6 @@ package com.naocraftlab.foggypalegarden.exception; -public class FoggyPaleGardenEnvironmentException extends FoggyPaleGardenException { +public final class FoggyPaleGardenEnvironmentException extends FoggyPaleGardenException { public FoggyPaleGardenEnvironmentException(String message) { super(message); diff --git a/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenException.java b/common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenException.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenException.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/exception/FoggyPaleGardenException.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java b/common/src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java similarity index 62% rename from src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java index 00f92c0..4a3a71a 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/gui/ClothConfigScreen.java @@ -3,19 +3,19 @@ import lombok.experimental.UtilityClass; import lombok.val; import me.shedaniel.clothconfig2.api.ConfigBuilder; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.world.GameMode; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameType; import java.util.HashSet; import java.util.List; -import static com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod.configFacade; +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; import static com.naocraftlab.foggypalegarden.config.ConfigMigrator.DEFAULT_CONFIG; -import static net.minecraft.text.Text.translatable; -import static net.minecraft.world.GameMode.ADVENTURE; -import static net.minecraft.world.GameMode.CREATIVE; -import static net.minecraft.world.GameMode.SPECTATOR; -import static net.minecraft.world.GameMode.SURVIVAL; +import static net.minecraft.world.level.GameType.ADVENTURE; +import static net.minecraft.world.level.GameType.CREATIVE; +import static net.minecraft.world.level.GameType.SPECTATOR; +import static net.minecraft.world.level.GameType.SURVIVAL; @UtilityClass public class ClothConfigScreen { @@ -23,41 +23,41 @@ public class ClothConfigScreen { public static Screen of(Screen parent) { configFacade().load(); - val builder = ConfigBuilder.create().setTitle(translatable("fpg.settings.title")).setParentScreen(parent); + val builder = ConfigBuilder.create().setTitle(Component.translatable("fpg.settings.title")).setParentScreen(parent); val entryBuilder = builder.entryBuilder(); - val generalCategory = builder.getOrCreateCategory(translatable("fpg.settings.category.general.title")); + val generalCategory = builder.getOrCreateCategory(Component.translatable("fpg.settings.category.general.title")); val presetEntry = entryBuilder.startSelector( - translatable("fpg.settings.currentPreset.title"), + Component.translatable("fpg.settings.currentPreset.title"), configFacade().getAvailablePresetCodes().toArray(), configFacade().getCurrentPreset().getCode() ).setTooltip( - translatable("fpg.settings.currentPreset.tooltip", configFacade().presetDirectoryPath().normalize().toString()) + Component.translatable("fpg.settings.currentPreset.tooltip", configFacade().presetDirectoryPath().normalize().toString()) ).setDefaultValue(DEFAULT_CONFIG.getPreset()) .build(); generalCategory.addEntry(presetEntry); val creativeEntry = entryBuilder.startBooleanToggle( - translatable("selectWorld.gameMode.creative"), + Component.translatable("selectWorld.gameMode.creative"), configFacade().isNoFogGameMode(CREATIVE) ).setDefaultValue(false).build(); val survivalEntry = entryBuilder.startBooleanToggle( - translatable("selectWorld.gameMode.survival"), + Component.translatable("selectWorld.gameMode.survival"), configFacade().isNoFogGameMode(SURVIVAL) ).setDefaultValue(false).build(); val adventureEntry = entryBuilder.startBooleanToggle( - translatable("selectWorld.gameMode.adventure"), + Component.translatable("selectWorld.gameMode.adventure"), configFacade().isNoFogGameMode(ADVENTURE) ).setDefaultValue(false).build(); val spectatorEntry = entryBuilder.startBooleanToggle( - translatable("selectWorld.gameMode.spectator"), + Component.translatable("selectWorld.gameMode.spectator"), configFacade().isNoFogGameMode(SPECTATOR) ).setDefaultValue(false).build(); val noFogGameModeCategory = entryBuilder.startSubCategory( - translatable("fpg.settings.subCategory.noFogGameMode.title"), + Component.translatable("fpg.settings.subCategory.noFogGameMode.title"), List.of(creativeEntry, survivalEntry, adventureEntry, spectatorEntry) - ).setTooltip(translatable("fpg.settings.subCategory.noFogGameMode.tooltip")) + ).setTooltip(Component.translatable("fpg.settings.subCategory.noFogGameMode.tooltip")) .setExpanded(true) .build(); generalCategory.addEntry(noFogGameModeCategory); @@ -65,7 +65,7 @@ public static Screen of(Screen parent) { builder.setSavingRunnable(() -> { configFacade().setCurrentPreset((String) presetEntry.getValue()); - val noFogGameModes = new HashSet(); + val noFogGameModes = new HashSet(); if (creativeEntry.getValue()) { noFogGameModes.add(CREATIVE); } diff --git a/common/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java b/common/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java new file mode 100644 index 0000000..95c5e88 --- /dev/null +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java @@ -0,0 +1,30 @@ +package com.naocraftlab.foggypalegarden.gui; + +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.ConfirmLinkScreen; +import net.minecraft.client.gui.screens.Screen; + +import java.net.URI; + +import static net.minecraft.network.chat.Component.translatable; + +public final class NoClothConfigScreen { + + private static final URI CLOTH_CONFIG_MODRINTH = URI.create("https://modrinth.com/mod/cloth-config"); + + public static Screen of(Screen parent) { + return new ConfirmLinkScreen( + confirmed -> onClick(confirmed, parent), + translatable("fpg.settings.warning.noClothConfig"), + CLOTH_CONFIG_MODRINTH.toString(), + true); + } + + private static void onClick(boolean confirmed, Screen parent) { + if (confirmed) { + Util.getPlatform().openUri(CLOTH_CONFIG_MODRINTH); + } + Minecraft.getInstance().setScreen(parent); + } +} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java b/common/src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java similarity index 64% rename from src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java index 948e1fd..b7425c2 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java +++ b/common/src/main/java/com/naocraftlab/foggypalegarden/mixin/PaleGardenFogMixin.java @@ -6,14 +6,15 @@ import com.naocraftlab.foggypalegarden.domain.model.Weather; import com.naocraftlab.foggypalegarden.domain.service.FogService; import lombok.val; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.render.BackgroundRenderer; -import net.minecraft.client.render.BackgroundRenderer.FogType; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.Fog; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.world.GameMode; -import net.minecraft.world.RaycastContext; +import net.minecraft.client.Camera; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.FogParameters; +import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Abilities; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.GameType; import org.joml.Vector4f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -21,54 +22,59 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import static com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod.configFacade; +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; import static com.naocraftlab.foggypalegarden.domain.model.Weather.CLEAR; import static com.naocraftlab.foggypalegarden.domain.model.Weather.RAIN; import static com.naocraftlab.foggypalegarden.domain.model.Weather.THUNDER; -import static net.minecraft.world.LightType.SKY; -import static net.minecraft.world.RaycastContext.FluidHandling.NONE; -import static net.minecraft.world.RaycastContext.ShapeType.COLLIDER; +import static net.minecraft.world.level.ClipContext.Block.COLLIDER; +import static net.minecraft.world.level.ClipContext.Fluid.NONE; +import static net.minecraft.world.level.GameType.ADVENTURE; +import static net.minecraft.world.level.GameType.CREATIVE; +import static net.minecraft.world.level.GameType.SPECTATOR; +import static net.minecraft.world.level.GameType.SURVIVAL; +import static net.minecraft.world.level.LightLayer.SKY; -@Mixin(BackgroundRenderer.class) +@Mixin(FogRenderer.class) public abstract class PaleGardenFogMixin { @Unique private static float fogDensity = 0.0f; - @Inject(method = "applyFog", at = @At("HEAD"), cancellable = true) - private static void injectApplyFog( + @Inject(method = "setupFog", at = @At("HEAD"), cancellable = true) + private static void injectSetupFog( Camera camera, - FogType fogType, + FogRenderer.FogMode fogType, Vector4f color, float viewDistance, boolean thickenFog, float tickDelta, - CallbackInfoReturnable cir + CallbackInfoReturnable cir ) { - val focusedEntity = (ClientPlayerEntity) camera.getFocusedEntity(); + val focusedEntity = camera.getEntity(); + val gameMode = resolveGameMode(focusedEntity); if (configFacade().isNoFogGameMode(gameMode)) { fogDensity = 0.0f; return; } - val world = (ClientWorld) focusedEntity.getWorld(); - val blockPos = camera.getBlockPos(); + val world = (ClientLevel) focusedEntity.getCommandSenderWorld(); + val blockPos = camera.getBlockPosition(); val biomeEntry = world.getBiome(blockPos); - val hitResult = world.raycast(new RaycastContext( - blockPos.toCenterPos(), blockPos.add(0, -256, 0).toCenterPos(), COLLIDER, NONE, focusedEntity + val hitResult = world.clip(new ClipContext( + blockPos.getCenter(), blockPos.offset(0, -256, 0).getCenter(), COLLIDER, NONE, focusedEntity )); val fogCharacteristics = FogService.calculateFogCharacteristics( Environment.builder() - .dimension(world.getRegistryKey().getValue().toString()) - .biome(biomeEntry.getIdAsString()) - .biomeTemperature(biomeEntry.value().getTemperature()) + .dimension(world.dimension().location().toString()) + .biome(biomeEntry.getRegisteredName()) + .biomeTemperature(biomeEntry.value().getBaseTemperature()) .difficulty(world.getDifficulty()) .weather(resolveWeather(world)) - .timeOfDay(world.getTimeOfDay()) - .skyLightLevel(world.getLightLevel(SKY, blockPos)) + .timeOfDay(world.getDayTime()) + .skyLightLevel(world.getBrightness(SKY, blockPos)) .height(blockPos.getY()) - .heightAboveSurface(blockPos.getY() - hitResult.getPos().y) + .heightAboveSurface(blockPos.getY() - hitResult.getBlockPos().getY()) .gameFogColor(toColor(color)) .fogDensity(fogDensity) .build() @@ -102,20 +108,25 @@ private static void injectApplyFog( } @Unique - private static GameMode resolveGameMode(ClientPlayerEntity player) { - val attributes = player.getAbilities(); - if (attributes.creativeMode) { - return GameMode.CREATIVE; - } else if (attributes.allowFlying && attributes.invulnerable && attributes.flying) { - return GameMode.SPECTATOR; - } else if (attributes.allowModifyWorld) { - return GameMode.SURVIVAL; + private static GameType resolveGameMode(Entity player) { + final Abilities attributes; + if (player instanceof LocalPlayer) { + attributes = ((LocalPlayer) player).getAbilities(); + } else { + return SPECTATOR; + } + if (attributes.instabuild) { + return CREATIVE; + } else if (attributes.mayfly && attributes.invulnerable && attributes.flying) { + return SPECTATOR; + } else if (attributes.mayBuild) { + return SURVIVAL; } - return GameMode.ADVENTURE; + return ADVENTURE; } @Unique - private static Weather resolveWeather(ClientWorld world) { + private static Weather resolveWeather(ClientLevel world) { if (world.isThundering()) { return THUNDER; } else if (world.isRaining()) { @@ -131,8 +142,8 @@ private static Color toColor(Vector4f color) { } @Unique - private static Fog fogOf(FogCharacteristics fogCharacteristics) { - return new Fog( + private static FogParameters fogOf(FogCharacteristics fogCharacteristics) { + return new FogParameters( fogCharacteristics.startDistance(), fogCharacteristics.endDistance(), fogCharacteristics.shape(), diff --git a/src/main/java/com/naocraftlab/foggypalegarden/util/Converter.java b/common/src/main/java/com/naocraftlab/foggypalegarden/util/Converter.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/util/Converter.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/util/Converter.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/util/FpgCollections.java b/common/src/main/java/com/naocraftlab/foggypalegarden/util/FpgCollections.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/util/FpgCollections.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/util/FpgCollections.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/util/FpgFiles.java b/common/src/main/java/com/naocraftlab/foggypalegarden/util/FpgFiles.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/util/FpgFiles.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/util/FpgFiles.java diff --git a/src/main/java/com/naocraftlab/foggypalegarden/util/Pair.java b/common/src/main/java/com/naocraftlab/foggypalegarden/util/Pair.java similarity index 100% rename from src/main/java/com/naocraftlab/foggypalegarden/util/Pair.java rename to common/src/main/java/com/naocraftlab/foggypalegarden/util/Pair.java diff --git a/src/main/resources/assets/foggypalegarden/icon.png b/common/src/main/resources/assets/foggypalegarden/icon.png similarity index 100% rename from src/main/resources/assets/foggypalegarden/icon.png rename to common/src/main/resources/assets/foggypalegarden/icon.png diff --git a/src/main/resources/assets/foggypalegarden/lang/ar_sa.json b/common/src/main/resources/assets/foggypalegarden/lang/ar_sa.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/ar_sa.json rename to common/src/main/resources/assets/foggypalegarden/lang/ar_sa.json diff --git a/src/main/resources/assets/foggypalegarden/lang/be_by.json b/common/src/main/resources/assets/foggypalegarden/lang/be_by.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/be_by.json rename to common/src/main/resources/assets/foggypalegarden/lang/be_by.json diff --git a/src/main/resources/assets/foggypalegarden/lang/de_de.json b/common/src/main/resources/assets/foggypalegarden/lang/de_de.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/de_de.json rename to common/src/main/resources/assets/foggypalegarden/lang/de_de.json diff --git a/src/main/resources/assets/foggypalegarden/lang/en_us.json b/common/src/main/resources/assets/foggypalegarden/lang/en_us.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/en_us.json rename to common/src/main/resources/assets/foggypalegarden/lang/en_us.json diff --git a/src/main/resources/assets/foggypalegarden/lang/es_mx.json b/common/src/main/resources/assets/foggypalegarden/lang/es_mx.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/es_mx.json rename to common/src/main/resources/assets/foggypalegarden/lang/es_mx.json diff --git a/src/main/resources/assets/foggypalegarden/lang/fr_fr.json b/common/src/main/resources/assets/foggypalegarden/lang/fr_fr.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/fr_fr.json rename to common/src/main/resources/assets/foggypalegarden/lang/fr_fr.json diff --git a/src/main/resources/assets/foggypalegarden/lang/it_it.json b/common/src/main/resources/assets/foggypalegarden/lang/it_it.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/it_it.json rename to common/src/main/resources/assets/foggypalegarden/lang/it_it.json diff --git a/src/main/resources/assets/foggypalegarden/lang/ja_jp.json b/common/src/main/resources/assets/foggypalegarden/lang/ja_jp.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/ja_jp.json rename to common/src/main/resources/assets/foggypalegarden/lang/ja_jp.json diff --git a/src/main/resources/assets/foggypalegarden/lang/ka_ge.json b/common/src/main/resources/assets/foggypalegarden/lang/ka_ge.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/ka_ge.json rename to common/src/main/resources/assets/foggypalegarden/lang/ka_ge.json diff --git a/src/main/resources/assets/foggypalegarden/lang/kk_kz.json b/common/src/main/resources/assets/foggypalegarden/lang/kk_kz.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/kk_kz.json rename to common/src/main/resources/assets/foggypalegarden/lang/kk_kz.json diff --git a/src/main/resources/assets/foggypalegarden/lang/ko_kr.json b/common/src/main/resources/assets/foggypalegarden/lang/ko_kr.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/ko_kr.json rename to common/src/main/resources/assets/foggypalegarden/lang/ko_kr.json diff --git a/src/main/resources/assets/foggypalegarden/lang/pt_br.json b/common/src/main/resources/assets/foggypalegarden/lang/pt_br.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/pt_br.json rename to common/src/main/resources/assets/foggypalegarden/lang/pt_br.json diff --git a/src/main/resources/assets/foggypalegarden/lang/ru_ru.json b/common/src/main/resources/assets/foggypalegarden/lang/ru_ru.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/ru_ru.json rename to common/src/main/resources/assets/foggypalegarden/lang/ru_ru.json diff --git a/src/main/resources/assets/foggypalegarden/lang/sv_se.json b/common/src/main/resources/assets/foggypalegarden/lang/sv_se.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/sv_se.json rename to common/src/main/resources/assets/foggypalegarden/lang/sv_se.json diff --git a/src/main/resources/assets/foggypalegarden/lang/uk_ua.json b/common/src/main/resources/assets/foggypalegarden/lang/uk_ua.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/uk_ua.json rename to common/src/main/resources/assets/foggypalegarden/lang/uk_ua.json diff --git a/src/main/resources/assets/foggypalegarden/lang/zh_cn.json b/common/src/main/resources/assets/foggypalegarden/lang/zh_cn.json similarity index 100% rename from src/main/resources/assets/foggypalegarden/lang/zh_cn.json rename to common/src/main/resources/assets/foggypalegarden/lang/zh_cn.json diff --git a/src/main/resources/foggypalegarden.mixins.json b/common/src/main/resources/foggypalegarden-common.mixins.json similarity index 57% rename from src/main/resources/foggypalegarden.mixins.json rename to common/src/main/resources/foggypalegarden-common.mixins.json index c2e2b44..fcd37a4 100644 --- a/src/main/resources/foggypalegarden.mixins.json +++ b/common/src/main/resources/foggypalegarden-common.mixins.json @@ -1,11 +1,13 @@ { "required": true, "package": "com.naocraftlab.foggypalegarden.mixin", - "compatibilityLevel": "JAVA_21", - "mixins": [ + "compatibilityLevel": "JAVA_${minecraftJavaVersion}", + "minVersion": "0.8", + "client": [ "PaleGardenFogMixin" ], + "mixins": [], "injectors": { "defaultRequire": 1 } -} \ No newline at end of file +} diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..6595079 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,56 @@ +architectury { + platformSetupLoomIde() + fabric() +} + +configurations { + common + shadowCommon + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentFabric.extendsFrom common +} + +dependencies { + modImplementation "net.fabricmc:fabric-loader:${commonFabricLoaderVersion}" + modApi("net.fabricmc.fabric-api:fabric-api:${fabricApiVersion}") { + exclude(module: 'fabric-api-deprecated') + } + + modImplementation("me.shedaniel.cloth:cloth-config-fabric:${commonClothConfigVersion}") { + exclude(group: 'net.fabricmc.fabric-api') + } + modImplementation("com.terraformersmc:modmenu:${fabricModMenuVersion}") { + exclude(group: 'net.fabricmc.fabric-api') + } + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } + shadowCommon(project(path: ':common', configuration: 'transformProductionFabric')) { transitive false } +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + archiveClassifier.set('dev-shadow') +} + +remapJar { + inputFile = shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} + +jar { + archiveClassifier.set('dev') +} + +sourcesJar { + def commonSources = project(':common').sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} diff --git a/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/FoggyPaleGardenClientMod.java b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/FoggyPaleGardenClientMod.java new file mode 100644 index 0000000..452e84f --- /dev/null +++ b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/FoggyPaleGardenClientMod.java @@ -0,0 +1,29 @@ +package com.naocraftlab.foggypalegarden.fabric; + +import com.mojang.brigadier.CommandDispatcher; +import com.naocraftlab.foggypalegarden.fabric.command.FpgNoFogGameModeCommand; +import com.naocraftlab.foggypalegarden.fabric.command.FpgPresetCommand; +import com.naocraftlab.foggypalegarden.fabric.command.FpgReloadConfigCommand; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.commands.CommandSourceStack; + +import static net.fabricmc.api.EnvType.CLIENT; + +@Environment(CLIENT) +public final class FoggyPaleGardenClientMod implements ClientModInitializer { + + @Override + public void onInitializeClient() { + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + registerCommands(dispatcher); + }); + } + + private static void registerCommands(CommandDispatcher dispatcher) { + FpgPresetCommand.register(dispatcher); + FpgReloadConfigCommand.register(dispatcher); + FpgNoFogGameModeCommand.register(dispatcher); + } +} diff --git a/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgNoFogGameModeCommand.java b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgNoFogGameModeCommand.java new file mode 100644 index 0000000..ee447dc --- /dev/null +++ b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgNoFogGameModeCommand.java @@ -0,0 +1,71 @@ +package com.naocraftlab.foggypalegarden.fabric.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameType; + +import java.util.stream.Stream; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static java.util.stream.Collectors.joining; +import static net.minecraft.commands.SharedSuggestionProvider.suggest; + +public class FpgNoFogGameModeCommand implements FpgCommand { + + private static final SuggestionProvider GAME_MODE_SUGGESTIONS = + (context, builder) -> suggest(Stream.of(GameType.values()).map(Enum::name), builder); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register( + Commands.literal(BASE_COMMAND) + .then(Commands.literal(NO_FOG_GAME_MODE_ARGUMENT) + .executes(FpgNoFogGameModeCommand::listNoFogGameModes) + .then( + Commands.argument(NO_FOG_GAME_MODE_ARGUMENT, StringArgumentType.string()) + .suggests(GAME_MODE_SUGGESTIONS) + .executes(FpgNoFogGameModeCommand::toggleFogForGameMode) + ) + ) + ); + } + + private static int toggleFogForGameMode(CommandContext context) { + val argumentValue = StringArgumentType.getString(context, NO_FOG_GAME_MODE_ARGUMENT); + try { + val gameMode = GameType.valueOf(argumentValue); + if (configFacade().toggleNoFogGameMode(gameMode)) { + context.getSource().sendFailure(Component.translatable("fpg.command.noFogGameMode.off", gameMode)); + } else { + context.getSource().sendSuccess(() -> Component.translatable("fpg.command.noFogGameMode.on", gameMode), false); + } + configFacade().save(); + return 1; + } catch (Exception e) { + val gameModes = Stream.of(GameType.values()).map(Enum::name).collect(joining("\n")); + context.getSource().sendFailure( + Component.translatable("fpg.command.noFogGameMode.notFound", argumentValue, gameModes) + ); + return 0; + } + } + + private static int listNoFogGameModes(CommandContext context) { + if (!configFacade().noFogGameModes().isEmpty()) { + val noFogGameModes = configFacade().noFogGameModes().stream() + .map(GameType::name) + .collect(joining("\n")); + context.getSource() + .sendSuccess(() -> Component.translatable("fpg.command.noFogGameMode.list", noFogGameModes), false); + } else { + context.getSource().sendSuccess(() -> Component.translatable("fpg.command.noFogGameMode.listEmpty"), false); + } + return 1; + } +} \ No newline at end of file diff --git a/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgPresetCommand.java b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgPresetCommand.java new file mode 100644 index 0000000..6f3028a --- /dev/null +++ b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgPresetCommand.java @@ -0,0 +1,70 @@ +package com.naocraftlab.foggypalegarden.fabric.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; + +import java.util.stream.Collectors; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +public class FpgPresetCommand implements FpgCommand { + + private static final SuggestionProvider PRESET_SUGGESTIONS = (context, builder) -> { + val presets = configFacade().getAvailablePresetCodes(); + return SharedSuggestionProvider.suggest(presets, builder); + }; + + public static void register(CommandDispatcher dispatcher) { + val command = net.minecraft.commands.Commands.literal(BASE_COMMAND) + .then(net.minecraft.commands.Commands.literal(PRESET_ARGUMENT) + .then(net.minecraft.commands.Commands.argument(PRESET_ARGUMENT, StringArgumentType.string()) + .suggests(PRESET_SUGGESTIONS) + .executes(FpgPresetCommand::setPreset)) + .executes(context -> { + val currentPreset = configFacade().getCurrentPreset().getCode(); + context.getSource() + .sendSuccess(() -> Component.translatable("fpg.command.preset.current", currentPreset), false); + return 1; + }) + ).executes(context -> { + val helpMessage = Component.translatable("fpg.command.help", String.join("\n", ALL_ARGUMENTS)) + .setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/help"))); + context.getSource().sendSuccess(() -> helpMessage, false); + return 1; + }); + + dispatcher.register(command); + } + + private static int setPreset(CommandContext context) { + val preset = StringArgumentType.getString(context, PRESET_ARGUMENT); + try { + if (configFacade().setCurrentPreset(preset)) { + context.getSource() + .sendSuccess(() -> Component.translatable("fpg.command.preset.applied", preset).withStyle(GREEN), false); + configFacade().save(); + return 1; + } else { + val allPresets = configFacade().getAvailablePresetCodes().stream().collect(Collectors.joining("\n")); + context.getSource() + .sendFailure(Component.translatable("fpg.command.preset.notFound", preset, allPresets).withStyle(RED)); + return 0; + } + } catch (Exception e) { + context.getSource() + .sendFailure(Component.translatable("fpg.command.preset.exception", e.getMessage()).withStyle(RED)); + return 0; + } + } +} diff --git a/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgReloadConfigCommand.java b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgReloadConfigCommand.java new file mode 100644 index 0000000..efbcc33 --- /dev/null +++ b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/command/FpgReloadConfigCommand.java @@ -0,0 +1,43 @@ +package com.naocraftlab.foggypalegarden.fabric.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; + +import java.util.stream.Collectors; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +public class FpgReloadConfigCommand implements FpgCommand { + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register( + net.minecraft.commands.Commands.literal(BASE_COMMAND) + .then(net.minecraft.commands.Commands.literal(RELOAD_CONFIG_ARGUMENT) + .executes(FpgReloadConfigCommand::reloadConfig)) + ); + } + + private static int reloadConfig(CommandContext context) { + try { + configFacade().load(); + val currentPreset = configFacade().getCurrentPreset().getCode(); + val allPresets = configFacade().getAvailablePresetCodes().stream().collect(Collectors.joining("\n")); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.reloadConfig.success", currentPreset, allPresets).withStyle(GREEN), + false + ); + return 1; + } catch (Exception e) { + context.getSource().sendFailure( + Component.translatable("fpg.command.reloadConfig.exception", e.getMessage()).withStyle(RED) + ); + return 0; + } + } +} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/integration/ModMenuIntegration.java b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/integration/ModMenuIntegration.java similarity index 87% rename from src/main/java/com/naocraftlab/foggypalegarden/integration/ModMenuIntegration.java rename to fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/integration/ModMenuIntegration.java index 596a9be..df3d805 100644 --- a/src/main/java/com/naocraftlab/foggypalegarden/integration/ModMenuIntegration.java +++ b/fabric/src/main/java/com/naocraftlab/foggypalegarden/fabric/integration/ModMenuIntegration.java @@ -1,11 +1,11 @@ -package com.naocraftlab.foggypalegarden.integration; +package com.naocraftlab.foggypalegarden.fabric.integration; import com.naocraftlab.foggypalegarden.gui.ClothConfigScreen; import com.naocraftlab.foggypalegarden.gui.NoClothConfigScreen; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; public final class ModMenuIntegration implements ModMenuApi { diff --git a/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 71% rename from src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json index f6f6750..4f2b3cc 100644 --- a/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -3,38 +3,40 @@ "id": "${modId}", "version": "${modVersion}", "name": "${modName}", + "icon": "assets/${modId}/icon.png", "description": "${modDescription}", + "license": "${modLicense}", "authors": [ "NaoCraftLab" ], + "contributors": [], "contact": { "homepage": "${modHomepage}", "sources": "${modSources}", "issues": "${modIssueTracker}", "discord": "${modDiscord}" }, - "license": "${modLicense}", - "icon": "assets/foggypalegarden/icon.png", "environment": "client", "entrypoints": { + "main": [], "client": [ - "com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod" + "com.naocraftlab.foggypalegarden.fabric.FoggyPaleGardenClientMod" ], "modmenu": [ - "com.naocraftlab.foggypalegarden.integration.ModMenuIntegration" + "com.naocraftlab.foggypalegarden.fabric.integration.ModMenuIntegration" ] }, "mixins": [ - "foggypalegarden.mixins.json" + "${modId}-common.mixins.json" ], "depends": { "java": ">=${minecraftJavaVersion}", - "minecraft": ">=${minecraftFirstSnapshotFullVersion}", - "fabricloader": ">=${fabricLoaderMinVersion}", + "minecraft": ">=${fabricMinMinecraftVersion}", + "fabricloader": ">=${commonFabricLoaderVersion}", "fabric-api": ">=${fabricApiVersion}" }, "suggests": { - "cloth-config": ">=${clothConfigVersion}", + "cloth-config": ">=${commonClothConfigVersion}", "modmenu": ">=${fabricModMenuVersion}" }, "custom": { @@ -51,4 +53,4 @@ } } } -} \ No newline at end of file +} diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..b501053 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,58 @@ +architectury { + platformSetupLoomIde() + forge() +} + +loom { + forge { + mixinConfig "${modId}-common.mixins.json" + } +} + +configurations { + common + shadowCommon + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentForge.extendsFrom common +} + +dependencies { + forge "net.minecraftforge:forge:${forgeVersion}" + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } + shadowCommon(project(path: ':common', configuration: 'transformProductionForge')) { transitive = false } + + modImplementation "me.shedaniel.cloth:cloth-config-forge:${commonClothConfigVersion}" +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + archiveClassifier.set('dev-shadow') +} + +remapJar { + inputFile = shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} + +jar { + archiveClassifier.set('dev') +} + +sourcesJar { + def commonSources = project(':common').sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +configurations.configureEach { + resolutionStrategy.force("net.sf.jopt-simple:jopt-simple:${forgeJoptSimpleVersion}") +} diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 0000000..8242585 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.platform=forge diff --git a/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/FoggyPaleGardenClientMod.java b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/FoggyPaleGardenClientMod.java new file mode 100755 index 0000000..619f9f6 --- /dev/null +++ b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/FoggyPaleGardenClientMod.java @@ -0,0 +1,39 @@ +package com.naocraftlab.foggypalegarden.forge; + +import com.mojang.logging.LogUtils; +import com.naocraftlab.foggypalegarden.gui.ClothConfigScreen; +import com.naocraftlab.foggypalegarden.gui.NoClothConfigScreen; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; +import org.slf4j.Logger; + +import static com.naocraftlab.foggypalegarden.FoggyPaleGarden.MOD_ID; +import static net.minecraftforge.api.distmarker.Dist.CLIENT; + +@OnlyIn(CLIENT) +@Mod(value = MOD_ID) +public final class FoggyPaleGardenClientMod { + + private static final Logger LOGGER = LogUtils.getLogger(); + + public FoggyPaleGardenClientMod() { + registerConfigScreenFactory(); + LOGGER.info("Foggy Pale Garden client setup complete."); + } + + private void registerConfigScreenFactory() { + ModLoadingContext.get().registerExtensionPoint( + ConfigScreenFactory.class, + () -> new ConfigScreenFactory((mc, screen) -> { + if (ModList.get().isLoaded("cloth_config")) { + return ClothConfigScreen.of(screen); + } else { + return NoClothConfigScreen.of(screen); + } + }) + ); + } +} diff --git a/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgNoFogGameModeCommand.java b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgNoFogGameModeCommand.java new file mode 100644 index 0000000..eed7f4e --- /dev/null +++ b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgNoFogGameModeCommand.java @@ -0,0 +1,93 @@ +package com.naocraftlab.foggypalegarden.forge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameType; +import net.minecraftforge.client.event.RegisterClientCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import java.util.stream.Stream; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static java.util.stream.Collectors.joining; +import static net.minecraft.ChatFormatting.GOLD; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgNoFogGameModeCommand implements FpgCommand { + + @SubscribeEvent + public static void registerCommands(RegisterClientCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + dispatcher.register( + Commands.literal(BASE_COMMAND) + .then(Commands.literal(NO_FOG_GAME_MODE_ARGUMENT) + .executes(FpgNoFogGameModeCommand::listNoFogGameModes) + .then(Commands.argument(NO_FOG_GAME_MODE_ARGUMENT_FIRST_ARG, StringArgumentType.string()) + .suggests((context, builder) -> SharedSuggestionProvider.suggest( + Stream.of(GameType.values()).map(Enum::name), builder + )) + .executes(FpgNoFogGameModeCommand::toggleFogForGameMode) + ) + ) + ); + } + + private static int toggleFogForGameMode(CommandContext context) { + String argumentValue = StringArgumentType.getString(context, NO_FOG_GAME_MODE_ARGUMENT_FIRST_ARG); + try { + GameType gameMode = GameType.valueOf(argumentValue.toUpperCase()); + if (configFacade().toggleNoFogGameMode(gameMode)) { + context.getSource().sendFailure( + Component.translatable("fpg.command.noFogGameMode.off", gameMode.name()) + .withStyle(style -> style.withColor(GOLD)) + ); + } else { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.on", gameMode.name()) + .withStyle(style -> style.withColor(GREEN)), + false + ); + } + configFacade().save(); + return 1; + } catch (Exception e) { + String gameModes = Stream.of(GameType.values()) + .map(Enum::name) + .collect(joining("\n")); + context.getSource().sendFailure( + Component.translatable("fpg.command.noFogGameMode.notFound", argumentValue, gameModes) + .withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } + + private static int listNoFogGameModes(CommandContext context) { + if (!configFacade().noFogGameModes().isEmpty()) { + String noFogGameModes = configFacade().noFogGameModes().stream() + .map(GameType::name) + .collect(joining("\n")); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.list", noFogGameModes) + .withStyle(style -> style.withColor(GREEN)), + false + ); + } else { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.listEmpty") + .withStyle(style -> style.withColor(GREEN)), + false + ); + } + return 1; + } +} diff --git a/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgPresetCommand.java b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgPresetCommand.java new file mode 100644 index 0000000..ee5a051 --- /dev/null +++ b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgPresetCommand.java @@ -0,0 +1,78 @@ +package com.naocraftlab.foggypalegarden.forge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraftforge.client.event.RegisterClientCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgPresetCommand implements FpgCommand { + + private static final SuggestionProvider PRESET_SUGGESTIONS = (context, builder) -> { + val presets = configFacade().getAvailablePresetCodes(); + return net.minecraft.commands.SharedSuggestionProvider.suggest(presets, builder); + }; + + @SubscribeEvent + public static void registerCommands(RegisterClientCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + + val command = Commands.literal(BASE_COMMAND) + .then(Commands.literal(PRESET_ARGUMENT) + .then(Commands.argument(PRESET_ARGUMENT, StringArgumentType.string()) + .suggests(PRESET_SUGGESTIONS) + .executes(FpgPresetCommand::setPreset)) + .executes(context -> { + val currentPreset = configFacade().getCurrentPreset().getCode(); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.preset.current", currentPreset), + false); + return 1; + }) + ).executes(context -> { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.help", String.join("\n", ALL_ARGUMENTS)), + false); + return 1; + }); + + dispatcher.register(command); + } + + private static int setPreset(CommandContext context) { + val preset = StringArgumentType.getString(context, PRESET_ARGUMENT); + try { + if (configFacade().setCurrentPreset(preset)) { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.preset.applied", preset).withStyle(style -> style.withColor(GREEN)), + false + ); + configFacade().save(); + return 1; + } else { + val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); + context.getSource().sendFailure( + Component.translatable("fpg.command.preset.notFound", preset, allPresets).withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } catch (Exception e) { + context.getSource().sendFailure( + Component.translatable("fpg.command.preset.exception", e.getMessage()).withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } +} diff --git a/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgReloadConfigCommand.java b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgReloadConfigCommand.java new file mode 100644 index 0000000..2ff11b7 --- /dev/null +++ b/forge/src/main/java/com/naocraftlab/foggypalegarden/forge/command/FpgReloadConfigCommand.java @@ -0,0 +1,49 @@ +package com.naocraftlab.foggypalegarden.forge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraftforge.client.event.RegisterClientCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgReloadConfigCommand implements FpgCommand { + + @SubscribeEvent + public static void registerCommands(RegisterClientCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + dispatcher.register( + Commands.literal(BASE_COMMAND) + .then(Commands.literal(RELOAD_CONFIG_ARGUMENT).executes(FpgReloadConfigCommand::reloadConfig)) + ); + } + + private static int reloadConfig(CommandContext context) { + try { + configFacade().load(); + val currentPreset = configFacade().getCurrentPreset().getCode(); + val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.reloadConfig.success", currentPreset, allPresets) + .withStyle(style -> style.withColor(GREEN)), + false + ); + return 1; + } catch (Exception e) { + context.getSource().sendFailure( + Component.translatable("fpg.command.reloadConfig.exception", e.getMessage()) + .withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..c1068f3 --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,34 @@ +modLoader = "javafml" +loaderVersion = "[${forgeMinLoaderVersion},)" +issueTrackerURL = "${modIssueTracker}" +displayURL = "${modHomepage}" +license = "${modLicense}" + +[[mods]] +modId = "${modId}" +version = "${modVersion}" +displayName = "${modName}" +authors = "NaoCraftLab" +description = "${modDescription}" +logoFile = "assets/${modId}/icon.png" + +[[dependencies.${modId}]] +modId = "forge" +mandatory = true +versionRange = "[${forgeMinVersion},)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.${modId}]] +modId = "minecraft" +mandatory = true +versionRange = "[${forgeMinMinecraftVersion},)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.${modId}]] +modId = "cloth_config" +mandatory = false +versionRange = "[${commonClothConfigVersion},)" +ordering = "NONE" +side = "CLIENT" diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..47358fb --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "${modName} resources", + "pack_format": 8 + } +} diff --git a/gradle.properties b/gradle.properties index c142e05..e14ab5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,14 @@ org.gradle.jvmargs=-Xmx3G -org.gradle.parallel=true + +# minecraft +minecraftVersion=1.21.3 +minecraftMappingsVersion=1.21.3 +minecraftJavaVersion=21 # mod -group=com.naocraftlab +modGroup=com.naocraftlab modId=foggypalegarden -modCurseForgeId=1114471 -modVersion=2.8.0 +modVersion=2.8.1 modName=Foggy Pale Garden modDescription=Adds dense fog to the Pale Garden biome. modLicense=MIT @@ -19,19 +22,37 @@ modDiscord=https://discord.gg/NmzHNyrGK4 modKoFi=https://ko-fi.com/naocraftlab modAuthorYouTube=https://www.youtube.com/@NaoCraftLab -# minecraft -minecraftJavaVersion=21 -minecraftFirstSnapshotVersion=24w40a -minecraftFirstSnapshotFullVersion=1.21.2-alpha.24.40.a -minecraftReleaseVersion=1.21.2 +# architectury +architecturyPlatforms=fabric,neoforge,forge +architecturyPluginVersion=3.4-SNAPSHOT +architecturyLoomVersion=1.7-SNAPSHOT + +# common +commonShadowVersion=8.1.1 +commonModrinthMinotaurVersion=2.+ +commonCurseGradleVersion=1.4.0 +commonLombokVersion=1.18.34 +commonFabricLoaderVersion=0.16.9 +commonClothConfigVersion=16.0.143 +commonJunitVersion=5.8.2 +commonMockitoVersion=4.0.0 +commonAssertJVersion=3.21.0 +commonJsonAssertVersion=1.5.0 # fabric -fabricSupportedLoaders=Fabric, Quilt -fabricYarnMappingsVersion=24w40a+build.11 -fabricLoomVersion=1.8-SNAPSHOT -fabricLoaderMinVersion=0.16.4 -fabricApiVersion=0.105.2+1.21.2 -clothConfigVersion=16.0.141 +fabricApiVersion=0.112.1+1.21.3 +fabricMinMinecraftVersion=1.21.3 fabricModMenuVersion=12.0.0-beta.1 -fabricModrinthGameVersions=24w40a,1.21.2-pre1,1.21.2-pre2,1.21.2-pre3,1.21.2-pre4,1.21.2-pre5,1.21.2-rc1,1.21.2-rc2,1.21.2,1.21.3,24w44a,24w45a,24w46a,1.21.4-pre1,1.21.4-pre2,1.21.4-pre3,1.21.4-rc1,1.21.4-rc2,1.21.4-rc3,1.21.4 -fabricCurseForgeGameVersions=1.21.2-Snapshot,1.21.2,1.21.3,1.21.4-Snapshot,1.21.4 + +# neoforge +neoforgeVersion=21.3.58 +neoforgeMinVersion=21.3.0-beta +neoforgeMinLoaderVersion=4 +neoforgeMinMinecraftVersion=1.21.3 + +# forge +forgeVersion=1.21.3-53.0.25 +forgeMinVersion=53.0.0 +forgeMinLoaderVersion=53 +forgeMinMinecraftVersion=1.21.3 +forgeJoptSimpleVersion=5.0.4 diff --git a/mcVersions/1.21.2-snapshot.properties b/mcVersions/1.21.2-snapshot.properties new file mode 100644 index 0000000..ab54e74 --- /dev/null +++ b/mcVersions/1.21.2-snapshot.properties @@ -0,0 +1,18 @@ +# minecraft +minecraftVersion=24w40a +minecraftMappingsVersion=24w40a +minecraftJavaVersion=21 + +# architectury +architecturyPlatforms=fabric +architecturyPluginVersion=3.4-SNAPSHOT +architecturyLoomVersion=1.7-SNAPSHOT + +# common +commonShadowVersion=8.1.1 +commonClothConfigVersion=16.0.141 + +# fabric +fabricApiVersion=0.105.2+1.21.2 +fabricMinMinecraftVersion=1.21.2-alpha.24.40.a +fabricModMenuVersion=12.0.0-beta.1 diff --git a/mcVersions/1.21.2.properties b/mcVersions/1.21.2.properties new file mode 100644 index 0000000..26ad05d --- /dev/null +++ b/mcVersions/1.21.2.properties @@ -0,0 +1,19 @@ +# minecraft +minecraftVersion=1.21.2 +minecraftMappingsVersion=1.21.2 +minecraftJavaVersion=21 + +# architectury +architecturyPlatforms=neoforge +architecturyPluginVersion=3.4-SNAPSHOT +architecturyLoomVersion=1.7-SNAPSHOT + +# common +commonShadowVersion=8.1.1 +commonClothConfigVersion=16.0.141 + +# neoforge +neoforgeVersion=21.2.1-beta +neoforgeMinVersion=21.2.0-beta +neoforgeMinLoaderVersion=4 +neoforgeMinMinecraftVersion=1.21.2 diff --git a/mcVersions/1.21.3.properties b/mcVersions/1.21.3.properties new file mode 100644 index 0000000..50d59b9 --- /dev/null +++ b/mcVersions/1.21.3.properties @@ -0,0 +1,20 @@ +# minecraft +minecraftVersion=1.21.3 +minecraftMappingsVersion=1.21.3 +minecraftJavaVersion=21 + +# architectury +architecturyPlatforms=forge +architecturyPluginVersion=3.4-SNAPSHOT +architecturyLoomVersion=1.7-SNAPSHOT + +# common +commonShadowVersion=8.1.1 +commonClothConfigVersion=16.0.143 + +# forge +forgeVersion=1.21.3-53.0.25 +forgeMinVersion=53.0.0 +forgeMinLoaderVersion=53 +forgeMinMinecraftVersion=1.21.3 +forgeJoptSimpleVersion=5.0.4 diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..16fccc6 --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,48 @@ +architectury { + platformSetupLoomIde() + neoForge() +} + +configurations { + common + shadowCommon + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentNeoForge.extendsFrom common +} + +dependencies { + neoForge "net.neoforged:neoforge:${project.ext.neoforgeVersion}" + + common(project(path: ':common', configuration: 'namedElements')) { transitive false } + shadowCommon(project(path: ':common', configuration: 'transformProductionNeoForge')) { transitive false } + + modImplementation "me.shedaniel.cloth:cloth-config-neoforge:${project.ext.commonClothConfigVersion}" +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + archiveClassifier.set('dev-shadow') +} + +remapJar { + inputFile = shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set(null) +} + +jar { + archiveClassifier.set('dev') +} + +sourcesJar { + def commonSources = project(':common').sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} \ No newline at end of file diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 0000000..7da18ea --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge diff --git a/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/FoggyPaleGardenClientMod.java b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/FoggyPaleGardenClientMod.java new file mode 100644 index 0000000..24aad8f --- /dev/null +++ b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/FoggyPaleGardenClientMod.java @@ -0,0 +1,47 @@ +package com.naocraftlab.foggypalegarden.neoforge; + +import com.mojang.logging.LogUtils; +import com.naocraftlab.foggypalegarden.gui.ClothConfigScreen; +import com.naocraftlab.foggypalegarden.gui.NoClothConfigScreen; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.fml.loading.moddiscovery.ModInfo; +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; +import org.slf4j.Logger; + +import static com.naocraftlab.foggypalegarden.FoggyPaleGarden.MOD_ID; +import static net.neoforged.api.distmarker.Dist.CLIENT; +import static net.neoforged.fml.common.EventBusSubscriber.Bus.MOD; + +@OnlyIn(CLIENT) +@EventBusSubscriber(modid = MOD_ID, bus = MOD, value = CLIENT) +public final class FoggyPaleGardenClientMod { + + private static final Logger LOGGER = LogUtils.getLogger(); + + @SubscribeEvent + public static void onClientSetup(FMLClientSetupEvent event) { + ModLoadingContext.get().registerExtensionPoint( + IConfigScreenFactory.class, + () -> (modContainer, parent) -> { + if (isModLoaded("cloth_config")) { + return ClothConfigScreen.of(parent); + } else { + return NoClothConfigScreen.of(parent); + } + } + ); + LOGGER.info("Foggy Pale Garden client setup complete"); + } + + private static boolean isModLoaded(String modId) { + return FMLLoader.getLoadingModList().getMods() + .stream() + .map(ModInfo::getModId) + .anyMatch(id -> id.equals(modId)); + } +} diff --git a/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgNoFogGameModeCommand.java b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgNoFogGameModeCommand.java new file mode 100644 index 0000000..f1c4a31 --- /dev/null +++ b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgNoFogGameModeCommand.java @@ -0,0 +1,93 @@ +package com.naocraftlab.foggypalegarden.neoforge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.GameType; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.RegisterCommandsEvent; + +import java.util.stream.Stream; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static java.util.stream.Collectors.joining; +import static net.minecraft.ChatFormatting.GOLD; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgNoFogGameModeCommand implements FpgCommand { + + @SubscribeEvent + public static void registerCommands(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + dispatcher.register( + Commands.literal(BASE_COMMAND) + .then(Commands.literal(NO_FOG_GAME_MODE_ARGUMENT) + .executes(FpgNoFogGameModeCommand::listNoFogGameModes) + .then(Commands.argument(NO_FOG_GAME_MODE_ARGUMENT_FIRST_ARG, StringArgumentType.string()) + .suggests((context, builder) -> SharedSuggestionProvider.suggest( + Stream.of(GameType.values()).map(Enum::name), builder + )) + .executes(FpgNoFogGameModeCommand::toggleFogForGameMode) + ) + ) + ); + } + + private static int toggleFogForGameMode(CommandContext context) { + String argumentValue = StringArgumentType.getString(context, NO_FOG_GAME_MODE_ARGUMENT_FIRST_ARG); + try { + GameType gameMode = GameType.valueOf(argumentValue.toUpperCase()); + if (configFacade().toggleNoFogGameMode(gameMode)) { + context.getSource().sendFailure( + Component.translatable("fpg.command.noFogGameMode.off", gameMode.name()) + .withStyle(style -> style.withColor(GOLD)) + ); + } else { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.on", gameMode.name()) + .withStyle(style -> style.withColor(GREEN)), + false + ); + } + configFacade().save(); + return 1; + } catch (Exception e) { + String gameModes = Stream.of(GameType.values()) + .map(Enum::name) + .collect(joining("\n")); + context.getSource().sendFailure( + Component.translatable("fpg.command.noFogGameMode.notFound", argumentValue, gameModes) + .withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } + + private static int listNoFogGameModes(CommandContext context) { + if (!configFacade().noFogGameModes().isEmpty()) { + String noFogGameModes = configFacade().noFogGameModes().stream() + .map(GameType::name) + .collect(joining("\n")); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.list", noFogGameModes) + .withStyle(style -> style.withColor(GREEN)), + false + ); + } else { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.noFogGameMode.listEmpty") + .withStyle(style -> style.withColor(GREEN)), + false + ); + } + return 1; + } +} diff --git a/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgPresetCommand.java b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgPresetCommand.java new file mode 100644 index 0000000..45d8ff6 --- /dev/null +++ b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgPresetCommand.java @@ -0,0 +1,78 @@ +package com.naocraftlab.foggypalegarden.neoforge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.RegisterCommandsEvent; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgPresetCommand implements FpgCommand { + + private static final SuggestionProvider PRESET_SUGGESTIONS = (context, builder) -> { + val presets = configFacade().getAvailablePresetCodes(); + return net.minecraft.commands.SharedSuggestionProvider.suggest(presets, builder); + }; + + @SubscribeEvent + public static void registerCommands(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + + val command = Commands.literal(BASE_COMMAND) + .then(Commands.literal(PRESET_ARGUMENT) + .then(Commands.argument(PRESET_ARGUMENT, StringArgumentType.string()) + .suggests(PRESET_SUGGESTIONS) + .executes(FpgPresetCommand::setPreset)) + .executes(context -> { + val currentPreset = configFacade().getCurrentPreset().getCode(); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.preset.current", currentPreset), + false); + return 1; + }) + ).executes(context -> { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.help", String.join("\n", ALL_ARGUMENTS)), + false); + return 1; + }); + + dispatcher.register(command); + } + + private static int setPreset(CommandContext context) { + val preset = StringArgumentType.getString(context, PRESET_ARGUMENT); + try { + if (configFacade().setCurrentPreset(preset)) { + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.preset.applied", preset).withStyle(style -> style.withColor(GREEN)), + false + ); + configFacade().save(); + return 1; + } else { + val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); + context.getSource().sendFailure( + Component.translatable("fpg.command.preset.notFound", preset, allPresets).withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } catch (Exception e) { + context.getSource().sendFailure( + Component.translatable("fpg.command.preset.exception", e.getMessage()).withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } +} diff --git a/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgReloadConfigCommand.java b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgReloadConfigCommand.java new file mode 100644 index 0000000..257be27 --- /dev/null +++ b/neoforge/src/main/java/com/naocraftlab/foggypalegarden/neoforge/command/FpgReloadConfigCommand.java @@ -0,0 +1,49 @@ +package com.naocraftlab.foggypalegarden.neoforge.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.naocraftlab.foggypalegarden.command.FpgCommand; +import lombok.val; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.RegisterCommandsEvent; + +import static com.naocraftlab.foggypalegarden.config.ConfigFacade.configFacade; +import static net.minecraft.ChatFormatting.GREEN; +import static net.minecraft.ChatFormatting.RED; + +@EventBusSubscriber +public final class FpgReloadConfigCommand implements FpgCommand { + + @SubscribeEvent + public static void registerCommands(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + dispatcher.register( + Commands.literal(BASE_COMMAND) + .then(Commands.literal(RELOAD_CONFIG_ARGUMENT).executes(FpgReloadConfigCommand::reloadConfig)) + ); + } + + private static int reloadConfig(CommandContext context) { + try { + configFacade().load(); + val currentPreset = configFacade().getCurrentPreset().getCode(); + val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); + context.getSource().sendSuccess( + () -> Component.translatable("fpg.command.reloadConfig.success", currentPreset, allPresets) + .withStyle(style -> style.withColor(GREEN)), + false + ); + return 1; + } catch (Exception e) { + context.getSource().sendFailure( + Component.translatable("fpg.command.reloadConfig.exception", e.getMessage()) + .withStyle(style -> style.withColor(RED)) + ); + return 0; + } + } +} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 0000000..c944554 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,30 @@ +modLoader = "javafml" +loaderVersion = "[${neoforgeMinLoaderVersion},)" +issueTrackerURL = "${modIssueTracker}" +displayURL = "${modHomepage}" +license = "${modLicense}" + +[[mods]] +modId = "${modId}" +version = "${modVersion}" +displayName = "${modName}" +authors = "NaoCraftLab" +description = "${modDescription}" +logoFile = "assets/${modId}/icon.png" + +[[mixins]] +config = "${modId}-common.mixins.json" + +[[dependencies.${modId}]] +modId = "neoforge" +mandatory = true +versionRange = "[${neoforgeMinVersion},)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.${modId}]] +modId = "minecraft" +mandatory = true +versionRange = "[${neoforgeMinMinecraftVersion},)" +ordering = "NONE" +side = "BOTH" diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..cb533dd --- /dev/null +++ b/settings.gradle @@ -0,0 +1,57 @@ +pluginManagement { + includeBuild("buildPluginSrc") + + repositories { + mavenCentral() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + maven { + name = 'Forge' + url = 'https://maven.minecraftforge.net/' + } + maven { + name = 'Architectury Plugin' + url = 'https://maven.architectury.dev/' + } + maven { + name = 'JitPack' + url = "https://jitpack.io" + } + gradlePluginPortal() + } + + plugins { + id 'architectury-plugin' version "${settings.ext.architecturyPluginVersion}" + id 'dev.architectury.loom' version "${settings.ext.architecturyLoomVersion}" apply false + id 'com.github.johnrengelman.shadow' version "${settings.ext.commonShadowVersion}" apply false + id 'com.modrinth.minotaur' version "${settings.ext.commonModrinthMinotaurVersion}" apply false + id 'com.matthewprenger.cursegradle' version "${settings.ext.commonCurseGradleVersion}" apply false + } +} + +plugins { + id 'com.naocraftlab.load-properties-settings-plugin' +} + +include('common') + +def platforms = settings.ext.architecturyPlatforms.split(',') +if (platforms.contains('fabric')) { + include('fabric') +} else { + println 'Fabric module is disabled for this version.' +} +if (platforms.contains('forge')) { + include('forge') +} else { + println 'Forge module is disabled for this version.' +} +if (platforms.contains('neoforge')) { + include('neoforge') +} else { + println 'NeoForge module is disabled for this version.' +} + +rootProject.name = modId diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index f874cbf..0000000 --- a/settings.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -pluginManagement { - repositories { - maven { url = uri("https://maven.fabricmc.net/") } - gradlePluginPortal() - mavenCentral() - } - - plugins { - val fabricLoomVersion: String by settings - id("fabric-loom") version fabricLoomVersion - } -} - -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" -} - -val modId: String by settings -rootProject.name = modId diff --git a/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGardenClientMod.java b/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGardenClientMod.java deleted file mode 100644 index 492d0a1..0000000 --- a/src/main/java/com/naocraftlab/foggypalegarden/FoggyPaleGardenClientMod.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.naocraftlab.foggypalegarden; - -import com.mojang.brigadier.CommandDispatcher; -import com.naocraftlab.foggypalegarden.command.FpgNoFogGameModeCommand; -import com.naocraftlab.foggypalegarden.command.FpgPresetCommand; -import com.naocraftlab.foggypalegarden.command.FpgReloadConfigCommand; -import com.naocraftlab.foggypalegarden.config.ConfigFacade; -import com.naocraftlab.foggypalegarden.config.ConfigMigrator; -import com.naocraftlab.foggypalegarden.domain.service.FogService; -import lombok.val; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.fabricmc.loader.api.FabricLoader; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Paths; - -public class FoggyPaleGardenClientMod implements ClientModInitializer { - - public static final String MOD_ID = "foggypalegarden"; - - private static ConfigFacade configFacade; - - - @Override - public void onInitializeClient() { - initConfigFacade(); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - registerCommands(dispatcher); - }); - } - - @NotNull - public static ConfigFacade configFacade() { - if (configFacade == null) { - initConfigFacade(); - } - return configFacade; - } - - - private static void initConfigFacade() { - val configFilePtah = FabricLoader.getInstance().getConfigDir().resolve(Paths.get(MOD_ID + ".json")); - val presetDirectoryPath = FabricLoader.getInstance().getConfigDir().resolve(Paths.get(MOD_ID.replaceAll("-", ""))); - configFacade = new ConfigFacade(configFilePtah, presetDirectoryPath, new ConfigMigrator(presetDirectoryPath)); - configFacade.registerCurrentPresetListener(FogService::onCurrentPresetChange); - configFacade.load(); - } - - private static void registerCommands(CommandDispatcher dispatcher) { - FpgPresetCommand.register(dispatcher); - FpgReloadConfigCommand.register(dispatcher); - FpgNoFogGameModeCommand.register(dispatcher); - } -} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgNoFogGameModeCommand.java b/src/main/java/com/naocraftlab/foggypalegarden/command/FpgNoFogGameModeCommand.java deleted file mode 100644 index 1fd784c..0000000 --- a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgNoFogGameModeCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.naocraftlab.foggypalegarden.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import lombok.val; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandSource; -import net.minecraft.text.Text; -import net.minecraft.world.GameMode; - -import java.util.stream.Stream; - -import static com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod.configFacade; -import static java.util.stream.Collectors.joining; -import static net.minecraft.util.Formatting.GREEN; -import static net.minecraft.util.Formatting.RED; -import static net.minecraft.util.Formatting.YELLOW; - -public class FpgNoFogGameModeCommand implements FpgCommand { - - private static final SuggestionProvider GAME_MODE_SUGGESTIONS - = (context, builder) -> CommandSource.suggestMatching(Stream.of(GameMode.values()).map(Enum::name), builder); - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register( - ClientCommandManager.literal(BASE_COMMAND).then(ClientCommandManager.literal(NO_FOG_GAME_MODE_ARGUMENT) - .executes(FpgNoFogGameModeCommand::listNoFogGameModes) - .then(ClientCommandManager.argument(NO_FOG_GAME_MODE_ARGUMENT, StringArgumentType.string()) - .suggests(GAME_MODE_SUGGESTIONS) - .executes(FpgNoFogGameModeCommand::toggleFogForGameMode) - ) - ) - ); - } - - private static int toggleFogForGameMode(CommandContext context) { - val argumentValue = StringArgumentType.getString(context, NO_FOG_GAME_MODE_ARGUMENT); - try { - val gameMode = GameMode.valueOf(argumentValue); - if (configFacade().toggleNoFogGameMode(gameMode)) { - context.getSource().sendError(Text.translatable("fpg.command.noFogGameMode.off", gameMode).formatted(YELLOW)); - } else { - context.getSource().sendFeedback(Text.translatable("fpg.command.noFogGameMode.on", gameMode).formatted(GREEN)); - } - configFacade().save(); - return 1; - } catch (Exception e) { - val gameModes = Stream.of(GameMode.values()).map(Enum::name).collect(joining("\n")); - context.getSource().sendError( - Text.translatable("fpg.command.noFogGameMode.notFound", argumentValue, gameModes).formatted(RED) - ); - return 0; - } - } - - private static int listNoFogGameModes(CommandContext context) { - if (!configFacade().noFogGameModes().isEmpty()) { - val noFogGameModes = configFacade().noFogGameModes().stream() - .map(GameMode::name) - .collect(joining("\n")); - context.getSource().sendFeedback(Text.translatable("fpg.command.noFogGameMode.list", noFogGameModes).formatted(GREEN)); - } else { - context.getSource().sendFeedback(Text.translatable("fpg.command.noFogGameMode.listEmpty").formatted(GREEN)); - } - return 1; - } -} \ No newline at end of file diff --git a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgPresetCommand.java b/src/main/java/com/naocraftlab/foggypalegarden/command/FpgPresetCommand.java deleted file mode 100644 index ee6da31..0000000 --- a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgPresetCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.naocraftlab.foggypalegarden.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import lombok.val; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.command.CommandSource; -import net.minecraft.text.Text; - -import static com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod.configFacade; -import static net.minecraft.util.Formatting.GREEN; -import static net.minecraft.util.Formatting.RED; - -public class FpgPresetCommand implements FpgCommand { - - private static final SuggestionProvider PRESET_SUGGESTIONS = (context, builder) -> { - val presets = configFacade().getAvailablePresetCodes(); - return CommandSource.suggestMatching(presets, builder); - }; - - public static void register(CommandDispatcher dispatcher) { - val command = ClientCommandManager.literal(BASE_COMMAND) - .then(ClientCommandManager.literal(PRESET_ARGUMENT) - .then(ClientCommandManager.argument(PRESET_ARGUMENT, StringArgumentType.string()) - .suggests(PRESET_SUGGESTIONS) - .executes(FpgPresetCommand::setPreset)) - .executes(context -> { - val currentPreset = configFacade().getCurrentPreset().getCode(); - context.getSource().sendFeedback(Text.translatable("fpg.command.preset.current", currentPreset)); - return 1; - }) - ).executes(context -> { - context.getSource().sendFeedback(Text.translatable("fpg.command.help", String.join("\n", ALL_ARGUMENTS))); - return 1; - }); - - dispatcher.register(command); - } - - private static int setPreset(CommandContext context) { - val preset = StringArgumentType.getString(context, PRESET_ARGUMENT); - try { - if (configFacade().setCurrentPreset(preset)) { - context.getSource().sendFeedback(Text.translatable("fpg.command.preset.applied", preset).formatted(GREEN)); - configFacade().save(); - return 1; - } else { - val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); - context.getSource().sendError(Text.translatable("fpg.command.preset.notFound", preset, allPresets).formatted(RED)); - return 0; - } - } catch (Exception e) { - context.getSource().sendError(Text.translatable("fpg.command.preset.exception", e.getMessage()).formatted(RED)); - return 0; - } - } -} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgReloadConfigCommand.java b/src/main/java/com/naocraftlab/foggypalegarden/command/FpgReloadConfigCommand.java deleted file mode 100644 index 54bd5f3..0000000 --- a/src/main/java/com/naocraftlab/foggypalegarden/command/FpgReloadConfigCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.naocraftlab.foggypalegarden.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import lombok.val; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.text.Text; - -import static com.naocraftlab.foggypalegarden.FoggyPaleGardenClientMod.configFacade; -import static net.minecraft.util.Formatting.GREEN; -import static net.minecraft.util.Formatting.RED; - -public class FpgReloadConfigCommand implements FpgCommand { - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register( - ClientCommandManager.literal(BASE_COMMAND) - .then(ClientCommandManager.literal(RELOAD_CONFIG_ARGUMENT).executes(FpgReloadConfigCommand::reloadConfig)) - ); - } - - private static int reloadConfig(CommandContext context) { - try { - configFacade().load(); - val currentPreset = configFacade().getCurrentPreset().getCode(); - val allPresets = String.join("\n", configFacade().getAvailablePresetCodes()); - context.getSource().sendFeedback( - Text.translatable("fpg.command.reloadConfig.success", currentPreset, allPresets).formatted(GREEN) - ); - return 1; - } catch (Exception e) { - context.getSource().sendError(Text.translatable("fpg.command.reloadConfig.exception", e.getMessage()).formatted(RED)); - return 0; - } - } -} diff --git a/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java b/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java deleted file mode 100644 index 26d3048..0000000 --- a/src/main/java/com/naocraftlab/foggypalegarden/gui/NoClothConfigScreen.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.naocraftlab.foggypalegarden.gui; - -import it.unimi.dsi.fastutil.booleans.BooleanConsumer; -import lombok.experimental.UtilityClass; -import lombok.val; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ConfirmLinkScreen; -import net.minecraft.client.gui.screen.Screen; - -import java.net.URI; - -import static net.minecraft.text.Text.translatable; -import static net.minecraft.util.Util.getOperatingSystem; - -@UtilityClass -public class NoClothConfigScreen { - - private static final URI CLOTH_CONFIG_MODRINTH = URI.create("https://modrinth.com/mod/cloth-config"); - - public static Screen of(Screen parent) { - return new ConfirmLinkScreen(onClick(parent), translatable("fpg.settings.warning.noClothConfig"), CLOTH_CONFIG_MODRINTH, true); - } - - private static BooleanConsumer onClick(Screen parent) { - return confirmed -> { - val client = MinecraftClient.getInstance(); - if (confirmed) { - getOperatingSystem().open(CLOTH_CONFIG_MODRINTH); - } - client.setScreen(parent); - }; - } -} diff --git a/src/test/java/com/naocraftlab/foggypalegarden/TestUtils.java b/src/test/java/com/naocraftlab/foggypalegarden/TestUtils.java deleted file mode 100644 index 16c8b5f..0000000 --- a/src/test/java/com/naocraftlab/foggypalegarden/TestUtils.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.naocraftlab.foggypalegarden; - -import lombok.experimental.UtilityClass; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.stream.Stream; - -@UtilityClass -public class TestUtils { - - public static long fileCount(Path directory) throws IOException { - try (Stream files = Files.list(directory)) { - return files.count(); - } - } -}