diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe07704..00000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 00000000..ac4c607d --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,32 @@ +name: Audit - Build +on: [pull_request] + +jobs: + build: + strategy: + matrix: + # Use these Java versions + java: [17] + # and run on both Linux and Windows + os: [ubuntu-20.04, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: checkout repository + uses: actions/checkout@v2 + - name: validate gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: setup jdk ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: make gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + - name: build + run: ./gradlew build + - name: capture build artifacts + if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from the latest java on one OS + uses: actions/upload-artifact@v2 + with: + name: Artifacts + path: build/libs/ \ No newline at end of file diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml deleted file mode 100644 index c6b041ec..00000000 --- a/.github/workflows/build-and-deploy.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Build and Deploy -on: - push: - branches: - - '*/main' - -jobs: - build-and-deploy: - env: - BRANCH_PREFIX: $(cat gradle.properties | grep mod_version | cut -d'+' -f2) - strategy: - matrix: - java: [ - 17, - ] - runs-on: ubuntu-latest - steps: - - name: check environment variables - run: env - - name: checkout repository - uses: actions/checkout@v2 - - name: validate gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - name: make gradle wrapper executable - run: chmod +x ./gradlew - - name: build - if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' - run: ./gradlew build - - name: capture build artifacts - if: | - ${{ matrix.java == '17' }} - github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' - uses: actions/upload-artifact@v2 - with: - name: Artifacts - path: build/libs/ - - name: get mod version - if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' - id: mod_version - run: | - mod_version_val=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d '\n') - echo "mod_version=$mod_version_val" >> $GITHUB_OUTPUT - - name: get minecraft version - if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' - id: minecraft_version - run: | - minecraft_version_val=$(grep "mod_version" gradle.properties | cut -d'+' -f2 | tr -d '\n') - echo "minecraft_version=$minecraft_version_val" >> $GITHUB_OUTPUT - - name: deploy with mc-publish - if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' - uses: Kir-Antipov/mc-publish@v3.2 - with: - curseforge-id: 514734 - curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} - curseforge-dependencies: | - fabric-api | depends | * - curseforge-files-secondary: build/libs/*-@(sources\|javadoc).jar - - modrinth-id: wFyCClLQ - modrinth-token: "${{ secrets.MODRINTH_TOKEN }}" - modrinth-dependencies: | - fabric-api | depends | * - # Modrinth has issues accepting javadocs right now - - github-tag: "${{ steps.mod_version.outputs.mod_version }}" - github-token: ${{ secrets.REPOSITORY_TOKEN }} - github-commitish: ${{ steps.minecraft_version.outputs.minecraft_version }}/main - github-files-secondary: build/libs/*-@(sources\|javadoc).jar - - version: "${{ steps.mod_version.outputs.mod_version }}" - version-type: release - changelog-file: CHANGELOG.md - - loaders: fabric - game-versions: "${{ steps.minecraft_version.outputs.minecraft_version }}" - java: "${{ matrix.java }}" \ No newline at end of file diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml new file mode 100644 index 00000000..9f0a9ea6 --- /dev/null +++ b/.github/workflows/deployment.yml @@ -0,0 +1,138 @@ +name: Deployment (J17) +on: + push: + branches-ignore: + - master + - "**-dev" + - "**-dev**" + - dev + +jobs: + build-and-deploy: + env: + BRANCH_PREFIX: $(cat gradle.properties | grep mod_version | cut -d'+' -f2) + strategy: + matrix: + java: [17] + runs-on: ubuntu-latest + steps: + - name: check environment variables + run: env + - name: checkout repository + uses: actions/checkout@v3 + - name: validate gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: setup jdk ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java }} + distribution: 'microsoft' + - name: make gradle wrapper executable + run: chmod +x ./gradlew + - name: build + if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + run: ./gradlew build + - name: capture build artifacts (forge) + if: | + ${{ matrix.java == '17' }} + github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + uses: actions/upload-artifact@v3 + with: + name: Artifacts (Forge) + path: forge/build/libs/ + - name: capture build artifacts (fabric) + if: | + ${{ matrix.java == '17' }} + github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + uses: actions/upload-artifact@v3 + with: + name: Artifacts (Fabric) + path: fabric/build/libs/ + - name: get mod version + if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + id: mod_version + run: | + archived_name=$(grep "archives_base_name" gradle.properties | cut -d'=' -f2 | tr -d '\n') + mod_version_val=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d '\n') + commitish_val=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | cut -d'-' -f1 | tr -d '\n') + echo "archive_name=$archived_name" >> $GITHUB_OUTPUT + echo "mod_version=$mod_version_val" >> $GITHUB_OUTPUT + echo "commitish=$commitish_val/main" >> $GITHUB_OUTPUT + - name: get minecraft version + if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + id: minecraft_version + run: | + minecraft_version_val=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2 | tr -d '\n') + echo "minecraft_version=$minecraft_version_val" >> $GITHUB_OUTPUT + + - name: deploy fabric! (mc-publish) + if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + uses: Kir-Antipov/mc-publish@v3.3 + with: + name: ${{ steps.mod_version.outputs.mod_version }} + files: | + fabric/build/libs/!(*-@(dev|sources|javadoc|shadow)).jar + fabric/build/libs/*-@(dev|sources|javadoc|shadow).jar + github-files: | + fabric/build/libs/!(*-@(dev|sources|javadoc|shadow)).jar + fabric/build/libs/*-@(dev|sources|javadoc|shadow).jar + + modrinth-id: oLPaySSb + curseforge-id: 1019391 + + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + + github-tag: ${{ steps.mod_version.outputs.mod_version }} + github-token: ${{ secrets.REPOSITORY_TOKEN }} + github-commitish: ${{ steps.commitish.outputs.commitish }} + + version: ${{ steps.mod_version.outputs.mod_version }}-fabric + changelog-file: CHANGELOG.md + + loaders: | + fabric + quilt + + dependencies: | + fabric-api@0.83.0+1.20.1(required){modrinth:P7dR8mSH}{curseforge:306612}#(ignore:github) + fabric-language-kotlin@1.9.5+kotlin.1.8.22(required){modrinth:Ha28R6CL}{curseforge:308769}#(ignore:github) + + game-versions: "${{ steps.minecraft_version.outputs.minecraft_version }}" + java: "${{ matrix.java }}" + + - name: deploy forge! (mc-publish) + if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}' + uses: Kir-Antipov/mc-publish@v3.3 + with: + name: ${{ steps.mod_version.outputs.mod_version }} + + files: | + forge/build/libs/!(*-@(dev|sources|javadoc|shadow)).jar + forge/build/libs/*-@(dev|sources|javadoc|shadow).jar + github-files: | + forge/build/libs/!(*-@(dev|sources|javadoc|shadow)).jar + forge/build/libs/*-@(dev|sources|javadoc|shadow).jar + + modrinth-id: oLPaySSb + curseforge-id: 1019391 + + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + modrinth-token: "${{ secrets.MODRINTH_TOKEN }}" + + github-tag: ${{ steps.mod_version.outputs.mod_version }} + github-token: ${{ secrets.REPOSITORY_TOKEN }} + github-commitish: ${{ steps.commitish.outputs.commitish }} + + version: ${{ steps.mod_version.outputs.mod_version }}-forge + changelog-file: CHANGELOG.md + + loaders: | + forge + neoforge + + dependencies: | + kotlinforforge@4.10.0(required){modrinth:ordsPcFz}{curseforge:351264}#(ignore:github) + + game-versions: "${{ steps.minecraft_version.outputs.minecraft_version }}" + java: "${{ matrix.java }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 09cd281f..ccb0c562 100644 --- a/.gitignore +++ b/.gitignore @@ -1,33 +1,19 @@ -# gradle - -.gradle/ build/ -out/ -classes/ - -# eclipse - -*.launch - -# idea - -.idea/ -*.iml *.ipr +run/ *.iws - -# vscode - -.settings/ -.vscode/ +out/ +*.iml +.gradle/ +output/ bin/ +libs/ + .classpath .project - -# macos - -*.DS_Store - -# fabric - -run/ +.idea/ +classes/ +.metadata +.vscode +.settings +*.launch \ No newline at end of file diff --git a/LICENSE b/LICENSE index 0ff0de68..f288702d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,22 +1,674 @@ -MIT License - -Copyright (c) 2022 CleverNucleus -Copyright (c) 2024 MerryweatherLost - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f77e93e7..00000000 --- a/build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -plugins { - id "fabric-loom" version "1.1-SNAPSHOT" - id "maven-publish" -} - -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name -version = project.mod_version -group = project.maven_group - -repositories { - -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version - } -} - -tasks.withType(JavaCompile).configureEach { - it.options.release = 17 -} - -javadoc { - options.addStringOption("Xdoclint:none", "-quiet") - classpath = files(sourceSets.main.compileClasspath) - include("**/api/**") -} - -task javadocJar(type: Jar) { - dependsOn javadoc - dependsOn processResources - from javadoc.destinationDir - from file("build/resources/main/fabric.mod.json") - archiveClassifier = "javadoc" -} - -// Modrinth has issues accepting javadocs right now -// build.dependsOn javadocJar - -java { - withSourcesJar() -} - -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} - } -} - -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - - repositories { - - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..d27d25f9 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,65 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("architectury-plugin") version "3.4-SNAPSHOT" + id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false + java + kotlin("jvm") version "2.0.0" + idea +} + +val minecraftVersion = project.properties["minecraft_version"] as String + +architectury.minecraft = minecraftVersion + +subprojects { + apply(plugin = "dev.architectury.loom") + + val loom = project.extensions.getByName("loom") + + repositories { + mavenCentral() + mavenLocal() + maven("https://maven.parchmentmc.org") + maven("https://maven.fabricmc.net/") + maven("https://maven.minecraftforge.net/") + maven("https://thedarkcolour.github.io/KotlinForForge/") + maven("https://maven.quiltmc.org/repository/release/") + maven("https://maven.terraformersmc.com") + maven("https://maven.wispforest.io/releases") + maven("https://maven.kosmx.dev/") + } + + @Suppress("UnstableApiUsage") + dependencies { + "minecraft"("com.mojang:minecraft:$minecraftVersion") + loom.silentMojangMappingsLicense() + "mappings"(loom.layered { + mappings("org.quiltmc:quilt-mappings:$minecraftVersion+build.${project.properties["quilt_mappings_version"]}:intermediary-v2") + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-$minecraftVersion:${project.properties["parchment"]}@zip") + }) + + compileOnly("org.jetbrains:annotations:24.1.0") + } +} + +allprojects { + apply(plugin = "java") + apply(plugin = "org.jetbrains.kotlin.jvm") + apply(plugin = "architectury-plugin") + apply(plugin = "maven-publish") + apply(plugin = "idea") + + version = project.properties["mod_version"] as String + group = project.properties["maven_group"] as String + base.archivesName.set(project.properties["archives_base_name"] as String) + + tasks.withType().configureEach { + options.encoding = "UTF-8" + options.release.set(17) + } + + java.withSourcesJar() +} + diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 00000000..fcf79f92 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,37 @@ +architectury { + common("forge", "fabric") + platformSetupLoomIde() +} + +val minecraftVersion = project.properties["minecraft_version"] as String + +loom.accessWidenerPath.set(file("src/main/resources/data_attributes.accesswidener")) + +sourceSets.main.get().resources.srcDir("src/main/generated/resources") + +dependencies { + // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies + // Do NOT use other classes from fabric loader + modImplementation("net.fabricmc:fabric-loader:${project.properties["fabric_loader_version"]}") +} + +publishing { + publications.create("mavenCommon") { + artifactId = "${project.properties["archives_base_name"]}" + "-Common" + from(components["java"]) + } + + repositories { + mavenLocal() + maven { + val releasesRepoUrl = "https://example.com/releases" + val snapshotsRepoUrl = "https://example.com/snapshots" + url = uri(if (project.version.toString().endsWith("SNAPSHOT") || project.version.toString().startsWith("0")) snapshotsRepoUrl else releasesRepoUrl) + name = "ExampleRepo" + credentials { + username = project.properties["repoLogin"]?.toString() + password = project.properties["repoPassword"]?.toString() + } + } + } +} diff --git a/common/src/main/kotlin/com/bibireden/data_attributes/DataAttributes.kt b/common/src/main/kotlin/com/bibireden/data_attributes/DataAttributes.kt new file mode 100644 index 00000000..6bfaaf9b --- /dev/null +++ b/common/src/main/kotlin/com/bibireden/data_attributes/DataAttributes.kt @@ -0,0 +1,18 @@ +package com.bibireden.data_attributes + +import com.mojang.logging.LogUtils +import org.slf4j.Logger + +object DataAttributes { + /** The mod id for data_attributes. */ + const val MOD_ID: String = "data_attributes" + + /** The logger for data_attributes. */ + val LOGGER: Logger = LogUtils.getLogger() + + /** Initializes the mod. */ + @JvmStatic + fun init() { + LOGGER.info("...") + } +} diff --git a/common/src/main/resources/data_attributes-common.mixins.json b/common/src/main/resources/data_attributes-common.mixins.json new file mode 100644 index 00000000..f2bc9186 --- /dev/null +++ b/common/src/main/resources/data_attributes-common.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "com.bibireden.data_attributes.mixin", + "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", + "client": [], + "mixins": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/common/src/main/resources/data_attributes.accesswidener b/common/src/main/resources/data_attributes.accesswidener new file mode 100644 index 00000000..13268c32 --- /dev/null +++ b/common/src/main/resources/data_attributes.accesswidener @@ -0,0 +1 @@ +accessWidener v2 named \ No newline at end of file diff --git a/common/src/main/resources/data_attributes.common.json b/common/src/main/resources/data_attributes.common.json new file mode 100644 index 00000000..173e5abc --- /dev/null +++ b/common/src/main/resources/data_attributes.common.json @@ -0,0 +1,3 @@ +{ + "accessWidener": "data_attributes.accesswidener" +} \ No newline at end of file diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts new file mode 100644 index 00000000..a5a4db20 --- /dev/null +++ b/fabric/build.gradle.kts @@ -0,0 +1,114 @@ +plugins { + id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.google.devtools.ksp") version "2.0.0-1.0.21" +} + +architectury { + platformSetupLoomIde() + fabric() +} + +val minecraftVersion = project.properties["minecraft_version"] as String + +configurations { + create("common") + create("shadowCommon") + compileClasspath.get().extendsFrom(configurations["common"]) + runtimeClasspath.get().extendsFrom(configurations["common"]) + getByName("developmentFabric").extendsFrom(configurations["common"]) +} + +loom { + accessWidenerPath.set(project(":common").loom.accessWidenerPath) +} + +// Fabric Datagen Gradle config. Remove if not using Fabric datagen +fabricApi.configureDataGeneration() + +dependencies { + modImplementation("net.fabricmc:fabric-loader:${project.properties["fabric_loader_version"]}") + modApi("net.fabricmc.fabric-api:fabric-api:${project.properties["fabric_api_version"]}+$minecraftVersion") + modImplementation("net.fabricmc:fabric-language-kotlin:${project.properties["fabric_language_kotlin_version"]}") + + include("io.wispforest:owo-sentinel:${project.properties["owo_version"]}") + + modImplementation("io.wispforest:endec:${project.properties["endec_version"]}")!!.let(::include) + modImplementation("io.wispforest.endec:netty:${project.properties["endec_netty_version"]}")!!.let(::include) + + modImplementation("com.terraformersmc:modmenu:${project.properties["modmenu_version"]}") { + exclude("net.fabricmc.fabric-api") + } + + annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.properties["mixinextras_version"]}")?.let { + implementation(it) + include(it) + } + + modImplementation("io.wispforest:owo-lib:${project.properties["owo_version"]}") + + implementation("com.google.devtools.ksp:symbol-processing-api:${project.properties["ksp_version"]}") + implementation("com.squareup:kotlinpoet-ksp:${project.properties["kotlinpoet_version"]}") + + ksp("dev.kosmx.kowoconfig:ksp-owo-config:${project.properties["ksp_owo_config_version"]}") + + "common"(project(":common", "namedElements")) { isTransitive = false } + "shadowCommon"(project(":common", "transformProductionFabric")) { isTransitive = false } +} + +tasks { + base.archivesName.set(base.archivesName.get() + "-Fabric") + processResources { + inputs.property("version", project.version) + + filesMatching("fabric.mod.json") { + expand(mapOf("version" to project.version)) + } + } + + shadowJar { + configurations = listOf(project.configurations.getByName("shadowCommon")) + archiveClassifier.set("dev-shadow") + } + + remapJar { + injectAccessWidener.set(true) + inputFile.set(shadowJar.get().archiveFile) + dependsOn(shadowJar) + } + + jar.get().archiveClassifier.set("dev") + + sourcesJar { + val commonSources = project(":common").tasks.sourcesJar + dependsOn(commonSources) + from(commonSources.get().archiveFile.map { zipTree(it) }) + } +} + +components { + java.run { + if (this is AdhocComponentWithVariants) + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) { skip() } + } +} + +publishing { + publications.create("mavenFabric") { + artifactId = "${project.properties["archives_base_name"]}" + "-Fabric" + from(components["java"]) + } + + repositories { + mavenLocal() + maven { + val releasesRepoUrl = "https://example.com/releases" + val snapshotsRepoUrl = "https://example.com/snapshots" + url = uri(if (project.version.toString().endsWith("SNAPSHOT") || project.version.toString().startsWith("0")) snapshotsRepoUrl else releasesRepoUrl) + name = "ExampleRepo" + credentials { + username = project.properties["repoLogin"]?.toString() + password = project.properties["repoPassword"]?.toString() + } + } + } +} \ No newline at end of file diff --git a/fabric/src/main/kotlin/com/bibireden/data_attributes/fabric/DataAttributesFabric.kt b/fabric/src/main/kotlin/com/bibireden/data_attributes/fabric/DataAttributesFabric.kt new file mode 100644 index 00000000..99787dc8 --- /dev/null +++ b/fabric/src/main/kotlin/com/bibireden/data_attributes/fabric/DataAttributesFabric.kt @@ -0,0 +1,10 @@ +package com.bibireden.data_attributes.fabric + +import com.bibireden.data_attributes.DataAttributes +import net.fabricmc.api.ModInitializer + +class DataAttributesFabric : ModInitializer { + override fun onInitialize() { + DataAttributes.init() + } +} diff --git a/fabric/src/main/resources/data_attributes.mixins.json b/fabric/src/main/resources/data_attributes.mixins.json new file mode 100644 index 00000000..114dcc09 --- /dev/null +++ b/fabric/src/main/resources/data_attributes.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "com.bibireden.data_attributes.fabric.mixin", + "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", + "client": [ + ], + "mixins": [ + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..581e4ea9 --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,33 @@ +{ + "schemaVersion": 1, + "id": "data_attributes", + "version": "${version}", + "name": "Data Attributes", + "description": "Allows the ability to cache player data to the server based on cached keys.", + "authors": [ + "Bare Minimum Studios", + "CleverNucleus (former author)" + ], + "contact": { + "homepage": "https://bareminimumstudios.github.io/Bare-Minimum-Docs/", + "sources": "https://github.com/BareMinimumStudios/data-attributes" + }, + "license": "MIT", + "icon": "assets/data_attributes/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "com.bibireden.data_attributes.fabric.DataAttributesFabric" + ] + }, + "mixins": [ + "data_attributes.mixins.json", + "data_attributes-common.mixins.json" + ], + "depends": { + "fabric": "*", + "minecraft": "~1.20.1", + "fabric-api": "*", + "fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23" + } +} \ No newline at end of file diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts new file mode 100644 index 00000000..1583c316 --- /dev/null +++ b/forge/build.gradle.kts @@ -0,0 +1,104 @@ +plugins { + id("com.github.johnrengelman.shadow") version "8.1.1" +} + +architectury { + platformSetupLoomIde() + forge() +} + +val minecraftVersion = project.properties["minecraft_version"] as String + +configurations { + create("common") + create("shadowCommon") + compileClasspath.get().extendsFrom(configurations["common"]) + runtimeClasspath.get().extendsFrom(configurations["common"]) + getByName("developmentForge").extendsFrom(configurations["common"]) +} + +loom { + accessWidenerPath.set(project(":common").loom.accessWidenerPath) + + forge { + convertAccessWideners.set(true) + extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name) + + mixinConfig("data_attributes-common.mixins.json") + mixinConfig("data_attributes.mixins.json") + } + + // Forge Datagen Gradle config. Remove if not using Forge datagen + runs.create("datagen") { + data() + programArgs("--all", "--mod", "data_attributes") + programArgs("--output", project(":common").file("src/main/generated/resources").absolutePath) + programArgs("--existing", project(":common").file("src/main/resources").absolutePath) + } +} + +dependencies { + forge("net.minecraftforge:forge:$minecraftVersion-${project.properties["forge_version"]}") + implementation("thedarkcolour:kotlinforforge:${project.properties["kotlin_forge_version"]}") + + "common"(project(":common", "namedElements")) { isTransitive = false } + "shadowCommon"(project(":common", "transformProductionForge")) { isTransitive = false } +} + +tasks { + base.archivesName.set(base.archivesName.get() + "-Forge") + processResources { + inputs.property("version", project.version) + + filesMatching("META-INF/mods.toml") { + expand(mapOf("version" to project.version)) + } + } + + shadowJar { + exclude("fabric.mod.json") + configurations = listOf(project.configurations.getByName("shadowCommon")) + archiveClassifier.set("dev-shadow") + } + + remapJar { + inputFile.set(shadowJar.get().archiveFile) + dependsOn(shadowJar) + } + + jar.get().archiveClassifier.set("dev") + + sourcesJar { + val commonSources = project(":common").tasks.sourcesJar + dependsOn(commonSources) + from(commonSources.get().archiveFile.map { zipTree(it) }) + } +} + +components { + java.run { + if (this is AdhocComponentWithVariants) + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) { skip() } + } +} + +publishing { + publications.create("mavenForge") { + artifactId = "${project.properties["archives_base_name"]}" + "-Forge" + from(components["java"]) + } + + repositories { + mavenLocal() + maven { + val releasesRepoUrl = "https://example.com/releases" + val snapshotsRepoUrl = "https://example.com/snapshots" + url = uri(if (project.version.toString().endsWith("SNAPSHOT") || project.version.toString().startsWith("0")) snapshotsRepoUrl else releasesRepoUrl) + name = "ExampleRepo" + credentials { + username = project.properties["repoLogin"]?.toString() + password = project.properties["repoPassword"]?.toString() + } + } + } +} \ No newline at end of file diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 00000000..32f842a6 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.platform=forge \ No newline at end of file diff --git a/forge/src/main/kotlin/com/bibireden/data_attributes/forge/DataAttributesForge.kt b/forge/src/main/kotlin/com/bibireden/data_attributes/forge/DataAttributesForge.kt new file mode 100644 index 00000000..2669bd64 --- /dev/null +++ b/forge/src/main/kotlin/com/bibireden/data_attributes/forge/DataAttributesForge.kt @@ -0,0 +1,11 @@ +package com.bibireden.data_attributes.forge + +import com.bibireden.data_attributes.DataAttributes +import net.minecraftforge.fml.common.Mod + +@Mod(DataAttributes.MOD_ID) +class DataAttributesForge { + init { + DataAttributes.init() + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 00000000..f2021ec0 --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,27 @@ +modLoader = "kotlinforforge" +loaderVersion = "[4.9,)" +issueTrackerURL = "https://github.com/BareMinimumStudios/data-attributes/issues" +license = "MIT" + +[[mods]] +modId = "data_attributes" +version = "${version}" +displayName = "Data Attributes" +authors = "Bare Minimum Studios" +description = '''TBD''' +logoFile = "data_attributes_icon.png" +displayURL = "https://github.com/BareMinimumStudios/data-attributes" + +[[dependencies.data_attributes]] +modId = "forge" +mandatory = true +versionRange = "[47,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.data_attributes]] +modId = "minecraft" +mandatory = true +versionRange = "[1.20.1]" +ordering = "NONE" +side = "BOTH" diff --git a/forge/src/main/resources/data_attributes.mixins.json b/forge/src/main/resources/data_attributes.mixins.json new file mode 100644 index 00000000..0a4cb874 --- /dev/null +++ b/forge/src/main/resources/data_attributes.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "com.bibireden.data_attributes.forge.mixin", + "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", + "client": [ + ], + "mixins": [ + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 00000000..23ba45b9 --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "Offline Player Cache", + "pack_format": 22 + } +} diff --git a/gradle.properties b/gradle.properties index f7a1b96e..01973948 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,37 @@ -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx6G +org.gradle.parallel=true -minecraft_version = 1.20.1 -yarn_mappings = 1.20.1+build.10 -loader_version = 0.15.3 +# METADATA +archives_base_name=DataAttributes +mod_version=2.0.0+1.20.1-beta.9 +minecraft_version=1.20.1 +maven_group=com.bibireden.data_attributes -mod_version=1.6.0+1.20.1 -maven_group=com.github.clevernucleus -archives_base_name=dataattributes_dc +# FABRIC SPECIFIC +fabric_loader_version=0.15.11 +fabric_api_version=0.92.2 +fabric_language_kotlin_version=1.11.0+kotlin.2.0.0 +# FABRIC DEPS +# ~ KSP +ksp_version=2.0.0-1.0.21 +kotlinpoet_version=1.17.0 +# ~ OwO +owo_version=0.11.2+1.20 +ksp_owo_config_version=0.1.0 +# ~ Endec +endec_version=0.1.7 +endec_netty_version=0.1.3 -fabric_api_version=0.91.0+1.20.1 + +# FORGE SPECIFIC +forge_version=47.2.32 +kotlin_forge_version=4.11.0 +# FORGE DEPS + +# COMBINED DEPS +modmenu_version=7.2.2 +mixinextras_version=0.5.0-beta.1 + +# MAPPINGS 💖 +parchment=2023.09.03 +quilt_mappings_version=23 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb879..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index c53aefaa..1aa94a42 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32..25da30db 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +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 @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +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 @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/img/fabric_api.png b/img/fabric_api.png deleted file mode 100644 index c736465d..00000000 Binary files a/img/fabric_api.png and /dev/null differ diff --git a/img/logo.png b/img/logo.png deleted file mode 100644 index eb63d8cd..00000000 Binary files a/img/logo.png and /dev/null differ diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index b02216ba..00000000 --- a/settings.gradle +++ /dev/null @@ -1,10 +0,0 @@ -pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - mavenCentral() - gradlePluginPortal() - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..374d39c0 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,19 @@ +pluginManagement.repositories { + maven("https://maven.fabricmc.net/") + maven("https://maven.architectury.dev/") + maven("https://maven.minecraftforge.net/") + gradlePluginPortal() +} + +plugins { + id("com.gradle.develocity") version "3.17.4" +} + +develocity.buildScan { + termsOfUseUrl = "https://gradle.com/terms-of-service" + termsOfUseAgree = "yes" +} + +include("common", "fabric", "forge") + +rootProject.name = "DataAttributes" diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributes.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributes.java deleted file mode 100644 index 647960c7..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributes.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc; - -import org.jetbrains.annotations.Nullable; - -import com.github.clevernucleus.dataattributes_dc.api.DataAttributesAPI; -import com.github.clevernucleus.dataattributes_dc.api.event.EntityAttributeModifiedEvents; -import com.github.clevernucleus.dataattributes_dc.impl.AttributeManager; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeContainer; - -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents; -import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking; -import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking.LoginSynchronizer; -import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.resource.ResourceType; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerLoginNetworkHandler; -import net.minecraft.util.Identifier; -import net.minecraft.world.World; - -public class DataAttributes implements ModInitializer { - // Identifiers for networking - public static final Identifier HANDSHAKE = new Identifier(DataAttributesAPI.MODID, "handshake"); - public static final Identifier RELOAD = new Identifier(DataAttributesAPI.MODID, "reload"); - - // Attribute manager instance - public static final AttributeManager MANAGER = new AttributeManager(); - - // Sends attribute data to the client during login query start - private static void loginQueryStart(ServerLoginNetworkHandler handler, MinecraftServer server, PacketSender sender, - LoginSynchronizer synchronizer) { - PacketByteBuf buf = PacketByteBufs.create(); - NbtCompound tag = new NbtCompound(); - DataAttributes.MANAGER.toNbt(tag); - buf.writeNbt(tag); - sender.sendPacket(HANDSHAKE, buf); - } - - // Placeholder for handling login query response - private static void loginQueryResponse(MinecraftServer server, ServerLoginNetworkHandler handler, - boolean understood, PacketByteBuf buf, LoginSynchronizer synchronizer, PacketSender responseSender) { - // Implementation details can be added as needed - } - - // Refreshes attributes for living entities - public static void refreshAttributes(final Entity entity) { - if (!(entity instanceof LivingEntity)) - return; - ((MutableAttributeContainer) ((LivingEntity) entity).getAttributes()).refresh(); - } - - // Handles health modification events for living entities - private static void healthModified(final EntityAttribute attribute, final @Nullable LivingEntity livingEntity, - final EntityAttributeModifier modifier, final double prevValue, final boolean isWasAdded) { - if (livingEntity == null) - return; - World world = livingEntity.getWorld(); - if (world.isClient) - return; - if (attribute != EntityAttributes.GENERIC_MAX_HEALTH) - return; - - float c0 = livingEntity.getHealth(); - float c1 = c0 * livingEntity.getMaxHealth() / (float) prevValue; - - livingEntity.setHealth(c1); - } - - @Override - public void onInitialize() { - // Registers the AttributeManager as a reload listener for server data - ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(MANAGER); - - // Registers event handlers - ServerLoginConnectionEvents.QUERY_START.register(DataAttributes::loginQueryStart); - ServerLoginNetworking.registerGlobalReceiver(HANDSHAKE, DataAttributes::loginQueryResponse); - ServerEntityWorldChangeEvents.AFTER_ENTITY_CHANGE_WORLD - .register((oldEntity, newEntity, from, to) -> refreshAttributes(newEntity)); - ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD - .register((player, from, to) -> refreshAttributes(player)); - EntityAttributeModifiedEvents.MODIFIED.register(DataAttributes::healthModified); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributesClient.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributesClient.java deleted file mode 100644 index 4a0ef710..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/DataAttributesClient.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; - -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientLoginNetworkHandler; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; - -public class DataAttributesClient implements ClientModInitializer { - // Handles the received login query packet - private static CompletableFuture loginQueryReceived(MinecraftClient client, - ClientLoginNetworkHandler handler, PacketByteBuf buf, - Consumer>> listenerAdder) { - onPacketReceived(client, buf); - return CompletableFuture.completedFuture(PacketByteBufs.empty()); - } - - // Handles the received update packet - private static void updateReceived(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, - PacketSender responseSender) { - onPacketReceived(client, buf); - } - - // Common method for handling received packets - private static void onPacketReceived(MinecraftClient client, PacketByteBuf buf) { - NbtCompound tag = buf.readNbt(); - - // Execute on the main thread to interact with the game state - client.execute(() -> { - if (tag != null) { - // Update the local AttributeManager with data from the server - DataAttributes.MANAGER.fromNbt(tag); - // Apply the changes to the client's game state - DataAttributes.MANAGER.apply(); - } - }); - } - - // Initialization method called when the client starts - @Override - public void onInitializeClient() { - // Register packet handlers for login query and update packets - ClientLoginNetworking.registerGlobalReceiver(DataAttributes.HANDSHAKE, - DataAttributesClient::loginQueryReceived); - ClientPlayNetworking.registerGlobalReceiver(DataAttributes.RELOAD, DataAttributesClient::updateReceived); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/DataAttributesAPI.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/DataAttributesAPI.java deleted file mode 100644 index 70a0c742..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/DataAttributesAPI.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api; - -import java.util.function.Function; -import java.util.function.Supplier; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; - -/** - * - * The core API access - provides access to the modid and safe static attribute - * instantiation. - * - * @author CleverNucleus - * - */ -public final class DataAttributesAPI { - - /** - * The modid for Data Attributes. - */ - public static final String MODID = "dataattributes"; - - /** - * The entity instance for LivingEntity.class. - */ - public static final String ENTITY_INSTANCE_LIVING_ENTITY = "living_entity"; - - /** - * The entity instance for MobEntity.class. - */ - public static final String ENTITY_INSTANCE_MOB_ENTITY = "mob_entity"; - - /** - * The entity instance for PathAwareEntity.class. - */ - public static final String ENTITY_INSTANCE_PATH_AWARE_ENTITY = "path_aware_entity"; - - /** - * The entity instance for HostileEntity.class. - */ - public static final String ENTITY_INSTANCE_HOSTILE_ENTITY = "hostile_entity"; - - /** - * The entity instance for PassiveEntity.class. - */ - public static final String ENTITY_INSTANCE_PASSIVE_ENTITY = "passive_entity"; - - /** - * The entity instance for AnimalEntity.class. - */ - public static final String ENTITY_INSTANCE_ANIMAL_ENTITY = "animal_entity"; - - /** - * @param attributeKey Attribute registry key. - * @return A supplier getting the registered attribute assigned to the input - * key. - * Uses a supplier because attributes added using json are null until - * datapacks are loaded/synced to the client, - * so static initialisation would not work. Using this you can safely - * access an attribute through a static reference. - */ - public static Supplier getAttribute(final Identifier attributeKey) { - return () -> Registries.ATTRIBUTE.get(attributeKey); - } - - /** - * Allows for an Optional-like use of attributes that may or may not exist all - * the time. This is the correct way of getting and using - * values from attributes loaded by datapacks. - * - * @param - * @param livingEntity - * @param entityAttribute - * @param fallback - * @param function - * @return If the input attribute is both registered to the game and present on - * the input entity, returns the returning value of the input function. - * Else returns the fallback input. - */ - public static T ifPresent(final LivingEntity livingEntity, Supplier entityAttribute, - final T fallback, Function function) { - AttributeContainer container = livingEntity.getAttributes(); - EntityAttribute attribute = entityAttribute.get(); - - if (attribute != null && container.hasAttribute(attribute)) { - return function.apply(container.getValue(attribute)); - } - - return fallback; - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/FunctionBehaviour.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/FunctionBehaviour.java deleted file mode 100644 index f6a376a5..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/FunctionBehaviour.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -/** - * @since 1.4.0 - * @author CleverNucleus - */ -public enum FunctionBehaviour { - /** Addition of values as defined by the parent attribute. Equivalent of EntityAttributeModifier.Operation.ADDITION. */ - ADDITION((byte)0), - /** Multiplication of parent attribute. Equivalent of EntityAttributeModifier.Operation.MULTIPLY_TOTAL. */ - MULTIPLY((byte)1); - - private final byte id; - - private FunctionBehaviour(final byte id) { - this.id = id; - } - - public static FunctionBehaviour of(final byte id) { - return switch(id) { - case 0 -> ADDITION; - case 1 -> MULTIPLY; - default -> ADDITION; - }; - } - - public byte id() { - return this.id; - } - - @Override - public String toString() { - return String.valueOf(this.id); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IAttributeFunction.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IAttributeFunction.java deleted file mode 100644 index 695a7aff..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IAttributeFunction.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -/** - * @since 1.4.0 - * @author CleverNucleus - */ -public interface IAttributeFunction { - - /** - * @return The FunctionBehaviour associated with this attribute function. - */ - FunctionBehaviour behaviour(); - - /** - * @return The value associated with this attribute function. - */ - double value(); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttribute.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttribute.java deleted file mode 100644 index a9279e12..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttribute.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -import java.util.Collection; -import java.util.Map; - -/** - * - * EntityAttribute's implement this through a mixin, and can be cast to this interface to get additional data added by Data Attributes. - * - * @author CleverNucleus - * - */ -public interface IEntityAttribute { - /** - * @return The attribute's minimum value; - */ - double minValue(); - - /** - * @return The attribute's maximum value; - */ - double maxValue(); - - /** - * @return The attribute's stacking behaviour. - */ - StackingBehaviour stackingBehaviour(); - - /** - * @return An immutable map of the function-parents attached to this attribute. - * @since 1.4.0 - */ - Map parents(); - - /** - * @return An immutable map of the function-children attached to this attribute. - * @since 1.4.0 - */ - Map children(); - - /** - * @return An immutable collection of the properties' keys attached to this attribute. - */ - Collection properties(); - - /** - * @param property A property key. - * @return true if this attribute has the input property key; false if not, or if the input is null. - */ - boolean hasProperty(final String property); - - /** - * @param property A property key. - * @return This attribute's property value assigned to the input property's key. If it does not exist or is null, returns 0.0F. - */ - String getProperty(final String property); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttributeInstance.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttributeInstance.java deleted file mode 100644 index e3cb2701..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IEntityAttributeInstance.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -import java.util.UUID; - -/** - * - * Access to an entity attribute instance. - * @author CleverNucleus - * - */ -public interface IEntityAttributeInstance { - - /** - * Changes the value of the input modifier (if it exists) and updates the instance and all children. - * @param uuid The uuid of the modifier. - * @param value The value to change the modifier to. - */ - void updateModifier(final UUID uuid, final double value); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IItemEntityAttributeModifiers.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IItemEntityAttributeModifiers.java deleted file mode 100644 index a22dbfdd..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/IItemEntityAttributeModifiers.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.item.ItemStack; - -/** - * Implement this in your Item class. - * - * @author CleverNucleus - * - */ -public interface IItemEntityAttributeModifiers { - - /** - * This method provides a mutable attribute modifier multimap so that items can have dynamically changing modifiers based on nbt. - * @param itemStack - * @param slot - * @return - */ - default Multimap getAttributeModifiers(ItemStack itemStack, EquipmentSlot slot) { - return HashMultimap.create(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingBehaviour.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingBehaviour.java deleted file mode 100644 index 311907ac..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingBehaviour.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -import java.util.function.Function; - -import net.minecraft.util.math.MathHelper; - -public enum StackingBehaviour { - FLAT((byte)0, x -> x, (k, k2, v, v2, m) -> k - v), - DIMINISHING((byte)1, x -> MathHelper.clamp(x, -1.0D, 1.0D), (k, k2, v, v2, m) -> ((1.0D - v2) * Math.pow(1.0D - m, (v - v2) / m)) - ((1.0D - k2) * Math.pow(1.0D - m, (k - k2) / m))); - - private final byte id; - private final Function clamp; - private final StackingFunction stack; - - private StackingBehaviour(final byte id, final Function clamp, final StackingFunction stack) { - this.id = id; - this.clamp = clamp; - this.stack = stack; - } - - public static StackingBehaviour of(final byte id) { - return switch(id) { - case 0 -> FLAT; - case 1 -> DIMINISHING; - default -> FLAT; - }; - } - - public byte id() { - return this.id; - } - - public double max(final double current, final double input) { - final double value = this.clamp.apply(input); - return Math.max(current, Math.abs(value)); - } - - public double stack(final double current, final double input) { - final double value = this.clamp.apply(input); - return current + Math.abs(value); - } - - public double result(final double k, final double k2, final double v, final double v2, final double increment) { - return this.stack.result(k, k2, v, v2, increment); - } - - @Override - public String toString() { - return String.valueOf(this.id); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingFunction.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingFunction.java deleted file mode 100644 index 5095bb78..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/attribute/StackingFunction.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.attribute; - -/** - * A functional interface used by stacking behaviour - essentially just a five input function. - * - * @author CleverNucleus - * - */ -@FunctionalInterface -public interface StackingFunction { - double result(final double k, final double k2, final double v, final double v2, final double i); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/AttributesReloadedEvent.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/AttributesReloadedEvent.java deleted file mode 100644 index 638eb4df..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/AttributesReloadedEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.event; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; - -/** - * Event that allows for logic reliant on datapack attributes to be ordered after they are loaded on both the server and client. - * - * @author CleverNucleus - * - */ -public final class AttributesReloadedEvent { - - /** - * Fired on Server upon joining world and on datapack reload through '/reload'. Fired on Client when selecting datapacks - * and after server has synced with client. - */ - public static final Event EVENT = EventFactory.createArrayBacked(Reloaded.class, callbacks -> () -> { - for(Reloaded callback : callbacks) { - callback.onCompletedReload(); - } - }); - - @FunctionalInterface - public interface Reloaded { - void onCompletedReload(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/EntityAttributeModifiedEvents.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/EntityAttributeModifiedEvents.java deleted file mode 100644 index 3f9e14b4..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/event/EntityAttributeModifiedEvents.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.event; - -import org.jetbrains.annotations.Nullable; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeModifier; - -/** - * Holds some attribute events. Both occur on both server and client. - * - * @author CleverNucleus - * - */ -public final class EntityAttributeModifiedEvents { - - /** - * Fired when the value of an attribute instance was modified, either by adding/removing a modifier or changing - * the value of the modifier, or by reloading the datapack and having the living entity renew its attribute container. - * Living entity and modifiers may or may not be null. - */ - public static final Event MODIFIED = EventFactory.createArrayBacked(Modified.class, callbacks -> (attribute, livingEntity, modifier, prevValue, isWasAdded) -> { - for(Modified callback : callbacks) { - callback.onModified(attribute, livingEntity, modifier, prevValue, isWasAdded); - } - }); - - /** - * Fired after the attribute instance value was calculated, but before it was output. This offers one last chance to alter the - * value in some way (for example round a decimal to an integer). - */ - public static final Event CLAMPED = EventFactory.createArrayBacked(Clamped.class, callbacks -> (attribute, value) -> { - double cache = value; - - for(Clamped callback : callbacks) { - cache = callback.onClamped(attribute, cache); - } - - return cache; - }); - - @FunctionalInterface - public interface Modified { - void onModified(final EntityAttribute attribute, final @Nullable LivingEntity livingEntity, final @Nullable EntityAttributeModifier modifier, final double prevValue, final boolean isWasAdded); - } - - @FunctionalInterface - public interface Clamped { - double onClamped(final EntityAttribute attribute, final double value); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemFields.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemFields.java deleted file mode 100644 index ff357b92..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemFields.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.item; - -import java.util.UUID; - -import net.minecraft.item.Item; - -/** - * Helper class that exposes {@link Item#ATTACK_DAMAGE_MODIFIER_ID} and {@link Item#ATTACK_SPEED_MODIFIER_ID}. - * - * @author CleverNucleus - * - */ -public final class ItemFields extends Item { - private ItemFields() { super(new Item.Settings()); } - - public static UUID attackDamageModifierID() { return ATTACK_DAMAGE_MODIFIER_ID; } - - public static UUID attackSpeedModifierID() { return ATTACK_SPEED_MODIFIER_ID; } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemHelper.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemHelper.java deleted file mode 100644 index ff353532..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/item/ItemHelper.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.item; - -import net.minecraft.item.ItemStack; -import net.minecraft.sound.SoundEvent; - -/** - * Helper interface to enable stack-specific operations. For example, using nbt - * data for stack-specific attributes. Can be - * used in tandem with FabricItem. - * - * @author CleverNucleus - * - */ -public interface ItemHelper { - - /** - * Fired on the constructor for itemstacks. All items are automatically an - * instance of ItemHelper, so checks should be - * made when using this to avoid running unnecessary logic on all itemstack - * creation events. Example usage includes - * attaching nbt data when an itemstack is first created. - * - * @param itemStack - * @param count - */ - default void onStackCreated(final ItemStack itemStack, final int count) { - } - - /** - * ItemStack dependent version of SwordItem#getAttackDamage and - * MiningToolItem#getAttackDamage. Default - * implementation returns the aforementioned. - * - * @param itemStack - * @return - */ - default float getAttackDamage(final ItemStack itemStack) { - return 0.0F; - } - - /** - * ItemStack dependent version of ArmorItem#getProtection. Default - * implementation returns aforementioned. - * - * @param itemStack - * @return - */ - default int getProtection(final ItemStack itemStack) { - return 0; - } - - /** - * ItemStack dependent version of ArmorItem#getToughness. Default implementation - * returns aforementioned. - * - * @param itemStack - * @return - */ - default float getToughness(final ItemStack itemStack) { - return 0.0F; - } - - /** - * ItemStack dependent version of Item#getEquipSound. Default implementation - * returns aforementioned. - * - * @param itemStack - * @return - */ - default SoundEvent getEquipSound(final ItemStack itemStack) { - return null; - } -} \ No newline at end of file diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/Maths.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/Maths.java deleted file mode 100644 index 85c45515..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/Maths.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.util; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Yes with an s because it's Mathematics not Mathematic. - */ -public final class Maths { - - /** - * Creates a static lookup map for the input enum#values implementation. - * @param The enum - * @param The key - * @param values Enum#values - * @param keyMapping - * @return - */ - public static Map enumLookupMap(V[] values, Function keyMapping) { - return Arrays.stream(values).collect(Collectors.toMap(keyMapping, e -> e)); - } - - /** - * Safe string to float. - * @param stringIn - * @return - */ - public static float parse(final String stringIn) { - float value; - - try { - value = Float.parseFloat(stringIn); - } catch(NumberFormatException | NullPointerException e) { - value = 0F; - } - - return value; - } - - /** - * A staircase function. - * @param x - * @param stretch - * @param steepness - * @param xOffset - * @param yOffset - * @return y - */ - public static double stairs(final double x, final double stretch, final double steepness, final double xOffset, final double yOffset) { - return steepness * stretch * (x - xOffset) - steepness * Math.sin(stretch * (x - xOffset)) + yOffset; - } - - - /** - * @param value - * @param min - * @param max - * @return Returns true if the value is less than max and greater than or equal to min. - * @since 1.4.0 - */ - public static boolean isWithinLimits(final double value, final double min, final double max) { - if(value < min || value >= max) return false; - return true; - } - - /** - * @param value - * @param arraySize This MUST be 8 or greater! No Checks are implemented for the sake of performance. - * @return Returns a byte array with the first 8 bytes storing the input double. - * @since 1.4.0 - */ - public static byte[] doubleToByteArray(final double value, final int arraySize) { - byte[] array = new byte[arraySize]; - ByteBuffer.wrap(array).putDouble(value); - return array; - } - - /** - * @param array This MUST be an array of size 8 or greater! No Checks are implemented for the sake of performance. - * @return Returns the double stored in the first 8 bytes of the array. - * @since 1.4.0 - */ - public static double byteArrayToDouble(final byte[] array) { - return ByteBuffer.wrap(array).getDouble(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/RandDistribution.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/RandDistribution.java deleted file mode 100644 index e0662d60..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/RandDistribution.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.util; - -import java.util.HashMap; -import java.util.Map; - -/** - * Specialised object that takes in a type and works out weighted distributions. - * @param Input type. - */ -public final class RandDistribution { - private Map distribution; - private T defualtValue; - private float distSum; - - /** - * Constructor. - * @param fallback Default value that is returned in case something fails. - */ - public RandDistribution(final T fallback) { - this.distribution = new HashMap<>(); - this.defualtValue = fallback; - } - - /** - * Adds to the internal inventory of the distributor. - * @param object Input object type. - * @param weight Input object type's weight. - */ - public void add(T object, float weight) { - if(this.distribution.get(object) != null) { - this.distSum -= this.distribution.get(object); - } - - this.distribution.put(object, weight); - this.distSum += weight; - } - - /** - * @return A randomly distributed and weighted result. - */ - public T getDistributedRandom() { - float rand = (float)Math.random(); - float dist = 1.0F / this.distSum; - float mean = 0.0F; - - for(T object : this.distribution.keySet()) { - mean += this.distribution.get(object); - - if(rand / dist <= mean) return object; - } - - return this.defualtValue; - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/VoidConsumer.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/VoidConsumer.java deleted file mode 100644 index e62be0ba..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/api/util/VoidConsumer.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.api.util; - -@FunctionalInterface -public interface VoidConsumer { void accept(); } diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeContainerHandler.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeContainerHandler.java deleted file mode 100644 index 9c8ff9c6..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeContainerHandler.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import com.github.clevernucleus.dataattributes_dc.impl.AttributeManager.Tuple; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeContainer; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableDefaultAttributeContainer; -import com.google.common.collect.ImmutableMap; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.DefaultAttributeContainer; -import net.minecraft.entity.attribute.DefaultAttributeRegistry; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; - -public final class AttributeContainerHandler { - private Map> implicitContainers; - private Map, DefaultAttributeContainer> explicitContainers; - - protected AttributeContainerHandler() { - this.implicitContainers = ImmutableMap.of(); - this.explicitContainers = ImmutableMap.of(); - } - - protected AttributeContainer getContainer(final EntityType entityType, - final LivingEntity livingEntity) { - DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); - ((MutableDefaultAttributeContainer) DefaultAttributeRegistry.get(entityType)).copy(builder); - - for (int i = 0; i < this.implicitContainers.size(); i++) { - Tuple tuple = this.implicitContainers.get(i); - Class type = tuple.livingEntity(); - - if (type.isInstance(livingEntity)) { - ((MutableDefaultAttributeContainer) tuple.value()).copy(builder); - } - } - - if (this.explicitContainers.containsKey(entityType)) { - ((MutableDefaultAttributeContainer) this.explicitContainers.get(entityType)).copy(builder); - } - - AttributeContainer container = new AttributeContainer(builder.build()); - ((MutableAttributeContainer) container).setLivingEntity(livingEntity); - - return container; - } - - @SuppressWarnings("unchecked") - protected void buildContainers(final Map entityTypeDataIn, - Map> entityTypeInstances) { - Collection entityTypes = Registries.ENTITY_TYPE.getIds().stream() - .filter(id -> DefaultAttributeRegistry.hasDefinitionFor(Registries.ENTITY_TYPE.get(id))) - .collect(Collectors.toSet()); - ImmutableMap.Builder> implicitContainers = ImmutableMap.builder(); - ImmutableMap.Builder, DefaultAttributeContainer> explicitContainers = ImmutableMap - .builder(); - Map> orderedEntityTypes = new HashMap<>(); - - for (Identifier identifier : entityTypeDataIn.keySet()) { - if (entityTypeInstances.containsKey(identifier)) { - Tuple tuple = entityTypeInstances.get(identifier); - orderedEntityTypes.put(tuple.value(), new Tuple(tuple.livingEntity(), identifier)); - } - if (!entityTypes.contains(identifier)) - continue; - EntityType entityType = (EntityType) Registries.ENTITY_TYPE - .get(identifier); - DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); - EntityTypeData entityTypeData = entityTypeDataIn.get(identifier); - entityTypeData.build(builder, DefaultAttributeRegistry.get(entityType)); - explicitContainers.put(entityType, builder.build()); - } - - final int size = orderedEntityTypes.size(); - final int max = orderedEntityTypes.keySet().stream().mapToInt(Integer::intValue).max().orElse(0); - - for (Map.Entry> entry : orderedEntityTypes.entrySet()) { - Tuple tuple = entry.getValue(); - Identifier identifier = tuple.value(); - final int hierarchy = entry.getKey(); - final int index = Math.round((float) size * (float) hierarchy / (float) max) - 1; - DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); - EntityTypeData entityTypeData = entityTypeDataIn.get(identifier); - entityTypeData.build(builder, null); - implicitContainers.put(index, new Tuple(tuple.livingEntity(), builder.build())); - } - - this.implicitContainers = implicitContainers.build(); - this.explicitContainers = explicitContainers.build(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeManager.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeManager.java deleted file mode 100644 index ff2b9d54..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/AttributeManager.java +++ /dev/null @@ -1,426 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import org.slf4j.Logger; - -import com.github.clevernucleus.dataattributes_dc.api.DataAttributesAPI; -import com.github.clevernucleus.dataattributes_dc.api.event.AttributesReloadedEvent; -import com.github.clevernucleus.dataattributes_dc.json.AttributeFunctionJson; -import com.github.clevernucleus.dataattributes_dc.json.AttributeOverrideJson; -import com.github.clevernucleus.dataattributes_dc.json.EntityTypesJson; -import com.github.clevernucleus.dataattributes_dc.json.FunctionsJson; -import com.github.clevernucleus.dataattributes_dc.json.PropertiesJson; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableEntityAttribute; -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.mojang.logging.LogUtils; - -import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.mob.HostileEntity; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.entity.mob.PathAwareEntity; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.PassiveEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.profiler.Profiler; -import net.minecraft.registry.Registries; - -public final class AttributeManager implements SimpleResourceReloadListener { - private static final Gson GSON = (new GsonBuilder()).excludeFieldsWithoutExposeAnnotation().create(); - private static final int PATH_SUFFIX_LENGTH = ".json".length(); - private static final Logger LOGGER = LogUtils.getLogger(); - private static final String DIRECTORY = "attributes"; - private static final Identifier ID = new Identifier(DataAttributesAPI.MODID, DIRECTORY); - private static final Map> ENTITY_TYPE_INSTANCES = new HashMap<>(); - - private Map entityAttributeData = ImmutableMap.of(); - private Map entityTypeData = ImmutableMap.of(); - private AttributeContainerHandler handler = new AttributeContainerHandler(); - private int updateFlag = 0; - - protected static final record Tuple(Class livingEntity, T value) { - } - - protected static final record Wrapper(Map entityAttributeData, - Map entityTypeData) { - } - - public AttributeManager() { - } - - private static Map formatFunctions( - Map functionsIn) { - Map functions = new HashMap(); - - for (String key : functionsIn.keySet()) { - AttributeFunctionJson value = functionsIn.get(key); - - functions.put(new Identifier(key), value); - } - - return functions; - } - - private static EntityAttribute getOrCreate(final Identifier identifier, EntityAttribute attributeIn) { - EntityAttribute attribute = Registries.ATTRIBUTE.get(identifier); - - if (attribute == null) { - attribute = MutableRegistryImpl.register(Registries.ATTRIBUTE, identifier, attributeIn); - } - - return attribute; - } - - private static void loadOverrides(ResourceManager manager, - Map entityAttributeData) { - Map cache = new HashMap(); - String location = DIRECTORY + "/overrides"; - int length = location.length() + 1; - - for (Map.Entry entry : manager - .findResources(location, id -> id.getPath().endsWith(".json")).entrySet()) { - Identifier resource = entry.getKey(); - String path = resource.getPath(); - Identifier identifier = new Identifier(resource.getNamespace(), - path.substring(length, path.length() - PATH_SUFFIX_LENGTH)); - - try { - BufferedReader reader = entry.getValue().getReader(); - - try { - AttributeOverrideJson json = JsonHelper.deserialize(GSON, (Reader) reader, - AttributeOverrideJson.class); - - if (json != null) { - AttributeOverrideJson object = cache.put(identifier, json); - - if (object == null) - continue; - throw new IllegalStateException("Duplicate data file ignored with ID " + identifier); - } - - LOGGER.error("Couldn't load data file {} from {} as it's null or empty", (Object) identifier, - (Object) resource); - } finally { - if (reader == null) - continue; - ((Reader) reader).close(); - } - } catch (IOException | IllegalArgumentException exception) { - LOGGER.error("Couldn't parse data file {} from {}", identifier, resource, exception); - } - } - - cache.forEach((key, value) -> entityAttributeData.put(key, new EntityAttributeData(value))); - } - - private static void loadFunctions(ResourceManager manager, - Map entityAttributeData) { - Map cache = new HashMap(); - int length = DIRECTORY.length() + 1; - - for (Map.Entry entry : manager - .findResources(DIRECTORY, id -> id.getPath().endsWith("functions.json")).entrySet()) { - Identifier resource = entry.getKey(); - String path = resource.getPath(); - Identifier identifier = new Identifier(resource.getNamespace(), - path.substring(length, path.length() - PATH_SUFFIX_LENGTH)); - - try { - BufferedReader reader = entry.getValue().getReader(); - - try { - FunctionsJson json = JsonHelper.deserialize(GSON, (Reader) reader, FunctionsJson.class); - - if (json != null) { - FunctionsJson object = cache.put(identifier, json); - - if (object == null) - continue; - throw new IllegalStateException("Duplicate data file ignored with ID " + identifier); - } - - LOGGER.error("Couldn't load data file {} from {} as it's null or empty", (Object) identifier, - (Object) resource); - } finally { - if (reader != null) - ((Reader) reader).close(); - } - } catch (IOException | IllegalArgumentException exception) { - LOGGER.error("Couldn't parse data file {} from {}", identifier, resource, exception); - } - } - - Map> functions = new HashMap>(); - cache.values().forEach(json -> json.merge(functions)); - - for (String key : functions.keySet()) { - Identifier identifier = new Identifier(key); - EntityAttributeData data = entityAttributeData.getOrDefault(identifier, new EntityAttributeData()); - data.putFunctions(formatFunctions(functions.get(key))); - entityAttributeData.put(identifier, data); - } - } - - private static void loadProperties(ResourceManager manager, - Map entityAttributeData) { - Map cache = new HashMap(); - int length = DIRECTORY.length() + 1; - - for (Map.Entry entry : manager - .findResources(DIRECTORY, id -> id.getPath().endsWith("properties.json")).entrySet()) { - Identifier resource = entry.getKey(); - String path = resource.getPath(); - Identifier identifier = new Identifier(resource.getNamespace(), - path.substring(length, path.length() - PATH_SUFFIX_LENGTH)); - - try { - BufferedReader reader = entry.getValue().getReader(); - - try { - PropertiesJson json = JsonHelper.deserialize(GSON, (Reader) reader, PropertiesJson.class); - - if (json != null) { - PropertiesJson object = cache.put(identifier, json); - - if (object == null) - continue; - throw new IllegalStateException("Duplicate data file ignored with ID " + identifier); - } - - LOGGER.error("Couldn't load data file {} from {} as it's null or empty", (Object) identifier, - (Object) resource); - } finally { - if (reader == null) - continue; - ((Reader) reader).close(); - } - } catch (IOException | IllegalArgumentException exception) { - LOGGER.error("Couldn't parse data file {} from {}", identifier, resource, exception); - } - } - - Map> properties = new HashMap>(); - cache.values().forEach(json -> json.merge(properties)); - - for (String key : properties.keySet()) { - Identifier identifier = new Identifier(key); - EntityAttributeData data = entityAttributeData.getOrDefault(identifier, new EntityAttributeData()); - data.putProperties(properties.get(key)); - entityAttributeData.put(identifier, data); - } - } - - private static void loadEntityTypes(ResourceManager manager, Map entityTypeData) { - Map cache = new HashMap(); - int length = DIRECTORY.length() + 1; - - for (Map.Entry entry : manager - .findResources(DIRECTORY, id -> id.getPath().endsWith("entity_types.json")).entrySet()) { - Identifier resource = entry.getKey(); - String path = resource.getPath(); - Identifier identifier = new Identifier(resource.getNamespace(), - path.substring(length, path.length() - PATH_SUFFIX_LENGTH)); - - try { - BufferedReader reader = entry.getValue().getReader(); - - try { - EntityTypesJson json = JsonHelper.deserialize(GSON, (Reader) reader, EntityTypesJson.class); - - if (json != null) { - EntityTypesJson object = cache.put(identifier, json); - - if (object == null) - continue; - throw new IllegalStateException("Duplicate data file ignored with ID " + identifier); - } - - LOGGER.error("Couldn't load data file {} from {} as it's null or empty", (Object) identifier, - (Object) resource); - } finally { - if (reader == null) - continue; - ((Reader) reader).close(); - } - } catch (IOException | IllegalArgumentException exception) { - LOGGER.error("Couldn't parse data file {} from {}", identifier, resource, exception); - } - } - - Map> entityTypes = new HashMap>(); - cache.values().forEach(json -> json.merge(entityTypes)); - - for (String key : entityTypes.keySet()) { - Identifier identifier = new Identifier(key); - EntityTypeData data = new EntityTypeData(entityTypes.get(key)); - entityTypeData.put(identifier, data); - } - } - - public void toNbt(NbtCompound tag) { - NbtCompound entityAttributeNbt = new NbtCompound(); - NbtCompound entityTypeNbt = new NbtCompound(); - - this.entityAttributeData.forEach((key, val) -> { - NbtCompound entry = new NbtCompound(); - val.writeToNbt(entry); - entityAttributeNbt.put(key.toString(), entry); - }); - - this.entityTypeData.forEach((key, val) -> { - NbtCompound entry = new NbtCompound(); - val.writeToNbt(entry); - entityTypeNbt.put(key.toString(), entry); - }); - - tag.put("Attributes", entityAttributeNbt); - tag.put("EntityTypes", entityTypeNbt); - tag.putInt("UpdateFlag", this.updateFlag); - } - - public void fromNbt(NbtCompound tag) { - if (tag.contains("Attributes")) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - NbtCompound nbtCompound = tag.getCompound("Attributes"); - nbtCompound.getKeys().forEach(key -> { - NbtCompound entry = nbtCompound.getCompound(key); - EntityAttributeData entityAttributeData = new EntityAttributeData(); - entityAttributeData.readFromNbt(entry); - builder.put(new Identifier(key), entityAttributeData); - }); - this.entityAttributeData = builder.build(); - } - - if (tag.contains("EntityTypes")) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - NbtCompound nbtCompound = tag.getCompound("EntityTypes"); - nbtCompound.getKeys().forEach(key -> { - NbtCompound entry = nbtCompound.getCompound(key); - EntityTypeData entityTypeData = new EntityTypeData(); - entityTypeData.readFromNbt(entry); - builder.put(new Identifier(key), entityTypeData); - }); - this.entityTypeData = builder.build(); - } - this.updateFlag = tag.getInt("UpdateFlag"); - } - - public void nextUpdateFlag() { - this.updateFlag++; - } - - public int getUpdateFlag() { - return this.updateFlag; - } - - public AttributeContainer getContainer(final EntityType entityType, - final LivingEntity livingEntity) { - return this.handler.getContainer(entityType, livingEntity); - } - - public void apply() { - MutableRegistryImpl.unregister(Registries.ATTRIBUTE); - - for (Identifier identifier : Registries.ATTRIBUTE.getIds()) { - EntityAttribute entityAttribute = Registries.ATTRIBUTE.get(identifier); - - if (entityAttribute == null) - continue; - - ((MutableEntityAttribute) entityAttribute).clear(); - } - - for (Identifier identifier : this.entityAttributeData.keySet()) { - EntityAttributeData entityAttributeData = this.entityAttributeData.get(identifier); - entityAttributeData.override(identifier, AttributeManager::getOrCreate); - } - - for (Identifier identifier : this.entityAttributeData.keySet()) { - EntityAttribute entityAttribute = Registries.ATTRIBUTE.get(identifier); - - if (entityAttribute == null) - continue; - - EntityAttributeData entityAttributeData = this.entityAttributeData.get(identifier); - entityAttributeData.copy(entityAttribute); - } - - this.handler.buildContainers(this.entityTypeData, ENTITY_TYPE_INSTANCES); - - AttributesReloadedEvent.EVENT.invoker().onCompletedReload(); - } - - @Override - public CompletableFuture load(ResourceManager manager, Profiler profiler, - Executor executor) { - return CompletableFuture.supplyAsync(() -> { - Map entityAttributeData = new HashMap(); - loadOverrides(manager, entityAttributeData); - loadFunctions(manager, entityAttributeData); - loadProperties(manager, entityAttributeData); - - Map entityTypeData = new HashMap(); - loadEntityTypes(manager, entityTypeData); - - return new AttributeManager.Wrapper(entityAttributeData, entityTypeData); - }, executor); - } - - @Override - public CompletableFuture apply(AttributeManager.Wrapper data, ResourceManager manager, Profiler profiler, - Executor executor) { - return CompletableFuture.runAsync(() -> { - ImmutableMap.Builder entityAttributeData = ImmutableMap.builder(); - data.entityAttributeData.forEach(entityAttributeData::put); - this.entityAttributeData = entityAttributeData.build(); - - ImmutableMap.Builder entityTypeData = ImmutableMap.builder(); - data.entityTypeData.forEach(entityTypeData::put); - this.entityTypeData = entityTypeData.build(); - - this.apply(); - }, executor); - } - - @Override - public Identifier getFabricId() { - return ID; - } - - static { - ENTITY_TYPE_INSTANCES.put( - new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_LIVING_ENTITY), - new Tuple(LivingEntity.class, 0)); - ENTITY_TYPE_INSTANCES.put(new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_MOB_ENTITY), - new Tuple(MobEntity.class, 1)); - ENTITY_TYPE_INSTANCES.put( - new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_PATH_AWARE_ENTITY), - new Tuple(PathAwareEntity.class, 2)); - ENTITY_TYPE_INSTANCES.put( - new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_HOSTILE_ENTITY), - new Tuple(HostileEntity.class, 3)); - ENTITY_TYPE_INSTANCES.put( - new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_PASSIVE_ENTITY), - new Tuple(PassiveEntity.class, 4)); - ENTITY_TYPE_INSTANCES.put( - new Identifier(DataAttributesAPI.MODID, DataAttributesAPI.ENTITY_INSTANCE_ANIMAL_ENTITY), - new Tuple(AnimalEntity.class, 5)); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityAttributeData.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityAttributeData.java deleted file mode 100644 index 67c2ae68..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityAttributeData.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.BiFunction; - -import com.github.clevernucleus.dataattributes_dc.json.AttributeFunctionJson; -import com.github.clevernucleus.dataattributes_dc.json.AttributeOverrideJson; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableEntityAttribute; - -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; - -public final class EntityAttributeData implements NbtIO { - private AttributeOverrideJson attribute; - private final Map functions; - private final Map properties; - - public EntityAttributeData() { - this.functions = new HashMap(); - this.properties = new HashMap(); - } - - public EntityAttributeData(final AttributeOverrideJson attribute) { - this(); - this.attribute = attribute; - } - - public void override(final Identifier identifier, - BiFunction function) { - if (this.attribute == null) - return; - EntityAttribute entityAttribute = function.apply(identifier, this.attribute.create()); - this.attribute.override((MutableEntityAttribute) entityAttribute); - } - - public void copy(EntityAttribute entityAttributeIn) { - MutableEntityAttribute mutableEntityAttribute = (MutableEntityAttribute) entityAttributeIn; - mutableEntityAttribute.properties(this.properties); - - for (Identifier identifier : this.functions.keySet()) { - EntityAttribute entityAttribute = Registries.ATTRIBUTE.get(identifier); - - if (entityAttribute == null) - continue; - - AttributeFunctionJson function = this.functions.get(identifier); - mutableEntityAttribute.addChild((MutableEntityAttribute) entityAttribute, function); - } - } - - public void putFunctions(Map functions) { - this.functions.putAll(functions); - } - - public void putProperties(Map properties) { - this.properties.putAll(properties); - } - - @Override - public void readFromNbt(NbtCompound tag) { - if (tag.contains("Attribute")) { - this.attribute = new AttributeOverrideJson(); - this.attribute.readFromNbt(tag.getCompound("Attribute")); - } - - NbtCompound functions = tag.getCompound("Functions"); - functions.getKeys().forEach(key -> this.functions.put(new Identifier(key), - AttributeFunctionJson.read(functions.getByteArray(key)))); - - NbtCompound properties = tag.getCompound("Properties"); - properties.getKeys().forEach(key -> this.properties.put(key, properties.getString(key))); - } - - @Override - public void writeToNbt(NbtCompound tag) { - NbtCompound attribute = new NbtCompound(); - - if (this.attribute != null) { - this.attribute.writeToNbt(attribute); - tag.put("Attribute", attribute); - } - - NbtCompound functions = new NbtCompound(); - this.functions.forEach((key, value) -> functions.putByteArray(key.toString(), value.write())); - tag.put("Functions", functions); - - NbtCompound properties = new NbtCompound(); - this.properties.forEach((key, value) -> properties.putString(key.toString(), value)); - tag.put("Properties", properties); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityTypeData.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityTypeData.java deleted file mode 100644 index 2c261aa7..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/EntityTypeData.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import java.util.HashMap; -import java.util.Map; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableDefaultAttributeContainer; - -import net.minecraft.entity.attribute.DefaultAttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.Registries; -import net.minecraft.util.Identifier; - -public final class EntityTypeData implements NbtIO { - public final Map data; - - public EntityTypeData() { - this.data = new HashMap(); - } - - public EntityTypeData(final Map data) { - this(); - data.forEach((key, value) -> this.data.put(new Identifier(key), value)); - } - - public void build(DefaultAttributeContainer.Builder builder, DefaultAttributeContainer container) { - if (container != null) { - ((MutableDefaultAttributeContainer) container).copy(builder); - } - - for (Identifier key : this.data.keySet()) { - EntityAttribute entityAttribute = Registries.ATTRIBUTE.get(key); - - if (entityAttribute == null) - continue; - - double value = this.data.get(key); - double clamp = entityAttribute.clamp(value); - builder.add(entityAttribute, clamp); - } - } - - @Override - public void readFromNbt(NbtCompound tag) { - tag.getKeys().forEach(key -> this.data.put(new Identifier(key), tag.getDouble(key))); - } - - @Override - public void writeToNbt(NbtCompound tag) { - this.data.forEach((key, value) -> tag.putDouble(key.toString(), value)); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/MutableRegistryImpl.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/MutableRegistryImpl.java deleted file mode 100644 index 6869ddaa..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/MutableRegistryImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableSimpleRegistry; - -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registry; - -public final class MutableRegistryImpl { - - @SuppressWarnings("unchecked") - public static T register(Registry registry, Identifier id, T value) { - ((MutableSimpleRegistry) registry).cacheId(id); - return Registry.register(registry, id, value); - } - - @SuppressWarnings("unchecked") - public static void unregister(Registry registry) { - ((MutableSimpleRegistry) registry).removeCachedIds(registry); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/NbtIO.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/NbtIO.java deleted file mode 100644 index 1ab6cef5..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/impl/NbtIO.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.impl; - -import net.minecraft.nbt.NbtCompound; - -public interface NbtIO { - void readFromNbt(NbtCompound tag); - void writeToNbt(NbtCompound tag); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeFunctionJson.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeFunctionJson.java deleted file mode 100644 index e5a3d94d..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeFunctionJson.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.json; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.FunctionBehaviour; -import com.github.clevernucleus.dataattributes_dc.api.attribute.IAttributeFunction; -import com.github.clevernucleus.dataattributes_dc.api.util.Maths; -import com.google.gson.annotations.Expose; - -public final class AttributeFunctionJson implements IAttributeFunction { - @Expose private FunctionBehaviour behaviour; - @Expose private double value; - - private AttributeFunctionJson() {} - - public static AttributeFunctionJson read(byte[] byteArray) { - AttributeFunctionJson functionTypeJson = new AttributeFunctionJson(); - functionTypeJson.behaviour = FunctionBehaviour.of(byteArray[8]); - functionTypeJson.value = Maths.byteArrayToDouble(byteArray); - return functionTypeJson; - } - - public byte[] write() { - byte[] byteArray = Maths.doubleToByteArray(this.value, 9); - byteArray[8] = this.behaviour.id(); - return byteArray; - } - - @Override - public FunctionBehaviour behaviour() { - return this.behaviour; - } - - @Override - public double value() { - return this.value; - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeOverrideJson.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeOverrideJson.java deleted file mode 100644 index b78e0f56..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/AttributeOverrideJson.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.json; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.StackingBehaviour; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableEntityAttribute; -import com.google.gson.annotations.Expose; - -import net.minecraft.entity.attribute.ClampedEntityAttribute; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.nbt.NbtCompound; - -public final class AttributeOverrideJson { - @Expose private double fallbackValue; - @Expose private double minValue; - @Expose private double maxValue; - @Expose private double incrementValue; - @Expose private String translationKey; - @Expose private StackingBehaviour stackingBehaviour; - - public AttributeOverrideJson() {} - - public EntityAttribute create() { - return new ClampedEntityAttribute(this.translationKey, this.fallbackValue, this.minValue, this.maxValue); - } - - public void override(final MutableEntityAttribute entityAttribute) { - entityAttribute.override(this.translationKey, this.minValue, this.maxValue, this.fallbackValue, this.incrementValue, this.stackingBehaviour); - } - - public void readFromNbt(NbtCompound tag) { - this.fallbackValue = tag.getDouble("FallbackValue"); - this.minValue = tag.getDouble("MinValue"); - this.maxValue = tag.getDouble("MaxValue"); - this.incrementValue = tag.getDouble("IncrementValue"); - this.translationKey = tag.getString("TranslationKey"); - byte stackingBehaviour = tag.getByte("StackingBehaviour"); - this.stackingBehaviour = StackingBehaviour.of(stackingBehaviour); - } - - public void writeToNbt(NbtCompound tag) { - tag.putDouble("FallbackValue", this.fallbackValue); - tag.putDouble("MinValue", this.minValue); - tag.putDouble("MaxValue", this.maxValue); - tag.putDouble("IncrementValue", this.incrementValue); - tag.putString("TranslationKey", this.translationKey); - tag.putByte("StackingBehaviour", this.stackingBehaviour.id()); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/EntityTypesJson.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/json/EntityTypesJson.java deleted file mode 100644 index ecb65d65..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/EntityTypesJson.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.json; - -import java.util.HashMap; -import java.util.Map; - -import com.google.gson.annotations.Expose; - -public final class EntityTypesJson { - @Expose private HashMap> values; - - private EntityTypesJson() {} - - public void merge(Map> entityTypesIn) { - for(String key : this.values.keySet()) { - Map entityTypes = entityTypesIn.getOrDefault(key, new HashMap()); - this.values.get(key).forEach(entityTypes::put); - entityTypesIn.put(key, entityTypes); - } - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/FunctionsJson.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/json/FunctionsJson.java deleted file mode 100644 index ae768e98..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/FunctionsJson.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.json; - -import java.util.HashMap; -import java.util.Map; - -import com.google.gson.annotations.Expose; - -public final class FunctionsJson { - @Expose private HashMap> values; - - private FunctionsJson() {} - - public void merge(Map> functionsIn) { - for(String key : this.values.keySet()) { - Map functions = functionsIn.getOrDefault(key, new HashMap()); - this.values.get(key).forEach(functions::put); - functionsIn.put(key, functions); - } - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/PropertiesJson.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/json/PropertiesJson.java deleted file mode 100644 index 3ab35805..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/json/PropertiesJson.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.json; - -import java.util.HashMap; -import java.util.Map; - -import com.google.gson.annotations.Expose; - -public final class PropertiesJson { - @Expose private HashMap> values; - - private PropertiesJson() {} - - public void merge(Map> propertiesIn) { - for(String key : this.values.keySet()) { - Map properties = propertiesIn.getOrDefault(key, new HashMap()); - this.values.get(key).forEach(properties::put); - propertiesIn.put(key, properties); - } - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/AttributeContainerMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/AttributeContainerMixin.java deleted file mode 100644 index 770cf45b..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/AttributeContainerMixin.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.api.event.EntityAttributeModifiedEvents; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeContainer; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeInstance; -import com.google.common.collect.Multimap; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.DefaultAttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; - -@Mixin(AttributeContainer.class) -abstract class AttributeContainerMixin implements MutableAttributeContainer { - - @Unique - private Map data_custom = new HashMap(); - - @Unique - private Map data_tracked = new HashMap(); - - @Unique - private LivingEntity data_livingEntity; - - @Final - @Shadow - private DefaultAttributeContainer fallback; - - @Shadow - private void updateTrackedStatus(EntityAttributeInstance instance) { - } - - // Injection to update the tracked status of the custom attributes - @Inject(method = "updateTrackedStatus", at = @At("HEAD"), cancellable = true) - private void data_updateTrackedStatus(EntityAttributeInstance instance, CallbackInfo ci) { - Identifier identifier = ((MutableAttributeInstance) instance).getId(); - - if (identifier != null) { - this.data_tracked.put(identifier, instance); - } - - ci.cancel(); - } - - // Injection to get the tracked custom attributes - @Inject(method = "getTracked", at = @At("Head"), cancellable = true) - private void data_getTracked(CallbackInfoReturnable> cir) { - Set tracked = this.data_tracked.values().stream().collect(Collectors.toSet()); - cir.setReturnValue(tracked); - } - - // Redirecting the getAttributesToSend method to use custom attributes - @Redirect(method = "getAttributesToSend", at = @At(value = "INVOKE", target = "Ljava/util/Map;values()Ljava/util/Collection;")) - private Collection data_getAttributesToSend(Map instances) { - return this.data_custom.values(); - } - - // Injection to get or create a custom attribute instance - @Inject(method = "getCustomInstance", at = @At("HEAD"), cancellable = true) - private void data_getCustomInstance(EntityAttribute attribute2, - CallbackInfoReturnable ci) { - Identifier identifier = Registries.ATTRIBUTE.getId(attribute2); - - if (identifier != null) { - EntityAttributeInstance entityAttributeInstance = this.data_custom - .computeIfAbsent(identifier, - id -> this.fallback.createOverride(this::updateTrackedStatus, attribute2)); - - if (entityAttributeInstance != null) { - MutableAttributeInstance mutable = (MutableAttributeInstance) entityAttributeInstance; - mutable.setContainerCallback((AttributeContainer) (Object) this); - - if (mutable.getId() == null) { - mutable.updateId(identifier); - } - } - - ci.setReturnValue(entityAttributeInstance); - } else { - ci.setReturnValue((EntityAttributeInstance) null); - } - } - - // Redirecting methods to use custom attributes - @Redirect(method = "hasAttribute", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_hasAttribute(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_custom.get(identifier); - } - - @Redirect(method = "hasModifierForAttribute", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_hasModifierForAttribute(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_custom.get(identifier); - } - - @Redirect(method = "getValue", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_getValue(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_custom.get(identifier); - } - - @Redirect(method = "getBaseValue", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_getBaseValue(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_custom.get(identifier); - } - - @Redirect(method = "getModifierValue", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_getModifierValue(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_custom.get(identifier); - } - - // Injection to remove custom modifiers - @Inject(method = "removeModifiers", at = @At("HEAD"), cancellable = true) - private void data_removeModifiers(Multimap attributeModifiers, - CallbackInfo ci) { - attributeModifiers.asMap().forEach((attribute, collection) -> { - Identifier identifier = Registries.ATTRIBUTE.getId(attribute); - EntityAttributeInstance entityAttributeInstance = this.data_custom.get(identifier); - - if (entityAttributeInstance != null) { - collection.forEach(entityAttributeInstance::removeModifier); - } - }); - - ci.cancel(); - } - - // Injection to set custom attributes from another container - @Inject(method = "setFrom", at = @At("HEAD"), cancellable = true) - private void data_setFrom(AttributeContainer other, CallbackInfo ci) { - AttributeContainer container = (AttributeContainer) (Object) this; - - ((MutableAttributeContainer) other).custom().values().forEach(attributeInstance -> { - EntityAttribute entityAttribute = attributeInstance.getAttribute(); - EntityAttributeInstance entityAttributeInstance = container.getCustomInstance(entityAttribute); - - if (entityAttributeInstance != null) { - entityAttributeInstance.setFrom(attributeInstance); - final double value = entityAttributeInstance.getValue(); - EntityAttributeModifiedEvents.MODIFIED.invoker().onModified(entityAttribute, this.data_livingEntity, - null, - value, false); - } - }); - - ci.cancel(); - } - - // Redirecting to use custom attributes for serialization - @Redirect(method = "toNbt", at = @At(value = "INVOKE", target = "Ljava/util/Map;values()Ljava/util/Collection;")) - private Collection data_toNbt(Map instances) { - return this.data_custom.values(); - } - - @Override - public Map custom() { - return this.data_custom; - } - - @Override - public LivingEntity getLivingEntity() { - return this.data_livingEntity; - } - - @Override - public void setLivingEntity(final LivingEntity livingEntity) { - this.data_livingEntity = livingEntity; - } - - @Override - public void refresh() { - for (EntityAttributeInstance instance : this.data_custom.values()) { - ((MutableAttributeInstance) instance).refresh(); - } - } - - @Override - public void clearTracked() { - this.data_tracked.clear(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ClampedEntityAttributeMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ClampedEntityAttributeMixin.java deleted file mode 100644 index fb7eab42..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ClampedEntityAttributeMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import org.spongepowered.asm.mixin.Final; -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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.StackingBehaviour; - -import net.minecraft.entity.attribute.ClampedEntityAttribute; - -// Mixing in additional behavior to ClampedEntityAttribute -@Mixin(ClampedEntityAttribute.class) -abstract class ClampedEntityAttributeMixin extends EntityAttributeMixin { - - @Final - @Shadow - private double minValue; // The minimum value of the clamped attribute - - @Final - @Shadow - private double maxValue; // The maximum value of the clamped attribute - - // Injecting into the constructor to customize attribute behavior - @Inject(method = "", at = @At("TAIL")) - private void data_init(String translationKey, double fallback, double min, double max, CallbackInfo ci) { - // Overriding the attribute with custom settings - this.override(translationKey, min, max, fallback, 0.0D, StackingBehaviour.FLAT); - } - - // Injecting into the getMinValue method to return custom min value - @Inject(method = "getMinValue", at = @At("HEAD"), cancellable = true) - private void data_getMinValue(CallbackInfoReturnable ci) { - ci.setReturnValue(this.minValue()); // Returning the custom min value - } - - // Injecting into the getMaxValue method to return custom max value - @Inject(method = "getMaxValue", at = @At("HEAD"), cancellable = true) - private void data_getMaxValue(CallbackInfoReturnable ci) { - ci.setReturnValue(this.maxValue()); // Returning the custom max value - } - - // Injecting into the clamp method to customize attribute clamping - @Inject(method = "clamp", at = @At("HEAD"), cancellable = true) - private void data_clamp(double value, CallbackInfoReturnable ci) { - ci.setReturnValue(this.data_clamped(value)); // Customizing clamping behavior - } - - // Overriding the clear method to also clear custom values - @Override - public void clear() { - super.clear(); // Calling the superclass clear method - this.data_minValue = this.minValue; // Resetting custom min value - this.data_maxValue = this.maxValue; // Resetting custom max value - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/DefaultAttributeContainerMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/DefaultAttributeContainerMixin.java deleted file mode 100644 index d622d3b2..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/DefaultAttributeContainerMixin.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.HashMap; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableDefaultAttributeContainer; - -import net.minecraft.entity.attribute.DefaultAttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; - -@Mixin(DefaultAttributeContainer.class) -abstract class DefaultAttributeContainerMixin implements MutableDefaultAttributeContainer { - - @Unique - private Map data_instances; // Custom map for attribute instances - - @Final - @Shadow - private Map instances; // Original map of attribute instances - - // Injecting into the constructor to initialize the custom map - @Inject(method = "", at = @At("TAIL")) - private void data_init(Map instances, CallbackInfo ci) { - this.data_instances = new HashMap(); - - // Populating the custom map with identifiers and instances - instances.forEach((attribute, instance) -> { - Identifier key = Registries.ATTRIBUTE.getId(attribute); - - if (key != null) { - this.data_instances.put(key, instance); - } - }); - } - - // Redirecting the 'require' method to use the custom map - @Redirect(method = "require", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_require(Map instances, Object attribute) { - EntityAttribute entityAttribute = (EntityAttribute) attribute; - Identifier identifier = Registries.ATTRIBUTE.getId(entityAttribute); - return this.data_instances.getOrDefault(identifier, this.instances.get(attribute)); - } - - // Redirecting the 'createOverride' method to use the custom map - @Redirect(method = "createOverride", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_createOverride(Map instances, Object attribute) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) attribute); - return this.data_instances.getOrDefault(identifier, this.instances.get(attribute)); - } - - // Injecting into the 'has' method to check for the existence of attributes in - // the custom map - @Inject(method = "has", at = @At("HEAD"), cancellable = true) - private void data_has(EntityAttribute type, CallbackInfoReturnable ci) { - Identifier identifier = Registries.ATTRIBUTE.getId(type); - ci.setReturnValue(this.data_instances.containsKey(identifier) || this.instances.containsKey(type)); - } - - // Redirecting the 'hasModifier' method to use the custom map - @Redirect(method = "hasModifier", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) - private Object data_hasModifier(Map instances, Object type) { - Identifier identifier = Registries.ATTRIBUTE.getId((EntityAttribute) type); - return this.data_instances.getOrDefault(identifier, this.instances.get(type)); - } - - // Implementing the 'copy' method to copy attributes from the original map to - // the builder - @Override - public void copy(DefaultAttributeContainer.Builder builder) { - for (EntityAttribute entityAttribute : this.instances.keySet()) { - EntityAttributeInstance entityAttributeInstance = this.instances.get(entityAttribute); - double value = entityAttributeInstance.getBaseValue(); - builder.add(entityAttribute, value); - } - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeInstanceMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeInstanceMixin.java deleted file mode 100644 index c59bc94e..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeInstanceMixin.java +++ /dev/null @@ -1,293 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.function.Consumer; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.FunctionBehaviour; -import com.github.clevernucleus.dataattributes_dc.api.attribute.IEntityAttribute; -import com.github.clevernucleus.dataattributes_dc.api.attribute.IEntityAttributeInstance; -import com.github.clevernucleus.dataattributes_dc.api.attribute.StackingBehaviour; -import com.github.clevernucleus.dataattributes_dc.api.event.EntityAttributeModifiedEvents; -import com.github.clevernucleus.dataattributes_dc.api.util.VoidConsumer; -import com.github.clevernucleus.dataattributes_dc.json.AttributeFunctionJson; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeContainer; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeInstance; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeModifier; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableEntityAttribute; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; - -@Mixin(EntityAttributeInstance.class) -abstract class EntityAttributeInstanceMixin implements MutableAttributeInstance, IEntityAttributeInstance { - - @Unique - private AttributeContainer data_containerCallback; - - @Unique - private Identifier data_identifier; - - @Final - @Shadow - private EntityAttribute type; - - @Final - @Shadow - private Map idToModifiers; - - @Final - @Shadow - private Set persistentModifiers; - - @Shadow - private double baseValue; - - @Shadow - private Collection getModifiersByOperation(EntityAttributeModifier.Operation operation) { - return Collections.emptySet(); - } - - @Shadow - protected void onUpdate() { - } - - @Inject(method = "", at = @At("TAIL")) - private void data_init(EntityAttribute type, Consumer updateCallback, CallbackInfo ci) { - this.data_identifier = Registries.ATTRIBUTE.getId(type); - } - - @Inject(method = "getAttribute", at = @At("HEAD"), cancellable = true) - private void data_getAttribute(CallbackInfoReturnable ci) { - EntityAttribute attribute = Registries.ATTRIBUTE.get(this.data_identifier); - - if (attribute != null) { - ci.setReturnValue(attribute); - } else { - ci.setReturnValue(this.type); - } - } - - @Inject(method = "computeValue", at = @At("HEAD"), cancellable = true) - private void data_computeValue(CallbackInfoReturnable ci) { - MutableEntityAttribute attribute = (MutableEntityAttribute) ((EntityAttributeInstance) (Object) this) - .getAttribute(); - StackingBehaviour behaviour = attribute.stackingBehaviour(); - double k = 0.0D, v = 0.0D, k2 = 0.0D, v2 = 0.0D; - - if (this.baseValue > 0.0D) { - k = behaviour.stack(k, this.baseValue); - k2 = behaviour.max(k2, this.baseValue); - } else { - v = behaviour.stack(v, this.baseValue); - v2 = behaviour.max(v2, this.baseValue); - } - - for (EntityAttributeModifier modifier : this - .getModifiersByOperation(EntityAttributeModifier.Operation.ADDITION)) { - double value = modifier.getValue(); - - if (value > 0.0D) { - k = behaviour.stack(k, value); - k2 = behaviour.max(k2, value); - } else { - v = behaviour.stack(v, value); - v2 = behaviour.max(v2, value); - } - } - - if (this.data_containerCallback != null) { - Map parents = ((MutableEntityAttribute) attribute) - .parentsMutable(); - - for (IEntityAttribute parent : parents.keySet()) { - EntityAttributeInstance instance = this.data_containerCallback - .getCustomInstance((EntityAttribute) parent); - - if (instance == null) - continue; - AttributeFunctionJson function = parents.get(parent); - - if (function.behaviour() != FunctionBehaviour.ADDITION) - continue; - double multiplier = function.value(); - double value = multiplier * instance.getValue(); - - if (value > 0.0D) { - k = behaviour.stack(k, value); - // We don't put this here because follow-on attribute values should always be - // diminishing (if the attribute supports it). - // k2 = behaviour.max(k2, value); - } else { - v = behaviour.stack(v, value); - // We don't put this here because follow-on attribute values should always be - // diminishing (if the attribute supports it). - // v2 = behaviour.max(v2, value); - } - } - } - - double d = attribute.sum(k, k2, v, v2); - double e = d; - - for (EntityAttributeModifier modifier : this - .getModifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_BASE)) { - e += d * modifier.getValue(); - } - - for (EntityAttributeModifier modifier : this - .getModifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_TOTAL)) { - e *= 1.0D + modifier.getValue(); - } - - if (this.data_containerCallback != null) { - Map parents = ((MutableEntityAttribute) attribute) - .parentsMutable(); - - for (IEntityAttribute parent : parents.keySet()) { - EntityAttributeInstance instance = this.data_containerCallback - .getCustomInstance((EntityAttribute) parent); - - if (instance == null) - continue; - AttributeFunctionJson function = parents.get(parent); - - if (function.behaviour() != FunctionBehaviour.MULTIPLY) - continue; - e *= 1.0D + (instance.getValue() * function.value()); - } - } - - double value = ((EntityAttribute) attribute).clamp(e); - ci.setReturnValue(value); - } - - @Inject(method = "addModifier", at = @At("HEAD"), cancellable = true) - private void data_addModifier(EntityAttributeModifier modifier, CallbackInfo ci) { - EntityAttributeInstance instance = (EntityAttributeInstance) (Object) this; - UUID key = modifier.getId(); - EntityAttributeModifier entityAttributeModifier = (EntityAttributeModifier) this.idToModifiers.get(key); - - if (entityAttributeModifier != null) { - throw new IllegalArgumentException("Modifier is already applied on this attribute!"); - } else { - this.actionModifier(() -> { - this.idToModifiers.put(key, modifier); - instance.getModifiers(modifier.getOperation()).add(modifier); - }, instance, modifier, true); - } - - ci.cancel(); - } - - @Inject(method = "removeModifier", at = @At("HEAD"), cancellable = true) - private void data_removeModifier(EntityAttributeModifier modifier, CallbackInfo ci) { - EntityAttributeInstance instance = (EntityAttributeInstance) (Object) this; - - this.actionModifier(() -> { - instance.getModifiers(modifier.getOperation()).remove(modifier); - this.idToModifiers.remove(modifier.getId()); - this.persistentModifiers.remove(modifier); - }, instance, modifier, false); - - ci.cancel(); - } - - @Redirect(method = "toNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/registry/Registry;getId(Ljava/lang/Object;)Lnet/minecraft/util/Identifier;")) - private Identifier data_toNbt(Registry registry, Object type) { - if (this.data_identifier == null) - return Registries.ATTRIBUTE.getId((EntityAttribute) type); - return this.data_identifier; - } - - @Override - public Identifier getId() { - return this.data_identifier; - } - - @Override - public void actionModifier(final VoidConsumer consumerIn, final EntityAttributeInstance instanceIn, - final EntityAttributeModifier modifierIn, final boolean isWasAdded) { - EntityAttribute entityAttribute = ((EntityAttributeInstance) (Object) this).getAttribute(); - MutableEntityAttribute parent = (MutableEntityAttribute) entityAttribute; - - if (this.data_containerCallback == null) - return; - for (IEntityAttribute child : parent.childrenMutable().keySet()) { - EntityAttribute attribute = (EntityAttribute) child; - EntityAttributeInstance instance = this.data_containerCallback.getCustomInstance(attribute); - - if (instance != null) { - instance.getValue(); - } - } - - final double value = instanceIn.getValue(); - - consumerIn.accept(); - - this.onUpdate(); - - LivingEntity livingEntity = ((MutableAttributeContainer) this.data_containerCallback).getLivingEntity(); - - EntityAttributeModifiedEvents.MODIFIED.invoker().onModified(entityAttribute, livingEntity, modifierIn, value, - isWasAdded); - - for (IEntityAttribute child : parent.childrenMutable().keySet()) { - EntityAttribute attribute = (EntityAttribute) child; - EntityAttributeInstance instance = this.data_containerCallback.getCustomInstance(attribute); - - if (instance != null) { - ((MutableAttributeInstance) instance).actionModifier(() -> { - }, instance, modifierIn, isWasAdded); - } - } - } - - @Override - public void setContainerCallback(final AttributeContainer containerIn) { - this.data_containerCallback = containerIn; - } - - @Override - public void updateId(final Identifier identifierIn) { - this.data_identifier = identifierIn; - } - - @Override - public void updateModifier(final UUID uuid, final double value) { - EntityAttributeInstance instance = (EntityAttributeInstance) (Object) this; - EntityAttributeModifier modifier = instance.getModifier(uuid); - - if (modifier == null) - return; - - this.actionModifier(() -> { - ((MutableAttributeModifier) modifier).updateValue(value); - }, instance, modifier, false); - } - - @Override - public void refresh() { - this.onUpdate(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeMixin.java deleted file mode 100644 index f97e6c0c..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeMixin.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.IAttributeFunction; -import com.github.clevernucleus.dataattributes_dc.api.attribute.IEntityAttribute; -import com.github.clevernucleus.dataattributes_dc.api.attribute.StackingBehaviour; -import com.github.clevernucleus.dataattributes_dc.api.event.EntityAttributeModifiedEvents; -import com.github.clevernucleus.dataattributes_dc.json.AttributeFunctionJson; -import com.github.clevernucleus.dataattributes_dc.mutable.MutableEntityAttribute; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.util.math.MathHelper; - -@Mixin(EntityAttribute.class) -abstract class EntityAttributeMixin implements MutableEntityAttribute { - - // Unique fields to store additional attribute data - @Unique private Map data_parents, data_children; - @Unique private Map data_properties; - @Unique private StackingBehaviour data_stackingBehaviour; - @Unique private String data_translationKey; - @Unique protected double data_fallbackValue, data_minValue, data_maxValue, data_incrementValue; - - // Original fields from the EntityAttribute class - @Final - @Shadow - private double fallback; - - @Final - @Shadow - private String translationKey; - - // Constructor injection to initialize additional fields - @Inject(method = "", at = @At("TAIL")) - private void data_init(String translationKey, double fallback, CallbackInfo ci) { - this.data_translationKey = translationKey; - this.data_fallbackValue = fallback; - this.data_minValue = Integer.MIN_VALUE; - this.data_maxValue = Integer.MAX_VALUE; - this.data_stackingBehaviour = StackingBehaviour.FLAT; - this.data_parents = new Object2ObjectArrayMap(); - this.data_children = new Object2ObjectArrayMap(); - this.data_properties = new HashMap(); - } - - // Injection to override the default value - @Inject(method = "getDefaultValue", at = @At("HEAD"), cancellable = true) - private void data_getDefaultValue(CallbackInfoReturnable ci) { - ci.setReturnValue(this.data_fallbackValue); - } - - // Injection to always consider the attribute as tracked - @Inject(method = "isTracked", at = @At("HEAD"), cancellable = true) - private void data_isTracked(CallbackInfoReturnable ci) { - ci.setReturnValue(true); - } - - // Injection to clamp attribute values and trigger an event - @Inject(method = "clamp", at = @At("HEAD"), cancellable = true) - private void data_clamp(double value, CallbackInfoReturnable ci) { - ci.setReturnValue(this.data_clamped(value)); - } - - // Injection to get the custom translation key - @Inject(method = "getTranslationKey", at = @At("HEAD"), cancellable = true) - private void data_getTranslationKey(CallbackInfoReturnable ci) { - ci.setReturnValue(this.data_translationKey); - } - - // Custom method to clamp attribute values and trigger an event - protected double data_clamped(double valueIn) { - double value = EntityAttributeModifiedEvents.CLAMPED.invoker().onClamped((EntityAttribute)(Object)this, valueIn); - return MathHelper.clamp(value, this.minValue(), this.maxValue()); - } - - // Override method to modify attribute properties - @Override - public void override(String translationKey, double minValue, double maxValue, double fallbackValue, double incrementValue, StackingBehaviour stackingBehaviour) { - this.data_translationKey = translationKey; - this.data_minValue = minValue; - this.data_maxValue = maxValue; - this.data_incrementValue = incrementValue; - this.data_fallbackValue = fallbackValue; - this.data_stackingBehaviour = stackingBehaviour; - } - - // Method to set additional properties for the attribute - @Override - public void properties(Map properties) { - if(properties == null) return; - this.data_properties = properties; - } - - // Method to add a parent attribute with an associated function - @Override - public void addParent(MutableEntityAttribute attributeIn, AttributeFunctionJson function) { - this.data_parents.put(attributeIn, function); - } - - // Method to add a child attribute with an associated function - @Override - public void addChild(MutableEntityAttribute attributeIn, AttributeFunctionJson function) { - if(this.contains(this, attributeIn)) return; - - attributeIn.addParent(this, function); - this.data_children.put(attributeIn, function); - } - - // Method to clear and reset attribute properties - @Override - public void clear() { - this.override(this.translationKey, this.fallback, this.fallback, this.fallback, 0.0D, StackingBehaviour.FLAT); - this.properties(new HashMap()); - this.data_parents.clear(); - this.data_children.clear(); - } - - // Method to calculate the sum of two attribute values based on stacking behavior - @Override - public double sum(final double k, final double k2, final double v, final double v2) { - return this.data_stackingBehaviour.result(k, k2, v, v2, this.data_incrementValue); - } - - // Method to check if one attribute contains another (checks parent-child relationships) - @Override - public boolean contains(MutableEntityAttribute a, MutableEntityAttribute b) { - if(b == null || a == b) return true; - - for(IEntityAttribute n : a.parentsMutable().keySet()) { - MutableEntityAttribute m = (MutableEntityAttribute)n; - - if(m.contains(m, b)) return true; - } - - return false; - } - - // Method to get the mutable map of parent attributes - @Override - public Map parentsMutable() { - return this.data_parents; - } - - // Method to get the mutable map of child attributes - @Override - public Map childrenMutable() { - return this.data_children; - } - - // Method to get the minimum value of the attribute - @Override - public double minValue() { - return this.data_minValue; - } - - // Method to get the maximum value of the attribute - @Override - public double maxValue() { - return this.data_maxValue; - } - - // Method to get the stacking behavior of the attribute - @Override - public StackingBehaviour stackingBehaviour() { - return this.data_stackingBehaviour; - } - - // Method to get an immutable map of parent attributes and their functions - @Override - public Map parents() { - return ImmutableMap.copyOf(this.data_parents); - } - - // Method to get an immutable map of child attributes and their functions - @Override - public Map children() { - return ImmutableMap.copyOf(this.data_children); - } - - // Method to get an immutable collection of property keys - @Override - public Collection properties() { - return ImmutableSet.copyOf(this.data_properties.keySet()); - } - - // Method to check if the attribute has a specific property - @Override - public boolean hasProperty(final String property) { - return this.data_properties.containsKey(property); - } - - // Method to get the value of a specific property - @Override - public String getProperty(final String property) { - return this.data_properties.getOrDefault(property, ""); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeModifierMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeModifierMixin.java deleted file mode 100644 index cdf62afe..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityAttributeModifierMixin.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.UUID; -import java.util.function.Supplier; - -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeModifier; - -import net.minecraft.entity.attribute.EntityAttributeModifier; - -@Mixin(EntityAttributeModifier.class) -abstract class EntityAttributeModifierMixin implements MutableAttributeModifier { - - // Custom field to store the modified value - @Unique - private double data_value; - - // Injection to capture the value during object creation - @Inject(method = "(Ljava/util/UUID;Ljava/util/function/Supplier;DLnet/minecraft/entity/attribute/EntityAttributeModifier$Operation;)V", at = @At("TAIL")) - private void init(UUID uuid, Supplier nameGetter, double value, EntityAttributeModifier.Operation operation, CallbackInfo ci) { - this.data_value = value; - } - - // Injection to override the original getValue method - @Inject(method = "getValue", at = @At("HEAD"), cancellable = true) - private void onGetValue(CallbackInfoReturnable ci) { - ci.setReturnValue(this.data_value); - } - - // Redirects to override the original toString and toNbt methods - @Redirect(method = "toString", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;value:D", opcode = Opcodes.GETFIELD)) - private double onToString(EntityAttributeModifier modifier) { - return this.data_value; - } - - @Redirect(method = "toNbt", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;value:D", opcode = Opcodes.GETFIELD)) - private double onToNbt(EntityAttributeModifier modifier) { - return this.data_value; - } - - // Custom method to update the stored value - @Override - public void updateValue(double value) { - this.data_value = value; - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityTrackerEntryMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityTrackerEntryMixin.java deleted file mode 100644 index e2d97e59..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/EntityTrackerEntryMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Set; - -import org.spongepowered.asm.mixin.Final; -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.Redirect; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableAttributeContainer; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.server.network.EntityTrackerEntry; - -@Mixin(EntityTrackerEntry.class) -abstract class EntityTrackerEntryMixin { - - // Shadowed field to access the 'entity' field in EntityTrackerEntry - @Final - @Shadow - private Entity entity; - - // Redirects the 'clear' method call on the Set - @Redirect(method = "syncEntityData", at = @At(value = "INVOKE", target = "Ljava/util/Set;clear()V")) - private void data_syncEntityData(Set set) { - // Accessing the attribute container of the living entity - MutableAttributeContainer container = (MutableAttributeContainer) ((LivingEntity) this.entity).getAttributes(); - - // Custom method to clear tracked attributes - container.clearTracked(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/LivingEntityMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/LivingEntityMixin.java deleted file mode 100644 index f4d7b3ae..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/LivingEntityMixin.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.github.clevernucleus.dataattributes_dc.DataAttributes; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.world.World; - -@Mixin(value = LivingEntity.class, priority = 999) -abstract class LivingEntityMixin { - - // Marking 'attributes' as @Mutable to allow modification - @Mutable - @Shadow - private AttributeContainer attributes; - - // Unique field to store the update flag - @Unique - private int data_updateFlag; - - // Injection at the end of the constructor - @Inject(method = "", at = @At("TAIL")) - private void data_init(EntityType entityType, World world, CallbackInfo ci) { - LivingEntity livingEntity = (LivingEntity)(Object)this; - // Initializing the attributes container using DataAttributes - this.attributes = DataAttributes.MANAGER.getContainer(entityType, livingEntity); - // Initializing the update flag - this.data_updateFlag = DataAttributes.MANAGER.getUpdateFlag(); - // Setting the entity's health to its maximum health - livingEntity.setHealth(livingEntity.getMaxHealth()); - } - - // Injection at the start of the 'tick' method - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;tickActiveItemStack()V")) - private void data_tick(CallbackInfo ci) { - LivingEntity livingEntity = (LivingEntity)(Object)this; - // Getting the current update flag from DataAttributes - final int updateFlag = DataAttributes.MANAGER.getUpdateFlag(); - - // Checking if the update flag has changed since the last tick - if (this.data_updateFlag != updateFlag) { - // Getting the attribute container from the entity - AttributeContainer container = livingEntity.getAttributes(); - - // Getting the modified attribute container from DataAttributes - @SuppressWarnings("unchecked") - AttributeContainer container2 = DataAttributes.MANAGER.getContainer((EntityType) livingEntity.getType(), livingEntity); - - // Setting the attributes of the entity to the modified container - container2.setFrom(container); - this.attributes = container2; - - // Updating the update flag - this.data_updateFlag = updateFlag; - - // Refreshing the entity's attributes using DataAttributes - DataAttributes.refreshAttributes(livingEntity); - } - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/MobEntityMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/MobEntityMixin.java deleted file mode 100644 index e493981d..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/MobEntityMixin.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import com.github.clevernucleus.dataattributes_dc.api.item.ItemHelper; - -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.MiningToolItem; -import net.minecraft.item.SwordItem; - -@Mixin(MobEntity.class) -abstract class MobEntityMixin { - - // Redirecting the getAttackDamage method calls for SwordItem - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 0)) - private float data_getAttackDamage_0(SwordItem swordItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) swordItem).getAttackDamage(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 1)) - private float data_getAttackDamage_1(SwordItem swordItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) swordItem2).getAttackDamage(oldStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 2)) - private float data_getAttackDamage_2(SwordItem swordItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) swordItem).getAttackDamage(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 3)) - private float data_getAttackDamage_3(SwordItem swordItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) swordItem2).getAttackDamage(oldStack); - } - - // Redirecting the getProtection method calls for ArmorItem - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 0)) - private int data_getProtection_0(ArmorItem armorItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem).getProtection(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 1)) - private int data_getProtection_1(ArmorItem armorItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem2).getProtection(oldStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 2)) - private int data_getProtection_2(ArmorItem armorItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem).getProtection(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 3)) - private int data_getProtection_3(ArmorItem armorItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem2).getProtection(oldStack); - } - - // Redirecting the getToughness method calls for ArmorItem - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 0)) - private float data_getToughness_0(ArmorItem armorItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem).getToughness(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 1)) - private float data_getToughness_1(ArmorItem armorItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem2).getToughness(oldStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 2)) - private float data_getToughness_2(ArmorItem armorItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem).getToughness(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 3)) - private float data_getToughness_3(ArmorItem armorItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) armorItem2).getToughness(oldStack); - } - - // Redirecting the getAttackDamage method calls for MiningToolItem - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 0)) - private float data_getAttackDamage_0(MiningToolItem miningToolItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) miningToolItem).getAttackDamage(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 1)) - private float data_getAttackDamage_1(MiningToolItem miningToolItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 2)) - private float data_getAttackDamage_2(MiningToolItem miningToolItem, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) miningToolItem).getAttackDamage(newStack); - } - - @Redirect(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 3)) - private float data_getAttackDamage_3(MiningToolItem miningToolItem2, ItemStack newStack, ItemStack oldStack) { - return ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/PlayerEntityMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/PlayerEntityMixin.java deleted file mode 100644 index 6095ab35..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/PlayerEntityMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import org.spongepowered.asm.mixin.Final; -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 net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.player.PlayerAbilities; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; - -@Mixin(PlayerEntity.class) -abstract class PlayerEntityMixin { - - // Shadowed field to access the 'abilities' field in PlayerEntity - @Shadow - @Final - private PlayerAbilities abilities; - - // Injection at the 'readCustomDataFromNbt' method - @Inject(method = "readCustomDataFromNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getAttributeInstance(Lnet/minecraft/entity/attribute/EntityAttribute;)Lnet/minecraft/entity/attribute/EntityAttributeInstance;")) - private void data_readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { - // Accessing the movement speed attribute value and setting it as the walk speed in PlayerAbilities - this.abilities.setWalkSpeed((float) ((PlayerEntity) (Object) this).getAttributeBaseValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ReloadCommandMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ReloadCommandMixin.java deleted file mode 100644 index f617dc19..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/ReloadCommandMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Collection; - -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 com.github.clevernucleus.dataattributes_dc.DataAttributes; - -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PlayerLookup; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.ReloadCommand; -import net.minecraft.server.command.ServerCommandSource; - -@Mixin(ReloadCommand.class) -abstract class ReloadCommandMixin { - - // Injection at the 'tryReloadDataPacks' method, after its normal execution - @Inject(method = "tryReloadDataPacks", at = @At("TAIL")) - private static void data_tryReloadDataPacks(Collection dataPacks, ServerCommandSource source, CallbackInfo ci) { - // Access the server from the command source - MinecraftServer server = source.getServer(); - - // Create a new PacketByteBuf for network communication - PacketByteBuf buf = PacketByteBufs.create(); - - // Create an NbtCompound to store data attributes information - NbtCompound tag = new NbtCompound(); - - // Trigger the next update flag in the data attributes manager - DataAttributes.MANAGER.nextUpdateFlag(); - - // Save data attributes information to the NbtCompound - DataAttributes.MANAGER.toNbt(tag); - - // Write the NbtCompound to the PacketByteBuf - buf.writeNbt(tag); - - // Send a custom network packet (DataAttributes.RELOAD) to all players on the server - PlayerLookup.all(server).forEach(player -> ServerPlayNetworking.send(player, DataAttributes.RELOAD, buf)); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/SimpleRegistryMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/SimpleRegistryMixin.java deleted file mode 100644 index 10e4c9e3..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/SimpleRegistryMixin.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.Validate; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.github.clevernucleus.dataattributes_dc.mutable.MutableSimpleRegistry; -import com.mojang.serialization.Lifecycle; - -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.ObjectList; -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.SimpleRegistry; -import net.minecraft.registry.entry.RegistryEntry; - -@Mixin(SimpleRegistry.class) -abstract class SimpleRegistryMixin implements MutableSimpleRegistry { - @Unique - private Collection data_idCache; - - @Final - @Shadow - private ObjectList> rawIdToEntry; - - @Final - @Shadow - private Object2IntMap entryToRawId; - - @Final - @Shadow - private Map> idToEntry; - - @Final - @Shadow - private Map, RegistryEntry.Reference> keyToEntry; - - @Final - @Shadow - private Map> valueToEntry; - - // @Final - // @Shadow - // private Function> valueToEntryFunction; - - @Final - @Shadow - private Map entryToLifecycle; - - @Shadow - private Lifecycle lifecycle; - - @Shadow - private List> cachedEntries; - - @Shadow - private int nextId; - - @Shadow - private boolean frozen; - - @Inject(method = "(Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Lifecycle;Z)V", at = @At("TAIL")) - private void data_init(CallbackInfo ci) { - this.data_idCache = new HashSet(); - } - - // @SuppressWarnings("unchecked") - // @Inject(method = "assertNotFrozen", at = @At("HEAD"), cancellable = true) - // private void data_assertNotFrozen(CallbackInfo ci) { - // if ((SimpleRegistry) (Object) this == Registries.ATTRIBUTE) { - // ci.cancel(); - // } - // } - - @Inject(method = "freeze", at = @At("RETURN")) - private void freeze(CallbackInfoReturnable cir) { - this.frozen = false; - } - - @SuppressWarnings("deprecation") - private void remove(RegistryKey key, Lifecycle lifecycle) { - Validate.notNull(key); - RegistryEntry.Reference reference = this.keyToEntry.get(key); - T value = reference.value(); - final int rawId = this.entryToRawId.getInt(value); - - this.rawIdToEntry.remove(rawId); - this.valueToEntry.remove(value); - this.idToEntry.remove(key.getValue()); - this.keyToEntry.remove(key); - this.nextId--; - this.lifecycle = this.lifecycle.add(lifecycle); - this.entryToLifecycle.remove(value); - this.cachedEntries = null; - this.entryToRawId.remove(value); - - for (T t : this.entryToRawId.keySet()) { - int i = this.entryToRawId.get(t); - - if (i > rawId) { - this.entryToRawId.replace(t, i - 1); - } - } - } - - @Override - public void removeCachedIds(Registry registry) { - for (Iterator iterator = this.data_idCache.iterator(); iterator.hasNext();) { - Identifier id = iterator.next(); - - this.remove(RegistryKey.of(registry.getKey(), id), Lifecycle.stable()); - iterator.remove(); - } - } - - @Override - public void cacheId(Identifier id) { - this.data_idCache.add(id); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ArmorItemMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ArmorItemMixin.java deleted file mode 100644 index f4b5c640..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ArmorItemMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin.item; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ItemStack; - -@Mixin(ArmorItem.class) -abstract class ArmorItemMixin extends ItemMixin { - - @Override - public int getProtection(final ItemStack itemStack) { - return ((ArmorItem) (Object) this).getProtection(); - } - - @Override - public float getToughness(final ItemStack itemStack) { - return ((ArmorItem) (Object) this).getToughness(); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemMixin.java deleted file mode 100644 index 0aca7f59..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin.item; - -import org.spongepowered.asm.mixin.Mixin; - -import com.github.clevernucleus.dataattributes_dc.api.item.ItemHelper; - -import net.minecraft.item.Equipment; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; - -@Mixin(Item.class) -abstract class ItemMixin implements ItemHelper { - - @Override - public SoundEvent getEquipSound(final ItemStack itemStack) { - return !(this instanceof Equipment) ? SoundEvents.ITEM_ARMOR_EQUIP_GENERIC : ((Equipment) this).getEquipSound(); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemStackMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemStackMixin.java deleted file mode 100644 index aa18c80e..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/ItemStackMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin.item; - -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 com.github.clevernucleus.dataattributes_dc.api.item.ItemHelper; - -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemStack; - -@Mixin(ItemStack.class) -abstract class ItemStackMixin { - @Inject(method = "(Lnet/minecraft/item/ItemConvertible;I)V", at = @At("TAIL")) - private void data_init(ItemConvertible item, int count, CallbackInfo ci) { - ItemStack stack = (ItemStack) (Object) this; - - if (item != null) { - ((ItemHelper) item.asItem()).onStackCreated(stack, count); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/MiningToolItemMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/MiningToolItemMixin.java deleted file mode 100644 index 0ac2a8e9..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/MiningToolItemMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin.item; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.MiningToolItem; - -@Mixin(MiningToolItem.class) -abstract class MiningToolItemMixin extends ItemMixin { - - // Overrides the getAttackDamage method from ItemMixin - @Override - public float getAttackDamage(final ItemStack itemStack) { - // Calls the original getAttackDamage method from MiningToolItem - return ((MiningToolItem) (Object) this).getAttackDamage(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/SwordItemMixin.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/SwordItemMixin.java deleted file mode 100644 index 27139943..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mixin/item/SwordItemMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mixin.item; - -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.SwordItem; - -@Mixin(SwordItem.class) -abstract class SwordItemMixin extends ItemMixin { - - // Overrides the getAttackDamage method from ItemMixin - @Override - public float getAttackDamage(final ItemStack itemStack) { - // Calls the original getAttackDamage method from SwordItem - return ((SwordItem) (Object) this).getAttackDamage(); - } -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeContainer.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeContainer.java deleted file mode 100644 index 8a68d593..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeContainer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -import java.util.Map; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.util.Identifier; - -public interface MutableAttributeContainer { - - // Returns a map of custom attributes associated with this container - Map custom(); - - // Returns the LivingEntity associated with this container - LivingEntity getLivingEntity(); - - // Sets the LivingEntity associated with this container - void setLivingEntity(final LivingEntity livingEntity); - - // Refreshes the attributes of the associated LivingEntity - void refresh(); - - // Clears any tracked information (possibly related to attribute changes) - void clearTracked(); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeInstance.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeInstance.java deleted file mode 100644 index a5fd82ed..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeInstance.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -import com.github.clevernucleus.dataattributes_dc.api.util.VoidConsumer; - -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.util.Identifier; - -public interface MutableAttributeInstance { - - // Returns the unique identifier of the attribute instance - Identifier getId(); - - // Performs an action on the attribute modifier - void actionModifier(final VoidConsumer consumerIn, final EntityAttributeInstance instanceIn, final EntityAttributeModifier modifierIn, final boolean isWasAdded); - - // Sets a callback for changes to the associated AttributeContainer - void setContainerCallback(final AttributeContainer containerIn); - - // Updates the identifier of the attribute instance - void updateId(final Identifier identifierIn); - - // Refreshes the attribute instance - void refresh(); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeModifier.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeModifier.java deleted file mode 100644 index 0bb0be81..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableAttributeModifier.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -public interface MutableAttributeModifier { - - // Updates the value of the attribute modifier - void updateValue(double value); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableDefaultAttributeContainer.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableDefaultAttributeContainer.java deleted file mode 100644 index e22ec508..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableDefaultAttributeContainer.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -import net.minecraft.entity.attribute.DefaultAttributeContainer; - -public interface MutableDefaultAttributeContainer { - - // Copies attribute configurations from a DefaultAttributeContainer.Builder - void copy(DefaultAttributeContainer.Builder builder); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableEntityAttribute.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableEntityAttribute.java deleted file mode 100644 index 15474f30..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableEntityAttribute.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -import java.util.Map; - -import com.github.clevernucleus.dataattributes_dc.api.attribute.IEntityAttribute; -import com.github.clevernucleus.dataattributes_dc.api.attribute.StackingBehaviour; -import com.github.clevernucleus.dataattributes_dc.json.AttributeFunctionJson; - -public interface MutableEntityAttribute extends IEntityAttribute { - - // Overrides the properties of the entity attribute - void override(String translationKey, double minValue, double maxValue, double fallbackValue, double incrementValue, StackingBehaviour stackingBehaviour); - - // Sets additional properties for the entity attribute - void properties(Map properties); - - // Adds a parent entity attribute with an associated function - void addParent(MutableEntityAttribute attributeIn, final AttributeFunctionJson function); - - // Adds a child entity attribute with an associated function - void addChild(MutableEntityAttribute attributeIn, final AttributeFunctionJson function); - - // Clears all properties and relationships of the entity attribute - void clear(); - - // Calculates the sum of values using specific parameters - double sum(final double k, final double k2, final double v, final double v2); - - // Checks if a given entity attribute is contained within another - boolean contains(MutableEntityAttribute a, MutableEntityAttribute b); - - // Returns a mutable map of parent entity attributes with associated functions - Map parentsMutable(); - - // Returns a mutable map of child entity attributes with associated functions - Map childrenMutable(); -} diff --git a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableSimpleRegistry.java b/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableSimpleRegistry.java deleted file mode 100644 index b79f5b2d..00000000 --- a/src/main/java/com/github/clevernucleus/dataattributes_dc/mutable/MutableSimpleRegistry.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.clevernucleus.dataattributes_dc.mutable; - -import net.minecraft.util.Identifier; -import net.minecraft.registry.Registry; - -public interface MutableSimpleRegistry { - - // Default method to remove cached identifiers from a registry - default void removeCachedIds(Registry registry) { - } - - // Default method to cache an identifier - default void cacheId(Identifier id) { - } -} diff --git a/src/main/resources/assets/dataattributes_dc/icon.png b/src/main/resources/assets/dataattributes_dc/icon.png deleted file mode 100644 index d8e87491..00000000 Binary files a/src/main/resources/assets/dataattributes_dc/icon.png and /dev/null differ diff --git a/src/main/resources/dataattributes_dc.mixins.json b/src/main/resources/dataattributes_dc.mixins.json deleted file mode 100644 index 2cfc21c7..00000000 --- a/src/main/resources/dataattributes_dc.mixins.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.clevernucleus.dataattributes_dc.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "SimpleRegistryMixin", - "EntityAttributeMixin", - "ClampedEntityAttributeMixin", - "EntityAttributeModifierMixin", - "EntityAttributeInstanceMixin", - "DefaultAttributeContainerMixin", - "AttributeContainerMixin", - "LivingEntityMixin", - "PlayerEntityMixin", - "MobEntityMixin", - "ReloadCommandMixin", - "EntityTrackerEntryMixin", - "item.ItemMixin", - "item.SwordItemMixin", - "item.ArmorItemMixin", - "item.MiningToolItemMixin", - "item.ItemStackMixin" - ], - "client": [], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index 1c9a73a6..00000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "schemaVersion": 1, - "id": "dataattributes_dc", - "version": "${version}", - "name": "Data Attributes: Directors Cut", - "description": "An updated mod that overhauls the entity attributes systems and exposes it with datapacks.", - "authors": [ - "CleverNucleus", - "MerryweatherLost", - "pokesmells", - "DROGERSMAN" - ], - "contact": { - "homepage": "https://github.com/PlayerEXDirectorsCut/data-attributes", - "sources": "https://github.com/PlayerEXDirectorsCut/data-attributes" - }, - "license": "MIT", - "icon": "assets/dataattributes_dc/icon.png", - "environment": "*", - "entrypoints": { - "main": [ - "com.github.clevernucleus.dataattributes_dc.DataAttributes" - ], - "client": [ - "com.github.clevernucleus.dataattributes_dc.DataAttributesClient" - ] - }, - "mixins": [ - "dataattributes_dc.mixins.json" - ], - "depends": { - "fabricloader": ">=0.14.21", - "fabric-api": ">=0.83.0", - "minecraft": "1.20.1", - "java": ">=17" - } -} \ No newline at end of file