From 8e8c774574cf28fa0c0a1a7c6dfbd6a7fd44442b Mon Sep 17 00:00:00 2001 From: RSwoop <47505753+RSwoop@users.noreply.github.com> Date: Mon, 5 Aug 2024 04:21:46 +0200 Subject: [PATCH] Code cleanup --- .github/workflows/codeql.yml | 54 +-- .github/workflows/fg-2.1.yml | 34 +- .github/workflows/fg-6.0.yml | 42 +-- .github/workflows/ng-7.0.yml | 36 +- README.md | 21 +- common/gradle.properties | 4 - docs/_config.yml | 2 +- docs/_includes/head_custom.html | 2 +- docs/_includes/nav_footer_custom.html | 3 +- docs/config.md | 14 +- docs/develop/develop.md | 1 + docs/index.md | 60 +++- docs/release-notes/release-notes.md | 1 + docs/release-notes/v0.1.md | 3 +- docs/release-notes/v0.2.md | 6 +- docs/release-notes/v0.3.md | 3 +- docs/release-notes/v0.4.md | 12 +- docs/setup.md | 18 +- docs/troubleshoot.md | 8 +- docs/updates.json | 164 ++++----- forge/fg-2.1/1.8.9/build.gradle | 2 +- .../therainbowville/minegasm/Minegasm.java | 16 +- .../minegasm/client/ClientEventHandler.java | 10 +- .../minegasm/client/ClientProxy.java | 4 +- .../minegasm/client/ToyController.java | 11 +- .../minegasm/common/CommonProxy.java | 3 +- .../src/main/resources/META-INF/mods.toml | 48 +-- .../1.8.9/src/main/resources/mcmod.info | 30 +- .../1.8.9/src/main/resources/pack.mcmeta | 12 +- forge/fg-2.1/gradle.properties | 1 - forge/fg-6.0/1.12.2/build.gradle | 54 +-- forge/fg-6.0/1.12.2/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 231 ++++++------- .../minegasm/client/ClientProxy.java | 10 +- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 104 +++--- .../minegasm/common/CommonProxy.java | 20 +- .../common/VibrationStateAdvancement.java | 66 ++-- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 30 +- .../common/VibrationStateHarvest.java | 28 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 33 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ConfigScreen.java | 305 ++++++++--------- .../minegasm/config/MinegasmConfig.java | 218 ++++++------ .../minegasm/config/ModListMenuScreen.java | 18 +- .../minegasm/config/PauseMenuButton.java | 108 +++--- .../config/PauseMenuButtonScreen.java | 33 +- .../mixin/ClientAdvancementManagerMixin.java | 11 +- .../minegasm/mixin/EntityPlayerSPMixin.java | 29 +- .../mixin/PlayerControllerMPMixin.java | 51 ++- .../minegasm/widgets/ButtonPress.java | 3 +- .../minegasm/widgets/GuiButtonExtraExt.java | 24 +- .../src/main/resources/META-INF/mods.toml | 48 +-- .../1.12.2/src/main/resources/mcmod.info | 30 +- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.12.2/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.15.2/build.gradle | 14 +- forge/fg-6.0/1.15.2/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 233 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 99 +++--- .../minegasm/common/Minegasm.java | 6 +- .../common/VibrationStateAdvancement.java | 66 ++-- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 29 +- .../common/VibrationStateHarvest.java | 28 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 114 +++---- .../minegasm/config/ConfigHelper.java | 48 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 294 ++++++++-------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 111 +++--- .../config/PauseMenuButtonScreen.java | 32 +- .../mixin/ClientAdvancementManagerMixin.java | 11 +- .../mixin/ClientPlayerEntityMixin.java | 21 +- .../minegasm/mixin/PlayerControllerMixin.java | 48 ++- .../minegasm/widgets/ForgeSlider.java | 127 +++---- .../src/main/resources/META-INF/mods.toml | 48 +-- .../resources/assets/minegasm/lang/en_us.json | 26 +- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.15.2/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.16.5/build.gradle | 14 +- forge/fg-6.0/1.16.5/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 231 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 99 +++--- .../minegasm/common/Minegasm.java | 6 +- .../common/VibrationStateAdvancement.java | 66 ++-- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 28 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 114 +++---- .../minegasm/config/ConfigHelper.java | 48 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 295 ++++++++-------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 116 +++---- .../config/PauseMenuButtonScreen.java | 34 +- .../mixin/ClientAdvancementManagerMixin.java | 11 +- .../mixin/ClientPlayerEntityMixin.java | 21 +- .../minegasm/mixin/PlayerControllerMixin.java | 48 ++- .../minegasm/widgets/ForgeSlider.java | 128 +++---- .../src/main/resources/META-INF/mods.toml | 48 +-- .../resources/assets/minegasm/lang/en_us.json | 26 +- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.16.5/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.18.2/build.gradle | 14 +- forge/fg-6.0/1.18.2/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 239 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 77 ++--- .../minegasm/common/Minegasm.java | 12 +- .../common/VibrationStateAdvancement.java | 49 ++- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 30 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 92 +++-- .../minegasm/config/ConfigHelper.java | 50 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 297 ++++++++-------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 155 ++++----- .../mixin/ClientAdvancementsMixin.java | 13 +- .../minegasm/mixin/LocalPlayerMixin.java | 26 +- .../mixin/MultiPlayerGameModeMixin.java | 52 ++- .../src/main/resources/META-INF/mods.toml | 48 +-- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.18.2/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.19.2/build.gradle | 14 +- forge/fg-6.0/1.19.2/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 236 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 77 ++--- .../minegasm/common/Minegasm.java | 12 +- .../common/VibrationStateAdvancement.java | 47 ++- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 30 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 92 +++-- .../minegasm/config/ConfigHelper.java | 55 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 297 ++++++++-------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 155 ++++----- .../mixin/ClientAdvancementsMixin.java | 13 +- .../minegasm/mixin/LocalPlayerMixin.java | 25 +- .../mixin/MultiPlayerGameModeMixin.java | 39 +-- .../src/main/resources/META-INF/mods.toml | 48 +-- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.19.2/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.19.4/build.gradle | 14 +- forge/fg-6.0/1.19.4/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 237 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 77 ++--- .../minegasm/common/Minegasm.java | 12 +- .../common/VibrationStateAdvancement.java | 47 ++- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 30 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 92 +++-- .../minegasm/config/ConfigHelper.java | 55 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 319 ++++++++--------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 91 +++-- .../mixin/ClientAdvancementsMixin.java | 13 +- .../minegasm/mixin/LocalPlayerMixin.java | 25 +- .../mixin/MultiPlayerGameModeMixin.java | 39 +-- .../src/main/resources/META-INF/mods.toml | 48 +-- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.19.4/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/1.20.4/build.gradle | 14 +- forge/fg-6.0/1.20.4/gradle.properties | 1 - .../minegasm/client/ClientEventHandler.java | 237 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 77 ++--- .../minegasm/common/Minegasm.java | 12 +- .../common/VibrationStateAdvancement.java | 45 ++- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 30 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 92 +++-- .../minegasm/config/ConfigHelper.java | 55 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 322 ++++++++---------- .../minegasm/config/MinegasmConfig.java | 21 +- .../minegasm/config/PauseMenuButton.java | 90 +++-- .../mixin/ClientAdvancementsMixin.java | 13 +- .../minegasm/mixin/LocalPlayerMixin.java | 25 +- .../mixin/MultiPlayerGameModeMixin.java | 39 +-- .../src/main/resources/META-INF/mods.toml | 48 +-- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.20.4/src/main/resources/pack.mcmeta | 12 +- forge/fg-6.0/gradle.properties | 4 - neoforge/ng-7.0/1.21/build.gradle | 2 +- neoforge/ng-7.0/1.21/gradle.properties | 3 - .../minegasm/client/ClientEventHandler.java | 240 ++++++------- .../minegasm/client/ToyController.java | 21 +- .../common/AbstractVibrationState.java | 77 ++--- .../minegasm/common/Minegasm.java | 12 +- .../common/VibrationStateAdvancement.java | 45 ++- .../minegasm/common/VibrationStateAttack.java | 21 +- .../minegasm/common/VibrationStateClient.java | 16 +- .../minegasm/common/VibrationStateFish.java | 25 +- .../common/VibrationStateHarvest.java | 30 +- .../minegasm/common/VibrationStateHurt.java | 22 +- .../minegasm/common/VibrationStateMine.java | 35 +- .../minegasm/common/VibrationStatePlace.java | 22 +- .../common/VibrationStateVitality.java | 35 +- .../common/VibrationStateXpChange.java | 42 ++- .../minegasm/config/ClientConfig.java | 88 +++-- .../minegasm/config/ConfigHelper.java | 50 ++- .../minegasm/config/ConfigHolder.java | 1 + .../minegasm/config/ConfigScreen.java | 289 ++++++++-------- .../minegasm/config/MinegasmConfig.java | 24 +- .../minegasm/config/PauseMenuButton.java | 71 ++-- .../mixin/ClientAdvancementsMixin.java | 13 +- .../minegasm/mixin/LocalPlayerMixin.java | 25 +- .../mixin/MultiPlayerGameModeMixin.java | 39 +-- .../src/main/resources/META-INF/mods.toml | 48 +-- .../src/main/resources/mixins.minegasm.json | 4 +- .../1.21/src/main/resources/pack.mcmeta | 12 +- neoforge/ng-7.0/gradle.properties | 4 - .../therainbowville/minegasm/Simulator.java | 8 +- .../minegasm/SimulatorTest.java | 3 +- 267 files changed, 5623 insertions(+), 6806 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a086ec4..b7e25ff 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -40,38 +40,38 @@ jobs: # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/fg-2.1.yml b/.github/workflows/fg-2.1.yml index cd6db19..bcf4baa 100644 --- a/.github/workflows/fg-2.1.yml +++ b/.github/workflows/fg-2.1.yml @@ -20,20 +20,20 @@ jobs: run: working-directory: forge/fg-2.1 steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: 8 - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - gradle-version: 4.10.3 - - name: Run Gradle build - working-directory: forge/fg-2.1 - run: gradle :${{ inputs.version }}:build - - uses: actions/upload-artifact@v4 - with: - name: Minegasm-${{ inputs.version }} - path: forge/fg-2.1/${{ inputs.version }}/build/libs/* + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: 4.10.3 + - name: Run Gradle build + working-directory: forge/fg-2.1 + run: gradle :${{ inputs.version }}:build + - uses: actions/upload-artifact@v4 + with: + name: Minegasm-${{ inputs.version }} + path: forge/fg-2.1/${{ inputs.version }}/build/libs/* diff --git a/.github/workflows/fg-6.0.yml b/.github/workflows/fg-6.0.yml index d93f548..8ba05f3 100644 --- a/.github/workflows/fg-6.0.yml +++ b/.github/workflows/fg-6.0.yml @@ -20,24 +20,24 @@ jobs: run: working-directory: forge/fg-6.0 steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: | - 8 - 16 - 17 - 21 - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - gradle-version: 8.9 - - name: Run Gradle build - working-directory: forge/fg-6.0 - run: gradle :${{ inputs.version }}:build - - uses: actions/upload-artifact@v4 - with: - name: Minegasm-${{ inputs.version }} - path: forge/fg-6.0/${{ inputs.version }}/build/libs/*-${{ inputs.version }}* + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: | + 8 + 16 + 17 + 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: 8.9 + - name: Run Gradle build + working-directory: forge/fg-6.0 + run: gradle :${{ inputs.version }}:build + - uses: actions/upload-artifact@v4 + with: + name: Minegasm-${{ inputs.version }} + path: forge/fg-6.0/${{ inputs.version }}/build/libs/*-${{ inputs.version }}* diff --git a/.github/workflows/ng-7.0.yml b/.github/workflows/ng-7.0.yml index 59fb223..a713f10 100644 --- a/.github/workflows/ng-7.0.yml +++ b/.github/workflows/ng-7.0.yml @@ -20,21 +20,21 @@ jobs: run: working-directory: neoforge/ng-7.0 steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: | - 21 - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - gradle-version: 8.9 - - name: Run Gradle build - working-directory: neoforge/ng-7.0 - run: gradle :${{ inputs.version }}:build - - uses: actions/upload-artifact@v4 - with: - name: Minegasm-${{ inputs.version }} - path: neoforge/ng-7.0/${{ inputs.version }}/build/libs/*-${{ inputs.version }}* + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: | + 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: 8.9 + - name: Run Gradle build + working-directory: neoforge/ng-7.0 + run: gradle :${{ inputs.version }}:build + - uses: actions/upload-artifact@v4 + with: + name: Minegasm-${{ inputs.version }} + path: neoforge/ng-7.0/${{ inputs.version }}/build/libs/*-${{ inputs.version }}* diff --git a/README.md b/README.md index fa6317d..bdd4038 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,20 @@ User Guide: https://www.minegasm.net/ -| Minecraft | Forge MDK | JDK | FG | Gradle | Status | -|-----------------------|--------------|-----|-----|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 1.20.4 | 49.1.0 | 17 | 6.0 | 8.9 | [![1.20.4](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.20.4.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.20.4.yml) | -| **1.19.4** | 45.3.0 | 17 | 6.0 | 8.9 | [![1.19.4](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.4.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.4.yml) | -| 1.19.2 | 43.4.0 | 17 | 6.0 | 8.9 | [![1.19.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.2.yml) | -| **1.18.2** | 40.2.0 | 17 | 6.0 | 8.9 | [![1.18.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.18.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.18.2.yml) | -| **1.16.5** | 36.2.34 | 8 | 6.0 | 8.9 | [![1.16.5](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.16.5.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.16.5.yml) | -| **1.15.2** | 31.2.57 | 8 | 6.0 | 8.9 | [![1.15.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.15.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.15.2.yml) | -| **1.12.2** | 14.23.5.2859 | 8 | 6.0 | 8.9 | [![1.12.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.12.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.12.2.yml) | +| Minecraft | Forge MDK | JDK | FG | Gradle | Status | +|------------|--------------|-----|-----|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 1.20.4 | 49.1.0 | 17 | 6.0 | 8.9 | [![1.20.4](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.20.4.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.20.4.yml) | +| **1.19.4** | 45.3.0 | 17 | 6.0 | 8.9 | [![1.19.4](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.4.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.4.yml) | +| 1.19.2 | 43.4.0 | 17 | 6.0 | 8.9 | [![1.19.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.19.2.yml) | +| **1.18.2** | 40.2.0 | 17 | 6.0 | 8.9 | [![1.18.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.18.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.18.2.yml) | +| **1.16.5** | 36.2.34 | 8 | 6.0 | 8.9 | [![1.16.5](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.16.5.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.16.5.yml) | +| **1.15.2** | 31.2.57 | 8 | 6.0 | 8.9 | [![1.15.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.15.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.15.2.yml) | +| **1.12.2** | 14.23.5.2859 | 8 | 6.0 | 8.9 | [![1.12.2](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.12.2.yml/badge.svg)](https://github.com/RainbowVille/minegasm/actions/workflows/gradle-forge-1.12.2.yml) | ## Work in progress -As more and more mods are switching to NeoForge, we plan to also completely switch to it from 1.21 onwards. We will have both Forge and NeoForge versions available for 1.20.6. +As more and more mods are switching to NeoForge, we plan to also completely switch to it from 1.21 onwards. We will have +both Forge and NeoForge versions available for 1.20.6. | Minecraft | (Neo)Forge MDK | JDK | FG/NG | Gradle | Status | |------------|----------------|-----|-------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/common/gradle.properties b/common/gradle.properties index a968cea..b42a06d 100644 --- a/common/gradle.properties +++ b/common/gradle.properties @@ -2,10 +2,7 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false - - ## Mod Properties - # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. mod_id=minegasm @@ -23,7 +20,6 @@ mod_group_id=com.therainbowville.minegasm mod_authors=RSwoop, RainbowVille's contributors # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description=Just a simple mod to bring some gasm into Minecraft. ;) - mod_issue_tracker_url=https://github.com/RainbowVille/minegasm/issues mod_update_json_url=https://www.minegasm.net/updates.json mod_display_url=https://www.minegasm.net/ diff --git a/docs/_config.yml b/docs/_config.yml index 27d8b64..8181d32 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -10,4 +10,4 @@ callouts: highlight: color: blue plugins: -- jemoji + - jemoji diff --git a/docs/_includes/head_custom.html b/docs/_includes/head_custom.html index 7e1e1ae..7d5ea19 100644 --- a/docs/_includes/head_custom.html +++ b/docs/_includes/head_custom.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/docs/_includes/nav_footer_custom.html b/docs/_includes/nav_footer_custom.html index f116f46..c60fa74 100644 --- a/docs/_includes/nav_footer_custom.html +++ b/docs/_includes/nav_footer_custom.html @@ -1,3 +1,4 @@ \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index e1d4212..22190ac 100644 --- a/docs/config.md +++ b/docs/config.md @@ -6,9 +6,12 @@ nav_order: 3 # Configuration -Since `v0.2`, it is possible to customize the behaviors of the mod to certain extent. It might be done through the mod config screen (when available) or by editing the `minegasm-client.toml` config file manually with a text editor. The file should typically reside in the minecraft's config directory (usually `.minecraft/config`). +Since `v0.2`, it is possible to customize the behaviors of the mod to certain extent. It might be done through the mod +config screen (when available) or by editing the `minegasm-client.toml` config file manually with a text editor. The +file should typically reside in the minecraft's config directory (usually `.minecraft/config`). There are a few tables (collections of key/value pairs) in the config file: + * `buttplug`: to configure the connection to the buttplug server * `minegasm`: to configure the in-game behaviors of the mod @@ -22,12 +25,13 @@ At the moment, there is only one option: ## minegasm -| Config | Key | Description | -|----------|-------------------------------|-----------------------------------------------------------------------| -| Vibrate | `vibrate` | Enable/disable vibration | -| Mode | `mode` | Select gameplay mode: NORMAL, MASOCHIST, HEDONIST, or CUSTOM | +| Config | Key | Description | +|---------|-----------|--------------------------------------------------------------| +| Vibrate | `vibrate` | Enable/disable vibration | +| Mode | `mode` | Select gameplay mode: NORMAL, MASOCHIST, HEDONIST, or CUSTOM | Furthermore, it contains the following table(s): + * intensity ### intensity diff --git a/docs/develop/develop.md b/docs/develop/develop.md index 394686f..9b594a0 100644 --- a/docs/develop/develop.md +++ b/docs/develop/develop.md @@ -6,6 +6,7 @@ has_children: true --- # Development Guide + {: .no_toc } This section is intended for contributors. diff --git a/docs/index.md b/docs/index.md index 1084d75..7bd384d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,10 +4,12 @@ title: Home nav_order: 1 --- -Minegasm is a client-side Minecraft (Java Edition) Forge mod that provides haptic feedback to enhance the gameplay experience. +Minegasm is a client-side Minecraft (Java Edition) Forge mod that provides haptic feedback to enhance the gameplay +experience. {: .warning } -This mod is intended for adults only. By downloading and using this mod, you agree that you are of legal age in your country. +This mod is intended for adults only. By downloading and using this mod, you agree that you are of legal age in your +country. ## Download @@ -22,7 +24,8 @@ This mod is intended for adults only. By downloading and using this mod, you agr | **1.15.2** | [31.2.57](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.15.2.html) | 8 | [minegasm-0.5.0-1.15.2-Forge-31.2.57.jar](https://github.com/RainbowVille/minegasm/releases/download/v0.5.0/minegasm-0.5.0-1.15.2-Forge-31.2.57.jar) | | **1.12.2** | [14.23.5.2859](http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.12.2.html) | 8 | [minegasm-0.5.0-1.12.2-Forge-14.23.5.2859.jar](https://github.com/RainbowVille/minegasm/releases/download/v0.5.0/minegasm-0.5.0-1.12.2-Forge-14.23.5.2859.jar) | -* Discontinued versions: 1.20.1, 1.16.3, 1.14.4, 1.13.2. Old releases that support those versions can be found on the [release page](./releases). +* Discontinued versions: 1.20.1, 1.16.3, 1.14.4, 1.13.2. Old releases that support those versions can be found on + the [release page](./releases). * Deprecated versions (might be removed in future releases): 1.17.1, 1.18.2 * While 1.17.1 can use both Java 16 or 17, we recommend Java 17. @@ -30,29 +33,45 @@ This mod is intended for adults only. By downloading and using this mod, you agr We will be switching to NeoForge from 1.21 onwards. Please stay tuned for updates. ### Dependencies + 1. Intiface Central: [https://intiface.com/central/](https://intiface.com/central/) -2. Minecraft Forge: the versions mentioned on the corresponding Forge column above are the tested versions (newer versions are probably okay) +2. Minecraft Forge: the versions mentioned on the corresponding Forge column above are the tested versions (newer + versions are probably okay) ## How to Use + 1. Make sure you have all the dependencies installed. -2. Download the JAR file and put it in your mods directory. If you don't know where your mods directory is, you can simply open your Minecraft, click the 'Mods' button on the main menu, then click 'Open Mods Folder'. -3. Run the Intiface Central and start the server (`ws://localhost:12345`). For advanced users, it is possible to use an Intiface server on a different endpoint by specifying it in the Minegasm config file. +2. Download the JAR file and put it in your mods directory. If you don't know where your mods directory is, you can + simply open your Minecraft, click the 'Mods' button on the main menu, then click 'Open Mods Folder'. +3. Run the Intiface Central and start the server (`ws://localhost:12345`). For advanced users, it is possible to use an + Intiface server on a different endpoint by specifying it in the Minegasm config file. 4. Turn on the device. -5. Start Minecraft and connect to a world. If everything works properly, you should see a message stating that Minegasm is connected to your device when you enter the world. If the connection fails, go back to Intiface Central and make sure that the Server Status shows that the server is running. To force Minegasm to retry to connect, leave the world and then re-enter. +5. Start Minecraft and connect to a world. If everything works properly, you should see a message stating that Minegasm + is connected to your device when you enter the world. If the connection fails, go back to Intiface Central and make + sure that the Server Status shows that the server is running. To force Minegasm to retry to connect, leave the world + and then re-enter. 6. Have fun! For more detailed instructions, please see the [setup page](./setup). ## Known Issues -* In-game config menu is missing for 1.17, 1.18, 1.19, and 1.20. The mod can still be configured manually by editing the config file. + +* In-game config menu is missing for 1.17, 1.18, 1.19, and 1.20. The mod can still be configured manually by editing the + config file. * The mod has only undergone limited testing in multiplayer mode and it might not work with some mods. -Make sure to check out our [issue tracker](https://github.com/RainbowVille/minegasm/issues?q=is%3Aissue+is%3Aopen+label%3Abug) for all the known issues and their status. The [troubleshooting page](./troubleshoot) provides suggestions of things to do if you encounter any issues. +Make sure to check out +our [issue tracker](https://github.com/RainbowVille/minegasm/issues?q=is%3Aissue+is%3Aopen+label%3Abug) for all the +known issues and their status. The [troubleshooting page](./troubleshoot) provides suggestions of things to do if you +encounter any issues. ## Supported Devices -In theory, this mod should be compatible with any devices on this list: [IoST Index – Vibrators with Buttplug.io Support](https://iostindex.com/?filter0ButtplugSupport=4&filter1Features=OutputsVibrators) + +In theory, this mod should be compatible with any devices on this +list: [IoST Index – Vibrators with Buttplug.io Support](https://iostindex.com/?filter0ButtplugSupport=4&filter1Features=OutputsVibrators) It has been confirmed by the developers to work with: + - [Lovense Edge](https://www.lovense.com/r/qvl9jn) (prostate massager) - [Lovense Hush](https://www.lovense.com/r/zrzb5e) (butt plug) - [Lovense Max 2](https://www.lovense.com/r/n4x2bh) (male masturbator) @@ -62,7 +81,9 @@ It has been confirmed by the developers to work with: Note that at the moment it doesn't work with any other devices that are not vibrators. ## Configuration -Minegasm is configurable through the `Mods > Config` screen, as well as by manually editing the `minegasm-client.toml` config file. + +Minegasm is configurable through the `Mods > Config` screen, as well as by manually editing the `minegasm-client.toml` +config file. The [config page](./config) explains this in further details. ## Gameplay Modes @@ -75,12 +96,20 @@ The [config page](./config) explains this in further details. | CUSTOM | The device will vibrate depending on the intensity levels configured by the user. | ## Support -In principle, we do not provide any dedicated (technical) supports. If you need any assistance, you can use the [discussion page](https://github.com/RainbowVille/minegasm/discussions). -Alternatively, you can join our [Discord server](https://discord.gg/GdgDD5QkNH) and ping `@RSwoop` in the appropriate channel in the **Minegasm Mod** section, but please be advised that he might not always be able to help you. -If you have any suggestions or found any bugs, please post them to our [issue tracker](https://github.com/RainbowVille/minegasm/issues) on GitHub. Please try to be as descriptive as possible and include your `debug.log` (please remove any references to your username first if that matters). The `debug.log` file is typically under the `logs` directory of your minecraft instance. In the vanilla installation on Windows, it is typically on `:\Users\\AppData\Roaming\.minecraft`. +In principle, we do not provide any dedicated (technical) supports. If you need any assistance, you can use +the [discussion page](https://github.com/RainbowVille/minegasm/discussions). +Alternatively, you can join our [Discord server](https://discord.gg/GdgDD5QkNH) and ping `@RSwoop` in the appropriate +channel in the **Minegasm Mod** section, but please be advised that he might not always be able to help you. + +If you have any suggestions or found any bugs, please post them to +our [issue tracker](https://github.com/RainbowVille/minegasm/issues) on GitHub. Please try to be as descriptive as +possible and include your `debug.log` (please remove any references to your username first if that matters). +The `debug.log` file is typically under the `logs` directory of your minecraft instance. In the vanilla installation on +Windows, it is typically on `:\Users\\AppData\Roaming\.minecraft`. ## Related Projects + Some (newer and generally more actively maintained) projects based on or inspired by Minegasm: | Project | Description | @@ -93,9 +122,11 @@ Please check them out and see if they fit your needs better. *Did you create a fork and want to be listed here? Open a pull request!* ## Acknowledgements + Our thanks to the following people, whose assistance have been instrumental in the development of this mod. ### Contributors +
    {% for contributor in site.github.contributors %}
  • @@ -105,5 +136,6 @@ Our thanks to the following people, whose assistance have been instrumental in t
### Credits + - `qdot` for the buttplug library - `Lone_Destroyer` for the original logo diff --git a/docs/release-notes/release-notes.md b/docs/release-notes/release-notes.md index 2677d24..b6c4341 100644 --- a/docs/release-notes/release-notes.md +++ b/docs/release-notes/release-notes.md @@ -6,4 +6,5 @@ has_children: true --- # Release Notes + {: .no_toc } diff --git a/docs/release-notes/v0.1.md b/docs/release-notes/v0.1.md index 04b15d1..c83b99f 100644 --- a/docs/release-notes/v0.1.md +++ b/docs/release-notes/v0.1.md @@ -7,4 +7,5 @@ parent: Release Notes # v0.1 -Initial release with very basic functionalities. The mod will connect to the toy upon starting and issue a vibrate command with a random intensity and duration whenever the player is hurt. +Initial release with very basic functionalities. The mod will connect to the toy upon starting and issue a vibrate +command with a random intensity and duration whenever the player is hurt. diff --git a/docs/release-notes/v0.2.md b/docs/release-notes/v0.2.md index f67b7a7..ff773ca 100644 --- a/docs/release-notes/v0.2.md +++ b/docs/release-notes/v0.2.md @@ -11,6 +11,8 @@ The mod is now configurable. From the mod config menu, you can choose between 3 * NORMAL: the toy will vibrate when you attack other entities, mine, or gain XP. * MASOCHIST: the toy will vibrate when you're hurt or dying. -* HEDONIST: the toy will vibrate on all events defined in other modes, except dying (this is replaced, instead, by having the toy vibrate when you're full and healthy). +* HEDONIST: the toy will vibrate on all events defined in other modes, except dying (this is replaced, instead, by + having the toy vibrate when you're full and healthy). -The fourth CUSTOM mode allows you to set your own preferences by defining the intensity of the vibration on various events. +The fourth CUSTOM mode allows you to set your own preferences by defining the intensity of the vibration on various +events. diff --git a/docs/release-notes/v0.3.md b/docs/release-notes/v0.3.md index c55e5d0..e3cc0f2 100644 --- a/docs/release-notes/v0.3.md +++ b/docs/release-notes/v0.3.md @@ -7,4 +7,5 @@ parent: Release Notes # v0.3 -*Internal only*. Switched the hardware control library to [`buttplug-rs-ffi`](https://github.com/buttplugio/buttplug-rs-ffi). Abandoned in favor of v0.4. +*Internal only*. Switched the hardware control library +to [`buttplug-rs-ffi`](https://github.com/buttplugio/buttplug-rs-ffi). Abandoned in favor of v0.4. diff --git a/docs/release-notes/v0.4.md b/docs/release-notes/v0.4.md index 141cc8d..a5f734e 100644 --- a/docs/release-notes/v0.4.md +++ b/docs/release-notes/v0.4.md @@ -8,10 +8,16 @@ parent: Release Notes # v0.4 * Now covers Minecraft 1.12 to 1.20 -* Migrated hardware control library to [`buttplug4j`](https://github.com/blackspherefollower/buttplug4j) (this supersedes v0.3) +* Migrated hardware control library to [`buttplug4j`](https://github.com/blackspherefollower/buttplug4j) (this + supersedes v0.3) * Java 11 is required for 1.12.2–1.16.5 because of the `buttplug4j` library. ## Known Issues + * The mod for 1.12.2 is reported to be broken. -* There is currently a bug in some versions of the Minecraft launcher that prevents the use of newer Java runtimes: [https://bugs.mojang.com/browse/MCL-18306](https://bugs.mojang.com/browse/MCL-18306). This affects the mods for the Minecraft versions before 1.17 as Minegasm requires at least Java 11. If you encounter this issue, a workaround is to delete `JavaCheck.jar` shipped with the launcher. -* In-game config menu is missing for 1.13.2, 1.17.1, 1.18.2, 1.19.4, and 1.20.1. The mod can still be configured manually by editing the config file. +* There is currently a bug in some versions of the Minecraft launcher that prevents the use of newer Java + runtimes: [https://bugs.mojang.com/browse/MCL-18306](https://bugs.mojang.com/browse/MCL-18306). This affects the mods + for the Minecraft versions before 1.17 as Minegasm requires at least Java 11. If you encounter this issue, a + workaround is to delete `JavaCheck.jar` shipped with the launcher. +* In-game config menu is missing for 1.13.2, 1.17.1, 1.18.2, 1.19.4, and 1.20.1. The mod can still be configured + manually by editing the config file. diff --git a/docs/setup.md b/docs/setup.md index 8e68897..f24b773 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -17,9 +17,13 @@ We assume you have Minecraft (Java Edition) installed. Download the installer from the Forge website (you can find the links on the Forge column in the Download section of this [homepage](./)). Make sure you download the correct version as indicated. -You will get a `jar` file with the name like `forge-1.12.2-14.23.5.2859-installer.jar`. The versions stated between the hyphens should respectively correspond to your Minecraft version and the Forge version supported by the mod. A newer version of the Forge that is compatible with the Minecraft version might work, but have not been tested by the developers. +You will get a `jar` file with the name like `forge-1.12.2-14.23.5.2859-installer.jar`. The versions stated between the +hyphens should respectively correspond to your Minecraft version and the Forge version supported by the mod. A newer +version of the Forge that is compatible with the Minecraft version might work, but have not been tested by the +developers. -Run the installer and choose `Install client` when asked. If you have multiple installations of minecraft, make sure you install it to the right location. +Run the installer and choose `Install client` when asked. If you have multiple installations of minecraft, make sure you +install it to the right location. ### Intiface Central @@ -28,7 +32,9 @@ Download and install the latest version of [Intiface Central](https://intiface.c ## Copying the mod 1. Download the `jar` file of the Minegasm mod. -2. Open your minecraft's `mods` directory and put the downloaded file there. Make sure to remove any older versions of Minegasm mod if you have installed them before. If you don't know where your mods directory is, you can simply open your Minecraft, click the `Mods` button on the main menu, then click `Open Mods Folder`. +2. Open your minecraft's `mods` directory and put the downloaded file there. Make sure to remove any older versions of + Minegasm mod if you have installed them before. If you don't know where your mods directory is, you can simply open + your Minecraft, click the `Mods` button on the main menu, then click `Open Mods Folder`. ## Start the buttplug server @@ -37,7 +43,9 @@ Download and install the latest version of [Intiface Central](https://intiface.c ## Play time! -1. Make sure your device is turned on and not currently connected to anything else (Intiface Central should indicate `Engine running, waiting for client`). +1. Make sure your device is turned on and not currently connected to anything else (Intiface Central should + indicate `Engine running, waiting for client`). 2. Start Minecraft Forge, make sure the mod is loaded. -3. When you enter the world, a message indicating that the mod is connected to your device should appear. If not, try again or check our [troubleshooting page](./troubleshoot) for some suggestions. +3. When you enter the world, a message indicating that the mod is connected to your device should appear. If not, try + again or check our [troubleshooting page](./troubleshoot) for some suggestions. 4. Enjoy! \ No newline at end of file diff --git a/docs/troubleshoot.md b/docs/troubleshoot.md index 0c0446f..dc1ae8a 100644 --- a/docs/troubleshoot.md +++ b/docs/troubleshoot.md @@ -6,6 +6,10 @@ nav_order: 4 # Troubleshooting -As with a lot of computer issues, the very first thing you should try is to restart everything. While not strictly necessary, we recommend that you start your device and the Intiface server before Minecraft. This should solve most intermittent issues. +As with a lot of computer issues, the very first thing you should try is to restart everything. While not strictly +necessary, we recommend that you start your device and the Intiface server before Minecraft. This should solve most +intermittent issues. -If you run this mod alongside other mods, try disabling them all first and then reenable them one by one when the mods run successfully. If you found any mods that are incompatible with this mod, please file an issue on our [issue tracker](https://github.com/RainbowVille/minegasm/issues). +If you run this mod alongside other mods, try disabling them all first and then reenable them one by one when the mods +run successfully. If you found any mods that are incompatible with this mod, please file an issue on +our [issue tracker](https://github.com/RainbowVille/minegasm/issues). diff --git a/docs/updates.json b/docs/updates.json index cf460ea..44b71f3 100644 --- a/docs/updates.json +++ b/docs/updates.json @@ -1,84 +1,84 @@ { - "homepage": "https://www.minegasm.net", - "promos": { - "1.20.4-latest": "0.5.0", - "1.20.4-recommended": "0.5.0", - "1.20.1-latest": "0.4.0", - "1.20.1-recommended": "0.4.0", - "1.19.4-latest": "0.5.0", - "1.19.4-recommended": "0.5.0", - "1.19.2-latest": "0.5.0", - "1.19.2-recommended": "0.5.0", - "1.18.2-latest": "0.5.0", - "1.18.2-recommended": "0.5.0", - "1.17.1-latest": "0.5.0", - "1.17.1-recommended": "0.5.0", - "1.16.5-latest": "0.5.0", - "1.16.5-recommended": "0.5.0", - "1.16.3-latest": "0.4.2", - "1.16.3-recommended": "0.4.2", - "1.15.2-latest": "0.5.0", - "1.15.2-recommended": "0.5.0", - "1.14.4-latest": "0.4.2", - "1.14.4-recommended": "0.4.2", - "1.13.2-latest": "0.4.2", - "1.13.2-recommended": "0.4.2", - "1.12.2-latest": "0.5.0", - "1.12.2-recommended": "0.5.0" - }, - "1.20.4": { - "0.5.0": "multiplayer support", - "0.4.2": "update to 1.20.4" - }, - "1.20.1": { - "0.4.0": "add support for 1.20" - }, - "1.19.4": { - "0.5.0": "multiplayer support", - "0.4.2": "update forge to 45.2.0", - "0.4.0": "add support for 1.19" - }, - "1.19.2": { - "0.5.0": "multiplayer support", - "0.4.2": "add support for 1.19.2" - }, - "1.18.2": { - "0.5.0": "multiplayer support", - "0.4.0": "add support for 1.18" - }, - "1.17.1": { - "0.5.0": "multiplayer support", - "0.4.0": "add support for 1.17" - }, - "1.16.5": { - "0.5.0": "multiplayer support", - "0.4.2": "fix crashes", - "0.4.0": "update dependencies", - "0.2.1": "fix crashes when harvesting", - "0.2.0": "update to 1.16.5, add new gameplay modes, now configurable" - }, - "1.16.3": { - "0.4.2": "re-add support for 1.16.3", - "0.1.1": "bug fixes and performance improvements", - "0.1.0": "initial MVP version" - }, - "1.15.2": { - "0.5.0": "multiplayer support", - "0.4.2": "fix crashes", - "0.4.0": "add support for 1.15" - }, - "1.14.4": { - "0.4.2": "fix crashes", - "0.4.0": "add support for 1.14" - }, - "1.13.2": { - "0.4.2": "fix crashes", - "0.4.0": "add support for 1.13" - }, - "1.12.2": { - "0.5.0": "multiplayer support", - "0.4.2": "fix crashes", - "0.4.0": "update dependencies", - "0.2.2": "add support for 1.12.2" - } + "homepage": "https://www.minegasm.net", + "promos": { + "1.20.4-latest": "0.5.0", + "1.20.4-recommended": "0.5.0", + "1.20.1-latest": "0.4.0", + "1.20.1-recommended": "0.4.0", + "1.19.4-latest": "0.5.0", + "1.19.4-recommended": "0.5.0", + "1.19.2-latest": "0.5.0", + "1.19.2-recommended": "0.5.0", + "1.18.2-latest": "0.5.0", + "1.18.2-recommended": "0.5.0", + "1.17.1-latest": "0.5.0", + "1.17.1-recommended": "0.5.0", + "1.16.5-latest": "0.5.0", + "1.16.5-recommended": "0.5.0", + "1.16.3-latest": "0.4.2", + "1.16.3-recommended": "0.4.2", + "1.15.2-latest": "0.5.0", + "1.15.2-recommended": "0.5.0", + "1.14.4-latest": "0.4.2", + "1.14.4-recommended": "0.4.2", + "1.13.2-latest": "0.4.2", + "1.13.2-recommended": "0.4.2", + "1.12.2-latest": "0.5.0", + "1.12.2-recommended": "0.5.0" + }, + "1.20.4": { + "0.5.0": "multiplayer support", + "0.4.2": "update to 1.20.4" + }, + "1.20.1": { + "0.4.0": "add support for 1.20" + }, + "1.19.4": { + "0.5.0": "multiplayer support", + "0.4.2": "update forge to 45.2.0", + "0.4.0": "add support for 1.19" + }, + "1.19.2": { + "0.5.0": "multiplayer support", + "0.4.2": "add support for 1.19.2" + }, + "1.18.2": { + "0.5.0": "multiplayer support", + "0.4.0": "add support for 1.18" + }, + "1.17.1": { + "0.5.0": "multiplayer support", + "0.4.0": "add support for 1.17" + }, + "1.16.5": { + "0.5.0": "multiplayer support", + "0.4.2": "fix crashes", + "0.4.0": "update dependencies", + "0.2.1": "fix crashes when harvesting", + "0.2.0": "update to 1.16.5, add new gameplay modes, now configurable" + }, + "1.16.3": { + "0.4.2": "re-add support for 1.16.3", + "0.1.1": "bug fixes and performance improvements", + "0.1.0": "initial MVP version" + }, + "1.15.2": { + "0.5.0": "multiplayer support", + "0.4.2": "fix crashes", + "0.4.0": "add support for 1.15" + }, + "1.14.4": { + "0.4.2": "fix crashes", + "0.4.0": "add support for 1.14" + }, + "1.13.2": { + "0.4.2": "fix crashes", + "0.4.0": "add support for 1.13" + }, + "1.12.2": { + "0.5.0": "multiplayer support", + "0.4.2": "fix crashes", + "0.4.0": "update dependencies", + "0.2.2": "add support for 1.12.2" + } } diff --git a/forge/fg-2.1/1.8.9/build.gradle b/forge/fg-2.1/1.8.9/build.gradle index bdae8fc..6081796 100644 --- a/forge/fg-2.1/1.8.9/build.gradle +++ b/forge/fg-2.1/1.8.9/build.gradle @@ -64,7 +64,7 @@ processResources { include "mcmod.info" //replace version and mcversion - expand "version":project.version, "mcversion":project.minecraft.version + expand "version": project.version, "mcversion": project.minecraft.version } //copy everything else, that"s not the mcmod.info diff --git a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/Minegasm.java b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/Minegasm.java index 3ce8080..9ac0148 100644 --- a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/Minegasm.java +++ b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/Minegasm.java @@ -12,29 +12,23 @@ public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; public static final String MODVERSION = "0.2.2"; - - @SidedProxy(clientSide = "com.therainbowville.minegasm.client.ClientProxy") - private static CommonProxy proxy; - - @Mod.Instance public static Minegasm instance; + @SidedProxy(clientSide = "com.therainbowville.minegasm.client.ClientProxy") + private static CommonProxy proxy; @Mod.EventHandler - public void preInit(FMLPreInitializationEvent event) - { + public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); } @Mod.EventHandler - public void init(FMLInitializationEvent event) - { + public void init(FMLInitializationEvent event) { proxy.init(event); } @Mod.EventHandler - public void postInit(FMLPostInitializationEvent event) - { + public void postInit(FMLPostInitializationEvent event) { proxy.postInit(event); } } diff --git a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index 4dd5d7e..c27ff0e 100644 --- a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,7 +1,6 @@ package com.therainbowville.minegasm.client; import com.mojang.authlib.GameProfile; -import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -9,7 +8,6 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,13 +20,13 @@ public final class ClientEventHandler { private static final Logger LOGGER = LogManager.getLogger(); - private static String playerName = null; - private static UUID playerID = null; private static final int TICKS_PER_SECOND = 20; private static final int DAY_CYCLE = 20 * 60; // 20 minutes + private static final double[] state = new double[DAY_CYCLE]; + private static String playerName = null; + private static UUID playerID = null; private static int tickCounter = -1; private static int clientTickCounter = -1; - private static final double[] state = new double[DAY_CYCLE]; private static boolean paused = false; private static boolean motdDisplayed = false; @@ -138,7 +136,7 @@ public void onWorldEntry(EntityJoinWorldEvent event) { //player.sendStatusMessage(new TextComponentString(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); } else { LOGGER.debug("Failed to connect"); - // player.sendStatusMessage(new TextComponentString(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + // player.sendStatusMessage(new TextComponentString(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } } else { clearState(); diff --git a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java index 13c112e..55be65e 100644 --- a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java +++ b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java @@ -2,12 +2,9 @@ import com.therainbowville.minegasm.common.CommonProxy; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.relauncher.Side; import org.apache.logging.log4j.Logger; public class ClientProxy extends CommonProxy { @@ -16,6 +13,7 @@ public class ClientProxy extends CommonProxy { public void preInit(FMLPreInitializationEvent event) { super.preInit(event); } + public void init(FMLInitializationEvent event) { super.init(event); MinecraftForge.EVENT_BUS.register(new ClientEventHandler()); diff --git a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 804f14a..a1e2984 100644 --- a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -2,21 +2,18 @@ //import io.github.blackspherefollower.buttplug4j.client.ButtplugClientDevice; //import io.github.blackspherefollower.buttplug4j.connectors.jetty.websocket.client.ButtplugClientWSClient; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.net.URI; -import java.util.List; -import java.util.Objects; - public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - //private static final ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - //private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + //private static final ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + //private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { /*try { diff --git a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java index 5282ba6..4fb7fe4 100644 --- a/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java +++ b/forge/fg-2.1/1.8.9/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java @@ -11,7 +11,6 @@ public void preInit(FMLPreInitializationEvent event) { public void init(FMLInitializationEvent event) { } - public void postInit(FMLPostInitializationEvent event) - { + public void postInit(FMLPostInitializationEvent event) { } } diff --git a/forge/fg-2.1/1.8.9/src/main/resources/META-INF/mods.toml b/forge/fg-2.1/1.8.9/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-2.1/1.8.9/src/main/resources/META-INF/mods.toml +++ b/forge/fg-2.1/1.8.9/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-2.1/1.8.9/src/main/resources/mcmod.info b/forge/fg-2.1/1.8.9/src/main/resources/mcmod.info index aa8963e..6bbf27c 100644 --- a/forge/fg-2.1/1.8.9/src/main/resources/mcmod.info +++ b/forge/fg-2.1/1.8.9/src/main/resources/mcmod.info @@ -1,16 +1,18 @@ [ -{ - "modid": "minegasm", - "name": "Minegasm", - "description": "Just a simple mod to bring some gasm into Minecraft. ;)", - "version": "0.5.0", - "mcversion": "${mcversion}", - "url": "https://minegasm.therainbowville.com/", - "updateUrl": "https://minegasm.therainbowville.com/updates.json", - "authorList": ["RSwoop"], - "credits": "", - "logoFile": "minegasm.png", - "screenshots": [], - "dependencies": [] -} + { + "modid": "minegasm", + "name": "Minegasm", + "description": "Just a simple mod to bring some gasm into Minecraft. ;)", + "version": "0.5.0", + "mcversion": "${mcversion}", + "url": "https://minegasm.therainbowville.com/", + "updateUrl": "https://minegasm.therainbowville.com/updates.json", + "authorList": [ + "RSwoop" + ], + "credits": "", + "logoFile": "minegasm.png", + "screenshots": [], + "dependencies": [] + } ] diff --git a/forge/fg-2.1/1.8.9/src/main/resources/pack.mcmeta b/forge/fg-2.1/1.8.9/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-2.1/1.8.9/src/main/resources/pack.mcmeta +++ b/forge/fg-2.1/1.8.9/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-2.1/gradle.properties b/forge/fg-2.1/gradle.properties index 2bb926a..8251b6b 100644 --- a/forge/fg-2.1/gradle.properties +++ b/forge/fg-2.1/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.8.9 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.12.2/build.gradle b/forge/fg-6.0/1.12.2/build.gradle index d51cb82..c77aba9 100644 --- a/forge/fg-6.0/1.12.2/build.gradle +++ b/forge/fg-6.0/1.12.2/build.gradle @@ -6,10 +6,10 @@ plugins { id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '8.1.1' - id 'org.spongepowered.mixin' version '0.7.+' + id 'org.spongepowered.mixin' version '0.7.+' } -apply plugin: 'org.spongepowered.mixin' +apply plugin: 'org.spongepowered.mixin' version = mod_version group = mod_group_id @@ -125,16 +125,16 @@ repositories { // flatDir { // dir 'libs' // } - + maven { url = 'https://repo.spongepowered.org/maven' - + } } configurations { shade - implementation.extendsFrom shade + implementation.extendsFrom shade } dependencies { @@ -144,8 +144,8 @@ dependencies { // If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"], // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - shade 'org.spongepowered:mixin:0.8.5' - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' + shade 'org.spongepowered:mixin:0.8.5' + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' shade 'io.github.blackspherefollower:buttplug4j.connectors.jetty.websocket.client:3.1.105' // Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings @@ -170,13 +170,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -189,24 +189,24 @@ mixin { // MixinGradle Settings add sourceSets.main, "mixins.${mod_id}.refmap.json" config "mixins.${mod_id}.json" -} - +} + // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { archiveClassifier = 'slim' manifest { attributes([ - 'Specification-Title' : mod_id, - 'Specification-Vendor' : mod_authors, - 'Specification-Version' : '1', // We are version 1 of ourselves - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.jar.archiveVersion, - 'Implementation-Vendor' : mod_authors, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Specification-Title' : mod_id, + 'Specification-Vendor' : mod_authors, + 'Specification-Version' : '1', // We are version 1 of ourselves + 'Implementation-Title' : project.name, + 'Implementation-Version' : project.jar.archiveVersion, + 'Implementation-Vendor' : mod_authors, + 'Implementation-Timestamp' : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "FMLCorePluginContainsFMLMod": "true", - "ForceLoadAsMod": "true", //Seems to do the opposite of what it claims to do while in dev enviroment, uncomment for build - "TweakClass": "org.spongepowered.asm.launch.MixinTweaker", - 'TweakOrder': '0' + "ForceLoadAsMod" : "true", //Seems to do the opposite of what it claims to do while in dev enviroment, uncomment for build + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + 'TweakOrder' : '0' ]) } @@ -219,7 +219,7 @@ tasks.named('shadowJar', ShadowJar) { // relocationPrefix "com.therainbowville.repack" relocate "com.fasterxml", "com.therainbowville.repack.com.fasterxml" - relocate ("org.eclipse", "com.therainbowville.repack.org.eclipse") { + relocate("org.eclipse", "com.therainbowville.repack.org.eclipse") { exclude "org/eclipse/jetty/version/**" } relocate "io", "com.therainbowville.repack.io" @@ -240,4 +240,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/gradle.properties b/forge/fg-6.0/1.12.2/gradle.properties index f9cf343..a47d882 100644 --- a/forge/fg-6.0/1.12.2/gradle.properties +++ b/forge/fg-6.0/1.12.2/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.12.2 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index a51fdfc..901c295 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,33 +1,26 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; - import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID) public class ClientEventHandler { @@ -37,7 +30,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -47,56 +40,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) { - EntityPlayer player = (EntityPlayer) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) { + EntityPlayer player = (EntityPlayer) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -110,26 +97,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - EntityPlayer player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency.getInt() == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + EntityPlayer player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency.getInt() == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -158,88 +145,72 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getEntityPlayer())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getEntityPlayer())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } - } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + } + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpChange(PlayerPickupXpEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((EntityPlayer)event.getEntityLiving()).experienceTotal, event.getOrb().xpValue); + public static void onXpChange(PlayerPickupXpEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((EntityPlayer) event.getEntityLiving()).experienceTotal, event.getOrb().xpValue); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerRespawnEvent event) - { + public static void onRespawn(PlayerRespawnEvent event) { Entity entity = event.player; if (entity instanceof EntityPlayer) { LOGGER.info("Client Entered world: " + entity.toString()); @@ -265,32 +236,34 @@ public static void onRespawn(PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); - + if (ToyController.isConnected) return; if (entity instanceof EntityPlayer) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - EntityPlayer player = (EntityPlayer) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getMinecraft().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.sendStatusMessage(new TextComponentString(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + EntityPlayer player = (EntityPlayer) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getMinecraft().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.sendStatusMessage(new TextComponentString(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.sendStatusMessage(new TextComponentString(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.sendStatusMessage(new TextComponentString(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java index fc3ef5a..fddf65d 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ClientProxy.java @@ -12,15 +12,15 @@ public class ClientProxy extends CommonProxy { public static Logger logger; + @SubscribeEvent + public static void registerModels(ModelRegistryEvent event) { + logger.info("Client RegisterModels..."); + } + @Override public void preInit(FMLPreInitializationEvent event) { logger = event.getModLog(); super.preInit(event); logger.info("Client PreInit..."); } - - @SubscribeEvent - public static void registerModels(ModelRegistryEvent event) { - logger.info("Client RegisterModels..."); - } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java index d973eea..5a5998a 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index f142133..1c89f13 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,61 +1,32 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(MinegasmConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -89,7 +60,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,18 +85,49 @@ public static int getIntensity(String type) { int returnValue = -1; - - switch (MinegasmConfig.mode) - { - case NORMAL: returnValue = normal.get(type); break; - case MASOCHIST: returnValue = masochist.get(type); break; - case HEDONIST: returnValue = hedonist.get(type); break; - case ACCUMULATION: returnValue = accumulation.get(type); break; - case CUSTOM: returnValue = custom.get(type); break; - }; - + + switch (MinegasmConfig.mode) { + case NORMAL: + returnValue = normal.get(type); + break; + case MASOCHIST: + returnValue = masochist.get(type); + break; + case HEDONIST: + returnValue = hedonist.get(type); + break; + case ACCUMULATION: + returnValue = accumulation.get(type); + break; + case CUSTOM: + returnValue = custom.get(type); + break; + } + ; + return returnValue; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java index 7f40f8b..ecb6f22 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/CommonProxy.java @@ -14,6 +14,16 @@ public class CommonProxy { public static Logger logger; + @SubscribeEvent + public static void registerBlocks(RegistryEvent.Register event) { + logger.info("Common RegisterBlocks..."); + } + + @SubscribeEvent + public static void registerItems(RegistryEvent.Register event) { + logger.info("Common RegisterItems..."); + } + public void preInit(FMLPreInitializationEvent event) { logger = event.getModLog(); logger.info("Common PreInit..."); @@ -26,14 +36,4 @@ public void init(FMLInitializationEvent event) { public void postInit(FMLPostInitializationEvent event) { logger.info("Common PostInit..."); } - - @SubscribeEvent - public static void registerBlocks(RegistryEvent.Register event) { - logger.info("Common RegisterBlocks..."); - } - - @SubscribeEvent - public static void registerItems(RegistryEvent.Register event) { - logger.info("Common RegisterItems..."); - } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 09d478d..4b571b1 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,49 +1,45 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEvent event) - { + + public void onAdvancement(AdvancementEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - if (advancement == null) return; - FrameType type = advancement.getDisplay().getFrame(); - int duration = 0; - - switch (type) { - case TASK: - duration = 5; - break; - case GOAL: - duration = 7; - break; - case CHALLENGE: - duration = 10; - break; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + if (advancement == null) return; + FrameType type = advancement.getDisplay().getFrame(); + int duration = 0; + + switch (type) { + case TASK: + duration = 5; + break; + case GOAL: + duration = 7; + break; + case CHALLENGE: + duration = 10; + break; + } + ; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index 8249fa1..c3abf22 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,40 +1,30 @@ package com.therainbowville.minegasm.common; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityFishHook; -import net.minecraft.util.math.Vec3d; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.entity.player.EntityPlayer; -public class VibrationStateFish extends AbstractVibrationState -{ +public class VibrationStateFish extends AbstractVibrationState { - public VibrationStateFish() - { + public VibrationStateFish() { super(0); } - - public void onTick(EntityPlayer player) - { + + public void onTick(EntityPlayer player) { if (player == null) return; - - if (player.fishEntity != null) - { + + if (player.fishEntity != null) { double x = player.fishEntity.motionX; double y = player.fishEntity.motionY; double z = player.fishEntity.motionZ; - if (y < -0.075 && player.fishEntity.isInWater() && x == 0 && z == 0) - { + if (y < -0.075 && player.fishEntity.isInWater() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index a7254ab..a4ed4a5 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,30 +1,24 @@ package com.therainbowville.minegasm.common; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index e037ab8..5ec52c6 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.block.state.IBlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.block.state.IBlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(IBlockState block) { + + public void onBreak(IBlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getUnlocalizedName(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(IBlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 8791a9d..f38a9de 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,30 +1,26 @@ package com.therainbowville.minegasm.common; -import net.minecraft.entity.player.EntityPlayer; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.entity.player.EntityPlayer; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(EntityPlayer player) - { + + public void onTick(EntityPlayer player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodStats().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(MinegasmConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(MinegasmConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(MinegasmConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(MinegasmConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -44,13 +40,12 @@ public void onTick(EntityPlayer player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index de004f7..610b34d 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,42 +1,32 @@ package com.therainbowville.minegasm.config; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; +import com.therainbowville.minegasm.common.Minegasm; +import com.therainbowville.minegasm.widgets.GuiButtonExtraExt; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiPageButtonList; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; -import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextComponentString; -import net.minecraft.client.gui.GuiPageButtonList; - -import net.minecraftforge.fml.client.config.GuiButtonExt; - -import net.minecraftforge.fml.client.config.GuiSlider; +import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.config.Config; import net.minecraftforge.common.config.ConfigManager; +import net.minecraftforge.fml.client.config.GuiSlider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.MinegasmConfig; -import com.therainbowville.minegasm.widgets.GuiButtonExtraExt; - - +import java.io.IOException; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.Objects; -import java.io.IOException; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends GuiScreen { private static final Logger LOGGER = LogManager.getLogger(); private final GuiScreen previous; - private boolean pauseMenu; - GuiTextField wsHost = null; - public MinegasmConfig.TickFrequencyOptions tickValue; + GuiTextField wsHost = null; + private boolean pauseMenu; private PlainTextLabel connectResponse; public ConfigScreen(GuiScreen previous) { @@ -47,7 +37,7 @@ public ConfigScreen(GuiScreen previous) { pauseMenu = false; tickValue = MinegasmConfig.tickFrequency; } - + public ConfigScreen(GuiScreen previous, boolean pause) { super(); //new TextComponentString("Minegasm Config") @@ -64,45 +54,44 @@ public void initGui() { // this.children.add(wsHost); class Responder implements GuiPageButtonList.GuiResponder { - public void setEntryValue(int id, int value) - { + public void setEntryValue(int id, int value) { LOGGER.info(value); } - public void setEntryValue(int id, boolean value) - { + + public void setEntryValue(int id, boolean value) { LOGGER.info(value); } - public void setEntryValue(int id, float value) - { + + public void setEntryValue(int id, float value) { LOGGER.info(value); } - public void setEntryValue(int id, String value) - { + + public void setEntryValue(int id, String value) { LOGGER.info(value); MinegasmConfig.serverUrl.serverUrl = value; } } - + wsHost.setGuiResponder(new Responder()); - + this.addButton(new GuiButtonExtraExt( - this.width / 2 - 155, this.height / 6 + 25, 150, 20, - "Reset Server Url", button -> { - MinegasmConfig.resetConfigUrl(); - wsHost.setText(MinegasmConfig.serverUrl.serverUrl); - } + this.width / 2 - 155, this.height / 6 + 25, 150, 20, + "Reset Server Url", button -> { + MinegasmConfig.resetConfigUrl(); + wsHost.setText(MinegasmConfig.serverUrl.serverUrl); + } )); - + connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, ("" + TextFormatting.GREEN)); this.addButton(connectResponse); - + GuiButtonExtraExt reconnectButton = new GuiButtonExtraExt( - this.width / 2 + 5, this.height / 6 + 25, 150, 20, - "Reconnect", button -> { - button.enabled = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + this.width / 2 + 5, this.height / 6 + 25, 150, 20, + "Reconnect", button -> { + button.enabled = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.enabled = true; @@ -111,74 +100,86 @@ public void setEntryValue(int id, String value) button.enabled = true; connectResponse.setValue(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - } + + }).start(); + } ); this.addButton(reconnectButton); - + reconnectButton.enabled = pauseMenu; - + this.addButton(new GuiButtonExtraExt(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - ("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { - MinegasmConfig.vibrate = !MinegasmConfig.vibrate; - button.setMessage(("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); - })); + ("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { + MinegasmConfig.vibrate = !MinegasmConfig.vibrate; + button.setMessage(("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); + })); this.addButton(new GuiButtonExtraExt(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - ("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { - MinegasmConfig.stealth = !MinegasmConfig.stealth; - button.setMessage(("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); - })); + ("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { + MinegasmConfig.stealth = !MinegasmConfig.stealth; + button.setMessage(("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); + })); this.addButton(new GuiButtonExtraExt(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - ("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { - MinegasmConfig.mode = MinegasmConfig.mode.next(); - button.setMessage(("Mode: " + gameplayModeToString(MinegasmConfig.mode))); - } + ("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { + MinegasmConfig.mode = MinegasmConfig.mode.next(); + button.setMessage(("Mode: " + gameplayModeToString(MinegasmConfig.mode))); + } )); this.addButton(new GuiButtonExtraExt( - this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, - ("Edit Custom Settings"), button -> this.mc.displayGuiScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, + ("Edit Custom Settings"), button -> this.mc.displayGuiScreen(new CustomModeConfigScreen(this, pauseMenu)))); this.addButton(new GuiButtonExtraExt(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - "Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency.getInt()), (button) -> { - tickValue = tickValue.next(); - MinegasmConfig.tickFrequency = tickValue; - MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency.getInt())); - button.setMessage(("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency.getInt()))); - } + "Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency.getInt()), (button) -> { + tickValue = tickValue.next(); + MinegasmConfig.tickFrequency = tickValue; + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency.getInt())); + button.setMessage(("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency.getInt()))); + } )); this.addButton(new GuiButtonExtraExt( - this.width / 2 - 100, this.height - 27, 200, 20, - ("Done"), button -> this.close())); + this.width / 2 - 100, this.height - 27, 200, 20, + ("Done"), button -> this.close())); } - - private String gameplayModeToString(MinegasmConfig.GameplayMode mode){ + + private String gameplayModeToString(MinegasmConfig.GameplayMode mode) { switch (mode) { - case NORMAL: return "Normal"; - case MASOCHIST: return "Masochist"; - case HEDONIST: return "Hedonist"; - case ACCUMULATION: return "Accumulation"; - case CUSTOM: return "Custom"; - default: return ""; + case NORMAL: + return "Normal"; + case MASOCHIST: + return "Masochist"; + case HEDONIST: + return "Hedonist"; + case ACCUMULATION: + return "Accumulation"; + case CUSTOM: + return "Custom"; + default: + return ""; } } - private String tickFrequencyToString(Integer frequency){ + private String tickFrequencyToString(Integer frequency) { switch (frequency) { - case 1: return "Every Tick"; - case 2: return "Every Other Tick"; - case 5: return "Every 5 Ticks"; - case 10: return "Every 10 Ticks"; - case 20: return "Every Second"; - default: return "Every " + Float.toString(frequency / 20f)+ " Seconds"; + case 1: + return "Every Tick"; + case 2: + return "Every Other Tick"; + case 5: + return "Every 5 Ticks"; + case 10: + return "Every 10 Ticks"; + case 20: + return "Every Second"; + default: + return "Every " + Float.toString(frequency / 20f) + " Seconds"; } } - + @Override public void updateScreen() { super.updateScreen(); @@ -204,23 +205,21 @@ public void drawScreen(int i, int j, float f) { this.wsHost.drawTextBox(); super.drawScreen(i, j, f); } - + @Override - public void keyTyped(char i, int j) throws IOException - { + public void keyTyped(char i, int j) throws IOException { this.wsHost.textboxKeyTyped(i, j); super.keyTyped(i, j); } @Override - public void mouseClicked(int x, int y, int btn) throws IOException - { + public void mouseClicked(int x, int y, int btn) throws IOException { this.wsHost.mouseClicked(x, y, btn); super.mouseClicked(x, y, btn); } - + class PlainTextLabel extends GuiButton { - + private TextComponentString text = new TextComponentString(""); private int x; private int y; @@ -231,8 +230,7 @@ public PlainTextLabel(int x, int y, int width, int height, String text) { this.y = y; } - public void setValue(String value) - { + public void setValue(String value) { text = new TextComponentString(value); } @@ -244,7 +242,7 @@ public void drawButton(Minecraft mc, int i, int j, float f) { drawCenteredString(Minecraft.getMinecraft().fontRenderer, text.getText(), Minecraft.getMinecraft().currentScreen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends GuiScreen { @@ -258,7 +256,7 @@ public CustomModeConfigScreen(GuiScreen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(GuiScreen previous, boolean pause) { super(); //new TextComponentString("Minegasm Custom Config") @@ -268,50 +266,50 @@ public CustomModeConfigScreen(GuiScreen previous, boolean pause) { @Override public void initGui() { - try{ - this.addButton(new GuiButtonExtraExt( - this.width / 2 + 5, this.height - 27, 150, 20, - ("Done"), button -> this.close())); + try { + this.addButton(new GuiButtonExtraExt( + this.width / 2 + 5, this.height - 27, 150, 20, + ("Done"), button -> this.close())); - IntensitiySliderBar.sliders.clear(); + IntensitiySliderBar.sliders.clear(); - // Attack - this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.IntensityConfig.class.getField("attackIntensity"))); - - // Hurt - this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.IntensityConfig.class.getField("hurtIntensity"))); - - // Mine - this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.IntensityConfig.class.getField("mineIntensity"))); - - // Place - this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.IntensityConfig.class.getField("placeIntensity"))); - - // XP Change - this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.IntensityConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.IntensityConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.IntensityConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.IntensityConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.IntensityConfig.class.getField("advancementIntensity"))); - - this.addButton(new GuiButtonExtraExt( - this.width / 2 - 155, this.height - 27, 150, 20, - ("Reset Values"), button -> { + // Attack + this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.IntensityConfig.class.getField("attackIntensity"))); + + // Hurt + this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.IntensityConfig.class.getField("hurtIntensity"))); + + // Mine + this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.IntensityConfig.class.getField("mineIntensity"))); + + // Place + this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.IntensityConfig.class.getField("placeIntensity"))); + + // XP Change + this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.IntensityConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.IntensityConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.IntensityConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.IntensityConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.IntensityConfig.class.getField("advancementIntensity"))); + + this.addButton(new GuiButtonExtraExt( + this.width / 2 - 155, this.height - 27, 150, 20, + ("Reset Values"), button -> { MinegasmConfig.resetConfigCustom(); LOGGER.info("Resetting"); IntensitiySliderBar.refreshAllValues(); } - )); - - + )); + + } catch (Throwable e) { LOGGER.throwing(e); } @@ -333,24 +331,22 @@ public void drawScreen(int i, int j, float f) { } } -class IntensitiySliderBar extends GuiSlider -{ +class IntensitiySliderBar extends GuiSlider { private static final Logger LOGGER = LogManager.getLogger(); public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { super(1, parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - prefix, // Prefix - "", // Suffix - 0, 100, field.getInt(MinegasmConfig.intensity), false, true); // Min, Max, Default value, percision, drawstring + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + prefix, // Prefix + "", // Suffix + 0, 100, field.getInt(MinegasmConfig.intensity), false, true); // Min, Max, Default value, percision, drawstring fieldReference = field; sliders.add(this); - - this.parent = (slider) -> { + + this.parent = (slider) -> { try { fieldReference.set(MinegasmConfig.intensity, slider.getValueInt()); } catch (Throwable e) { @@ -359,16 +355,13 @@ class IntensitiySliderBar extends GuiSlider }; } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { slider.refreshValue(); } } - private void refreshValue() - { + private void refreshValue() { try { LOGGER.info(fieldReference.getInt(MinegasmConfig.intensity)); this.setValue(fieldReference.getInt(MinegasmConfig.intensity)); diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index e7f8faa..64b94d0 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -2,12 +2,12 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.config.Config; -import net.minecraftforge.common.config.Config.*; +import net.minecraftforge.common.config.Config.Comment; +import net.minecraftforge.common.config.Config.Ignore; import net.minecraftforge.common.config.ConfigManager; import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,13 +15,10 @@ @Config(modid = Minegasm.MOD_ID) public class MinegasmConfig { - private static final Logger LOGGER = LogManager.getLogger(); - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; static final boolean DEFAULT_VIBRATE = true; static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; static final boolean DEFAULT_STEALTH = false; - static final int DEFAULT_ATTACK_INTENSITY = 60; static final int DEFAULT_HURT_INTENSITY = 0; static final int DEFAULT_MINE_INTENSITY = 80; @@ -31,92 +28,28 @@ public class MinegasmConfig { static final int DEFAULT_HARVEST_INTENSITY = 0; static final int DEFAULT_VITALITY_INTENSITY = 0; static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + private static final Logger LOGGER = LogManager.getLogger(); public static ServerUrlConfig serverUrl = new ServerUrlConfig(); - - public static class ServerUrlConfig { - @Comment("The URL of the Intiface/Buttplug server") - public String serverUrl; - - public ServerUrlConfig() { - this.serverUrl = DEFAULT_SERVER_URL; - } - } - @Comment("Enable vibration") public static boolean vibrate = true; - @Comment("Game mode") public static GameplayMode mode = GameplayMode.NORMAL; - public static boolean stealth = false; - public static TickFrequencyOptions tickFrequency = TickFrequencyOptions.EVERY_TICK; - @Ignore public static int ticksPerSecond = Math.max(1, Math.toIntExact(20 / tickFrequency.getInt())); + @Comment("Intensity configurations for the CUSTOM game mode") + public static IntensityConfig intensity = new IntensityConfig(); public static void updateTicksPerSecond() { ticksPerSecond = Math.max(1, Math.toIntExact(20 / tickFrequency.getInt())); } - - @Comment("Intensity configurations for the CUSTOM game mode") - public static IntensityConfig intensity = new IntensityConfig(); - - public static class IntensityConfig { - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int attackIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int hurtIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int mineIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int placeIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int xpChangeIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int fishingIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int harvestIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int vitalityIntensity; - @Config.RangeInt(min = 0, max = 100) - @Config.SlidingOption - public int advancementIntensity; - - public IntensityConfig(){ - resetConfigValues(); - } - - public void resetConfigValues() - { - this.attackIntensity = DEFAULT_ATTACK_INTENSITY; - this.hurtIntensity = DEFAULT_HURT_INTENSITY; - this.mineIntensity = DEFAULT_MINE_INTENSITY; - this.placeIntensity = DEFAULT_PLACE_INTENSITY; - this.xpChangeIntensity = DEFAULT_XP_CHANGE_INTENSITY; - this.fishingIntensity = DEFAULT_FISHING_INTENSITY; - this.harvestIntensity = DEFAULT_HARVEST_INTENSITY; - this.vitalityIntensity = DEFAULT_VITALITY_INTENSITY; - this.advancementIntensity = DEFAULT_ADVANCEMENT_INTENSITY; - } - } - - public static void resetConfigUrl() - { + + public static void resetConfigUrl() { serverUrl.serverUrl = DEFAULT_SERVER_URL; } - - public static void resetConfigCustom() - { + + public static void resetConfigCustom() { intensity.attackIntensity = DEFAULT_ATTACK_INTENSITY; intensity.hurtIntensity = DEFAULT_HURT_INTENSITY; intensity.mineIntensity = DEFAULT_MINE_INTENSITY; @@ -128,16 +61,6 @@ public static void resetConfigCustom() intensity.advancementIntensity = DEFAULT_ADVANCEMENT_INTENSITY; } - @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID) - private static class EventHandler { - @SubscribeEvent - public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) { - if (event.getModID().equals(Minegasm.MOD_ID)) { - ConfigManager.sync(Minegasm.MOD_ID, Config.Type.INSTANCE); - } - } - } - public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -149,51 +72,43 @@ public enum GameplayMode { GameplayMode(String translateKey) { this.translateKey = - Objects.requireNonNull(translateKey, "translateKey"); + Objects.requireNonNull(translateKey, "translateKey"); } public String getTranslateKey() { return this.translateKey; } - - public GameplayMode next() - { + + public GameplayMode next() { boolean foundCurrent = false; - for (GameplayMode type : values()) - { + for (GameplayMode type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } - + } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -201,21 +116,88 @@ public static TickFrequencyOptions fromInt(int value) } return null; } - - public TickFrequencyOptions next() - { + + public int getInt() { + return value; + } + + public TickFrequencyOptions next() { boolean foundCurrent = false; - for (TickFrequencyOptions type : values()) - { + for (TickFrequencyOptions type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } } + public static class ServerUrlConfig { + @Comment("The URL of the Intiface/Buttplug server") + public String serverUrl; + + public ServerUrlConfig() { + this.serverUrl = DEFAULT_SERVER_URL; + } + } + + public static class IntensityConfig { + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int attackIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int hurtIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int mineIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int placeIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int xpChangeIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int fishingIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int harvestIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int vitalityIntensity; + @Config.RangeInt(min = 0, max = 100) + @Config.SlidingOption + public int advancementIntensity; + + public IntensityConfig() { + resetConfigValues(); + } + + public void resetConfigValues() { + this.attackIntensity = DEFAULT_ATTACK_INTENSITY; + this.hurtIntensity = DEFAULT_HURT_INTENSITY; + this.mineIntensity = DEFAULT_MINE_INTENSITY; + this.placeIntensity = DEFAULT_PLACE_INTENSITY; + this.xpChangeIntensity = DEFAULT_XP_CHANGE_INTENSITY; + this.fishingIntensity = DEFAULT_FISHING_INTENSITY; + this.harvestIntensity = DEFAULT_HARVEST_INTENSITY; + this.vitalityIntensity = DEFAULT_VITALITY_INTENSITY; + this.advancementIntensity = DEFAULT_ADVANCEMENT_INTENSITY; + } + } + + @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID) + private static class EventHandler { + @SubscribeEvent + public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) { + if (event.getModID().equals(Minegasm.MOD_ID)) { + ConfigManager.sync(Minegasm.MOD_ID, Config.Type.INSTANCE); + } + } + } + // Server // -- none at the moment diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ModListMenuScreen.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ModListMenuScreen.java index b515c3d..d915236 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ModListMenuScreen.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/ModListMenuScreen.java @@ -1,30 +1,22 @@ package com.therainbowville.minegasm.config; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.fml.client.config.GuiConfig; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import net.minecraftforge.fml.client.config.GuiConfig; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiIngameMenu; - -import org.apache.commons.lang3.mutable.MutableObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.common.Minegasm; - @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID) public class ModListMenuScreen { private static final Logger LOGGER = LogManager.getLogger(); - + @SubscribeEvent public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { - if(event.getGui() instanceof GuiConfig && ((GuiConfig)event.getGui()).modID.equals(Minegasm.MOD_ID)) { // Make sure GUI is Escape menu - Minecraft.getMinecraft().displayGuiScreen(new ConfigScreen(((GuiConfig)event.getGui()).parentScreen)); + if (event.getGui() instanceof GuiConfig && ((GuiConfig) event.getGui()).modID.equals(Minegasm.MOD_ID)) { // Make sure GUI is Escape menu + Minecraft.getMinecraft().displayGuiScreen(new ConfigScreen(((GuiConfig) event.getGui()).parentScreen)); } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 402ab0e..40cd28d 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,85 +1,81 @@ package com.therainbowville.minegasm.config; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.client.config.GuiButtonExt; +import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.widgets.GuiButtonExtraExt; +import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends GuiButtonExtraExt -{ +public class PauseMenuButton extends GuiButtonExtraExt { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - - public PauseMenuButton(int x, int y) { - super(x, y, 20, 20, (""), PauseMenuButton::clicked); + + public PauseMenuButton(int x, int y) { + super(x, y, 20, 20, (""), PauseMenuButton::clicked); xPos = x; yPos = y; - } - - @Override - public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) { -// mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + } + + public static void clicked(GuiButtonExtraExt button) { + LOGGER.info("Logged Here"); + Minecraft.getMinecraft().displayGuiScreen(new ConfigScreen(Minecraft.getMinecraft().currentScreen, true)); + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) { +// mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); // mstack.scale(0.25f, 0.25f, 1); // blit(xPos, yPos, 0, 0, 20, 20); super.drawButton(mc, mouseX, mouseY, partialTicks); mc.getTextureManager().bindTexture(LOGO); - drawModalRectWithCustomSizedTexture(xPos + 2, yPos + 2, 0, 0, 16, 16, 16, 16); - } - - public static void clicked(GuiButtonExtraExt button) - { - LOGGER.info("Logged Here"); - Minecraft.getMinecraft().displayGuiScreen(new ConfigScreen(Minecraft.getMinecraft().currentScreen, true)); + drawModalRectWithCustomSizedTexture(xPos + 2, yPos + 2, 0, 0, 16, 16, 16, 16); } - + public static class SingleMenuRow { - public final String left, right; - public SingleMenuRow(String left, String right) { - this.left = I18n.format(left); - this.right = I18n.format(right); - } - public SingleMenuRow(String center) { - this(center, center); - } - } - - public static class MenuRows { - public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") - )); + public final String left, right; + + public SingleMenuRow(String left, String right) { + this.left = I18n.format(left); + this.right = I18n.format(right); + } + + public SingleMenuRow(String center) { + this(center, center); + } + } + + public static class MenuRows { + public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + )); - public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), + public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), // new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") - )); + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") + )); - protected final List leftButtons, rightButtons; + protected final List leftButtons, rightButtons; - public MenuRows(List variants) { - leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); - rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); - } - } + public MenuRows(List variants) { + leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); + rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); + } + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java index 10a0d71..c823274 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java @@ -1,27 +1,23 @@ package com.therainbowville.minegasm.config; +import com.therainbowville.minegasm.common.Minegasm; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiIngameMenu; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiIngameMenu; - import org.apache.commons.lang3.mutable.MutableObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.common.Minegasm; - @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID) public class PauseMenuButtonScreen { private static final Logger LOGGER = LogManager.getLogger(); - + @SubscribeEvent public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { - if(event.getGui() instanceof GuiIngameMenu) { // Make sure GUI is Escape menu + if (event.getGui() instanceof GuiIngameMenu) { // Make sure GUI is Escape menu PauseMenuButton.MenuRows menu = PauseMenuButton.MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -32,16 +28,15 @@ public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getButtonList() - .stream() - .filter(w -> w instanceof GuiButton) - .map(w -> (GuiButton) w) - .filter(w -> w.displayString - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.width), w.y))); - if (toAdd.getValue() != null) - { + .stream() + .filter(w -> w instanceof GuiButton) + .map(w -> (GuiButton) w) + .filter(w -> w.displayString + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.width), w.y))); + if (toAdd.getValue() != null) { event.getButtonList().add(toAdd.getValue()); } } diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java index 000e0e0..fd5a849 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java @@ -1,6 +1,6 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; @@ -8,7 +8,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.play.server.SPacketAdvancementInfo; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.AdvancementEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -25,15 +24,17 @@ public class ClientAdvancementManagerMixin { @Inject(method = "read", at = @At("HEAD"), cancellable = true) public void onUpdate(SPacketAdvancementInfo advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getMinecraft().isIntegratedServerRunning()) { return; } + if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgressUpdates().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgressUpdates().entrySet()) { Advancement advancement = ((ClientAdvancementManager) (Object) this).getAdvancementList().getAdvancement(entry.getKey()); if (advancement != null) { EntityPlayer player = Minecraft.getMinecraft().player; AdvancementEvent event = new AdvancementEvent(player, advancement); - ClientEventHandler.onAdvancementEvent(event); + ClientEventHandler.onAdvancementEvent(event); } } } diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/EntityPlayerSPMixin.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/EntityPlayerSPMixin.java index 153cb7d..462a3f9 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/EntityPlayerSPMixin.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/EntityPlayerSPMixin.java @@ -1,20 +1,14 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; -import net.minecraft.world.World; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerPickupXpEvent; - - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -22,7 +16,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.Shadow; @Mixin(EntityPlayerSP.class) public class EntityPlayerSPMixin { @@ -38,8 +31,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "attackEntityFrom", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getMinecraft().isIntegratedServerRunning()) { return; } - + if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((EntityLivingBase) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -48,19 +43,21 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) { - + EntityXPOrb orb = new EntityXPOrb(((EntityPlayer) (Object) this).world); orb.xpValue = amount; LOGGER.info("Experience changed"); PlayerPickupXpEvent event = new PlayerPickupXpEvent((EntityPlayer) (Object) this, orb); ClientEventHandler.onXpChange(event); - + } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMPMixin.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMPMixin.java index 4f4651f..f75022b 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMPMixin.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMPMixin.java @@ -1,44 +1,37 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraft.client.multiplayer.PlayerControllerMP; -import net.minecraftforge.event.world.BlockEvent.BreakEvent; -import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.util.math.BlockPos; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.Vec3d; import net.minecraft.util.EnumHand; -import net.minecraft.util.EnumActionResult; - -import net.minecraft.item.ItemBlock; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - import net.minecraft.util.math.BlockPos; - +import net.minecraft.util.math.Vec3d; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerControllerMP.class) public class PlayerControllerMPMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "onPlayerDestroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getMinecraft().isIntegratedServerRunning()) { return; } - + if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + return; + } + EntityPlayer player = Minecraft.getMinecraft().player; if (player != null) { BreakEvent event = new BreakEvent(player.world, blockPos, player.world.getBlockState(blockPos), player); @@ -47,20 +40,24 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci } @Inject(method = "processRightClickBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;onItemUse(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumHand;Lnet/minecraft/util/EnumFacing;FFF)Lnet/minecraft/util/EnumActionResult;", - shift = At.Shift.AFTER), cancellable = true) + shift = At.Shift.AFTER), cancellable = true) public void onUseItemOn(EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand, CallbackInfoReturnable cir) { - if (Minecraft.getMinecraft().isIntegratedServerRunning() ) { return; } - - if (player.getHeldItem(hand).getItem() instanceof ItemBlock){ + if (Minecraft.getMinecraft().isIntegratedServerRunning()) { + return; + } + + if (player.getHeldItem(hand).getItem() instanceof ItemBlock) { this.placedBlock = true; } - + } - + @Inject(method = "processRightClickBlock", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand, CallbackInfoReturnable cir) { - if (Minecraft.getMinecraft().isIntegratedServerRunning() || !this.placedBlock) { return; } - + if (Minecraft.getMinecraft().isIntegratedServerRunning() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == EnumActionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/ButtonPress.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/ButtonPress.java index ea52ea9..c1acc54 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/ButtonPress.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/ButtonPress.java @@ -1,6 +1,5 @@ package com.therainbowville.minegasm.widgets; -public interface ButtonPress -{ +public interface ButtonPress { public void onClick(GuiButtonExtraExt button); } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/GuiButtonExtraExt.java b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/GuiButtonExtraExt.java index 22a41c2..bf044ae 100644 --- a/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/GuiButtonExtraExt.java +++ b/forge/fg-6.0/1.12.2/src/main/java/com/therainbowville/minegasm/widgets/GuiButtonExtraExt.java @@ -1,35 +1,25 @@ package com.therainbowville.minegasm.widgets; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TextComponentString; import net.minecraft.client.Minecraft; - import net.minecraftforge.fml.client.config.GuiButtonExt; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class GuiButtonExtraExt extends GuiButtonExt -{ +public class GuiButtonExtraExt extends GuiButtonExt { private ButtonPress onPress; - - public GuiButtonExtraExt(int x, int y, int width, int height, java.lang.String displayString, ButtonPress onPress) - { + + public GuiButtonExtraExt(int x, int y, int width, int height, java.lang.String displayString, ButtonPress onPress) { super(16, x, y, width, height, displayString); this.onPress = onPress; } @Override() - public boolean mousePressed(Minecraft mc, int i, int j) - { + public boolean mousePressed(Minecraft mc, int i, int j) { if (isMouseOver() && this.enabled == true) onPress.onClick(this); return super.mousePressed(mc, i, j); } - - public void setMessage(java.lang.String message) - { + + public void setMessage(java.lang.String message) { this.displayString = message; } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.12.2/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.12.2/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.12.2/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.12.2/src/main/resources/mcmod.info b/forge/fg-6.0/1.12.2/src/main/resources/mcmod.info index aa8963e..6bbf27c 100644 --- a/forge/fg-6.0/1.12.2/src/main/resources/mcmod.info +++ b/forge/fg-6.0/1.12.2/src/main/resources/mcmod.info @@ -1,16 +1,18 @@ [ -{ - "modid": "minegasm", - "name": "Minegasm", - "description": "Just a simple mod to bring some gasm into Minecraft. ;)", - "version": "0.5.0", - "mcversion": "${mcversion}", - "url": "https://minegasm.therainbowville.com/", - "updateUrl": "https://minegasm.therainbowville.com/updates.json", - "authorList": ["RSwoop"], - "credits": "", - "logoFile": "minegasm.png", - "screenshots": [], - "dependencies": [] -} + { + "modid": "minegasm", + "name": "Minegasm", + "description": "Just a simple mod to bring some gasm into Minecraft. ;)", + "version": "0.5.0", + "mcversion": "${mcversion}", + "url": "https://minegasm.therainbowville.com/", + "updateUrl": "https://minegasm.therainbowville.com/updates.json", + "authorList": [ + "RSwoop" + ], + "credits": "", + "logoFile": "minegasm.png", + "screenshots": [], + "dependencies": [] + } ] diff --git a/forge/fg-6.0/1.12.2/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.12.2/src/main/resources/mixins.minegasm.json index 14c0c6e..23bb913 100644 --- a/forge/fg-6.0/1.12.2/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.12.2/src/main/resources/mixins.minegasm.json @@ -5,8 +5,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "PlayerControllerMPMixin", "ClientAdvancementManagerMixin", - "EntityPlayerSPMixin" + "EntityPlayerSPMixin", + "PlayerControllerMPMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.12.2/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.12.2/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.12.2/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.12.2/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/build.gradle b/forge/fg-6.0/1.15.2/build.gradle index dc035f1..d83f93d 100644 --- a/forge/fg-6.0/1.15.2/build.gradle +++ b/forge/fg-6.0/1.15.2/build.gradle @@ -162,13 +162,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -221,4 +221,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/gradle.properties b/forge/fg-6.0/1.15.2/gradle.properties index 1e5b0f1..1c7a457 100644 --- a/forge/fg-6.0/1.15.2/gradle.properties +++ b/forge/fg-6.0/1.15.2/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.15.2 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index 80398fa..49569c5 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,35 +1,25 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; - import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { @@ -39,7 +29,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -49,56 +39,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof PlayerEntity && !(entity instanceof FakePlayer)) { - PlayerEntity player = (PlayerEntity) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof PlayerEntity && !(entity instanceof FakePlayer)) { + PlayerEntity player = (PlayerEntity) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -112,26 +96,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - PlayerEntity player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(Minecraft.getInstance().player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + PlayerEntity player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(Minecraft.getInstance().player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -160,96 +144,79 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((PlayerEntity)event.getEntityLiving()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((PlayerEntity) event.getEntityLiving()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } @@ -277,35 +244,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof PlayerEntity) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - PlayerEntity player = (PlayerEntity) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(new StringTextComponent(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + PlayerEntity player = (PlayerEntity) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(new StringTextComponent(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(new StringTextComponent(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(new StringTextComponent(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 8e264a0..04f2b48 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -115,18 +86,44 @@ public static int getIntensity(String type) { int returnValue = -1; - - switch (MinegasmConfig.mode) - { - case NORMAL: returnValue = normal.get(type); - case MASOCHIST: returnValue = masochist.get(type); - case HEDONIST: returnValue = hedonist.get(type); - case ACCUMULATION: returnValue = accumulation.get(type); - case CUSTOM: returnValue = custom.get(type); - }; - + + switch (MinegasmConfig.mode) { + case NORMAL: + returnValue = normal.get(type); + case MASOCHIST: + returnValue = masochist.get(type); + case HEDONIST: + returnValue = hedonist.get(type); + case ACCUMULATION: + returnValue = accumulation.get(type); + case CUSTOM: + returnValue = custom.get(type); + } + ; + return returnValue; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index dc7646a..214e8a5 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -16,8 +16,7 @@ import org.apache.logging.log4j.Logger; @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -36,8 +35,7 @@ public Minegasm() { context.registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (mc, screen) -> new ConfigScreen(screen)); } - private void setupCommon(final FMLCommonSetupEvent event) - { + private void setupCommon(final FMLCommonSetupEvent event) { LOGGER.info("Common setup..."); } diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 09d478d..4b571b1 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,49 +1,45 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEvent event) - { + + public void onAdvancement(AdvancementEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - if (advancement == null) return; - FrameType type = advancement.getDisplay().getFrame(); - int duration = 0; - - switch (type) { - case TASK: - duration = 5; - break; - case GOAL: - duration = 7; - break; - case CHALLENGE: - duration = 10; - break; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + if (advancement == null) return; + FrameType type = advancement.getDisplay().getFrame(); + int duration = 0; + + switch (type) { + case TASK: + duration = 5; + break; + case GOAL: + duration = 7; + break; + case CHALLENGE: + duration = 10; + break; + } + ; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index 6353a0e..f9a6646 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,41 +1,32 @@ package com.therainbowville.minegasm.common; -import net.minecraft.client.Minecraft; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.util.math.Vec3d; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ +public class VibrationStateFish extends AbstractVibrationState { - public VibrationStateFish() - { + public VibrationStateFish() { super(0); } - - public void onTick(ClientPlayerEntity player) - { + + public void onTick(ClientPlayerEntity player) { if (player == null) return; - - if (player.fishing != null) - { + + if (player.fishing != null) { Vec3d vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && player.fishing.isInWater() && x == 0 && z == 0) - { + if (y < -0.075 && player.fishing.isInWater() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index a7254ab..a4ed4a5 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,30 +1,24 @@ package com.therainbowville.minegasm.common; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index 477f80b..7cb8710 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.block.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.block.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 20c13d9..ba95d54 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.entity.player.PlayerEntity; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.entity.player.PlayerEntity; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(PlayerEntity player) - { + + public void onTick(PlayerEntity player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(PlayerEntity player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index bbd310c..06408b0 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -154,45 +144,37 @@ public enum GameplayMode { public String getTranslateKey() { return this.translateKey; } - - public GameplayMode next() - { + + public GameplayMode next() { boolean foundCurrent = false; - for (GameplayMode type : values()) - { + for (GameplayMode type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } - + } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -200,19 +182,21 @@ public static TickFrequencyOptions fromInt(int value) } return null; } - - public TickFrequencyOptions next() - { + + public int getInt() { + return value; + } + + public TickFrequencyOptions next() { boolean foundCurrent = false; - for (TickFrequencyOptions type : values()) - { + for (TickFrequencyOptions type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index c647c9f..38353d0 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -16,7 +16,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -30,30 +30,28 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index b422dfa..543991f 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index 634ae5f..cfb07c2 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,43 +1,28 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.IngameMenuScreen; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.StringTextComponent; - -import net.minecraftforge.fml.client.gui.widget.ExtendedButton; -import net.minecraftforge.eventbus.api.SubscribeEvent; - +import net.minecraft.util.text.TextFormatting; import net.minecraftforge.client.gui.widget.ForgeSlider; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - +import net.minecraftforge.fml.client.gui.widget.ExtendedButton; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.Objects; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; - TextFieldWidget wsHost = null; - public ClientConfig.TickFrequencyOptions tickValue; + TextFieldWidget wsHost = null; + private boolean pauseMenu; private PlainTextLabel connectResponse; public ConfigScreen(Screen previous) { @@ -46,7 +31,7 @@ public ConfigScreen(Screen previous) { pauseMenu = false; tickValue = ClientConfig.TickFrequencyOptions.fromInt(MinegasmConfig.tickFrequency); } - + public ConfigScreen(Screen previous, boolean pause) { super(new StringTextComponent("Minegasm Config")); this.previous = previous; @@ -59,31 +44,31 @@ protected void init() { wsHost = new TextFieldWidget(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, "ws://localhost:12345"); wsHost.setValue(MinegasmConfig.serverUrl); this.addButton(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addButton(new ExtendedButton( - this.width / 2 - 155, this.height / 6 + 25, 150, 20, - "Reset Server Url", button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - } + this.width / 2 - 155, this.height / 6 + 25, 150, 20, + "Reset Server Url", button -> { + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + } )); - + connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, ("" + TextFormatting.GREEN)); this.addButton(connectResponse); - + Button reconnectButton = new ExtendedButton( - this.width / 2 + 5, this.height / 6 + 25, 150, 20, - "Reconnect", button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + this.width / 2 + 5, this.height / 6 + 25, 150, 20, + "Reconnect", button -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -92,74 +77,86 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - } + + }).start(); + } ); this.addButton(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addButton(new ExtendedButton(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - ("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { - MinegasmConfig.vibrate = !MinegasmConfig.vibrate; - button.setMessage(("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); - })); + ("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { + MinegasmConfig.vibrate = !MinegasmConfig.vibrate; + button.setMessage(("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); + })); this.addButton(new ExtendedButton(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - ("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { - MinegasmConfig.stealth = !MinegasmConfig.stealth; - button.setMessage(("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); - })); + ("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { + MinegasmConfig.stealth = !MinegasmConfig.stealth; + button.setMessage(("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); + })); this.addButton(new ExtendedButton(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - ("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { - MinegasmConfig.mode = MinegasmConfig.mode.next(); - button.setMessage(("Mode: " + gameplayModeToString(MinegasmConfig.mode))); - } + ("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { + MinegasmConfig.mode = MinegasmConfig.mode.next(); + button.setMessage(("Mode: " + gameplayModeToString(MinegasmConfig.mode))); + } )); this.addButton(new ExtendedButton( - this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, - ("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, + ("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); this.addButton(new ExtendedButton(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - ("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency)), (button) -> { - tickValue = tickValue.next(); - MinegasmConfig.tickFrequency = tickValue.getInt(); - MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - button.setMessage(("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency))); - } + ("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency)), (button) -> { + tickValue = tickValue.next(); + MinegasmConfig.tickFrequency = tickValue.getInt(); + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); + button.setMessage(("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency))); + } )); this.addButton(new ExtendedButton( - this.width / 2 - 100, this.height - 27, 200, 20, - ("Done"), button -> this.onClose())); + this.width / 2 - 100, this.height - 27, 200, 20, + ("Done"), button -> this.onClose())); } - - private String gameplayModeToString(ClientConfig.GameplayMode mode){ + + private String gameplayModeToString(ClientConfig.GameplayMode mode) { switch (mode) { - case NORMAL: return "Normal"; - case MASOCHIST: return "Masochist"; - case HEDONIST: return "Hedonist"; - case ACCUMULATION: return "Accumulation"; - case CUSTOM: return "Custom"; - default: return ""; + case NORMAL: + return "Normal"; + case MASOCHIST: + return "Masochist"; + case HEDONIST: + return "Hedonist"; + case ACCUMULATION: + return "Accumulation"; + case CUSTOM: + return "Custom"; + default: + return ""; } } - private String tickFrequencyToString(Integer frequency){ + private String tickFrequencyToString(Integer frequency) { switch (frequency) { - case 1: return "Every Tick"; - case 2: return "Every Other Tick"; - case 5: return "Every 5 Ticks"; - case 10: return "Every 10 Ticks"; - case 20: return "Every Second"; - default: return "Every " + Float.toString(frequency / 20f)+ " Seconds"; + case 1: + return "Every Tick"; + case 2: + return "Every Other Tick"; + case 5: + return "Every 5 Ticks"; + case 10: + return "Every 10 Ticks"; + case 20: + return "Every Second"; + default: + return "Every " + Float.toString(frequency / 20f) + " Seconds"; } } - + @Override public void tick() { super.tick(); @@ -185,9 +182,9 @@ public void render(int i, int j, float f) { drawCenteredString(this.font, this.title.getString(), this.width / 2, 15, 0xFFFFFF); super.render(i, j, f); } - + class PlainTextLabel extends Widget { - + private StringTextComponent text = new StringTextComponent(""); private int x; private int y; @@ -198,8 +195,7 @@ public PlainTextLabel(int x, int y, int width, int height, String text) { this.y = y; } - public void setValue(String value) - { + public void setValue(String value) { text = new StringTextComponent(value); } @@ -211,7 +207,7 @@ public void render(int i, int j, float f) { drawCenteredString(Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -224,7 +220,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(new StringTextComponent("Minegasm Custom Config")); this.previous = previous; @@ -233,49 +229,49 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addButton(new ExtendedButton( - this.width / 2 + 5, this.height - 27, 150, 20, - ("Done"), button -> this.onClose())); + try { + this.addButton(new ExtendedButton( + this.width / 2 + 5, this.height - 27, 150, 20, + ("Done"), button -> this.onClose())); - IntensitiySliderBar.sliders.clear(); + IntensitiySliderBar.sliders.clear(); - // Attack - this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addButton(new ExtendedButton( - this.width / 2 - 155, this.height - 27, 150, 20, - ("Reset Values"), button -> { + // Attack + this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addButton(new ExtendedButton( + this.width / 2 - 155, this.height - 27, 150, 20, + ("Reset Values"), button -> { ConfigHolder.getClientInstance().resetConfigCustom(); IntensitiySliderBar.refreshAllValues(); } - )); - - + )); + + } catch (Throwable e) { LOGGER.throwing(e); } @@ -298,27 +294,30 @@ public void render(int i, int j, float f) { } } -class IntensitiySliderBar extends ForgeSlider -{ +class IntensitiySliderBar extends ForgeSlider { private static final Logger LOGGER = LogManager.getLogger(); public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - prefix, // Prefix - "", // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + prefix, // Prefix + "", // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { try { fieldReference.set(null, this.getValueInt()); } catch (Throwable e) { @@ -326,16 +325,7 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index 79b2dd9..48a0aea 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -21,7 +21,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static int ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -47,23 +47,21 @@ public static void onModConfigEvent(final ModConfig.ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -73,15 +71,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 2efdbf8..b12f46a 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,89 +1,80 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.AbstractGui; -import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - - public PauseMenuButton(int x, int y) { - super(x, y, 20, 20, (""), PauseMenuButton::clicked); + + public PauseMenuButton(int x, int y) { + super(x, y, 20, 20, (""), PauseMenuButton::clicked); xPos = x; yPos = y; - } - - @Override - public void renderBg(Minecraft mc, int mouseX, int mouseY) { -// mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + } + + public static void clicked(Button button) { + Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); + } + + @Override + public void renderBg(Minecraft mc, int mouseX, int mouseY) { +// mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); // mstack.scale(0.25f, 0.25f, 1); // blit(xPos, yPos, 0, 0, 20, 20); super.renderBg(mc, mouseX, mouseY); Minecraft.getInstance().getTextureManager().bind(LOGO); - blit(xPos + 2, yPos + 2, 0, 0, 0, 16, 16, 16, 16); - } - - public static void clicked(Button button) - { - Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); + blit(xPos + 2, yPos + 2, 0, 0, 0, 16, 16, 16, 16); } - + public static class SingleMenuRow { - public final String left, right; - public SingleMenuRow(String left, String right) { - this.left = I18n.get(left); - this.right = I18n.get(right); - } - public SingleMenuRow(String center) { - this(center, center); - } - } - - public static class MenuRows { - public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") - )); + public final String left, right; - public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") - )); + public SingleMenuRow(String left, String right) { + this.left = I18n.get(left); + this.right = I18n.get(right); + } - protected final List leftButtons, rightButtons; + public SingleMenuRow(String center) { + this(center, center); + } + } + + public static class MenuRows { + public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + )); + + public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") + )); - public MenuRows(List variants) { - leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); - rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); - } - } + protected final List leftButtons, rightButtons; + + public MenuRows(List variants) { + leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); + rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); + } + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java index cc1da2e..6f9d5e6 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java @@ -1,27 +1,23 @@ package com.therainbowville.minegasm.config; +import com.therainbowville.minegasm.common.Minegasm; +import net.minecraft.client.gui.screen.IngameMenuScreen; +import net.minecraft.client.gui.widget.Widget; import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; - -import net.minecraft.client.gui.widget.Widget; -import net.minecraft.client.gui.screen.IngameMenuScreen; - +import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.mutable.MutableObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.common.Minegasm; - @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { private static final Logger LOGGER = LogManager.getLogger(); - + @SubscribeEvent public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { - if(event.getGui() instanceof IngameMenuScreen) { // Make sure GUI is Escape menu + if (event.getGui() instanceof IngameMenuScreen) { // Make sure GUI is Escape menu PauseMenuButton.MenuRows menu = PauseMenuButton.MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -32,14 +28,14 @@ public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getWidgetList() - .stream() - .filter(w -> w instanceof Widget) - .map(w -> (Widget) w) - .filter(w -> w.getMessage() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); + .stream() + .filter(w -> w instanceof Widget) + .map(w -> (Widget) w) + .filter(w -> w.getMessage() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); if (toAdd.getValue() != null) event.addWidget(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java index e9c8dc7..bfb23b7 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java @@ -1,6 +1,6 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; @@ -8,7 +8,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.play.server.SAdvancementInfoPacket; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.AdvancementEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancementManager.class) public class ClientAdvancementManagerMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(SAdvancementInfoPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { Advancement advancement = ((ClientAdvancementManager) (Object) this).getAdvancements().get(entry.getKey()); PlayerEntity player = minecraft.player; AdvancementEvent event = new AdvancementEvent(player, advancement); diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java index 5be1051..7ba526b 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java @@ -1,18 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.LivingEntity; - +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.DamageSource; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -35,8 +30,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LivingEntity) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -45,8 +42,10 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) { XpChange event = new XpChange((PlayerEntity) (Object) this, amount); diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java index 1b2859c..f45362e 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java @@ -1,62 +1,60 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraft.client.multiplayer.PlayerController; -import net.minecraftforge.event.world.BlockEvent.BreakEvent; -import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.multiplayer.PlayerController; import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.ActionResultType; - +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; - +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerController.class) public class PlayerControllerMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + PlayerEntity player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level, blockPos, player.level.getBlockState(blockPos), player); ClientEventHandler.onBreak(event); } } - + @Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;useOn(Lnet/minecraft/item/ItemUseContext;)Lnet/minecraft/util/ActionResultType;", shift = At.Shift.AFTER), cancellable = true) public void onUseItemOn(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockRayTraceResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - - if (player.getItemInHand(hand).getItem() instanceof BlockItem){ + if (Minecraft.getInstance().isLocalServer()) { + return; + } + + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { this.placedBlock = true; } } - + @Inject(method = "useItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockRayTraceResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == ActionResultType.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java index 35bc090..6993ede 100644 --- a/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java +++ b/forge/fg-6.0/1.15.2/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java @@ -6,7 +6,6 @@ package net.minecraftforge.client.gui.widget; import net.minecraft.client.gui.widget.AbstractSlider; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.math.MathHelper; import org.lwjgl.glfw.GLFW; @@ -15,37 +14,33 @@ /** * Slider widget implementation which allows inputting values in a certain range with optional step size. */ -public class ForgeSlider extends AbstractSlider -{ +public class ForgeSlider extends AbstractSlider { + private final DecimalFormat format; protected String prefix; protected String suffix; - protected double minValue; protected double maxValue; - - /** Allows input of discontinuous values with a certain step */ + /** + * Allows input of discontinuous values with a certain step + */ protected double stepSize; - protected boolean drawString; - private final DecimalFormat format; - /** - * @param x x position of upper left corner - * @param y y position of upper left corner - * @param width Width of the widget - * @param height Height of the widget - * @param prefix {@link String} displayed before the value string - * @param suffix {@link String} displayed after the value string - * @param minValue Minimum (left) value of slider - * @param maxValue Maximum (right) value of slider + * @param x x position of upper left corner + * @param y y position of upper left corner + * @param width Width of the widget + * @param height Height of the widget + * @param prefix {@link String} displayed before the value string + * @param suffix {@link String} displayed after the value string + * @param minValue Minimum (left) value of slider + * @param maxValue Maximum (right) value of slider * @param currentValue Starting value when widget is first displayed - * @param stepSize Size of step used. Precision will automatically be calculated based on this value if this value is not 0. - * @param precision Only used when {@code stepSize} is 0. Limited to a maximum of 4 (inclusive). - * @param drawString Should text be displayed on the widget + * @param stepSize Size of step used. Precision will automatically be calculated based on this value if this value is not 0. + * @param precision Only used when {@code stepSize} is 0. Limited to a maximum of 4 (inclusive). + * @param drawString Should text be displayed on the widget */ - public ForgeSlider(int x, int y, int width, int height, String prefix, String suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) - { + public ForgeSlider(int x, int y, int width, int height, String prefix, String suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) { super(x, y, width, height, 0D); this.prefix = prefix; this.suffix = suffix; @@ -55,8 +50,7 @@ public ForgeSlider(int x, int y, int width, int height, String prefix, String su this.value = this.snapToNearest((currentValue - minValue) / (maxValue - minValue)); this.drawString = drawString; - if (stepSize == 0D) - { + if (stepSize == 0D) { precision = Math.min(precision, 4); StringBuilder builder = new StringBuilder("0"); @@ -68,13 +62,9 @@ public ForgeSlider(int x, int y, int width, int height, String prefix, String su builder.append('0'); this.format = new DecimalFormat(builder.toString()); - } - else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) - { + } else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) { this.format = new DecimalFormat("0"); - } - else - { + } else { this.format = new DecimalFormat(Double.toString(this.stepSize).replaceAll("\\d", "0")); } @@ -84,68 +74,58 @@ else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) /** * Overload with {@code stepSize} set to 1, useful for sliders with whole number values. */ - public ForgeSlider(int x, int y, int width, int height, String prefix, String suffix, double minValue, double maxValue, double currentValue, boolean drawString) - { + public ForgeSlider(int x, int y, int width, int height, String prefix, String suffix, double minValue, double maxValue, double currentValue, boolean drawString) { this(x, y, width, height, prefix, suffix, minValue, maxValue, currentValue, 1D, 0, drawString); } /** * @return Current slider value as a double */ - public double getValue() - { + public double getValue() { return this.value * (maxValue - minValue) + minValue; } /** - * @return Current slider value as an long + * @param value The new slider value */ - public long getValueLong() - { - return Math.round(this.getValue()); + public void setValue(double value) { + this.value = this.snapToNearest((value - this.minValue) / (this.maxValue - this.minValue)); + this.updateMessage(); } /** - * @return Current slider value as an int + * @return Current slider value as an long */ - public int getValueInt() - { - return (int) this.getValueLong(); + public long getValueLong() { + return Math.round(this.getValue()); } /** - * @param value The new slider value + * @return Current slider value as an int */ - public void setValue(double value) - { - this.value = this.snapToNearest((value - this.minValue) / (this.maxValue - this.minValue)); - this.updateMessage(); + public int getValueInt() { + return (int) this.getValueLong(); } - public String getValueString() - { + public String getValueString() { return this.format.format(this.getValue()); } @Override - public void onClick(double mouseX, double mouseY) - { + public void onClick(double mouseX, double mouseY) { this.setValueFromMouse(mouseX); } @Override - protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) - { + protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) { super.onDrag(mouseX, mouseY, dragX, dragY); this.setValueFromMouse(mouseX); } @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) - { + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { boolean flag = keyCode == GLFW.GLFW_KEY_LEFT; - if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) - { + if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) { if (this.minValue > this.maxValue) flag = !flag; float f = flag ? -1F : 1F; @@ -158,16 +138,14 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) return false; } - private void setValueFromMouse(double mouseX) - { + private void setValueFromMouse(double mouseX) { this.setSliderValue((mouseX - (this.x + 4)) / (this.width - 8)); } /** * @param value Percentage of slider range */ - private void setSliderValue(double value) - { + private void setSliderValue(double value) { double oldValue = this.value; this.value = this.snapToNearest(value); if (!MathHelper.equal(oldValue, this.value)) @@ -180,41 +158,34 @@ private void setSliderValue(double value) * Snaps the value, so that the displayed value is the nearest multiple of {@code stepSize}. * If {@code stepSize} is 0, no snapping occurs. */ - private double snapToNearest(double value) - { - if(stepSize <= 0D) + private double snapToNearest(double value) { + if (stepSize <= 0D) return MathHelper.clamp(value, 0D, 1D); value = MathHelper.lerp(MathHelper.clamp(value, 0D, 1D), this.minValue, this.maxValue); value = (stepSize * Math.round(value / stepSize)); - if (this.minValue > this.maxValue) - { + if (this.minValue > this.maxValue) { value = MathHelper.clamp(value, this.maxValue, this.minValue); - } - else - { + } else { value = MathHelper.clamp(value, this.minValue, this.maxValue); } - return (value-this.minValue)/(this.maxValue-this.minValue) * (1D-0D) + 0D; + return (value - this.minValue) / (this.maxValue - this.minValue) * (1D - 0D) + 0D; // return MathHelper.map(value, this.minValue, this.maxValue, 0D, 1D); } @Override - protected void updateMessage() - { - if (this.drawString) - { + protected void updateMessage() { + if (this.drawString) { this.setMessage(prefix + this.getValueString() + suffix); - } - else - { + } else { this.setMessage(""); } } @Override - protected void applyValue() {} + protected void applyValue() { + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.15.2/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.15.2/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.15.2/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.15.2/src/main/resources/assets/minegasm/lang/en_us.json b/forge/fg-6.0/1.15.2/src/main/resources/assets/minegasm/lang/en_us.json index f5f5b24..fa5f32b 100644 --- a/forge/fg-6.0/1.15.2/src/main/resources/assets/minegasm/lang/en_us.json +++ b/forge/fg-6.0/1.15.2/src/main/resources/assets/minegasm/lang/en_us.json @@ -1,16 +1,14 @@ { - "gui.minegasm.config.vibrate": "Vibrate", - - "gui.minegasm.config.mode": "Mode", - "gui.minegasm.config.mode.normal": "Normal", - "gui.minegasm.config.mode.masochist": "Masochist", - "gui.minegasm.config.mode.hedonist": "Hedonist", - "gui.minegasm.config.mode.custom": "Custom", - - "gui.minegasm.config.intensity.attack": "Attack", - "gui.minegasm.config.intensity.hurt": "Hurt", - "gui.minegasm.config.intensity.mine": "Mine", - "gui.minegasm.config.intensity.xp": "XP", - "gui.minegasm.config.intensity.harvest": "Harvest", - "gui.minegasm.config.intensity.vitality": "Vitality" + "gui.minegasm.config.vibrate": "Vibrate", + "gui.minegasm.config.mode": "Mode", + "gui.minegasm.config.mode.normal": "Normal", + "gui.minegasm.config.mode.masochist": "Masochist", + "gui.minegasm.config.mode.hedonist": "Hedonist", + "gui.minegasm.config.mode.custom": "Custom", + "gui.minegasm.config.intensity.attack": "Attack", + "gui.minegasm.config.intensity.hurt": "Hurt", + "gui.minegasm.config.intensity.mine": "Mine", + "gui.minegasm.config.intensity.xp": "XP", + "gui.minegasm.config.intensity.harvest": "Harvest", + "gui.minegasm.config.intensity.vitality": "Vitality" } diff --git a/forge/fg-6.0/1.15.2/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.15.2/src/main/resources/mixins.minegasm.json index 755c291..d14e4fd 100644 --- a/forge/fg-6.0/1.15.2/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.15.2/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "PlayerControllerMixin", + "ClientAdvancementManagerMixin", "ClientPlayerEntityMixin", - "ClientAdvancementManagerMixin" + "PlayerControllerMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.15.2/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.15.2/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.15.2/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.15.2/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/build.gradle b/forge/fg-6.0/1.16.5/build.gradle index dc035f1..d83f93d 100644 --- a/forge/fg-6.0/1.16.5/build.gradle +++ b/forge/fg-6.0/1.16.5/build.gradle @@ -162,13 +162,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -221,4 +221,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/gradle.properties b/forge/fg-6.0/1.16.5/gradle.properties index aa62cb1..f85480e 100644 --- a/forge/fg-6.0/1.16.5/gradle.properties +++ b/forge/fg-6.0/1.16.5/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.16.5 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index 914ae7c..cec51c2 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,35 +1,25 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; - import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.EntityLeaveWorldEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { @@ -39,7 +29,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -49,56 +39,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof PlayerEntity && !(entity instanceof FakePlayer)) { - PlayerEntity player = (PlayerEntity) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof PlayerEntity && !(entity instanceof FakePlayer)) { + PlayerEntity player = (PlayerEntity) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -112,26 +96,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - PlayerEntity player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + PlayerEntity player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -160,96 +144,79 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((PlayerEntity)event.getEntityLiving()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((PlayerEntity) event.getEntityLiving()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } @@ -277,35 +244,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof PlayerEntity) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - PlayerEntity player = (PlayerEntity) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(new StringTextComponent(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + PlayerEntity player = (PlayerEntity) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(new StringTextComponent(String.format("Connected to " + TextFormatting.GREEN + "%s" + TextFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(new StringTextComponent(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(new StringTextComponent(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 8e264a0..04f2b48 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -115,18 +86,44 @@ public static int getIntensity(String type) { int returnValue = -1; - - switch (MinegasmConfig.mode) - { - case NORMAL: returnValue = normal.get(type); - case MASOCHIST: returnValue = masochist.get(type); - case HEDONIST: returnValue = hedonist.get(type); - case ACCUMULATION: returnValue = accumulation.get(type); - case CUSTOM: returnValue = custom.get(type); - }; - + + switch (MinegasmConfig.mode) { + case NORMAL: + returnValue = normal.get(type); + case MASOCHIST: + returnValue = masochist.get(type); + case HEDONIST: + returnValue = hedonist.get(type); + case ACCUMULATION: + returnValue = accumulation.get(type); + case CUSTOM: + returnValue = custom.get(type); + } + ; + return returnValue; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index dc7646a..214e8a5 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -16,8 +16,7 @@ import org.apache.logging.log4j.Logger; @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -36,8 +35,7 @@ public Minegasm() { context.registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (mc, screen) -> new ConfigScreen(screen)); } - private void setupCommon(final FMLCommonSetupEvent event) - { + private void setupCommon(final FMLCommonSetupEvent event) { LOGGER.info("Common setup..."); } diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 09d478d..4b571b1 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,49 +1,45 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEvent event) - { + + public void onAdvancement(AdvancementEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - if (advancement == null) return; - FrameType type = advancement.getDisplay().getFrame(); - int duration = 0; - - switch (type) { - case TASK: - duration = 5; - break; - case GOAL: - duration = 7; - break; - case CHALLENGE: - duration = 10; - break; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + if (advancement == null) return; + FrameType type = advancement.getDisplay().getFrame(); + int duration = 0; + + switch (type) { + case TASK: + duration = 5; + break; + case GOAL: + duration = 7; + break; + case CHALLENGE: + duration = 10; + break; + } + ; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index ccff7d1..a715d2c 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.vector.Vector3d; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(PlayerEntity player) - { - if (player.fishing != null) - { + + public void onTick(PlayerEntity player) { + if (player.fishing != null) { Vector3d vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index a7254ab..a4ed4a5 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,30 +1,24 @@ package com.therainbowville.minegasm.common; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index 477f80b..7cb8710 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.block.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.block.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 20c13d9..ba95d54 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.entity.player.PlayerEntity; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.entity.player.PlayerEntity; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(PlayerEntity player) - { + + public void onTick(PlayerEntity player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(PlayerEntity player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index bbd310c..06408b0 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -154,45 +144,37 @@ public enum GameplayMode { public String getTranslateKey() { return this.translateKey; } - - public GameplayMode next() - { + + public GameplayMode next() { boolean foundCurrent = false; - for (GameplayMode type : values()) - { + for (GameplayMode type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } - + } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -200,19 +182,21 @@ public static TickFrequencyOptions fromInt(int value) } return null; } - - public TickFrequencyOptions next() - { + + public int getInt() { + return value; + } + + public TickFrequencyOptions next() { boolean foundCurrent = false; - for (TickFrequencyOptions type : values()) - { + for (TickFrequencyOptions type : values()) { if (foundCurrent) return type; - else if (this == type) + else if (this == type) foundCurrent = true; } return values()[0]; } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index c647c9f..38353d0 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -16,7 +16,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -30,30 +30,28 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index b422dfa..543991f 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index 584702d..2f4e9bd 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,43 +1,29 @@ package com.therainbowville.minegasm.config; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.DialogTexts; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.IngameMenuScreen; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.gui.DialogTexts; -import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.StringTextComponent; - -import net.minecraftforge.fml.client.gui.widget.ExtendedButton; -import net.minecraftforge.eventbus.api.SubscribeEvent; - +import net.minecraft.util.text.TextFormatting; import net.minecraftforge.client.gui.widget.ForgeSlider; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - +import net.minecraftforge.fml.client.gui.widget.ExtendedButton; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.Objects; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; TextFieldWidget wsHost = null; - + private boolean pauseMenu; private ClientConfig.TickFrequencyOptions tickValue; private PlainTextLabel connectResponse; @@ -47,7 +33,7 @@ public ConfigScreen(Screen previous) { pauseMenu = false; tickValue = ClientConfig.TickFrequencyOptions.fromInt(MinegasmConfig.tickFrequency); } - + public ConfigScreen(Screen previous, boolean pause) { super(new StringTextComponent("Minegasm Config")); this.previous = previous; @@ -60,31 +46,31 @@ protected void init() { wsHost = new TextFieldWidget(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addButton(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addButton(new ExtendedButton( - this.width / 2 - 155, this.height / 6 + 25, 150, 20, - new StringTextComponent("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - } + this.width / 2 - 155, this.height / 6 + 25, 150, 20, + new StringTextComponent("Reset Server Url"), button -> { + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + } )); - + connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, new StringTextComponent("" + TextFormatting.GREEN)); this.addButton(connectResponse); - + Button reconnectButton = new ExtendedButton( - this.width / 2 + 5, this.height / 6 + 25, 150, 20, - new StringTextComponent("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + this.width / 2 + 5, this.height / 6 + 25, 150, 20, + new StringTextComponent("Reconnect"), button -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -93,77 +79,89 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(TextFormatting.YELLOW + "Minegasm " + TextFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - } + + }).start(); + } ); this.addButton(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addButton(new ExtendedButton(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - new StringTextComponent("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { - MinegasmConfig.vibrate = !MinegasmConfig.vibrate; - button.setMessage(new StringTextComponent("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); - })); + new StringTextComponent("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False")), (button) -> { + MinegasmConfig.vibrate = !MinegasmConfig.vibrate; + button.setMessage(new StringTextComponent("Vibration: " + (MinegasmConfig.vibrate ? "True" : "False"))); + })); this.addButton(new ExtendedButton(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - new StringTextComponent("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { - MinegasmConfig.stealth = !MinegasmConfig.stealth; - button.setMessage(new StringTextComponent("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); - })); + new StringTextComponent("Stealth: " + (MinegasmConfig.stealth ? "True" : "False")), (button) -> { + MinegasmConfig.stealth = !MinegasmConfig.stealth; + button.setMessage(new StringTextComponent("Stealth: " + (MinegasmConfig.stealth ? "True" : "False"))); + })); this.addButton(new ExtendedButton(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - new StringTextComponent("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { - MinegasmConfig.mode = MinegasmConfig.mode.next(); - button.setMessage(new StringTextComponent("Mode: " + gameplayModeToString(MinegasmConfig.mode))); - } + new StringTextComponent("Mode: " + gameplayModeToString(MinegasmConfig.mode)), (button) -> { + MinegasmConfig.mode = MinegasmConfig.mode.next(); + button.setMessage(new StringTextComponent("Mode: " + gameplayModeToString(MinegasmConfig.mode))); + } )); this.addButton(new ExtendedButton( - this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, - new StringTextComponent("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, + new StringTextComponent("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); this.addButton(new ExtendedButton(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - new StringTextComponent("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency)), (button) -> { - tickValue = tickValue.next(); - MinegasmConfig.tickFrequency = tickValue.getInt(); - MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - button.setMessage(new StringTextComponent("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency))); - } + new StringTextComponent("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency)), (button) -> { + tickValue = tickValue.next(); + MinegasmConfig.tickFrequency = tickValue.getInt(); + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); + button.setMessage(new StringTextComponent("Tick Frequency: " + tickFrequencyToString(MinegasmConfig.tickFrequency))); + } ) ); this.addButton(new ExtendedButton( - this.width / 2 - 100, this.height - 27, 200, 20, - DialogTexts.GUI_DONE, button -> this.onClose())); - + this.width / 2 - 100, this.height - 27, 200, 20, + DialogTexts.GUI_DONE, button -> this.onClose())); + } - - private String gameplayModeToString(ClientConfig.GameplayMode mode){ + + private String gameplayModeToString(ClientConfig.GameplayMode mode) { switch (mode) { - case NORMAL: return "Normal"; - case MASOCHIST: return "Masochist"; - case HEDONIST: return "Hedonist"; - case ACCUMULATION: return "Accumulation"; - case CUSTOM: return "Custom"; - default: return ""; + case NORMAL: + return "Normal"; + case MASOCHIST: + return "Masochist"; + case HEDONIST: + return "Hedonist"; + case ACCUMULATION: + return "Accumulation"; + case CUSTOM: + return "Custom"; + default: + return ""; } } - private String tickFrequencyToString(Integer frequency){ + private String tickFrequencyToString(Integer frequency) { switch (frequency) { - case 1: return "Every Tick"; - case 2: return "Every Other Tick"; - case 5: return "Every 5 Ticks"; - case 10: return "Every 10 Ticks"; - case 20: return "Every Second"; - default: return "Every " + Float.toString(frequency / 20f)+ " Seconds"; + case 1: + return "Every Tick"; + case 2: + return "Every Other Tick"; + case 5: + return "Every 5 Ticks"; + case 10: + return "Every 10 Ticks"; + case 20: + return "Every Second"; + default: + return "Every " + Float.toString(frequency / 20f) + " Seconds"; } } - + @Override public void tick() { super.tick(); @@ -189,9 +187,9 @@ public void render(MatrixStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - + class PlainTextLabel extends Widget { - + private StringTextComponent text = new StringTextComponent(""); private int x; private int y; @@ -202,8 +200,7 @@ public PlainTextLabel(int x, int y, int width, int height, StringTextComponent t this.y = y; } - public void setValue(String value) - { + public void setValue(String value) { text = new StringTextComponent(value); } @@ -215,7 +212,7 @@ public void render(MatrixStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -228,7 +225,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(new StringTextComponent("Minegasm Custom Config")); this.previous = previous; @@ -237,49 +234,49 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addButton(new ExtendedButton( - this.width / 2 + 5, this.height - 27, 150, 20, - DialogTexts.GUI_DONE, button -> this.onClose())); + try { + this.addButton(new ExtendedButton( + this.width / 2 + 5, this.height - 27, 150, 20, + DialogTexts.GUI_DONE, button -> this.onClose())); - IntensitiySliderBar.sliders.clear(); + IntensitiySliderBar.sliders.clear(); - // Attack - this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addButton(new ExtendedButton( - this.width / 2 - 155, this.height - 27, 150, 20, - new StringTextComponent("Reset Values"), button -> { + // Attack + this.addButton(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addButton(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addButton(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addButton(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addButton(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addButton(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addButton(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addButton(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addButton(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addButton(new ExtendedButton( + this.width / 2 - 155, this.height - 27, 150, 20, + new StringTextComponent("Reset Values"), button -> { ConfigHolder.getClientInstance().resetConfigCustom(); IntensitiySliderBar.refreshAllValues(); } - )); - - + )); + + } catch (Throwable e) { LOGGER.throwing(e); } @@ -302,27 +299,30 @@ public void render(MatrixStack poseStack, int i, int j, float f) { } } -class IntensitiySliderBar extends ForgeSlider -{ +class IntensitiySliderBar extends ForgeSlider { private static final Logger LOGGER = LogManager.getLogger(); public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - new StringTextComponent(prefix), // Prefix - new StringTextComponent(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + new StringTextComponent(prefix), // Prefix + new StringTextComponent(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { try { fieldReference.set(null, this.getValueInt()); } catch (Throwable e) { @@ -330,16 +330,7 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index 79b2dd9..48a0aea 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -21,7 +21,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static int ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -47,23 +47,21 @@ public static void onModConfigEvent(final ModConfig.ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -73,15 +71,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 7680039..d53b0d2 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,89 +1,83 @@ package com.therainbowville.minegasm.config; import com.mojang.blaze3d.matrix.MatrixStack; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; -import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.StringTextComponent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - - public PauseMenuButton(int x, int y) { - super(x, y, 20, 20, new StringTextComponent(""), PauseMenuButton::clicked); + + public PauseMenuButton(int x, int y) { + super(x, y, 20, 20, new StringTextComponent(""), PauseMenuButton::clicked); xPos = x; yPos = y; - } - - @Override - public void renderBg(MatrixStack mstack, Minecraft mc, int mouseX, int mouseY) { - mstack.pushPose(); - mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); - mstack.scale(0.25f, 0.25f, 1); - Minecraft.getInstance().getTextureManager().bind(LOGO); - AbstractGui.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); - mstack.popPose(); - } - - public static void clicked(Button button) - { + } + + public static void clicked(Button button) { Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); } - + + @Override + public void renderBg(MatrixStack mstack, Minecraft mc, int mouseX, int mouseY) { + mstack.pushPose(); + mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + mstack.scale(0.25f, 0.25f, 1); + Minecraft.getInstance().getTextureManager().bind(LOGO); + AbstractGui.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); + mstack.popPose(); + } + public static class SingleMenuRow { - public final String left, right; - public SingleMenuRow(String left, String right) { - this.left = I18n.get(left); - this.right = I18n.get(right); - } - public SingleMenuRow(String center) { - this(center, center); - } - } - - public static class MenuRows { - public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") - )); + public final String left, right; + + public SingleMenuRow(String left, String right) { + this.left = I18n.get(left); + this.right = I18n.get(right); + } + + public SingleMenuRow(String center) { + this(center, center); + } + } + + public static class MenuRows { + public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + )); - public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") - )); + public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") + )); - protected final List leftButtons, rightButtons; + protected final List leftButtons, rightButtons; - public MenuRows(List variants) { - leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); - rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); - } - } + public MenuRows(List variants) { + leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); + rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); + } + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java index 3a5fab4..a4cbe5d 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/config/PauseMenuButtonScreen.java @@ -1,27 +1,23 @@ package com.therainbowville.minegasm.config; +import com.therainbowville.minegasm.common.Minegasm; +import net.minecraft.client.gui.screen.IngameMenuScreen; +import net.minecraft.client.gui.widget.Widget; import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; - -import net.minecraft.client.gui.widget.Widget; -import net.minecraft.client.gui.screen.IngameMenuScreen; - +import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.mutable.MutableObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.common.Minegasm; - @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { private static final Logger LOGGER = LogManager.getLogger(); - + @SubscribeEvent public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { - if(event.getGui() instanceof IngameMenuScreen) { // Make sure GUI is Escape menu + if (event.getGui() instanceof IngameMenuScreen) { // Make sure GUI is Escape menu PauseMenuButton.MenuRows menu = PauseMenuButton.MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -32,15 +28,15 @@ public static void onGuiInit(GuiScreenEvent.InitGuiEvent event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getWidgetList() - .stream() - .filter(w -> w instanceof Widget) - .map(w -> (Widget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); + .stream() + .filter(w -> w instanceof Widget) + .map(w -> (Widget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); if (toAdd.getValue() != null) event.addWidget(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java index e9c8dc7..bfb23b7 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementManagerMixin.java @@ -1,6 +1,6 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; @@ -8,7 +8,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.play.server.SAdvancementInfoPacket; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.AdvancementEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancementManager.class) public class ClientAdvancementManagerMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(SAdvancementInfoPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { Advancement advancement = ((ClientAdvancementManager) (Object) this).getAdvancements().get(entry.getKey()); PlayerEntity player = minecraft.player; AdvancementEvent event = new AdvancementEvent(player, advancement); diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java index 5be1051..7ba526b 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/ClientPlayerEntityMixin.java @@ -1,18 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.LivingEntity; - +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.DamageSource; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -35,8 +30,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LivingEntity) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -45,8 +42,10 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) { XpChange event = new XpChange((PlayerEntity) (Object) this, amount); diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java index 02d69a1..71a1584 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/mixin/PlayerControllerMixin.java @@ -1,63 +1,61 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraft.client.multiplayer.PlayerController; -import net.minecraftforge.event.world.BlockEvent.BreakEvent; -import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.multiplayer.PlayerController; import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.ActionResultType; - +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; - +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerController.class) public class PlayerControllerMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + PlayerEntity player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level, blockPos, player.level.getBlockState(blockPos), player); ClientEventHandler.onBreak(event); } } - + @Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;useOn(Lnet/minecraft/item/ItemUseContext;)Lnet/minecraft/util/ActionResultType;", shift = At.Shift.AFTER), cancellable = true) public void onUseItemOn(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockRayTraceResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } } - + @Inject(method = "useItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockRayTraceResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == ActionResultType.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java index 51cc125..fb2e7dd 100644 --- a/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java +++ b/forge/fg-6.0/1.16.5/src/main/java/com/therainbowville/minegasm/widgets/ForgeSlider.java @@ -6,8 +6,8 @@ package net.minecraftforge.client.gui.widget; import net.minecraft.client.gui.widget.AbstractSlider; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.StringTextComponent; import org.lwjgl.glfw.GLFW; import java.text.DecimalFormat; @@ -15,37 +15,33 @@ /** * Slider widget implementation which allows inputting values in a certain range with optional step size. */ -public class ForgeSlider extends AbstractSlider -{ +public class ForgeSlider extends AbstractSlider { + private final DecimalFormat format; protected StringTextComponent prefix; protected StringTextComponent suffix; - protected double minValue; protected double maxValue; - - /** Allows input of discontinuous values with a certain step */ + /** + * Allows input of discontinuous values with a certain step + */ protected double stepSize; - protected boolean drawString; - private final DecimalFormat format; - /** - * @param x x position of upper left corner - * @param y y position of upper left corner - * @param width Width of the widget - * @param height Height of the widget - * @param prefix {@link StringTextComponent} displayed before the value string - * @param suffix {@link StringTextComponent} displayed after the value string - * @param minValue Minimum (left) value of slider - * @param maxValue Maximum (right) value of slider + * @param x x position of upper left corner + * @param y y position of upper left corner + * @param width Width of the widget + * @param height Height of the widget + * @param prefix {@link StringTextComponent} displayed before the value string + * @param suffix {@link StringTextComponent} displayed after the value string + * @param minValue Minimum (left) value of slider + * @param maxValue Maximum (right) value of slider * @param currentValue Starting value when widget is first displayed - * @param stepSize Size of step used. Precision will automatically be calculated based on this value if this value is not 0. - * @param precision Only used when {@code stepSize} is 0. Limited to a maximum of 4 (inclusive). - * @param drawString Should text be displayed on the widget + * @param stepSize Size of step used. Precision will automatically be calculated based on this value if this value is not 0. + * @param precision Only used when {@code stepSize} is 0. Limited to a maximum of 4 (inclusive). + * @param drawString Should text be displayed on the widget */ - public ForgeSlider(int x, int y, int width, int height, StringTextComponent prefix, StringTextComponent suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) - { + public ForgeSlider(int x, int y, int width, int height, StringTextComponent prefix, StringTextComponent suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) { super(x, y, width, height, StringTextComponent.EMPTY, 0D); this.prefix = prefix; this.suffix = suffix; @@ -55,8 +51,7 @@ public ForgeSlider(int x, int y, int width, int height, StringTextComponent pref this.value = this.snapToNearest((currentValue - minValue) / (maxValue - minValue)); this.drawString = drawString; - if (stepSize == 0D) - { + if (stepSize == 0D) { precision = Math.min(precision, 4); StringBuilder builder = new StringBuilder("0"); @@ -68,13 +63,9 @@ public ForgeSlider(int x, int y, int width, int height, StringTextComponent pref builder.append('0'); this.format = new DecimalFormat(builder.toString()); - } - else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) - { + } else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) { this.format = new DecimalFormat("0"); - } - else - { + } else { this.format = new DecimalFormat(Double.toString(this.stepSize).replaceAll("\\d", "0")); } @@ -84,68 +75,58 @@ else if (MathHelper.equal(this.stepSize, Math.floor(this.stepSize))) /** * Overload with {@code stepSize} set to 1, useful for sliders with whole number values. */ - public ForgeSlider(int x, int y, int width, int height, StringTextComponent prefix, StringTextComponent suffix, double minValue, double maxValue, double currentValue, boolean drawString) - { + public ForgeSlider(int x, int y, int width, int height, StringTextComponent prefix, StringTextComponent suffix, double minValue, double maxValue, double currentValue, boolean drawString) { this(x, y, width, height, prefix, suffix, minValue, maxValue, currentValue, 1D, 0, drawString); } /** * @return Current slider value as a double */ - public double getValue() - { + public double getValue() { return this.value * (maxValue - minValue) + minValue; } /** - * @return Current slider value as an long + * @param value The new slider value */ - public long getValueLong() - { - return Math.round(this.getValue()); + public void setValue(double value) { + this.value = this.snapToNearest((value - this.minValue) / (this.maxValue - this.minValue)); + this.updateMessage(); } /** - * @return Current slider value as an int + * @return Current slider value as an long */ - public int getValueInt() - { - return (int) this.getValueLong(); + public long getValueLong() { + return Math.round(this.getValue()); } /** - * @param value The new slider value + * @return Current slider value as an int */ - public void setValue(double value) - { - this.value = this.snapToNearest((value - this.minValue) / (this.maxValue - this.minValue)); - this.updateMessage(); + public int getValueInt() { + return (int) this.getValueLong(); } - public String getValueString() - { + public String getValueString() { return this.format.format(this.getValue()); } @Override - public void onClick(double mouseX, double mouseY) - { + public void onClick(double mouseX, double mouseY) { this.setValueFromMouse(mouseX); } @Override - protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) - { + protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) { super.onDrag(mouseX, mouseY, dragX, dragY); this.setValueFromMouse(mouseX); } @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) - { + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { boolean flag = keyCode == GLFW.GLFW_KEY_LEFT; - if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) - { + if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) { if (this.minValue > this.maxValue) flag = !flag; float f = flag ? -1F : 1F; @@ -158,16 +139,14 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) return false; } - private void setValueFromMouse(double mouseX) - { + private void setValueFromMouse(double mouseX) { this.setSliderValue((mouseX - (this.x + 4)) / (this.width - 8)); } /** * @param value Percentage of slider range */ - private void setSliderValue(double value) - { + private void setSliderValue(double value) { double oldValue = this.value; this.value = this.snapToNearest(value); if (!MathHelper.equal(oldValue, this.value)) @@ -180,41 +159,34 @@ private void setSliderValue(double value) * Snaps the value, so that the displayed value is the nearest multiple of {@code stepSize}. * If {@code stepSize} is 0, no snapping occurs. */ - private double snapToNearest(double value) - { - if(stepSize <= 0D) + private double snapToNearest(double value) { + if (stepSize <= 0D) return MathHelper.clamp(value, 0D, 1D); value = MathHelper.lerp(MathHelper.clamp(value, 0D, 1D), this.minValue, this.maxValue); value = (stepSize * Math.round(value / stepSize)); - if (this.minValue > this.maxValue) - { + if (this.minValue > this.maxValue) { value = MathHelper.clamp(value, this.maxValue, this.minValue); - } - else - { + } else { value = MathHelper.clamp(value, this.minValue, this.maxValue); } - return (value-this.minValue)/(this.maxValue-this.minValue) * (1D-0D) + 0D; + return (value - this.minValue) / (this.maxValue - this.minValue) * (1D - 0D) + 0D; // return MathHelper.map(value, this.minValue, this.maxValue, 0D, 1D); } @Override - protected void updateMessage() - { - if (this.drawString) - { + protected void updateMessage() { + if (this.drawString) { this.setMessage(new StringTextComponent("").append(prefix).append(this.getValueString()).append(suffix)); - } - else - { + } else { this.setMessage(StringTextComponent.EMPTY); } } @Override - protected void applyValue() {} + protected void applyValue() { + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.16.5/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.16.5/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.16.5/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.16.5/src/main/resources/assets/minegasm/lang/en_us.json b/forge/fg-6.0/1.16.5/src/main/resources/assets/minegasm/lang/en_us.json index f5f5b24..fa5f32b 100644 --- a/forge/fg-6.0/1.16.5/src/main/resources/assets/minegasm/lang/en_us.json +++ b/forge/fg-6.0/1.16.5/src/main/resources/assets/minegasm/lang/en_us.json @@ -1,16 +1,14 @@ { - "gui.minegasm.config.vibrate": "Vibrate", - - "gui.minegasm.config.mode": "Mode", - "gui.minegasm.config.mode.normal": "Normal", - "gui.minegasm.config.mode.masochist": "Masochist", - "gui.minegasm.config.mode.hedonist": "Hedonist", - "gui.minegasm.config.mode.custom": "Custom", - - "gui.minegasm.config.intensity.attack": "Attack", - "gui.minegasm.config.intensity.hurt": "Hurt", - "gui.minegasm.config.intensity.mine": "Mine", - "gui.minegasm.config.intensity.xp": "XP", - "gui.minegasm.config.intensity.harvest": "Harvest", - "gui.minegasm.config.intensity.vitality": "Vitality" + "gui.minegasm.config.vibrate": "Vibrate", + "gui.minegasm.config.mode": "Mode", + "gui.minegasm.config.mode.normal": "Normal", + "gui.minegasm.config.mode.masochist": "Masochist", + "gui.minegasm.config.mode.hedonist": "Hedonist", + "gui.minegasm.config.mode.custom": "Custom", + "gui.minegasm.config.intensity.attack": "Attack", + "gui.minegasm.config.intensity.hurt": "Hurt", + "gui.minegasm.config.intensity.mine": "Mine", + "gui.minegasm.config.intensity.xp": "XP", + "gui.minegasm.config.intensity.harvest": "Harvest", + "gui.minegasm.config.intensity.vitality": "Vitality" } diff --git a/forge/fg-6.0/1.16.5/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.16.5/src/main/resources/mixins.minegasm.json index 755c291..d14e4fd 100644 --- a/forge/fg-6.0/1.16.5/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.16.5/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "PlayerControllerMixin", + "ClientAdvancementManagerMixin", "ClientPlayerEntityMixin", - "ClientAdvancementManagerMixin" + "PlayerControllerMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.16.5/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.16.5/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.16.5/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.16.5/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/build.gradle b/forge/fg-6.0/1.18.2/build.gradle index 72dd3c8..41da947 100644 --- a/forge/fg-6.0/1.18.2/build.gradle +++ b/forge/fg-6.0/1.18.2/build.gradle @@ -163,13 +163,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -222,4 +222,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/gradle.properties b/forge/fg-6.0/1.18.2/gradle.properties index 1ca7263..472fc66 100644 --- a/forge/fg-6.0/1.18.2/gradle.properties +++ b/forge/fg-6.0/1.18.2/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.18.2 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index b08f1be..df81e51 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,39 +1,27 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.TextComponent; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.network.chat.TextComponent; -import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.EntityLeaveWorldEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { @@ -43,7 +31,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -53,56 +41,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof Player && !(entity instanceof FakePlayer)) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof Player && !(entity instanceof FakePlayer)) { + Player player = (Player) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -116,26 +98,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - Player player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + Player player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -164,96 +146,79 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntityLiving()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((Player) event.getEntityLiving()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent event) - { - if (isPlayer(event.getEntityLiving())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent event) { + if (isPlayer(event.getEntityLiving())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } @@ -288,35 +253,37 @@ public static void onWorldLoaded(WorldEvent.Load event) { @SubscribeEvent public static void onWorldEntry(EntityJoinWorldEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - Player player = (Player) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(new TextComponent(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + Player player = (Player) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(new TextComponent(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(new TextComponent(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(new TextComponent(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index e88aad1..41f0895 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,8 +85,7 @@ public static int getIntensity(String type) { custom.put("advancement", MinegasmConfig.advancementIntensity); - return switch (MinegasmConfig.mode) - { + return switch (MinegasmConfig.mode) { case NORMAL -> normal.get(type); case MASOCHIST -> masochist.get(type); case HEDONIST -> hedonist.get(type); @@ -123,6 +93,27 @@ public static int getIntensity(String type) { case CUSTOM -> custom.get(type); }; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index a0f7955..e5cf29c 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -1,19 +1,17 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.ConfigHelper; +import com.therainbowville.minegasm.config.ConfigHolder; +import net.minecraftforge.client.ConfigGuiHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.client.ConfigGuiHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.config.ConfigHolder; -import com.therainbowville.minegasm.config.ConfigHelper; - @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -24,7 +22,7 @@ public Minegasm() { context.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC); MinecraftForge.EVENT_BUS.register(this); - + ModLoadingContext.get().registerExtensionPoint(ConfigGuiHandler.ConfigGuiFactory.class, ConfigHelper::createConfigGuiFactory); } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index e716f67..4fb9afd 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,41 +1,36 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEvent event) - { + + public void onAdvancement(AdvancementEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - if (advancement == null) return; - FrameType type = advancement.getDisplay().getFrame(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + if (advancement == null) return; + FrameType type = advancement.getDisplay().getFrame(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index 99f8e03..5a6dd99 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index a1ab209..bb67298 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(Player player) - { - if (player.fishing != null) - { + + public void onTick(Player player) { + if (player.fishing != null) { Vec3 vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 47bfe38..b1b5f78 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,32 +1,24 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index f2e1798..e4b0cdc 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index a69f846..c589034 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.level.block.state.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index 06ef6d8..e645db2 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index e40998b..d516850 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.entity.player.Player; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.entity.player.Player; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(Player player) - { + + public void onTick(Player player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(Player player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index f61d685..58f63af 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index c3ca8ff..d68ff8b 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -155,30 +145,24 @@ public String getTranslateKey() { return this.translateKey; } } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -186,6 +170,10 @@ public static TickFrequencyOptions fromInt(int value) } return null; } + + public int getInt() { + return value; + } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index c7ba222..d6d2024 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -1,8 +1,6 @@ package com.therainbowville.minegasm.config; import net.minecraftforge.client.ConfigGuiHandler; -import net.minecraftforge.common.ForgeConfigSpec; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,7 +14,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -30,30 +28,28 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index b422dfa..543991f 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index d4fb3a9..e1629a1 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,49 +1,37 @@ package com.therainbowville.minegasm.config; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraftforge.client.gui.widget.ForgeSlider; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.Component; -import net.minecraftforge.event.TickEvent; -import net.minecraft.client.Minecraft; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraftforge.client.gui.widget.ForgeSlider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.function.IntConsumer; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; EditBox wsHost = null; + private boolean pauseMenu; public ConfigScreen(Screen previous) { super(new TextComponent("Minegasm Config")); this.previous = previous; pauseMenu = false; } - + public ConfigScreen(Screen previous, boolean pause) { super(new TextComponent("Minegasm Config")); this.previous = previous; @@ -55,31 +43,31 @@ protected void init() { wsHost = new EditBox(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addRenderableWidget(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addRenderableWidget(new Button( - this.width / 2 - 155, this.height / 6 + 25, 150, 20, - new TextComponent("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - } + this.width / 2 - 155, this.height / 6 + 25, 150, 20, + new TextComponent("Reset Server Url"), button -> { + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + } )); - + PlainTextLabel connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, new TextComponent("" + ChatFormatting.GREEN)); this.addRenderableWidget(connectResponse); - + Button reconnectButton = new Button( - this.width / 2 + 5, this.height / 6 + 25, 150, 20, - new TextComponent("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + this.width / 2 + 5, this.height / 6 + 25, 150, 20, + new TextComponent("Reconnect"), button -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -88,71 +76,71 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - } + + }).start(); + } ); this.addRenderableWidget(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.vibrate) - .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - new TextComponent("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); + .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, + new TextComponent("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.stealth) - .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - new TextComponent("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); + .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, + new TextComponent("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); this.addRenderableWidget( - CycleButton.builder((ClientConfig.GameplayMode mode) -> - new TextComponent(switch (mode) { - case NORMAL -> "Normal"; - case MASOCHIST -> "Masochist"; - case HEDONIST -> "Hedonist"; - case ACCUMULATION -> "Accumulation"; - case CUSTOM -> "Custom"; - })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) - .withInitialValue(MinegasmConfig.mode) - .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - new TextComponent("Mode"), (button, value) -> { - MinegasmConfig.mode = value; - }) + CycleButton.builder((ClientConfig.GameplayMode mode) -> + new TextComponent(switch (mode) { + case NORMAL -> "Normal"; + case MASOCHIST -> "Masochist"; + case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; + case CUSTOM -> "Custom"; + })) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) + .withInitialValue(MinegasmConfig.mode) + .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, + new TextComponent("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); this.addRenderableWidget(new Button( - this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, - new TextComponent("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, + new TextComponent("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); this.addRenderableWidget( - CycleButton.builder((Integer tickFrequency) -> - new TextComponent(switch (tickFrequency) { - case 1 -> "Every Tick"; - case 2 -> "Every Other Tick"; - case 5 -> "Every 5 Ticks"; - case 10 -> "Every 10 Ticks"; - case 20 -> "Every Second"; - default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; - })) - .withValues(1, 2, 5, 10, 20, 30, 40, 50) - .withInitialValue(MinegasmConfig.tickFrequency) - .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - new TextComponent("Tick Frequency"), (button, value) -> { - MinegasmConfig.tickFrequency = value; - MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); - LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); - } - ) + CycleButton.builder((Integer tickFrequency) -> + new TextComponent(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f) + " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + new TextComponent("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(1, Math.toIntExact(20 / MinegasmConfig.tickFrequency)); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) ); this.addRenderableWidget(new Button( - this.width / 2 - 100, this.height - 27, 200, 20, - CommonComponents.GUI_DONE, button -> this.onClose())); - + this.width / 2 - 100, this.height - 27, 200, 20, + CommonComponents.GUI_DONE, button -> this.onClose())); + } - + @Override public void tick() { super.tick(); @@ -178,9 +166,9 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - + class PlainTextLabel extends AbstractWidget { - + private static TextComponent text = new TextComponent(""); private int x; private int y; @@ -191,11 +179,10 @@ public PlainTextLabel(int x, int y, int width, int height, TextComponent text) { this.y = y; } - public static void setValue(String value) - { + public static void setValue(String value) { text = new TextComponent(value); } - + @Override public void updateNarration(NarrationElementOutput output) { defaultButtonNarrationText(output); @@ -205,13 +192,13 @@ public void updateNarration(NarrationElementOutput output) { public void render(PoseStack poseStack, int i, int j, float f) { if (text == null || text.getString().isEmpty()) return; - + // RenderSystem.setShaderColor(1, 1, 1, 1); // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -224,7 +211,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(new TextComponent("Minegasm Custom Config")); this.previous = previous; @@ -233,49 +220,49 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addRenderableWidget(new Button( - this.width / 2 + 5, this.height - 27, 150, 20, - CommonComponents.GUI_DONE, button -> this.onClose())); + try { + this.addRenderableWidget(new Button( + this.width / 2 + 5, this.height - 27, 150, 20, + CommonComponents.GUI_DONE, button -> this.onClose())); - IntensitiySliderBar.sliders.clear(); + IntensitiySliderBar.sliders.clear(); - // Attack - this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addRenderableWidget(new Button( - this.width / 2 - 155, this.height - 27, 150, 20, - new TextComponent("Reset Values"), button -> { + // Attack + this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addRenderableWidget(new Button( + this.width / 2 - 155, this.height - 27, 150, 20, + new TextComponent("Reset Values"), button -> { ConfigHolder.getClientInstance().resetConfigCustom(); IntensitiySliderBar.refreshAllValues(); } - )); - - + )); + + } catch (Throwable e) { LOGGER.throwing(e); } @@ -296,28 +283,31 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - - private class IntensitiySliderBar extends ForgeSlider - { + + private class IntensitiySliderBar extends ForgeSlider { public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - new TextComponent(prefix), // Prefix - new TextComponent(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + new TextComponent(prefix), // Prefix + new TextComponent(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; // LOGGER.info("S: " + sliders.size() + " X: " + parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155) + " Y: " + parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2)); sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { // LOGGER.info("applyValue"); //responder.accept(this.getValueInt()); try { @@ -327,22 +317,13 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { LOGGER.throwing(e); } } - + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index b1a115a..7eccb05 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -22,7 +22,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static int ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -48,23 +48,21 @@ public static void onModConfigEvent(final ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -74,15 +72,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 23255ae..a2c9dbd 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,110 +1,99 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.PauseScreen; import net.minecraft.client.resources.language.I18n; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; - -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.commons.lang3.mutable.MutableObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.apache.commons.lang3.mutable.MutableObject; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - - public PauseMenuButton(int x, int y) { - super(x, y, 20, 20, new TextComponent(""), PauseMenuButton::clicked); + + public PauseMenuButton(int x, int y) { + super(x, y, 20, 20, new TextComponent(""), PauseMenuButton::clicked); xPos = x; yPos = y; - } - - @Override - public void renderBg(PoseStack mstack, Minecraft mc, int mouseX, int mouseY) { - mstack.pushPose(); - mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); - mstack.scale(0.25f, 0.25f, 1); - RenderSystem.setShaderTexture(0, LOGO); - GuiComponent.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); - mstack.popPose(); - } - - public static void clicked(Button button) - { + } + + public static void clicked(Button button) { Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); } - + + @Override + public void renderBg(PoseStack mstack, Minecraft mc, int mouseX, int mouseY) { + mstack.pushPose(); + mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + mstack.scale(0.25f, 0.25f, 1); + RenderSystem.setShaderTexture(0, LOGO); + GuiComponent.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); + mstack.popPose(); + } + public static class SingleMenuRow { - public final String left, right; - public SingleMenuRow(String left, String right) { - this.left = I18n.get(left); - this.right = I18n.get(right); - } - public SingleMenuRow(String center) { - this(center, center); - } - } - - public static class MenuRows { - public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") - )); - - public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") - )); - - protected final List leftButtons, rightButtons; - - public MenuRows(List variants) { - leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); - rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); - } - } - + public final String left, right; + + public SingleMenuRow(String left, String right) { + this.left = I18n.get(left); + this.right = I18n.get(right); + } + + public SingleMenuRow(String center) { + this(center, center); + } + } + + public static class MenuRows { + public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + )); + + public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") + )); + + protected final List leftButtons, rightButtons; + + public MenuRows(List variants) { + leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); + rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); + } + } + @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { - + @SubscribeEvent public static void onGuiInit(ScreenEvent.InitScreenEvent event) { - if(event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu + if (event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu MenuRows menu = MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -114,15 +103,15 @@ public static void onGuiInit(ScreenEvent.InitScreenEvent event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getListenersList() - .stream() - .filter(w -> w instanceof AbstractWidget) - .map(w -> (AbstractWidget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); + .stream() + .filter(w -> w instanceof AbstractWidget) + .map(w -> (AbstractWidget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); if (toAdd.getValue() != null) event.addListener(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java index a9b7175..2c974bd 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java @@ -1,14 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientAdvancements; -import net.minecraft.world.entity.player.Player; import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.entity.player.AdvancementEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancements.class) public class ClientAdvancementsMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(ClientboundUpdateAdvancementsPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { Advancement advancement = ((ClientAdvancements) (Object) this).getAdvancements().get(entry.getKey()); Player player = minecraft.player; AdvancementEvent event = new AdvancementEvent(player, advancement); diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java index e29b27f..d2eb738 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java @@ -1,16 +1,11 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; +import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; - import net.minecraft.world.damagesource.DamageSource; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -33,8 +28,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LocalPlayer) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -43,13 +40,14 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) - { + if (amount > 0) { XpChange event = new XpChange((LocalPlayer) (Object) this, amount); - ClientEventHandler.onXpChange(event); + ClientEventHandler.onXpChange(event); } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java index 1eeb37e..5ed25d3 100644 --- a/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java +++ b/forge/fg-6.0/1.18.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java @@ -1,46 +1,36 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraftforge.event.world.BlockEvent.BreakEvent; -import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; - -import net.minecraft.world.level.block.Block; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.player.Player; -import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; -import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.InteractionResult; - +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; - - -import net.minecraft.core.BlockPos; - +import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(MultiPlayerGameMode.class) public class MultiPlayerGameModeMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + Player player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level, blockPos, player.level.getBlockState(blockPos), player); @@ -50,18 +40,22 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci @Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;", shift = At.Shift.AFTER), cancellable = true) public void onUseItemOn(LocalPlayer player, ClientLevel world, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } - + } - + @Inject(method = "useItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(LocalPlayer player, ClientLevel world, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == InteractionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.18.2/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.18.2/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.18.2/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.18.2/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.18.2/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.18.2/src/main/resources/mixins.minegasm.json index 714cffb..7c64560 100644 --- a/forge/fg-6.0/1.18.2/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.18.2/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "MultiPlayerGameModeMixin", + "ClientAdvancementsMixin", "LocalPlayerMixin", - "ClientAdvancementsMixin" + "MultiPlayerGameModeMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.18.2/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.18.2/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.18.2/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.18.2/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/build.gradle b/forge/fg-6.0/1.19.2/build.gradle index 72dd3c8..41da947 100644 --- a/forge/fg-6.0/1.19.2/build.gradle +++ b/forge/fg-6.0/1.19.2/build.gradle @@ -163,13 +163,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -222,4 +222,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/gradle.properties b/forge/fg-6.0/1.19.2/gradle.properties index 6c4c3c6..93549be 100644 --- a/forge/fg-6.0/1.19.2/gradle.properties +++ b/forge/fg-6.0/1.19.2/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.19.2 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index ddee208..bb8e51d 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,37 +1,26 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.network.chat.Component; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ClientEventHandler { @@ -41,7 +30,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -51,56 +40,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof Player && !(entity instanceof FakePlayer)) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof Player && !(entity instanceof FakePlayer)) { + Player player = (Player) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -114,26 +97,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - Player player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + Player player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -162,95 +145,78 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntity()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((Player) event.getEntity()).totalExperience, event.getAmount()); } } - + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } @@ -277,35 +243,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinLevelEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - Player player = (Player) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + Player player = (Player) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 0ae06df..db103e1 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,8 +85,7 @@ public static int getIntensity(String type) { custom.put("advancement", MinegasmConfig.advancementIntensity); - return switch (MinegasmConfig.mode) - { + return switch (MinegasmConfig.mode) { case NORMAL -> normal.get(type); case MASOCHIST -> masochist.get(type); case HEDONIST -> hedonist.get(type); @@ -123,6 +93,27 @@ public static int getIntensity(String type) { case CUSTOM -> custom.get(type); }; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index 32b71ba..59099a1 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -1,19 +1,17 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.ConfigHelper; +import com.therainbowville.minegasm.config.ConfigHolder; +import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.client.ConfigScreenHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.config.ConfigHolder; -import com.therainbowville.minegasm.config.ConfigHelper; - @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -24,7 +22,7 @@ public Minegasm() { context.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC); MinecraftForge.EVENT_BUS.register(this); - + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, ConfigHelper::createConfigScreenFactory); } } diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index c47afad..ecef97f 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,40 +1,35 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEarnEvent event) - { + + public void onAdvancement(AdvancementEarnEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - FrameType type = advancement.getDisplay().getFrame(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + FrameType type = advancement.getDisplay().getFrame(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index 61e1866..fac9cbb 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(Player player) - { - if (player.fishing != null) - { + + public void onTick(Player player) { + if (player.fishing != null) { Vec3 vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 6b373cd..a4ed4a5 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,32 +1,24 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index e4c467d..5d1228e 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.level.block.state.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 5824f8f..6892ceb 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.entity.player.Player; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.entity.player.Player; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(Player player) - { + + public void onTick(Player player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(Player player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index c3ca8ff..d68ff8b 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -155,30 +145,24 @@ public String getTranslateKey() { return this.translateKey; } } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -186,6 +170,10 @@ public static TickFrequencyOptions fromInt(int value) } return null; } + + public int getInt() { + return value; + } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index e51ab15..ddaa8ce 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -1,11 +1,6 @@ package com.therainbowville.minegasm.config; import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.common.ForgeConfigSpec; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,7 +14,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -33,13 +28,12 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + // Field[] fields = MinegasmConfigBuffer.class.getFields(); // for (Field field : fields) @@ -50,24 +44,23 @@ public static void saveClient() // LOGGER.info(method); // method.invoke(configField.get(ConfigHolder.CLIENT), field.get(buffer)); // } - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index 7687547..b13ac9f 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index d8d2b47..b3ce778 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,49 +1,37 @@ package com.therainbowville.minegasm.config; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraftforge.client.gui.widget.ForgeSlider; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Component; -import net.minecraftforge.event.TickEvent; -import net.minecraft.client.Minecraft; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraftforge.client.gui.widget.ForgeSlider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.function.IntConsumer; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; EditBox wsHost = null; + private boolean pauseMenu; public ConfigScreen(Screen previous) { super(Component.literal("Minegasm Config")); this.previous = previous; pauseMenu = false; } - + public ConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Config")); this.previous = previous; @@ -55,31 +43,31 @@ protected void init() { wsHost = new EditBox(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addRenderableWidget(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addRenderableWidget(new Button( - this.width / 2 - 155, this.height / 6 + 25, 150, 20, - Component.literal("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - } + this.width / 2 - 155, this.height / 6 + 25, 150, 20, + Component.literal("Reset Server Url"), button -> { + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + } )); - + PlainTextLabel connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, Component.literal("" + ChatFormatting.GREEN)); this.addRenderableWidget(connectResponse); - + Button reconnectButton = new Button( - this.width / 2 + 5, this.height / 6 + 25, 150, 20, - Component.literal("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + this.width / 2 + 5, this.height / 6 + 25, 150, 20, + Component.literal("Reconnect"), button -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -88,71 +76,71 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - } + + }).start(); + } ); this.addRenderableWidget(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.vibrate) - .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); + .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.stealth) - .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); + .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); this.addRenderableWidget( - CycleButton.builder((ClientConfig.GameplayMode mode) -> - Component.literal(switch (mode) { - case NORMAL -> "Normal"; - case MASOCHIST -> "Masochist"; - case HEDONIST -> "Hedonist"; - case ACCUMULATION -> "Accumulation"; - case CUSTOM -> "Custom"; - })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) - .withInitialValue(MinegasmConfig.mode) - .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - Component.literal("Mode"), (button, value) -> { - MinegasmConfig.mode = value; - }) + CycleButton.builder((ClientConfig.GameplayMode mode) -> + Component.literal(switch (mode) { + case NORMAL -> "Normal"; + case MASOCHIST -> "Masochist"; + case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; + case CUSTOM -> "Custom"; + })) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) + .withInitialValue(MinegasmConfig.mode) + .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, + Component.literal("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); this.addRenderableWidget(new Button( - this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, - Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); + this.width / 2 + 5, this.height / 6 + 25 * 4, 150, 20, + Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu)))); this.addRenderableWidget( - CycleButton.builder((Integer tickFrequency) -> - Component.literal(switch (tickFrequency) { - case 1 -> "Every Tick"; - case 2 -> "Every Other Tick"; - case 5 -> "Every 5 Ticks"; - case 10 -> "Every 10 Ticks"; - case 20 -> "Every Second"; - default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; - })) - .withValues(1, 2, 5, 10, 20, 30, 40, 50) - .withInitialValue(MinegasmConfig.tickFrequency) - .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - Component.literal("Tick Frequency"), (button, value) -> { - MinegasmConfig.tickFrequency = value; - MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); - } - ) + CycleButton.builder((Integer tickFrequency) -> + Component.literal(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f) + " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + Component.literal("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) ); this.addRenderableWidget(new Button( - this.width / 2 - 100, this.height - 27, 200, 20, - CommonComponents.GUI_DONE, button -> this.onClose())); - + this.width / 2 - 100, this.height - 27, 200, 20, + CommonComponents.GUI_DONE, button -> this.onClose())); + } - + @Override public void tick() { super.tick(); @@ -178,9 +166,9 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - + class PlainTextLabel extends AbstractWidget { - + private static Component text = Component.literal(""); private int x; private int y; @@ -191,11 +179,10 @@ public PlainTextLabel(int x, int y, int width, int height, Component text) { this.y = y; } - public static void setValue(String value) - { + public static void setValue(String value) { text = Component.literal(value); } - + @Override public void updateNarration(NarrationElementOutput output) { defaultButtonNarrationText(output); @@ -205,13 +192,13 @@ public void updateNarration(NarrationElementOutput output) { public void render(PoseStack poseStack, int i, int j, float f) { if (text == null || text.getString().isEmpty()) return; - + // RenderSystem.setShaderColor(1, 1, 1, 1); // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -224,7 +211,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Custom Config")); this.previous = previous; @@ -233,49 +220,49 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addRenderableWidget(new Button( - this.width / 2 + 5, this.height - 27, 150, 20, - CommonComponents.GUI_DONE, button -> this.onClose())); + try { + this.addRenderableWidget(new Button( + this.width / 2 + 5, this.height - 27, 150, 20, + CommonComponents.GUI_DONE, button -> this.onClose())); - IntensitiySliderBar.sliders.clear(); + IntensitiySliderBar.sliders.clear(); - // Attack - this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addRenderableWidget(new Button( - this.width / 2 - 155, this.height - 27, 150, 20, - Component.literal("Reset Values"), button -> { + // Attack + this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addRenderableWidget(new Button( + this.width / 2 - 155, this.height - 27, 150, 20, + Component.literal("Reset Values"), button -> { ConfigHolder.getClientInstance().resetConfigCustom(); IntensitiySliderBar.refreshAllValues(); } - )); - - + )); + + } catch (Throwable e) { LOGGER.throwing(e); } @@ -296,28 +283,31 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - - private class IntensitiySliderBar extends ForgeSlider - { + + private class IntensitiySliderBar extends ForgeSlider { public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - Component.literal(prefix), // Prefix - Component.literal(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + Component.literal(prefix), // Prefix + Component.literal(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; // LOGGER.info("S: " + sliders.size() + " X: " + parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155) + " Y: " + parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2)); sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { // LOGGER.info("applyValue"); //responder.accept(this.getValueInt()); try { @@ -327,22 +317,13 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { LOGGER.throwing(e); } } - + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index cb0e2fd..301e2f9 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -22,7 +22,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static float ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -48,23 +48,21 @@ public static void onModConfigEvent(final ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -74,15 +72,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index fd51d2b..4b979a5 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,110 +1,99 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.PauseScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; - -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.commons.lang3.mutable.MutableObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.apache.commons.lang3.mutable.MutableObject; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - - public PauseMenuButton(int x, int y) { - super(x, y, 20, 20, Component.literal(""), PauseMenuButton::clicked); + + public PauseMenuButton(int x, int y) { + super(x, y, 20, 20, Component.literal(""), PauseMenuButton::clicked); xPos = x; yPos = y; - } - - @Override - public void renderBg(PoseStack mstack, Minecraft mc, int mouseX, int mouseY) { - mstack.pushPose(); - mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); - mstack.scale(0.25f, 0.25f, 1); - RenderSystem.setShaderTexture(0, LOGO); - GuiComponent.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); - mstack.popPose(); - } - - public static void clicked(Button button) - { + } + + public static void clicked(Button button) { Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); } - + + @Override + public void renderBg(PoseStack mstack, Minecraft mc, int mouseX, int mouseY) { + mstack.pushPose(); + mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + mstack.scale(0.25f, 0.25f, 1); + RenderSystem.setShaderTexture(0, LOGO); + GuiComponent.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); + mstack.popPose(); + } + public static class SingleMenuRow { - public final String left, right; - public SingleMenuRow(String left, String right) { - this.left = I18n.get(left); - this.right = I18n.get(right); - } - public SingleMenuRow(String center) { - this(center, center); - } - } - - public static class MenuRows { - public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") - )); - - public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") - )); - - protected final List leftButtons, rightButtons; - - public MenuRows(List variants) { - leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); - rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); - } - } - + public final String left, right; + + public SingleMenuRow(String left, String right) { + this.left = I18n.get(left); + this.right = I18n.get(right); + } + + public SingleMenuRow(String center) { + this(center, center); + } + } + + public static class MenuRows { + public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + )); + + public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") + )); + + protected final List leftButtons, rightButtons; + + public MenuRows(List variants) { + leftButtons = variants.stream().map(r -> r.left).collect(Collectors.toList()); + rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); + } + } + @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { - + @SubscribeEvent public static void onGuiInit(ScreenEvent.Init event) { - if(event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu + if (event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu MenuRows menu = MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -114,15 +103,15 @@ public static void onGuiInit(ScreenEvent.Init event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getListenersList() - .stream() - .filter(w -> w instanceof AbstractWidget) - .map(w -> (AbstractWidget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); + .stream() + .filter(w -> w instanceof AbstractWidget) + .map(w -> (AbstractWidget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.x + offsetX_ + (onLeft ? -20 : w.getWidth()), w.y))); if (toAdd.getValue() != null) event.addListener(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java index 6b0a63d..f142795 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java @@ -1,14 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientAdvancements; -import net.minecraft.world.entity.player.Player; import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancements.class) public class ClientAdvancementsMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(ClientboundUpdateAdvancementsPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { if (entry.getValue().isDone()) { Advancement advancement = ((ClientAdvancements) (Object) this).getAdvancements().get(entry.getKey()); Player player = minecraft.player; diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java index d409c35..d2eb738 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java @@ -1,15 +1,11 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.damagesource.DamageSource; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -32,8 +28,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LocalPlayer) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -41,14 +39,15 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) - { + if (amount > 0) { XpChange event = new XpChange((LocalPlayer) (Object) this, amount); - ClientEventHandler.onXpChange(event); + ClientEventHandler.onXpChange(event); } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java index 72179ef..7ebf4b0 100644 --- a/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java +++ b/forge/fg-6.0/1.19.2/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java @@ -1,21 +1,16 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraftforge.event.level.BlockEvent.BreakEvent; -import net.minecraft.core.BlockPos; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.world.entity.player.Player; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; - +import net.minecraftforge.event.level.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -26,13 +21,15 @@ @Mixin(MultiPlayerGameMode.class) public class MultiPlayerGameModeMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + Player player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level, blockPos, player.level.getBlockState(blockPos), player); @@ -42,18 +39,22 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci @Inject(method = "performUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"), cancellable = true) public void onUseItemOn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } - + } - + @Inject(method = "performUseItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == InteractionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.19.2/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.19.2/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.19.2/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.19.2/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.19.2/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.19.2/src/main/resources/mixins.minegasm.json index 714cffb..7c64560 100644 --- a/forge/fg-6.0/1.19.2/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.19.2/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "MultiPlayerGameModeMixin", + "ClientAdvancementsMixin", "LocalPlayerMixin", - "ClientAdvancementsMixin" + "MultiPlayerGameModeMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.2/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.19.2/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.19.2/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.19.2/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/build.gradle b/forge/fg-6.0/1.19.4/build.gradle index 72dd3c8..41da947 100644 --- a/forge/fg-6.0/1.19.4/build.gradle +++ b/forge/fg-6.0/1.19.4/build.gradle @@ -163,13 +163,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -222,4 +222,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/gradle.properties b/forge/fg-6.0/1.19.4/gradle.properties index d5cfb60..c9bac47 100644 --- a/forge/fg-6.0/1.19.4/gradle.properties +++ b/forge/fg-6.0/1.19.4/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.19.4 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index f4b8b0e..84680d6 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,37 +1,25 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.common.util.FakePlayer; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.network.chat.Component; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { @@ -41,7 +29,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -51,56 +39,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof Player && !(entity instanceof FakePlayer)) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof Player && !(entity instanceof FakePlayer)) { + Player player = (Player) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -114,26 +96,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - Player player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + Player player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -162,96 +144,79 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntity()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((Player) event.getEntity()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } @@ -278,35 +243,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinLevelEvent event) { Entity entity = event.getEntity(); - if( !entity.level.isClientSide() ) { + if (!entity.level.isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - Player player = (Player) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + Player player = (Player) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 0ae06df..db103e1 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,8 +85,7 @@ public static int getIntensity(String type) { custom.put("advancement", MinegasmConfig.advancementIntensity); - return switch (MinegasmConfig.mode) - { + return switch (MinegasmConfig.mode) { case NORMAL -> normal.get(type); case MASOCHIST -> masochist.get(type); case HEDONIST -> hedonist.get(type); @@ -123,6 +93,27 @@ public static int getIntensity(String type) { case CUSTOM -> custom.get(type); }; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index 32b71ba..59099a1 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -1,19 +1,17 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.ConfigHelper; +import com.therainbowville.minegasm.config.ConfigHolder; +import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.client.ConfigScreenHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.config.ConfigHolder; -import com.therainbowville.minegasm.config.ConfigHelper; - @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -24,7 +22,7 @@ public Minegasm() { context.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC); MinecraftForge.EVENT_BUS.register(this); - + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, ConfigHelper::createConfigScreenFactory); } } diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index c47afad..ecef97f 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,40 +1,35 @@ package com.therainbowville.minegasm.common; -import net.minecraft.advancements.FrameType; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.FrameType; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEarnEvent event) - { + + public void onAdvancement(AdvancementEarnEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement(); - FrameType type = advancement.getDisplay().getFrame(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement(); + FrameType type = advancement.getDisplay().getFrame(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index 61e1866..fac9cbb 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(Player player) - { - if (player.fishing != null) - { + + public void onTick(Player player) { + if (player.fishing != null) { Vec3 vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level.getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 6b373cd..a4ed4a5 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,32 +1,24 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index e4c467d..5d1228e 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.level.block.state.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 5824f8f..6892ceb 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.entity.player.Player; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.entity.player.Player; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(Player player) - { + + public void onTick(Player player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(Player player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index c3ca8ff..d68ff8b 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -155,30 +145,24 @@ public String getTranslateKey() { return this.translateKey; } } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -186,6 +170,10 @@ public static TickFrequencyOptions fromInt(int value) } return null; } + + public int getInt() { + return value; + } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index e51ab15..ddaa8ce 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -1,11 +1,6 @@ package com.therainbowville.minegasm.config; import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.common.ForgeConfigSpec; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,7 +14,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -33,13 +28,12 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + // Field[] fields = MinegasmConfigBuffer.class.getFields(); // for (Field field : fields) @@ -50,24 +44,23 @@ public static void saveClient() // LOGGER.info(method); // method.invoke(configField.get(ConfigHolder.CLIENT), field.get(buffer)); // } - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index 7687547..b13ac9f 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index b124066..97842a5 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,49 +1,37 @@ package com.therainbowville.minegasm.config; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraftforge.client.gui.widget.ForgeSlider; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Component; -import net.minecraftforge.event.TickEvent; -import net.minecraft.client.Minecraft; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraftforge.client.gui.widget.ForgeSlider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.function.IntConsumer; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; EditBox wsHost = null; + private boolean pauseMenu; public ConfigScreen(Screen previous) { super(Component.literal("Minegasm Config")); this.previous = previous; pauseMenu = false; } - + public ConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Config")); this.previous = previous; @@ -55,29 +43,29 @@ protected void init() { wsHost = new EditBox(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addRenderableWidget(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - }).pos(this.width / 2 - 155, this.height / 6 + 25) - .size(150, 20) - .build() + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + }).pos(this.width / 2 - 155, this.height / 6 + 25) + .size(150, 20) + .build() ); - + PlainTextLabel connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, Component.literal("" + ChatFormatting.GREEN)); this.addRenderableWidget(connectResponse); - + Button reconnectButton = new Button.Builder(Component.literal("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -86,78 +74,78 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - }) - .pos(this.width / 2 + 5, this.height / 6 + 25) - .size(150, 20) - .build(); - + + }).start(); + }) + .pos(this.width / 2 + 5, this.height / 6 + 25) + .size(150, 20) + .build(); + this.addRenderableWidget(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.vibrate) - .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); + .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.stealth) - .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); + .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); this.addRenderableWidget( - CycleButton.builder((ClientConfig.GameplayMode mode) -> - Component.literal(switch (mode) { - case NORMAL -> "Normal"; - case MASOCHIST -> "Masochist"; - case HEDONIST -> "Hedonist"; - case ACCUMULATION -> "Accumulation"; - case CUSTOM -> "Custom"; - })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) - .withInitialValue(MinegasmConfig.mode) - .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - Component.literal("Mode"), (button, value) -> { - MinegasmConfig.mode = value; - }) + CycleButton.builder((ClientConfig.GameplayMode mode) -> + Component.literal(switch (mode) { + case NORMAL -> "Normal"; + case MASOCHIST -> "Masochist"; + case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; + case CUSTOM -> "Custom"; + })) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) + .withInitialValue(MinegasmConfig.mode) + .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, + Component.literal("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); - this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) - .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) - .size(150, 20) - .build() + this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) + .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) + .size(150, 20) + .build() ); this.addRenderableWidget( - CycleButton.builder((Integer tickFrequency) -> - Component.literal(switch (tickFrequency) { - case 1 -> "Every Tick"; - case 2 -> "Every Other Tick"; - case 5 -> "Every 5 Ticks"; - case 10 -> "Every 10 Ticks"; - case 20 -> "Every Second"; - default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; - })) - .withValues(1, 2, 5, 10, 20, 30, 40, 50) - .withInitialValue(MinegasmConfig.tickFrequency) - .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - Component.literal("Tick Frequency"), (button, value) -> { - MinegasmConfig.tickFrequency = value; - MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); - } - ) + CycleButton.builder((Integer tickFrequency) -> + Component.literal(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f) + " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + Component.literal("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) ); this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 - 100, this.height - 27) - .size(200, 20) - .build() + .pos(this.width / 2 - 100, this.height - 27) + .size(200, 20) + .build() ); - + } - + @Override public void tick() { super.tick(); @@ -183,9 +171,9 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - + class PlainTextLabel extends AbstractWidget { - + private static Component text = Component.literal(""); private int x; private int y; @@ -196,11 +184,10 @@ public PlainTextLabel(int x, int y, int width, int height, Component text) { this.y = y; } - public static void setValue(String value) - { + public static void setValue(String value) { text = Component.literal(value); } - + @Override public void updateWidgetNarration(NarrationElementOutput output) { defaultButtonNarrationText(output); @@ -210,13 +197,13 @@ public void updateWidgetNarration(NarrationElementOutput output) { public void renderWidget(PoseStack poseStack, int i, int j, float f) { if (text == null || text.getString().isEmpty()) return; - + // RenderSystem.setShaderColor(1, 1, 1, 1); // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); drawCenteredString(poseStack, Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -229,7 +216,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Custom Config")); this.previous = previous; @@ -238,52 +225,52 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 + 5, this.height - 27) - .size(150, 20) - .build() - ); + try { + this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) + .pos(this.width / 2 + 5, this.height - 27) + .size(150, 20) + .build() + ); + + IntensitiySliderBar.sliders.clear(); + + // Attack + this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { + ConfigHolder.getClientInstance().resetConfigCustom(); + IntensitiySliderBar.refreshAllValues(); + }) + .pos(this.width / 2 - 155, this.height - 27) + .size(150, 20) + .build() + ); - IntensitiySliderBar.sliders.clear(); - // Attack - this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { - ConfigHolder.getClientInstance().resetConfigCustom(); - IntensitiySliderBar.refreshAllValues(); - }) - .pos(this.width / 2 - 155, this.height - 27) - .size(150, 20) - .build() - ); - - } catch (Throwable e) { LOGGER.throwing(e); } @@ -304,28 +291,31 @@ public void render(PoseStack poseStack, int i, int j, float f) { drawCenteredString(poseStack, this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(poseStack, i, j, f); } - - private class IntensitiySliderBar extends ForgeSlider - { + + private class IntensitiySliderBar extends ForgeSlider { public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - Component.literal(prefix), // Prefix - Component.literal(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + Component.literal(prefix), // Prefix + Component.literal(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; // LOGGER.info("S: " + sliders.size() + " X: " + parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155) + " Y: " + parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2)); sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { // LOGGER.info("applyValue"); //responder.accept(this.getValueInt()); try { @@ -335,22 +325,13 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { LOGGER.throwing(e); } } - + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index cb0e2fd..301e2f9 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -22,7 +22,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static float ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -48,23 +48,21 @@ public static void onModConfigEvent(final ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -74,15 +72,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index b5b0317..4f7fa47 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,95 +1,84 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.PauseScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; - -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.commons.lang3.mutable.MutableObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.apache.commons.lang3.mutable.MutableObject; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - + public PauseMenuButton(int x, int y) { super(new Button.Builder(Component.literal(""), PauseMenuButton::clicked).pos(x, y).size(20, 20)); xPos = x; yPos = y; } - + + public static void clicked(Button button) { + Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); + } + @Override public void renderWidget(PoseStack mstack, int i, int j, float k) { super.renderWidget(mstack, i, j, k); mstack.pushPose(); - mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + mstack.translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); mstack.scale(0.25f, 0.25f, 1); RenderSystem.setShaderTexture(0, LOGO); GuiComponent.blit(mstack, 0, 0, 0, 0, 0, 64, 64, 64, 64); mstack.popPose(); } - - public static void clicked(Button button) - { - Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); - } - + public static class SingleMenuRow { public final String left, right; + public SingleMenuRow(String left, String right) { this.left = I18n.get(left); this.right = I18n.get(right); } + public SingleMenuRow(String center) { this(center, center); } } - + public static class MenuRows { public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") )); public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") )); protected final List leftButtons, rightButtons; @@ -99,13 +88,13 @@ public MenuRows(List variants) { rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); } } - + @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { - + @SubscribeEvent public static void onGuiInit(ScreenEvent.Init event) { - if(event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu + if (event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu MenuRows menu = MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -115,15 +104,15 @@ public static void onGuiInit(ScreenEvent.Init event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getListenersList() - .stream() - .filter(w -> w instanceof AbstractWidget) - .map(w -> (AbstractWidget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); + .stream() + .filter(w -> w instanceof AbstractWidget) + .map(w -> (AbstractWidget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); if (toAdd.getValue() != null) event.addListener(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java index 6b0a63d..f142795 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java @@ -1,14 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientAdvancements; -import net.minecraft.world.entity.player.Player; import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancements.class) public class ClientAdvancementsMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(ClientboundUpdateAdvancementsPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { if (entry.getValue().isDone()) { Advancement advancement = ((ClientAdvancements) (Object) this).getAdvancements().get(entry.getKey()); Player player = minecraft.player; diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java index d409c35..d2eb738 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java @@ -1,15 +1,11 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.damagesource.DamageSource; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -32,8 +28,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LocalPlayer) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -41,14 +39,15 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) - { + if (amount > 0) { XpChange event = new XpChange((LocalPlayer) (Object) this, amount); - ClientEventHandler.onXpChange(event); + ClientEventHandler.onXpChange(event); } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java index 72179ef..7ebf4b0 100644 --- a/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java +++ b/forge/fg-6.0/1.19.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java @@ -1,21 +1,16 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraftforge.event.level.BlockEvent.BreakEvent; -import net.minecraft.core.BlockPos; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.world.entity.player.Player; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; - +import net.minecraftforge.event.level.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -26,13 +21,15 @@ @Mixin(MultiPlayerGameMode.class) public class MultiPlayerGameModeMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + Player player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level, blockPos, player.level.getBlockState(blockPos), player); @@ -42,18 +39,22 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci @Inject(method = "performUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"), cancellable = true) public void onUseItemOn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } - + } - + @Inject(method = "performUseItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == InteractionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.19.4/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.19.4/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.19.4/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.19.4/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.19.4/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.19.4/src/main/resources/mixins.minegasm.json index 714cffb..7c64560 100644 --- a/forge/fg-6.0/1.19.4/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.19.4/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "MultiPlayerGameModeMixin", + "ClientAdvancementsMixin", "LocalPlayerMixin", - "ClientAdvancementsMixin" + "MultiPlayerGameModeMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.19.4/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.19.4/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.19.4/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.19.4/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/build.gradle b/forge/fg-6.0/1.20.4/build.gradle index 72dd3c8..41da947 100644 --- a/forge/fg-6.0/1.20.4/build.gradle +++ b/forge/fg-6.0/1.20.4/build.gradle @@ -163,13 +163,13 @@ dependencies { // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + forge_version : forge_version, forge_version_range: forge_version_range, + loader_version_range : loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, mod_issue_tracker_url: mod_issue_tracker_url, mod_update_json_url: mod_update_json_url, - mod_display_url: mod_display_url, mod_logo_file: mod_logo_file + mod_display_url : mod_display_url, mod_logo_file: mod_logo_file ] inputs.properties replaceProperties @@ -222,4 +222,4 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -tasks.register("prepareKotlinBuildScriptModel") { } \ No newline at end of file +tasks.register("prepareKotlinBuildScriptModel") {} \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/gradle.properties b/forge/fg-6.0/1.20.4/gradle.properties index c0968f7..2351d11 100644 --- a/forge/fg-6.0/1.20.4/gradle.properties +++ b/forge/fg-6.0/1.20.4/gradle.properties @@ -1,5 +1,4 @@ ## Environment Properties - # The Minecraft version must agree with the Forge version to get a valid artifact minecraft_version=1.20.4 # The Minecraft version range can use any release version of Minecraft as bounds. diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index 23401ce..2bcd28b 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,36 +1,24 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.network.chat.Component; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class ClientEventHandler { @@ -40,7 +28,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -50,56 +38,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof Player) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof Player) { + Player player = (Player) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -113,26 +95,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { try { - if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { - Player player = event.player; - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (event.phase == TickEvent.Phase.END && isPlayer(event.player)) { + Player player = event.player; - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -161,97 +143,80 @@ public static void onClientTick(TickEvent.ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingHurtEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingHurtEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onItemPickup(EntityItemPickupEvent event) - { + public static void onItemPickup(EntityItemPickupEvent event) { LOGGER.info("Pickup item: " + event.getItem().toString()); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntity()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((Player) event.getEntity()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level().isClientSide() ) { + if (!entity.level().isClientSide()) { return; } @@ -278,35 +243,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinLevelEvent event) { Entity entity = event.getEntity(); - if( !entity.level().isClientSide() ) { + if (!entity.level().isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - Player player = (Player) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + Player player = (Player) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 0ae06df..db103e1 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,8 +85,7 @@ public static int getIntensity(String type) { custom.put("advancement", MinegasmConfig.advancementIntensity); - return switch (MinegasmConfig.mode) - { + return switch (MinegasmConfig.mode) { case NORMAL -> normal.get(type); case MASOCHIST -> masochist.get(type); case HEDONIST -> hedonist.get(type); @@ -123,6 +93,27 @@ public static int getIntensity(String type) { case CUSTOM -> custom.get(type); }; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index 32b71ba..59099a1 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -1,19 +1,17 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.ConfigHelper; +import com.therainbowville.minegasm.config.ConfigHolder; +import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.client.ConfigScreenHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.config.ConfigHolder; -import com.therainbowville.minegasm.config.ConfigHelper; - @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); @@ -24,7 +22,7 @@ public Minegasm() { context.registerConfig(ModConfig.Type.SERVER, ConfigHolder.SERVER_SPEC); MinecraftForge.EVENT_BUS.register(this); - + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, ConfigHelper::createConfigScreenFactory); } } diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 605c8d2..1ab7e6d 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,40 +1,35 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementType; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEarnEvent event) - { + + public void onAdvancement(AdvancementEarnEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement().value(); - AdvancementType type = advancement.display().get().getType(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement().value(); + AdvancementType type = advancement.display().get().getType(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index db66ed2..d55d5bb 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(Player player) - { - if (player.fishing != null) - { + + public void onTick(Player player) { + if (player.fishing != null) { Vec3 vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level().getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level().getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 6b373cd..a4ed4a5 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,32 +1,24 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index e4c467d..5d1228e 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.level.block.state.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 5824f8f..6892ceb 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.entity.player.Player; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.entity.player.Player; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(Player player) - { + + public void onTick(Player player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(Player player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index c3ca8ff..d68ff8b 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -2,21 +2,28 @@ import com.therainbowville.minegasm.common.Minegasm; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.fml.mclanguageprovider.MinecraftModLanguageProvider; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ForgeConfigSpec.ConfigValue serverUrl; - final ForgeConfigSpec.BooleanValue vibrate; final ForgeConfigSpec.EnumValue mode; final ForgeConfigSpec.BooleanValue stealth; final ForgeConfigSpec.EnumValue tickFrequency; - final ForgeConfigSpec.IntValue attackIntensity; final ForgeConfigSpec.IntValue hurtIntensity; final ForgeConfigSpec.IntValue mineIntensity; @@ -26,22 +33,7 @@ public final class ClientConfig { final ForgeConfigSpec.IntValue harvestIntensity; final ForgeConfigSpec.IntValue vitalityIntensity; final ForgeConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ForgeConfigSpec.Builder builder) { builder.push("buttplug"); @@ -63,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -84,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -94,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -109,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -118,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -136,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -155,30 +145,24 @@ public String getTranslateKey() { return this.translateKey; } } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -186,6 +170,10 @@ public static TickFrequencyOptions fromInt(int value) } return null; } + + public int getInt() { + return value; + } } - + } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index e51ab15..ddaa8ce 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -1,11 +1,6 @@ package com.therainbowville.minegasm.config; import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.common.ForgeConfigSpec; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,7 +14,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -33,13 +28,12 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + // Field[] fields = MinegasmConfigBuffer.class.getFields(); // for (Field field : fields) @@ -50,24 +44,23 @@ public static void saveClient() // LOGGER.info(method); // method.invoke(configField.get(ConfigHolder.CLIENT), field.get(buffer)); // } - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index 7687547..b13ac9f 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ForgeConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new); diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index 0b06af7..79b36bf 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -1,50 +1,37 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ToyController; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraftforge.client.gui.widget.ForgeSlider; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Component; -import net.minecraftforge.event.TickEvent; -import net.minecraft.client.Minecraft; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.client.ToyController; -import com.therainbowville.minegasm.client.ClientEventHandler; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraftforge.client.gui.widget.ForgeSlider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.lang.reflect.Field; -import java.lang.Thread; import java.util.ArrayList; -import java.util.function.IntConsumer; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; EditBox wsHost = null; + private boolean pauseMenu; public ConfigScreen(Screen previous) { super(Component.literal("Minegasm Config")); this.previous = previous; pauseMenu = false; } - + public ConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Config")); this.previous = previous; @@ -56,29 +43,29 @@ protected void init() { wsHost = new EditBox(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addRenderableWidget(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - }).pos(this.width / 2 - 155, this.height / 6 + 25) - .size(150, 20) - .build() + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + }).pos(this.width / 2 - 155, this.height / 6 + 25) + .size(150, 20) + .build() ); - + PlainTextLabel connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, Component.literal("" + ChatFormatting.GREEN)); this.addRenderableWidget(connectResponse); - + Button reconnectButton = new Button.Builder(Component.literal("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -87,78 +74,78 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - }) - .pos(this.width / 2 + 5, this.height / 6 + 25) - .size(150, 20) - .build(); - + + }).start(); + }) + .pos(this.width / 2 + 5, this.height / 6 + 25) + .size(150, 20) + .build(); + this.addRenderableWidget(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.vibrate) - .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); + .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.stealth) - .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); + .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); this.addRenderableWidget( - CycleButton.builder((ClientConfig.GameplayMode mode) -> - Component.literal(switch (mode) { - case NORMAL -> "Normal"; - case MASOCHIST -> "Masochist"; - case HEDONIST -> "Hedonist"; - case ACCUMULATION -> "Accumulation"; - case CUSTOM -> "Custom"; - })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) - .withInitialValue(MinegasmConfig.mode) - .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - Component.literal("Mode"), (button, value) -> { - MinegasmConfig.mode = value; - }) + CycleButton.builder((ClientConfig.GameplayMode mode) -> + Component.literal(switch (mode) { + case NORMAL -> "Normal"; + case MASOCHIST -> "Masochist"; + case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; + case CUSTOM -> "Custom"; + })) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) + .withInitialValue(MinegasmConfig.mode) + .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, + Component.literal("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); - this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) - .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) - .size(150, 20) - .build() + this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) + .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) + .size(150, 20) + .build() ); this.addRenderableWidget( - CycleButton.builder((Integer tickFrequency) -> - Component.literal(switch (tickFrequency) { - case 1 -> "Every Tick"; - case 2 -> "Every Other Tick"; - case 5 -> "Every 5 Ticks"; - case 10 -> "Every 10 Ticks"; - case 20 -> "Every Second"; - default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; - })) - .withValues(1, 2, 5, 10, 20, 30, 40, 50) - .withInitialValue(MinegasmConfig.tickFrequency) - .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - Component.literal("Tick Frequency"), (button, value) -> { - MinegasmConfig.tickFrequency = value; - MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); - } - ) + CycleButton.builder((Integer tickFrequency) -> + Component.literal(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f) + " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + Component.literal("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) ); this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 - 100, this.height - 27) - .size(200, 20) - .build() + .pos(this.width / 2 - 100, this.height - 27) + .size(200, 20) + .build() ); - + } - + @Override public void tick() { super.tick(); @@ -184,9 +171,9 @@ public void render(GuiGraphics graphics, int i, int j, float f) { graphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(graphics, i, j, f); } - + class PlainTextLabel extends AbstractWidget { - + private static Component text = Component.literal(""); private int x; private int y; @@ -197,11 +184,10 @@ public PlainTextLabel(int x, int y, int width, int height, Component text) { this.y = y; } - public static void setValue(String value) - { + public static void setValue(String value) { text = Component.literal(value); } - + @Override public void updateWidgetNarration(NarrationElementOutput output) { defaultButtonNarrationText(output); @@ -211,13 +197,13 @@ public void updateWidgetNarration(NarrationElementOutput output) { public void renderWidget(GuiGraphics graphics, int i, int j, float f) { if (text == null || text.getString().isEmpty()) return; - + // RenderSystem.setShaderColor(1, 1, 1, 1); // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); graphics.drawCenteredString(Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -230,7 +216,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Custom Config")); this.previous = previous; @@ -239,52 +225,52 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 + 5, this.height - 27) - .size(150, 20) - .build() - ); + try { + this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) + .pos(this.width / 2 + 5, this.height - 27) + .size(150, 20) + .build() + ); + + IntensitiySliderBar.sliders.clear(); + + // Attack + this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { + ConfigHolder.getClientInstance().resetConfigCustom(); + IntensitiySliderBar.refreshAllValues(); + }) + .pos(this.width / 2 - 155, this.height - 27) + .size(150, 20) + .build() + ); - IntensitiySliderBar.sliders.clear(); - // Attack - this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { - ConfigHolder.getClientInstance().resetConfigCustom(); - IntensitiySliderBar.refreshAllValues(); - }) - .pos(this.width / 2 - 155, this.height - 27) - .size(150, 20) - .build() - ); - - } catch (Throwable e) { LOGGER.throwing(e); } @@ -305,28 +291,31 @@ public void render(GuiGraphics graphics, int i, int j, float f) { graphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(graphics, i, j, f); } - - private class IntensitiySliderBar extends ForgeSlider - { + + private class IntensitiySliderBar extends ForgeSlider { public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - Component.literal(prefix), // Prefix - Component.literal(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + Component.literal(prefix), // Prefix + Component.literal(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; // LOGGER.info("S: " + sliders.size() + " X: " + parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155) + " Y: " + parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2)); sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { // LOGGER.info("applyValue"); //responder.accept(this.getValueInt()); try { @@ -336,22 +325,13 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { LOGGER.throwing(e); } } - + } } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index cb0e2fd..301e2f9 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -22,7 +22,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static float ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -48,23 +48,21 @@ public static void onModConfigEvent(final ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -74,15 +72,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index ae74e11..68313af 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -1,95 +1,83 @@ package com.therainbowville.minegasm.config; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.therainbowville.minegasm.common.Minegasm; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.PauseScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; - -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.ScreenEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.commons.lang3.mutable.MutableObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.apache.commons.lang3.mutable.MutableObject; - -import com.therainbowville.minegasm.common.Minegasm; -import com.therainbowville.minegasm.config.ClientConfig; -import com.therainbowville.minegasm.config.MinegasmConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = new ResourceLocation(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - + public PauseMenuButton(int x, int y) { super(new Button.Builder(Component.literal(""), PauseMenuButton::clicked).pos(x, y).size(20, 20)); xPos = x; yPos = y; } - + + public static void clicked(Button button) { + Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); + } + @Override public void renderWidget(GuiGraphics graphics, int i, int j, float k) { super.renderWidget(graphics, i, j, k); graphics.pose().pushPose(); - graphics.pose().translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + graphics.pose().translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); graphics.pose().scale(0.25f, 0.25f, 1); RenderSystem.setShaderTexture(0, LOGO); graphics.blit(LOGO, 0, 0, 0, 0, 64, 64, 64, 64); graphics.pose().popPose(); } - - public static void clicked(Button button) - { - Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); - } - + public static class SingleMenuRow { public final String left, right; + public SingleMenuRow(String left, String right) { this.left = I18n.get(left); this.right = I18n.get(right); } + public SingleMenuRow(String center) { this(center, center); } } - + public static class MenuRows { public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") )); public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") )); protected final List leftButtons, rightButtons; @@ -99,13 +87,13 @@ public MenuRows(List variants) { rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); } } - + @Mod.EventBusSubscriber(modid = Minegasm.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class PauseMenuButtonScreen { - + @SubscribeEvent public static void onGuiInit(ScreenEvent.Init event) { - if(event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu + if (event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu MenuRows menu = MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -115,15 +103,15 @@ public static void onGuiInit(ScreenEvent.Init event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getListenersList() - .stream() - .filter(w -> w instanceof AbstractWidget) - .map(w -> (AbstractWidget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); + .stream() + .filter(w -> w instanceof AbstractWidget) + .map(w -> (AbstractWidget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); if (toAdd.getValue() != null) event.addListener(toAdd.getValue()); } diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java index c791383..c21233b 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java @@ -1,14 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientAdvancements; -import net.minecraft.world.entity.player.Player; import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancements.class) public class ClientAdvancementsMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(ClientboundUpdateAdvancementsPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { if (entry.getValue().isDone()) { AdvancementHolder advancement = ((ClientAdvancements) (Object) this).get(entry.getKey()); Player player = minecraft.player; diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java index d409c35..d2eb738 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java @@ -1,15 +1,11 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.damagesource.DamageSource; - -import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -32,8 +28,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingHurtEvent event = new LivingHurtEvent((LocalPlayer) (Object) this, source, amount); ClientEventHandler.onHurt(event); @@ -41,14 +39,15 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) - { + if (amount > 0) { XpChange event = new XpChange((LocalPlayer) (Object) this, amount); - ClientEventHandler.onXpChange(event); + ClientEventHandler.onXpChange(event); } } } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java index 15c77e4..a50385d 100644 --- a/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java +++ b/forge/fg-6.0/1.20.4/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java @@ -1,21 +1,16 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.minecraftforge.event.level.BlockEvent.BreakEvent; -import net.minecraft.core.BlockPos; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.world.entity.player.Player; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; - +import net.minecraftforge.event.level.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -26,13 +21,15 @@ @Mixin(MultiPlayerGameMode.class) public class MultiPlayerGameModeMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + Player player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level(), blockPos, player.level().getBlockState(blockPos), player); @@ -42,18 +39,22 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci @Inject(method = "performUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"), cancellable = true) public void onUseItemOn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } - + } - + @Inject(method = "performUseItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == InteractionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/forge/fg-6.0/1.20.4/src/main/resources/META-INF/mods.toml b/forge/fg-6.0/1.20.4/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/forge/fg-6.0/1.20.4/src/main/resources/META-INF/mods.toml +++ b/forge/fg-6.0/1.20.4/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/forge/fg-6.0/1.20.4/src/main/resources/mixins.minegasm.json b/forge/fg-6.0/1.20.4/src/main/resources/mixins.minegasm.json index 714cffb..7c64560 100644 --- a/forge/fg-6.0/1.20.4/src/main/resources/mixins.minegasm.json +++ b/forge/fg-6.0/1.20.4/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "MultiPlayerGameModeMixin", + "ClientAdvancementsMixin", "LocalPlayerMixin", - "ClientAdvancementsMixin" + "MultiPlayerGameModeMixin" ] } \ No newline at end of file diff --git a/forge/fg-6.0/1.20.4/src/main/resources/pack.mcmeta b/forge/fg-6.0/1.20.4/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/forge/fg-6.0/1.20.4/src/main/resources/pack.mcmeta +++ b/forge/fg-6.0/1.20.4/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/forge/fg-6.0/gradle.properties b/forge/fg-6.0/gradle.properties index e3575a9..9dbb08d 100644 --- a/forge/fg-6.0/gradle.properties +++ b/forge/fg-6.0/gradle.properties @@ -2,10 +2,7 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false - - ## Mod Properties - # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. mod_id=minegasm @@ -23,7 +20,6 @@ mod_group_id=com.therainbowville.minegasm mod_authors=RSwoop, RainbowVille's contributors # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description=Just a simple mod to bring some gasm into Minecraft. ;) - mod_issue_tracker_url=https://github.com/RainbowVille/minegasm/issues mod_update_json_url=https://www.minegasm.net/updates.json mod_display_url=https://www.minegasm.net/ diff --git a/neoforge/ng-7.0/1.21/build.gradle b/neoforge/ng-7.0/1.21/build.gradle index 903129d..9d0fd92 100644 --- a/neoforge/ng-7.0/1.21/build.gradle +++ b/neoforge/ng-7.0/1.21/build.gradle @@ -6,7 +6,7 @@ plugins { id 'net.neoforged.gradle.userdev' version '7.0.145' } -task wrapper(type: Wrapper){ +task wrapper(type: Wrapper) { gradleVersion = '8.9' } diff --git a/neoforge/ng-7.0/1.21/gradle.properties b/neoforge/ng-7.0/1.21/gradle.properties index e298c9e..b3a0b1a 100644 --- a/neoforge/ng-7.0/1.21/gradle.properties +++ b/neoforge/ng-7.0/1.21/gradle.properties @@ -2,7 +2,6 @@ org.gradle.jvmargs=-Xmx1G org.gradle.daemon=false org.gradle.debug=false - #read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings # you can also find the latest versions at: https://parchmentmc.org/docs/getting-started neogradle.subsystems.parchment.minecraftVersion=1.21 @@ -21,9 +20,7 @@ neo_version=21.0.114-beta neo_version_range=[21.0.0-beta,) # The loader version range can only use the major version of FML as bounds loader_version_range=[4,) - ## Mod Properties - # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. mod_id=examplemod diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java index 9754db0..b94298d 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java @@ -1,39 +1,25 @@ package com.therainbowville.minegasm.client; -import com.therainbowville.minegasm.common.Minegasm; import com.therainbowville.minegasm.common.*; -import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.network.chat.Component; -import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ClientTickEvent; -import net.neoforged.neoforge.event.tick.PlayerTickEvent; -import net.neoforged.neoforge.event.tick.EntityTickEvent; import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; -import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; import net.neoforged.neoforge.event.entity.living.LivingDamageEvent; import net.neoforged.neoforge.event.entity.player.*; import net.neoforged.neoforge.event.level.BlockEvent; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; - +import net.neoforged.neoforge.event.tick.PlayerTickEvent; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.*; -import java.util.stream.Collectors; -import java.lang.Thread; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; @EventBusSubscriber(modid = Minegasm.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class ClientEventHandler { @@ -43,7 +29,7 @@ public class ClientEventHandler { private static int clientTickCounter = -1; private static boolean paused = false; private static UUID playerId = null; - + private static Map vibrationStates = new HashMap(); static { @@ -53,56 +39,50 @@ public class ClientEventHandler { vibrationStates.put("hurt", new VibrationStateHurt()); vibrationStates.put("mine", new VibrationStateMine()); vibrationStates.put("place", new VibrationStatePlace()); - vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine)vibrationStates.get("mine"))); + vibrationStates.put("harvest", new VibrationStateHarvest((VibrationStateMine) vibrationStates.get("mine"))); vibrationStates.put("vitality", new VibrationStateVitality()); vibrationStates.put("xpChange", new VibrationStateXpChange()); vibrationStates.put("generic", new VibrationStateClient()); } - public static void afterConnect() - { + public static void afterConnect() { //setState(getStateCounter(), 5); - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); } - - private static double getIntensity() - { + + private static double getIntensity() { double intensity = 0; - for (Map.Entry state : vibrationStates.entrySet()) - { + for (Map.Entry state : vibrationStates.entrySet()) { intensity = Math.max(intensity, state.getValue().getIntensity()); // LOGGER.info(state.getKey() + ": " + state.getValue().getIntensity()); - + } return intensity / 100; } - - private static void tickAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void tickAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.onTick(); } } - - private static void resetAll() - { - for (AbstractVibrationState state : vibrationStates.values()) - { + + private static void resetAll() { + for (AbstractVibrationState state : vibrationStates.values()) { state.resetState(); } } - private static boolean isPlayer(Entity entity){ - try { - if (entity instanceof Player) { - Player player = (Player) entity;; - UUID uuid = player.getGameProfile().getId(); - return uuid.equals(playerId); + private static boolean isPlayer(Entity entity) { + try { + if (entity instanceof Player) { + Player player = (Player) entity; + ; + UUID uuid = player.getGameProfile().getId(); + return uuid.equals(playerId); + } + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - } return false; } @@ -116,26 +96,26 @@ private static void clearState() { @SubscribeEvent public static void onPlayerTick(PlayerTickEvent event) { try { - if (isPlayer(event.getEntity())) { - Player player = event.getEntity(); - - tickCounter = (tickCounter + 1) % 100; - - - if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) - { - tickAll(); - - ((VibrationStateVitality)vibrationStates.get("vitality")).onTick(player); - ((VibrationStateFish)vibrationStates.get("fish")).onTick(player); - - double newVibrationLevel = getIntensity(); - - if (ToyController.currentVibrationLevel != newVibrationLevel) - ToyController.setVibrationLevel(newVibrationLevel); - } + if (isPlayer(event.getEntity())) { + Player player = event.getEntity(); - } + tickCounter = (tickCounter + 1) % 100; + + + if (tickCounter % MinegasmConfig.tickFrequency == 0) // TODO: Add ticks per second config option (Default: Every tick) + { + tickAll(); + + ((VibrationStateVitality) vibrationStates.get("vitality")).onTick(player); + ((VibrationStateFish) vibrationStates.get("fish")).onTick(player); + + double newVibrationLevel = getIntensity(); + + if (ToyController.currentVibrationLevel != newVibrationLevel) + ToyController.setVibrationLevel(newVibrationLevel); + } + + } } catch (Throwable e) { LOGGER.throwing(e); } @@ -162,91 +142,75 @@ public static void onClientTick(ClientTickEvent event) { } @SubscribeEvent - public static void onAttack(AttackEntityEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAttack)vibrationStates.get("attack")).onAttack(); + public static void onAttack(AttackEntityEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAttack) vibrationStates.get("attack")).onAttack(); } } @SubscribeEvent - public static void onCriticalHit(CriticalHitEvent event) - { + public static void onCriticalHit(CriticalHitEvent event) { LOGGER.debug("Critical: " + event.isVanillaCritical()); } @SubscribeEvent - public static void onHurt(LivingDamageEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHurt)vibrationStates.get("hurt")).onHurt(); + public static void onHurt(LivingDamageEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHurt) vibrationStates.get("hurt")).onHurt(); } } @SubscribeEvent - public static void onBreak(BlockEvent.BreakEvent event) - { - if (isPlayer(event.getPlayer())) - { - ((VibrationStateMine)vibrationStates.get("mine")).onBreak(event.getState()); + public static void onBreak(BlockEvent.BreakEvent event) { + if (isPlayer(event.getPlayer())) { + ((VibrationStateMine) vibrationStates.get("mine")).onBreak(event.getState()); } } - + // Triggers when player starts to break block @SubscribeEvent - public static void onHarvest(PlayerEvent.HarvestCheck event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateHarvest)vibrationStates.get("harvest")).onHarvest(); + public static void onHarvest(PlayerEvent.HarvestCheck event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateHarvest) vibrationStates.get("harvest")).onHarvest(); } } - + @SubscribeEvent - public static void onPlace(BlockEvent.EntityPlaceEvent event){ - if (isPlayer(event.getEntity())) - { - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + public static void onPlace(BlockEvent.EntityPlaceEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } } - - public static void onPlace(){ - ((VibrationStatePlace)vibrationStates.get("place")).onPlace(); + + public static void onPlace() { + ((VibrationStatePlace) vibrationStates.get("place")).onPlace(); } @SubscribeEvent - public static void onXpPickup(PlayerXpEvent.PickupXp event) - { + public static void onXpPickup(PlayerXpEvent.PickupXp event) { //LOGGER.info("Pickup XP: " + event.getOrb().xpValue); } @SubscribeEvent - public static void onXpChange(PlayerXpEvent.XpChange event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateXpChange)vibrationStates.get("xpChange")).onXpChange(((Player)event.getEntity()).totalExperience, event.getAmount()); + public static void onXpChange(PlayerXpEvent.XpChange event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateXpChange) vibrationStates.get("xpChange")).onXpChange(((Player) event.getEntity()).totalExperience, event.getAmount()); } } - - + + @SubscribeEvent - public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) - { - if (isPlayer(event.getEntity())) - { - ((VibrationStateAdvancement)vibrationStates.get("advancement")).onAdvancement(event); + public static void onAdvancementEvent(AdvancementEvent.AdvancementEarnEvent event) { + if (isPlayer(event.getEntity())) { + ((VibrationStateAdvancement) vibrationStates.get("advancement")).onAdvancement(event); } } @SubscribeEvent - public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) - { + public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) { Entity entity = event.getEntity(); - if( !entity.level().isClientSide() ) { + if (!entity.level().isClientSide()) { return; } @@ -273,35 +237,37 @@ public static void onRespawn(PlayerEvent.PlayerRespawnEvent event) @SubscribeEvent public static void onWorldEntry(EntityJoinLevelEvent event) { Entity entity = event.getEntity(); - if( !entity.level().isClientSide() ) { + if (!entity.level().isClientSide()) { return; } - + if (ToyController.isConnected) return; if (entity instanceof Player) { LOGGER.info("Player respawn world: " + entity.toString()); - - new Thread(()-> { try { - Player player = (Player) entity; - UUID uuid = player.getGameProfile().getId(); - - if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { - LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); - LOGGER.info("Stealth: " + MinegasmConfig.stealth); - if (ToyController.connectDevice()) { - ((VibrationStateClient)vibrationStates.get("generic")).setVibration(5, 1); - if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + + new Thread(() -> { + try { + Player player = (Player) entity; + UUID uuid = player.getGameProfile().getId(); + + if (uuid.equals(Minecraft.getInstance().player.getGameProfile().getId())) { + LOGGER.info("Player in: " + player.getGameProfile().getName() + " " + player.getGameProfile().getId().toString()); + LOGGER.info("Stealth: " + MinegasmConfig.stealth); + if (ToyController.connectDevice()) { + ((VibrationStateClient) vibrationStates.get("generic")).setVibration(5, 1); + if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format("Connected to " + ChatFormatting.GREEN + "%s" + ChatFormatting.RESET + " [%d]", ToyController.getDeviceName(), ToyController.getDeviceId())), true); + } + } else if (!MinegasmConfig.stealth) { + player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); } - } else if (!MinegasmConfig.stealth){ - player.displayClientMessage(Component.literal(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start\n%s", ToyController.getLastErrorMessage())), false); + playerId = uuid; } - playerId = uuid; + } catch (Throwable e) { + LOGGER.throwing(e); } - } catch (Throwable e) { - LOGGER.throwing(e); - }}).start(); + }).start(); } } } diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ToyController.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ToyController.java index 4577128..7999ae4 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ToyController.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/client/ToyController.java @@ -9,22 +9,16 @@ import java.net.URI; import java.util.List; import java.util.Objects; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.Executors; +import java.util.concurrent.*; public class ToyController { private static final Logger LOGGER = LogManager.getLogger(); - private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); - private static ButtplugClientDevice device = null; - private static boolean shutDownHookAdded = false; public static String lastErrorMessage = ""; public static boolean isConnected = false; public static double currentVibrationLevel = 0; + private static ButtplugClientWSClient client = new ButtplugClientWSClient("Minegasm"); + private static ButtplugClientDevice device = null; + private static boolean shutDownHookAdded = false; public static boolean connectDevice() { try { @@ -40,9 +34,8 @@ public Void call() throws Exception { return null; } }); - - try - { + + try { future.get(3, TimeUnit.SECONDS); } catch (TimeoutException e) { future.cancel(true); @@ -51,7 +44,7 @@ public Void call() throws Exception { } finally { executor.shutdownNow(); } - + client.startScanning(); Thread.sleep(5000); diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java index 0ae06df..db103e1 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/AbstractVibrationState.java @@ -1,62 +1,33 @@ package com.therainbowville.minegasm.common; -import java.util.Map; -import java.util.HashMap; - import com.therainbowville.minegasm.config.ClientConfig; import com.therainbowville.minegasm.config.MinegasmConfig; - import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; // Architecture inspired from https://github.com/Fyustorm/mInetiface -public abstract class AbstractVibrationState -{ - +public abstract class AbstractVibrationState { + protected static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); protected final float streakCountdownAmount; protected float intensity; protected float vibrationCountdown; protected float vibrationFeedbackCountdown; - - protected AbstractVibrationState(float streakSeconds) - { + + protected AbstractVibrationState(float streakSeconds) { streakCountdownAmount = streakSeconds; vibrationCountdown = 0; vibrationFeedbackCountdown = 0; intensity = 0; } - - public void onTick() - { - if (accumulationEnabled()) - { - if (vibrationCountdown > 0) - vibrationCountdown--; - else if (intensity > 0) { - intensity = Math.max(0, intensity - 5); - vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; - } - } else { - vibrationCountdown = Math.max(0, vibrationCountdown - 1); - } - - vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); - } - - public void resetState() - { - vibrationCountdown = 0; - vibrationFeedbackCountdown = 0; - intensity = 0; - } - - protected static boolean accumulationEnabled() - { + + protected static boolean accumulationEnabled() { return MinegasmConfig.mode.equals(ClientConfig.GameplayMode.ACCUMULATION); } - + public static int getIntensity(String type) { Map normal = new HashMap<>(); normal.put("attack", 60); @@ -90,7 +61,7 @@ public static int getIntensity(String type) { hedonist.put("harvest", 20); hedonist.put("vitality", 10); hedonist.put("advancement", 100); - + Map accumulation = new HashMap<>(); accumulation.put("attack", 1); accumulation.put("hurt", 1); @@ -114,8 +85,7 @@ public static int getIntensity(String type) { custom.put("advancement", MinegasmConfig.advancementIntensity); - return switch (MinegasmConfig.mode) - { + return switch (MinegasmConfig.mode) { case NORMAL -> normal.get(type); case MASOCHIST -> masochist.get(type); case HEDONIST -> hedonist.get(type); @@ -123,6 +93,27 @@ public static int getIntensity(String type) { case CUSTOM -> custom.get(type); }; } - + + public void onTick() { + if (accumulationEnabled()) { + if (vibrationCountdown > 0) + vibrationCountdown--; + else if (intensity > 0) { + intensity = Math.max(0, intensity - 5); + vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; + } + } else { + vibrationCountdown = Math.max(0, vibrationCountdown - 1); + } + + vibrationFeedbackCountdown = Math.max(0, vibrationFeedbackCountdown - 1); + } + + public void resetState() { + vibrationCountdown = 0; + vibrationFeedbackCountdown = 0; + intensity = 0; + } + public abstract int getIntensity(); } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/Minegasm.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/Minegasm.java index 6be7cd7..b40eef8 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/Minegasm.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/Minegasm.java @@ -1,21 +1,15 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.ConfigHolder; import net.neoforged.fml.ModContainer; -import net.neoforged.neoforge.client.gui.IConfigScreenFactory; -import net.neoforged.neoforge.common.NeoForge; -import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.NeoForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.therainbowville.minegasm.config.ConfigHolder; -import com.therainbowville.minegasm.config.ConfigHelper; -import com.therainbowville.minegasm.config.ConfigScreen; - @Mod(Minegasm.MOD_ID) -public class Minegasm -{ +public class Minegasm { public static final String MOD_ID = "minegasm"; public static final String NAME = "Minegasm"; private static final Logger LOGGER = LogManager.getLogger(); diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java index 9f1037c..9eab9f6 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAdvancement.java @@ -1,40 +1,35 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementType; import net.neoforged.neoforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateAdvancement extends AbstractVibrationState -{ - public VibrationStateAdvancement() - { +public class VibrationStateAdvancement extends AbstractVibrationState { + public VibrationStateAdvancement() { super(0); } - - public void onAdvancement(AdvancementEarnEvent event) - { + + public void onAdvancement(AdvancementEarnEvent event) { if (getIntensity("advancement") == 0) return; - try { - LOGGER.info("Advancement Event: " + event); - Advancement advancement = event.getAdvancement().value(); - AdvancementType type = advancement.display().get().getType(); - int duration = switch (type) { - case TASK -> 5; - case GOAL -> 7; - case CHALLENGE -> 10; - }; + try { + LOGGER.info("Advancement Event: " + event); + Advancement advancement = event.getAdvancement().value(); + AdvancementType type = advancement.display().get().getType(); + int duration = switch (type) { + case TASK -> 5; + case GOAL -> 7; + case CHALLENGE -> 10; + }; - vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; - vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; - } catch (Throwable e) { + vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; + vibrationFeedbackCountdown = 1.5f * MinegasmConfig.ticksPerSecond; + } catch (Throwable e) { LOGGER.throwing(e); + } } - } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java index acd0375..e88e47a 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateAttack.java @@ -2,19 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateAttack extends AbstractVibrationState -{ - public VibrationStateAttack() - { +public class VibrationStateAttack extends AbstractVibrationState { + public VibrationStateAttack() { super(3); } - - public void onAttack() - { + + public void onAttack() { if (getIntensity("attack") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * 0; @@ -23,9 +19,8 @@ public void onAttack() vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } } - - public int getIntensity() - { + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java index c952b68..559ba3d 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateClient.java @@ -2,21 +2,17 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateClient extends AbstractVibrationState -{ - public VibrationStateClient() - { +public class VibrationStateClient extends AbstractVibrationState { + public VibrationStateClient() { super(0); } - - public void setVibration(int intensity, int durationSeconds) - { + + public void setVibration(int intensity, int durationSeconds) { intensity = intensity; vibrationCountdown = durationSeconds * MinegasmConfig.ticksPerSecond; } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return Math.toIntExact(Math.round(intensity)); else return 0; diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java index db66ed2..d55d5bb 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateFish.java @@ -1,35 +1,28 @@ package com.therainbowville.minegasm.common; +import com.therainbowville.minegasm.config.MinegasmConfig; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateFish extends AbstractVibrationState -{ - public VibrationStateFish() - { +public class VibrationStateFish extends AbstractVibrationState { + public VibrationStateFish() { super(0); } - - public void onTick(Player player) - { - if (player.fishing != null) - { + + public void onTick(Player player) { + if (player.fishing != null) { Vec3 vector = player.fishing.getDeltaMovement(); double x = vector.x(); double y = vector.y(); double z = vector.z(); - if (y < -0.075 && !player.level().getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) - { + if (y < -0.075 && !player.level().getFluidState(player.fishing.blockPosition()).isEmpty() && x == 0 && z == 0) { vibrationCountdown = 1.5f * MinegasmConfig.ticksPerSecond; LOGGER.info("Fishing!"); } } } - - public int getIntensity() - { + + public int getIntensity() { if (vibrationCountdown > 0) return getIntensity("fishing"); else return 0; diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java index 6b373cd..a4ed4a5 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHarvest.java @@ -1,32 +1,24 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - -import com.therainbowville.minegasm.config.MinegasmConfig; - -public class VibrationStateHarvest extends AbstractVibrationState -{ +public class VibrationStateHarvest extends AbstractVibrationState { private VibrationStateMine mineState; - - public VibrationStateHarvest(VibrationStateMine state) - { + + public VibrationStateHarvest(VibrationStateMine state) { super(0); mineState = state; } - public void onHarvest() { + public void onHarvest() { vibrationCountdown = 3; mineState.onHarvest(); - } - - public int getIntensity() - { - if (vibrationCountdown > 0){ + } + + public int getIntensity() { + if (vibrationCountdown > 0) { if (accumulationEnabled()) return Math.min(100, mineState.getIntensity() + 20); - else - return getIntensity("harvest"); - } - else return 0; + else + return getIntensity("harvest"); + } else return 0; } } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java index 7219c5e..117e19d 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateHurt.java @@ -2,18 +2,15 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateHurt extends AbstractVibrationState -{ - public VibrationStateHurt() - { +public class VibrationStateHurt extends AbstractVibrationState { + public VibrationStateHurt() { super(3); } - - public void onHurt() { + + public void onHurt() { if (getIntensity("hurt") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + 10); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; @@ -21,10 +18,9 @@ public void onHurt() { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java index e4c467d..5d1228e 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateMine.java @@ -1,22 +1,18 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.level.block.state.BlockState; - import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.level.block.state.BlockState; -public class VibrationStateMine extends AbstractVibrationState -{ - public VibrationStateMine() - { +public class VibrationStateMine extends AbstractVibrationState { + public VibrationStateMine() { super(5); } - - public void onBreak(BlockState block) { + + public void onBreak(BlockState block) { if (getIntensity("mine") == 0) return; - + String blockName = block.getBlock().getName().getString(); - if (accumulationEnabled()) - { + if (accumulationEnabled()) { if (blockName.contains("Ore")) { intensity = Math.min(100, intensity + 1); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; @@ -29,19 +25,18 @@ public void onBreak(BlockState block) { if (blockName.contains("Ore")) { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; - } else + } else vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public void onHarvest() { - if (accumulationEnabled()){ + } + + public void onHarvest() { + if (accumulationEnabled()) { vibrationCountdown = Math.max(3, vibrationCountdown); } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java index aee4ebf..0ba025c 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStatePlace.java @@ -2,28 +2,24 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStatePlace extends AbstractVibrationState -{ - public VibrationStatePlace() - { +public class VibrationStatePlace extends AbstractVibrationState { + public VibrationStatePlace() { super(5); } - - public void onPlace() { + + public void onPlace() { if (getIntensity("place") == 0) return; - - if (accumulationEnabled()) - { + + if (accumulationEnabled()) { intensity = Math.min(100, intensity + .5f); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { vibrationCountdown = 3 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java index 5824f8f..6892ceb 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateVitality.java @@ -1,31 +1,27 @@ package com.therainbowville.minegasm.common; -import net.minecraft.world.entity.player.Player; - -import com.therainbowville.minegasm.config.MinegasmConfig; import com.therainbowville.minegasm.config.ClientConfig; +import com.therainbowville.minegasm.config.MinegasmConfig; +import net.minecraft.world.entity.player.Player; -public class VibrationStateVitality extends AbstractVibrationState -{ +public class VibrationStateVitality extends AbstractVibrationState { private int intensityCooldown; private boolean targetMet; - - public VibrationStateVitality() - { + + public VibrationStateVitality() { super(1); intensityCooldown = 0; targetMet = false; } - - public void onTick(Player player) - { + + public void onTick(Player player) { float playerHealth = player.getHealth(); float playerFoodLevel = player.getFoodData().getFoodLevel(); - - if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1 ) - || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20) ){ - if (targetMet == false){ + if ((MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth > 0 && playerHealth <= 1) + || (!MinegasmConfig.mode.equals(ClientConfig.GameplayMode.MASOCHIST) && playerHealth >= 20 && playerFoodLevel >= 20)) { + + if (targetMet == false) { targetMet = true; vibrationFeedbackCountdown = 3 * MinegasmConfig.ticksPerSecond; } @@ -45,13 +41,12 @@ public void onTick(Player player) vibrationCountdown = 1; } } - - public int getIntensity() - { + + public int getIntensity() { if (getIntensity("vitality") == 0) return 0; - + //if (accumulationEnabled()) - //return Math.toIntExact(Math.round(intensity)); + //return Math.toIntExact(Math.round(intensity)); //else if (vibrationFeedbackCountdown > 0) return Math.min(100, getIntensity("vitality") + 20); diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java index 34b1633..4b3fec6 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/common/VibrationStateXpChange.java @@ -2,45 +2,41 @@ import com.therainbowville.minegasm.config.MinegasmConfig; -public class VibrationStateXpChange extends AbstractVibrationState -{ - private int lastLevel; - - public VibrationStateXpChange() - { +public class VibrationStateXpChange extends AbstractVibrationState { + private int lastLevel; + + public VibrationStateXpChange() { super(1); lastLevel = -1; } - + // Code adapted from https://github.com/Fyustorm/mInetiface - public void onXpChange(int level, int amount) { + public void onXpChange(int level, int amount) { if (amount == 0 || getIntensity("xpChange") == 0) return; - - if (lastLevel == -1) { - lastLevel = level; - } - if (lastLevel != level) { - amount *= 2; - } + if (lastLevel == -1) { + lastLevel = level; + } + + if (lastLevel != level) { + amount *= 2; + } - lastLevel = level; + lastLevel = level; - if (accumulationEnabled()) - { + if (accumulationEnabled()) { intensity = Math.min(100, intensity + amount / 5); vibrationCountdown = streakCountdownAmount * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } else { - int duration = Math.toIntExact( Math.round( Math.ceil( Math.log(amount + 0.5) ) ) ); + int duration = Math.toIntExact(Math.round(Math.ceil(Math.log(amount + 0.5)))); vibrationCountdown = duration * MinegasmConfig.ticksPerSecond; vibrationFeedbackCountdown = 1 * MinegasmConfig.ticksPerSecond; } - } - - public int getIntensity() - { + } + + public int getIntensity() { if (accumulationEnabled()) return Math.toIntExact(Math.round(intensity)); else if (vibrationFeedbackCountdown > 0) diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java index bd0c785..41dae82 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ClientConfig.java @@ -6,13 +6,24 @@ import java.util.Objects; public final class ClientConfig { + static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; + static final boolean DEFAULT_VIBRATE = true; + static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; + static final boolean DEFAULT_STEALTH = false; + static final int DEFAULT_ATTACK_INTENSITY = 60; + static final int DEFAULT_HURT_INTENSITY = 0; + static final int DEFAULT_MINE_INTENSITY = 80; + static final int DEFAULT_PLACE_INTENSITY = 20; + static final int DEFAULT_XP_CHANGE_INTENSITY = 100; + static final int DEFAULT_FISHING_INTENSITY = 50; + static final int DEFAULT_HARVEST_INTENSITY = 0; + static final int DEFAULT_VITALITY_INTENSITY = 0; + static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; final ModConfigSpec.ConfigValue serverUrl; - final ModConfigSpec.BooleanValue vibrate; final ModConfigSpec.EnumValue mode; final ModConfigSpec.BooleanValue stealth; final ModConfigSpec.EnumValue tickFrequency; - final ModConfigSpec.IntValue attackIntensity; final ModConfigSpec.IntValue hurtIntensity; final ModConfigSpec.IntValue mineIntensity; @@ -22,22 +33,7 @@ public final class ClientConfig { final ModConfigSpec.IntValue harvestIntensity; final ModConfigSpec.IntValue vitalityIntensity; final ModConfigSpec.IntValue advancementIntensity; - - static final String DEFAULT_SERVER_URL = "ws://localhost:12345/buttplug"; - static final boolean DEFAULT_VIBRATE = true; - static final GameplayMode DEFAULT_MODE = GameplayMode.NORMAL; - static final boolean DEFAULT_STEALTH = false; - - static final int DEFAULT_ATTACK_INTENSITY = 60; - static final int DEFAULT_HURT_INTENSITY = 0; - static final int DEFAULT_MINE_INTENSITY = 80; - static final int DEFAULT_PLACE_INTENSITY = 20; - static final int DEFAULT_XP_CHANGE_INTENSITY = 100; - static final int DEFAULT_FISHING_INTENSITY = 50; - static final int DEFAULT_HARVEST_INTENSITY = 0; - static final int DEFAULT_VITALITY_INTENSITY = 0; - static final int DEFAULT_ADVANCEMENT_INTENSITY = 100; - + ClientConfig(final ModConfigSpec.Builder builder) { builder.push("buttplug"); @@ -59,7 +55,7 @@ public final class ClientConfig { stealth = builder .translation(Minegasm.MOD_ID + ".config.stealth") .define("stealth", DEFAULT_STEALTH); - + tickFrequency = builder .translation(Minegasm.MOD_ID + ".config.mode") .defineEnum("tickFrequency", TickFrequencyOptions.EVERY_TICK); @@ -80,7 +76,7 @@ public final class ClientConfig { .comment("Vibration intensity when mining on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.mine") .defineInRange("mineIntensity", DEFAULT_MINE_INTENSITY, 0, 100); - + placeIntensity = builder .comment("Vibration intensity when placing blocks on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.place") @@ -90,7 +86,7 @@ public final class ClientConfig { .comment("Vibration intensity when gaining XP on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.xp_change") .defineInRange("xpChangeIntensity", DEFAULT_XP_CHANGE_INTENSITY, 0, 100); - + fishingIntensity = builder .comment("Vibration intensity when fishing on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.fishing") @@ -105,7 +101,7 @@ public final class ClientConfig { .comment("Vibration intensity on high level of player's vitality on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.vitality") .defineInRange("vitalityIntensity", DEFAULT_VITALITY_INTENSITY, 0, 100); - + advancementIntensity = builder .comment("Vibration intensity on achieving advancement on custom mode") .translation(Minegasm.MOD_ID + ".config.intensity.advancement") @@ -114,14 +110,12 @@ public final class ClientConfig { builder.pop(); builder.pop(); } - - public void resetConfigUrl() - { + + public void resetConfigUrl() { ConfigHolder.CLIENT.serverUrl.set(DEFAULT_SERVER_URL); } - - public void resetConfigCustom() - { + + public void resetConfigCustom() { ConfigHolder.CLIENT.attackIntensity.set(DEFAULT_ATTACK_INTENSITY); ConfigHolder.CLIENT.hurtIntensity.set(DEFAULT_HURT_INTENSITY); ConfigHolder.CLIENT.mineIntensity.set(DEFAULT_MINE_INTENSITY); @@ -132,7 +126,7 @@ public void resetConfigCustom() ConfigHolder.CLIENT.vitalityIntensity.set(DEFAULT_VITALITY_INTENSITY); ConfigHolder.CLIENT.advancementIntensity.set(DEFAULT_ADVANCEMENT_INTENSITY); } - + public enum GameplayMode { NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"), MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"), @@ -151,30 +145,24 @@ public String getTranslateKey() { return this.translateKey; } } - + public enum TickFrequencyOptions { - EVERY_TICK(1), - EVERY_OTHER_TICK(2), - EVERY_5_TICKS(5), - EVERY_10_TICKS(10), - EVERY_20_TICKS(20), - EVERY_30_TICKS(30), - EVERY_40_TICKS(40), + EVERY_TICK(1), + EVERY_OTHER_TICK(2), + EVERY_5_TICKS(5), + EVERY_10_TICKS(10), + EVERY_20_TICKS(20), + EVERY_30_TICKS(30), + EVERY_40_TICKS(40), EVERY_50_TICKS(50); - + private int value; - + TickFrequencyOptions(int value) { this.value = value; } - - public int getInt() - { - return value; - } - - public static TickFrequencyOptions fromInt(int value) - { + + public static TickFrequencyOptions fromInt(int value) { for (TickFrequencyOptions type : values()) { if (type.getInt() == value) { return type; @@ -182,6 +170,10 @@ public static TickFrequencyOptions fromInt(int value) } return null; } + + public int getInt() { + return value; + } } - + } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java index 33bfaf2..338ef58 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHelper.java @@ -13,7 +13,7 @@ public static void bakeClient() { MinegasmConfig.stealth = ConfigHolder.CLIENT.stealth.get(); MinegasmConfig.tickFrequency = ConfigHolder.CLIENT.tickFrequency.get().getInt(); MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - + MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get(); MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get(); MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get(); @@ -27,13 +27,12 @@ public static void bakeClient() { public static void bakeServer() { } - - public static void saveClient() - { - try{ - - MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); - + + public static void saveClient() { + try { + + MinegasmConfigBuffer buffer = new MinegasmConfigBuffer(); + // Field[] fields = MinegasmConfigBuffer.class.getFields(); // for (Field field : fields) @@ -44,24 +43,23 @@ public static void saveClient() // LOGGER.info(method); // method.invoke(configField.get(ConfigHolder.CLIENT), field.get(buffer)); // } - - ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); - ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); - ConfigHolder.CLIENT.mode.set(buffer.mode); - ConfigHolder.CLIENT.stealth.set(buffer.stealth); - ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); - - ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); - ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); - ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); - ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); - ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); - ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); - ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); - ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); - ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); - } catch (Throwable e) - { + + ConfigHolder.CLIENT.serverUrl.set(buffer.serverUrl); + ConfigHolder.CLIENT.vibrate.set(buffer.vibrate); + ConfigHolder.CLIENT.mode.set(buffer.mode); + ConfigHolder.CLIENT.stealth.set(buffer.stealth); + ConfigHolder.CLIENT.tickFrequency.set(ClientConfig.TickFrequencyOptions.fromInt(buffer.tickFrequency)); + + ConfigHolder.CLIENT.attackIntensity.set(buffer.attackIntensity); + ConfigHolder.CLIENT.hurtIntensity.set(buffer.hurtIntensity); + ConfigHolder.CLIENT.mineIntensity.set(buffer.mineIntensity); + ConfigHolder.CLIENT.placeIntensity.set(buffer.placeIntensity); + ConfigHolder.CLIENT.xpChangeIntensity.set(buffer.xpChangeIntensity); + ConfigHolder.CLIENT.fishingIntensity.set(buffer.fishingIntensity); + ConfigHolder.CLIENT.harvestIntensity.set(buffer.harvestIntensity); + ConfigHolder.CLIENT.vitalityIntensity.set(buffer.vitalityIntensity); + ConfigHolder.CLIENT.advancementIntensity.set(buffer.advancementIntensity); + } catch (Throwable e) { LOGGER.info(e); } } diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java index de8216c..5b721d2 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigHolder.java @@ -9,6 +9,7 @@ public final class ConfigHolder { public static final ModConfigSpec SERVER_SPEC; static final ClientConfig CLIENT; static final ServerConfig SERVER; + static { { final Pair specPair = new ModConfigSpec.Builder().configure(ClientConfig::new); diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java index a116e10..28d95eb 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/ConfigScreen.java @@ -23,15 +23,15 @@ public class ConfigScreen extends Screen { private static final Logger LOGGER = LogManager.getLogger(); private final Screen previous; - private boolean pauseMenu; EditBox wsHost = null; + private boolean pauseMenu; public ConfigScreen(Screen previous) { super(Component.literal("Minegasm Config")); this.previous = previous; pauseMenu = false; } - + public ConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Config")); this.previous = previous; @@ -43,29 +43,29 @@ protected void init() { wsHost = new EditBox(Minecraft.getInstance().font, this.width / 2 - 100, this.height / 6, 200, 20, null); wsHost.setValue(MinegasmConfig.serverUrl); this.addRenderableWidget(wsHost); - + wsHost.setResponder(s -> { LOGGER.info(s); MinegasmConfig.serverUrl = s; - }); - + }); + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Server Url"), button -> { - ConfigHolder.getClientInstance().resetConfigUrl(); - MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); - wsHost.setValue(MinegasmConfig.serverUrl); - }).pos(this.width / 2 - 155, this.height / 6 + 25) - .size(150, 20) - .build() + ConfigHolder.getClientInstance().resetConfigUrl(); + MinegasmConfig.serverUrl = ConfigHolder.getClientInstance().serverUrl.get(); + wsHost.setValue(MinegasmConfig.serverUrl); + }).pos(this.width / 2 - 155, this.height / 6 + 25) + .size(150, 20) + .build() ); - + PlainTextLabel connectResponse = new PlainTextLabel(this.width / 2 - 155, this.height / 6 + 50, 310, 15, Component.literal("" + ChatFormatting.GREEN)); this.addRenderableWidget(connectResponse); - + Button reconnectButton = new Button.Builder(Component.literal("Reconnect"), button -> { - button.active = false; - connectResponse.setValue("Connecting"); - new Thread(() -> { + button.active = false; + connectResponse.setValue("Connecting"); + new Thread(() -> { if (ToyController.connectDevice()) { ClientEventHandler.afterConnect(); button.active = true; @@ -74,78 +74,78 @@ protected void init() { button.active = true; connectResponse.setValue(String.format(ChatFormatting.YELLOW + "Minegasm " + ChatFormatting.RESET + "failed to start: %s", ToyController.getLastErrorMessage())); } - - }).start(); - }) - .pos(this.width / 2 + 5, this.height / 6 + 25) - .size(150, 20) - .build(); - + + }).start(); + }) + .pos(this.width / 2 + 5, this.height / 6 + 25) + .size(150, 20) + .build(); + this.addRenderableWidget(reconnectButton); - + reconnectButton.active = pauseMenu; - + this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.vibrate) - .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); + .create(this.width / 2 - 155, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Vibration"), (button, value) -> MinegasmConfig.vibrate = value)); this.addRenderableWidget(CycleButton.onOffBuilder(MinegasmConfig.stealth) - .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, - Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); + .create(this.width / 2 + 5, this.height / 6 + 25 * 3, 150, 20, + Component.literal("Stealth"), (button, value) -> MinegasmConfig.stealth = value)); this.addRenderableWidget( - CycleButton.builder((ClientConfig.GameplayMode mode) -> - Component.literal(switch (mode) { - case NORMAL -> "Normal"; - case MASOCHIST -> "Masochist"; - case HEDONIST -> "Hedonist"; - case ACCUMULATION -> "Accumulation"; - case CUSTOM -> "Custom"; - })) - .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) - .withInitialValue(MinegasmConfig.mode) - .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, - Component.literal("Mode"), (button, value) -> { - MinegasmConfig.mode = value; - }) + CycleButton.builder((ClientConfig.GameplayMode mode) -> + Component.literal(switch (mode) { + case NORMAL -> "Normal"; + case MASOCHIST -> "Masochist"; + case HEDONIST -> "Hedonist"; + case ACCUMULATION -> "Accumulation"; + case CUSTOM -> "Custom"; + })) + .withValues(ClientConfig.GameplayMode.NORMAL, ClientConfig.GameplayMode.MASOCHIST, ClientConfig.GameplayMode.HEDONIST, ClientConfig.GameplayMode.ACCUMULATION, ClientConfig.GameplayMode.CUSTOM) + .withInitialValue(MinegasmConfig.mode) + .create(this.width / 2 - 155, this.height / 6 + 25 * 4, 150, 20, + Component.literal("Mode"), (button, value) -> { + MinegasmConfig.mode = value; + }) ); - this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) - .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) - .size(150, 20) - .build() + this.addRenderableWidget(new Button.Builder(Component.literal("Edit Custom Settings"), button -> minecraft.setScreen(new CustomModeConfigScreen(this, pauseMenu))) + .pos(this.width / 2 + 5, this.height / 6 + 25 * 4) + .size(150, 20) + .build() ); this.addRenderableWidget( - CycleButton.builder((Integer tickFrequency) -> - Component.literal(switch (tickFrequency) { - case 1 -> "Every Tick"; - case 2 -> "Every Other Tick"; - case 5 -> "Every 5 Ticks"; - case 10 -> "Every 10 Ticks"; - case 20 -> "Every Second"; - default -> "Every " + Float.toString(tickFrequency / 20f)+ " Seconds"; - })) - .withValues(1, 2, 5, 10, 20, 30, 40, 50) - .withInitialValue(MinegasmConfig.tickFrequency) - .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, - Component.literal("Tick Frequency"), (button, value) -> { - MinegasmConfig.tickFrequency = value; - MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); - LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); - } - ) + CycleButton.builder((Integer tickFrequency) -> + Component.literal(switch (tickFrequency) { + case 1 -> "Every Tick"; + case 2 -> "Every Other Tick"; + case 5 -> "Every 5 Ticks"; + case 10 -> "Every 10 Ticks"; + case 20 -> "Every Second"; + default -> "Every " + Float.toString(tickFrequency / 20f) + " Seconds"; + })) + .withValues(1, 2, 5, 10, 20, 30, 40, 50) + .withInitialValue(MinegasmConfig.tickFrequency) + .create(this.width / 2 - 100, this.height / 6 + 25 * 5, 200, 20, + Component.literal("Tick Frequency"), (button, value) -> { + MinegasmConfig.tickFrequency = value; + MinegasmConfig.ticksPerSecond = Math.max(0, 20f / MinegasmConfig.tickFrequency); + LOGGER.info("TPS: " + MinegasmConfig.ticksPerSecond); + } + ) ); this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 - 100, this.height - 27) - .size(200, 20) - .build() + .pos(this.width / 2 - 100, this.height - 27) + .size(200, 20) + .build() ); - + } - + @Override public void tick() { super.tick(); @@ -171,9 +171,9 @@ public void render(GuiGraphics graphics, int i, int j, float f) { graphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(graphics, i, j, f); } - + class PlainTextLabel extends AbstractWidget { - + private static Component text = Component.literal(""); private int x; private int y; @@ -184,11 +184,10 @@ public PlainTextLabel(int x, int y, int width, int height, Component text) { this.y = y; } - public static void setValue(String value) - { + public static void setValue(String value) { text = Component.literal(value); } - + @Override public void updateWidgetNarration(NarrationElementOutput output) { defaultButtonNarrationText(output); @@ -198,13 +197,13 @@ public void updateWidgetNarration(NarrationElementOutput output) { public void renderWidget(GuiGraphics graphics, int i, int j, float f) { if (text == null || text.getString().isEmpty()) return; - + // RenderSystem.setShaderColor(1, 1, 1, 1); // Minecraft.getInstance().font.draw(poseStack, text.getString(), x, y, 0xFFFFFF); graphics.drawCenteredString(Minecraft.getInstance().font, text.getString(), Minecraft.getInstance().screen.width / 2, this.y + this.height / 4, 0xFFFFFF); } } - + } class CustomModeConfigScreen extends Screen { @@ -217,7 +216,7 @@ public CustomModeConfigScreen(Screen previous) { this.previous = previous; pauseMenu = false; } - + public CustomModeConfigScreen(Screen previous, boolean pause) { super(Component.literal("Minegasm Custom Config")); this.previous = previous; @@ -226,52 +225,52 @@ public CustomModeConfigScreen(Screen previous, boolean pause) { @Override protected void init() { - try{ - this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) - .pos(this.width / 2 + 5, this.height - 27) - .size(150, 20) - .build() - ); + try { + this.addRenderableWidget(new Button.Builder(CommonComponents.GUI_DONE, button -> this.onClose()) + .pos(this.width / 2 + 5, this.height - 27) + .size(150, 20) + .build() + ); + + IntensitiySliderBar.sliders.clear(); + + // Attack + this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); + + // Hurt + this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); + + // Mine + this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); + + // Place + this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); + + // XP Change + this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); + + // Fishing + this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); + + // Harvest + this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); + + // Vitality + this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); + + // Advancement + this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); + + this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { + ConfigHolder.getClientInstance().resetConfigCustom(); + IntensitiySliderBar.refreshAllValues(); + }) + .pos(this.width / 2 - 155, this.height - 27) + .size(150, 20) + .build() + ); - IntensitiySliderBar.sliders.clear(); - // Attack - this.addRenderableWidget(new IntensitiySliderBar(this, "Attack: ", MinegasmConfig.class.getField("attackIntensity"))); - - // Hurt - this.addRenderableWidget(new IntensitiySliderBar(this, "Hurt: ", MinegasmConfig.class.getField("hurtIntensity"))); - - // Mine - this.addRenderableWidget(new IntensitiySliderBar(this, "Mine: ", MinegasmConfig.class.getField("mineIntensity"))); - - // Place - this.addRenderableWidget(new IntensitiySliderBar(this, "Place: ", MinegasmConfig.class.getField("placeIntensity"))); - - // XP Change - this.addRenderableWidget(new IntensitiySliderBar(this, "XP Change: ", MinegasmConfig.class.getField("xpChangeIntensity"))); - - // Fishing - this.addRenderableWidget(new IntensitiySliderBar(this, "Fishing: ", MinegasmConfig.class.getField("fishingIntensity"))); - - // Harvest - this.addRenderableWidget(new IntensitiySliderBar(this, "Harvest: ", MinegasmConfig.class.getField("harvestIntensity"))); - - // Vitality - this.addRenderableWidget(new IntensitiySliderBar(this, "Vitality: ", MinegasmConfig.class.getField("vitalityIntensity"))); - - // Advancement - this.addRenderableWidget(new IntensitiySliderBar(this, "Advancement: ", MinegasmConfig.class.getField("advancementIntensity"))); - - this.addRenderableWidget(new Button.Builder(Component.literal("Reset Values"), button -> { - ConfigHolder.getClientInstance().resetConfigCustom(); - IntensitiySliderBar.refreshAllValues(); - }) - .pos(this.width / 2 - 155, this.height - 27) - .size(150, 20) - .build() - ); - - } catch (Throwable e) { LOGGER.throwing(e); } @@ -292,28 +291,31 @@ public void render(GuiGraphics graphics, int i, int j, float f) { graphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 0xFFFFFF); super.render(graphics, i, j, f); } - - private class IntensitiySliderBar extends ExtendedSlider - { + + private class IntensitiySliderBar extends ExtendedSlider { public static ArrayList sliders = new ArrayList(); private Field fieldReference; - - IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception - { - super( parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos - parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2), // y pos - 150, 20, // Width, height - Component.literal(prefix), // Prefix - Component.literal(""), // Suffix - 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring + + IntensitiySliderBar(CustomModeConfigScreen parent, String prefix, Field field) throws Exception { + super(parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155), // x pos + parent.height / 6 + 25 * (int) Math.floor(sliders.size() / 2), // y pos + 150, 20, // Width, height + Component.literal(prefix), // Prefix + Component.literal(""), // Suffix + 0, 100, field.getInt(null), 1, 1, true); // Min, Max, Default value, stepsize, percision, drawstring fieldReference = field; // LOGGER.info("S: " + sliders.size() + " X: " + parent.width / 2 + (sliders.size() % 2 == 1 ? 5 : -155) + " Y: " + parent.height / 6 + 25 * (int)Math.floor(sliders.size() / 2)); sliders.add(this); } - + + public static void refreshAllValues() { + for (IntensitiySliderBar slider : sliders) { + slider.refreshValue(); + } + } + @Override - public void applyValue() - { + public void applyValue() { // LOGGER.info("applyValue"); //responder.accept(this.getValueInt()); try { @@ -323,22 +325,13 @@ public void applyValue() } } - public static void refreshAllValues() - { - for (IntensitiySliderBar slider : sliders) - { - slider.refreshValue(); - } - } - - private void refreshValue() - { + private void refreshValue() { try { this.setValue(fieldReference.getInt(null)); } catch (Throwable e) { LOGGER.throwing(e); } } - + } } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java index cbbdc63..8ebd69f 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/MinegasmConfig.java @@ -3,12 +3,11 @@ import com.therainbowville.minegasm.common.Minegasm; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.config.ModConfigEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import net.neoforged.fml.common.EventBusSubscriber; @EventBusSubscriber(modid = Minegasm.MOD_ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) @@ -23,7 +22,7 @@ public class MinegasmConfig { public static boolean stealth; public static int tickFrequency; public static float ticksPerSecond; - + public static int attackIntensity; public static int hurtIntensity; public static int mineIntensity; @@ -49,23 +48,21 @@ public static void onModConfigEvent(final ModConfigEvent event) { LOGGER.debug("Baked server config"); } } - - public static void save() - { + + public static void save() { ConfigHelper.saveClient(); } - + } -class MinegasmConfigBuffer -{ +class MinegasmConfigBuffer { public String serverUrl; public boolean vibrate; public ClientConfig.GameplayMode mode = ClientConfig.GameplayMode.NORMAL; public boolean stealth; public int tickFrequency; - + public int attackIntensity; public int hurtIntensity; public int mineIntensity; @@ -75,15 +72,14 @@ class MinegasmConfigBuffer public int harvestIntensity; public int vitalityIntensity; public int advancementIntensity; - - MinegasmConfigBuffer() - { + + MinegasmConfigBuffer() { this.serverUrl = MinegasmConfig.serverUrl; this.vibrate = MinegasmConfig.vibrate; this.mode = MinegasmConfig.mode; this.stealth = MinegasmConfig.stealth; this.tickFrequency = MinegasmConfig.tickFrequency; - + this.attackIntensity = MinegasmConfig.attackIntensity; this.hurtIntensity = MinegasmConfig.hurtIntensity; this.mineIntensity = MinegasmConfig.mineIntensity; diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java index 8956e56..f46963f 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/config/PauseMenuButton.java @@ -11,10 +11,9 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ScreenEvent; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; import org.apache.commons.lang3.mutable.MutableObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -24,61 +23,61 @@ import java.util.stream.Collectors; // Adapted from https://github.com/Creators-of-Create/Create/ -public class PauseMenuButton extends Button -{ +public class PauseMenuButton extends Button { private static final Logger LOGGER = LogManager.getLogger(); private static ResourceLocation LOGO = ResourceLocation.fromNamespaceAndPath(Minegasm.MOD_ID, "textures/logo.png"); - + int xPos; int yPos; - + public PauseMenuButton(int x, int y) { super(new Builder(Component.literal(""), PauseMenuButton::clicked).pos(x, y).size(20, 20)); xPos = x; yPos = y; } - + + public static void clicked(Button button) { + Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); + } + @Override public void renderWidget(GuiGraphics graphics, int i, int j, float k) { super.renderWidget(graphics, i, j, k); graphics.pose().pushPose(); - graphics.pose().translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); + graphics.pose().translate(xPos + width / 2 - (64 * 0.25f) / 2, yPos + height / 2 - (64 * 0.25f) / 2, 0); graphics.pose().scale(0.25f, 0.25f, 1); RenderSystem.setShaderTexture(0, LOGO); graphics.blit(LOGO, 0, 0, 0, 0, 64, 64, 64, 64); graphics.pose().popPose(); } - - public static void clicked(Button button) - { - Minecraft.getInstance().setScreen(new ConfigScreen(Minecraft.getInstance().screen, true)); - } - + public static class SingleMenuRow { public final String left, right; + public SingleMenuRow(String left, String right) { this.left = I18n.get(left); this.right = I18n.get(right); } + public SingleMenuRow(String center) { this(center, center); } } - + public static class MenuRows { public static final MenuRows MAIN_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.singleplayer"), - new SingleMenuRow("menu.multiplayer"), - new SingleMenuRow("fml.menu.mods", "menu.online"), - new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") + new SingleMenuRow("menu.singleplayer"), + new SingleMenuRow("menu.multiplayer"), + new SingleMenuRow("fml.menu.mods", "menu.online"), + new SingleMenuRow("narrator.button.language", "narrator.button.accessibility") )); public static final MenuRows INGAME_MENU = new MenuRows(Arrays.asList( - new SingleMenuRow("menu.returnToGame"), - new SingleMenuRow("gui.advancements", "gui.stats"), - new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), - new SingleMenuRow("menu.options", "menu.shareToLan"), - new SingleMenuRow("menu.returnToMenu") + new SingleMenuRow("menu.returnToGame"), + new SingleMenuRow("gui.advancements", "gui.stats"), + new SingleMenuRow("menu.sendFeedback", "menu.reportBugs"), + new SingleMenuRow("menu.options", "menu.shareToLan"), + new SingleMenuRow("menu.returnToMenu") )); protected final List leftButtons, rightButtons; @@ -88,13 +87,13 @@ public MenuRows(List variants) { rightButtons = variants.stream().map(r -> r.right).collect(Collectors.toList()); } } - + @EventBusSubscriber(modid = Minegasm.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class PauseMenuButtonScreen { - + @SubscribeEvent public static void onGuiInit(ScreenEvent.Init event) { - if(event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu + if (event.getScreen() instanceof PauseScreen) { // Make sure GUI is Escape menu MenuRows menu = MenuRows.INGAME_MENU; int rowIdx = 3; int offsetX = 4; @@ -104,15 +103,15 @@ public static void onGuiInit(ScreenEvent.Init event) { int offsetX_ = offsetX; MutableObject toAdd = new MutableObject<>(null); event.getListenersList() - .stream() - .filter(w -> w instanceof AbstractWidget) - .map(w -> (AbstractWidget) w) - .filter(w -> w.getMessage() - .getString() - .equals(target)) - .findFirst() - .ifPresent(w -> toAdd - .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); + .stream() + .filter(w -> w instanceof AbstractWidget) + .map(w -> (AbstractWidget) w) + .filter(w -> w.getMessage() + .getString() + .equals(target)) + .findFirst() + .ifPresent(w -> toAdd + .setValue(new PauseMenuButton(w.getX() + offsetX_ + (onLeft ? -20 : w.getWidth()), w.getY()))); if (toAdd.getValue() != null) event.addListener(toAdd.getValue()); } diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java index dccb310..ad00030 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/ClientAdvancementsMixin.java @@ -1,14 +1,13 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientAdvancements; -import net.minecraft.world.entity.player.Player; import net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket; import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.common.NeoForge; +import net.minecraft.world.entity.player.Player; import net.neoforged.neoforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,15 +20,17 @@ @Mixin(ClientAdvancements.class) public class ClientAdvancementsMixin { - private static Logger LOGGER = LogManager.getLogger(); private static final Minecraft minecraft = Minecraft.getInstance(); + private static Logger LOGGER = LogManager.getLogger(); @Inject(method = "update", at = @At("HEAD"), cancellable = true) public void onUpdate(ClientboundUpdateAdvancementsPacket advancementInfoPacket, CallbackInfo ci) { - if (Minecraft.getInstance().isLocalServer()) { return; } + if (Minecraft.getInstance().isLocalServer()) { + return; + } LOGGER.info("Advancement updated"); - for(Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { + for (Map.Entry entry : advancementInfoPacket.getProgress().entrySet()) { if (entry.getValue().isDone()) { AdvancementHolder advancement = ((ClientAdvancements) (Object) this).get(entry.getKey()); Player player = minecraft.player; diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java index bcb7704..16ef2a8 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/LocalPlayerMixin.java @@ -1,16 +1,12 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.damagesource.DamageSource; - import net.neoforged.neoforge.common.damagesource.DamageContainer; -import net.neoforged.neoforge.event.entity.living.LivingHealEvent; import net.neoforged.neoforge.event.entity.living.LivingDamageEvent; import net.neoforged.neoforge.event.entity.player.PlayerXpEvent.XpChange; - -import net.neoforged.neoforge.common.NeoForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -33,8 +29,10 @@ public void onHeal(float amount, CallbackInfo ci) { @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) public void onHurt(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (amount > 0) { LivingDamageEvent event = new LivingDamageEvent.Post((LocalPlayer) (Object) this, new DamageContainer(source, amount)); ClientEventHandler.onHurt(event); @@ -42,14 +40,15 @@ public void onHurt(DamageSource source, float amount, CallbackInfoReturnable 0) - { + if (amount > 0) { XpChange event = new XpChange((LocalPlayer) (Object) this, amount); - ClientEventHandler.onXpChange(event); + ClientEventHandler.onXpChange(event); } } } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java index 88f4547..ca11a3e 100644 --- a/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java +++ b/neoforge/ng-7.0/1.21/src/main/java/com/therainbowville/minegasm/mixin/MultiPlayerGameModeMixin.java @@ -1,21 +1,16 @@ package com.therainbowville.minegasm.mixin; -import com.therainbowville.minegasm.client.ClientEventHandler; - -import net.neoforged.neoforge.event.level.BlockEvent.BreakEvent; -import net.minecraft.core.BlockPos; +import com.therainbowville.minegasm.client.ClientEventHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.world.entity.player.Player; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.BlockHitResult; - +import net.neoforged.neoforge.event.level.BlockEvent.BreakEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; @@ -26,13 +21,15 @@ @Mixin(MultiPlayerGameMode.class) public class MultiPlayerGameModeMixin { private static Logger LOGGER = LogManager.getLogger(); - + boolean placedBlock; @Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true) public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer()) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + Player player = Minecraft.getInstance().player; if (player != null) { BreakEvent event = new BreakEvent(player.level(), blockPos, player.level().getBlockState(blockPos), player); @@ -42,18 +39,22 @@ public void onDestroyBlock(BlockPos blockPos, CallbackInfoReturnable ci @Inject(method = "performUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"), cancellable = true) public void onUseItemOn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() ) { return; } - + if (Minecraft.getInstance().isLocalServer()) { + return; + } + if (player.getItemInHand(hand).getItem() instanceof BlockItem) { - this.placedBlock = true; + this.placedBlock = true; } - + } - + @Inject(method = "performUseItemOn", at = @At("RETURN"), cancellable = true) public void onUseItemOnReturn(LocalPlayer player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable cir) { - if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { return; } - + if (Minecraft.getInstance().isLocalServer() || !this.placedBlock) { + return; + } + if (cir.getReturnValue() == InteractionResult.SUCCESS) { ClientEventHandler.onPlace(); } diff --git a/neoforge/ng-7.0/1.21/src/main/resources/META-INF/mods.toml b/neoforge/ng-7.0/1.21/src/main/resources/META-INF/mods.toml index 723ca8c..daa7061 100644 --- a/neoforge/ng-7.0/1.21/src/main/resources/META-INF/mods.toml +++ b/neoforge/ng-7.0/1.21/src/main/resources/META-INF/mods.toml @@ -4,36 +4,36 @@ # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory +modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. -license="${mod_license}" +license = "${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional -issueTrackerURL="${mod_issue_tracker_url}" +issueTrackerURL = "${mod_issue_tracker_url}" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${mod_id}" #mandatory +modId = "${mod_id}" #mandatory # The version number of the mod -version="${mod_version}" #mandatory +version = "${mod_version}" #mandatory # A display name for the mod -displayName="${mod_name}" #mandatory +displayName = "${mod_name}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional -updateJSONURL="${mod_update_json_url}" +updateJSONURL = "${mod_update_json_url}" # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional -displayURL="${mod_display_url}" +displayURL = "${mod_display_url}" # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional -logoFile="${mod_logo_file}" +logoFile = "${mod_logo_file}" # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI -authors="${mod_authors}" #optional +authors = "${mod_authors}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -43,29 +43,29 @@ authors="${mod_authors}" #optional #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) -description='''${mod_description}''' +description = '''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies.${ mod_id }]] #optional # the modid of the dependency -modId="forge" #mandatory +modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified -mandatory=true #mandatory +mandatory = true #mandatory # The version range of the dependency -versionRange="${forge_version_range}" #mandatory +versionRange = "${forge_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory # BEFORE - This mod is loaded BEFORE the dependency # AFTER - This mod is loaded AFTER the dependency -ordering="NONE" +ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER -side="BOTH" +side = "BOTH" # Here's another dependency -[[dependencies.${mod_id}]] -modId="minecraft" -mandatory=true +[[dependencies.${ mod_id }]] +modId = "minecraft" +mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange="${minecraft_version_range}" -ordering="NONE" -side="BOTH" +versionRange = "${minecraft_version_range}" +ordering = "NONE" +side = "BOTH" # Features are specific properties of the game environment, that you may want to declare you require. This example declares # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't diff --git a/neoforge/ng-7.0/1.21/src/main/resources/mixins.minegasm.json b/neoforge/ng-7.0/1.21/src/main/resources/mixins.minegasm.json index 714cffb..7c64560 100644 --- a/neoforge/ng-7.0/1.21/src/main/resources/mixins.minegasm.json +++ b/neoforge/ng-7.0/1.21/src/main/resources/mixins.minegasm.json @@ -4,8 +4,8 @@ "compatibilityLevel": "JAVA_8", "refmap": "mixins.minegasm.refmap.json", "mixins": [ - "MultiPlayerGameModeMixin", + "ClientAdvancementsMixin", "LocalPlayerMixin", - "ClientAdvancementsMixin" + "MultiPlayerGameModeMixin" ] } \ No newline at end of file diff --git a/neoforge/ng-7.0/1.21/src/main/resources/pack.mcmeta b/neoforge/ng-7.0/1.21/src/main/resources/pack.mcmeta index add527b..eca79ae 100644 --- a/neoforge/ng-7.0/1.21/src/main/resources/pack.mcmeta +++ b/neoforge/ng-7.0/1.21/src/main/resources/pack.mcmeta @@ -1,8 +1,8 @@ { - "pack": { - "description": { - "text": "${mod_id} resources" - }, - "pack_format": 15 - } + "pack": { + "description": { + "text": "${mod_id} resources" + }, + "pack_format": 15 + } } \ No newline at end of file diff --git a/neoforge/ng-7.0/gradle.properties b/neoforge/ng-7.0/gradle.properties index e3575a9..9dbb08d 100644 --- a/neoforge/ng-7.0/gradle.properties +++ b/neoforge/ng-7.0/gradle.properties @@ -2,10 +2,7 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false - - ## Mod Properties - # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. mod_id=minegasm @@ -23,7 +20,6 @@ mod_group_id=com.therainbowville.minegasm mod_authors=RSwoop, RainbowVille's contributors # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description=Just a simple mod to bring some gasm into Minecraft. ;) - mod_issue_tracker_url=https://github.com/RainbowVille/minegasm/issues mod_update_json_url=https://www.minegasm.net/updates.json mod_display_url=https://www.minegasm.net/ diff --git a/simulator/src/main/java/com/therainbowville/minegasm/Simulator.java b/simulator/src/main/java/com/therainbowville/minegasm/Simulator.java index cbbfb8b..93d5a55 100644 --- a/simulator/src/main/java/com/therainbowville/minegasm/Simulator.java +++ b/simulator/src/main/java/com/therainbowville/minegasm/Simulator.java @@ -1,11 +1,11 @@ package com.therainbowville.minegasm; public class Simulator { - public String getGreeting() { - return "Hello World!"; - } - public static void main(String[] args) { System.out.println(new Simulator().getGreeting()); } + + public String getGreeting() { + return "Hello World!"; + } } diff --git a/simulator/src/test/java/com/therainbowville/minegasm/SimulatorTest.java b/simulator/src/test/java/com/therainbowville/minegasm/SimulatorTest.java index f3b9409..da348ec 100644 --- a/simulator/src/test/java/com/therainbowville/minegasm/SimulatorTest.java +++ b/simulator/src/test/java/com/therainbowville/minegasm/SimulatorTest.java @@ -5,7 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; class SimulatorTest { - @Test void appHasAGreeting() { + @Test + void appHasAGreeting() { Simulator classUnderTest = new Simulator(); assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); }