diff --git a/.gitea/workflows/java.yml b/.gitea/workflows/java.yml new file mode 100644 index 0000000..5c47e28 --- /dev/null +++ b/.gitea/workflows/java.yml @@ -0,0 +1,29 @@ +on: [ push ] + +name: Build fabric mod + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle 8.12.1 + uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 + with: + gradle-version: '8.12.1' + + - name: Build with Gradle Wrapper + run: chmod +x ./gradlew; ./gradlew build + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: build + path: build/libs/* \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34d600a --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# gradle + +.gradle/ +build/ +out/ +classes/ + +# eclipse + +*.launch + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store + +# fabric + +run/ + +# java + +hs_err_*.log +replay_*.log +*.hprof +*.jfr + +remappedSrc/ diff --git a/LICENSE b/LICENSE index 2d58298..07b7a81 100644 --- a/LICENSE +++ b/LICENSE @@ -1,428 +1,13 @@ -Attribution-ShareAlike 4.0 International + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 -======================================================================= +Copyright (C) 2004 Sam Hocevar -Creative Commons Corporation ("Creative Commons") is not a law firm and -does not provide legal services or legal advice. Distribution of -Creative Commons public licenses does not create a lawyer-client or -other relationship. Creative Commons makes its licenses and related -information available on an "as-is" basis. Creative Commons gives no -warranties regarding its licenses, any material licensed under their -terms and conditions, or any related information. Creative Commons -disclaims all liability for damages resulting from their use to the -fullest extent possible. +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. -Using Creative Commons Public Licenses - -Creative Commons public licenses provide a standard set of terms and -conditions that creators and other rights holders may use to share -original works of authorship and other material subject to copyright -and certain other rights specified in the public license below. The -following considerations are for informational purposes only, are not -exhaustive, and do not form part of our licenses. - - Considerations for licensors: Our public licenses are - intended for use by those authorized to give the public - permission to use material in ways otherwise restricted by - copyright and certain other rights. Our licenses are - irrevocable. Licensors should read and understand the terms - and conditions of the license they choose before applying it. - Licensors should also secure all rights necessary before - applying our licenses so that the public can reuse the - material as expected. Licensors should clearly mark any - material not subject to the license. This includes other CC- - licensed material, or material used under an exception or - limitation to copyright. More considerations for licensors: - wiki.creativecommons.org/Considerations_for_licensors - - Considerations for the public: By using one of our public - licenses, a licensor grants the public permission to use the - licensed material under specified terms and conditions. If - the licensor's permission is not necessary for any reason--for - example, because of any applicable exception or limitation to - copyright--then that use is not regulated by the license. Our - licenses grant only permissions under copyright and certain - other rights that a licensor has authority to grant. Use of - the licensed material may still be restricted for other - reasons, including because others have copyright or other - rights in the material. A licensor may make special requests, - such as asking that all changes be marked or described. - Although not required by our licenses, you are encouraged to - respect those requests where reasonable. More considerations - for the public: - wiki.creativecommons.org/Considerations_for_licensees - -======================================================================= - -Creative Commons Attribution-ShareAlike 4.0 International Public -License - -By exercising the Licensed Rights (defined below), You accept and agree -to be bound by the terms and conditions of this Creative Commons -Attribution-ShareAlike 4.0 International Public License ("Public -License"). To the extent this Public License may be interpreted as a -contract, You are granted the Licensed Rights in consideration of Your -acceptance of these terms and conditions, and the Licensor grants You -such rights in consideration of benefits the Licensor receives from -making the Licensed Material available under these terms and -conditions. - - -Section 1 -- Definitions. - - a. Adapted Material means material subject to Copyright and Similar - Rights that is derived from or based upon the Licensed Material - and in which the Licensed Material is translated, altered, - arranged, transformed, or otherwise modified in a manner requiring - permission under the Copyright and Similar Rights held by the - Licensor. For purposes of this Public License, where the Licensed - Material is a musical work, performance, or sound recording, - Adapted Material is always produced where the Licensed Material is - synched in timed relation with a moving image. - - b. Adapter's License means the license You apply to Your Copyright - and Similar Rights in Your contributions to Adapted Material in - accordance with the terms and conditions of this Public License. - - c. BY-SA Compatible License means a license listed at - creativecommons.org/compatiblelicenses, approved by Creative - Commons as essentially the equivalent of this Public License. - - d. Copyright and Similar Rights means copyright and/or similar rights - closely related to copyright including, without limitation, - performance, broadcast, sound recording, and Sui Generis Database - Rights, without regard to how the rights are labeled or - categorized. For purposes of this Public License, the rights - specified in Section 2(b)(1)-(2) are not Copyright and Similar - Rights. - - e. Effective Technological Measures means those measures that, in the - absence of proper authority, may not be circumvented under laws - fulfilling obligations under Article 11 of the WIPO Copyright - Treaty adopted on December 20, 1996, and/or similar international - agreements. - - f. Exceptions and Limitations means fair use, fair dealing, and/or - any other exception or limitation to Copyright and Similar Rights - that applies to Your use of the Licensed Material. - - g. License Elements means the license attributes listed in the name - of a Creative Commons Public License. The License Elements of this - Public License are Attribution and ShareAlike. - - h. Licensed Material means the artistic or literary work, database, - or other material to which the Licensor applied this Public - License. - - i. Licensed Rights means the rights granted to You subject to the - terms and conditions of this Public License, which are limited to - all Copyright and Similar Rights that apply to Your use of the - Licensed Material and that the Licensor has authority to license. - - j. Licensor means the individual(s) or entity(ies) granting rights - under this Public License. - - k. Share means to provide material to the public by any means or - process that requires permission under the Licensed Rights, such - as reproduction, public display, public performance, distribution, - dissemination, communication, or importation, and to make material - available to the public including in ways that members of the - public may access the material from a place and at a time - individually chosen by them. - - l. Sui Generis Database Rights means rights other than copyright - resulting from Directive 96/9/EC of the European Parliament and of - the Council of 11 March 1996 on the legal protection of databases, - as amended and/or succeeded, as well as other essentially - equivalent rights anywhere in the world. - - m. You means the individual or entity exercising the Licensed Rights - under this Public License. Your has a corresponding meaning. - - -Section 2 -- Scope. - - a. License grant. - - 1. Subject to the terms and conditions of this Public License, - the Licensor hereby grants You a worldwide, royalty-free, - non-sublicensable, non-exclusive, irrevocable license to - exercise the Licensed Rights in the Licensed Material to: - - a. reproduce and Share the Licensed Material, in whole or - in part; and - - b. produce, reproduce, and Share Adapted Material. - - 2. Exceptions and Limitations. For the avoidance of doubt, where - Exceptions and Limitations apply to Your use, this Public - License does not apply, and You do not need to comply with - its terms and conditions. - - 3. Term. The term of this Public License is specified in Section - 6(a). - - 4. Media and formats; technical modifications allowed. The - Licensor authorizes You to exercise the Licensed Rights in - all media and formats whether now known or hereafter created, - and to make technical modifications necessary to do so. The - Licensor waives and/or agrees not to assert any right or - authority to forbid You from making technical modifications - necessary to exercise the Licensed Rights, including - technical modifications necessary to circumvent Effective - Technological Measures. For purposes of this Public License, - simply making modifications authorized by this Section 2(a) - (4) never produces Adapted Material. - - 5. Downstream recipients. - - a. Offer from the Licensor -- Licensed Material. Every - recipient of the Licensed Material automatically - receives an offer from the Licensor to exercise the - Licensed Rights under the terms and conditions of this - Public License. - - b. Additional offer from the Licensor -- Adapted Material. - Every recipient of Adapted Material from You - automatically receives an offer from the Licensor to - exercise the Licensed Rights in the Adapted Material - under the conditions of the Adapter's License You apply. - - c. No downstream restrictions. You may not offer or impose - any additional or different terms or conditions on, or - apply any Effective Technological Measures to, the - Licensed Material if doing so restricts exercise of the - Licensed Rights by any recipient of the Licensed - Material. - - 6. No endorsement. Nothing in this Public License constitutes or - may be construed as permission to assert or imply that You - are, or that Your use of the Licensed Material is, connected - with, or sponsored, endorsed, or granted official status by, - the Licensor or others designated to receive attribution as - provided in Section 3(a)(1)(A)(i). - - b. Other rights. - - 1. Moral rights, such as the right of integrity, are not - licensed under this Public License, nor are publicity, - privacy, and/or other similar personality rights; however, to - the extent possible, the Licensor waives and/or agrees not to - assert any such rights held by the Licensor to the limited - extent necessary to allow You to exercise the Licensed - Rights, but not otherwise. - - 2. Patent and trademark rights are not licensed under this - Public License. - - 3. To the extent possible, the Licensor waives any right to - collect royalties from You for the exercise of the Licensed - Rights, whether directly or through a collecting society - under any voluntary or waivable statutory or compulsory - licensing scheme. In all other cases the Licensor expressly - reserves any right to collect such royalties. - - -Section 3 -- License Conditions. - -Your exercise of the Licensed Rights is expressly made subject to the -following conditions. - - a. Attribution. - - 1. If You Share the Licensed Material (including in modified - form), You must: - - a. retain the following if it is supplied by the Licensor - with the Licensed Material: - - i. identification of the creator(s) of the Licensed - Material and any others designated to receive - attribution, in any reasonable manner requested by - the Licensor (including by pseudonym if - designated); - - ii. a copyright notice; - - iii. a notice that refers to this Public License; - - iv. a notice that refers to the disclaimer of - warranties; - - v. a URI or hyperlink to the Licensed Material to the - extent reasonably practicable; - - b. indicate if You modified the Licensed Material and - retain an indication of any previous modifications; and - - c. indicate the Licensed Material is licensed under this - Public License, and include the text of, or the URI or - hyperlink to, this Public License. - - 2. You may satisfy the conditions in Section 3(a)(1) in any - reasonable manner based on the medium, means, and context in - which You Share the Licensed Material. For example, it may be - reasonable to satisfy the conditions by providing a URI or - hyperlink to a resource that includes the required - information. - - 3. If requested by the Licensor, You must remove any of the - information required by Section 3(a)(1)(A) to the extent - reasonably practicable. - - b. ShareAlike. - - In addition to the conditions in Section 3(a), if You Share - Adapted Material You produce, the following conditions also apply. - - 1. The Adapter's License You apply must be a Creative Commons - license with the same License Elements, this version or - later, or a BY-SA Compatible License. - - 2. You must include the text of, or the URI or hyperlink to, the - Adapter's License You apply. You may satisfy this condition - in any reasonable manner based on the medium, means, and - context in which You Share Adapted Material. - - 3. You may not offer or impose any additional or different terms - or conditions on, or apply any Effective Technological - Measures to, Adapted Material that restrict exercise of the - rights granted under the Adapter's License You apply. - - -Section 4 -- Sui Generis Database Rights. - -Where the Licensed Rights include Sui Generis Database Rights that -apply to Your use of the Licensed Material: - - a. for the avoidance of doubt, Section 2(a)(1) grants You the right - to extract, reuse, reproduce, and Share all or a substantial - portion of the contents of the database; - - b. if You include all or a substantial portion of the database - contents in a database in which You have Sui Generis Database - Rights, then the database in which You have Sui Generis Database - Rights (but not its individual contents) is Adapted Material, - including for purposes of Section 3(b); and - - c. You must comply with the conditions in Section 3(a) if You Share - all or a substantial portion of the contents of the database. - -For the avoidance of doubt, this Section 4 supplements and does not -replace Your obligations under this Public License where the Licensed -Rights include other Copyright and Similar Rights. - - -Section 5 -- Disclaimer of Warranties and Limitation of Liability. - - a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE - EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS - AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF - ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, - IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, - WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR - PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, - ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT - KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT - ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. - - b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE - TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, - NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, - INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, - COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR - USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN - ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR - DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR - IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. - - c. The disclaimer of warranties and limitation of liability provided - above shall be interpreted in a manner that, to the extent - possible, most closely approximates an absolute disclaimer and - waiver of all liability. - - -Section 6 -- Term and Termination. - - a. This Public License applies for the term of the Copyright and - Similar Rights licensed here. However, if You fail to comply with - this Public License, then Your rights under this Public License - terminate automatically. - - b. Where Your right to use the Licensed Material has terminated under - Section 6(a), it reinstates: - - 1. automatically as of the date the violation is cured, provided - it is cured within 30 days of Your discovery of the - violation; or - - 2. upon express reinstatement by the Licensor. - - For the avoidance of doubt, this Section 6(b) does not affect any - right the Licensor may have to seek remedies for Your violations - of this Public License. - - c. For the avoidance of doubt, the Licensor may also offer the - Licensed Material under separate terms or conditions or stop - distributing the Licensed Material at any time; however, doing so - will not terminate this Public License. - - d. Sections 1, 5, 6, 7, and 8 survive termination of this Public - License. - - -Section 7 -- Other Terms and Conditions. - - a. The Licensor shall not be bound by any additional or different - terms or conditions communicated by You unless expressly agreed. - - b. Any arrangements, understandings, or agreements regarding the - Licensed Material not stated herein are separate from and - independent of the terms and conditions of this Public License. - - -Section 8 -- Interpretation. - - a. For the avoidance of doubt, this Public License does not, and - shall not be interpreted to, reduce, limit, restrict, or impose - conditions on any use of the Licensed Material that could lawfully - be made without permission under this Public License. - - b. To the extent possible, if any provision of this Public License is - deemed unenforceable, it shall be automatically reformed to the - minimum extent necessary to make it enforceable. If the provision - cannot be reformed, it shall be severed from this Public License - without affecting the enforceability of the remaining terms and - conditions. - - c. No term or condition of this Public License will be waived and no - failure to comply consented to unless expressly agreed to by the - Licensor. - - d. Nothing in this Public License constitutes or may be interpreted - as a limitation upon, or waiver of, any privileges and immunities - that apply to the Licensor or You, including from the legal - processes of any jurisdiction or authority. - - -======================================================================= - -Creative Commons is not a party to its public -licenses. Notwithstanding, Creative Commons may elect to apply one of -its public licenses to material it publishes and in those instances -will be considered the “Licensor.” The text of the Creative Commons -public licenses is dedicated to the public domain under the CC0 Public -Domain Dedication. Except for the limited purpose of indicating that -material is shared under a Creative Commons public license or as -otherwise permitted by the Creative Commons policies published at -creativecommons.org/policies, Creative Commons does not authorize the -use of the trademark "Creative Commons" or any other trademark or logo -of Creative Commons without its prior written consent including, -without limitation, in connection with any unauthorized modifications -to any of its public licenses or any other arrangements, -understandings, or agreements concerning use of licensed material. For -the avoidance of doubt, this paragraph does not form part of the -public licenses. - -Creative Commons may be contacted at creativecommons.org. + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + 0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file diff --git a/README.md b/README.md index e2be31c..ca695e9 100644 --- a/README.md +++ b/README.md @@ -2,44 +2,49 @@ This mod can record your movements and play them back. -![Preview gif](preview.gif) +## How to use -## Controls +Simply start recording, perform any actions, stop the recording, return to the starting point, and then you can replay everything you did. + +### Showcase + +![Preview gif](img/preview.gif) + +This is how menu looks like: + +![repeating mod menu](img/menu.png) + + +### Controls Default Repeating Mod keys ``` Menu | J -Toggle recording | not specified -Toggle replay | not specified +Toggle recording | not specified by default +Toggle replay | not specified by default ``` -## Menu +## Where to download -How menu looks like +### Stable releases -![repeating mod menu](https://github.com/MeexReay/repeating-mod/assets/127148610/4123068f-b150-45ae-8ae3-fcaa0e6bb9f8) +You can find stable releases on [Modrinth](https://modrinth.com/mod/repeating-mod/versions) or on [Releases page](https://git.meex.lol/MeexReay/repeating_mod/releases) -## Todo -Releases dont have striked lines +### Development artifacts -- ~~fix "Space in record name deletes record 0_0"~~ -- ~~fix "Save record (edit name) on recording crashes the game"~~ -- ~~select record on click (you can see start and finish points when its selected)~~ -- ~~select record on import~~ -- ~~change icon in mod menu to new one~~ -- ~~fix "Crashes the game when leaving world while record is replaying"~~ -- ~~copy file to record list when import~~ -- record gui mouse clicks and key pressing -- create new preview.gif -- practice mode like in geometry dash for parkours +Artifacts are automatically built with [Gitea Actions](https://git.meex.lol/MeexReay/repeating_mod/actions) on each commit. \ +[Download latest artifact](https://git.meex.lol/MeexReay/repeating_mod/actions/runs/latest/artifacts/build) -## How to build +## Roadmap -How to build mod from source +- [ ] relative mode for repeating actions (like mining) +- [ ] record mouse and keyboard in gui +- [ ] practice mode (like in geometry dash but for parkours) -``` -gradlew build -``` +### Contributing -Compiled .jar file you can find in `build/libs` +If you would like to contribute to the project, feel free to fork the repository and submit a pull request. + +### License +This project is licensed under the WTFPL License diff --git a/build.gradle b/build.gradle index 84a69d1..ffbc124 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' + id 'fabric-loom' version "${loom_version}" id 'maven-publish' } @@ -19,8 +19,8 @@ repositories { } dependencies { - compileOnly 'org.projectlombok:lombok:1.18.24' - annotationProcessor 'org.projectlombok:lombok:1.18.24' + compileOnly 'org.projectlombok:lombok:1.18.38' + annotationProcessor 'org.projectlombok:lombok:1.18.38' //add joml modImplementation 'org.joml:joml:1.10.4' @@ -33,7 +33,6 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - } processResources { @@ -45,7 +44,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 17 + it.options.release = 21 } java { @@ -54,8 +53,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { diff --git a/gradle.properties b/gradle.properties index 4fe0e23..780fbef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,20 @@ -# Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G -org.gradle.parallel=true - -# Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.20 -yarn_mappings=1.20+build.1 -loader_version=0.15.10 - -#Fabric api -fabric_version=0.83.0+1.20 - -# Mod Properties -mod_version = 1.1.1+1.20 -maven_group = themixray.repeating.mod -archives_base_name = repeating-mod \ No newline at end of file +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G +org.gradle.parallel=true + +# Fabric Properties +# check these on https://fabricmc.net/develop +minecraft_version=1.21.6 +yarn_mappings=1.21.6+build.1 +loader_version=0.16.14 +loom_version=1.10-SNAPSHOT + +# Fabric API +fabric_version=0.127.0+1.21.6 + +# Mod Properties +mod_version = 1.1.2+1.21.6 +maven_group = ru.themixray +archives_base_name = repeating-mod + +# Compatible with: 1.21.6 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e644113..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23..e18bc25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 25da30d..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/img/menu.png b/img/menu.png new file mode 100644 index 0000000..5cf7928 Binary files /dev/null and b/img/menu.png differ diff --git a/preview.gif b/img/preview.gif similarity index 100% rename from preview.gif rename to img/preview.gif diff --git a/remappedSrc/themixray/repeating/mod/Main.java b/remappedSrc/themixray/repeating/mod/Main.java deleted file mode 100644 index 6a851ea..0000000 --- a/remappedSrc/themixray/repeating/mod/Main.java +++ /dev/null @@ -1,325 +0,0 @@ -package themixray.repeating.mod; - -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.Vec3d; -import org.lwjgl.glfw.GLFW; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import themixray.repeating.mod.event.RecordDelayEvent; -import themixray.repeating.mod.event.RecordEvent; -import themixray.repeating.mod.event.RecordInputEvent; -import themixray.repeating.mod.event.RecordMoveEvent; -import themixray.repeating.mod.render.RenderHelper; -import themixray.repeating.mod.render.RenderSystem; -import themixray.repeating.mod.render.buffer.WorldBuffer; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.util.*; - -public class Main implements ClientModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("repeating-mod"); - public static final MinecraftClient client = MinecraftClient.getInstance(); - public static final FabricLoader loader = FabricLoader.getInstance(); - public static Main me; - - public RecordList record_list; - public RecordState now_record; - - public boolean is_recording = false; - public long last_record = -1; - public TickTask move_tick = null; - - public TickTask replay_tick = null; - public boolean is_replaying = false; - public boolean loop_replay = false; - public static RecordInputEvent input_replay = null; - - public long living_ticks = 0; - - public static RepeatingScreen menu; - private static KeyBinding menu_key; - private static KeyBinding toggle_replay_key; - private static KeyBinding toggle_record_key; - - public long record_pos_delay = 20; - - public static Random rand = new Random(); - - public EasyConfig conf; - public File records_folder; - - @Override - public void onInitializeClient() { - LOGGER.info("Repeating mod initialized"); - me = this; - - now_record = null; - - records_folder = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating_mod_records"); - if (!records_folder.exists()) records_folder.mkdir(); - - record_list = new RecordList(records_folder); - record_list.loadRecords(); - - RenderSystem.init(); - WorldRenderEvents.LAST.register(context -> { - WorldBuffer buffer = RenderHelper.startTri(context); - if (now_record != null) { - Vec3d start_pos = now_record.getStartRecordPos(); - Vec3d finish_pos = now_record.getFinishRecordPos(); - - if (start_pos != null) drawRecordPos(buffer, start_pos, new Color(70, 230, 70, 128)); - if (finish_pos != null) drawRecordPos(buffer, finish_pos, new Color(230, 70, 70, 128)); - } - RenderHelper.endTri(buffer); - }); - - Map def = new HashMap<>(); - def.put("record_pos_delay", String.valueOf(record_pos_delay)); - - conf = new EasyConfig(loader.getConfigDir(),"repeating-mod",def); - - record_pos_delay = Long.parseLong(conf.data.get("record_pos_delay")); - - menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.menu",InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_J,"text.repeating-mod.name")); - toggle_replay_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.toggle_replay",InputUtil.Type.KEYSYM, - -1,"text.repeating-mod.name")); - toggle_record_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.toggle_record",InputUtil.Type.KEYSYM, - -1,"text.repeating-mod.name")); - - menu = new RepeatingScreen(); - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (menu_key.wasPressed()) - client.setScreen(menu); - if (toggle_replay_key.wasPressed()) { - if (now_record != null) { - if (!is_recording) { - if (is_replaying) - stopReplay(); - else startReplay(); - menu.updateButtons(); - } - } - } - if (toggle_record_key.wasPressed()) { - if (!is_replaying) { - if (is_recording) - stopRecording(); - else startRecording(); - menu.updateButtons(); - } - } - }); - - new TickTask(0,0) { - @Override - public void run() { - living_ticks++; - } - }; - - System.setProperty("java.awt.headless", "false"); - } - - public void setNowRecord(RecordState record) { - now_record = record; - } - - public void drawRecordPos(WorldBuffer buffer, Vec3d pos, Color color) { - RenderHelper.drawRectFromTri(buffer, - (float) pos.getX() - 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() - 0.25F, - - (float) pos.getX() + 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() - 0.25F, - - (float) pos.getX() + 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() + 0.25F, - - (float) pos.getX() - 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() + 0.25F, - color); - } - - public void startRecording() { - is_recording = true; - menu.updateButtons(); - - now_record = record_list.newRecord(); - - Vec3d start_pos = client.player.getPos(); - now_record.addEvent(new RecordMoveEvent(start_pos,client.player.getHeadYaw(),client.player.getPitch())); - now_record.setStartRecordPos(start_pos); - - if (record_pos_delay > 0) { - move_tick = new TickTask( - record_pos_delay, - record_pos_delay) { - @Override - public void run() { - now_record.addEvent(new RecordMoveEvent(client.player.getPos(), - client.player.getHeadYaw(), client.player.getPitch())); - } - }; - } - - sendMessage(Text.translatable("message.repeating-mod.record_start")); - } - - public void recordTick(RecordEvent e) { - if (is_recording) { - long now = living_ticks; - if (last_record != -1) { - long diff = now - last_record - 2; - if (diff > 0) now_record.addEvent(new RecordDelayEvent(diff)); - } - now_record.addEvent(e); - last_record = now; - } - } - - public void recordAllInput() { - if (client.player == null) { - stopRecording(); - return; - } - - RecordInputEvent l = ((RecordInputEvent) now_record.getLastEvent("input")); - if (l == null) { - RecordInputEvent e = new RecordInputEvent( - client.player.input.sneaking, - client.player.input.jumping, - client.player.input.movementSideways, - client.player.input.movementForward, - client.player.input.pressingForward, - client.player.input.pressingBack, - client.player.input.pressingLeft, - client.player.input.pressingRight, - client.player.getHeadYaw(), - client.player.getBodyYaw(), - client.player.getPitch(), - client.player.isSprinting(), - client.player.getYaw(), - client.player.getMovementSpeed()); - recordTick(e); - } else { - RecordInputEvent e = new RecordInputEvent( - ((Boolean) client.player.input.sneaking == l.sneaking) ? null : client.player.input.sneaking, - ((Boolean) client.player.input.jumping == l.jumping) ? null : client.player.input.jumping, - (((Float) client.player.input.movementSideways).equals(l.movementSideways)) ? null : client.player.input.movementSideways, - (((Float) client.player.input.movementForward).equals(l.movementForward)) ? null : client.player.input.movementForward, - ((Boolean) client.player.input.pressingForward == l.pressingForward) ? null : client.player.input.pressingForward, - ((Boolean) client.player.input.pressingBack == l.pressingBack) ? null : client.player.input.pressingBack, - ((Boolean) client.player.input.pressingLeft == l.pressingLeft) ? null : client.player.input.pressingLeft, - ((Boolean) client.player.input.pressingRight == l.pressingRight) ? null : client.player.input.pressingRight, - client.player.getHeadYaw(), Main.client.player.getBodyYaw(),client.player.getPitch(), - ((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(), - client.player.getYaw(),client.player.getMovementSpeed()); - - if (!(e.isEmpty() && - e.yaw == l.yaw && - e.head_yaw == l.head_yaw && - e.pitch == l.pitch && - e.body_yaw == l.body_yaw)) { - e.fillEmpty(l); - recordTick(e); - } - } - } - - public void stopRecording() { - is_recording = false; - now_record.setFinishRecordPos(client.player.getPos()); - try { - now_record.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (move_tick != null) { - move_tick.cancel(); - move_tick = null; - } - menu.updateButtons(); - last_record = -1; - sendMessage(Text.translatable("message.repeating-mod.record_stop")); - } - - - public void startReplay() { - is_recording = false; - is_replaying = true; - menu.updateButtons(); - - List events = now_record.getEvents(); - - replay_tick = new TickTask(0,0, TickTask.TickAt.CLIENT_TAIL) { - public int replay_index = 0; - - @Override - public void run() { - if (!is_replaying) cancel(); - RecordEvent e = events.get(replay_index); - if (e instanceof RecordDelayEvent) { - setDelay(((RecordDelayEvent) e).delay); - } else { - e.replay(); - } - - replay_index++; - if (!loop_replay) { - if (replay_index == events.size()) { - stopReplay(); - cancel(); - } - } else if (replay_index == events.size()) { - replay_index = 0; - } - } - }; - - sendMessage(Text.translatable("message.repeating-mod.replay_start")); - } - - public void stopReplay() { - is_recording = false; - is_replaying = false; - if (replay_tick != null) { - replay_tick.cancel(); - replay_tick = null; - } - menu.updateButtons(); - record_list.getWidget().getWidget(now_record).getChildren().get(3).setMessage(Text.translatable("text.repeating-mod.start")); - sendMessage(Text.translatable("message.repeating-mod.replay_stop")); - } - - public static void sendMessage(MutableText text) { - client.player.sendMessage(Text.literal("[") - .append(Text.translatable("text.repeating-mod.name")) - .append("] ").formatted(Formatting.BOLD,Formatting.DARK_GRAY) - .append(text.formatted(Formatting.RESET).formatted(Formatting.GRAY))); - } - - public static void sendDebug(String s) { - client.player.sendMessage(Text.literal("[DEBUG] ").append(Text.of(s))); - } -} diff --git a/remappedSrc/themixray/repeating/mod/RecordList.java b/remappedSrc/themixray/repeating/mod/RecordList.java deleted file mode 100644 index e17a0e8..0000000 --- a/remappedSrc/themixray/repeating/mod/RecordList.java +++ /dev/null @@ -1,77 +0,0 @@ -package themixray.repeating.mod; - -import net.minecraft.text.Text; -import themixray.repeating.mod.widget.RecordListWidget; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class RecordList { - private final File folder; - private List records; - private RecordListWidget widget; - - public RecordList(File folder) { - this.folder = folder; - this.records = new ArrayList<>(); - this.widget = new RecordListWidget(0, 0, 180, 200); - } - - public List getRecords() { - return records; - } - - public File getFolder() { - return folder; - } - - public RecordListWidget getWidget() { - return widget; - } - - public void loadRecords() { - for (File file : folder.listFiles()) { - try { - addRecord(file); - } catch (Exception e) {} - } - } - - public void addRecord(File file) throws Exception { - addRecord(RecordState.load(file)); - } - - public void addRecord(RecordState record) { - records.add(record); - widget.addWidget(record); - } - - public void removeRecord(RecordState record) { - records.remove(record); - widget.removeWidget(record); - } - - public RecordState newRecord() { - Date date = new Date(); - String name = "Unnamed"; - String author = Main.client.player.getName().getString(); - - File file = new File(Main.me.records_folder, - "record_" + RecordState.FILE_DATE_FORMAT.format(date) + - "_" + Main.rand.nextInt(10) + ".rrm"); - - RecordState state = new RecordState( - file, name, date, author, - new ArrayList<>(), - null, - null); - - addRecord(state); - - return state; - } -} diff --git a/remappedSrc/themixray/repeating/mod/RecordState.java b/remappedSrc/themixray/repeating/mod/RecordState.java deleted file mode 100644 index 239194a..0000000 --- a/remappedSrc/themixray/repeating/mod/RecordState.java +++ /dev/null @@ -1,169 +0,0 @@ -package themixray.repeating.mod; - -import com.google.common.collect.Lists; -import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.event.RecordEvent; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class RecordState { - public static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM.dd.yyyy HH:mm:ss"); - public static SimpleDateFormat FILE_DATE_FORMAT = new SimpleDateFormat("MM-dd-yyyy_HH-mm-ss"); - - private final File file; - private String name; - private Date date; - private String author; - - private List events; - private Vec3d start_record_pos; - private Vec3d finish_record_pos; - - public RecordState(File file, - String name, - Date date, - String author, - List events, - Vec3d start_record_pos, - Vec3d finish_record_pos) { - this.file = file; - this.name = name; - this.date = date; - this.author = author; - - this.events = events; - this.start_record_pos = start_record_pos; - this.finish_record_pos = finish_record_pos; - } - - public File getFile() { - return file; - } - - public String getName() { - return name; - } - - public String getAuthor() { - return author; - } - - public Date getDate() { - return date; - } - - public List getEvents() { - return events; - } - - public Vec3d getFinishRecordPos() { - return finish_record_pos; - } - - public Vec3d getStartRecordPos() { - return start_record_pos; - } - - public void setAuthor(String author) { - this.author = author; - } - - public void setDate(Date date) { - this.date = date; - } - - public void setName(String name) { - this.name = name; - } - - public void setEvents(List events) { - this.events = events; - } - - public void setFinishRecordPos(Vec3d finish_record_pos) { - this.finish_record_pos = finish_record_pos; - } - - public void setStartRecordPos(Vec3d start_record_pos) { - this.start_record_pos = start_record_pos; - } - - public void addEvent(RecordEvent event) { - events.add(event); - } - - public RecordEvent getLastEvent(String type) { - for (RecordEvent r: Lists.reverse(new ArrayList<>(events))) { - if (r.getType().equals(type)) { - return r; - } - } - return null; - } - - public void save() throws IOException { - StringBuilder text = new StringBuilder(); - - text.append(name).append("\n") - .append(DATE_FORMAT.format(date)).append("\n") - .append(author).append("\n"); - - text.append(start_record_pos.getX()).append("n") - .append(start_record_pos.getY()).append("n") - .append(start_record_pos.getZ()).append("x") - .append(finish_record_pos.getX()).append("n") - .append(finish_record_pos.getY()).append("n") - .append(finish_record_pos.getZ()); - - for (int i = 0; i < events.size(); i++) { - text.append("\n"); - text.append(events.get(i).serialize()); - } - - Files.write(file.toPath(), text.toString().getBytes()); - } - - public static RecordState load(File file) throws Exception { - String text = Files.readString(file.toPath()); - List lines = List.of(text.split("\n")); - - List signature = lines.subList(0,4); - - String name = signature.get(0); - Date date = DATE_FORMAT.parse(signature.get(1)); - String author = signature.get(2); - - String record_pos = signature.get(3); - - String[] lss0 = record_pos.split("x"); - String[] lss1 = lss0[0].split("n"); - String[] lss2 = lss0[1].split("n"); - - Vec3d start_record_pos = new Vec3d( - Float.parseFloat(lss1[0]), - Float.parseFloat(lss1[1]), - Float.parseFloat(lss1[2])); - Vec3d finish_record_pos = new Vec3d( - Float.parseFloat(lss2[0]), - Float.parseFloat(lss2[1]), - Float.parseFloat(lss2[2])); - - List event_lines = lines.subList(4,lines.size()); - List events = event_lines.stream().map(RecordEvent::deserialize).toList(); - - return new RecordState(file, name, date, author, events, start_record_pos, finish_record_pos); - } - - public void remove() { - file.delete(); - Main.me.record_list.removeRecord(this); - Main.me.record_list.getWidget().removeWidget(this); - } -} diff --git a/remappedSrc/themixray/repeating/mod/RepeatingScreen.java b/remappedSrc/themixray/repeating/mod/RepeatingScreen.java deleted file mode 100644 index 19609e4..0000000 --- a/remappedSrc/themixray/repeating/mod/RepeatingScreen.java +++ /dev/null @@ -1,193 +0,0 @@ -package themixray.repeating.mod; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.SliderWidget; -import net.minecraft.text.Text; -import themixray.repeating.mod.widget.RecordListWidget; - -import java.awt.*; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class RepeatingScreen extends Screen { - private static List render_listeners = new ArrayList<>(); - - public ButtonWidget record_btn; - public ButtonWidget loop_btn; - public ButtonWidget import_btn; - - public SliderWidget pos_delay_slider; - - public boolean was_build = false; - - protected RepeatingScreen() { - super(Text.empty()); - } - - public static void addRenderListener(RenderListener render) { - render_listeners.add(render); - } - - public static void removeRenderListener(RenderListener render) { - render_listeners.remove(render); - } - - public void updateButtons() { - if (was_build) { - record_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.is_recording) ? "stop_record" : "start_record"))); - loop_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.loop_replay) ? "off_loop" : "on_loop"))); - } - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - renderBackground(context,mouseX,mouseY,delta); - - for (RenderListener l : render_listeners) { - if (l.beforeRender()) { - l.render(context, mouseX, mouseY, delta); - } - } - - super.render(context, mouseX, mouseY, delta); - - for (RenderListener l : render_listeners) { - if (!l.beforeRender()) { - l.render(context, mouseX, mouseY, delta); - } - } - } - - @Override - protected void init() { - RecordListWidget list_widget = Main.me.record_list.getWidget(); - - list_widget.method_46421(width / 2 + 2); - list_widget.method_46419(height / 2 - list_widget.getHeight() / 2); - list_widget.init(this); - - - record_btn = ButtonWidget.builder( - Text.translatable("text.repeating-mod.start_record"), button -> { - if (!Main.me.is_replaying) { - if (Main.me.is_recording) - Main.me.stopRecording(); - else Main.me.startRecording(); - updateButtons(); - } - }) - .dimensions(width / 2 - 120, height / 2 - 32, 120, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.record_tooltip"))) - .build(); - - loop_btn = ButtonWidget.builder(Text.empty(), button -> { - Main.me.loop_replay = !Main.me.loop_replay; - updateButtons(); - }) - .dimensions(width / 2 - 120, height / 2 - 10, 120, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.loop_tooltip"))) - .build(); - - pos_delay_slider = new SliderWidget( - width / 2 - 120, height / 2 + 12, 120, 20, - (Main.me.record_pos_delay < 0) ? Text.translatable("text.repeating-mod.nan_pos_delay") : - Text.translatable("text.repeating-mod.pos_delay", String.valueOf(Main.me.record_pos_delay)), - (Main.me.record_pos_delay+1d)/101d) { - - @Override - protected void updateMessage() { - double v = value*101d-1d; - if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); - else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); - } - - @Override - protected void applyValue() { - double v = value*101d-1d; - if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); - else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); - Main.me.record_pos_delay = (long) v; - Main.me.conf.data.put("record_pos_delay",String.valueOf(Main.me.record_pos_delay)); - Main.me.conf.save(); - } - - @Override - public void onRelease(double mouseX, double mouseY) { - super.onRelease(mouseX, mouseY); - applyValue(); - } - - @Override - protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) { - super.onDrag(mouseX, mouseY, deltaX, deltaY); - applyValue(); - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - updateMessage(); - } - }; - pos_delay_slider.setTooltip(Tooltip.of(Text.translatable("text.repeating-mod.pos_delay_tooltip"))); - - import_btn = ButtonWidget.builder(Text.translatable("text.repeating-mod.import"), button -> { - new Thread(() -> { - FileDialog fd = new FileDialog((java.awt.Frame) null); - fd.setMultipleMode(true); - fd.setName("Choose record files"); - fd.setTitle("Choose record files"); - fd.setFilenameFilter((dir, name) -> name.endsWith(".rrm")); - fd.setVisible(true); - - File[] files = fd.getFiles(); - if (files != null) { - for (File file : files) { - try { - Main.me.record_list.addRecord(file); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }}).start(); - }) - .dimensions(width / 2 + 2, height / 2 - list_widget.getHeight() / 2 - 22, 180, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.import_tooltip"))) - .build(); - - was_build = true; - - updateButtons(); - - addDrawableChild(loop_btn); - addDrawableChild(record_btn); - addDrawableChild(import_btn); - addDrawableChild(pos_delay_slider); - } - - public T addDrawableChild(T drawableElement) { - return super.addDrawableChild(drawableElement); - } - - public T addDrawable(T drawable) { - return super.addDrawable(drawable); - } - - public T addSelectableChild(T child) { - return super.addSelectableChild(child); - } - - public void remove(Element child) { - super.remove(child); - } -} diff --git a/remappedSrc/themixray/repeating/mod/TickTask.java b/remappedSrc/themixray/repeating/mod/TickTask.java deleted file mode 100644 index f3beed1..0000000 --- a/remappedSrc/themixray/repeating/mod/TickTask.java +++ /dev/null @@ -1,94 +0,0 @@ -package themixray.repeating.mod; - -import java.util.ArrayList; -import java.util.List; - -public abstract class TickTask implements Runnable { - public static List tasks = new ArrayList<>(); - - public static void tickTasks(TickAt at) { - for (TickTask t:new ArrayList<>(tasks)) - if (t.getAt() == at) t.tick(); - } - - private long living; - private long delay; - - private boolean is_repeating; - private long period; - - private boolean is_cancelled; - private TickAt at; - - public enum TickAt { - CLIENT_HEAD, CLIENT_TAIL, - MOVEMENT_HEAD, MOVEMENT_TAIL, - RENDER_HEAD, RENDER_TAIL - } - - public TickTask(long delay, TickAt at) { - this.is_cancelled = false; - this.is_repeating = false; - this.delay = delay; - this.living = 0; - this.period = 0; - this.at = at; - tasks.add(this); - } - - public TickTask(long delay, long period, TickAt at) { - this.is_cancelled = false; - this.is_repeating = true; - this.delay = delay; - this.period = period; - this.living = 0; - this.at = at; - tasks.add(this); - } - - public TickTask(long delay) { - this(delay,TickAt.CLIENT_HEAD); - } - - public TickTask(long delay, long period) { - this(delay,period,TickAt.CLIENT_HEAD); - } - - public void cancel() { - if (!is_cancelled) { - is_cancelled = true; - tasks.remove(this); - } - } - - public boolean isCancelled() { - return is_cancelled; - } - - public TickAt getAt() { - return at; - } - - public void setDelay(long delay) { - if (is_repeating) { - this.delay = delay; - } - } - public long getDelay() { - return this.delay; - } - - public void tick() { - if (living >= delay) { - if (is_repeating) { - delay = period; - run(); - living = -1; - } else { - run(); - cancel(); - } - } - living++; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordBlockBreakEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordBlockBreakEvent.java deleted file mode 100644 index a39380c..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordBlockBreakEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package themixray.repeating.mod.event; - -import net.minecraft.util.math.BlockPos; -import themixray.repeating.mod.Main; - -public class RecordBlockBreakEvent extends RecordEvent { - public BlockPos pos; - - public static RecordBlockBreakEvent fromArgs(String[] a) { - return new RecordBlockBreakEvent(new BlockPos( - Integer.parseInt(a[0]), - Integer.parseInt(a[1]), - Integer.parseInt(a[2]))); - } - - public RecordBlockBreakEvent( - BlockPos pos) { - this.pos = pos; - } - - public void replay() { - Main.client.interactionManager.breakBlock(pos); - } - - public String serialize() { - return "b=" + pos.getX() + "&" + pos.getY() + "&" + pos.getZ(); - } - - public String getType() { - return "block_break"; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordBlockInteractEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordBlockInteractEvent.java deleted file mode 100644 index 59d0b76..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordBlockInteractEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -package themixray.repeating.mod.event; - -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.Main; - -public class RecordBlockInteractEvent extends RecordEvent { - public Hand hand; - public BlockHitResult hitResult; - - public static RecordBlockInteractEvent fromArgs(String[] a) { - return new RecordBlockInteractEvent( - Hand.valueOf(a[5]), - new BlockHitResult(new Vec3d( - Double.parseDouble(a[0]), - Double.parseDouble(a[1]), - Double.parseDouble(a[2])), - Direction.byId(Integer.parseInt(a[4])), - new BlockPos( - Integer.parseInt(a[0]), - Integer.parseInt(a[1]), - Integer.parseInt(a[2])), - a[3].equals("1"))); - } - - public RecordBlockInteractEvent(Hand hand, BlockHitResult hitResult) { - this.hand = hand; - this.hitResult = hitResult; - } - - public void replay() { - Main.client.interactionManager.interactBlock(Main.client.player, hand, hitResult); - } - - public String serialize() { - return "i=" + hitResult.getBlockPos().getX() + "&" + hitResult.getBlockPos().getY() + "&" + hitResult.getBlockPos().getZ() + - "&" + (hitResult.isInsideBlock() ? "1" : "0") + "&" + hitResult.getSide().getId() + "&" + hand.name(); - } - - public String getType() { - return "block_interact"; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordDelayEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordDelayEvent.java deleted file mode 100644 index 7e4bcca..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordDelayEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package themixray.repeating.mod.event; - -public class RecordDelayEvent extends RecordEvent { - public long delay; - - public static RecordDelayEvent fromArgs(String[] a) { - return new RecordDelayEvent(Long.parseLong(a[0])); - } - - public RecordDelayEvent(long delay) { - this.delay = delay; - } - - public void replay() { - try { - Thread.sleep(delay / 20 * 1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public String serialize() { - return "d=" + delay; - } - - public String getType() { - return "delay"; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordEvent.java deleted file mode 100644 index e7c2ffe..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package themixray.repeating.mod.event; - -public abstract class RecordEvent { - public abstract void replay(); - public abstract String serialize(); - public abstract String getType(); - - public static RecordEvent deserialize(String t) { - try { - String type = String.valueOf(t.charAt(0)); - String[] args = t.substring(2).split("&"); - if (type.equals("d")) { - return RecordDelayEvent.fromArgs(args); - } else if (type.equals("m")) { - return RecordMoveEvent.fromArgs(args); - } else if (type.equals("p")) { - return RecordInputEvent.fromArgs(args); - } else if (type.equals("b")) { - return RecordBlockBreakEvent.fromArgs(args); - } else if (type.equals("i")) { - return RecordBlockInteractEvent.fromArgs(args); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordInputEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordInputEvent.java deleted file mode 100644 index a760440..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordInputEvent.java +++ /dev/null @@ -1,147 +0,0 @@ -package themixray.repeating.mod.event; - -import themixray.repeating.mod.Main; - -public class RecordInputEvent extends RecordEvent { - public Boolean sneaking; - public Boolean jumping; - public Boolean pressingForward; - public Boolean pressingBack; - public Boolean pressingLeft; - public Boolean pressingRight; - public Boolean sprinting; - - public Float movementSideways; - public Float movementForward; - - public float yaw; - public float head_yaw; - public float body_yaw; - public float pitch; - public float speed; - - public static RecordInputEvent fromArgs(String[] a) { - return new RecordInputEvent( - (a[0].equals("n") ? null : a[0].equals("1")), - (a[1].equals("n") ? null : a[1].equals("1")), - (a[2].equals("n") ? null : Float.parseFloat(a[2])), - (a[3].equals("n") ? null : Float.parseFloat(a[3])), - (a[4].equals("n") ? null : a[4].equals("1")), - (a[5].equals("n") ? null : a[5].equals("1")), - (a[6].equals("n") ? null : a[6].equals("1")), - (a[7].equals("n") ? null : a[7].equals("1")), - Float.parseFloat(a[8]), Float.parseFloat(a[9]), - Float.parseFloat(a[10]), - (a[11].equals("n") ? null : a[11].equals("1")), - Float.parseFloat(a[12]), - Float.parseFloat(a[13])); - } - - public RecordInputEvent(Boolean sneaking, - Boolean jumping, - Float movementSideways, - Float movementForward, - Boolean pressingForward, - Boolean pressingBack, - Boolean pressingLeft, - Boolean pressingRight, - float head_yaw, - float body_yaw, - float head_pitch, - Boolean sprinting, - float yaw, - float speed) { - this.sneaking = sneaking; - this.jumping = jumping; - this.movementSideways = movementSideways; - this.movementForward = movementForward; - this.pressingForward = pressingForward; - this.pressingBack = pressingBack; - this.pressingLeft = pressingLeft; - this.pressingRight = pressingRight; - this.head_yaw = head_yaw; - this.body_yaw = body_yaw; - this.pitch = head_pitch; - this.sprinting = sprinting; - this.yaw = yaw; - this.speed = speed; - } - - public void fillEmpty(RecordInputEvent e) { - if (sneaking == null) sneaking = e.sneaking; - if (jumping == null) jumping = e.jumping; - if (movementSideways == null) movementSideways = e.movementSideways; - if (movementForward == null) movementForward = e.movementForward; - if (pressingForward == null) pressingForward = e.pressingForward; - if (pressingBack == null) pressingBack = e.pressingBack; - if (pressingLeft == null) pressingLeft = e.pressingLeft; - if (pressingRight == null) pressingRight = e.pressingRight; - if (sprinting == null) sprinting = e.sprinting; - } - - public boolean isEmpty() { - return sneaking == null && - jumping == null && - movementSideways == null && - movementForward == null && - pressingForward == null && - pressingBack == null && - pressingLeft == null && - pressingRight == null && - sprinting == null; - } - - public void replay() { - Main.input_replay = this; - } - - public void inputCallback() { - if (sprinting != null && Main.client.player.isSprinting() != sprinting) - Main.client.player.setSprinting(sprinting); - if (Main.client.player.getYaw() != yaw) - Main.client.player.setYaw(yaw); - if (Main.client.player.getHeadYaw() != head_yaw) - Main.client.player.setHeadYaw(head_yaw); - if (Main.client.player.getBodyYaw() != body_yaw) - Main.client.player.setBodyYaw(body_yaw); - if (Main.client.player.getPitch() != pitch) - Main.client.player.setPitch(pitch); - if (Main.client.player.getMovementSpeed() != speed) - Main.client.player.setMovementSpeed(speed); - if (sneaking != null && Main.client.player.input.sneaking != sneaking) - Main.client.player.input.sneaking = sneaking; - if (jumping != null && Main.client.player.input.jumping != jumping) - Main.client.player.input.jumping = jumping; - if (movementSideways != null && Main.client.player.input.movementSideways != movementSideways) - Main.client.player.input.movementSideways = movementSideways; - if (movementForward != null && Main.client.player.input.movementForward != movementForward) - Main.client.player.input.movementForward = movementForward; - if (pressingForward != null && Main.client.player.input.pressingForward != pressingForward) - Main.client.player.input.pressingForward = pressingForward; - if (pressingBack != null && Main.client.player.input.pressingBack != pressingBack) - Main.client.player.input.pressingBack = pressingBack; - if (pressingLeft != null && Main.client.player.input.pressingLeft != pressingLeft) - Main.client.player.input.pressingLeft = pressingLeft; - if (pressingRight != null && Main.client.player.input.pressingRight != pressingRight) - Main.client.player.input.pressingRight = pressingRight; - } - - public String serialize() { - return "p=" + - ((sneaking == null) ? "n" : (sneaking ? "1" : "0")) + "&" + - ((jumping == null) ? "n" : (jumping ? "1" : "0")) + "&" + - ((movementSideways == null) ? "n" : movementSideways) + "&" + - ((movementForward == null) ? "n" : movementForward) + "&" + - ((pressingForward == null) ? "n" : (pressingForward ? "1" : "0")) + "&" + - ((pressingBack == null) ? "n" : (pressingBack ? "1" : "0")) + "&" + - ((pressingLeft == null) ? "n" : (pressingLeft ? "1" : "0")) + "&" + - ((pressingRight == null) ? "n" : (pressingRight ? "1" : "0")) + "&" + - head_yaw + "&" + body_yaw + "&" + pitch + "&" + - ((sprinting == null) ? "n" : (sprinting ? "1" : "0") + - "&" + yaw + "&" + speed); - } - - public String getType() { - return "input"; - } -} diff --git a/remappedSrc/themixray/repeating/mod/event/RecordMoveEvent.java b/remappedSrc/themixray/repeating/mod/event/RecordMoveEvent.java deleted file mode 100644 index 7b964de..0000000 --- a/remappedSrc/themixray/repeating/mod/event/RecordMoveEvent.java +++ /dev/null @@ -1,42 +0,0 @@ -package themixray.repeating.mod.event; - -import net.minecraft.entity.MovementType; -import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.Main; - -public class RecordMoveEvent extends RecordEvent { - public Vec3d vec; - public float yaw; - public float pitch; - - public static RecordMoveEvent fromArgs(String[] a) { - return new RecordMoveEvent(new Vec3d( - Double.parseDouble(a[0]), - Double.parseDouble(a[1]), - Double.parseDouble(a[2])), - Float.parseFloat(a[3]), - Float.parseFloat(a[4])); - } - - public RecordMoveEvent(Vec3d vec, float yaw, float pitch) { - this.vec = vec; - this.yaw = yaw; - this.pitch = pitch; - } - - public void replay() { - Vec3d p = Main.client.player.getPos(); - Vec3d v = new Vec3d(vec.getX() - p.getX(), vec.getY() - p.getY(), vec.getZ() - p.getZ()); - Main.client.player.move(MovementType.SELF, v); - Main.client.player.setYaw(yaw); - Main.client.player.setPitch(pitch); - } - - public String serialize() { - return "m=" + vec.getX() + "&" + vec.getY() + "&" + vec.getZ() + "&" + yaw + "&" + pitch; - } - - public String getType() { - return "move"; - } -} diff --git a/remappedSrc/themixray/repeating/mod/mixin/ClientMixin.java b/remappedSrc/themixray/repeating/mod/mixin/ClientMixin.java deleted file mode 100644 index 60e9e64..0000000 --- a/remappedSrc/themixray/repeating/mod/mixin/ClientMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.MinecraftClient; -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 themixray.repeating.mod.Main; -import themixray.repeating.mod.TickTask; - -@Mixin(MinecraftClient.class) -public abstract class ClientMixin { - @Inject(at = @At(value = "HEAD"), method = "tick") - private void onTickHead(CallbackInfo ci) { - if (Main.me.is_recording) - Main.me.recordAllInput(); - TickTask.tickTasks(TickTask.TickAt.CLIENT_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.CLIENT_TAIL); - } -} diff --git a/remappedSrc/themixray/repeating/mod/mixin/MovementMixin.java b/remappedSrc/themixray/repeating/mod/mixin/MovementMixin.java deleted file mode 100644 index 45190ba..0000000 --- a/remappedSrc/themixray/repeating/mod/mixin/MovementMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; -import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.HitResult; -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 themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordBlockBreakEvent; -import themixray.repeating.mod.event.RecordBlockInteractEvent; -import themixray.repeating.mod.TickTask; - -@Mixin(ClientPlayerEntity.class) -public abstract class MovementMixin { - - @Inject(at = @At(value = "HEAD"), method = "init") - private void init(CallbackInfo ci) { - PlayerBlockBreakEvents.AFTER.register((world, player, pos, blockState, blockEntity) -> { - if (Main.me.is_recording) - Main.me.recordTick(new RecordBlockBreakEvent(pos)); - }); - - UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (hitResult.getType().equals(HitResult.Type.BLOCK)) - if (Main.me.is_recording) - Main.me.recordTick(new RecordBlockInteractEvent(hand,hitResult)); - return ActionResult.PASS; - }); - } - - @Inject(at = @At(value = "HEAD"), method = "tickMovement") - private void onMoveHead(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.MOVEMENT_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onMoveTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.MOVEMENT_TAIL); - } -} diff --git a/remappedSrc/themixray/repeating/mod/mixin/NetworkMixin.java b/remappedSrc/themixray/repeating/mod/mixin/NetworkMixin.java deleted file mode 100644 index 4f85878..0000000 --- a/remappedSrc/themixray/repeating/mod/mixin/NetworkMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.listener.ServerPlayPacketListener; -import net.minecraft.network.packet.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.time.Duration; -import java.util.function.BooleanSupplier; - -@Mixin(ClientPlayNetworkHandler.class) -public abstract class NetworkMixin { -// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;)V") -// private void onSendPacket1Head(Packet packet, -// CallbackInfo ci) { -// -// } -// -// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V") -// private void onSendPacket2Head(Packet packet, -// BooleanSupplier sendCondition, -// Duration expirationTime, -// CallbackInfo ci) { -// -// } -} diff --git a/remappedSrc/themixray/repeating/mod/mixin/RendererMixin.java b/remappedSrc/themixray/repeating/mod/mixin/RendererMixin.java deleted file mode 100644 index edb363d..0000000 --- a/remappedSrc/themixray/repeating/mod/mixin/RendererMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.render.*; -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 themixray.repeating.mod.TickTask; - -@Mixin(GameRenderer.class) -public abstract class RendererMixin { - @Inject(at = @At(value = "HEAD"), method = "tick") - private void onTickHead(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.RENDER_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.RENDER_TAIL); - } -} diff --git a/remappedSrc/themixray/repeating/mod/render/RenderHelper.java b/remappedSrc/themixray/repeating/mod/render/RenderHelper.java deleted file mode 100644 index 4f80464..0000000 --- a/remappedSrc/themixray/repeating/mod/render/RenderHelper.java +++ /dev/null @@ -1,200 +0,0 @@ -package themixray.repeating.mod.render; - -import lombok.experimental.UtilityClass; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.render.buffer.WorldBuffer; -import themixray.repeating.mod.render.shader.ShaderManager; - -import java.awt.*; - -import static org.lwjgl.opengl.GL33.*; - -@UtilityClass -public class RenderHelper { - public WorldBuffer startLines(WorldRenderContext context) { - glEnable(GL_LINE_SMOOTH); - return new WorldBuffer(GL_LINES, ShaderManager.getPositionColorShader(), context); - } - - public void endLines(WorldBuffer buffer) { - glEnable(GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - glDepthMask(false); - buffer.draw(); - glDepthMask(true); - glDisable(GL_BLEND); - } - - public void drawLine(WorldBuffer buffer, float x1, float y1, float z1, float x2, float y2, float z2, Color color) { - buffer.vert(x1, y1, z1, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x2, y2, z2, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - } - - public static WorldBuffer startTri(WorldRenderContext context) { - return new WorldBuffer(GL_TRIANGLES, ShaderManager.getPositionColorShader(), context); - } - - public static void endTri(WorldBuffer buffer) { - //glDepthRange(0, 0.7); - glEnable(GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); - glDepthMask(false); - buffer.draw(); - glDepthMask(true); - glEnable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthRange(0, 1); - } - - public void drawTri(WorldBuffer buffer, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, Color color) { - buffer.vert(x1, y1, z1, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x2, y2, z2, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x3, y3, z3, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - } - - public static void drawRectFromTri(WorldBuffer buffer, - float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3, - float x4, float y4, float z4, - Color color) { - drawTri(buffer, - x1, y1, z1, - x2, y2, z2, - x3, y3, z3, - color); - drawTri(buffer, - x3, y3, z3, - x4, y4, z4, - x1, y1, z1, - color); - } - - public void drawRectFromLines(WorldBuffer buffer, - float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3, - float x4, float y4, float z4, - Color color) { - drawLine(buffer, - x1, y1, z1, - x2, y2, z2, - color); - drawLine(buffer, - x2, y2, z2, - x3, y3, z3, - color); - drawLine(buffer, - x3, y3, z3, - x4, y4, z4, - color); - drawLine(buffer, - x4, y4, z4, - x1, y1, z1, - color); - } - - public void drawBoxFromTri(WorldBuffer buffer, - float x1, float y1, float z1, - float x2, float y2, float z2, - Color color) { - float[][] v = new float[][]{ - new float[]{Math.min(x1, x2), Math.min(y1, y2), Math.min(z1, z2)}, - new float[]{Math.max(x1, x2), Math.max(y1, y2), Math.max(z1, z2)}}; - - drawRectFromTri(buffer, - v[0][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[0][2], - v[0][0], v[1][1], v[0][2], - color); - - drawRectFromTri(buffer, - v[0][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[1][2], - v[0][0], v[0][1], v[1][2], - color); - - drawRectFromTri(buffer, - v[0][0], v[0][1], v[0][2], - v[0][0], v[0][1], v[1][2], - v[0][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[0][2], - color); - - drawRectFromTri(buffer, - v[0][0], v[0][1], v[1][2], - v[1][0], v[0][1], v[1][2], - v[1][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[1][2], - color); - - drawRectFromTri(buffer, - v[0][0], v[1][1], v[0][2], - v[1][0], v[1][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[1][2], - color); - - drawRectFromTri(buffer, - v[1][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[1][2], - v[1][0], v[1][1], v[1][2], - v[1][0], v[1][1], v[0][2], - color); - } - - public void drawBoxFromLines(WorldBuffer buffer, - float x1, float y1, float z1, - float x2, float y2, float z2, - Color color) { - float[][] v = new float[][]{ - new float[]{Math.min(x1, x2), Math.min(y1, y2), Math.min(z1, z2)}, - new float[]{Math.max(x1, x2), Math.max(y1, y2), Math.max(z1, z2)}}; - - drawRectFromLines(buffer, - v[0][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[0][2], - v[1][0], v[1][1], v[0][2], - v[0][0], v[1][1], v[0][2], - color); - - drawRectFromLines(buffer, - v[0][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[1][2], - v[0][0], v[0][1], v[1][2], - color); - - drawRectFromLines(buffer, - v[0][0], v[0][1], v[0][2], - v[0][0], v[0][1], v[1][2], - v[0][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[0][2], - color); - - drawRectFromLines(buffer, - v[0][0], v[0][1], v[1][2], - v[1][0], v[0][1], v[1][2], - v[1][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[1][2], - color); - - drawRectFromLines(buffer, - v[0][0], v[1][1], v[0][2], - v[1][0], v[1][1], v[0][2], - v[1][0], v[1][1], v[1][2], - v[0][0], v[1][1], v[1][2], - color); - - drawRectFromLines(buffer, - v[1][0], v[0][1], v[0][2], - v[1][0], v[0][1], v[1][2], - v[1][0], v[1][1], v[1][2], - v[1][0], v[1][1], v[0][2], - color); - } -} diff --git a/remappedSrc/themixray/repeating/mod/render/RenderSystem.java b/remappedSrc/themixray/repeating/mod/render/RenderSystem.java deleted file mode 100644 index a5fa15c..0000000 --- a/remappedSrc/themixray/repeating/mod/render/RenderSystem.java +++ /dev/null @@ -1,13 +0,0 @@ -package themixray.repeating.mod.render; - -import lombok.experimental.UtilityClass; -import themixray.repeating.mod.render.buffer.BufferManager; -import themixray.repeating.mod.render.shader.ShaderManager; - -@UtilityClass -public class RenderSystem { - public static void init() { - BufferManager.init(); - ShaderManager.init(); - } -} diff --git a/remappedSrc/themixray/repeating/mod/render/buffer/Vertex.java b/remappedSrc/themixray/repeating/mod/render/buffer/Vertex.java deleted file mode 100644 index 5aaa113..0000000 --- a/remappedSrc/themixray/repeating/mod/render/buffer/Vertex.java +++ /dev/null @@ -1,30 +0,0 @@ -package themixray.repeating.mod.render.buffer; - -import lombok.Getter; - -public class Vertex { - @Getter - private float x; - @Getter - private float y; - @Getter - private float z; - @Getter - private float r; - @Getter - private float g; - @Getter - private float b; - @Getter - private float a; - - public Vertex(float x, float y, float z, float r, float g, float b, float a) { - this.x = x; - this.y = y; - this.z = z; - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } -} \ No newline at end of file diff --git a/remappedSrc/themixray/repeating/mod/render/shader/Shader.java b/remappedSrc/themixray/repeating/mod/render/shader/Shader.java deleted file mode 100644 index e11dd9a..0000000 --- a/remappedSrc/themixray/repeating/mod/render/shader/Shader.java +++ /dev/null @@ -1,42 +0,0 @@ -package themixray.repeating.mod.render.shader; - -import lombok.Getter; - -import java.nio.FloatBuffer; - -import static org.lwjgl.opengl.GL33.*; - -public class Shader { - @Getter - private final int id; - - - public Shader(String name) { - int v = ShaderManager.loadShaderProgram(name, ShaderManager.ShaderType.VERTEX); - int f = ShaderManager.loadShaderProgram(name, ShaderManager.ShaderType.FRAGMENT); - this.id = glCreateProgram(); - glAttachShader(id, v); - glAttachShader(id, f); - glLinkProgram(id); - } - - public void bind() { - glUseProgram(id); - } - - public void unbind() { - glUseProgram(0); - } - - public void uniformMatrix4f(String name, FloatBuffer matrix) { - bind(); - glUniformMatrix4fv(glGetUniformLocation(id, name), false, matrix); - unbind(); - } - - public void uniformValue2f(String name, float value1, float value2) { - bind(); - glUniform2f(glGetUniformLocation(id, name), value1, value2); - unbind(); - } -} diff --git a/remappedSrc/themixray/repeating/mod/widget/RecordListWidget.java b/remappedSrc/themixray/repeating/mod/widget/RecordListWidget.java deleted file mode 100644 index 1ac42b2..0000000 --- a/remappedSrc/themixray/repeating/mod/widget/RecordListWidget.java +++ /dev/null @@ -1,150 +0,0 @@ -package themixray.repeating.mod.widget; - -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.*; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.RecordState; -import themixray.repeating.mod.RepeatingScreen; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - -public class RecordListWidget extends ScrollableWidget { - private List widgets = new ArrayList<>(); - private boolean focused = false; - - public RecordListWidget(int x, int y, int width, int height) { - super(x,y,width,height,Text.empty()); - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - focused = true; - boolean res = super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); - focused = false; - return res; - } - - @Override - protected double getDeltaYPerScroll() { - return 10; - } - - @Override - protected void renderContents(DrawContext ctx, int mouseX, int mouseY, float delta) { - int y = 0; - for (RecordWidget wid: widgets) { - wid.method_46419(y); - wid.render(ctx, mouseX, (int) (mouseY + this.getScrollY()), delta); - - y += wid.getHeight(); - y += 2; - } - } - - public void addWidget(RecordState record) { - RecordWidget widget = new RecordWidget(0, 0, width, 55, record, this); - widget.init(null); - widgets.add(0, widget); - } - - public void removeWidget(RecordState record) { - widgets.removeIf(i -> i.getRecord().equals(record)); - } - - @Override - public void setFocused(boolean focused) { - - } - - @Override - public boolean isFocused() { - return focused; - } - - @Override - protected int getContentsHeight() { - return !widgets.isEmpty() ? widgets.size() * 55 + (widgets.size() - 1) * 2 : 0; - } - - public void init(RepeatingScreen screen) { - for (RecordWidget widget : widgets) { - widget.init(screen); - } - - screen.addDrawableChild(this); - } - - @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) { - - } - - public RecordWidget getWidget(RecordState record) { - for (RecordWidget widget : widgets) { - if (widget.getRecord().equals(record)) { - return widget; - } - } - return null; - } - - public interface transport { - boolean check(ClickableWidget ch); - } - - public boolean checkTransport(transport tr) { - for (RecordWidget wid : widgets) { - for (ClickableWidget child : wid.getChildren()) { - if (tr.check(child)) { - return true; - } - } - } - return false; - } - - public boolean checkTransportNF(transport tr) { - for (RecordWidget wid : widgets) { - for (ClickableWidget child : wid.getChildren()) { - boolean res = tr.check(child); - - if (res) { - child.setFocused(true); - return true; - } else { - child.setFocused(false); - } - } - } - return false; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - return checkTransportNF((c) -> c.mouseClicked(mouseX, mouseY + this.getScrollY(), button)) || super.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean charTyped(char chr, int modifiers) { - return checkTransport((c) -> c.charTyped(chr, modifiers)) || super.charTyped(chr, modifiers); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - return checkTransport((c) -> c.keyPressed(keyCode, scanCode, modifiers)) || super.keyPressed(keyCode, scanCode, modifiers); - } - - @Override - public boolean keyReleased(int keyCode, int scanCode, int modifiers) { - return checkTransport((c) -> c.keyReleased(keyCode, scanCode, modifiers)) || super.keyReleased(keyCode, scanCode, modifiers); - } -} diff --git a/remappedSrc/themixray/repeating/mod/widget/RecordWidget.java b/remappedSrc/themixray/repeating/mod/widget/RecordWidget.java deleted file mode 100644 index bef439a..0000000 --- a/remappedSrc/themixray/repeating/mod/widget/RecordWidget.java +++ /dev/null @@ -1,196 +0,0 @@ -package themixray.repeating.mod.widget; - -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.*; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.RecordState; -import themixray.repeating.mod.RenderListener; -import themixray.repeating.mod.RepeatingScreen; - -import java.awt.*; -import java.io.IOException; -import java.util.ArrayList; - -import java.util.List; -import java.util.function.Consumer; - -public class RecordWidget implements Drawable, Widget { - private RecordState record; - - private List children; - - private RecordListWidget parent; - - private int x; - private int y; - private int width; - private int height; - - public RecordWidget(int x, int y, int width, int height, RecordState record, RecordListWidget parent) { - this.parent = parent; - this.record = record; - - this.x = x; - this.y = y; - this.width = width; - this.height = height; - - this.children = new ArrayList<>(); - } - - public void method_46421(int x) { - this.x = x; - } - public void method_46419(int y) { - this.y = y; - } - public int getX() { - return x; - } - public int getY() { - return y; - } - public int getWidth() { - return width; - } - public int getHeight() { - return height; - } - - public List getChildren() { - return children; - } - - @Override - public void forEachChild(Consumer consumer) { - children.forEach(consumer); - } - - public void init(RepeatingScreen screen) { - this.children = new ArrayList<>(); - - TextFieldWidget name_widget = new TextFieldWidget( - Main.client.textRenderer, - parent.getX() + getX() + 5, - parent.getY() + getY() + 5, - 102, - 10, - Text.empty()); - - name_widget.setText(record.getName()); - - name_widget.setChangedListener((s) -> { - record.setName(s); - try { - record.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - - children.add(name_widget); - - ButtonWidget delete_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.delete"), (i) -> { - record.remove(); - }).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4, 65, 13).build(); - - children.add(delete_button); - - ButtonWidget export_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.export"), (i) -> { - if (Desktop.isDesktopSupported()) { - Desktop desk = Desktop.getDesktop(); - try { - desk.browseFileDirectory(record.getFile()); - } catch (Exception e) { - try { - desk.browse(record.getFile().toURI()); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - } - }).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 14, 65, 13).build(); - - children.add(export_button); - - ButtonWidget replay_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.start"), (i) -> { - if (Main.me.is_replaying) { - Main.me.stopReplay(); - } - - i.setMessage(Text.translatable("text.repeating-mod.stop")); - Main.me.now_record = record; - Main.me.startReplay(); - }).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 28, 65, 13) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.replay_tooltip"))).build(); - - children.add(replay_button); - } - - public RecordState getRecord() { - return record; - } - - public void drawText(int x, int y, DrawContext ctx, List lines, float size, int line_height, boolean shadow) { - ctx.getMatrices().push(); - ctx.getMatrices().scale(size, size, size); - - int now_y = y; - - for (Text line : lines) { - ctx.drawText(Main.client.textRenderer, line, (int) (x / size), (int) (now_y / size), line.getStyle().getColor().getRgb(), shadow); - now_y += line_height; - } - - ctx.getMatrices().pop(); - } - - @Override - public void render(DrawContext ctx, int mouseX, int mouseY, float delta) { - int color = record.equals(Main.me.now_record) ? 0xFF555555 : 0xFF333333; - - ctx.fill(parent.getX() + getX(), - parent.getY() + getY(), - parent.getX() + getX() + getWidth(), - parent.getY() + getY() + getHeight(), - color); - - drawText( - parent.getX() + getX() + 5, - parent.getY() + getY() + 5 + 12, - ctx, List.of( - Text.translatable("text.repeating-mod.recorded_at") - .append(": ") - .styled((s) -> s.withColor(0xbbbbbb)), - Text.literal(RecordState.DATE_FORMAT.format(record.getDate())).styled((s) -> s.withColor(0xffffff)), - Text.translatable("text.repeating-mod.author") - .append(": ") - .styled((s) -> s.withColor(0xbbbbbb)), - Text.literal(record.getAuthor()).styled((s) -> s.withColor(0xffffff)) - ), 1, - 9, - false); - - if (!children.isEmpty()) { - ClickableWidget name_widget = children.get(0); - name_widget.setPosition(parent.getX() + getX() + 5, parent.getY() + getY() + 5); - - ClickableWidget delete_button = children.get(1); - delete_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4); - - ClickableWidget export_button = children.get(2); - export_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 14); - - ClickableWidget replay_button = children.get(3); - replay_button.setPosition(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 28); - } - - for (ClickableWidget child : children) { - child.render(ctx, mouseX, mouseY, delta); - } - } -} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..27efeb0 --- /dev/null +++ b/shell.nix @@ -0,0 +1,6 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + shellHook = '' + export LD_LIBRARY_PATH="''${LD_LIBRARY_PATH}''${LD_LIBRARY_PATH:+:}${pkgs.libglvnd}/lib" + ''; +} \ No newline at end of file diff --git a/remappedSrc/themixray/repeating/mod/EasyConfig.java b/src/main/java/ru/themixray/repeating_mod/EasyConfig.java similarity index 95% rename from remappedSrc/themixray/repeating/mod/EasyConfig.java rename to src/main/java/ru/themixray/repeating_mod/EasyConfig.java index 8836722..b592deb 100644 --- a/remappedSrc/themixray/repeating/mod/EasyConfig.java +++ b/src/main/java/ru/themixray/repeating_mod/EasyConfig.java @@ -1,103 +1,103 @@ -package themixray.repeating.mod; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.io.File; - -public class EasyConfig { - public final Path path; - public final File file; - public Map data; - - public EasyConfig(File f, Map def) { - this.path = f.toPath(); - this.file = f; - this.data = new HashMap<>(); - - if (!file.exists()) { - try { - file.createNewFile(); - write(def); - } catch (IOException e) { - e.printStackTrace(); - } - } - - reload(); - - for (Map.Entry m:def.entrySet()) - if (!data.containsKey(m.getKey())) - data.put(m.getKey(),m.getValue()); - - save(); - } - public EasyConfig(Path f, Map def) { - this(f.toFile(),def); - } - public EasyConfig(String parent,String child,Map def) { - this(new File(parent,child),def); - } - public EasyConfig(File parent,String child,Map def) { - this(new File(parent,child),def); - } - public EasyConfig(Path parent,String child,Map def) { - this(new File(parent.toFile(),child),def); - } - - public EasyConfig(File f) { - this(f,new HashMap<>()); - } - public EasyConfig(Path path) { - this(path.toFile(),new HashMap<>()); - } - public EasyConfig(String parent,String child) { - this(new File(parent,child),new HashMap<>()); - } - public EasyConfig(File parent,String child) { - this(new File(parent,child),new HashMap<>()); - } - public EasyConfig(Path parent,String child) { - this(new File(parent.toFile(),child),new HashMap<>()); - } - - public void reload() { - data = read(); - } - public void save() { - write(data); - } - - private String toText(Map p) { - StringBuilder t = new StringBuilder(); - for (Map.Entry e:p.entrySet()) - t.append(e.getKey()).append("=").append(e.getValue()).append("\n"); - return t.toString(); - } - private Map toMap(String j) { - Map m = new HashMap<>(); - for (String l:j.split("\n")) { - String s[] = l.split("="); - m.put(s[0],s[1]); - } - return m; - } - - private Map read() { - try { - return toMap(Files.readString(path)); - } catch (IOException e) { - e.printStackTrace(); - } - return new HashMap<>(); - } - private void write(Map p) { - try { - Files.write(path, toText(p).getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } -} +package ru.themixray.repeating_mod; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.io.File; + +public class EasyConfig { + public final Path path; + public final File file; + public Map data; + + public EasyConfig(File f, Map def) { + this.path = f.toPath(); + this.file = f; + this.data = new HashMap<>(); + + if (!file.exists()) { + try { + file.createNewFile(); + write(def); + } catch (IOException e) { + e.printStackTrace(); + } + } + + reload(); + + for (Map.Entry m:def.entrySet()) + if (!data.containsKey(m.getKey())) + data.put(m.getKey(),m.getValue()); + + save(); + } + public EasyConfig(Path f, Map def) { + this(f.toFile(),def); + } + public EasyConfig(String parent,String child,Map def) { + this(new File(parent,child),def); + } + public EasyConfig(File parent,String child,Map def) { + this(new File(parent,child),def); + } + public EasyConfig(Path parent,String child,Map def) { + this(new File(parent.toFile(),child),def); + } + + public EasyConfig(File f) { + this(f,new HashMap<>()); + } + public EasyConfig(Path path) { + this(path.toFile(),new HashMap<>()); + } + public EasyConfig(String parent,String child) { + this(new File(parent,child),new HashMap<>()); + } + public EasyConfig(File parent,String child) { + this(new File(parent,child),new HashMap<>()); + } + public EasyConfig(Path parent,String child) { + this(new File(parent.toFile(),child),new HashMap<>()); + } + + public void reload() { + data = read(); + } + public void save() { + write(data); + } + + private String toText(Map p) { + StringBuilder t = new StringBuilder(); + for (Map.Entry e:p.entrySet()) + t.append(e.getKey()).append("=").append(e.getValue()).append("\n"); + return t.toString(); + } + private Map toMap(String j) { + Map m = new HashMap<>(); + for (String l:j.split("\n")) { + String s[] = l.split("="); + m.put(s[0],s[1]); + } + return m; + } + + private Map read() { + try { + return toMap(Files.readString(path)); + } catch (IOException e) { + e.printStackTrace(); + } + return new HashMap<>(); + } + private void write(Map p) { + try { + Files.write(path, toText(p).getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/themixray/repeating/mod/Main.java b/src/main/java/ru/themixray/repeating_mod/Main.java similarity index 71% rename from src/main/java/themixray/repeating/mod/Main.java rename to src/main/java/ru/themixray/repeating_mod/Main.java index c2b8645..296904c 100644 --- a/src/main/java/themixray/repeating/mod/Main.java +++ b/src/main/java/ru/themixray/repeating_mod/Main.java @@ -1,339 +1,309 @@ -package themixray.repeating.mod; - -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.Vec3d; -import org.lwjgl.glfw.GLFW; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import themixray.repeating.mod.event.events.DelayEvent; -import themixray.repeating.mod.event.RecordEvent; -import themixray.repeating.mod.event.events.InputEvent; -import themixray.repeating.mod.event.events.MoveEvent; -import themixray.repeating.mod.render.RenderHelper; -import themixray.repeating.mod.render.RenderSystem; -import themixray.repeating.mod.render.buffer.WorldBuffer; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.List; - -public class Main implements ClientModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger("repeating-mod"); - public static final MinecraftClient client = MinecraftClient.getInstance(); - public static final FabricLoader loader = FabricLoader.getInstance(); - public static Main me; - - public RecordList record_list; - public RecordState now_record; - - public boolean is_recording = false; - public long last_record = -1; - public TickTask move_tick = null; - - public TickTask replay_tick = null; - public boolean is_replaying = false; - public boolean loop_replay = false; - public static InputEvent input_replay = null; - - public long living_ticks = 0; - - public static RepeatingScreen menu; - private static KeyBinding menu_key; - private static KeyBinding toggle_replay_key; - private static KeyBinding toggle_record_key; - - public long record_pos_delay = 20; - - public static Random rand = new Random(); - - public EasyConfig conf; - public File records_folder; - - @Override - public void onInitializeClient() { - LOGGER.info("Repeating mod initialized"); - me = this; - - now_record = null; - - records_folder = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating_mod_records"); - if (!records_folder.exists()) records_folder.mkdir(); - - record_list = new RecordList(records_folder); - record_list.loadRecords(); - - RenderSystem.init(); - WorldRenderEvents.LAST.register(context -> { - WorldBuffer buffer = RenderHelper.startTri(context); - if (now_record != null) { - Vec3d start_pos = now_record.getStartRecordPos(); - Vec3d finish_pos = now_record.getFinishRecordPos(); - - if (start_pos != null) drawRecordPos(buffer, start_pos, new Color(70, 230, 70, 128)); - if (finish_pos != null) drawRecordPos(buffer, finish_pos, new Color(230, 70, 70, 128)); - } - RenderHelper.endTri(buffer); - }); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - TickTask.tickTasks(TickTask.TickAt.CLIENT_EVENT); - }); - - Map def = new HashMap<>(); - def.put("record_pos_delay", String.valueOf(record_pos_delay)); - - conf = new EasyConfig(loader.getConfigDir(),"repeating-mod",def); - - record_pos_delay = Long.parseLong(conf.data.get("record_pos_delay")); - - menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.menu",InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_J,"text.repeating-mod.name")); - toggle_replay_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.toggle_replay",InputUtil.Type.KEYSYM, - -1,"text.repeating-mod.name")); - toggle_record_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.repeating-mod.toggle_record",InputUtil.Type.KEYSYM, - -1,"text.repeating-mod.name")); - - menu = new RepeatingScreen(); - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (menu_key.wasPressed()) - client.setScreen(menu); - if (toggle_replay_key.wasPressed()) { - if (now_record != null) { - if (!is_recording) { - if (is_replaying) - stopReplay(); - else startReplay(); - menu.updateButtons(); - } - } - } - if (toggle_record_key.wasPressed()) { - if (!is_replaying) { - if (is_recording) - stopRecording(); - else startRecording(); - menu.updateButtons(); - } - } - }); - - new TickTask(0,0) { - @Override - public void run() { - living_ticks++; - } - }; - - System.setProperty("java.awt.headless", "false"); - } - - public void setNowRecord(RecordState record) { - now_record = record; - } - - public void drawRecordPos(WorldBuffer buffer, Vec3d pos, Color color) { - RenderHelper.drawRectFromTri(buffer, - (float) pos.getX() - 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() - 0.25F, - - (float) pos.getX() + 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() - 0.25F, - - (float) pos.getX() + 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() + 0.25F, - - (float) pos.getX() - 0.25F, - (float) pos.getY() + 0.01F, - (float) pos.getZ() + 0.25F, - color); - } - - public void startRecording() { - is_recording = true; - menu.updateButtons(); - - now_record = record_list.newRecord(); - - Vec3d start_pos = client.player.getPos(); - now_record.addEvent(new MoveEvent(start_pos,client.player.getHeadYaw(),client.player.getPitch())); - now_record.setStartRecordPos(start_pos); - - if (record_pos_delay > 0) { - move_tick = new TickTask( - record_pos_delay, - record_pos_delay) { - @Override - public void run() { - now_record.addEvent(new MoveEvent(client.player.getPos(), - client.player.getHeadYaw(), client.player.getPitch())); - } - }; - } - - sendMessage(Text.translatable("message.repeating-mod.record_start")); - } - - public void recordTick(RecordEvent e) { - if (is_recording) { - long now = living_ticks; - if (last_record != -1) { - long diff = now - last_record - 2; - if (diff > 0) now_record.addEvent(new DelayEvent(diff)); - } - now_record.addEvent(e); - last_record = now; - } - } - - public void recordAllInput() { - if (client.player == null) { - stopRecording(); - return; - } - - InputEvent l = ((InputEvent) now_record.getLastEvent("input")); - if (l == null) { - InputEvent e = new InputEvent( - client.player.input.sneaking, - client.player.input.jumping, - client.player.input.movementSideways, - client.player.input.movementForward, - client.player.input.pressingForward, - client.player.input.pressingBack, - client.player.input.pressingLeft, - client.player.input.pressingRight, - client.player.getHeadYaw(), - client.player.getBodyYaw(), - client.player.getPitch(), - client.player.isSprinting(), - client.player.getYaw(), - client.player.getMovementSpeed()); - recordTick(e); - } else { - InputEvent e = new InputEvent( - ((Boolean) client.player.input.sneaking == l.sneaking) ? null : client.player.input.sneaking, - ((Boolean) client.player.input.jumping == l.jumping) ? null : client.player.input.jumping, - (((Float) client.player.input.movementSideways).equals(l.movementSideways)) ? null : client.player.input.movementSideways, - (((Float) client.player.input.movementForward).equals(l.movementForward)) ? null : client.player.input.movementForward, - ((Boolean) client.player.input.pressingForward == l.pressingForward) ? null : client.player.input.pressingForward, - ((Boolean) client.player.input.pressingBack == l.pressingBack) ? null : client.player.input.pressingBack, - ((Boolean) client.player.input.pressingLeft == l.pressingLeft) ? null : client.player.input.pressingLeft, - ((Boolean) client.player.input.pressingRight == l.pressingRight) ? null : client.player.input.pressingRight, - client.player.getHeadYaw(), Main.client.player.getBodyYaw(),client.player.getPitch(), - ((Boolean) client.player.isSprinting() == l.sprinting) ? null : client.player.isSprinting(), - client.player.getYaw(),client.player.getMovementSpeed()); - - if (!(e.isEmpty() && - e.yaw == l.yaw && - e.head_yaw == l.head_yaw && - e.pitch == l.pitch && - e.body_yaw == l.body_yaw)) { - e.fillEmpty(l); - recordTick(e); - } - } - } - - public void stopRecording() { - is_recording = false; - now_record.setFinishRecordPos(client.player.getPos()); - try { - now_record.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (move_tick != null) { - move_tick.cancel(); - move_tick = null; - } - menu.updateButtons(); - last_record = -1; - sendMessage(Text.translatable("message.repeating-mod.record_stop")); - } - - - public void startReplay() { - is_recording = false; - is_replaying = true; - menu.updateButtons(); - - List events = now_record.getEvents(); - - replay_tick = new TickTask(0,0, TickTask.TickAt.CLIENT_EVENT) { - public int replay_index = 0; - - @Override - public void run() { - if (!is_replaying) { - cancel(); - return; - } - - RecordEvent e = events.get(replay_index); - if (e instanceof DelayEvent) { - setDelay(((DelayEvent) e).delay); - } else { - e.replay(); - } - - replay_index++; - if (!loop_replay) { - if (replay_index == events.size()) { - stopReplay(); - cancel(); - } - } else if (replay_index == events.size()) { - replay_index = 0; - } - } - }; - - sendMessage(Text.translatable("message.repeating-mod.replay_start")); - } - - public void stopReplay() { - is_recording = false; - is_replaying = false; - if (replay_tick != null) { - replay_tick.cancel(); - replay_tick = null; - } - try { - now_record.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - menu.updateButtons(); - record_list.getWidget().getWidget(now_record).getChildren().get(3).setMessage(Text.translatable("text.repeating-mod.start")); - sendMessage(Text.translatable("message.repeating-mod.replay_stop")); - } - - public static void sendMessage(MutableText text) { - client.player.sendMessage(Text.literal("[") - .append(Text.translatable("text.repeating-mod.name")) - .append("] ").formatted(Formatting.BOLD,Formatting.DARK_GRAY) - .append(text.formatted(Formatting.RESET).formatted(Formatting.GRAY))); - } - - public static void sendDebug(String s) { - client.player.sendMessage(Text.literal("[DEBUG] ").append(Text.of(s))); - } -} +package ru.themixray.repeating_mod; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.Vec3d; +import org.lwjgl.glfw.GLFW; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ru.themixray.repeating_mod.event.events.DelayEvent; +import ru.themixray.repeating_mod.event.RecordEvent; +import ru.themixray.repeating_mod.event.events.InputEvent; +import ru.themixray.repeating_mod.event.events.MoveEvent; +import ru.themixray.repeating_mod.render.RenderHelper; +import ru.themixray.repeating_mod.render.RenderSystem; +import ru.themixray.repeating_mod.render.buffer.WorldBuffer; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.List; + +public class Main implements ClientModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger("repeating-mod"); + public static final MinecraftClient client = MinecraftClient.getInstance(); + public static final FabricLoader loader = FabricLoader.getInstance(); + public static Main me; + + public RecordList record_list; + public RecordState now_record; + + public boolean is_recording = false; + public long last_record = -1; + public TickTask move_tick = null; + + public TickTask replay_tick = null; + public boolean is_replaying = false; + public boolean loop_replay = false; + public static InputEvent input_replay = null; + + public long living_ticks = 0; + + public static RepeatingScreen menu; + private static KeyBinding menu_key; + private static KeyBinding toggle_replay_key; + private static KeyBinding toggle_record_key; + + public long record_pos_delay = -1; + + public static Random rand = new Random(); + + public EasyConfig conf; + public File records_folder; + + @Override + public void onInitializeClient() { + LOGGER.info("Repeating mod initialized"); + me = this; + + now_record = null; + + records_folder = new File(FabricLoader.getInstance().getGameDir().toFile(),"repeating_mod_records"); + if (!records_folder.exists()) records_folder.mkdir(); + + record_list = new RecordList(records_folder); + record_list.loadRecords(); + + RenderSystem.init(); + WorldRenderEvents.AFTER_ENTITIES.register(context -> { + WorldBuffer buffer = RenderHelper.startTri(context); + if (now_record != null) { + Vec3d start_pos = now_record.getStartRecordPos(); + Vec3d finish_pos = now_record.getFinishRecordPos(); + + if (start_pos != null) drawRecordPos(buffer, start_pos, new Color(70, 230, 70, 128)); + if (finish_pos != null) drawRecordPos(buffer, finish_pos, new Color(230, 70, 70, 128)); + } + RenderHelper.endTri(buffer); + }); + + ClientTickEvents.END_CLIENT_TICK.register(client -> { + TickTask.tickTasks(TickTask.TickAt.CLIENT_EVENT); + }); + + Map def = new HashMap<>(); + def.put("record_pos_delay", String.valueOf(record_pos_delay)); + + conf = new EasyConfig(loader.getConfigDir(),"repeating-mod",def); + + record_pos_delay = Long.parseLong(conf.data.get("record_pos_delay")); + + menu_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.repeating-mod.menu",InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_J,"text.repeating-mod.name")); + toggle_replay_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.repeating-mod.toggle_replay",InputUtil.Type.KEYSYM, + -1,"text.repeating-mod.name")); + toggle_record_key = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.repeating-mod.toggle_record",InputUtil.Type.KEYSYM, + -1,"text.repeating-mod.name")); + + menu = new RepeatingScreen(); + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (menu_key.wasPressed()) + client.setScreen(menu); + if (toggle_replay_key.wasPressed()) { + if (now_record != null) { + if (!is_recording) { + if (is_replaying) + stopReplay(); + else startReplay(); + menu.updateButtons(); + } + } + } + if (toggle_record_key.wasPressed()) { + if (!is_replaying) { + if (is_recording) + stopRecording(); + else startRecording(); + menu.updateButtons(); + } + } + }); + + new TickTask(0,0) { + @Override + public void run() { + living_ticks++; + } + }; + + System.setProperty("java.awt.headless", "false"); + } + + public void setNowRecord(RecordState record) { + now_record = record; + } + + public void drawRecordPos(WorldBuffer buffer, Vec3d pos, Color color) { + RenderHelper.drawRectFromTri(buffer, + (float) pos.getX() - 0.25F, + (float) pos.getY() + 0.01F, + (float) pos.getZ() - 0.25F, + + (float) pos.getX() + 0.25F, + (float) pos.getY() + 0.01F, + (float) pos.getZ() - 0.25F, + + (float) pos.getX() + 0.25F, + (float) pos.getY() + 0.01F, + (float) pos.getZ() + 0.25F, + + (float) pos.getX() - 0.25F, + (float) pos.getY() + 0.01F, + (float) pos.getZ() + 0.25F, + color); + } + + public void startRecording() { + is_recording = true; + menu.updateButtons(); + + now_record = record_list.newRecord(); + + Vec3d start_pos = client.player.getPos(); + recordTick(new MoveEvent(start_pos,client.player.getHeadYaw(),client.player.getPitch())); + now_record.setStartRecordPos(start_pos); + + if (record_pos_delay > 0) { + move_tick = new TickTask( + record_pos_delay, + record_pos_delay) { + @Override + public void run() { + recordTick(new MoveEvent(client.player.getPos(), + client.player.getHeadYaw(), client.player.getPitch())); + } + }; + } + + sendMessage(Text.translatable("message.repeating-mod.record_start")); + } + + public void recordTick(RecordEvent e) { + if (is_recording) { + long now = living_ticks; + if (last_record != -1) { + long diff = now - last_record - 2; + if (diff > 0) now_record.addEvent(new DelayEvent(diff)); + } + now_record.addEvent(e); + last_record = now; + } + } + + public void recordAllInput() { + if (client.player == null) { + stopRecording(); + return; + } + + InputEvent curr = InputEvent.current(); + if (curr == null) return; + + InputEvent last = ((InputEvent) now_record.getLastEvent("input")); + if (last == null) { + recordTick(curr); + } else if (!curr.equals(last)) { + recordTick(curr.differs(last)); + } + } + + public void stopRecording() { + is_recording = false; + now_record.setFinishRecordPos(client.player.getPos()); + try { + now_record.save(); + } catch (IOException e) { + throw new RuntimeException(e); + } + if (move_tick != null) { + move_tick.cancel(); + move_tick = null; + } + menu.updateButtons(); + last_record = -1; + sendMessage(Text.translatable("message.repeating-mod.record_stop")); + } + + + public void startReplay() { + is_recording = false; + is_replaying = true; + menu.updateButtons(); + + List events = now_record.getEvents(); + + replay_tick = new TickTask(0,0, TickTask.TickAt.CLIENT_EVENT) { + public int replay_index = 0; + + @Override + public void run() { + if (!is_replaying) { + cancel(); + return; + } + + RecordEvent e = events.get(replay_index); + if (e != null) { + if (e instanceof DelayEvent) { + setDelay(((DelayEvent) e).delay); + } else { + e.replay(); + } + } + + replay_index++; + if (!loop_replay) { + if (replay_index >= events.size()) { + stopReplay(); + cancel(); + } + } else if (replay_index >= events.size()) { + replay_index = 0; + } + } + }; + + sendMessage(Text.translatable("message.repeating-mod.replay_start")); + } + + public void stopReplay() { + is_recording = false; + is_replaying = false; + if (replay_tick != null) { + replay_tick.cancel(); + replay_tick = null; + } + try { + now_record.save(); + } catch (IOException e) { + throw new RuntimeException(e); + } + menu.updateButtons(); + record_list.getWidget().getWidget(now_record).getChildren().get(3).setMessage(Text.translatable("text.repeating-mod.start")); + sendMessage(Text.translatable("message.repeating-mod.replay_stop")); + } + + public static void sendMessage(MutableText text) { + client.player.sendMessage(Text.literal("[") + .append(Text.translatable("text.repeating-mod.name")) + .append("] ").formatted(Formatting.BOLD,Formatting.DARK_GRAY) + .append(text.formatted(Formatting.RESET).formatted(Formatting.GRAY)), false); + } + +// public static void sendDebug(String s) { +// client.player.sendMessage(Text.literal("[DEBUG] ").append(Text.of(s)), false); +// } +} diff --git a/src/main/java/themixray/repeating/mod/RecordList.java b/src/main/java/ru/themixray/repeating_mod/RecordList.java similarity index 92% rename from src/main/java/themixray/repeating/mod/RecordList.java rename to src/main/java/ru/themixray/repeating_mod/RecordList.java index 99fffe7..cebbc45 100644 --- a/src/main/java/themixray/repeating/mod/RecordList.java +++ b/src/main/java/ru/themixray/repeating_mod/RecordList.java @@ -1,12 +1,9 @@ -package themixray.repeating.mod; +package ru.themixray.repeating_mod; -import net.minecraft.text.Text; -import themixray.repeating.mod.widget.RecordListWidget; +import ru.themixray.repeating_mod.widget.RecordListWidget; import java.io.File; -import java.io.IOException; import java.nio.file.Files; -import java.text.SimpleDateFormat; import java.util.*; public class RecordList { @@ -51,6 +48,7 @@ public class RecordList { } public void addRecord(RecordState record) { + if (record == null) return; records.add(record); widget.addWidget(record); } diff --git a/src/main/java/themixray/repeating/mod/RecordState.java b/src/main/java/ru/themixray/repeating_mod/RecordState.java similarity index 95% rename from src/main/java/themixray/repeating/mod/RecordState.java rename to src/main/java/ru/themixray/repeating_mod/RecordState.java index 21d782b..3a684f5 100644 --- a/src/main/java/themixray/repeating/mod/RecordState.java +++ b/src/main/java/ru/themixray/repeating_mod/RecordState.java @@ -1,10 +1,9 @@ -package themixray.repeating.mod; +package ru.themixray.repeating_mod; import com.google.common.collect.Lists; import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.event.RecordEvent; -import java.awt.*; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -96,6 +95,7 @@ public class RecordState { } public void addEvent(RecordEvent event) { + if (event == null) return; events.add(event); } @@ -124,9 +124,10 @@ public class RecordState { .append(finish_record_pos.getY()).append("n") .append(finish_record_pos.getZ()); - for (int i = 0; i < events.size(); i++) { + for (RecordEvent event : events) { + if (event == null) continue; text.append("\n"); - text.append(events.get(i).serialize()); + text.append(event.serialize()); } Files.write(file.toPath(), text.toString().getBytes()); diff --git a/remappedSrc/themixray/repeating/mod/RenderListener.java b/src/main/java/ru/themixray/repeating_mod/RenderListener.java similarity index 86% rename from remappedSrc/themixray/repeating/mod/RenderListener.java rename to src/main/java/ru/themixray/repeating_mod/RenderListener.java index 9992e48..80558be 100644 --- a/remappedSrc/themixray/repeating/mod/RenderListener.java +++ b/src/main/java/ru/themixray/repeating_mod/RenderListener.java @@ -1,4 +1,4 @@ -package themixray.repeating.mod; +package ru.themixray.repeating_mod; import net.minecraft.client.gui.DrawContext; diff --git a/src/main/java/themixray/repeating/mod/RepeatingScreen.java b/src/main/java/ru/themixray/repeating_mod/RepeatingScreen.java similarity index 95% rename from src/main/java/themixray/repeating/mod/RepeatingScreen.java rename to src/main/java/ru/themixray/repeating_mod/RepeatingScreen.java index 0fcd5ec..0783386 100644 --- a/src/main/java/themixray/repeating/mod/RepeatingScreen.java +++ b/src/main/java/ru/themixray/repeating_mod/RepeatingScreen.java @@ -1,187 +1,187 @@ -package themixray.repeating.mod; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.SliderWidget; -import net.minecraft.text.Text; -import themixray.repeating.mod.widget.RecordListWidget; - -import java.awt.*; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class RepeatingScreen extends Screen { - private static List render_listeners = new ArrayList<>(); - - public ButtonWidget record_btn; - public ButtonWidget loop_btn; - public ButtonWidget import_btn; - - public SliderWidget pos_delay_slider; - - public boolean was_build = false; - - protected RepeatingScreen() { - super(Text.empty()); - } - - public static void addRenderListener(RenderListener render) { - render_listeners.add(render); - } - - public static void removeRenderListener(RenderListener render) { - render_listeners.remove(render); - } - - public void updateButtons() { - if (was_build) { - record_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.is_recording) ? "stop_record" : "start_record"))); - loop_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.loop_replay) ? "off_loop" : "on_loop"))); - } - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - renderBackground(context); - - for (RenderListener l : render_listeners) { - if (l.beforeRender()) { - l.render(context, mouseX, mouseY, delta); - } - } - - super.render(context, mouseX, mouseY, delta); - - for (RenderListener l : render_listeners) { - if (!l.beforeRender()) { - l.render(context, mouseX, mouseY, delta); - } - } - } - - @Override - protected void init() { - RecordListWidget list_widget = Main.me.record_list.getWidget(); - - list_widget.setX(width / 2 + 2); - list_widget.setY(height / 2 - list_widget.getHeight() / 2); - list_widget.init(this); - - - record_btn = ButtonWidget.builder( - Text.translatable("text.repeating-mod.start_record"), button -> { - if (!Main.me.is_replaying) { - if (Main.me.is_recording) - Main.me.stopRecording(); - else Main.me.startRecording(); - updateButtons(); - } - }) - .dimensions(width / 2 - 120, height / 2 - 32, 120, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.record_tooltip"))) - .build(); - - loop_btn = ButtonWidget.builder(Text.empty(), button -> { - Main.me.loop_replay = !Main.me.loop_replay; - updateButtons(); - }) - .dimensions(width / 2 - 120, height / 2 - 10, 120, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.loop_tooltip"))) - .build(); - - pos_delay_slider = new SliderWidget( - width / 2 - 120, height / 2 + 12, 120, 20, - (Main.me.record_pos_delay < 0) ? Text.translatable("text.repeating-mod.nan_pos_delay") : - Text.translatable("text.repeating-mod.pos_delay", String.valueOf(Main.me.record_pos_delay)), - (Main.me.record_pos_delay+1d)/101d) { - - @Override - protected void updateMessage() { - double v = value*101d-1d; - if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); - else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); - } - - @Override - protected void applyValue() { - double v = value*101d-1d; - if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); - else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); - Main.me.record_pos_delay = (long) v; - Main.me.conf.data.put("record_pos_delay",String.valueOf(Main.me.record_pos_delay)); - Main.me.conf.save(); - } - - @Override - public void onRelease(double mouseX, double mouseY) { - super.onRelease(mouseX, mouseY); - applyValue(); - } - - @Override - protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) { - super.onDrag(mouseX, mouseY, deltaX, deltaY); - applyValue(); - } - }; - pos_delay_slider.setTooltip(Tooltip.of(Text.translatable("text.repeating-mod.pos_delay_tooltip"))); - - import_btn = ButtonWidget.builder(Text.translatable("text.repeating-mod.import"), button -> { - new Thread(() -> { - FileDialog fd = new FileDialog((java.awt.Frame) null); - fd.setMultipleMode(true); - fd.setName("Choose record files"); - fd.setTitle("Choose record files"); - fd.setFilenameFilter((dir, name) -> name.endsWith(".rrm")); - fd.setVisible(true); - - File[] files = fd.getFiles(); - if (files != null) { - for (File file : files) { - try { - Main.me.setNowRecord(Main.me.record_list.cloneRecord(file)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }}).start(); - }) - .dimensions(width / 2 + 2, height / 2 - list_widget.getHeight() / 2 - 22, 180, 20) - .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.import_tooltip"))) - .build(); - - was_build = true; - - updateButtons(); - - addDrawableChild(loop_btn); - addDrawableChild(record_btn); - addDrawableChild(import_btn); - addDrawableChild(pos_delay_slider); - } - - public T addDrawableChild(T drawableElement) { - return super.addDrawableChild(drawableElement); - } - - public T addDrawable(T drawable) { - return super.addDrawable(drawable); - } - - public T addSelectableChild(T child) { - return super.addSelectableChild(child); - } - - public void remove(Element child) { - super.remove(child); - } -} +package ru.themixray.repeating_mod; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.SliderWidget; +import net.minecraft.text.Text; +import ru.themixray.repeating_mod.widget.RecordListWidget; + +import java.awt.*; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class RepeatingScreen extends Screen { + private static List render_listeners = new ArrayList<>(); + + public ButtonWidget record_btn; + public ButtonWidget loop_btn; + public ButtonWidget import_btn; + + public SliderWidget pos_delay_slider; + + public boolean was_build = false; + + protected RepeatingScreen() { + super(Text.empty()); + } + + public static void addRenderListener(RenderListener render) { + render_listeners.add(render); + } + + public static void removeRenderListener(RenderListener render) { + render_listeners.remove(render); + } + + public void updateButtons() { + if (was_build) { + record_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.is_recording) ? "stop_record" : "start_record"))); + loop_btn.setMessage(Text.translatable("text.repeating-mod." + ((Main.me.loop_replay) ? "off_loop" : "on_loop"))); + } + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { +// renderBackground(context, mouseX, mouseY, delta); + + for (RenderListener l : render_listeners) { + if (l.beforeRender()) { + l.render(context, mouseX, mouseY, delta); + } + } + + super.render(context, mouseX, mouseY, delta); + + for (RenderListener l : render_listeners) { + if (!l.beforeRender()) { + l.render(context, mouseX, mouseY, delta); + } + } + } + + @Override + protected void init() { + RecordListWidget list_widget = Main.me.record_list.getWidget(); + + list_widget.setX(width / 2 + 2); + list_widget.setY(height / 2 - list_widget.getHeight() / 2); + list_widget.init(this); + + + record_btn = ButtonWidget.builder( + Text.translatable("text.repeating-mod.start_record"), button -> { + if (!Main.me.is_replaying) { + if (Main.me.is_recording) + Main.me.stopRecording(); + else Main.me.startRecording(); + updateButtons(); + } + }) + .dimensions(width / 2 - 120, height / 2 - 32, 120, 20) + .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.record_tooltip"))) + .build(); + + loop_btn = ButtonWidget.builder(Text.empty(), button -> { + Main.me.loop_replay = !Main.me.loop_replay; + updateButtons(); + }) + .dimensions(width / 2 - 120, height / 2 - 10, 120, 20) + .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.loop_tooltip"))) + .build(); + + pos_delay_slider = new SliderWidget( + width / 2 - 120, height / 2 + 12, 120, 20, + (Main.me.record_pos_delay < 0) ? Text.translatable("text.repeating-mod.nan_pos_delay") : + Text.translatable("text.repeating-mod.pos_delay", String.valueOf(Main.me.record_pos_delay)), + (Main.me.record_pos_delay+1d)/101d) { + + @Override + protected void updateMessage() { + double v = value*101d-1d; + if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); + else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); + } + + @Override + protected void applyValue() { + double v = value*101d-1d; + if (v <= 1) setMessage(Text.translatable("text.repeating-mod.nan_pos_delay")); + else setMessage(Text.translatable("text.repeating-mod.pos_delay", String.valueOf((long) v))); + Main.me.record_pos_delay = (long) v; + Main.me.conf.data.put("record_pos_delay",String.valueOf(Main.me.record_pos_delay)); + Main.me.conf.save(); + } + + @Override + public void onRelease(double mouseX, double mouseY) { + super.onRelease(mouseX, mouseY); + applyValue(); + } + + @Override + protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) { + super.onDrag(mouseX, mouseY, deltaX, deltaY); + applyValue(); + } + }; + pos_delay_slider.setTooltip(Tooltip.of(Text.translatable("text.repeating-mod.pos_delay_tooltip"))); + + import_btn = ButtonWidget.builder(Text.translatable("text.repeating-mod.import"), button -> { + new Thread(() -> { + FileDialog fd = new FileDialog((java.awt.Frame) null); + fd.setMultipleMode(true); + fd.setName("Choose record files"); + fd.setTitle("Choose record files"); + fd.setFilenameFilter((dir, name) -> name.endsWith(".rrm")); + fd.setVisible(true); + + File[] files = fd.getFiles(); + if (files != null) { + for (File file : files) { + try { + Main.me.setNowRecord(Main.me.record_list.cloneRecord(file)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }}).start(); + }) + .dimensions(width / 2 + 2, height / 2 - list_widget.getHeight() / 2 - 22, 180, 20) + .tooltip(Tooltip.of(Text.translatable("text.repeating-mod.import_tooltip"))) + .build(); + + was_build = true; + + updateButtons(); + + addDrawableChild(loop_btn); + addDrawableChild(record_btn); + addDrawableChild(import_btn); + addDrawableChild(pos_delay_slider); + } + + public T addDrawableChild(T drawableElement) { + return super.addDrawableChild(drawableElement); + } + + public T addDrawable(T drawable) { + return super.addDrawable(drawable); + } + + public T addSelectableChild(T child) { + return super.addSelectableChild(child); + } + + public void remove(Element child) { + super.remove(child); + } +} diff --git a/src/main/java/themixray/repeating/mod/TickTask.java b/src/main/java/ru/themixray/repeating_mod/TickTask.java similarity index 94% rename from src/main/java/themixray/repeating/mod/TickTask.java rename to src/main/java/ru/themixray/repeating_mod/TickTask.java index e014511..d8adbef 100644 --- a/src/main/java/themixray/repeating/mod/TickTask.java +++ b/src/main/java/ru/themixray/repeating_mod/TickTask.java @@ -1,95 +1,95 @@ -package themixray.repeating.mod; - -import java.util.ArrayList; -import java.util.List; - -public abstract class TickTask implements Runnable { - public static List tasks = new ArrayList<>(); - - public static void tickTasks(TickAt at) { - for (TickTask t:new ArrayList<>(tasks)) - if (t.getAt() == at) t.tick(); - } - - private long living; - private long delay; - - private boolean is_repeating; - private long period; - - private boolean is_cancelled; - private TickAt at; - - public enum TickAt { - CLIENT_HEAD, CLIENT_TAIL, - MOVEMENT_HEAD, MOVEMENT_TAIL, - RENDER_HEAD, RENDER_TAIL, - CLIENT_EVENT - } - - public TickTask(long delay, TickAt at) { - this.is_cancelled = false; - this.is_repeating = false; - this.delay = delay; - this.living = 0; - this.period = 0; - this.at = at; - tasks.add(this); - } - - public TickTask(long delay, long period, TickAt at) { - this.is_cancelled = false; - this.is_repeating = true; - this.delay = delay; - this.period = period; - this.living = 0; - this.at = at; - tasks.add(this); - } - - public TickTask(long delay) { - this(delay,TickAt.CLIENT_HEAD); - } - - public TickTask(long delay, long period) { - this(delay,period,TickAt.CLIENT_HEAD); - } - - public void cancel() { - if (!is_cancelled) { - is_cancelled = true; - tasks.remove(this); - } - } - - public boolean isCancelled() { - return is_cancelled; - } - - public TickAt getAt() { - return at; - } - - public void setDelay(long delay) { - if (is_repeating) { - this.delay = delay; - } - } - public long getDelay() { - return this.delay; - } - - public void tick() { - if (living >= delay) { - if (is_repeating) { - delay = period; - run(); - living = -1; - } else { - run(); - cancel(); - } - } - living++; - } -} +package ru.themixray.repeating_mod; + +import java.util.ArrayList; +import java.util.List; + +public abstract class TickTask implements Runnable { + public static List tasks = new ArrayList<>(); + + public static void tickTasks(TickAt at) { + for (TickTask t:new ArrayList<>(tasks)) + if (t.getAt() == at) t.tick(); + } + + private long living; + private long delay; + + private boolean is_repeating; + private long period; + + private boolean is_cancelled; + private TickAt at; + + public enum TickAt { + CLIENT_HEAD, CLIENT_TAIL, + MOVEMENT_HEAD, MOVEMENT_TAIL, + RENDER_HEAD, RENDER_TAIL, + CLIENT_EVENT + } + + public TickTask(long delay, TickAt at) { + this.is_cancelled = false; + this.is_repeating = false; + this.delay = delay; + this.living = 0; + this.period = 0; + this.at = at; + tasks.add(this); + } + + public TickTask(long delay, long period, TickAt at) { + this.is_cancelled = false; + this.is_repeating = true; + this.delay = delay; + this.period = period; + this.living = 0; + this.at = at; + tasks.add(this); + } + + public TickTask(long delay) { + this(delay,TickAt.CLIENT_HEAD); + } + + public TickTask(long delay, long period) { + this(delay,period,TickAt.CLIENT_HEAD); + } + + public void cancel() { + if (!is_cancelled) { + is_cancelled = true; + tasks.remove(this); + } + } + + public boolean isCancelled() { + return is_cancelled; + } + + public TickAt getAt() { + return at; + } + + public void setDelay(long delay) { + if (is_repeating) { + this.delay = delay; + } + } + public long getDelay() { + return this.delay; + } + + public void tick() { + if (living >= delay) { + if (is_repeating) { + delay = period; + run(); + living = -1; + } else { + run(); + cancel(); + } + } + living++; + } +} diff --git a/src/main/java/themixray/repeating/mod/event/RecordEvent.java b/src/main/java/ru/themixray/repeating_mod/event/RecordEvent.java similarity index 87% rename from src/main/java/themixray/repeating/mod/event/RecordEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/RecordEvent.java index 0c2cb64..c55db10 100644 --- a/src/main/java/themixray/repeating/mod/event/RecordEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/RecordEvent.java @@ -1,6 +1,6 @@ -package themixray.repeating.mod.event; +package ru.themixray.repeating_mod.event; -import themixray.repeating.mod.event.events.*; +import ru.themixray.repeating_mod.event.events.*; public abstract class RecordEvent { public abstract void replay(); diff --git a/src/main/java/themixray/repeating/mod/event/RecordEventType.java b/src/main/java/ru/themixray/repeating_mod/event/RecordEventType.java similarity index 95% rename from src/main/java/themixray/repeating/mod/event/RecordEventType.java rename to src/main/java/ru/themixray/repeating_mod/event/RecordEventType.java index 957159f..853f002 100644 --- a/src/main/java/themixray/repeating/mod/event/RecordEventType.java +++ b/src/main/java/ru/themixray/repeating_mod/event/RecordEventType.java @@ -1,6 +1,6 @@ -package themixray.repeating.mod.event; +package ru.themixray.repeating_mod.event; -import themixray.repeating.mod.event.events.*; +import ru.themixray.repeating_mod.event.events.*; public enum RecordEventType { BLOCK_BREAK('b',"block_break",BlockBreakEvent.class), diff --git a/src/main/java/themixray/repeating/mod/event/events/BlockBreakEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/BlockBreakEvent.java similarity index 85% rename from src/main/java/themixray/repeating/mod/event/events/BlockBreakEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/BlockBreakEvent.java index 0e34fba..dd8a656 100644 --- a/src/main/java/themixray/repeating/mod/event/events/BlockBreakEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/BlockBreakEvent.java @@ -1,8 +1,8 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; import net.minecraft.util.math.BlockPos; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class BlockBreakEvent extends RecordEvent { public BlockPos pos; diff --git a/src/main/java/themixray/repeating/mod/event/events/BlockInteractEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/BlockInteractEvent.java similarity index 85% rename from src/main/java/themixray/repeating/mod/event/events/BlockInteractEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/BlockInteractEvent.java index bdae075..16a8425 100644 --- a/src/main/java/themixray/repeating/mod/event/events/BlockInteractEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/BlockInteractEvent.java @@ -1,12 +1,12 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class BlockInteractEvent extends RecordEvent { public Hand hand; @@ -19,7 +19,7 @@ public class BlockInteractEvent extends RecordEvent { Double.parseDouble(a[0]), Double.parseDouble(a[1]), Double.parseDouble(a[2])), - Direction.byId(Integer.parseInt(a[4])), + Direction.byIndex(Integer.parseInt(a[4])), new BlockPos( Integer.parseInt(a[0]), Integer.parseInt(a[1]), @@ -44,7 +44,7 @@ public class BlockInteractEvent extends RecordEvent { String.valueOf(hitResult.getBlockPos().getY()), String.valueOf(hitResult.getBlockPos().getZ()), (hitResult.isInsideBlock() ? "1" : "0"), - String.valueOf(hitResult.getSide().getId()), + String.valueOf(hitResult.getSide().getIndex()), hand.name() }; } diff --git a/src/main/java/themixray/repeating/mod/event/events/DelayEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/DelayEvent.java similarity index 84% rename from src/main/java/themixray/repeating/mod/event/events/DelayEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/DelayEvent.java index 1978702..25dcbac 100644 --- a/src/main/java/themixray/repeating/mod/event/events/DelayEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/DelayEvent.java @@ -1,6 +1,6 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.event.RecordEvent; public class DelayEvent extends RecordEvent { public long delay; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiCharTypeEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiCharTypeEvent.java similarity index 84% rename from src/main/java/themixray/repeating/mod/event/events/GuiCharTypeEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiCharTypeEvent.java index 4428984..7c8dae9 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiCharTypeEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiCharTypeEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiCharTypeEvent extends RecordEvent { private char chr; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiCloseEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiCloseEvent.java similarity index 73% rename from src/main/java/themixray/repeating/mod/event/events/GuiCloseEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiCloseEvent.java index f2c3024..38908fb 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiCloseEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiCloseEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiCloseEvent extends RecordEvent { public GuiCloseEvent() {} diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiKeyPressEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyPressEvent.java similarity index 86% rename from src/main/java/themixray/repeating/mod/event/events/GuiKeyPressEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyPressEvent.java index cf5221f..0e83969 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiKeyPressEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyPressEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiKeyPressEvent extends RecordEvent { private int keyCode; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiKeyReleaseEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyReleaseEvent.java similarity index 86% rename from src/main/java/themixray/repeating/mod/event/events/GuiKeyReleaseEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyReleaseEvent.java index 8134c73..253f8bf 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiKeyReleaseEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiKeyReleaseEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiKeyReleaseEvent extends RecordEvent { private int keyCode; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiMouseClickEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseClickEvent.java similarity index 86% rename from src/main/java/themixray/repeating/mod/event/events/GuiMouseClickEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseClickEvent.java index 1c47776..6cc2393 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiMouseClickEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseClickEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiMouseClickEvent extends RecordEvent { private double mouseX; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiMouseDragEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseDragEvent.java similarity index 89% rename from src/main/java/themixray/repeating/mod/event/events/GuiMouseDragEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseDragEvent.java index f351482..eba566f 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiMouseDragEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseDragEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiMouseDragEvent extends RecordEvent { private double mouseX; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiMouseMoveEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseMoveEvent.java similarity index 84% rename from src/main/java/themixray/repeating/mod/event/events/GuiMouseMoveEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseMoveEvent.java index 7da1c82..94480f2 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiMouseMoveEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseMoveEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiMouseMoveEvent extends RecordEvent { private double mouseX; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiMouseReleaseEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseReleaseEvent.java similarity index 86% rename from src/main/java/themixray/repeating/mod/event/events/GuiMouseReleaseEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseReleaseEvent.java index 63b8b6b..3e8c1b4 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiMouseReleaseEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseReleaseEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiMouseReleaseEvent extends RecordEvent { private double mouseX; diff --git a/src/main/java/themixray/repeating/mod/event/events/GuiMouseScrollEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseScrollEvent.java similarity index 79% rename from src/main/java/themixray/repeating/mod/event/events/GuiMouseScrollEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseScrollEvent.java index 470c29c..8df7061 100644 --- a/src/main/java/themixray/repeating/mod/event/events/GuiMouseScrollEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/GuiMouseScrollEvent.java @@ -1,7 +1,7 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class GuiMouseScrollEvent extends RecordEvent { private double mouseX; @@ -16,7 +16,7 @@ public class GuiMouseScrollEvent extends RecordEvent { public void replay() { if (Main.client.currentScreen != null) { - Main.client.currentScreen.mouseScrolled(mouseX, mouseY, amount); +// Main.client.currentScreen.mouseScrolled(mouseX, mouseY, amount); } } diff --git a/src/main/java/ru/themixray/repeating_mod/event/events/InputEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/InputEvent.java new file mode 100644 index 0000000..01d1f39 --- /dev/null +++ b/src/main/java/ru/themixray/repeating_mod/event/events/InputEvent.java @@ -0,0 +1,195 @@ +package ru.themixray.repeating_mod.event.events; + +import net.minecraft.client.input.Input; +import net.minecraft.util.PlayerInput; +import net.minecraft.util.math.Vec2f; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; + +import java.lang.reflect.Field; + +public class InputEvent extends RecordEvent { + public Boolean forward; + public Boolean backward; + public Boolean left; + public Boolean right; + public Boolean jump; + public Boolean sneak; + public Boolean sprint; + + public float yaw; + public float head_yaw; + public float body_yaw; + public float pitch; + public float speed; + public float movementForward; + public float movementSideways; + + public static InputEvent current() { + if (Main.client.player == null) return null; + return new InputEvent( + Main.client.player.input.playerInput.forward(), + Main.client.player.input.playerInput.backward(), + Main.client.player.input.playerInput.left(), + Main.client.player.input.playerInput.right(), + Main.client.player.input.playerInput.jump(), + Main.client.player.input.playerInput.sneak(), + Main.client.player.input.playerInput.sprint(), + Main.client.player.getHeadYaw(), + Main.client.player.getBodyYaw(), + Main.client.player.getPitch(), + Main.client.player.getYaw(), + Main.client.player.getMovementSpeed(), + Main.client.player.input.getMovementInput().y, + Main.client.player.input.getMovementInput().x + ); + } + + public InputEvent(Boolean forward, + Boolean backward, + Boolean left, + Boolean right, + Boolean jump, + Boolean sneak, + Boolean sprint, + float head_yaw, + float body_yaw, + float head_pitch, + float yaw, + float speed, + float movementForward, + float movementSideways) { + this.forward = forward; + this.backward = backward; + this.left = left; + this.right = right; + this.jump = jump; + this.sneak = sneak; + this.sprint = sprint; + + this.head_yaw = head_yaw; + this.body_yaw = body_yaw; + this.pitch = head_pitch; + this.yaw = yaw; + this.speed = speed; + this.movementForward = movementForward; + this.movementSideways = movementSideways; + } + + /** + * Returns differences of this InputEvent to the provided one, saving first booleans if differ and first floats always + */ + public InputEvent differs(InputEvent event) { + return new InputEvent( + forward == event.forward ? null : forward, + backward == event.backward ? null : backward, + left == event.left ? null : left, + right == event.right ? null : right, + jump == event.jump ? null : jump, + sneak == event.sneak ? null : sneak, + sprint == event.sprint ? null : sprint, + head_yaw, + body_yaw, + pitch, + yaw, + speed, + movementForward, + movementSideways + ); + } + + public static InputEvent deserialize(String[] a) { + return new InputEvent( + (a[0].equals("n") ? null : a[0].equals("1")), + (a[1].equals("n") ? null : a[1].equals("1")), + (a[2].equals("n") ? null : a[2].equals("1")), + (a[3].equals("n") ? null : a[3].equals("1")), + (a[4].equals("n") ? null : a[4].equals("1")), + (a[5].equals("n") ? null : a[5].equals("1")), + (a[6].equals("n") ? null : a[6].equals("1")), + Float.parseFloat(a[7]), + Float.parseFloat(a[8]), + Float.parseFloat(a[9]), + Float.parseFloat(a[10]), + Float.parseFloat(a[11]), + Float.parseFloat(a[12]), + Float.parseFloat(a[13]) + ); + } + + protected String[] serializeArgs() { + return new String[] { + ((forward == null) ? "n" : (forward ? "1" : "0")), + ((backward == null) ? "n" : (backward ? "1" : "0")), + ((left == null) ? "n" : (left ? "1" : "0")), + ((right == null) ? "n" : (right ? "1" : "0")), + ((jump == null) ? "n" : (jump ? "1" : "0")), + ((sneak == null) ? "n" : (sneak ? "1" : "0")), + ((sprint == null) ? "n" : (sprint ? "1" : "0")), + String.valueOf(head_yaw), + String.valueOf(body_yaw), + String.valueOf(pitch), + String.valueOf(yaw), + String.valueOf(speed), + String.valueOf(movementForward), + String.valueOf(movementSideways) + }; + } + + public boolean equals(InputEvent event) { + return event.forward == forward && + event.backward == backward && + event.sprint == sprint && + event.jump == jump && + event.sneak == sneak && + event.left == left && + event.right == right && + event.speed == speed && + event.head_yaw == head_yaw && + event.body_yaw == body_yaw && + event.yaw == yaw && + event.pitch == pitch && + event.movementForward == movementForward && + event.movementSideways == movementSideways; + } + + public void replay() { + Main.input_replay = this; + } + + public void inputCallback() { + if (Main.client.player != null) { + if (sprint != null && Main.client.player.isSprinting() != sprint) + Main.client.player.setSprinting(sprint); + if (Main.client.player.getYaw() != yaw) + Main.client.player.setYaw(yaw); + if (Main.client.player.getHeadYaw() != head_yaw) + Main.client.player.setHeadYaw(head_yaw); + if (Main.client.player.getBodyYaw() != body_yaw) + Main.client.player.setBodyYaw(body_yaw); + if (Main.client.player.getPitch() != pitch) + Main.client.player.setPitch(pitch); + if (Main.client.player.getMovementSpeed() != speed) + Main.client.player.setMovementSpeed(speed); + + try { + Field field = Input.class.getDeclaredField("movementVector"); + field.setAccessible(true); + field.set(Main.client.player.input, new Vec2f(movementSideways, movementForward)); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + + PlayerInput input = Main.client.player.input.playerInput; + Main.client.player.input.playerInput = new PlayerInput( + this.forward == null ? input.forward() : this.forward, + this.backward == null ? input.backward() : this.backward, + this.left == null ? input.left() : this.left, + this.right == null ? input.right() : this.right, + this.jump == null ? input.jump() : this.jump, + this.sneak == null ? input.sneak() : this.sneak, + this.sprint == null ? input.sprint() : this.sprint + ); + } + } +} diff --git a/src/main/java/themixray/repeating/mod/event/events/MoveEvent.java b/src/main/java/ru/themixray/repeating_mod/event/events/MoveEvent.java similarity index 64% rename from src/main/java/themixray/repeating/mod/event/events/MoveEvent.java rename to src/main/java/ru/themixray/repeating_mod/event/events/MoveEvent.java index c8b8bf1..9506eae 100644 --- a/src/main/java/themixray/repeating/mod/event/events/MoveEvent.java +++ b/src/main/java/ru/themixray/repeating_mod/event/events/MoveEvent.java @@ -1,15 +1,17 @@ -package themixray.repeating.mod.event.events; +package ru.themixray.repeating_mod.event.events; import net.minecraft.entity.MovementType; import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.RecordEvent; public class MoveEvent extends RecordEvent { public Vec3d vec; public float yaw; public float pitch; + public static final float MOVE_THRESHOLD = 0.001f; + public static MoveEvent deserialize(String[] a) { return new MoveEvent(new Vec3d( Double.parseDouble(a[0]), @@ -29,9 +31,13 @@ public class MoveEvent extends RecordEvent { if (Main.client.player != null) { Vec3d p = Main.client.player.getPos(); Vec3d v = new Vec3d(vec.getX() - p.getX(), vec.getY() - p.getY(), vec.getZ() - p.getZ()); - Main.client.player.move(MovementType.SELF, v); - Main.client.player.setYaw(yaw); - Main.client.player.setPitch(pitch); + if (Math.abs(v.x) > MOVE_THRESHOLD || Math.abs(v.y) > MOVE_THRESHOLD || Math.abs(v.z) > MOVE_THRESHOLD) + Main.client.player.move(MovementType.SELF, v); + + if (Math.abs(Main.client.player.getYaw() - yaw) > MOVE_THRESHOLD) + Main.client.player.setYaw(yaw); + if (Math.abs(Main.client.player.getPitch() - pitch) > MOVE_THRESHOLD) + Main.client.player.setPitch(pitch); } } diff --git a/src/main/java/themixray/repeating/mod/mixin/ClientMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/ClientMixin.java similarity index 82% rename from src/main/java/themixray/repeating/mod/mixin/ClientMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/ClientMixin.java index 60e9e64..10b1a8e 100644 --- a/src/main/java/themixray/repeating/mod/mixin/ClientMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/ClientMixin.java @@ -1,24 +1,24 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.MinecraftClient; -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 themixray.repeating.mod.Main; -import themixray.repeating.mod.TickTask; - -@Mixin(MinecraftClient.class) -public abstract class ClientMixin { - @Inject(at = @At(value = "HEAD"), method = "tick") - private void onTickHead(CallbackInfo ci) { - if (Main.me.is_recording) - Main.me.recordAllInput(); - TickTask.tickTasks(TickTask.TickAt.CLIENT_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.CLIENT_TAIL); - } -} +package ru.themixray.repeating_mod.mixin; + +import net.minecraft.client.MinecraftClient; +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 ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.TickTask; + +@Mixin(MinecraftClient.class) +public abstract class ClientMixin { + @Inject(at = @At(value = "HEAD"), method = "tick") + private void onTickHead(CallbackInfo ci) { + if (Main.me.is_recording) + Main.me.recordAllInput(); + TickTask.tickTasks(TickTask.TickAt.CLIENT_HEAD); + } + + @Inject(at = @At(value = "TAIL"), method = "tick") + private void onTickTail(CallbackInfo ci) { + TickTask.tickTasks(TickTask.TickAt.CLIENT_TAIL); + } +} diff --git a/remappedSrc/themixray/repeating/mod/mixin/EntityMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/EntityMixin.java similarity index 78% rename from remappedSrc/themixray/repeating/mod/mixin/EntityMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/EntityMixin.java index eed7b58..93257cc 100644 --- a/remappedSrc/themixray/repeating/mod/mixin/EntityMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/EntityMixin.java @@ -1,31 +1,31 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import themixray.repeating.mod.Main; - -import java.util.UUID; - -@Mixin(Entity.class) -public abstract class EntityMixin { - @Shadow public abstract UUID getUuid(); - - @Inject(at = @At(value = "HEAD"), method = "setSprinting", cancellable = true) - private void onSprint(boolean sprinting,CallbackInfo ci) { - if (Main.client.player != null) { - if (getUuid().equals(Main.client.player.getUuid())) { - if (Main.me.is_replaying) { - if (Main.input_replay != null && - Main.input_replay.sprinting != null && - Main.input_replay.sprinting != sprinting) { - ci.cancel(); - } - } - } - } - } -} +package ru.themixray.repeating_mod.mixin; + +import net.minecraft.entity.Entity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.themixray.repeating_mod.Main; + +import java.util.UUID; + +@Mixin(Entity.class) +public abstract class EntityMixin { + @Shadow public abstract UUID getUuid(); + + @Inject(at = @At(value = "HEAD"), method = "setSprinting", cancellable = true) + private void onSprint(boolean sprinting,CallbackInfo ci) { + if (Main.client.player != null) { + if (getUuid().equals(Main.client.player.getUuid())) { + if (Main.me.is_replaying) { + if (Main.input_replay != null && + Main.input_replay.sprint != null && + Main.input_replay.sprint != sprinting) { + ci.cancel(); + } + } + } + } + } +} diff --git a/remappedSrc/themixray/repeating/mod/mixin/InputMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/InputMixin.java similarity index 77% rename from remappedSrc/themixray/repeating/mod/mixin/InputMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/InputMixin.java index 800e147..261c59c 100644 --- a/remappedSrc/themixray/repeating/mod/mixin/InputMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/InputMixin.java @@ -1,20 +1,20 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.input.KeyboardInput; -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 themixray.repeating.mod.Main; - -@Mixin(KeyboardInput.class) -public abstract class InputMixin { - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(boolean slowDown, float f, CallbackInfo ci) { - if (Main.me.is_replaying) { - if (Main.input_replay != null) { - Main.input_replay.inputCallback(); - } - } - } -} +package ru.themixray.repeating_mod.mixin; + +import net.minecraft.client.input.KeyboardInput; +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 ru.themixray.repeating_mod.Main; + +@Mixin(KeyboardInput.class) +public abstract class InputMixin { + @Inject(at = @At(value = "TAIL"), method = "tick") + private void onTickTail(CallbackInfo ci) { + if (Main.me.is_replaying) { + if (Main.input_replay != null) { + Main.input_replay.inputCallback(); + } + } + } +} diff --git a/src/main/java/themixray/repeating/mod/mixin/MovementMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/MovementMixin.java similarity index 82% rename from src/main/java/themixray/repeating/mod/mixin/MovementMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/MovementMixin.java index b850676..73f970b 100644 --- a/src/main/java/themixray/repeating/mod/mixin/MovementMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/MovementMixin.java @@ -1,44 +1,44 @@ -package themixray.repeating.mod.mixin; - -import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; -import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.HitResult; -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 themixray.repeating.mod.Main; -import themixray.repeating.mod.event.events.BlockBreakEvent; -import themixray.repeating.mod.event.events.BlockInteractEvent; -import themixray.repeating.mod.TickTask; - -@Mixin(ClientPlayerEntity.class) -public abstract class MovementMixin { - - @Inject(at = @At(value = "HEAD"), method = "init") - private void init(CallbackInfo ci) { - PlayerBlockBreakEvents.AFTER.register((world, player, pos, blockState, blockEntity) -> { - if (Main.me.is_recording) - Main.me.recordTick(new BlockBreakEvent(pos)); - }); - - UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (hitResult.getType().equals(HitResult.Type.BLOCK)) - if (Main.me.is_recording) - Main.me.recordTick(new BlockInteractEvent(hand,hitResult)); - return ActionResult.PASS; - }); - } - - @Inject(at = @At(value = "HEAD"), method = "tickMovement") - private void onMoveHead(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.MOVEMENT_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onMoveTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.MOVEMENT_TAIL); - } -} +package ru.themixray.repeating_mod.mixin; + +import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.HitResult; +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 ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.events.BlockBreakEvent; +import ru.themixray.repeating_mod.event.events.BlockInteractEvent; +import ru.themixray.repeating_mod.TickTask; + +@Mixin(ClientPlayerEntity.class) +public abstract class MovementMixin { + + @Inject(at = @At(value = "HEAD"), method = "init") + private void init(CallbackInfo ci) { + PlayerBlockBreakEvents.AFTER.register((world, player, pos, blockState, blockEntity) -> { + if (Main.me.is_recording) + Main.me.recordTick(new BlockBreakEvent(pos)); + }); + + UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { + if (hitResult.getType().equals(HitResult.Type.BLOCK)) + if (Main.me.is_recording) + Main.me.recordTick(new BlockInteractEvent(hand,hitResult)); + return ActionResult.PASS; + }); + } + + @Inject(at = @At(value = "HEAD"), method = "tickMovement") + private void onMoveHead(CallbackInfo ci) { + TickTask.tickTasks(TickTask.TickAt.MOVEMENT_HEAD); + } + + @Inject(at = @At(value = "TAIL"), method = "tick") + private void onMoveTail(CallbackInfo ci) { + TickTask.tickTasks(TickTask.TickAt.MOVEMENT_TAIL); + } +} diff --git a/src/main/java/themixray/repeating/mod/mixin/NetworkMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/NetworkMixin.java similarity index 94% rename from src/main/java/themixray/repeating/mod/mixin/NetworkMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/NetworkMixin.java index 4f85878..58f7570 100644 --- a/src/main/java/themixray/repeating/mod/mixin/NetworkMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/NetworkMixin.java @@ -1,29 +1,29 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.listener.ServerPlayPacketListener; -import net.minecraft.network.packet.Packet; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.time.Duration; -import java.util.function.BooleanSupplier; - -@Mixin(ClientPlayNetworkHandler.class) -public abstract class NetworkMixin { -// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;)V") -// private void onSendPacket1Head(Packet packet, -// CallbackInfo ci) { -// -// } -// -// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V") -// private void onSendPacket2Head(Packet packet, -// BooleanSupplier sendCondition, -// Duration expirationTime, -// CallbackInfo ci) { -// -// } -} +package ru.themixray.repeating_mod.mixin; + +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.listener.ServerPlayPacketListener; +import net.minecraft.network.packet.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.time.Duration; +import java.util.function.BooleanSupplier; + +@Mixin(ClientPlayNetworkHandler.class) +public abstract class NetworkMixin { +// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;)V") +// private void onSendPacket1Head(Packet packet, +// CallbackInfo ci) { +// +// } +// +// @Inject(at = @At(value = "HEAD"), method = "sendPacket(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V") +// private void onSendPacket2Head(Packet packet, +// BooleanSupplier sendCondition, +// Duration expirationTime, +// CallbackInfo ci) { +// +// } +} diff --git a/src/main/java/themixray/repeating/mod/mixin/PlayerMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/PlayerMixin.java similarity index 64% rename from src/main/java/themixray/repeating/mod/mixin/PlayerMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/PlayerMixin.java index 67735f9..c5627c8 100644 --- a/src/main/java/themixray/repeating/mod/mixin/PlayerMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/PlayerMixin.java @@ -1,18 +1,12 @@ -package themixray.repeating.mod.mixin; +package ru.themixray.repeating_mod.mixin; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.entity.Entity; import net.minecraft.network.ClientConnection; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import themixray.repeating.mod.Main; - -import java.util.UUID; +import ru.themixray.repeating_mod.Main; @Mixin(ClientConnection.class) public abstract class PlayerMixin { diff --git a/src/main/java/themixray/repeating/mod/mixin/RendererMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/RendererMixin.java similarity index 85% rename from src/main/java/themixray/repeating/mod/mixin/RendererMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/RendererMixin.java index edb363d..c035167 100644 --- a/src/main/java/themixray/repeating/mod/mixin/RendererMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/RendererMixin.java @@ -1,21 +1,21 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.render.*; -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 themixray.repeating.mod.TickTask; - -@Mixin(GameRenderer.class) -public abstract class RendererMixin { - @Inject(at = @At(value = "HEAD"), method = "tick") - private void onTickHead(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.RENDER_HEAD); - } - - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(CallbackInfo ci) { - TickTask.tickTasks(TickTask.TickAt.RENDER_TAIL); - } -} +package ru.themixray.repeating_mod.mixin; + +import net.minecraft.client.render.*; +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 ru.themixray.repeating_mod.TickTask; + +@Mixin(GameRenderer.class) +public abstract class RendererMixin { + @Inject(at = @At(value = "HEAD"), method = "tick") + private void onTickHead(CallbackInfo ci) { + TickTask.tickTasks(TickTask.TickAt.RENDER_HEAD); + } + + @Inject(at = @At(value = "TAIL"), method = "tick") + private void onTickTail(CallbackInfo ci) { + TickTask.tickTasks(TickTask.TickAt.RENDER_TAIL); + } +} diff --git a/src/main/java/themixray/repeating/mod/mixin/ScreenMixin.java b/src/main/java/ru/themixray/repeating_mod/mixin/ScreenMixin.java similarity index 81% rename from src/main/java/themixray/repeating/mod/mixin/ScreenMixin.java rename to src/main/java/ru/themixray/repeating_mod/mixin/ScreenMixin.java index bfa46c8..3d74704 100644 --- a/src/main/java/themixray/repeating/mod/mixin/ScreenMixin.java +++ b/src/main/java/ru/themixray/repeating_mod/mixin/ScreenMixin.java @@ -1,20 +1,15 @@ -package themixray.repeating.mod.mixin; +package ru.themixray.repeating_mod.mixin; import net.minecraft.client.gui.AbstractParentElement; import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.ParentElement; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.GameRenderer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; 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 themixray.repeating.mod.Main; -import themixray.repeating.mod.TickTask; -import themixray.repeating.mod.event.events.*; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.event.events.*; @Mixin(Screen.class) public abstract class ScreenMixin extends AbstractParentElement implements Drawable { @@ -80,11 +75,11 @@ public abstract class ScreenMixin extends AbstractParentElement implements Drawa return super.mouseReleased(mouseX, mouseY, button); } - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (Main.me.is_recording) { -// Main.me.now_record.addEvent(new GuiMouseScrollEvent(mouseX, mouseY, amount)); - } - return super.mouseScrolled(mouseX, mouseY, amount); - } +// @Override +// public boolean mouseScrolled(double mouseX, double mouseY, double amount) { +// if (Main.me.is_recording) { +//// Main.me.now_record.addEvent(new GuiMouseScrollEvent(mouseX, mouseY, amount)); +// } +// return super.mouseScrolled(mouseX, mouseY, amount); +// } } diff --git a/src/main/java/themixray/repeating/mod/render/RenderHelper.java b/src/main/java/ru/themixray/repeating_mod/render/RenderHelper.java similarity index 87% rename from src/main/java/themixray/repeating/mod/render/RenderHelper.java rename to src/main/java/ru/themixray/repeating_mod/render/RenderHelper.java index 4f80464..c67abd4 100644 --- a/src/main/java/themixray/repeating/mod/render/RenderHelper.java +++ b/src/main/java/ru/themixray/repeating_mod/render/RenderHelper.java @@ -1,10 +1,10 @@ -package themixray.repeating.mod.render; +package ru.themixray.repeating_mod.render; import lombok.experimental.UtilityClass; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.util.math.Vec3d; -import themixray.repeating.mod.render.buffer.WorldBuffer; -import themixray.repeating.mod.render.shader.ShaderManager; +import org.joml.Vector3f; +import ru.themixray.repeating_mod.render.buffer.WorldBuffer; +import ru.themixray.repeating_mod.render.shader.ShaderManager; import java.awt.*; @@ -27,8 +27,8 @@ public class RenderHelper { } public void drawLine(WorldBuffer buffer, float x1, float y1, float z1, float x2, float y2, float z2, Color color) { - buffer.vert(x1, y1, z1, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x2, y2, z2, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + buffer.vert(new Vector3f(x1, y1, z1), color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + buffer.vert(new Vector3f(x2, y2, z2), color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); } public static WorldBuffer startTri(WorldRenderContext context) { @@ -49,9 +49,9 @@ public class RenderHelper { } public void drawTri(WorldBuffer buffer, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, Color color) { - buffer.vert(x1, y1, z1, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x2, y2, z2, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); - buffer.vert(x3, y3, z3, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + buffer.vert(new Vector3f(x1, y1, z1), color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + buffer.vert(new Vector3f(x2, y2, z2), color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + buffer.vert(new Vector3f(x3, y3, z3), color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); } public static void drawRectFromTri(WorldBuffer buffer, diff --git a/src/main/java/themixray/repeating/mod/render/RenderSystem.java b/src/main/java/ru/themixray/repeating_mod/render/RenderSystem.java similarity index 52% rename from src/main/java/themixray/repeating/mod/render/RenderSystem.java rename to src/main/java/ru/themixray/repeating_mod/render/RenderSystem.java index a5fa15c..90f12e9 100644 --- a/src/main/java/themixray/repeating/mod/render/RenderSystem.java +++ b/src/main/java/ru/themixray/repeating_mod/render/RenderSystem.java @@ -1,8 +1,8 @@ -package themixray.repeating.mod.render; +package ru.themixray.repeating_mod.render; import lombok.experimental.UtilityClass; -import themixray.repeating.mod.render.buffer.BufferManager; -import themixray.repeating.mod.render.shader.ShaderManager; +import ru.themixray.repeating_mod.render.buffer.BufferManager; +import ru.themixray.repeating_mod.render.shader.ShaderManager; @UtilityClass public class RenderSystem { diff --git a/remappedSrc/themixray/repeating/mod/render/buffer/BufferManager.java b/src/main/java/ru/themixray/repeating_mod/render/buffer/BufferManager.java similarity index 95% rename from remappedSrc/themixray/repeating/mod/render/buffer/BufferManager.java rename to src/main/java/ru/themixray/repeating_mod/render/buffer/BufferManager.java index 76d2853..9fb32ff 100644 --- a/remappedSrc/themixray/repeating/mod/render/buffer/BufferManager.java +++ b/src/main/java/ru/themixray/repeating_mod/render/buffer/BufferManager.java @@ -1,4 +1,4 @@ -package themixray.repeating.mod.render.buffer; +package ru.themixray.repeating_mod.render.buffer; import lombok.experimental.UtilityClass; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; diff --git a/src/main/java/themixray/repeating/mod/render/buffer/Vertex.java b/src/main/java/ru/themixray/repeating_mod/render/buffer/Vertex.java similarity index 50% rename from src/main/java/themixray/repeating/mod/render/buffer/Vertex.java rename to src/main/java/ru/themixray/repeating_mod/render/buffer/Vertex.java index 5aaa113..a87e2e6 100644 --- a/src/main/java/themixray/repeating/mod/render/buffer/Vertex.java +++ b/src/main/java/ru/themixray/repeating_mod/render/buffer/Vertex.java @@ -1,14 +1,11 @@ -package themixray.repeating.mod.render.buffer; +package ru.themixray.repeating_mod.render.buffer; import lombok.Getter; +import org.joml.Vector3f; public class Vertex { @Getter - private float x; - @Getter - private float y; - @Getter - private float z; + private Vector3f pos; @Getter private float r; @Getter @@ -18,10 +15,8 @@ public class Vertex { @Getter private float a; - public Vertex(float x, float y, float z, float r, float g, float b, float a) { - this.x = x; - this.y = y; - this.z = z; + public Vertex(Vector3f pos, float r, float g, float b, float a) { + this.pos = pos; this.r = r; this.g = g; this.b = b; diff --git a/remappedSrc/themixray/repeating/mod/render/buffer/WorldBuffer.java b/src/main/java/ru/themixray/repeating_mod/render/buffer/WorldBuffer.java similarity index 63% rename from remappedSrc/themixray/repeating/mod/render/buffer/WorldBuffer.java rename to src/main/java/ru/themixray/repeating_mod/render/buffer/WorldBuffer.java index 390f97d..fa27670 100644 --- a/remappedSrc/themixray/repeating/mod/render/buffer/WorldBuffer.java +++ b/src/main/java/ru/themixray/repeating_mod/render/buffer/WorldBuffer.java @@ -1,11 +1,12 @@ -package themixray.repeating.mod.render.buffer; +package ru.themixray.repeating_mod.render.buffer; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.util.math.Vec3d; import org.apache.commons.lang3.ArrayUtils; import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.lwjgl.BufferUtils; -import themixray.repeating.mod.render.shader.Shader; +import ru.themixray.repeating_mod.render.shader.Shader; import java.nio.FloatBuffer; import java.util.ArrayList; @@ -18,17 +19,19 @@ public class WorldBuffer { private final int drawMode; private final Shader shader; private FloatBuffer projectionMatrix; - private final Vec3d cameraPos; + private final Vector3f cameraPos; + private final Quaternionf cameraRot; public WorldBuffer(int drawMode, Shader shader, WorldRenderContext worldRenderContext) { this.drawMode = drawMode; this.shader = shader; - this.cameraPos = worldRenderContext.camera().getPos(); - makeProjectionMatrix(worldRenderContext.projectionMatrix(), worldRenderContext.matrixStack().peek().getPositionMatrix()); + this.cameraPos = worldRenderContext.camera().getPos().toVector3f(); + this.cameraRot = worldRenderContext.camera().getRotation().invert(); + this.projectionMatrix = worldRenderContext.projectionMatrix().mul(worldRenderContext.matrixStack().peek().getPositionMatrix()).get(BufferUtils.createFloatBuffer(16)); } - public void vert(float x, float y, float z, float r, float g, float b, float a) { - vertices.add(new Vertex(x - (float) cameraPos.x, y - (float) cameraPos.y, z - (float) cameraPos.z, r, g, b, a)); + public void vert(Vector3f pos, float r, float g, float b, float a) { + vertices.add(new Vertex(cameraRot.transform(pos.sub(cameraPos)), r, g, b, a)); } public void draw() { @@ -36,7 +39,7 @@ public class WorldBuffer { BufferManager.bindBuffer(); BufferManager.writeBuffer(getBuffer()); - applyProjectionMatrix(); + shader.uniformMatrix4f("u_projection", projectionMatrix); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); glEnableVertexAttribArray(0); @@ -55,12 +58,12 @@ public class WorldBuffer { private FloatBuffer getBuffer() { FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(vertices.size() * 7); ArrayList floats = new ArrayList<>(); - for (Vertex vertex : vertices) { - floats.add(vertex.getX()); - floats.add(vertex.getY()); - floats.add(vertex.getZ()); + for (ru.themixray.repeating_mod.render.buffer.Vertex vertex : vertices) { + floats.add(vertex.getPos().x); + floats.add(vertex.getPos().y); + floats.add(vertex.getPos().z); } - for (Vertex vertex : vertices) { + for (ru.themixray.repeating_mod.render.buffer.Vertex vertex : vertices) { floats.add(vertex.getR()); floats.add(vertex.getG()); floats.add(vertex.getB()); @@ -71,12 +74,4 @@ public class WorldBuffer { floatBuffer.put(ArrayUtils.toPrimitive(floatArray)); return floatBuffer.flip(); } - - private void makeProjectionMatrix(Matrix4f projectionMatrix, Matrix4f viewModelMatrix) { - this.projectionMatrix = projectionMatrix.mul(viewModelMatrix).get(BufferUtils.createFloatBuffer(16)); - } - - private void applyProjectionMatrix() { - shader.uniformMatrix4f("u_projection", projectionMatrix); - } } diff --git a/src/main/java/themixray/repeating/mod/render/shader/Shader.java b/src/main/java/ru/themixray/repeating_mod/render/shader/Shader.java similarity index 67% rename from src/main/java/themixray/repeating/mod/render/shader/Shader.java rename to src/main/java/ru/themixray/repeating_mod/render/shader/Shader.java index e11dd9a..efe5550 100644 --- a/src/main/java/themixray/repeating/mod/render/shader/Shader.java +++ b/src/main/java/ru/themixray/repeating_mod/render/shader/Shader.java @@ -1,4 +1,4 @@ -package themixray.repeating.mod.render.shader; +package ru.themixray.repeating_mod.render.shader; import lombok.Getter; @@ -12,8 +12,8 @@ public class Shader { public Shader(String name) { - int v = ShaderManager.loadShaderProgram(name, ShaderManager.ShaderType.VERTEX); - int f = ShaderManager.loadShaderProgram(name, ShaderManager.ShaderType.FRAGMENT); + int v = ru.themixray.repeating_mod.render.shader.ShaderManager.loadShaderProgram(name, ru.themixray.repeating_mod.render.shader.ShaderManager.ShaderType.VERTEX); + int f = ru.themixray.repeating_mod.render.shader.ShaderManager.loadShaderProgram(name, ru.themixray.repeating_mod.render.shader.ShaderManager.ShaderType.FRAGMENT); this.id = glCreateProgram(); glAttachShader(id, v); glAttachShader(id, f); diff --git a/remappedSrc/themixray/repeating/mod/render/shader/ShaderManager.java b/src/main/java/ru/themixray/repeating_mod/render/shader/ShaderManager.java similarity index 89% rename from remappedSrc/themixray/repeating/mod/render/shader/ShaderManager.java rename to src/main/java/ru/themixray/repeating_mod/render/shader/ShaderManager.java index f11c98b..f5e26a6 100644 --- a/remappedSrc/themixray/repeating/mod/render/shader/ShaderManager.java +++ b/src/main/java/ru/themixray/repeating_mod/render/shader/ShaderManager.java @@ -1,6 +1,6 @@ -package themixray.repeating.mod.render.shader; +package ru.themixray.repeating_mod.render.shader; -import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.opengl.GlStateManager; import com.mojang.blaze3d.platform.TextureUtil; import lombok.Getter; import lombok.SneakyThrows; @@ -27,21 +27,21 @@ import static org.lwjgl.opengl.GL33.*; @UtilityClass public class ShaderManager { @Getter - private Shader positionColorShader; + private ru.themixray.repeating_mod.render.shader.Shader positionColorShader; public void init() { ClientLifecycleEvents.CLIENT_STARTED.register(client -> loadShaders()); } private void loadShaders() { - positionColorShader = new Shader("position_color"); + positionColorShader = new ru.themixray.repeating_mod.render.shader.Shader("position_color"); } public int loadShaderProgram(String name, ShaderType type) { try { boolean file_present = true; ResourceFactory resourceFactory = MinecraftClient.getInstance().getResourceManager(); - Optional resource = resourceFactory.getResource(new Identifier("renderer", "shader/" + name + type.fileExtension)); + Optional resource = resourceFactory.getResource(Identifier.of("renderer", "shader/" + name + type.fileExtension)); int i = glCreateShader(type.glType); if (resource.isPresent()) { GlStateManager.glShaderSource(i, new GlImportProcessor() { @@ -51,7 +51,7 @@ public class ShaderManager { public String loadImport(boolean inline, String name) { return IOUtils.toString(resource.get().getInputStream(), StandardCharsets.UTF_8); } - }.readSource(readResourceAsString(resource.get().getInputStream()))); + }.readSource(readResourceAsString(resource.get().getInputStream())).getFirst()); } else file_present = false; glCompileShader(i); if (glGetShaderi(i, GL_COMPILE_STATUS) == 0 || !file_present) { diff --git a/src/main/java/themixray/repeating/mod/widget/RecordListWidget.java b/src/main/java/ru/themixray/repeating_mod/widget/RecordListWidget.java similarity index 79% rename from src/main/java/themixray/repeating/mod/widget/RecordListWidget.java rename to src/main/java/ru/themixray/repeating_mod/widget/RecordListWidget.java index d038f91..b17af92 100644 --- a/src/main/java/themixray/repeating/mod/widget/RecordListWidget.java +++ b/src/main/java/ru/themixray/repeating_mod/widget/RecordListWidget.java @@ -1,22 +1,14 @@ -package themixray.repeating.mod.widget; +package ru.themixray.repeating_mod.widget; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.*; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.RecordState; -import themixray.repeating.mod.RepeatingScreen; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.RecordState; +import ru.themixray.repeating_mod.RepeatingScreen; -import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; -import java.util.function.Consumer; public class RecordListWidget extends ScrollableWidget { private LinkedList widgets = new LinkedList<>(); @@ -34,27 +26,40 @@ public class RecordListWidget extends ScrollableWidget { return res; } + @Override + protected int getContentsHeightWithPadding() { + return !widgets.isEmpty() ? widgets.size() * 55 + (widgets.size() - 1) * 2 : 0; + } + @Override protected double getDeltaYPerScroll() { return 10; } @Override - protected void renderContents(DrawContext ctx, int mouseX, int mouseY, float delta) { - int y = 0; + protected void renderWidget(DrawContext ctx, int mouseX, int mouseY, float delta) { + ctx.fill(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight(), 0xff000000); + + ctx.enableScissor(this.getX(), this.getY(), this.getX() + this.getWidth(), this.getY() + this.getHeight()); + + int y = (int) -this.getScrollY(); for (RecordWidget wid: widgets) { wid.setY(y); - wid.render(ctx, mouseX, (int) (mouseY + this.getScrollY()), delta); + wid.render(ctx, mouseX, (int) (mouseY), delta); y += wid.getHeight(); y += 2; } + + ctx.disableScissor(); + + this.drawScrollbar(ctx); } public void addWidget(RecordState record) { - RecordWidget widget = new RecordWidget(0, 0, width, 55, record, this); + RecordWidget widget = new RecordWidget(0, 0, width - 6, 55, record, this); widget.init(null); - widgets.add(0, widget); + widgets.addFirst(widget); } public void removeWidget(RecordState record) { @@ -71,11 +76,6 @@ public class RecordListWidget extends ScrollableWidget { return focused; } - @Override - protected int getContentsHeight() { - return !widgets.isEmpty() ? widgets.size() * 55 + (widgets.size() - 1) * 2 : 0; - } - public void init(RepeatingScreen screen) { for (RecordWidget widget : widgets) { widget.init(screen); @@ -133,7 +133,7 @@ public class RecordListWidget extends ScrollableWidget { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - return checkTransportNF(mouseX, mouseY + getScrollY(), button) || super.mouseClicked(mouseX, mouseY, button); + return checkTransportNF(mouseX, mouseY, button) || super.checkScrollbarDragged(mouseX, mouseY, button); } @Override diff --git a/src/main/java/themixray/repeating/mod/widget/RecordWidget.java b/src/main/java/ru/themixray/repeating_mod/widget/RecordWidget.java similarity index 89% rename from src/main/java/themixray/repeating/mod/widget/RecordWidget.java rename to src/main/java/ru/themixray/repeating_mod/widget/RecordWidget.java index 3838168..5b9954e 100644 --- a/src/main/java/themixray/repeating/mod/widget/RecordWidget.java +++ b/src/main/java/ru/themixray/repeating_mod/widget/RecordWidget.java @@ -1,17 +1,15 @@ -package themixray.repeating.mod.widget; +package ru.themixray.repeating_mod.widget; +import lombok.Getter; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.*; -import net.minecraft.text.Style; import net.minecraft.text.Text; -import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; -import themixray.repeating.mod.Main; -import themixray.repeating.mod.RecordState; -import themixray.repeating.mod.RenderListener; -import themixray.repeating.mod.RepeatingScreen; +import ru.themixray.repeating_mod.Main; +import ru.themixray.repeating_mod.RecordState; +import ru.themixray.repeating_mod.RepeatingScreen; import java.awt.*; import java.io.IOException; @@ -21,6 +19,7 @@ import java.util.List; import java.util.function.Consumer; public class RecordWidget implements Drawable, Widget { + @Getter private RecordState record; private List children; @@ -134,7 +133,8 @@ public class RecordWidget implements Drawable, Widget { children.add(export_button); - ButtonWidget replay_button = ButtonWidget.builder(Text.translatable("text.repeating-mod.start"), (i) -> { + ButtonWidget replay_button = ButtonWidget.builder(Text.translatable("text.repeating-mod." + + (getRecord().equals(Main.me.now_record) && Main.me.is_replaying ? "stop" : "start")), (i) -> { if (Main.me.is_replaying) { Main.me.stopReplay(); if (getRecord().equals(Main.me.now_record)) { @@ -143,7 +143,7 @@ public class RecordWidget implements Drawable, Widget { } i.setMessage(Text.translatable("text.repeating-mod.stop")); - Main.me.now_record = record; + Main.me.now_record = getRecord(); Main.me.startReplay(); Main.client.setScreen(null); }).dimensions(parent.getX() + getX() + 110,parent.getY() + getY() + 4 + 28, 65, 13) @@ -152,22 +152,13 @@ public class RecordWidget implements Drawable, Widget { children.add(replay_button); } - public RecordState getRecord() { - return record; - } - - public void drawText(int x, int y, DrawContext ctx, List lines, float size, int line_height, boolean shadow) { - ctx.getMatrices().push(); - ctx.getMatrices().scale(size, size, size); - + public void drawText(int x, int y, DrawContext ctx, List lines, int line_height, boolean shadow) { int now_y = y; for (Text line : lines) { - ctx.drawText(Main.client.textRenderer, line, (int) (x / size), (int) (now_y / size), line.getStyle().getColor().getRgb(), shadow); + ctx.drawText(Main.client.textRenderer, line, x, now_y, 0xff000000 + line.getStyle().getColor().getRgb(), shadow); now_y += line_height; } - - ctx.getMatrices().pop(); } @Override @@ -192,7 +183,7 @@ public class RecordWidget implements Drawable, Widget { .append(": ") .styled((s) -> s.withColor(0xbbbbbb)), Text.literal(record.getAuthor()).styled((s) -> s.withColor(0xffffff)) - ), 1, + ), 9, false); diff --git a/src/main/java/themixray/repeating/mod/EasyConfig.java b/src/main/java/themixray/repeating/mod/EasyConfig.java deleted file mode 100644 index 8836722..0000000 --- a/src/main/java/themixray/repeating/mod/EasyConfig.java +++ /dev/null @@ -1,103 +0,0 @@ -package themixray.repeating.mod; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.io.File; - -public class EasyConfig { - public final Path path; - public final File file; - public Map data; - - public EasyConfig(File f, Map def) { - this.path = f.toPath(); - this.file = f; - this.data = new HashMap<>(); - - if (!file.exists()) { - try { - file.createNewFile(); - write(def); - } catch (IOException e) { - e.printStackTrace(); - } - } - - reload(); - - for (Map.Entry m:def.entrySet()) - if (!data.containsKey(m.getKey())) - data.put(m.getKey(),m.getValue()); - - save(); - } - public EasyConfig(Path f, Map def) { - this(f.toFile(),def); - } - public EasyConfig(String parent,String child,Map def) { - this(new File(parent,child),def); - } - public EasyConfig(File parent,String child,Map def) { - this(new File(parent,child),def); - } - public EasyConfig(Path parent,String child,Map def) { - this(new File(parent.toFile(),child),def); - } - - public EasyConfig(File f) { - this(f,new HashMap<>()); - } - public EasyConfig(Path path) { - this(path.toFile(),new HashMap<>()); - } - public EasyConfig(String parent,String child) { - this(new File(parent,child),new HashMap<>()); - } - public EasyConfig(File parent,String child) { - this(new File(parent,child),new HashMap<>()); - } - public EasyConfig(Path parent,String child) { - this(new File(parent.toFile(),child),new HashMap<>()); - } - - public void reload() { - data = read(); - } - public void save() { - write(data); - } - - private String toText(Map p) { - StringBuilder t = new StringBuilder(); - for (Map.Entry e:p.entrySet()) - t.append(e.getKey()).append("=").append(e.getValue()).append("\n"); - return t.toString(); - } - private Map toMap(String j) { - Map m = new HashMap<>(); - for (String l:j.split("\n")) { - String s[] = l.split("="); - m.put(s[0],s[1]); - } - return m; - } - - private Map read() { - try { - return toMap(Files.readString(path)); - } catch (IOException e) { - e.printStackTrace(); - } - return new HashMap<>(); - } - private void write(Map p) { - try { - Files.write(path, toText(p).getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/themixray/repeating/mod/RenderListener.java b/src/main/java/themixray/repeating/mod/RenderListener.java deleted file mode 100644 index 9992e48..0000000 --- a/src/main/java/themixray/repeating/mod/RenderListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package themixray.repeating.mod; - -import net.minecraft.client.gui.DrawContext; - -public interface RenderListener { - default boolean beforeRender() { - return true; - } - - void render(DrawContext context, int mouseX, int mouseY, float delta); -} diff --git a/src/main/java/themixray/repeating/mod/event/events/InputEvent.java b/src/main/java/themixray/repeating/mod/event/events/InputEvent.java deleted file mode 100644 index 9ca3128..0000000 --- a/src/main/java/themixray/repeating/mod/event/events/InputEvent.java +++ /dev/null @@ -1,150 +0,0 @@ -package themixray.repeating.mod.event.events; - -import themixray.repeating.mod.Main; -import themixray.repeating.mod.event.RecordEvent; - -public class InputEvent extends RecordEvent { - public Boolean sneaking; - public Boolean jumping; - public Boolean pressingForward; - public Boolean pressingBack; - public Boolean pressingLeft; - public Boolean pressingRight; - public Boolean sprinting; - - public Float movementSideways; - public Float movementForward; - - public float yaw; - public float head_yaw; - public float body_yaw; - public float pitch; - public float speed; - - public InputEvent(Boolean sneaking, - Boolean jumping, - Float movementSideways, - Float movementForward, - Boolean pressingForward, - Boolean pressingBack, - Boolean pressingLeft, - Boolean pressingRight, - float head_yaw, - float body_yaw, - float head_pitch, - Boolean sprinting, - float yaw, - float speed) { - this.sneaking = sneaking; - this.jumping = jumping; - this.movementSideways = movementSideways; - this.movementForward = movementForward; - this.pressingForward = pressingForward; - this.pressingBack = pressingBack; - this.pressingLeft = pressingLeft; - this.pressingRight = pressingRight; - this.head_yaw = head_yaw; - this.body_yaw = body_yaw; - this.pitch = head_pitch; - this.sprinting = sprinting; - this.yaw = yaw; - this.speed = speed; - } - - public static InputEvent deserialize(String[] a) { - return new InputEvent( - (a[0].equals("n") ? null : a[0].equals("1")), - (a[1].equals("n") ? null : a[1].equals("1")), - (a[2].equals("n") ? null : Float.parseFloat(a[2])), - (a[3].equals("n") ? null : Float.parseFloat(a[3])), - (a[4].equals("n") ? null : a[4].equals("1")), - (a[5].equals("n") ? null : a[5].equals("1")), - (a[6].equals("n") ? null : a[6].equals("1")), - (a[7].equals("n") ? null : a[7].equals("1")), - Float.parseFloat(a[8]), Float.parseFloat(a[9]), - Float.parseFloat(a[10]), - (a[11].equals("n") ? null : a[11].equals("1")), - Float.parseFloat(a[12]), - Float.parseFloat(a[13])); - } - - protected String[] serializeArgs() { - return new String[] { - ((sneaking == null) ? "n" : (sneaking ? "1" : "0")), // sneaking - ((jumping == null) ? "n" : (jumping ? "1" : "0")), // jumping - ((movementSideways == null) ? "n" : String.valueOf(movementSideways)), // movement sideways - ((movementForward == null) ? "n" : String.valueOf(movementForward)), // movement forward - ((pressingForward == null) ? "n" : (pressingForward ? "1" : "0")), // pressing forward - ((pressingBack == null) ? "n" : (pressingBack ? "1" : "0")), // pressing back - ((pressingLeft == null) ? "n" : (pressingLeft ? "1" : "0")), // pressing left - ((pressingRight == null) ? "n" : (pressingRight ? "1" : "0")), // pressing right - String.valueOf(head_yaw), // head yaw - String.valueOf(body_yaw), // body yaw - String.valueOf(pitch), // pitch - ((sprinting == null) ? "n" : (sprinting ? "1" : "0")), // sprinting - String.valueOf(yaw), // yaw - String.valueOf(speed) // speed - }; - } - - public void fillEmpty(InputEvent e) { - if (sneaking == null) sneaking = e.sneaking; - if (jumping == null) jumping = e.jumping; - if (movementSideways == null) movementSideways = e.movementSideways; - if (movementForward == null) movementForward = e.movementForward; - if (pressingForward == null) pressingForward = e.pressingForward; - if (pressingBack == null) pressingBack = e.pressingBack; - if (pressingLeft == null) pressingLeft = e.pressingLeft; - if (pressingRight == null) pressingRight = e.pressingRight; - if (sprinting == null) sprinting = e.sprinting; - } - - public boolean isEmpty() { - return sneaking == null && - jumping == null && - movementSideways == null && - movementForward == null && - pressingForward == null && - pressingBack == null && - pressingLeft == null && - pressingRight == null && - sprinting == null; - } - - public void replay() { - Main.input_replay = this; - } - - public void inputCallback() { - if (Main.client.player != null) { - if (sprinting != null && Main.client.player.isSprinting() != sprinting) - Main.client.player.setSprinting(sprinting); - if (Main.client.player.getYaw() != yaw) - Main.client.player.setYaw(yaw); - if (Main.client.player.getHeadYaw() != head_yaw) - Main.client.player.setHeadYaw(head_yaw); - if (Main.client.player.getBodyYaw() != body_yaw) - Main.client.player.setBodyYaw(body_yaw); - if (Main.client.player.getPitch() != pitch) - Main.client.player.setPitch(pitch); - if (Main.client.player.getMovementSpeed() != speed) - Main.client.player.setMovementSpeed(speed); - if (sneaking != null && Main.client.player.input.sneaking != sneaking) - Main.client.player.input.sneaking = sneaking; - if (jumping != null && Main.client.player.input.jumping != jumping) - Main.client.player.input.jumping = jumping; - if (movementSideways != null && Main.client.player.input.movementSideways != movementSideways) - Main.client.player.input.movementSideways = movementSideways; - if (movementForward != null && Main.client.player.input.movementForward != movementForward) - Main.client.player.input.movementForward = movementForward; - if (pressingForward != null && Main.client.player.input.pressingForward != pressingForward) - Main.client.player.input.pressingForward = pressingForward; - if (pressingBack != null && Main.client.player.input.pressingBack != pressingBack) - Main.client.player.input.pressingBack = pressingBack; - if (pressingLeft != null && Main.client.player.input.pressingLeft != pressingLeft) - Main.client.player.input.pressingLeft = pressingLeft; - if (pressingRight != null && Main.client.player.input.pressingRight != pressingRight) - Main.client.player.input.pressingRight = pressingRight; - } - } -} diff --git a/src/main/java/themixray/repeating/mod/mixin/EntityMixin.java b/src/main/java/themixray/repeating/mod/mixin/EntityMixin.java deleted file mode 100644 index eed7b58..0000000 --- a/src/main/java/themixray/repeating/mod/mixin/EntityMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import themixray.repeating.mod.Main; - -import java.util.UUID; - -@Mixin(Entity.class) -public abstract class EntityMixin { - @Shadow public abstract UUID getUuid(); - - @Inject(at = @At(value = "HEAD"), method = "setSprinting", cancellable = true) - private void onSprint(boolean sprinting,CallbackInfo ci) { - if (Main.client.player != null) { - if (getUuid().equals(Main.client.player.getUuid())) { - if (Main.me.is_replaying) { - if (Main.input_replay != null && - Main.input_replay.sprinting != null && - Main.input_replay.sprinting != sprinting) { - ci.cancel(); - } - } - } - } - } -} diff --git a/src/main/java/themixray/repeating/mod/mixin/InputMixin.java b/src/main/java/themixray/repeating/mod/mixin/InputMixin.java deleted file mode 100644 index 800e147..0000000 --- a/src/main/java/themixray/repeating/mod/mixin/InputMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package themixray.repeating.mod.mixin; - -import net.minecraft.client.input.KeyboardInput; -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 themixray.repeating.mod.Main; - -@Mixin(KeyboardInput.class) -public abstract class InputMixin { - @Inject(at = @At(value = "TAIL"), method = "tick") - private void onTickTail(boolean slowDown, float f, CallbackInfo ci) { - if (Main.me.is_replaying) { - if (Main.input_replay != null) { - Main.input_replay.inputCallback(); - } - } - } -} diff --git a/src/main/java/themixray/repeating/mod/render/buffer/BufferManager.java b/src/main/java/themixray/repeating/mod/render/buffer/BufferManager.java deleted file mode 100644 index 76d2853..0000000 --- a/src/main/java/themixray/repeating/mod/render/buffer/BufferManager.java +++ /dev/null @@ -1,48 +0,0 @@ -package themixray.repeating.mod.render.buffer; - -import lombok.experimental.UtilityClass; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; - -import java.nio.FloatBuffer; - -import static org.lwjgl.opengl.GL33.*; - -@UtilityClass -public class BufferManager { - private int vao; - private int vbo; - - private int prevVao; - - public void init() { - ClientLifecycleEvents.CLIENT_STARTED.register(client -> { - vao = glGenVertexArrays(); - vbo = glGenBuffers(); - }); - } - - public static void bindBuffer() { - glBindBuffer(GL_ARRAY_BUFFER, vbo); - } - - public static void unbindBuffer() { - glBindBuffer(GL_ARRAY_BUFFER, 0); - } - - public static void writeBuffer(FloatBuffer buffer) { - glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); - } - - public static void draw(int drawMode, int verts) { - glDrawArrays(drawMode, 0, verts); - } - - public static void bind() { - prevVao = glGetInteger(GL_VERTEX_ARRAY_BINDING); - glBindVertexArray(vao); - } - - public static void unbind() { - glBindVertexArray(prevVao); - } -} diff --git a/src/main/java/themixray/repeating/mod/render/buffer/WorldBuffer.java b/src/main/java/themixray/repeating/mod/render/buffer/WorldBuffer.java deleted file mode 100644 index 390f97d..0000000 --- a/src/main/java/themixray/repeating/mod/render/buffer/WorldBuffer.java +++ /dev/null @@ -1,82 +0,0 @@ -package themixray.repeating.mod.render.buffer; - -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.util.math.Vec3d; -import org.apache.commons.lang3.ArrayUtils; -import org.joml.Matrix4f; -import org.lwjgl.BufferUtils; -import themixray.repeating.mod.render.shader.Shader; - -import java.nio.FloatBuffer; -import java.util.ArrayList; -import java.util.List; - -import static org.lwjgl.opengl.GL33.*; - -public class WorldBuffer { - private final List vertices = new ArrayList<>(); - private final int drawMode; - private final Shader shader; - private FloatBuffer projectionMatrix; - private final Vec3d cameraPos; - - public WorldBuffer(int drawMode, Shader shader, WorldRenderContext worldRenderContext) { - this.drawMode = drawMode; - this.shader = shader; - this.cameraPos = worldRenderContext.camera().getPos(); - makeProjectionMatrix(worldRenderContext.projectionMatrix(), worldRenderContext.matrixStack().peek().getPositionMatrix()); - } - - public void vert(float x, float y, float z, float r, float g, float b, float a) { - vertices.add(new Vertex(x - (float) cameraPos.x, y - (float) cameraPos.y, z - (float) cameraPos.z, r, g, b, a)); - } - - public void draw() { - BufferManager.bind(); - BufferManager.bindBuffer(); - - BufferManager.writeBuffer(getBuffer()); - applyProjectionMatrix(); - - glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); - glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, vertices.size() * 3 * 4L); - glEnableVertexAttribArray(1); - - BufferManager.unbindBuffer(); - - shader.bind(); - BufferManager.draw(drawMode, this.vertices.size()); - shader.unbind(); - - BufferManager.unbind(); - } - - private FloatBuffer getBuffer() { - FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(vertices.size() * 7); - ArrayList floats = new ArrayList<>(); - for (Vertex vertex : vertices) { - floats.add(vertex.getX()); - floats.add(vertex.getY()); - floats.add(vertex.getZ()); - } - for (Vertex vertex : vertices) { - floats.add(vertex.getR()); - floats.add(vertex.getG()); - floats.add(vertex.getB()); - floats.add(vertex.getA()); - } - Float[] floatArray = new Float[floats.size()]; - floats.toArray(floatArray); - floatBuffer.put(ArrayUtils.toPrimitive(floatArray)); - return floatBuffer.flip(); - } - - private void makeProjectionMatrix(Matrix4f projectionMatrix, Matrix4f viewModelMatrix) { - this.projectionMatrix = projectionMatrix.mul(viewModelMatrix).get(BufferUtils.createFloatBuffer(16)); - } - - private void applyProjectionMatrix() { - shader.uniformMatrix4f("u_projection", projectionMatrix); - } -} diff --git a/src/main/java/themixray/repeating/mod/render/shader/ShaderManager.java b/src/main/java/themixray/repeating/mod/render/shader/ShaderManager.java deleted file mode 100644 index f11c98b..0000000 --- a/src/main/java/themixray/repeating/mod/render/shader/ShaderManager.java +++ /dev/null @@ -1,97 +0,0 @@ -package themixray.repeating.mod.render.shader; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.platform.TextureUtil; -import lombok.Getter; -import lombok.SneakyThrows; -import lombok.experimental.UtilityClass; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.GlImportProcessor; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceFactory; -import net.minecraft.util.Identifier; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.system.MemoryUtil; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Optional; - -import static org.lwjgl.opengl.GL33.*; - -@UtilityClass -public class ShaderManager { - @Getter - private Shader positionColorShader; - - public void init() { - ClientLifecycleEvents.CLIENT_STARTED.register(client -> loadShaders()); - } - - private void loadShaders() { - positionColorShader = new Shader("position_color"); - } - - public int loadShaderProgram(String name, ShaderType type) { - try { - boolean file_present = true; - ResourceFactory resourceFactory = MinecraftClient.getInstance().getResourceManager(); - Optional resource = resourceFactory.getResource(new Identifier("renderer", "shader/" + name + type.fileExtension)); - int i = glCreateShader(type.glType); - if (resource.isPresent()) { - GlStateManager.glShaderSource(i, new GlImportProcessor() { - @SneakyThrows - @Nullable - @Override - public String loadImport(boolean inline, String name) { - return IOUtils.toString(resource.get().getInputStream(), StandardCharsets.UTF_8); - } - }.readSource(readResourceAsString(resource.get().getInputStream()))); - } else file_present = false; - glCompileShader(i); - if (glGetShaderi(i, GL_COMPILE_STATUS) == 0 || !file_present) { - String shaderInfo = StringUtils.trim(glGetShaderInfoLog(i, 32768)); - throw new IOException("Couldn't compile " + type.name + " program (" + name + ") : " + shaderInfo); - } - return i; - } catch (IOException e) { - e.printStackTrace(); - } - return 0; - } - - private String readResourceAsString(InputStream inputStream) { - ByteBuffer byteBuffer = null; - try { - byteBuffer = TextureUtil.readResource(inputStream); - int i = byteBuffer.position(); - byteBuffer.rewind(); - return MemoryUtil.memASCII(byteBuffer, i); - } catch (IOException ignored) { - } finally { - if (byteBuffer != null) { - MemoryUtil.memFree(byteBuffer); - } - } - return null; - } - - public enum ShaderType { - VERTEX("vertex", ".vsh", GL_VERTEX_SHADER), - FRAGMENT("fragment", ".fsh", GL_FRAGMENT_SHADER); - private final String name; - private final String fileExtension; - private final int glType; - - ShaderType(String name, String fileExtension, int glType) { - this.name = name; - this.fileExtension = fileExtension; - this.glType = glType; - } - } -} diff --git a/src/main/resources/assets/minecraft/font/default.json b/src/main/resources/assets/minecraft/font/default.json index 6501fb4..ef1f683 100644 --- a/src/main/resources/assets/minecraft/font/default.json +++ b/src/main/resources/assets/minecraft/font/default.json @@ -1,17 +1,17 @@ -{ - "providers": [ - { - "file":"repeating-mod:ui/no-loop.png", - "chars":["\ueffe"], - "height":16, - "ascent":12, - "type":"bitmap" - },{ - "file":"repeating-mod:ui/loop.png", - "chars":["\uefff"], - "height":16, - "ascent":12, - "type":"bitmap" - } - ] +{ + "providers": [ + { + "file":"repeating-mod:ui/no-loop.png", + "chars":["\ueffe"], + "height":16, + "ascent":12, + "type":"bitmap" + },{ + "file":"repeating-mod:ui/loop.png", + "chars":["\uefff"], + "height":16, + "ascent":12, + "type":"bitmap" + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/repeating-mod/lang/en_us.json b/src/main/resources/assets/repeating-mod/lang/en_us.json index 774b7d8..d2f69be 100644 --- a/src/main/resources/assets/repeating-mod/lang/en_us.json +++ b/src/main/resources/assets/repeating-mod/lang/en_us.json @@ -1,36 +1,36 @@ -{ - "key.repeating-mod.menu": "Repeating menu", - "key.repeating-mod.toggle_replay": "Toggle replay", - "key.repeating-mod.toggle_record": "Toggle recording", - - "text.repeating-mod.name": "Repeating Mod", - "text.repeating-mod.start_record": "Start record", - "text.repeating-mod.stop_record": "Stop record", - "text.repeating-mod.start_replay": "Start replay", - "text.repeating-mod.stop_replay": "Stop replay", - "text.repeating-mod.record_tooltip": "Start/stop recording all activities", - "text.repeating-mod.replay_tooltip": "Start/stop repeating recorded actions", - "text.repeating-mod.loop_tooltip": "Enable/disable repeating of recorded actions replay", - "text.repeating-mod.export_record": "Export record", - "text.repeating-mod.import": "Import record", - "text.repeating-mod.export_tooltip": "Exporting a recording to a file", - "text.repeating-mod.import_tooltip": "Importing a recording from a file", - "text.repeating-mod.dev": "In development...", - "text.repeating-mod.nan_pos_delay": "No pos timer", - "text.repeating-mod.pos_delay": "Pos timer: %s ticks", - "text.repeating-mod.pos_delay_tooltip": "Timer after which the pos\nevent is added (20 ticks = 1 sec)", - "text.repeating-mod.unnamed": "Unnamed Record", - "text.repeating-mod.on_loop": "Enable repeat", - "text.repeating-mod.off_loop": "Disable repeat", - "text.repeating-mod.recorded_at": "Recorded at", - "text.repeating-mod.author": "Author", - "text.repeating-mod.delete": "Delete", - "text.repeating-mod.start": "Start", - "text.repeating-mod.stop": "Stop", - "text.repeating-mod.export": "Export", - - "message.repeating-mod.replay_start": "Replay started", - "message.repeating-mod.replay_stop": "Replay finished", - "message.repeating-mod.record_start": "Record started", - "message.repeating-mod.record_stop": "Record finished" +{ + "key.repeating-mod.menu": "Repeating menu", + "key.repeating-mod.toggle_replay": "Toggle replay", + "key.repeating-mod.toggle_record": "Toggle recording", + + "text.repeating-mod.name": "Repeating Mod", + "text.repeating-mod.start_record": "Start record", + "text.repeating-mod.stop_record": "Stop record", + "text.repeating-mod.start_replay": "Start replay", + "text.repeating-mod.stop_replay": "Stop replay", + "text.repeating-mod.record_tooltip": "Start/stop recording all activities", + "text.repeating-mod.replay_tooltip": "Start/stop repeating recorded actions", + "text.repeating-mod.loop_tooltip": "Enable/disable repeating of recorded actions replay", + "text.repeating-mod.export_record": "Export record", + "text.repeating-mod.import": "Import record", + "text.repeating-mod.export_tooltip": "Exporting a recording to a file", + "text.repeating-mod.import_tooltip": "Importing a recording from a file", + "text.repeating-mod.dev": "In development...", + "text.repeating-mod.nan_pos_delay": "No pos timer", + "text.repeating-mod.pos_delay": "Pos timer: %s ticks", + "text.repeating-mod.pos_delay_tooltip": "Timer after which the pos\nevent is added (20 ticks = 1 sec)", + "text.repeating-mod.unnamed": "Unnamed Record", + "text.repeating-mod.on_loop": "Enable repeat", + "text.repeating-mod.off_loop": "Disable repeat", + "text.repeating-mod.recorded_at": "Recorded at", + "text.repeating-mod.author": "Author", + "text.repeating-mod.delete": "Delete", + "text.repeating-mod.start": "Start", + "text.repeating-mod.stop": "Stop", + "text.repeating-mod.export": "Export", + + "message.repeating-mod.replay_start": "Replay started", + "message.repeating-mod.replay_stop": "Replay finished", + "message.repeating-mod.record_start": "Record started", + "message.repeating-mod.record_stop": "Record finished" } \ No newline at end of file diff --git a/src/main/resources/assets/repeating-mod/lang/ru_ru.json b/src/main/resources/assets/repeating-mod/lang/ru_ru.json index 2cf3521..84bf569 100644 --- a/src/main/resources/assets/repeating-mod/lang/ru_ru.json +++ b/src/main/resources/assets/repeating-mod/lang/ru_ru.json @@ -1,38 +1,38 @@ -{ - "key.repeating-mod.menu": "Меню репитинга", - "key.repeating-mod.toggle_replay": "Вкл/выкл повтор", - "key.repeating-mod.toggle_record": "Вкл/выкл запись", - - "text.repeating-mod.name": "Репитинг Мод", - "text.repeating-mod.start_record": "Начать запись", - "text.repeating-mod.stop_record": "Остановить запись", - "text.repeating-mod.start_replay": "Начать повтор", - "text.repeating-mod.stop_replay": "Остановить повтор", - "text.repeating-mod.record_tooltip": "Начать/остановить запись всех действий", - "text.repeating-mod.replay_tooltip": "Начать/остановить повтор записанных действий", - "text.repeating-mod.loop_tooltip": "Вкл/выкл повтор записи", - "text.repeating-mod.import": "Импорт записи", - "text.repeating-mod.export_tooltip": "Экспорт записи в файл", - "text.repeating-mod.import_tooltip": "Импорт записи из файла", - "text.repeating-mod.dev": "В разработке...", - "text.repeating-mod.nan_pos_delay": "Таймера позиции нету", - "text.repeating-mod.pos_delay": "Таймер позиции: %s тиков", - "text.repeating-mod.pos_delay_tooltip": "Таймер, после которой добавляется\nивент позиции (20 тиков = 1 сек)", - "text.repeating-mod.unnamed": "Безымянная Запись", - "text.repeating-mod.on_loop": "Включить повторение", - "text.repeating-mod.off_loop": "Выключить повторение", - "text.repeating-mod.recorded_at": "Записано в", - "text.repeating-mod.author": "Автор", - - "message.repeating-mod.replay_start": "Повтор начат", - "message.repeating-mod.replay_stop": "Повтор закончен", - "message.repeating-mod.record_start": "Запись начата", - "message.repeating-mod.record_stop": "Запись закончена", - - "text.repeating-mod.export_record": "Экпорт записи", - "text.repeating-mod.export": "Экспорт", - "text.repeating-mod.delete": "Удалить", - "text.repeating-mod.start": "Старт", - "text.repeating-mod.stop": "Стоп" -} - +{ + "key.repeating-mod.menu": "Меню репитинга", + "key.repeating-mod.toggle_replay": "Вкл/выкл повтор", + "key.repeating-mod.toggle_record": "Вкл/выкл запись", + + "text.repeating-mod.name": "Репитинг Мод", + "text.repeating-mod.start_record": "Начать запись", + "text.repeating-mod.stop_record": "Остановить запись", + "text.repeating-mod.start_replay": "Начать повтор", + "text.repeating-mod.stop_replay": "Остановить повтор", + "text.repeating-mod.record_tooltip": "Начать/остановить запись всех действий", + "text.repeating-mod.replay_tooltip": "Начать/остановить повтор записанных действий", + "text.repeating-mod.loop_tooltip": "Вкл/выкл повтор записи", + "text.repeating-mod.import": "Импорт записи", + "text.repeating-mod.export_tooltip": "Экспорт записи в файл", + "text.repeating-mod.import_tooltip": "Импорт записи из файла", + "text.repeating-mod.dev": "В разработке...", + "text.repeating-mod.nan_pos_delay": "Таймера позиции нету", + "text.repeating-mod.pos_delay": "Таймер позиции: %s тиков", + "text.repeating-mod.pos_delay_tooltip": "Таймер, после которой добавляется\nивент позиции (20 тиков = 1 сек)", + "text.repeating-mod.unnamed": "Безымянная Запись", + "text.repeating-mod.on_loop": "Включить повторение", + "text.repeating-mod.off_loop": "Выключить повторение", + "text.repeating-mod.recorded_at": "Записано в", + "text.repeating-mod.author": "Автор", + + "message.repeating-mod.replay_start": "Повтор начат", + "message.repeating-mod.replay_stop": "Повтор закончен", + "message.repeating-mod.record_start": "Запись начата", + "message.repeating-mod.record_stop": "Запись закончена", + + "text.repeating-mod.export_record": "Экпорт записи", + "text.repeating-mod.export": "Экспорт", + "text.repeating-mod.delete": "Удалить", + "text.repeating-mod.start": "Старт", + "text.repeating-mod.stop": "Стоп" +} + diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7a2119f..4a40393 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,38 +1,38 @@ -{ - "schemaVersion": 1, - "id": "repeating-mod", - "version": "${version}", - - "name": "Repeating Mod", - "description": "Mod that repeats your recorded actions. ", - "authors": [ - "TheMixRay" - ], - "contact": { - "homepage": "https://modrinth.com/mod/repeating-mod", - "sources": "https://github.com/MeexReay/repeating-mod" - }, - - "license": "CC0-1.0", - "icon": "icon.png", - - "environment": "client", - "entrypoints": { - "client": [ - "themixray.repeating.mod.Main" - ] - }, - "mixins": [ - "repeating-mod.mixins.json" - ], - - "depends": { - "fabricloader": ">=0.14.14", - "fabric-api": "*", - "minecraft": ">=1.20", - "java": ">=17" - }, - "suggests": { - "another-mod": "*" - } -} +{ + "schemaVersion": 1, + "id": "repeating-mod", + "version": "${version}", + + "name": "Repeating Mod", + "description": "Mod that repeats your recorded actions. ", + "authors": [ + "TheMixRay" + ], + "contact": { + "homepage": "https://modrinth.com/mod/repeating-mod", + "sources": "https://github.com/MeexReay/repeating-mod" + }, + + "license": "WTFPL", + "icon": "icon.png", + + "environment": "client", + "entrypoints": { + "client": [ + "ru.themixray.repeating_mod.Main" + ] + }, + "mixins": [ + "repeating-mod.mixins.json" + ], + + "depends": { + "fabricloader": ">=0.14.14", + "fabric-api": "*", + "minecraft": ">=1.21.4", + "java": ">=17" + }, + "suggests": { + "another-mod": "*" + } +} diff --git a/src/main/resources/repeating-mod.mixins.json b/src/main/resources/repeating-mod.mixins.json index 6156b8f..7bfbaa8 100644 --- a/src/main/resources/repeating-mod.mixins.json +++ b/src/main/resources/repeating-mod.mixins.json @@ -1,20 +1,20 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "themixray.repeating.mod.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "MovementMixin", - "InputMixin", - "RendererMixin", - "EntityMixin", - "ClientMixin", - "ScreenMixin", - "PlayerMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "ru.themixray.repeating_mod.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "MovementMixin", + "InputMixin", + "RendererMixin", + "EntityMixin", + "ClientMixin", + "ScreenMixin", + "PlayerMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}