diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4ffbd90 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# This is the universal Text Editor Configuration +# for all GTNewHorizons projects +# See: https://editorconfig.org/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{bat,ini}] +end_of_line = crlf + +[*.{dtd,json,info,mcmeta,md,sh,svg,xml,xsd,xsl,yaml,yml}] +indent_size = 2 + +[*.lang] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fd2792b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,44 @@ +* text eol=lf + +*.[jJ][aA][rR] binary + +*.[pP][nN][gG] binary +*.[jJ][pP][gG] binary +*.[jJ][pP][eE][gG] binary +*.[gG][iI][fF] binary +*.[tT][iI][fF] binary +*.[tT][iI][fF][fF] binary +*.[iI][cC][oO] binary +*.[sS][vV][gG] text +*.[eE][pP][sS] binary +*.[xX][cC][fF] binary + +*.[kK][aA][rR] binary +*.[mM]4[aA] binary +*.[mM][iI][dD] binary +*.[mM][iI][dD][iI] binary +*.[mM][pP]3 binary +*.[oO][gG][gG] binary +*.[rR][aA] binary + +*.7[zZ] binary +*.[gG][zZ] binary +*.[tT][aA][rR] binary +*.[tT][gG][zZ] binary +*.[zZ][iI][pP] binary + +*.[tT][cC][nN] binary +*.[sS][oO] binary +*.[dD][lL][lL] binary +*.[dD][yY][lL][iI][bB] binary +*.[pP][sS][dD] binary +*.[tT][tT][fF] binary +*.[oO][tT][fF] binary + +*.[pP][aA][tT][cC][hH] -text + +*.[bB][aA][tT] text eol=crlf +*.[cC][mM][dD] text eol=crlf +*.[pP][sS]1 text eol=crlf + +*[aA][uU][tT][oO][gG][eE][nN][eE][rR][aA][tT][eE][dD]* binary diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..3ee2f68 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,13 @@ + +name: Build and test + +on: + pull_request: + branches: [ master, main ] + push: + branches: [ master, main ] + +jobs: + build-and-test: + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master + secrets: inherit diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml new file mode 100644 index 0000000..e4c0be6 --- /dev/null +++ b/.github/workflows/release-tags.yml @@ -0,0 +1,14 @@ + +name: Release tagged build + +on: + push: + tags: [ '*' ] + +permissions: + contents: write + +jobs: + release-tags: + uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master + secrets: inherit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e80e0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +.gradle +.settings +/.idea/ +/.vscode/ +/run/ +/build/ +/eclipse/ +.classpath +.project +/bin/ +/config/ +/crash-reports/ +/logs/ +options.txt +/saves/ +usernamecache.json +banned-ips.json +banned-players.json +eula.txt +ops.json +server.properties +servers.dat +usercache.json +whitelist.json +/out/ +*.iml +*.ipr +*.iws +src/main/resources/mixins.*([!.]).json +*.bat +*.DS_Store +!gradlew.bat +.factorypath +addon.local.gradle +addon.local.gradle.kts +addon.late.local.gradle +addon.late.local.gradle.kts +layout.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e413e58 --- /dev/null +++ b/LICENSE @@ -0,0 +1,222 @@ +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. http://fsf.org + +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 http://www.gnu.org/licenses. +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 http://www.gnu.org/licenses. + +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 http://www.gnu.org/philosophy/why-not-lgpl.html. + +Close diff --git a/README.md b/README.md new file mode 100644 index 0000000..10edf0a --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Chance Cubes +This is a fork of Chance Cubes for Minecraft 1.7.10. It has been forked from the sources for version 1.7.10-2.4.1.182 of the original Chance Cubes. Obtained from CurseForge under the GPL v3 license. + +This fork is also licensed under the GPL v3. + +## Building + +This fork uses https://github.com/GTNewHorizons/GTNHGradle to build, and follows the example from https://github.com/GTNewHorizons/ExampleMod1.7.10 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e57a16f --- /dev/null +++ b/build.gradle @@ -0,0 +1,5 @@ +//version: 1707058017 + +plugins { + id 'com.gtnewhorizons.gtnhconvention' +} diff --git a/dependencies.gradle b/dependencies.gradle new file mode 100644 index 0000000..3d61393 --- /dev/null +++ b/dependencies.gradle @@ -0,0 +1,40 @@ +/* + * Add your dependencies here. Supported configurations: + * - api("group:name:version:classifier"): if you use the types from this dependency in the public API of this mod + * Available at runtime and compiletime for mods depending on this mod + * - implementation("g:n:v:c"): if you need this for internal implementation details of the mod, but none of it is visible via the public API + * Available at runtime but not compiletime for mods depending on this mod + * - compileOnly("g:n:v:c"): if the mod you're building doesn't need this dependency during runtime at all, e.g. for optional mods + * Not available at all for mods depending on this mod, only visible at compiletime for this mod + * - compileOnlyApi("g:n:v:c"): like compileOnly, but also visible at compiletime for mods depending on this mod + * Available at compiletime but not runtime for mods depending on this mod + * - runtimeOnlyNonPublishable("g:n:v:c"): if you want to include a mod in this mod's runClient/runServer runs, but not publish it as a dependency + * Not available at all for mods depending on this mod, only visible at runtime for this mod + * - devOnlyNonPublishable("g:n:v:c"): a combination of runtimeOnlyNonPublishable and compileOnly for dependencies present at both compiletime and runtime, + * but not published as Maven dependencies - useful for RFG-deobfuscated dependencies or local testing + * - runtimeOnly("g:n:v:c"): if you don't need this at compile time, but want it to be present at runtime + * Available at runtime for mods depending on this mod + * - annotationProcessor("g:n:v:c"): mostly for java compiler plugins, if you know you need this, use it, otherwise don't worry + * - testCONFIG("g:n:v:c") - replace CONFIG by one of the above (except api), same as above but for the test sources instead of main + * + * - shadowImplementation("g:n:v:c"): effectively the same as API, but the dependency is included in your jar under a renamed package name + * Requires you to enable usesShadowedDependencies in gradle.properties + * + * - compile("g:n:v:c"): deprecated, replace with "api" (works like the old "compile") or "implementation" (can be more efficient) + * + * You can exclude transitive dependencies (dependencies of the chosen dependency) by appending { transitive = false } if needed, + * but use this sparingly as it can break using your mod as another mod's dependency if you're not careful. + * + * To depend on obfuscated jars you can use `devOnlyNonPublishable(rfg.deobf("dep:spec:1.2.3"))` to fetch an obfuscated jar from maven, + * or `devOnlyNonPublishable(rfg.deobf(project.files("libs/my-mod-jar.jar")))` to use a file. + * + * Gradle names for some of the configuration can be misleading, compileOnlyApi and runtimeOnly both get published as dependencies in Maven, but compileOnly does not. + * The buildscript adds runtimeOnlyNonPublishable to also have a runtime dependency that's not published. + * + * For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph + */ +dependencies { + api("com.github.GTNewHorizons:CTMLib:1.4.5:dev") + compileOnly("com.github.GTNewHorizons:waila:1.7.3:dev") + compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.5.27-GTNH:dev") +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..7611751 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,183 @@ +# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable. +# LOCAL to test local config updates. +gtnh.settings.blowdryerTag = 0.2.2 + +# Human-readable mod name, available for mcmod.info population. +modName = Chance Cubes + +# Case-sensitive identifier string, available for mcmod.info population and used for automatic mixin JSON generation. +# Conventionally lowercase. +modId = chancecubes + +# Root package of the mod, used to find various classes in other properties, +# mcmod.info substitution, enabling assertions in run tasks, etc. +modGroup = chanceCubes + +# Whether to use modGroup as the maven publishing group. +# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods. +useModGroupForPublishing = false + +# Updates your build.gradle and settings.gradle automatically whenever an update is available. +autoUpdateBuildScript = false + +# Version of Minecraft to target +minecraftVersion = 1.7.10 + +# Version of Minecraft Forge to target +forgeVersion = 10.13.4.1614 + +# Specify an MCP channel for dependency deobfuscation and the deobfParams task. +channel = stable + +# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task. +mappingsVersion = 12 + +# Defines other MCP mappings for dependency deobfuscation. +remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/ + +# Select a default username for testing your mod. You can always override this per-run by running +# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE. +developmentEnvironmentUserName = Developer + +# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8. +# See https://github.com/bsideup/jabel for details on how this works. +enableModernJavaSyntax = true + +# Enables injecting missing generics into the decompiled source code for a better coding experience. +# Turns most publicly visible List, Map, etc. into proper List, Map types. +enableGenericInjection = true + +# Generate a class with a String field for the mod version named as defined below. +# If generateGradleTokenClass is empty or not missing, no such class will be generated. +# If gradleTokenVersion is empty or missing, the field will not be present in the class. +generateGradleTokenClass = chanceCubes.Tags + +# Name of the token containing the project's current version to generate/replace. +gradleTokenVersion = VERSION + +# [DEPRECATED] +# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java +# public static final String VERSION = "GRADLETOKEN_VERSION"; +# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's +# version in @Mod([...], version = VERSION, [...]). +# Leave these properties empty to skip individual token replacements. +replaceGradleTokenInFile = + +# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can +# leave this property empty. +# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api +apiPackage = + +# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/ +# There can be multiple files in a space-separated list. +# Example value: mymodid_at.cfg nei_at.cfg +accessTransformersFile = + +# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! +usesMixins = false + +# Adds some debug arguments like verbose output and class export. +usesMixinDebug = false + +# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise. +mixinPlugin = + +# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail! +mixinsPackage = + +# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! +# This parameter is for legacy compatibility only +# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin +coreModClass = + +# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class +# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! +containsMixinsAndOrCoreModOnly = false + +# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins. +forceEnableMixins = false + +# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your +# responsibility to check the license and request permission for distribution if required. +usesShadowedDependencies = false + +# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access +# their own classes, making the minimization unreliable. +minimizeShadowedDependencies = true + +# If disabled, won't rename the shadowed classes. +relocateShadowedDependencies = true + +# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories. +includeWellKnownRepositories = true + +# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven. +# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables. +# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle. +usesMavenPublishing = true + +# Maven repository to publish the mod to. +# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/ + +# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token. +# +# The project's ID on Modrinth. Can be either the slug or the ID. +# Leave this empty if you don't want to publish to Modrinth. +modrinthProjectId = + +# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth. +# Syntax: scope1-type1:name1;scope2-type2:name2;... +# Where scope can be one of [required, optional, incompatible, embedded], +# type can be one of [project, version], +# and the name is the Modrinth project or version slug/id of the other mod. +# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech +# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true +modrinthRelations = + +# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens. +# +# The project's numeric ID on CurseForge. You can find this in the About Project box. +# Leave this empty if you don't want to publish on CurseForge. +curseForgeProjectId = + +# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge. +# Syntax: type1:name1;type2:name2;... +# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible], +# and the name is the CurseForge project slug of the other mod. +# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft +# Note: UniMixins is automatically set as a required dependency if usesMixins = true. +curseForgeRelations = + +# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older +# projects. New projects should not use this parameter. +# customArchiveBaseName = + +# Optional parameter to have the build automatically fail if an illegal version is used. +# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'. +# The check is ONLY performed if the version is a git tag. +# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+ +# versionPattern = + +# Uncomment to prevent the source code from being published. +# noPublishedSources = true + +# Uncomment this to disable Spotless checks. +# This should only be uncommented to keep it easier to sync with upstream/other forks. +# That is, if there is no other active fork/upstream, NEVER change this. +# disableSpotless = true + +# Uncomment this to disable Checkstyle checks (currently wildcard import check). +# disableCheckstyle = true + +# Override the IDEA build type. Valid values are: "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle" +# (force use delegated build). +# This is meant to be set in $HOME/.gradle/gradle.properties. +# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be native build. +# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want! +# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you. +# ideaOverrideBuildType = idea + +# Whether IDEA should run spotless checks when pressing the Build button. +# This is meant to be set in $HOME/.gradle/gradle.properties. +# ideaCheckSpotlessOnBuild = true + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a80b22c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# 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. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# 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». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# 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/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# 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 + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + 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 +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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" \ + -classpath "$CLASSPATH" \ + 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. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..09bbb51 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +before_install: + - ./gradlew setupCIWorkspace \ No newline at end of file diff --git a/repositories.gradle b/repositories.gradle new file mode 100644 index 0000000..7e002f2 --- /dev/null +++ b/repositories.gradle @@ -0,0 +1,5 @@ +// Add any additional repositories for your dependencies here. + +repositories { + +} diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..4c107c8 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,21 @@ + +pluginManagement { + repositories { + maven { + // RetroFuturaGradle + name "GTNH Maven" + url "https://nexus.gtnewhorizons.com/repository/public/" + mavenContent { + includeGroup("com.gtnewhorizons") + includeGroupByRegex("com\\.gtnewhorizons\\..+") + } + } + gradlePluginPortal() + mavenCentral() + mavenLocal() + } +} + +plugins { + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.21' +} diff --git a/src/main/java/chanceCubes/CCubesCore.java b/src/main/java/chanceCubes/CCubesCore.java new file mode 100644 index 0000000..ea8c4b4 --- /dev/null +++ b/src/main/java/chanceCubes/CCubesCore.java @@ -0,0 +1,141 @@ +package chanceCubes; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.MinecraftForge; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.client.gui.CCubesGuiHandler; +import chanceCubes.client.listeners.WorldRenderListener; +import chanceCubes.commands.CCubesClientCommands; +import chanceCubes.commands.CCubesServerCommands; +import chanceCubes.config.CCubesSettings; +import chanceCubes.config.ConfigLoader; +import chanceCubes.config.CustomRewardsLoader; +import chanceCubes.hookins.ModHookUtil; +import chanceCubes.items.CCubesItems; +import chanceCubes.listeners.PlayerConnectListener; +import chanceCubes.listeners.TickListener; +import chanceCubes.listeners.WorldGen; +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.proxy.CommonProxy; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.registry.GiantCubeRegistry; +import chanceCubes.util.CCubesAchievements; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.network.NetworkRegistry; + +@Mod( + modid = CCubesCore.MODID, + version = CCubesCore.VERSION, + name = CCubesCore.NAME, + guiFactory = "chanceCubes.config.ConfigGuiFactory") +public class CCubesCore { + + public static final String MODID = "chancecubes"; + public static final String VERSION = "@VERSION@"; + public static final String NAME = "Chance Cubes"; + + public static final String gameVersion = "1.7.10"; + + @Instance(value = MODID) + public static CCubesCore instance; + @SidedProxy(clientSide = "chanceCubes.proxy.ClientProxy", serverSide = "chanceCubes.proxy.CommonProxy") + public static CommonProxy proxy; + public static CreativeTabs modTab = new CreativeTabs(MODID) { + + public Item getTabIconItem() { + return Item.getItemFromBlock(CCubesBlocks.chanceCube); + } + }; + public static Logger logger; + + @EventHandler + public void init(FMLInitializationEvent event) { + + } + + @EventHandler + public void load(FMLPreInitializationEvent event) { + logger = event.getModLog(); + ConfigLoader.loadConfigSettings(event.getSuggestedConfigurationFile(), event.getSourceFile()); + + CCubesBlocks.loadBlocks(); + CCubesItems.loadItems(); + CraftingRecipies.loadRecipies(); + CCubesPacketHandler.init(); + CCubesAchievements.loadAchievements(); + proxy.registerRenderings(); + proxy.registerEvents(); + + FMLCommonHandler.instance() + .bus() + .register(new PlayerConnectListener()); + FMLCommonHandler.instance() + .bus() + .register(new TickListener()); + MinecraftForge.EVENT_BUS.register(new WorldGen()); + MinecraftForge.EVENT_BUS.register(new WorldRenderListener()); + + if (CCubesSettings.chestLoot) { + ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceCube), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceIcosahedron), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.MINESHAFT_CORRIDOR) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceCube), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.MINESHAFT_CORRIDOR) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceIcosahedron), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CORRIDOR) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceCube), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CORRIDOR) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceIcosahedron), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.VILLAGE_BLACKSMITH) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceCube), 1, 2, 5)); + ChestGenHooks.getInfo(ChestGenHooks.VILLAGE_BLACKSMITH) + .addItem(new WeightedRandomChestContent(new ItemStack(CCubesBlocks.chanceIcosahedron), 1, 2, 5)); + } + + NetworkRegistry.INSTANCE.registerGuiHandler(this, new CCubesGuiHandler()); + } + + @EventHandler + public void postInit(FMLPostInitializationEvent event) { + ChanceCubeRegistry.loadDefaultRewards(); + GiantCubeRegistry.loadDefaultRewards(); + CustomRewardsLoader.instance.loadCustomRewards(); + CustomRewardsLoader.instance.fetchRemoteInfo(); + ConfigLoader.config.save(); + } + + @EventHandler + public void serverLoad(FMLServerStartingEvent event) { + ModHookUtil.loadCustomModRewards(); + + if (event.getSide() + .isClient()) { + CCubesCore.logger.log(Level.INFO, "Client-side commands loaded"); + ClientCommandHandler.instance.registerCommand(new CCubesClientCommands()); + } else if (event.getSide() + .isServer()) { + CCubesCore.logger.log(Level.INFO, "Server-side commands loaded"); + event.registerServerCommand(new CCubesServerCommands()); + } + + } +} diff --git a/src/main/java/chanceCubes/CraftingRecipies.java b/src/main/java/chanceCubes/CraftingRecipies.java new file mode 100644 index 0000000..68f19cb --- /dev/null +++ b/src/main/java/chanceCubes/CraftingRecipies.java @@ -0,0 +1,83 @@ +package chanceCubes; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.config.CCubesSettings; +import chanceCubes.items.CCubesItems; +import cpw.mods.fml.common.registry.GameRegistry; + +public class CraftingRecipies { + + public static void loadRecipies() { + if (CCubesSettings.craftingRecipie) GameRegistry.addShapedRecipe( + new ItemStack(CCubesBlocks.chanceCube, 1), + "LLL", + "LBL", + "LLL", + 'B', + new ItemStack(Blocks.lapis_block), + 'L', + new ItemStack(Items.dye, 1, 4)); + + GameRegistry.addShapedRecipe( + new ItemStack(CCubesItems.chancePendantT1, 1), + "GBG", + "BDB", + "GBG", + 'G', + new ItemStack(Blocks.gold_block), + 'B', + new ItemStack(Blocks.lapis_block), + 'D', + new ItemStack(Blocks.diamond_block)); + GameRegistry.addShapedRecipe( + new ItemStack(CCubesItems.chancePendantT2, 1), + "GBG", + "BPB", + "GBG", + 'P', + new ItemStack(CCubesItems.chancePendantT1), + 'B', + new ItemStack(Blocks.lapis_block), + 'G', + new ItemStack(Blocks.gold_block)); + GameRegistry.addShapedRecipe( + new ItemStack(CCubesItems.chancePendantT3, 1), + "GBG", + "BPB", + "GBG", + 'P', + new ItemStack(CCubesItems.chancePendantT2), + 'B', + new ItemStack(Blocks.lapis_block), + 'G', + new ItemStack(Blocks.gold_block)); + + GameRegistry.addShapedRecipe( + new ItemStack(CCubesItems.silkPendant, 1), + "SBS", + "SPS", + "SBS", + 'P', + new ItemStack(CCubesItems.chancePendantT1), + 'B', + new ItemStack(Blocks.lapis_block), + 'S', + new ItemStack(Items.string)); + + GameRegistry.addShapedRecipe( + new ItemStack(CCubesItems.scanner, 1), + "IGI", + "GPG", + "IGI", + 'P', + new ItemStack(CCubesItems.chancePendantT1), + 'G', + new ItemStack(Blocks.glass), + 'I', + new ItemStack(Items.iron_ingot)); + } +} diff --git a/src/main/java/chanceCubes/blocks/BaseChanceBlock.java b/src/main/java/chanceCubes/blocks/BaseChanceBlock.java new file mode 100644 index 0000000..9420132 --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BaseChanceBlock.java @@ -0,0 +1,23 @@ +package chanceCubes.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; + +import chanceCubes.CCubesCore; + +public class BaseChanceBlock extends Block { + + private String blockName = "Chance_Cube_Unnamed"; + + public BaseChanceBlock(String name) { + super(Material.ground); + this.blockName = name; + this.setHardness(0.5f); + this.setBlockName(blockName); + this.setCreativeTab(CCubesCore.modTab); + } + + public String getBlockName() { + return this.blockName; + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockChanceCube.java b/src/main/java/chanceCubes/blocks/BlockChanceCube.java new file mode 100644 index 0000000..23805a7 --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockChanceCube.java @@ -0,0 +1,162 @@ +package chanceCubes.blocks; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.boss.EntityWither; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.ChunkCache; +import net.minecraft.world.Explosion; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CCubesSettings; +import chanceCubes.items.CCubesItems; +import chanceCubes.items.ItemChanceCube; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.util.GiantCubeUtil; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockChanceCube extends BaseChanceBlock implements ITileEntityProvider { + + @SideOnly(Side.CLIENT) + private IIcon[] icons; + @SideOnly(Side.CLIENT) + private IIcon[] specialIcons; + + private boolean tempOverride = false; + + public BlockChanceCube() { + super("Chance_Cube"); + this.setBlockTextureName("chancecubes:chanceCube"); + this.setLightLevel(2); + } + + @Override + public TileEntity createNewTileEntity(World world, int p_149915_2_) { + return new TileChanceCube(); + } + + @Override + public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { + if (!world.isRemote && player != null && !(player instanceof FakePlayer)) { + TileChanceCube te = (TileChanceCube) world.getTileEntity(x, y, z); + if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem() + .getItem() + .equals(CCubesItems.silkPendant)) { + ItemStack stack = new ItemStack(Item.getItemFromBlock(CCubesBlocks.chanceCube), 1); + ((ItemChanceCube) stack.getItem()).setChance(stack, te.isScanned() ? te.getChance() : -101); + this.dropBlockAsItem(world, x, y, z, stack); + world.setBlockToAir(x, y, z); + world.removeTileEntity(x, y, z); + return true; + } + + if (te != null) { + world.setBlockToAir(x, y, z); + ChanceCubeRegistry.INSTANCE.triggerRandomReward(world, x, y, z, player, te.getChance()); + } + } + return true; + } + + @Override + public int quantityDropped(Random p_149745_1_) { + return 0; + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + return !(entity instanceof EntityWither) && super.canEntityDestroy(world, x, y, z, entity); + } + + @Override + public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) { + + } + + @Override + public boolean canDropFromExplosion(Explosion explosion) { + return false; + } + + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) { + this.icons = new IIcon[6]; + this.icons[0] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_1"); + this.icons[1] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_6"); + this.icons[2] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_2"); + this.icons[3] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_5"); + this.icons[4] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_4"); + this.icons[5] = register.registerIcon(CCubesCore.MODID + ":chancecube_face_3"); + if (CCubesSettings.hasHolidayTexture) { + this.specialIcons = new IIcon[6]; + String texture = CCubesSettings.holidayTextureName; + this.specialIcons[0] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_1"); + this.specialIcons[1] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_6"); + this.specialIcons[2] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_2"); + this.specialIcons[3] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_5"); + this.specialIcons[4] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_4"); + this.specialIcons[5] = register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_3"); + } + } + + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess acess, int x, int y, int z, int side) { + if (tempOverride) return this.getIcon(side, acess.getBlockMetadata(x, y, z)); + World world = null; + if (acess instanceof World) { + world = (World) acess; + } else if (acess instanceof ChunkCache) { + TileEntity te = ((ChunkCache) acess).getTileEntity(x, y, z); + if (te == null) return this.getIcon(side, acess.getBlockMetadata(x, y, z)); + world = te.getWorldObj(); + } else { + return this.getIcon(side, acess.getBlockMetadata(x, y, z)); + } + + int dim = world.provider.dimensionId; + Block block = world.getBlock(x, y - 1, z); + if (block instanceof BaseChanceBlock) return this.getIcon(side, acess.getBlockMetadata(x, y, z)); + if (dim == 0 && CCubesSettings.hiddenOverWorldCubes) { + if (block.equals(Blocks.air)) return Blocks.stone.getIcon(side, acess.getBlockMetadata(x, y, z)); + return world.getBlock(x, y - 1, z) + .getIcon(side, acess.getBlockMetadata(x, y, z)); + } + if (dim == 1 && CCubesSettings.hiddenEndCubes) { + if (block.equals(Blocks.air)) return Blocks.end_stone.getIcon(side, acess.getBlockMetadata(x, y, z)); + return world.getBlock(x, y - 1, z) + .getIcon(side, acess.getBlockMetadata(x, y, z)); + } + if (dim == -1 && CCubesSettings.hiddenNetherCubes) { + if (block.equals(Blocks.air)) return Blocks.netherrack.getIcon(side, acess.getBlockMetadata(x, y, z)); + return world.getBlock(x, y - 1, z) + .getIcon(side, acess.getBlockMetadata(x, y, z)); + } + + return this.getIcon(side, acess.getBlockMetadata(x, y, z)); + } + + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + if (CCubesSettings.hasHolidayTexture) return this.specialIcons[side]; + else return this.icons[side]; + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { + GiantCubeUtil.checkMultiBlockForm(x, y, z, world, true); + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockChanceD20.java b/src/main/java/chanceCubes/blocks/BlockChanceD20.java new file mode 100644 index 0000000..62798ee --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockChanceD20.java @@ -0,0 +1,125 @@ +package chanceCubes.blocks; + +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.Explosion; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +import chanceCubes.config.CCubesSettings; +import chanceCubes.items.CCubesItems; +import chanceCubes.items.ItemChanceCube; +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.network.PacketTriggerD20; +import chanceCubes.tileentities.TileChanceD20; +import chanceCubes.util.CCubesAchievements; +import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; + +public class BlockChanceD20 extends BaseChanceBlock implements ITileEntityProvider { + + public BlockChanceD20() { + super("Chance_Icosahedron"); + super.setHardness(-1F); + this.setLightLevel(7); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileChanceD20(); + } + + @Override + public int getRenderType() { + return CCubesSettings.d20RenderID; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + public boolean renderAsNormalBlock() { + return isOpaqueCube(); + } + + @Override + public int getLightValue() { + /* + * BUGFIX: + * Vanilla has a bug here somehow, regarding light levels. See ChunkCache#getLightBrightnessForSkyBlocks. + * It seems that this returns the "low" light value, i.e. 0-15. However, the light value of blocks is on a scale + * of 0-255 (for some ungodly reason). + * This ruins the bit-packing mojang does for light levels, as the level returned from getLightValue() by + * defualt is 105 in our case. + * What should be 0xF00070 turns into 0xF00690, causing the block emitting the light to be dark (and the AO to + * treat it as dark) but the surrounding blocks are lit up. + * Anyways, thanks a lot mojang, as usual. + */ + return 7; + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + TileChanceD20 te = (TileChanceD20) world.getTileEntity(x, y, z); + if (te.getStage() > 0) setBlockBounds(0, 0, 0, 0, 0, 0); + else setBlockBounds(0, 0, 0, 1, 1, 1); + } + + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { + this.startd20(world, x, y, z, player); + } + + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, + float p_149727_7_, float p_149727_8_, float p_149727_9_) { + return this.startd20(world, x, y, z, player); + } + + public boolean startd20(World world, int x, int y, int z, EntityPlayer player) { + if (player == null || player instanceof FakePlayer) return false; + + TileChanceD20 te = (TileChanceD20) world.getTileEntity(x, y, z); + if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem() + .getItem() + .equals(CCubesItems.silkPendant)) { + if (!world.isRemote) { + ItemStack stack = new ItemStack(Item.getItemFromBlock(CCubesBlocks.chanceIcosahedron), 1); + ((ItemChanceCube) stack.getItem()).setChance(stack, te.isScanned() ? te.getChance() : -101); + this.dropBlockAsItem(world, x, y, z, stack); + world.setBlockToAir(x, y, z); + world.removeTileEntity(x, y, z); + } + return true; + } + + if (te != null && !world.isRemote) { + player.triggerAchievement(CCubesAchievements.chanceIcosahedron); + te.startBreaking(player); + CCubesPacketHandler.INSTANCE.sendToAllAround( + new PacketTriggerD20(x, y, z), + new TargetPoint(world.provider.dimensionId, x, y, z, 50)); + return true; + } + + return false; + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + return false; + } + + @Override + public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) { + + } + + @Override + public boolean canDropFromExplosion(Explosion explosion) { + return false; + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockCompactGiantCube.java b/src/main/java/chanceCubes/blocks/BlockCompactGiantCube.java new file mode 100644 index 0000000..73ca0b3 --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockCompactGiantCube.java @@ -0,0 +1,22 @@ +package chanceCubes.blocks; + +import net.minecraft.world.World; + +import chanceCubes.util.GiantCubeUtil; + +public class BlockCompactGiantCube extends BaseChanceBlock { + + public static final String blockName = "Compact_Giant_Chance_Cube"; + + public BlockCompactGiantCube() { + super("Compact_Giant_Chance_Cube"); + this.setHardness(0.5f); + this.setBlockTextureName("chancecubes:chanceCube"); + } + + public void onPostBlockPlaced(World world, int x, int y, int z, int p_149714_5_) { + super.onPostBlockPlaced(world, x, y, z, p_149714_5_); + if (world.isRemote) return; + GiantCubeUtil.setupStructure(x - 1, y, z - 1, world, true); + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockCubeDispenser.java b/src/main/java/chanceCubes/blocks/BlockCubeDispenser.java new file mode 100644 index 0000000..44c82bb --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockCubeDispenser.java @@ -0,0 +1,117 @@ +package chanceCubes.blocks; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.boss.EntityWither; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.Explosion; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.tileentities.TileCubeDispenser; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockCubeDispenser extends BaseChanceBlock implements ITileEntityProvider { + + @SideOnly(Side.CLIENT) + private IIcon top, side; + + public BlockCubeDispenser() { + super("Cube_Dispenser"); + this.setHardness(2f); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileCubeDispenser(); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float p_149727_7_, + float p_149727_8_, float p_149727_9_) { + if (!(world.getTileEntity(x, y, z) instanceof TileCubeDispenser)) return false; + TileCubeDispenser te = (TileCubeDispenser) world.getTileEntity(x, y, z); + if (player.isSneaking()) { + world.setBlockMetadataWithNotify(x, y, z, (world.getBlockMetadata(x, y, z) + 1) % 3, 3); + } else { + if (player.inventory.getCurrentItem() != null && Block.getBlockFromItem( + player.inventory.getCurrentItem() + .getItem()) + .equals(te.getCurrentBlock(world.getBlockMetadata(x, y, z)))) + player.inventory.decrStackSize(player.inventory.currentItem, 1); + } + return true; + } + + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { + if (world.isRemote) return; + if (!(world.getTileEntity(x, y, z) instanceof TileCubeDispenser)) return; + TileCubeDispenser te = (TileCubeDispenser) world.getTileEntity(x, y, z); + + double px = player.posX; + double py = player.posY; + double pz = player.posZ; + + EntityItem entitem = te.getNewEntityItem(world.getBlockMetadata(x, y, z)); + entitem.setLocationAndAngles(px, py, pz, 0, 0); + if (player.isSneaking()) { + entitem.getEntityItem().stackSize = 1; + world.spawnEntityInWorld(entitem); + } else { + entitem.getEntityItem().stackSize = 64; + world.spawnEntityInWorld(entitem); + } + } + + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) { + this.top = register.registerIcon(CCubesCore.MODID + ":cubeDispenser_Top"); + this.side = register.registerIcon(CCubesCore.MODID + ":cubeDispenser_Side"); + } + + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + if (side == 0 || side == 1) return this.top; + return this.side; + } + + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + return !(entity instanceof EntityWither) && super.canEntityDestroy(world, x, y, z, entity); + } + + @Override + public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) { + + } + + @Override + public boolean canDropFromExplosion(Explosion explosion) { + return false; + } + + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { + return null; + } + + /** + * Returns the quantity of items to drop on block destruction. + */ + public int quantityDropped(Random p_149745_1_) { + return 0; + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockFallingCustom.java b/src/main/java/chanceCubes/blocks/BlockFallingCustom.java new file mode 100644 index 0000000..47a000d --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockFallingCustom.java @@ -0,0 +1,87 @@ +package chanceCubes.blocks; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockFalling; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class BlockFallingCustom extends EntityFallingBlock { + + private int normY; + private OffsetBlock osb; + + public BlockFallingCustom(World world, double x, double y, double z, Block b, int data, int normY, + OffsetBlock osb) { + super(world, x, y, z, b, data); + this.normY = normY; + this.osb = osb; + } + + public void onUpdate() { + if (super.func_145805_f() == null || super.func_145805_f().getMaterial() == Material.air) { + this.setDead(); + } else { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + ++this.field_145812_b; + this.motionY -= 0.04D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.98; + this.motionY *= 0.98; + this.motionZ *= 0.98; + + if (!this.worldObj.isRemote) { + int i = MathHelper.floor_double(this.posX); + int j = MathHelper.floor_double(this.posY - .5); + int k = MathHelper.floor_double(this.posZ); + + if (this.onGround) { + this.motionX *= 0.7; + this.motionZ *= 0.7; + this.motionY *= -0.5; + + if (this.worldObj.getBlock(i, j, k) != Blocks.piston_extension) { + this.setDead(); + if (this.worldObj.canPlaceEntityOnSide( + super.func_145805_f(), + i, + j, + k, + true, + 1, + (Entity) null, + (ItemStack) null) && !BlockFalling.func_149831_e(this.worldObj, i, j - 1, k) + && this.worldObj.setBlock(i, j, k, super.func_145805_f(), this.field_145814_a, 3)) + osb.placeInWorld(worldObj, i, j, k, false); + else if (this.field_145813_c) this.entityDropItem( + new ItemStack( + super.func_145805_f(), + 1, + super.func_145805_f().damageDropped(this.field_145814_a)), + 0.0F); + } + } else if (normY == j) { + this.setDead(); + osb.placeInWorld(worldObj, i, j, k, false); + } else if (this.field_145812_b > 100 && !this.worldObj.isRemote && (j < 1 || j > 256) + || this.field_145812_b > 600) { + if (this.field_145813_c) this.entityDropItem( + new ItemStack( + super.func_145805_f(), + 1, + super.func_145805_f().damageDropped(this.field_145814_a)), + 0.0F); + this.setDead(); + } + } + } + } +} diff --git a/src/main/java/chanceCubes/blocks/BlockGiantCube.java b/src/main/java/chanceCubes/blocks/BlockGiantCube.java new file mode 100644 index 0000000..80f382b --- /dev/null +++ b/src/main/java/chanceCubes/blocks/BlockGiantCube.java @@ -0,0 +1,153 @@ +package chanceCubes.blocks; + +import static team.chisel.ctmlib.Dir.BOTTOM; +import static team.chisel.ctmlib.Dir.LEFT; +import static team.chisel.ctmlib.Dir.RIGHT; +import static team.chisel.ctmlib.Dir.TOP; + +import java.util.Random; + +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CCubesSettings; +import chanceCubes.items.CCubesItems; +import chanceCubes.registry.GiantCubeRegistry; +import chanceCubes.tileentities.TileGiantCube; +import chanceCubes.util.CCubesAchievements; +import chanceCubes.util.GiantCubeUtil; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import team.chisel.ctmlib.CTM; +import team.chisel.ctmlib.TextureSubmap; + +public class BlockGiantCube extends BaseChanceBlock implements ITileEntityProvider { + + public static final String blockName = "Giant_Chance_Cube"; + + @SideOnly(Side.CLIENT) + private TextureSubmap[] subMap; + @SideOnly(Side.CLIENT) + private TextureSubmap[] specialIcons; + + public BlockGiantCube() { + super("Giant_Chance_Cube"); + this.setBlockTextureName("chancecubes:chanceCube"); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileGiantCube(); + } + + @Override + public int quantityDropped(Random p_149745_1_) { + return 0; + } + + @Override + public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { + if (!world.isRemote && player != null && !(player instanceof FakePlayer)) { + TileGiantCube te = (TileGiantCube) world.getTileEntity(x, y, z); + if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem() + .getItem() + .equals(CCubesItems.silkPendant)) { + ItemStack stack = new ItemStack(Item.getItemFromBlock(CCubesBlocks.chanceCompactGiantCube), 1); + this.dropBlockAsItem(world, x, y, z, stack); + GiantCubeUtil.removeStructure(te.getMasterX(), te.getMasterY(), te.getMasterZ(), world); + return true; + } + if (te != null) { + if (!te.hasMaster()) { + world.setBlockToAir(x, y, z); + return false; + } + // player.addChatMessage(new ChatComponentText("The Giant Cube and rewards are currently In + // developement")); + // player.addChatMessage(new ChatComponentText("Please let me know what you think of the idea and leave + // sugestions!")); + player.triggerAchievement(CCubesAchievements.GiantChanceCube); + GiantCubeRegistry.INSTANCE + .triggerRandomReward(world, te.getMasterX(), te.getMasterY(), te.getMasterZ(), player, 0); + GiantCubeUtil.removeStructure(te.getMasterX(), te.getMasterY(), te.getMasterZ(), world); + } + } + return true; + } + + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) { + this.subMap = new TextureSubmap[6]; + this.subMap[0] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_1"), 3, 3); + this.subMap[1] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_6"), 3, 3); + this.subMap[2] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_2"), 3, 3); + this.subMap[3] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_5"), 3, 3); + this.subMap[4] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_4"), 3, 3); + this.subMap[5] = new TextureSubmap(register.registerIcon(CCubesCore.MODID + ":chancecube_face_3"), 3, 3); + if (CCubesSettings.hasHolidayTexture) { + this.specialIcons = new TextureSubmap[6]; + String texture = CCubesSettings.holidayTextureName; + this.specialIcons[0] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_1"), + 3, + 3); + this.specialIcons[1] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_6"), + 3, + 3); + this.specialIcons[2] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_2"), + 3, + 3); + this.specialIcons[3] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_5"), + 3, + 3); + this.specialIcons[4] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_4"), + 3, + 3); + this.specialIcons[5] = new TextureSubmap( + register.registerIcon(CCubesCore.MODID + ":" + texture + "_face_3"), + 3, + 3); + } + } + + @Override + public IIcon getIcon(int side, int meta) { + if (CCubesSettings.hasHolidayTexture) return this.specialIcons[side].getBaseIcon(); + else return this.subMap[side].getBaseIcon(); + } + + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + CTM ctm = CTM.getInstance(); + ctm.buildConnectionMap(world, x, y, z, side, CCubesBlocks.chanceGiantCube, 0); + + if (ctm.connectedAnd(TOP, RIGHT, BOTTOM, LEFT)) return this.getIconAt(side, 1, 1); + else if (ctm.connectedAnd(TOP, BOTTOM, RIGHT)) return this.getIconAt(side, 0, 1); + else if (ctm.connectedAnd(LEFT, RIGHT, BOTTOM)) return this.getIconAt(side, 1, 0); + else if (ctm.connectedAnd(LEFT, RIGHT, TOP)) return this.getIconAt(side, 1, 2); + else if (ctm.connectedAnd(LEFT, BOTTOM, TOP)) return this.getIconAt(side, 2, 1); + else if (ctm.connectedAnd(BOTTOM, RIGHT)) return this.getIconAt(side, 0, 0); + else if (ctm.connectedAnd(TOP, RIGHT)) return this.getIconAt(side, 0, 2); + else if (ctm.connectedAnd(LEFT, BOTTOM)) return this.getIconAt(side, 2, 0); + else if (ctm.connectedAnd(LEFT, TOP)) return this.getIconAt(side, 2, 2); + else return this.getIconAt(side, 1, 1); + } + + public IIcon getIconAt(int side, int x, int y) { + if (CCubesSettings.hasHolidayTexture) return this.specialIcons[side].getSubIcon(x, y); + else return this.subMap[side].getSubIcon(x, y); + } +} diff --git a/src/main/java/chanceCubes/blocks/CCubesBlocks.java b/src/main/java/chanceCubes/blocks/CCubesBlocks.java new file mode 100644 index 0000000..a410487 --- /dev/null +++ b/src/main/java/chanceCubes/blocks/CCubesBlocks.java @@ -0,0 +1,34 @@ +package chanceCubes.blocks; + +import chanceCubes.items.ItemChanceCube; +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.tileentities.TileChanceD20; +import chanceCubes.tileentities.TileCubeDispenser; +import chanceCubes.tileentities.TileGiantCube; +import cpw.mods.fml.common.registry.GameRegistry; + +public class CCubesBlocks { + + public static BaseChanceBlock chanceCube; + public static BaseChanceBlock chanceIcosahedron; + public static BaseChanceBlock chanceGiantCube; + public static BaseChanceBlock chanceCompactGiantCube; + public static BaseChanceBlock chanceCubeDispenser; + + public static void loadBlocks() { + GameRegistry.registerBlock(chanceCube = new BlockChanceCube(), ItemChanceCube.class, chanceCube.getBlockName()); + GameRegistry.registerBlock( + chanceIcosahedron = new BlockChanceD20(), + ItemChanceCube.class, + chanceIcosahedron.getBlockName()); + GameRegistry.registerBlock(chanceGiantCube = new BlockGiantCube(), chanceGiantCube.getBlockName()); + GameRegistry + .registerBlock(chanceCompactGiantCube = new BlockCompactGiantCube(), chanceCompactGiantCube.getBlockName()); + GameRegistry.registerBlock(chanceCubeDispenser = new BlockCubeDispenser(), chanceCubeDispenser.getBlockName()); + + GameRegistry.registerTileEntity(TileChanceCube.class, "tileChanceCube"); + GameRegistry.registerTileEntity(TileChanceD20.class, "tileChanceIcosahedron"); + GameRegistry.registerTileEntity(TileGiantCube.class, "tileChanceGiant"); + GameRegistry.registerTileEntity(TileCubeDispenser.class, "tileCubeDispenser"); + } +} diff --git a/src/main/java/chanceCubes/client/gui/CCubesGuiHandler.java b/src/main/java/chanceCubes/client/gui/CCubesGuiHandler.java new file mode 100644 index 0000000..7094e00 --- /dev/null +++ b/src/main/java/chanceCubes/client/gui/CCubesGuiHandler.java @@ -0,0 +1,42 @@ +package chanceCubes.client.gui; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.containers.CreativePendantContainer; +import chanceCubes.items.CCubesItems; +import cpw.mods.fml.common.network.IGuiHandler; + +public class CCubesGuiHandler implements IGuiHandler { + + public final static int CREATIVE_PENDANT_ID = 0; + public final static int REWARD_SELECTOR_PENDANT_ID = 1; + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) { + case CREATIVE_PENDANT_ID: + if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem() + .getItem() + .equals(CCubesItems.creativePendant)) return new CreativePendantGui(player, world); + break; + default: + return null; + } + return null; + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) { + case CREATIVE_PENDANT_ID: + if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem() + .getItem() + .equals(CCubesItems.creativePendant)) return new CreativePendantContainer(player.inventory, world); + break; + default: + return null; + } + return null; + } +} diff --git a/src/main/java/chanceCubes/client/gui/ConfigGui.java b/src/main/java/chanceCubes/client/gui/ConfigGui.java new file mode 100644 index 0000000..3229534 --- /dev/null +++ b/src/main/java/chanceCubes/client/gui/ConfigGui.java @@ -0,0 +1,610 @@ +package chanceCubes.client.gui; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiListExtended.IGuiListEntry; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; + +import org.apache.logging.log4j.Level; +import org.lwjgl.input.Keyboard; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import chanceCubes.CCubesCore; +import chanceCubes.client.gui.CustomExtendedList.CustomTextEntry; +import chanceCubes.config.CustomRewardsLoader; +import chanceCubes.rewards.rewardparts.ChestChanceItem; +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.rewards.rewardparts.EntityPart; +import chanceCubes.rewards.rewardparts.ExpirencePart; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.ParticlePart; +import chanceCubes.rewards.rewardparts.PotionPart; +import chanceCubes.rewards.rewardparts.SoundPart; + +public class ConfigGui extends GuiScreen { + + private ConfigEditState editState; + private boolean isCreatingNew = false; + private boolean isDeleting = false; + private GuiButton buttonNew; + private GuiButton buttonSave; + // private GuiButton buttonDelete; + private GuiButton buttonCancel; + private GuiButton buttonback; + private String buttonNewText = "New File"; + private String deleteWarnText = "WARNING YOU ARE DELETING EVERYTHING YOU CLICK!!"; + private GuiTextField textFieldNew; + + private String[] prevStage = new String[4]; + private String drawString = ""; + + private CustomExtendedList entries; + + private JsonParser json; + private Gson gson; + + private GuiScreen parentScreen; + + public ConfigGui(GuiScreen screen) { + json = new JsonParser(); + + gson = new GsonBuilder().setPrettyPrinting() + .create(); + + parentScreen = screen; + } + + @SuppressWarnings("unchecked") + public void initGui() { + editState = ConfigEditState.Files; + + this.buttonList.clear(); + Keyboard.enableRepeatEvents(true); + + this.buttonList.add(buttonback = new GuiButton(0, this.width / 2 - 175, this.height - 55, 98, 20, "Back")); + this.buttonList + .add(this.buttonNew = new GuiButton(1, this.width / 2 - 50, this.height - 25, 100, 20, buttonNewText)); + this.buttonList + .add(this.buttonCancel = new GuiButton(2, this.width / 2 - 50, this.height - 55, 100, 20, "Cancel")); + this.buttonList.add(this.buttonSave = new GuiButton(3, this.width / 2 - 50, this.height - 25, 100, 20, "Save")); + // this.buttonList.add(this.buttonDelete = new GuiButton(4, this.width / 2 - 175, this.height - 25, 98, 20, + // "Delete")); + buttonCancel.visible = false; + textFieldNew = new GuiTextField(mc.fontRenderer, this.width - 250, this.height - 40, 200, 20); + + entries = new CustomExtendedList(this, this.mc, this.width, this.height, 32, this.height - 64, 36); + + loadFiles(); + } + + public void onGuiClosed() { + CustomRewardsLoader.instance.loadCustomRewards(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + entries.drawScreen(mouseX, mouseY, partialTicks); + super.drawScreen(mouseX, mouseY, partialTicks); + if (this.isCreatingNew) this.textFieldNew.drawTextBox(); + if (this.isDeleting) mc.fontRenderer.drawString( + this.deleteWarnText, + this.width / 2 - (int) (deleteWarnText.length() * 2.5), + this.height / 2, + 0xFF0000); + mc.fontRenderer.drawString(this.drawString, this.width / 2 - (int) (drawString.length() * 2.5), 10, 0xFFFFFF); + } + + protected void actionPerformed(GuiButton button) { + if (button.enabled) { + if (button.id == 0) { + this.prevEditStage(); + } else if (button.id == 1) { + if (this.isCreatingNew) { + buttonNew.displayString = this.buttonNewText; + File file = null; + JsonElement fileJson = new JsonObject(); + switch (editState) { + case Files: { + String fileName = this.textFieldNew.getText(); + if (!fileName.contains(".json")) fileName += ".json"; + file = new File( + CustomRewardsLoader.instance.getFolderFile() + .getAbsolutePath() + "/" + fileName); + try { + file.createNewFile(); + } catch (IOException e) { + CCubesCore.logger + .log(Level.ERROR, "Failed to create the new file for a custom reward!"); + e.printStackTrace(); + return; + } + break; + } + case All_Rewards: { + String rewardName = this.textFieldNew.getText(); + file = new File( + CustomRewardsLoader.instance.getFolderFile() + .getAbsolutePath() + "/" + this.prevStage[0]); + if (!file.exists()) { + CCubesCore.logger.log(Level.ERROR, "Failed to find the file to edit a reward"); + return; + } + + fileJson = json.parse(this.loadFileContents(file)); + JsonObject newRewardJson = new JsonObject(); + newRewardJson.addProperty("Chance", 0); + fileJson.getAsJsonObject() + .add(rewardName, newRewardJson); + break; + } + case Single_Reward: { + String rewardType = this.textFieldNew.getText(); + file = new File( + CustomRewardsLoader.instance.getFolderFile() + .getAbsolutePath() + "/" + this.prevStage[0]); + if (!file.exists()) { + CCubesCore.logger.log(Level.ERROR, "Failed to find the file to edit a reward"); + return; + } + + fileJson = json.parse(this.loadFileContents(file)); + JsonElement rewardJson = fileJson.getAsJsonObject() + .get(this.prevStage[1]); + if (rewardJson == null) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to find the reward with the given name of " + this.prevStage[1]); + return; + } + + JsonArray rewardTypeArray = new JsonArray(); + rewardJson.getAsJsonObject() + .add(rewardType, rewardTypeArray); + break; + } + case Reward_Type: { + String defaultValue = this.textFieldNew.getText(); + file = new File( + CustomRewardsLoader.instance.getFolderFile() + .getAbsolutePath() + "/" + this.prevStage[0]); + if (!file.exists()) { + CCubesCore.logger.log(Level.ERROR, "Failed to find the file to edit a reward"); + return; + } + fileJson = json.parse(this.loadFileContents(file)); + JsonElement rewardJson = fileJson.getAsJsonObject() + .get(this.prevStage[1]); + if (rewardJson == null) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to find the reward with the given name of " + this.prevStage[1]); + return; + } + + JsonArray rewardTypeArray = rewardJson.getAsJsonObject() + .get(this.prevStage[2]) + .getAsJsonArray(); + JsonObject rewardInstance = new JsonObject(); + rewardInstance.addProperty(this.prevStage[2].toLowerCase(), defaultValue); + rewardTypeArray.add(rewardInstance); + break; + } + case Edit_Reward_Type: { + break; + } + } + + try { + FileOutputStream outputStream = new FileOutputStream(file); + OutputStreamWriter writer = new OutputStreamWriter(outputStream); + writer.append(gson.toJson(fileJson)); + writer.close(); + outputStream.close(); + } catch (IOException e) { + CCubesCore.logger.log(Level.ERROR, "Failed to create the new file for a custom reward!"); + e.printStackTrace(); + return; + } + + this.textFieldNew.setText(""); + // buttonDelete.visible = true; + buttonCancel.visible = false; + buttonback.enabled = true; + this.reloadStage(); + } else { + buttonNew.displayString = "Create"; + // buttonDelete.visible = false; + buttonCancel.visible = true; + buttonback.enabled = false; + } + this.isCreatingNew = !this.isCreatingNew; + } else if (button.id == 2) { + if (this.isCreatingNew) { + this.isCreatingNew = false; + this.buttonNew.displayString = this.buttonNewText; + // this.buttonDelete.visible = true; + this.buttonCancel.visible = false; + this.buttonback.enabled = true; + } else if (this.isDeleting) { + this.isDeleting = false; + // this.buttonDelete.enabled = true; + this.buttonCancel.visible = false; + this.buttonback.enabled = true; + this.buttonNew.enabled = true; + } + } else if (button.id == 3) { + File file = null; + JsonElement fileJson = new JsonObject(); + file = new File( + CustomRewardsLoader.instance.getFolderFile() + .getAbsolutePath() + "/" + this.prevStage[0]); + if (!file.exists()) { + CCubesCore.logger.log(Level.ERROR, "Failed to find the file to edit a reward"); + return; + } + fileJson = json.parse(this.loadFileContents(file)); + JsonElement rewardJson = fileJson.getAsJsonObject() + .get(this.prevStage[1]); + if (rewardJson == null) { + CCubesCore.logger + .log(Level.ERROR, "Failed to find the reward with the given name of " + this.prevStage[1]); + return; + } + + if (this.entries.getListEntry(0) instanceof CustomTextEntry + && ((CustomTextEntry) this.entries.getListEntry(0)).getLabel() + .equalsIgnoreCase("Chance:")) { + CustomTextEntry textBox = (CustomTextEntry) this.entries.getListEntry(0); + try { + int chance = Integer.parseInt( + textBox.getTextBox() + .getText()); + if (chance < -100) chance = -100; + else if (chance > 100) chance = 100; + rewardJson.getAsJsonObject() + .addProperty("Chance", chance); + } catch (NumberFormatException e) { + CCubesCore.logger + .log(Level.ERROR, "Failed to cast the chance value of the reward to an integer"); + return; + } + try { + FileOutputStream outputStream = new FileOutputStream(file); + OutputStreamWriter writer = new OutputStreamWriter(outputStream); + writer.append(gson.toJson(fileJson)); + writer.close(); + outputStream.close(); + } catch (IOException e) { + CCubesCore.logger.log(Level.ERROR, "Failed to create the new file for a custom reward!"); + e.printStackTrace(); + return; + } + } else { + this.saveRewardPart(file, fileJson, rewardJson); + } + + this.textFieldNew.setText(""); + buttonCancel.visible = false; + // buttonDelete.visible = true; + buttonback.enabled = true; + this.reloadStage(); + } else if (button.id == 4) { + this.isDeleting = true; + // this.buttonDelete.enabled = false; + this.buttonCancel.visible = true; + this.buttonback.enabled = false; + this.buttonNew.enabled = false; + } + } + } + + @Override + protected void mouseClicked(int x, int y, int mouseEvent) { + this.textFieldNew.mouseClicked(x, y, mouseEvent); + this.entries.func_148179_a(x, y, mouseEvent); + super.mouseClicked(x, y, mouseEvent); + } + + protected void keyTyped(char p_73869_1_, int p_73869_2_) { + if (!this.textFieldNew.textboxKeyTyped(p_73869_1_, p_73869_2_)) { + this.entries.keyTyped(p_73869_1_, p_73869_2_); + } + } + + public void nextEditStage(int id, String name) { + switch (editState) { + case Files: { + editState = ConfigEditState.All_Rewards; + this.loadFileRewards(name); + this.prevStage[0] = name; + break; + } + case All_Rewards: { + editState = ConfigEditState.Single_Reward; + this.loadSingleReward(name); + this.prevStage[1] = name; + break; + } + case Single_Reward: { + editState = ConfigEditState.Reward_Type; + this.loadRewardType(name); + this.prevStage[2] = name; + break; + } + case Reward_Type: { + editState = ConfigEditState.Edit_Reward_Type; + this.loadSpecificRewardType(name, this.prevStage[2]); + this.prevStage[3] = id + ":" + name; + break; + } + case Edit_Reward_Type: { + break; + } + } + } + + public void prevEditStage() { + switch (editState) { + case Files: { + this.mc.displayGuiScreen(this.parentScreen); + break; + } + case All_Rewards: { + editState = ConfigEditState.Files; + this.loadFiles(); + break; + } + case Single_Reward: { + editState = ConfigEditState.All_Rewards; + this.loadFileRewards(this.prevStage[0]); + break; + } + case Reward_Type: { + editState = ConfigEditState.Single_Reward; + this.loadSingleReward(this.prevStage[1]); + break; + } + case Edit_Reward_Type: { + editState = ConfigEditState.Reward_Type; + this.loadRewardType(this.prevStage[2]); + break; + } + } + } + + public void reloadStage() { + switch (editState) { + case Files: { + this.loadFiles(); + break; + } + case All_Rewards: { + this.loadFileRewards(this.prevStage[0]); + break; + } + case Single_Reward: { + this.loadSingleReward(this.prevStage[1]); + break; + } + case Reward_Type: { + this.loadRewardType(this.prevStage[2]); + break; + } + case Edit_Reward_Type: { + this.loadSpecificRewardType( + this.prevStage[3].substring(this.prevStage[3].indexOf(":") + 1), + this.prevStage[2]); + break; + } + } + } + + public void loadFiles() { + buttonSave.visible = false; + this.buttonNew.visible = true; + entries.clearElements(); + this.buttonNew.displayString = "New File"; + this.buttonNewText = "New File"; + drawString = "Select the file that you would like to load"; + for (String s : CustomRewardsLoader.instance.getRewardsFiles()) entries.addButton(s); + } + + public void loadFileRewards(String file) { + buttonSave.visible = false; + this.buttonNew.visible = true; + this.buttonNew.displayString = "New Reward"; + this.buttonNewText = "New Reward"; + drawString = "Select the reward that you would like to edit"; + entries.clearElements(); + for (String s : CustomRewardsLoader.instance.getRewardsFromFile(file)) entries.addButton(s); + } + + public void loadSingleReward(String reward) { + buttonSave.visible = false; + this.buttonNew.visible = true; + this.buttonNew.displayString = "New Part"; + this.buttonNewText = "New Part"; + drawString = "Select the reward type that you would like to edit"; + entries.clearElements(); + for (String s : CustomRewardsLoader.instance.getReward(this.prevStage[0], reward)) entries.addButton(s); + } + + public void loadRewardType(String type) { + buttonSave.visible = false; + this.buttonNew.visible = true; + this.buttonNew.displayString = "New " + type; + this.buttonNewText = "New " + type; + drawString = "Select the specific reward part that you would like to edit"; + entries.clearElements(); + if (type.equalsIgnoreCase("Chance")) { + buttonSave.visible = true; + this.buttonNew.visible = false; + entries.addTextEntry( + "Chance", + CustomRewardsLoader.instance.getRewardType(this.prevStage[0], this.prevStage[1], type) + .get(0)); + } else { + for (String s : CustomRewardsLoader.instance.getRewardType(this.prevStage[0], this.prevStage[1], type)) + entries.addButton(s); + } + } + + public void loadSpecificRewardType(String rawJson, String type) { + buttonSave.visible = true; + this.buttonNew.visible = false; + drawString = "Edit your reward parts"; + entries.clearElements(); + JsonObject convertedJson; + try { + convertedJson = json.parse(rawJson) + .getAsJsonObject(); + } catch (Exception e) { + CCubesCore.logger.log(Level.ERROR, "Unable to parse the file "); + return; + } + + if (type.equalsIgnoreCase("Item")) this.loadRewardPart(convertedJson, ItemPart.elements); + else if (type.equalsIgnoreCase("Block")) this.loadRewardPart(convertedJson, OffsetBlock.elements); + else if (type.equalsIgnoreCase("Message")) this.loadRewardPart(convertedJson, MessagePart.elements); + else if (type.equalsIgnoreCase("Command")) this.loadRewardPart(convertedJson, CommandPart.elements); + else if (type.equalsIgnoreCase("Entity")) this.loadRewardPart(convertedJson, EntityPart.elements); + else if (type.equalsIgnoreCase("Experience")) this.loadRewardPart(convertedJson, ExpirencePart.elements); + else if (type.equalsIgnoreCase("Potion")) this.loadRewardPart(convertedJson, PotionPart.elements); + else if (type.equalsIgnoreCase("Schematic")) + this.loadRewardPart(convertedJson, new String[] { "fileName:S", "delay:I" }); + else if (type.equalsIgnoreCase("Sound")) this.loadRewardPart(convertedJson, SoundPart.elements); + else if (type.equalsIgnoreCase("Chest")) this.loadRewardPart(convertedJson, ChestChanceItem.elements); + else if (type.equalsIgnoreCase("Particle")) this.loadRewardPart(convertedJson, ParticlePart.elements); + + } + + public enum ConfigEditState { + + Files(0), + All_Rewards(1), + Single_Reward(2), + Reward_Type(3), + Edit_Reward_Type(4); + + private int posNum; + + ConfigEditState(int pos) { + this.posNum = pos; + } + + public int getPosition() { + return this.posNum; + } + } + + public void loadRewardPart(JsonObject convertedJson, String[] parts) { + for (String s : parts) { + s = s.substring(0, s.length() - 2); + String value = ""; + if (convertedJson.has(s)) value = convertedJson.get(s) + .getAsString(); + entries.addTextEntry(s, value); + } + } + + public void saveRewardPart(File file, JsonElement fileJson, JsonElement rewardJson) { + JsonArray rewardTypeArray = rewardJson.getAsJsonObject() + .get(this.prevStage[2]) + .getAsJsonArray(); + JsonObject rewardInstance = rewardTypeArray + .get(Integer.parseInt(this.prevStage[3].substring(0, this.prevStage[3].indexOf(":")))) + .getAsJsonObject(); + String[] rewardElements = this.getsElementsFromReward(this.prevStage[2]); + for (int i = 0; i < this.entries.getSize(); i++) { + IGuiListEntry entry = this.entries.getListEntry(i); + if (entry instanceof CustomTextEntry) { + CustomTextEntry textBox = (CustomTextEntry) entry; + try { + for (String s : rewardElements) { + String s1 = s.substring(0, s.length() - 2); + String s2 = s.substring(s.length() - 1); + String label = textBox.getLabel() + .substring( + 0, + textBox.getLabel() + .length() - 1); + String value = textBox.getTextBox() + .getText(); + if (value.equalsIgnoreCase("")) continue; + if (s1.equalsIgnoreCase(label)) { + if (s2.equalsIgnoreCase("I")) rewardInstance.addProperty(label, Integer.parseInt(value)); + if (s2.equalsIgnoreCase("S")) rewardInstance.addProperty(label, value); + if (s2.equalsIgnoreCase("B")) + rewardInstance.addProperty(label, Boolean.parseBoolean(value)); + } + } + } catch (Exception e) { + CCubesCore.logger.log( + Level.ERROR, + "An error has occured while saving this reward! Please make sure all fields are correctly filled!"); + } + + } + } + this.prevStage[3] = this.prevStage[3].substring(0, this.prevStage[3].indexOf(":") + 1) + + rewardInstance.toString(); + try { + FileOutputStream outputStream = new FileOutputStream(file); + OutputStreamWriter writer = new OutputStreamWriter(outputStream); + writer.append(gson.toJson(fileJson)); + writer.close(); + outputStream.close(); + } catch (IOException e) { + CCubesCore.logger.log(Level.ERROR, "Failed to create the new file for a custom reward!"); + e.printStackTrace(); + return; + } + } + + public String[] getsElementsFromReward(String reward) { + if (reward.equalsIgnoreCase("Item")) return ItemPart.elements; + else if (reward.equalsIgnoreCase("Block")) return OffsetBlock.elements; + else if (reward.equalsIgnoreCase("Message")) return MessagePart.elements; + else if (reward.equalsIgnoreCase("Command")) return CommandPart.elements; + else if (reward.equalsIgnoreCase("Entity")) return EntityPart.elements; + else if (reward.equalsIgnoreCase("Experience")) return ExpirencePart.elements; + else if (reward.equalsIgnoreCase("Potion")) return PotionPart.elements; + else if (reward.equalsIgnoreCase("Schematic")) return new String[] { "fileName:S", "delay:I" }; + else if (reward.equalsIgnoreCase("Sound")) return SoundPart.elements; + else if (reward.equalsIgnoreCase("Chest")) return ChestChanceItem.elements; + return new String[0]; + } + + public String loadFileContents(File file) { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); + String result = ""; + String line = ""; + while ((line = reader.readLine()) != null) { + result += line; + } + reader.close(); + return result; + } catch (IOException e) { + return ""; + } + + } +} diff --git a/src/main/java/chanceCubes/client/gui/CreativePendantGui.java b/src/main/java/chanceCubes/client/gui/CreativePendantGui.java new file mode 100644 index 0000000..8b0e2d5 --- /dev/null +++ b/src/main/java/chanceCubes/client/gui/CreativePendantGui.java @@ -0,0 +1,93 @@ +package chanceCubes.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.containers.CreativePendantContainer; +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.network.PacketCreativePendant; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class CreativePendantGui extends GuiContainer { + + private static final ResourceLocation guiTextures = new ResourceLocation( + CCubesCore.MODID + ":textures/gui/container/guiCreativePendant.png"); + private int chanceValue = 0; + private static CreativePendantContainer container; + private EntityPlayer player; + + public CreativePendantGui(EntityPlayer player, World world) { + super(container = new CreativePendantContainer(player.inventory, world)); + this.xSize = 176; + this.ySize = 167; + this.player = player; + } + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + @SuppressWarnings("unchecked") + public void initGui() { + super.initGui(); + this.buttonList.clear(); + this.buttonList.add( + new GuiButton(0, this.width / 2 - 40, (this.height / 2) - 63, 20, 20, I18n.format("-1", new Object[0]))); + this.buttonList.add( + new GuiButton(1, this.width / 2 + 15, (this.height / 2) - 63, 20, 20, I18n.format("+1", new Object[0]))); + this.buttonList.add( + new GuiButton(2, this.width / 2 - 60, (this.height / 2) - 63, 20, 20, I18n.format("-5", new Object[0]))); + this.buttonList.add( + new GuiButton(3, this.width / 2 + 35, (this.height / 2) - 63, 20, 20, I18n.format("+5", new Object[0]))); + this.buttonList.add( + new GuiButton(4, this.width / 2 - 80, (this.height / 2) - 63, 20, 20, I18n.format("-10", new Object[0]))); + this.buttonList.add( + new GuiButton(5, this.width / 2 + 55, (this.height / 2) - 63, 20, 20, I18n.format("+10", new Object[0]))); + this.buttonList.add( + new GuiButton( + 6, + this.width / 2 + 12, + (this.height / 2) - 35, + 70, + 20, + I18n.format("Set Chance", new Object[0]))); + } + + protected void actionPerformed(GuiButton button) { + if (button.id == 0) this.chanceValue -= 1; + else if (button.id == 1) this.chanceValue += 1; + else if (button.id == 2) this.chanceValue -= 5; + else if (button.id == 3) this.chanceValue += 5; + else if (button.id == 4) this.chanceValue -= 10; + else if (button.id == 5) this.chanceValue += 10; + else if (button.id == 6 && container.getChanceCubesInPendant() != null) CCubesPacketHandler.INSTANCE + .sendToServer(new PacketCreativePendant(this.player.getCommandSenderName(), this.chanceValue)); + + if (this.chanceValue > 100) this.chanceValue = 100; + if (this.chanceValue < -100) this.chanceValue = -100; + } + + @Override + protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { + this.fontRendererObj.drawString("Chance Value", 50, 5, 0); + String cValue = "" + this.chanceValue; + this.fontRendererObj.drawString(cValue, (88 - (cValue.length() * 3)), 27, 0); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + Minecraft.getMinecraft() + .getTextureManager() + .bindTexture(guiTextures); + int k = (this.width - this.xSize) / 2; + int l = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(k, l, 0, 0, xSize, ySize); + } +} diff --git a/src/main/java/chanceCubes/client/gui/CustomExtendedList.java b/src/main/java/chanceCubes/client/gui/CustomExtendedList.java new file mode 100644 index 0000000..f308212 --- /dev/null +++ b/src/main/java/chanceCubes/client/gui/CustomExtendedList.java @@ -0,0 +1,148 @@ +package chanceCubes.client.gui; + +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiListExtended; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.renderer.Tessellator; + +import com.google.common.collect.Lists; + +public class CustomExtendedList extends GuiListExtended { + + public List elements = Lists.newArrayList(); + + private Minecraft mc; + private ConfigGui parentScreen; + + public CustomExtendedList(ConfigGui parentScreen, Minecraft mc, int p_i45010_2_, int p_i45010_3_, int p_i45010_4_, + int p_i45010_5_, int p_i45010_6_) { + super(mc, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_); + this.parentScreen = parentScreen; + this.mc = mc; + } + + @Override + public IGuiListEntry getListEntry(int index) { + return elements.get(index); + } + + @Override + protected int getSize() { + return elements.size(); + } + + public void addButton(String e) { + elements.add(new CustomListEntry(e, parentScreen, mc, elements.size())); + } + + public void addTextEntry(String label, String textBoxText) { + elements.add(new CustomTextEntry(parentScreen, mc, label, textBoxText)); + } + + public void clearElements() { + elements.clear(); + } + + protected void keyTyped(char p_73869_1_, int p_73869_2_) { + for (IGuiListEntry entry : elements) + if (entry instanceof CustomTextEntry) ((CustomTextEntry) entry).keyTyped(p_73869_1_, p_73869_2_); + } + + @Override + public boolean func_148179_a(int x, int y, int mouseEvent) { + super.func_148179_a(x, y, mouseEvent); + for (IGuiListEntry entry : elements) + if (entry instanceof CustomTextEntry) ((CustomTextEntry) entry).mousePressed(0, x, y, mouseEvent, 0, 0); + return true; + } + + public class CustomListEntry implements IGuiListEntry { + + private String name; + private GuiButton button; + private ConfigGui parentScreen; + private Minecraft mc; + + public CustomListEntry(String name, ConfigGui parentScreen, Minecraft mc, int id) { + this.name = name; + this.parentScreen = parentScreen; + button = new GuiButton(id, 0, 0, 200, 20, name); + this.mc = mc; + } + + @Override + public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, Tessellator tessellator, + int mouseX, int mouseY, boolean isSelected) { + this.button.displayString = name; + this.button.xPosition = x; + this.button.yPosition = y; + // this.button.enabled = enabled(); + this.button.drawButton(mc, mouseX, mouseY); + } + + @Override + public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY) { + if (this.button.mousePressed(mc, x, y)) parentScreen.nextEditStage(button.id, button.displayString); + return false; + } + + @Override + public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY) { + + } + } + + public class CustomTextEntry implements IGuiListEntry { + + private GuiTextField text; + @SuppressWarnings("unused") + private ConfigGui parentScreen; + private Minecraft mc; + private String label; + + public CustomTextEntry(ConfigGui parentScreen, Minecraft mc, String label, String textBoxText) { + this.parentScreen = parentScreen; + text = new GuiTextField(mc.fontRenderer, 0, 0, 200, 20); + text.setMaxStringLength(1000); + text.setText(textBoxText); + this.mc = mc; + this.label = label + ":"; + } + + @Override + public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, Tessellator tessellator, + int mouseX, int mouseY, boolean isSelected) { + this.text.xPosition = x + 30; + this.text.yPosition = y; + // this.button.enabled = enabled(); + this.text.drawTextBox(); + mc.fontRenderer.drawString(this.label, x - (int) (label.length() * 3), y + 7, 0xFFFFFF); + } + + @Override + public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY) { + text.mouseClicked(x, y, mouseEvent); + return false; + } + + @Override + public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY) { + + } + + public void keyTyped(char p_73869_1_, int p_73869_2_) { + this.text.textboxKeyTyped(p_73869_1_, p_73869_2_); + } + + public String getLabel() { + return this.label; + } + + public GuiTextField getTextBox() { + return this.text; + } + } +} diff --git a/src/main/java/chanceCubes/client/gui/RewardSelectorPendantGui.java b/src/main/java/chanceCubes/client/gui/RewardSelectorPendantGui.java new file mode 100644 index 0000000..933b948 --- /dev/null +++ b/src/main/java/chanceCubes/client/gui/RewardSelectorPendantGui.java @@ -0,0 +1,109 @@ +package chanceCubes.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import chanceCubes.CCubesCore; +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.network.PacketRewardSelector; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.registry.GiantCubeRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RewardSelectorPendantGui extends GuiScreen { + + private static final ResourceLocation guiTextures = new ResourceLocation( + CCubesCore.MODID + ":textures/gui/container/guiRewardSelectorPendant.png"); + private GuiTextField rewardField; + private String rewardName = ""; + private EntityPlayer player; + private int imageWidth = 176; + private int imageHeight = 54; + private ItemStack stack; + + public RewardSelectorPendantGui(EntityPlayer player, ItemStack stack) { + this.stack = stack; + this.player = player; + if (stack.getTagCompound() != null && stack.getTagCompound() + .hasKey("Reward")) + this.rewardName = stack.getTagCompound() + .getString("Reward"); + } + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + @SuppressWarnings("unchecked") + public void initGui() { + this.buttonList.clear(); + Keyboard.enableRepeatEvents(true); + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + this.rewardField = new GuiTextField(this.fontRendererObj, i + 17, j + 10, 143, 12); + this.rewardField.setTextColor(-1); + this.rewardField.setDisabledTextColour(-1); + this.rewardField.setEnableBackgroundDrawing(true); + this.rewardField.setMaxStringLength(100); + this.rewardField.setText(this.rewardName); + this.buttonList.add(new GuiButton(0, i + 57, j + 27, 70, 20, I18n.format("Set Reward", new Object[0]))); + } + + public void onGuiClosed() { + super.onGuiClosed(); + Keyboard.enableRepeatEvents(false); + } + + protected void actionPerformed(GuiButton button) { + if (button.enabled) { + if (button.id == 0) { + if (ChanceCubeRegistry.INSTANCE.getRewardByName(this.rewardField.getText()) != null + || GiantCubeRegistry.INSTANCE.getRewardByName(this.rewardField.getText()) != null) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) nbt = new NBTTagCompound(); + nbt.setString("Reward", this.rewardName); + stack.setTagCompound(nbt); + + CCubesPacketHandler.INSTANCE.sendToServer( + new PacketRewardSelector(this.player.getCommandSenderName(), this.rewardField.getText())); + rewardName = this.rewardField.getText(); + this.player.closeScreen(); + } else { + this.rewardField.setText("Invalid Name!"); + rewardName = ""; + } + } + } + } + + protected void keyTyped(char p_73869_1_, int p_73869_2_) { + if (!this.rewardField.textboxKeyTyped(p_73869_1_, p_73869_2_)) super.keyTyped(p_73869_1_, p_73869_2_); + } + + protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_) { + super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_); + this.rewardField.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_); + } + + public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) { + this.mc.getTextureManager() + .bindTexture(guiTextures); + int k = (this.width - this.imageWidth) / 2; + int l = (this.height - this.imageHeight) / 2; + this.drawTexturedModalRect(k, l, 0, 0, this.imageWidth, this.imageHeight); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_BLEND); + this.rewardField.drawTextBox(); + super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); + } +} diff --git a/src/main/java/chanceCubes/client/listeners/RenderEvent.java b/src/main/java/chanceCubes/client/listeners/RenderEvent.java new file mode 100644 index 0000000..8103a56 --- /dev/null +++ b/src/main/java/chanceCubes/client/listeners/RenderEvent.java @@ -0,0 +1,73 @@ +package chanceCubes.client.listeners; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class RenderEvent { + + private static boolean islookingAt = false; + private static int chance = -201; + private static int chanceIncrease = 0; + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onGuiRender(RenderGameOverlayEvent.Post event) { + if (event.type != ElementType.HELMET || event.isCancelable()) return; + + Minecraft mc = Minecraft.getMinecraft(); + + ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int k = scaledresolution.getScaledWidth(); + int l = scaledresolution.getScaledHeight(); + + FontRenderer fontrenderer = mc.fontRenderer; + + GL11.glPushMatrix(); + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glColor4f(1F, 1F, 1F, 1F); + + if (islookingAt) { + if (chance == -201) { + fontrenderer.drawString( + "The chance of this cube is: Destruction... Probably", + (k / 2) - 80, + (l / 2) - 30, + 16777215); + } else { + fontrenderer.drawString("The chance of this cube is: " + chance, (k / 2) - 80, (l / 2) - 30, 16777215); + if (chanceIncrease != 0) { + int c = chance + chanceIncrease; + fontrenderer.drawString( + "Chance with pendants is: " + (c > 100 ? 100 : c < -100 ? -100 : c), + (k / 2) - 80, + (l / 2) - 15, + 16777215); + } + } + } + + GL11.glPopMatrix(); + } + + public static void setLookingAtChance(int c) { + chance = c; + } + + public static void setLookingAt(boolean lookingAt) { + islookingAt = lookingAt; + } + + public static void setChanceIncrease(int increase) { + chanceIncrease = increase; + } +} diff --git a/src/main/java/chanceCubes/client/listeners/WorldRenderListener.java b/src/main/java/chanceCubes/client/listeners/WorldRenderListener.java new file mode 100644 index 0000000..b2122ce --- /dev/null +++ b/src/main/java/chanceCubes/client/listeners/WorldRenderListener.java @@ -0,0 +1,81 @@ +package chanceCubes.client.listeners; + +import net.minecraft.entity.Entity; +import net.minecraftforge.client.event.RenderWorldLastEvent; + +import org.lwjgl.opengl.GL11; + +import chanceCubes.CCubesCore; +import chanceCubes.util.Location3I; +import chanceCubes.util.SchematicUtil; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class WorldRenderListener { + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onGuiRender(RenderWorldLastEvent event) { + if (SchematicUtil.selectionPoints[0] != null && SchematicUtil.selectionPoints[1] != null) { + GL11.glPushMatrix(); + + Entity entity = CCubesCore.proxy.getClientPlayer(); + double interpPosX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * event.partialTicks; + double interpPosY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * event.partialTicks; + double interpPosZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * event.partialTicks; + + GL11.glTranslated(-interpPosX, -interpPosY, -interpPosZ); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glLineWidth(1.5F); + GL11.glBegin(GL11.GL_LINES); + + Location3I pos1 = SchematicUtil.selectionPoints[0]; + Location3I pos2 = SchematicUtil.selectionPoints[1]; + int lowX = pos1.getX() < pos2.getX() ? pos1.getX() : pos2.getX(); + int highX = pos1.getX() > pos2.getX() ? pos1.getX() : pos2.getX(); + int lowY = pos1.getY() < pos2.getY() ? pos1.getY() : pos2.getY(); + int highY = pos1.getY() > pos2.getY() ? pos1.getY() : pos2.getY(); + int lowZ = pos1.getZ() < pos2.getZ() ? pos1.getZ() : pos2.getZ(); + int highZ = pos1.getZ() > pos2.getZ() ? pos1.getZ() : pos2.getZ(); + + GL11.glColor4d(0.9, 0.0, 0.5, 1); + + GL11.glVertex3d(lowX, lowY, lowZ); + GL11.glVertex3d(highX, lowY, lowZ); + GL11.glVertex3d(lowX, lowY, highZ); + GL11.glVertex3d(highX, lowY, highZ); + GL11.glVertex3d(lowX, highY, lowZ); + GL11.glVertex3d(highX, highY, lowZ); + GL11.glVertex3d(lowX, highY, highZ); + GL11.glVertex3d(highX, highY, highZ); + + GL11.glVertex3d(lowX, lowY, lowZ); + GL11.glVertex3d(lowX, lowY, highZ); + GL11.glVertex3d(highX, lowY, lowZ); + GL11.glVertex3d(highX, lowY, highZ); + GL11.glVertex3d(lowX, highY, lowZ); + GL11.glVertex3d(lowX, highY, highZ); + GL11.glVertex3d(highX, highY, lowZ); + GL11.glVertex3d(highX, highY, highZ); + + GL11.glVertex3d(lowX, lowY, lowZ); + GL11.glVertex3d(lowX, highY, lowZ); + GL11.glVertex3d(highX, lowY, lowZ); + GL11.glVertex3d(highX, highY, lowZ); + GL11.glVertex3d(lowX, lowY, highZ); + GL11.glVertex3d(lowX, highY, highZ); + GL11.glVertex3d(highX, lowY, highZ); + GL11.glVertex3d(highX, highY, highZ); + + GL11.glEnd(); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + GL11.glPopMatrix(); + } + } +} diff --git a/src/main/java/chanceCubes/commands/CCubesClientCommands.java b/src/main/java/chanceCubes/commands/CCubesClientCommands.java new file mode 100644 index 0000000..98933fe --- /dev/null +++ b/src/main/java/chanceCubes/commands/CCubesClientCommands.java @@ -0,0 +1,15 @@ +package chanceCubes.commands; + +import net.minecraft.command.ICommandSender; + +public class CCubesClientCommands extends CCubesServerCommands { + + public CCubesClientCommands() { + super(); + } + + @Override + public void processCommand(ICommandSender icommandsender, String[] astring) { + super.processCommand(icommandsender, astring); + } +} diff --git a/src/main/java/chanceCubes/commands/CCubesServerCommands.java b/src/main/java/chanceCubes/commands/CCubesServerCommands.java new file mode 100644 index 0000000..43ef0ce --- /dev/null +++ b/src/main/java/chanceCubes/commands/CCubesServerCommands.java @@ -0,0 +1,199 @@ +package chanceCubes.commands; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CustomRewardsLoader; +import chanceCubes.hookins.ModHookUtil; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.registry.GiantCubeRegistry; +import chanceCubes.util.Location3I; +import chanceCubes.util.SchematicUtil; +import cpw.mods.fml.common.registry.GameData; + +public class CCubesServerCommands implements ICommand { + + private List aliases; + List tab; + + public CCubesServerCommands() { + this.aliases = new ArrayList(); + this.aliases.add("Chancecubes"); + this.aliases.add("chancecubes"); + this.aliases.add("ChanceCube"); + this.aliases.add("Chancecube"); + this.aliases.add("chancecube"); + this.aliases.add("CCubes"); + + tab = new ArrayList(); + tab.add("reload"); + tab.add("version"); + tab.add("handNBT"); + } + + @Override + public String getCommandName() { + return "ChanceCubes"; + } + + @Override + public String getCommandUsage(ICommandSender icommandsender) { + return "/ChanceCubes "; + } + + @Override + public List getCommandAliases() { + return this.aliases; + } + + @Override + public void processCommand(ICommandSender icommandsender, String[] astring) { + if (astring.length > 0 && astring[0].equalsIgnoreCase("reload")) { + ChanceCubeRegistry.INSTANCE.ClearRewards(); + GiantCubeRegistry.INSTANCE.ClearRewards(); + ChanceCubeRegistry.loadDefaultRewards(); + GiantCubeRegistry.loadDefaultRewards(); + CustomRewardsLoader.instance.loadCustomRewards(); + CustomRewardsLoader.instance.fetchRemoteInfo(); + ChanceCubeRegistry.loadCustomUserRewards(); + ModHookUtil.loadCustomModRewards(); + icommandsender.addChatMessage(new ChatComponentText("Rewards Reloaded")); + } else if (astring.length > 0 && astring[0].equalsIgnoreCase("version")) { + icommandsender.addChatMessage(new ChatComponentText("Chance Cubes Version " + CCubesCore.VERSION)); + } else if (astring[0].equalsIgnoreCase("handNBT")) { + if (icommandsender instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) icommandsender; + if (player.inventory.getCurrentItem() != null) { + NBTTagCompound nbt = player.inventory.getCurrentItem().stackTagCompound; + if (nbt != null) icommandsender.addChatMessage(new ChatComponentText(nbt.toString())); + else icommandsender.addChatMessage(new ChatComponentText("This item has no tag nbt data")); + } + } + } else if (astring[0].equalsIgnoreCase("handID")) { + if (icommandsender instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) icommandsender; + ItemStack stack = player.inventory.getCurrentItem(); + if (stack != null) { + String info = GameData.getItemRegistry() + .getNameForObject(stack.getItem()); + if (info == null || info == "") info = GameData.getBlockRegistry() + .getNameForObject(stack.getItem()); + icommandsender.addChatMessage(new ChatComponentText(info)); + icommandsender.addChatMessage(new ChatComponentText("meta: " + stack.getItemDamage())); + } + } + } else if (astring[0].equalsIgnoreCase("disableReward")) { + if (astring.length > 1) { + if (ChanceCubeRegistry.INSTANCE.unregisterReward(astring[1])) icommandsender + .addChatMessage(new ChatComponentText(astring[1] + " Has been temporarily disabled.")); + else icommandsender.addChatMessage( + new ChatComponentText( + astring[1] + " is either not currently enabled or is not a valid reward name.")); + } else { + icommandsender.addChatMessage(new ChatComponentText("Try /chancecubes enableReward ")); + } + } else if (astring[0].equalsIgnoreCase("enableReward")) { + if (astring.length > 1) { + if (ChanceCubeRegistry.INSTANCE.enableReward(astring[1])) + icommandsender.addChatMessage(new ChatComponentText(astring[1] + " Has been enabled.")); + else icommandsender.addChatMessage( + new ChatComponentText( + astring[1] + " is either not currently disabled or is not a valid reward name.")); + } else { + icommandsender.addChatMessage(new ChatComponentText("Try /chancecubes disableReward ")); + } + } + if (astring[0].equalsIgnoreCase("schematic")) { + if (Minecraft.getMinecraft() + .isSingleplayer()) { + if (icommandsender instanceof EntityPlayer) { + World world = Minecraft.getMinecraft() + .getIntegratedServer() + .getEntityWorld(); + EntityPlayer player = (EntityPlayer) icommandsender; + if (player.capabilities.isCreativeMode) { + if (astring.length >= 3) { + if (astring[1].equalsIgnoreCase("setPoint")) { + if (astring[2].equalsIgnoreCase("1")) { + SchematicUtil.selectionPoints[0] = new Location3I( + (int) player.posX, + (int) player.posY - 1, + (int) player.posZ); + icommandsender.addChatMessage(new ChatComponentText("Point 1 set")); + } + if (astring[2].equalsIgnoreCase("2")) { + SchematicUtil.selectionPoints[1] = new Location3I( + (int) player.posX, + (int) player.posY - 1, + (int) player.posZ); + icommandsender.addChatMessage(new ChatComponentText("Point 2 set")); + } + } else if (astring[1].equalsIgnoreCase("create")) { + if (SchematicUtil.selectionPoints[0] == null + || SchematicUtil.selectionPoints[1] == null) { + icommandsender.addChatMessage(new ChatComponentText("Both points are not set!")); + return; + } + SchematicUtil.createCustomSchematic( + world, + SchematicUtil.selectionPoints[0], + SchematicUtil.selectionPoints[1], + astring[2].endsWith(".ccs") ? astring[2] : astring[2] + ".ccs"); + icommandsender.addChatMessage( + new ChatComponentText( + "Schematic file named " + + (astring[2].endsWith(".ccs") ? astring[2] : astring[2] + ".ccs") + + " created!")); + SchematicUtil.selectionPoints[0] = null; + SchematicUtil.selectionPoints[1] = null; + } + } else { + icommandsender.addChatMessage(new ChatComponentText("invalid arguments")); + } + } else { + icommandsender.addChatMessage( + new ChatComponentText("Sorry, you need to be in creative to use this command")); + } + } + } else { + icommandsender + .addChatMessage(new ChatComponentText("Sorry, but this command only works in single player")); + } + } else if (astring[0].equalsIgnoreCase("test")) { + + } + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { + return true; + } + + @SuppressWarnings("rawtypes") + @Override + public List addTabCompletionOptions(ICommandSender icommandsender, String[] astring) { + if (astring.length == 0) return tab; + return null; + } + + @Override + public boolean isUsernameIndex(String[] astring, int i) { + return false; + } + + @Override + public int compareTo(Object o) { + System.out.println("TESTING: " + o); + return 0; + } +} diff --git a/src/main/java/chanceCubes/config/CCubesSettings.java b/src/main/java/chanceCubes/config/CCubesSettings.java new file mode 100644 index 0000000..be0fbe5 --- /dev/null +++ b/src/main/java/chanceCubes/config/CCubesSettings.java @@ -0,0 +1,44 @@ +package chanceCubes.config; + +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; + +public class CCubesSettings { + + public static int d20RenderID = -1; + + public static int pendantUses = 32; + + public static boolean enableHardCodedRewards = true; + + public static int rangeMin = 20; + public static int rangeMax = 20; + public static boolean d20UseNormalChances = false; + + public static boolean oreGeneration = true; + public static int oreGenAmount = 4; + public static boolean surfaceGeneration = true; + public static int surfaceGenAmount = 1; + public static String[] blockedWorlds = new String[] {}; + public static boolean chestLoot = true; + public static boolean craftingRecipie = true; + public static boolean hiddenOverWorldCubes = false; + public static boolean hiddenNetherCubes = false; + public static boolean hiddenEndCubes = false; + + public static boolean userSpecificRewards = true; + public static boolean disabledRewards = true; + + public static boolean holidayRewards = true; + public static boolean holidayRewardTriggered = false; + public static boolean doesHolidayRewardTrigger = false; + public static IChanceCubeReward holidayReward = null; + public static boolean hasHolidayTexture = false; + public static String holidayTextureName = ""; + + public static int dropHeight = 20; + + public static boolean isBlockedWorld(String world) { + for (String blockedWorld : blockedWorlds) if (blockedWorld.equalsIgnoreCase(world)) return true; + return false; + } +} diff --git a/src/main/java/chanceCubes/config/ConfigGuiFactory.java b/src/main/java/chanceCubes/config/ConfigGuiFactory.java new file mode 100644 index 0000000..2d064bf --- /dev/null +++ b/src/main/java/chanceCubes/config/ConfigGuiFactory.java @@ -0,0 +1,33 @@ +package chanceCubes.config; + +import java.util.Set; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; + +import chanceCubes.client.gui.ConfigGui; +import cpw.mods.fml.client.IModGuiFactory; + +public class ConfigGuiFactory implements IModGuiFactory { + + @Override + public void initialize(Minecraft minecraftInstance) { + + } + + @Override + public Class mainConfigGuiClass() { + return ConfigGui.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } + +} diff --git a/src/main/java/chanceCubes/config/ConfigLoader.java b/src/main/java/chanceCubes/config/ConfigLoader.java new file mode 100644 index 0000000..2bc7f0f --- /dev/null +++ b/src/main/java/chanceCubes/config/ConfigLoader.java @@ -0,0 +1,146 @@ +package chanceCubes.config; + +import java.io.File; + +import net.minecraftforge.common.config.Configuration; + +public class ConfigLoader { + + public static Configuration config; + public static final String genCat = "General Settings"; + public static final String rewardCat = "Rewards"; + public static final String giantRewardCat = "Giant Chance Cube Rewards"; + + public static File folder; + + public static void loadConfigSettings(File file, File resources) { + folder = new File( + file.getParentFile() + .getAbsolutePath() + "/ChanceCubes"); + folder.mkdirs(); + config = new Configuration(new File(folder + "/" + file.getName())); + config.load(); + + config.setCategoryComment(rewardCat, "Set to false to disable a specific reward"); + + CCubesSettings.rangeMin = config.getInt( + "chanceRangeMin", + genCat, + 20, + 0, + 100, + "The minimum chance range value. Changes the range of chance that the chance block can pick from. i.e. If you have your range set to default 75. A chance cube with a chance value of 0 can get rewards of -75 to 75 in chance value."); + CCubesSettings.rangeMax = config.getInt( + "chanceRangeMax", + genCat, + 20, + 0, + 100, + "The maximum chance range value. Changes the range of chance that the chance block can pick from. i.e. If you have your range set to default 75. A chance cube with a chance value of 0 can get rewards of -75 to 75 in chance value."); + CCubesSettings.d20UseNormalChances = config.getBoolean( + "D20UseNormalChanceValues", + genCat, + false, + "Set to true if the D20's should have any chance value from -100 to 100. Set to false to have the D20's only have a chance value of either -100 or 100"); + + CCubesSettings.enableHardCodedRewards = config.getBoolean( + "EnableDefaultRewards", + genCat, + true, + "Set to true if the default rewards should be loaded, false if they shouldn't"); + + CCubesSettings.pendantUses = config + .getInt("pendantUses", genCat, CCubesSettings.pendantUses, 0, 1000, "Number of uses for a pendant"); + CCubesSettings.oreGeneration = config.getBoolean( + "GenerateAsOre", + genCat, + true, + "true if Chance Cubes should generate like ores with in the world. false if they should not"); + CCubesSettings.oreGenAmount = config + .getInt("oreGenAmount", genCat, 4, 1, 100, "Amount of chance cubes to try and spawn, per chunk, as an ore"); + CCubesSettings.surfaceGeneration = config.getBoolean( + "GenerateOnSurface", + genCat, + true, + "true if Chance Cubes should generate on the surface of the world. false if they should not"); + CCubesSettings.surfaceGenAmount = config.getInt( + "surfaceGenAmount", + genCat, + 1, + 0, + 100, + "Percentage chance of a chunk to have a chance cube spawned on the surface."); + CCubesSettings.blockedWorlds = config + .getStringList("BlockedWorlds", genCat, new String[0], "Worlds that Chance cubes shold not generate in"); + CCubesSettings.chestLoot = config.getBoolean( + "ChestLoot", + genCat, + true, + "true if Chance Cubes should generate as chest loot in the world. false if they should not"); + CCubesSettings.craftingRecipie = config.getBoolean( + "CraftingRecipe", + genCat, + true, + "true if Chance Cubes should have a crafting recipe. false if they should not"); + CCubesSettings.hiddenOverWorldCubes = config.getBoolean( + "HiddenOverWorldCubes", + genCat, + false, + "true if Chance Cubes should blend into it's enviroment in the over world"); + CCubesSettings.hiddenNetherCubes = config.getBoolean( + "HiddenNetherCubes", + genCat, + false, + "true if Chance Cubes should blend into it's enviroment in the nether"); + CCubesSettings.hiddenEndCubes = config.getBoolean( + "HiddenEndCubes", + genCat, + false, + "true if Chance Cubes should blend into it's enviroment in the end"); + + CCubesSettings.rangeMax = config.getInt( + "chanceRangeMax", + genCat, + 20, + 0, + 256, + "How many blocks above the Chance Cube that a block that will fall should be droped from"); + + CCubesSettings.userSpecificRewards = config.getBoolean( + "UserSpecificRewards", + genCat, + true, + "true if Chance Cubes should load in user specific rewards (for a select few only)"); + CCubesSettings.disabledRewards = config.getBoolean( + "GloballyDisabledRewards", + genCat, + true, + "true if Chance Cubes should check for globally disabled rewards (Rewards that are usually bugged or not working correctly). NOTE: The mod sends your Chance Cubes mod version to the web server to check for disabled rewards for your given version and the version number is subsequently logged. Feel free to make an inquiry if you wish to know more."); + CCubesSettings.holidayRewards = config.getBoolean( + "HolidayRewards", + genCat, + true, + "Set to false if you wish to disable the super special holiday rewards. Why would you want to do that?"); + CCubesSettings.holidayRewardTriggered = config.getBoolean( + "HolidayRewardTriggered", + genCat, + false, + "Don't touch! Well I mean you can touch it, if you want. I can't stop you. I'm only text."); + + config.save(); + + File customConfigFolder = new File( + file.getParentFile() + .getAbsolutePath() + "/ChanceCubes/CustomRewards"); + customConfigFolder.mkdirs(); + + new File( + file.getParentFile() + .getAbsolutePath() + "/ChanceCubes/CustomRewards/Schematics").mkdirs(); + new File( + file.getParentFile() + .getAbsolutePath() + "/ChanceCubes/CustomRewards/Sounds").mkdirs(); + + new CustomRewardsLoader(customConfigFolder, resources); + } +} diff --git a/src/main/java/chanceCubes/config/CustomRewardsLoader.java b/src/main/java/chanceCubes/config/CustomRewardsLoader.java new file mode 100644 index 0000000..a770f07 --- /dev/null +++ b/src/main/java/chanceCubes/config/CustomRewardsLoader.java @@ -0,0 +1,977 @@ +package chanceCubes.config; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; + +import org.apache.logging.log4j.Level; + +import com.google.common.collect.Lists; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import chanceCubes.CCubesCore; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.registry.GiantCubeRegistry; +import chanceCubes.rewards.defaultRewards.BasicReward; +import chanceCubes.rewards.rewardparts.ChestChanceItem; +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.rewards.rewardparts.EntityPart; +import chanceCubes.rewards.rewardparts.ExpirencePart; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.OffsetTileEntity; +import chanceCubes.rewards.rewardparts.ParticlePart; +import chanceCubes.rewards.rewardparts.PotionPart; +import chanceCubes.rewards.rewardparts.SoundPart; +import chanceCubes.rewards.type.BlockRewardType; +import chanceCubes.rewards.type.ChestRewardType; +import chanceCubes.rewards.type.CommandRewardType; +import chanceCubes.rewards.type.EntityRewardType; +import chanceCubes.rewards.type.ExperienceRewardType; +import chanceCubes.rewards.type.IRewardType; +import chanceCubes.rewards.type.ItemRewardType; +import chanceCubes.rewards.type.MessageRewardType; +import chanceCubes.rewards.type.ParticleEffectRewardType; +import chanceCubes.rewards.type.PotionRewardType; +import chanceCubes.rewards.type.SoundRewardType; +import chanceCubes.util.CustomEntry; +import chanceCubes.util.HTTPUtil; +import chanceCubes.util.SchematicUtil; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.registry.GameRegistry; + +public class CustomRewardsLoader { + + public static CustomRewardsLoader instance; + + private File folder; + private File source; + private static JsonParser json; + + public CustomRewardsLoader(File folder, File source) { + instance = this; + this.folder = folder; + this.source = source; + json = new JsonParser(); + + CustomSoundsLoader customSounds = new CustomSoundsLoader( + folder, + new File(folder.getAbsolutePath() + "/CustomSounds-Resourcepack"), + "Chance Cubes Resource Pack"); + customSounds.addCustomSounds(); + customSounds.assemble(); + } + + public void loadCustomRewards() { + for (File f : folder.listFiles()) { + if (!f.isFile() || !f.getName() + .contains(".json")) continue; + if (f.getName() + .substring( + f.getName() + .indexOf(".")) + .equalsIgnoreCase(".json")) { + JsonElement fileJson; + try { + CCubesCore.logger.log(Level.INFO, "Loading custom rewards file " + f.getName()); + fileJson = json.parse(new FileReader(f)); + } catch (Exception e) { + CCubesCore.logger + .log(Level.ERROR, "Unable to parse the file " + f.getName() + ". Skipping file loading."); + CCubesCore.logger.log(Level.ERROR, "Parse Error: " + e.getMessage()); + continue; + } + + for (Entry reward : fileJson.getAsJsonObject() + .entrySet()) { + CustomEntry parsedReward = this.parseReward(reward); + BasicReward basicReward = parsedReward.getKey(); + if (basicReward == null) { + CCubesCore.logger.log( + Level.ERROR, + "Seems your reward is setup incorrectly, or is disabled for this version of minecraft with a depedency, and Chance Cubes was not able to load the reward " + + reward.getKey() + + " for the file " + + f.getName()); + continue; + } + if (parsedReward.getValue()) GiantCubeRegistry.INSTANCE.registerReward(basicReward); + else ChanceCubeRegistry.INSTANCE.registerReward(basicReward); + } + CCubesCore.logger.log(Level.INFO, "Loaded custom rewards file " + f.getName()); + } + } + } + + public void fetchRemoteInfo() { + String rewardURL = "https://api.theprogrammingturkey.com/chance_cubes/ChanceCubesAPI.php"; + + try { + String today = new SimpleDateFormat("MM/dd").format(new Date()); + // String today = "12/25"; + JsonObject json = HTTPUtil + .getWebFile( + rewardURL, + new CustomEntry("version", CCubesCore.VERSION), + new CustomEntry("date", today)) + .getAsJsonObject(); + this.loadDisabledRewards( + json.get("Disabled Rewards") + .getAsJsonArray()); + this.loadHolidayRewards(json.get("Holiday Rewards")); + System.out.println(json.toString()); + + } catch (Exception e) { + CCubesCore.logger.log(Level.ERROR, "Failed to fetch remote information for the mod!"); + e.printStackTrace(); + return; + } + } + + private void loadHolidayRewards(JsonElement json) { + if (!CCubesSettings.holidayRewards || !json.isJsonObject()) return; + + JsonObject holidays = json.getAsJsonObject(); + if (holidays.has("Texture") && !(holidays.get("Texture") instanceof JsonNull)) { + CCubesSettings.hasHolidayTexture = true; + CCubesSettings.holidayTextureName = holidays.get("Texture") + .getAsString(); + } else { + CCubesSettings.hasHolidayTexture = false; + CCubesSettings.holidayTextureName = ""; + } + + if (!CCubesSettings.holidayRewardTriggered) { + if (holidays.has("Holiday") && !(holidays.get("Holiday") instanceof JsonNull) + && holidays.has("Reward") + && !(holidays.get("Reward") instanceof JsonNull)) { + String holidayName = holidays.get("Holiday") + .getAsString(); + BasicReward basicReward = this + .parseReward(new CustomEntry(holidayName, holidays.get("Reward"))) + .getKey(); + if (basicReward != null) { + CCubesSettings.doesHolidayRewardTrigger = true; + CCubesSettings.holidayReward = basicReward; + CCubesCore.logger.log(Level.ERROR, "Custom holiday reward \"" + holidayName + "\" loaded!"); + } else { + CCubesCore.logger + .log(Level.ERROR, "Failed to load the Custom holiday reward \"" + holidayName + "\"!"); + } + } + } + } + + private void loadDisabledRewards(JsonArray disabledRewards) { + if (CCubesSettings.disabledRewards) { + for (JsonElement reward : disabledRewards) { + boolean removed = ChanceCubeRegistry.INSTANCE.unregisterReward(reward.getAsString()); + if (!removed) removed = GiantCubeRegistry.INSTANCE.unregisterReward(reward.getAsString()); + CCubesCore.logger.log( + Level.WARN, + "The reward " + reward.getAsString() + + " has been disabled by the mod author due to a bug or some other reason."); + } + } + } + + public CustomEntry parseReward(Entry reward) { + List rewards = new ArrayList(); + JsonObject rewardElements = reward.getValue() + .getAsJsonObject(); + int chance = 0; + boolean isGiantCubeReward = false; + for (Entry rewardElement : rewardElements.entrySet()) { + if (rewardElement.getKey() + .equalsIgnoreCase("chance")) { + chance = rewardElement.getValue() + .getAsInt(); + continue; + } else if (rewardElement.getKey() + .equalsIgnoreCase("dependencies")) { + boolean gameversion = false; + boolean versionUsed = false; + for (Entry dependencies : rewardElement.getValue() + .getAsJsonObject() + .entrySet()) { + if (dependencies.getKey() + .equalsIgnoreCase("mod")) { + if (!Loader.isModLoaded( + dependencies.getValue() + .getAsString())) + return null; + } else if (dependencies.getKey() + .equalsIgnoreCase("mcVersion")) { + versionUsed = true; + String[] versionsToCheck = dependencies.getValue() + .getAsString() + .split(","); + for (String toCheckV : versionsToCheck) { + String currentMCV = CCubesCore.gameVersion; + if (toCheckV.contains("*")) { + currentMCV = currentMCV.substring(0, currentMCV.lastIndexOf(".")); + toCheckV = toCheckV.substring(0, toCheckV.lastIndexOf(".")); + } + if (currentMCV.equalsIgnoreCase(toCheckV)) gameversion = true; + } + } + } + if (!gameversion && versionUsed) return null; + continue; + } else if (rewardElement.getKey() + .equalsIgnoreCase("isGiantCubeReward")) { + isGiantCubeReward = rewardElement.getValue() + .getAsBoolean(); + } + + try { + JsonArray rewardTypes = rewardElement.getValue() + .getAsJsonArray(); + if (rewardElement.getKey() + .equalsIgnoreCase("Item")) this.loadItemReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Block")) this.loadBlockReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Message")) this.loadMessageReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Command")) this.loadCommandReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Entity")) this.loadEntityReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Experience")) this.loadExperienceReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Potion")) this.loadPotionReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Schematic")) this.loadSchematicReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Sound")) this.loadSoundReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Chest")) this.loadChestReward(rewardTypes, rewards); + else if (rewardElement.getKey() + .equalsIgnoreCase("Particle")) this.loadParticleReward(rewardTypes, rewards); + } catch (Exception ex) { + CCubesCore.logger + .log(Level.ERROR, "Failed to load a custom reward for some reason. I will try better next time."); + CCubesCore.logger.log(Level.ERROR, ex.getMessage()); + // ex.printStackTrace(); + } + } + return new CustomEntry( + new BasicReward(reward.getKey(), chance, rewards.toArray(new IRewardType[rewards.size()])), + isGiantCubeReward); + } + + public List loadItemReward(JsonArray rawReward, List rewards) { + List items = new ArrayList(); + for (JsonElement fullelement : rawReward) { + String itemInfo = fullelement.getAsJsonObject() + .get("item") + .getAsJsonObject() + .get("id") + .getAsString(); + JsonElement element = fullelement.getAsJsonObject() + .get("item") + .getAsJsonObject(); + if (itemInfo.contains(":")) { + String mod = itemInfo.substring(0, itemInfo.indexOf(":")); + String name = itemInfo.substring(itemInfo.indexOf(":") + 1); + int id = Item.getIdFromItem(GameRegistry.findItem(mod, name)); + element.getAsJsonObject() + .addProperty("id", id); + } + + ItemPart stack; + + try { + String jsonEdited = this.removedKeyQuotes(element.toString()); + NBTBase nbtbase = JsonToNBT.func_150315_a(jsonEdited); + + if (!(nbtbase instanceof NBTTagCompound)) { + CCubesCore.logger.log(Level.ERROR, "Failed to convert the JSON to NBT for: " + element.toString()); + continue; + } else { + ItemStack itemstack = ItemStack.loadItemStackFromNBT((NBTTagCompound) nbtbase); + if (itemstack == null) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to create an itemstack from the JSON of: " + jsonEdited + + " and the NBT of: " + + ((NBTTagCompound) nbtbase).toString()); + continue; + } else stack = new ItemPart(itemstack); + } + } catch (NBTException e1) { + CCubesCore.logger.log(Level.ERROR, e1.getMessage()); + continue; + } + + if (fullelement.getAsJsonObject() + .has("delay")) + stack.setDelay( + fullelement.getAsJsonObject() + .get("delay") + .getAsInt()); + + items.add(stack); + } + rewards.add(new ItemRewardType(items.toArray(new ItemPart[items.size()]))); + return rewards; + } + + public List loadBlockReward(JsonArray rawReward, List rewards) { + List blocks = new ArrayList(); + for (JsonElement element : rawReward) { + int x = element.getAsJsonObject() + .get("XOffSet") + .getAsInt(); + int y = element.getAsJsonObject() + .get("YOffSet") + .getAsInt(); + int z = element.getAsJsonObject() + .get("ZOffSet") + .getAsInt(); + String mod = element.getAsJsonObject() + .get("Block") + .getAsString() + .substring( + 0, + element.getAsJsonObject() + .get("Block") + .getAsString() + .indexOf(":")); + String blockName = element.getAsJsonObject() + .get("Block") + .getAsString() + .substring( + element.getAsJsonObject() + .get("Block") + .getAsString() + .indexOf(":") + 1); + Block block = GameRegistry.findBlock(mod, blockName); + boolean falling = element.getAsJsonObject() + .get("Falling") + .getAsBoolean(); + + OffsetBlock offBlock = new OffsetBlock(x, y, z, block, falling); + + if (element.getAsJsonObject() + .has("delay")) + offBlock.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + + if (element.getAsJsonObject() + .has("RelativeToPlayer")) + offBlock.setRelativeToPlayer( + element.getAsJsonObject() + .get("RelativeToPlayer") + .getAsBoolean()); + + blocks.add(offBlock); + } + rewards.add(new BlockRewardType(blocks.toArray(new OffsetBlock[blocks.size()]))); + return rewards; + } + + public List loadMessageReward(JsonArray rawReward, List rewards) { + List msgs = new ArrayList(); + for (JsonElement element : rawReward) { + MessagePart message = new MessagePart( + element.getAsJsonObject() + .get("message") + .getAsString()); + + if (element.getAsJsonObject() + .has("delay")) + message.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + if (element.getAsJsonObject() + .has("serverWide")) + message.setServerWide( + element.getAsJsonObject() + .get("serverWide") + .getAsBoolean()); + if (element.getAsJsonObject() + .has("range")) + message.setRange( + element.getAsJsonObject() + .get("range") + .getAsInt()); + + msgs.add(message); + } + rewards.add(new MessageRewardType(msgs.toArray(new MessagePart[msgs.size()]))); + return rewards; + } + + public List loadCommandReward(JsonArray rawReward, List rewards) { + List commands = new ArrayList(); + for (JsonElement element : rawReward) { + CommandPart command = new CommandPart( + element.getAsJsonObject() + .get("command") + .getAsString()); + + if (element.getAsJsonObject() + .has("delay")) + command.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + commands.add(command); + } + rewards.add(new CommandRewardType(commands.toArray(new CommandPart[commands.size()]))); + return rewards; + } + + public List loadEntityReward(JsonArray rawReward, List rewards) { + List entities = new ArrayList(); + for (JsonElement element : rawReward) { + EntityPart ent; + + try { + String jsonEdited = this.removedKeyQuotes( + element.getAsJsonObject() + .get("entity") + .getAsJsonObject() + .toString()); + NBTBase nbtbase = JsonToNBT.func_150315_a(jsonEdited); + + if (!(nbtbase instanceof NBTTagCompound)) { + CCubesCore.logger.log(Level.ERROR, "Failed to convert the JSON to NBT for: " + element.toString()); + continue; + } else { + ent = new EntityPart((NBTTagCompound) nbtbase); + } + } catch (Exception e1) { + CCubesCore.logger.log(Level.ERROR, "The Entiy loading failed for a custom reward!"); + CCubesCore.logger.log(Level.ERROR, "-------------------------------------------"); + e1.printStackTrace(); + continue; + } + + if (element.getAsJsonObject() + .has("delay")) + ent.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + entities.add(ent); + } + rewards.add(new EntityRewardType(entities.toArray(new EntityPart[entities.size()]))); + return rewards; + } + + public List loadExperienceReward(JsonArray rawReward, List rewards) { + List exp = new ArrayList(); + for (JsonElement element : rawReward) { + ExpirencePart exppart = new ExpirencePart( + element.getAsJsonObject() + .get("experienceAmount") + .getAsInt()); + + if (element.getAsJsonObject() + .has("delay")) + exppart.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + if (element.getAsJsonObject() + .has("numberOfOrbs")) + exppart.setNumberofOrbs( + element.getAsJsonObject() + .get("numberOfOrbs") + .getAsInt()); + exp.add(exppart); + } + rewards.add(new ExperienceRewardType(exp.toArray(new ExpirencePart[exp.size()]))); + return rewards; + } + + public List loadPotionReward(JsonArray rawReward, List rewards) { + List potionEffects = new ArrayList(); + for (JsonElement element : rawReward) { + PotionPart exppart = new PotionPart( + new PotionEffect( + element.getAsJsonObject() + .get("potionid") + .getAsInt(), + element.getAsJsonObject() + .get("duration") + .getAsInt() * 20)); + + if (element.getAsJsonObject() + .has("delay")) + exppart.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + potionEffects.add(exppart); + } + rewards.add(new PotionRewardType(potionEffects.toArray(new PotionPart[potionEffects.size()]))); + return rewards; + } + + public List loadSoundReward(JsonArray rawReward, List rewards) { + List sounds = new ArrayList(); + for (JsonElement element : rawReward) { + SoundPart sound = new SoundPart( + element.getAsJsonObject() + .get("sound") + .getAsString()); + + if (element.getAsJsonObject() + .has("delay")) + sound.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + if (element.getAsJsonObject() + .has("serverWide")) + sound.setServerWide( + element.getAsJsonObject() + .get("serverWide") + .getAsBoolean()); + if (element.getAsJsonObject() + .has("range")) + sound.setRange( + element.getAsJsonObject() + .get("range") + .getAsInt()); + if (element.getAsJsonObject() + .has("playAtPlayersLocation")) + sound.setAtPlayersLocation( + element.getAsJsonObject() + .get("playAtPlayersLocation") + .getAsBoolean()); + if (element.getAsJsonObject() + .has("volume")) + sound.setVolume( + element.getAsJsonObject() + .get("volume") + .getAsInt()); + if (element.getAsJsonObject() + .has("pitch")) + sound.setPitch( + element.getAsJsonObject() + .get("pitch") + .getAsInt()); + + sounds.add(sound); + } + rewards.add(new SoundRewardType(sounds.toArray(new SoundPart[sounds.size()]))); + return rewards; + } + + public List loadChestReward(JsonArray rawReward, List rewards) { + List items = Lists.newArrayList(); + for (JsonElement element : rawReward) { + JsonObject obj = element.getAsJsonObject(); + if (obj.has("item") && obj.has("chance")) { + int meta = 0; + if (obj.has("meta")) meta = obj.get("meta") + .getAsInt(); + + int amountMin = 0; + if (obj.has("amountMin")) amountMin = obj.get("amountMin") + .getAsInt(); + + int amountMax = 8; + if (obj.has("amountMax")) amountMax = obj.get("amountMax") + .getAsInt(); + + items.add( + new ChestChanceItem( + obj.get("item") + .getAsString(), + meta, + obj.get("chance") + .getAsInt(), + amountMin, + amountMax)); + } else { + CCubesCore.logger.log(Level.ERROR, "A chest reward failed to load do to missing params"); + } + + } + rewards.add(new ChestRewardType(items.toArray(new ChestChanceItem[items.size()]))); + return rewards; + } + + public List loadParticleReward(JsonArray rawReward, List rewards) { + List particles = new ArrayList(); + for (JsonElement element : rawReward) { + ParticlePart particle = new ParticlePart( + element.getAsJsonObject() + .get("particle") + .getAsString()); + + if (element.getAsJsonObject() + .has("delay")) + particle.setDelay( + element.getAsJsonObject() + .get("delay") + .getAsInt()); + + particles.add(particle); + } + rewards.add(new ParticleEffectRewardType(particles.toArray(new ParticlePart[particles.size()]))); + return rewards; + } + + public List loadSchematicReward(JsonArray rawReward, List rewards) { + List blocks = new ArrayList(); + for (JsonElement element : rawReward) { + String fileName = element.getAsJsonObject() + .get("fileName") + .getAsString(); + if (fileName.endsWith(".schematic")) { + Schematic schem = null; + + try { + schem = parseSchematic( + element.getAsJsonObject() + .get("fileName") + .getAsString(), + false); + } catch (IOException e) { + e.printStackTrace(); + } + + if (schem == null) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to load the schematic of " + element.getAsJsonObject() + .get("fileName") + .getAsString() + ". It seems to be dead :("); + continue; + } + + int multiplier = 0; + if (element.getAsJsonObject() + .has("delay")) + multiplier = element.getAsJsonObject() + .get("delay") + .getAsInt(); + + int i = 0; + short halfLength = (short) (schem.length / 2); + short halfWidth = (short) (schem.width / 2); + + for (int yy = 0; yy < schem.height; yy++) { + for (int zz = 0; zz < schem.length; zz++) { + for (int xx = 0; xx < schem.width; xx++) { + int j = schem.blocks[i]; + if (j < 0) j = 128 + (128 + j); + + Block b = Block.getBlockById(j); + if (b != Blocks.air) { + boolean falling = false; + if (element.getAsJsonObject() + .has("falling")) + falling = element.getAsJsonObject() + .get("falling") + .getAsBoolean(); + OffsetBlock block = new OffsetBlock(halfWidth - xx, yy, halfLength - zz, b, falling); + if (element.getAsJsonObject() + .has("RelativeToPlayer")) + block.setRelativeToPlayer( + element.getAsJsonObject() + .get("RelativeToPlayer") + .getAsBoolean()); + block.setDelay(i * multiplier); + block.setData(schem.data[i]); + blocks.add(block); + } + i++; + } + } + } + + if (schem.tileentities != null) { + for (int i1 = 0; i1 < schem.tileentities.tagCount(); ++i1) { + NBTTagCompound nbttagcompound4 = schem.tileentities.getCompoundTagAt(i1); + TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound4); + + if (tileentity != null) { + boolean falling = false; + if (element.getAsJsonObject() + .has("falling")) + falling = element.getAsJsonObject() + .get("falling") + .getAsBoolean(); + Block b = null; + for (OffsetBlock osb : blocks) + if (osb.xOff == tileentity.xCoord && osb.yOff == tileentity.yCoord + && osb.zOff == tileentity.zCoord) b = osb.getBlock(); + if (b == null) b = Blocks.stone; + OffsetTileEntity block = new OffsetTileEntity( + tileentity.xCoord, + tileentity.yCoord, + tileentity.zCoord, + b, + nbttagcompound4, + falling); + if (element.getAsJsonObject() + .has("RelativeToPlayer")) + block.setRelativeToPlayer( + element.getAsJsonObject() + .get("RelativeToPlayer") + .getAsBoolean()); + block.setDelay(i1 * multiplier); + block.setData(schem.data[i1]); + blocks.add(block); + } + } + } + } else { + if (!fileName.endsWith(".ccs")) fileName += ".ccs"; + int xoff = 0; + int yoff = 0; + int zoff = 0; + float delay = 0; + boolean falling = true; + boolean relativeToPlayer = false; + if (element.getAsJsonObject() + .has("XOffSet")) + xoff = element.getAsJsonObject() + .get("XOffSet") + .getAsInt(); + if (element.getAsJsonObject() + .has("YOffSet")) + yoff = element.getAsJsonObject() + .get("YOffSet") + .getAsInt(); + if (element.getAsJsonObject() + .has("ZOffSet")) + zoff = element.getAsJsonObject() + .get("ZOffSet") + .getAsInt(); + if (element.getAsJsonObject() + .has("delay")) + delay = element.getAsJsonObject() + .get("delay") + .getAsFloat(); + if (element.getAsJsonObject() + .has("falling")) + falling = element.getAsJsonObject() + .get("falling") + .getAsBoolean(); + if (element.getAsJsonObject() + .has("RelativeToPlayer")) + relativeToPlayer = element.getAsJsonObject() + .get("RelativeToPlayer") + .getAsBoolean(); + blocks.addAll( + SchematicUtil.loadCustomSchematic(fileName, xoff, yoff, zoff, delay, falling, relativeToPlayer) + .getBlocks()); + } + } + rewards.add(new BlockRewardType(blocks.toArray(new OffsetBlock[blocks.size()]))); + return rewards; + } + + public Schematic parseSchematic(String name, boolean hardcoded) throws IOException { + if (!name.contains(".schematic")) name = name + ".schematic"; + InputStream is; + + if (hardcoded) { + is = new FileInputStream(new File(source.getAbsolutePath() + "/assets/chancecubes/schematics/" + name)); + } else { + File schematic = new File( + folder.getParentFile() + .getAbsolutePath() + "/CustomRewards/Schematics/" + + name); + is = new FileInputStream(schematic); + } + + NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(is); + + short width = nbtdata.getShort("Width"); + short height = nbtdata.getShort("Height"); + short length = nbtdata.getShort("Length"); + + byte[] blocks = nbtdata.getByteArray("Blocks"); + byte[] data = nbtdata.getByteArray("Data"); + + NBTTagList tileentities = nbtdata.getTagList("TileEntities", 10); + is.close(); + + return new Schematic(tileentities, width, height, length, blocks, data); + } + + public class Schematic { + + public NBTTagList tileentities; + public short width; + public short height; + public short length; + public byte[] blocks; + public byte[] data; + + public Schematic(NBTTagList tileentities, short width, short height, short length, byte[] blocks, byte[] data) { + this.tileentities = tileentities; + this.width = width; + this.height = height; + this.length = length; + this.blocks = blocks; + this.data = data; + } + } + + public String removedKeyQuotes(String raw) { + StringBuilder sb = new StringBuilder(raw.toString()); + int index = 0; + while ((index = sb.indexOf("\"", index)) != -1) { + int secondQuote = sb.indexOf("\"", index + 1); + if (secondQuote == -1) break; + if (sb.charAt(secondQuote + 1) == ':') { + sb.deleteCharAt(index); + sb.delete(secondQuote - 1, secondQuote); + index = secondQuote; + } else { + index++; + } + } + return sb.toString(); + } + + public List getRewardsFiles() { + List files = Lists.newArrayList(); + for (File f : folder.listFiles()) { + if (!f.isFile()) continue; + if (f.getName() + .substring( + f.getName() + .indexOf(".")) + .equalsIgnoreCase(".json")) files.add(f.getName()); + } + return files; + } + + public List getRewardsFromFile(String file) { + List rewards = Lists.newArrayList(); + + File rewardsFile = new File(this.folder.getPath() + "\\" + file); + + JsonElement fileJson; + try { + fileJson = json.parse(new FileReader(rewardsFile)); + } catch (Exception e) { + CCubesCore.logger + .log(Level.ERROR, "Unable to parse the file " + rewardsFile.getName() + ". Skipping file loading."); + return null; + } + + for (Entry reward : fileJson.getAsJsonObject() + .entrySet()) rewards.add(reward.getKey()); + + return rewards; + } + + public List getReward(String file, String rewardName) { + List rewardinfo = Lists.newArrayList(); + + File rewardsFile = new File(this.folder.getPath() + "\\" + file); + JsonElement fileJson; + + try { + fileJson = json.parse(new FileReader(rewardsFile)); + } catch (Exception e) { + CCubesCore.logger + .log(Level.ERROR, "Unable to parse the file " + rewardsFile.getName() + ". Skipping file loading."); + return null; + } + + for (Entry reward : fileJson.getAsJsonObject() + .entrySet()) { + JsonObject rewardElements = reward.getValue() + .getAsJsonObject(); + for (Entry rewardElement : rewardElements.entrySet()) + rewardinfo.add(rewardElement.getKey()); + } + return rewardinfo; + } + + public List getRewardType(String file, String s, String type) { + List rewardinfo = Lists.newArrayList(); + + File rewardsFile = new File(this.folder.getPath() + "\\" + file); + JsonElement fileJson; + try { + fileJson = json.parse(new FileReader(rewardsFile)); + } catch (Exception e) { + CCubesCore.logger + .log(Level.ERROR, "Unable to parse the file " + rewardsFile.getName() + ". Skipping file loading."); + return null; + } + + for (Entry reward : fileJson.getAsJsonObject() + .entrySet()) { + JsonObject rewardElements = reward.getValue() + .getAsJsonObject(); + for (Entry rewardElement : rewardElements.entrySet()) { + if (rewardElement.getKey() + .equalsIgnoreCase(type)) { + if (rewardElement.getValue() instanceof JsonArray) { + JsonArray rewardTypeArray = rewardElement.getValue() + .getAsJsonArray(); + for (int i = 0; i < rewardTypeArray.size(); i++) rewardinfo.add( + rewardTypeArray.get(i) + .toString()); + } else { + rewardinfo.add( + rewardElement.getValue() + .toString()); + } + } + } + } + return rewardinfo; + } + + public int compareDates(Calendar first, Calendar second) { + int fm = first.get(Calendar.MONTH); + int sm = second.get(Calendar.MONTH); + + int fd = first.get(Calendar.DAY_OF_MONTH); + int sd = second.get(Calendar.DAY_OF_MONTH); + + if (fm < sm) return 1; + else if (fm == sm) return fd == sd ? 0 : fd < sd ? 1 : -1; + else return -2; + } + + public File getFolderFile() { + return this.folder; + } +} diff --git a/src/main/java/chanceCubes/config/CustomSoundsLoader.java b/src/main/java/chanceCubes/config/CustomSoundsLoader.java new file mode 100644 index 0000000..2f5ffd2 --- /dev/null +++ b/src/main/java/chanceCubes/config/CustomSoundsLoader.java @@ -0,0 +1,140 @@ +package chanceCubes.config; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.FileResourcePack; +import net.minecraft.client.resources.IResourcePack; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import chanceCubes.CCubesCore; +import chanceCubes.util.FileUtil; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.ReflectionHelper; + +/** + * Code Referenced and sourced from the EnderCore and CustomThings mods. + * All referenced sources and code belong to their original authors and is used with their permission. + * View the + */ + +public class CustomSoundsLoader { + + private File folder; + private File dir; + private File zip; + private String name; + private String mcmeta; + private List customsSounds = new ArrayList(); + private static List defaultResourcePacks; + + private static Gson gson = new GsonBuilder().setPrettyPrinting() + .create(); + + public CustomSoundsLoader(File folder, File directory, String packName) { + this.folder = folder; + this.dir = directory; + this.zip = new File(dir.getAbsolutePath() + ".zip"); + this.name = packName; + this.mcmeta = String.format("{\"pack\":{\"pack_format\":1,\"description\":\"%s\"}}", this.name); + } + + public void addCustomSounds() { + JsonObject root = new JsonObject(); + for (File f : new File(folder.getAbsolutePath() + "/Sounds") + .listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".ogg"))) { + String simpleName = f.getName() + .substring( + 0, + f.getName() + .indexOf('.')); + customsSounds.add(new CustomFile("assets/minecraft/sounds", f));// add record .ogg + JsonObject event = new JsonObject(); + event.addProperty("catagory", "master"); // put under the "record" category for sound options + JsonArray sounds = new JsonArray(); // array of sounds (will only ever be one) + JsonObject sound = new JsonObject(); // sound object (instead of primitive to use 'stream' flag) + sound.addProperty("name", simpleName); // path to file + sound.addProperty("stream", true); // prevents lag for large files + sounds.add(sound); + event.add("sounds", sounds); + root.add(CCubesCore.MODID + "." + simpleName, event); // event name (same as name sent to ItemCustomRecord) + } + customsSounds.add( + new CustomFile( + "assets/minecraft", + FileUtil.writeToFile(folder.getAbsolutePath() + "/Sounds/sounds.json", gson.toJson(root))));// add + // record + // .ogg + } + + public void assemble() { + + FileUtil.safeDeleteDirectory(dir); + dir.mkdirs(); + + String pathToDir = dir.getAbsolutePath(); + File metaFile = new File(pathToDir + "/pack.mcmeta"); + + try { + FileUtil.writeNewFile(metaFile, mcmeta); + + for (CustomFile custom : customsSounds) { + File directory = new File(pathToDir + (custom.ext != null ? "/" + custom.ext : "")); + directory.mkdirs(); + FileUtils.copyFile(custom.file, new File(directory.getAbsolutePath() + "/" + custom.file.getName())); + } + + FileUtil.zipFolderContents(dir, zip); + FileUtil.safeDeleteDirectory(dir); + } catch (IOException e) { + throw new RuntimeException(e); + } + + if (FMLCommonHandler.instance() + .getEffectiveSide() + .isClient()) { + try { + if (defaultResourcePacks == null) defaultResourcePacks = ReflectionHelper.getPrivateValue( + Minecraft.class, + Minecraft.getMinecraft(), + "defaultResourcePacks", + "field_110449_ao", + "ap"); + + File dest = new File(dir.getParent() + "/Resourcepack/" + zip.getName()); + FileUtil.safeDelete(dest); + FileUtils.copyFile(zip, dest); + FileUtil.safeDelete(zip); + FileUtil.writeNewFile( + new File(dest.getParent() + "/readme.txt"), + "This is the resource pack for loading in custom sounds to chance cubes. Feel free to ignore this file and folder."); + defaultResourcePacks.add(new FileResourcePack(dest)); + } catch (Exception e) { + CCubesCore.logger + .error("Failed to inject the resource pack for the custom sounds in the Chance Cubes rewards: ", e); + } + } + } + + private class CustomFile { + + private String ext; + private File file; + + private CustomFile(String ext, File file) { + this.ext = ext; + this.file = file; + } + } +} diff --git a/src/main/java/chanceCubes/containers/CreativePendantContainer.java b/src/main/java/chanceCubes/containers/CreativePendantContainer.java new file mode 100644 index 0000000..8827f7a --- /dev/null +++ b/src/main/java/chanceCubes/containers/CreativePendantContainer.java @@ -0,0 +1,93 @@ +package chanceCubes.containers; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryBasic; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.items.ItemChanceCube; + +public class CreativePendantContainer extends Container { + + private World theWorld; + + private IInventory pendantSlot = new InventoryBasic("CreativePendant", true, 1) { + + public boolean isItemValidForSlot(int slot, ItemStack stack) { + return stack.getItem() instanceof ItemChanceCube || stack.getItem() + .equals(CCubesBlocks.chanceIcosahedron); + } + }; + + public CreativePendantContainer(InventoryPlayer player, World world) { + this.theWorld = world; + + for (int i = 0; i < 9; i++) this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + + for (int y = 0; y < 3; y++) for (int x = 0; x < 9; x++) + this.addSlotToContainer(new Slot(player, 9 + (9 * y + x), 8 + x * 18, 84 + y * 18)); + + this.addSlotToContainer(new Slot(pendantSlot, 0, 80, 50) { + + public boolean isItemValid(ItemStack stack) { + if (stack.getItem() instanceof ItemChanceCube) return true; + return false; + } + }); + } + + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slot) { + ItemStack stack = null; + Slot slotObject = (Slot) inventorySlots.get(slot); + + // null checks and checks if the item can be stacked (maxStackSize > 1) + if (slotObject != null && slotObject.getHasStack()) { + ItemStack stackInSlot = slotObject.getStack(); + stack = stackInSlot.copy(); + + if (slot > 35) { + if (!this.mergeItemStack(stackInSlot, 0, 36, true)) return null; + } else if (stack.getItem() + .equals(CCubesBlocks.chanceCube) + || stack.getItem() + .equals(CCubesBlocks.chanceIcosahedron)) { + if (!this.mergeItemStack(stackInSlot, 36, 37, true)) return null; + } + + if (stackInSlot.stackSize == 0) slotObject.putStack(null); + else slotObject.onSlotChanged(); + + if (stackInSlot.stackSize == stack.stackSize) return null; + slotObject.onPickupFromSlot(player, stackInSlot); + } + return stack; + } + + /** + * Called when the container is closed. + */ + public void onContainerClosed(EntityPlayer player) { + super.onContainerClosed(player); + + if (!this.theWorld.isRemote) { + ItemStack itemstack = this.pendantSlot.getStackInSlotOnClosing(0); + + if (itemstack != null) player.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + + public ItemStack getChanceCubesInPendant() { + return this.pendantSlot.getStackInSlot(0); + } +} diff --git a/src/main/java/chanceCubes/hookins/ModHookUtil.java b/src/main/java/chanceCubes/hookins/ModHookUtil.java new file mode 100644 index 0000000..7b4ec46 --- /dev/null +++ b/src/main/java/chanceCubes/hookins/ModHookUtil.java @@ -0,0 +1,27 @@ +package chanceCubes.hookins; + +import org.apache.logging.log4j.Level; + +import chanceCubes.CCubesCore; +import chanceCubes.hookins.mods.ExtraUtilsModHook; +import chanceCubes.hookins.mods.ThermalExpansionModHook; +import chanceCubes.hookins.mods.ThermalFoundationModHook; +import cpw.mods.fml.common.Loader; + +public class ModHookUtil { + + public static void loadCustomModRewards() { + if (Loader.isModLoaded("ExtraUtilities")) { + new ExtraUtilsModHook(); + CCubesCore.logger.log(Level.INFO, "Loaded custom rewards for the mod Extra Utilities"); + } + if (Loader.isModLoaded("ThermalFoundation")) { + new ThermalFoundationModHook(); + CCubesCore.logger.log(Level.INFO, "Loaded custom rewards for the mod Thermal Foundation"); + } + if (Loader.isModLoaded("ThermalExpansion")) { + new ThermalExpansionModHook(); + CCubesCore.logger.log(Level.INFO, "Loaded custom rewards for the mod Thermal Expansion"); + } + } +} diff --git a/src/main/java/chanceCubes/hookins/mods/BaseModHook.java b/src/main/java/chanceCubes/hookins/mods/BaseModHook.java new file mode 100644 index 0000000..2a89f55 --- /dev/null +++ b/src/main/java/chanceCubes/hookins/mods/BaseModHook.java @@ -0,0 +1,19 @@ +package chanceCubes.hookins.mods; + +public abstract class BaseModHook { + + public String modId; + + private boolean enabled = false; + + public BaseModHook(String modId) { + this.modId = modId; + this.enabled = true; + } + + public abstract void loadRewards(); + + public boolean isEnabled() { + return this.enabled; + } +} diff --git a/src/main/java/chanceCubes/hookins/mods/ExtraUtilsModHook.java b/src/main/java/chanceCubes/hookins/mods/ExtraUtilsModHook.java new file mode 100644 index 0000000..1da8aae --- /dev/null +++ b/src/main/java/chanceCubes/hookins/mods/ExtraUtilsModHook.java @@ -0,0 +1,190 @@ +package chanceCubes.hookins.mods; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.BasicReward; +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.type.BlockRewardType; +import chanceCubes.rewards.type.CommandRewardType; +import chanceCubes.rewards.type.ItemRewardType; +import cpw.mods.fml.common.registry.GameRegistry; + +public class ExtraUtilsModHook extends BaseModHook { + + public ExtraUtilsModHook() { + super("ExtraUtilities"); + loadRewards(); + } + + @Override + public void loadRewards() { + ItemStack stack; + + if (GameRegistry.findItem(super.modId, "unstableingot") != null) { + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":unstableingot", + -100, + new ItemRewardType(new ItemPart(GameRegistry.findItemStack(super.modId, "unstableingot", 1))) { + + @Override + public void trigger(ItemPart s, World world, int x, int y, int z, EntityPlayer player) { + ItemStack stack1 = s.getItemStack() + .copy(); + NBTTagCompound ts = new NBTTagCompound(); + + if (ts.hasKey("crafting")) ts.removeTag("crafting"); + if (stack1.getItemDamage() > 0) return; + + ts.setInteger("dimension", world.provider.dimensionId); + ts.setLong("time", world.getTotalWorldTime()); + stack1.setTagCompound(ts); + + world.setBlock( + (int) player.posX, + (int) player.posY, + (int) player.posZ, + Blocks.crafting_table); + player.displayGUIWorkbench((int) player.posX, (int) player.posY, (int) player.posZ); + + if (!player.inventory.addItemStackToInventory(stack1)) + player.inventory.setInventorySlotContents(player.inventory.currentItem, stack1); + + if ((player instanceof EntityPlayerMP)) + ((EntityPlayerMP) player).mcServer.getConfigurationManager() + .syncPlayerInventory((EntityPlayerMP) player); + } + })); + } + + if (GameRegistry.findItem(super.modId, "generator.64") != null) { + stack = GameRegistry.findItemStack(super.modId, "generator.64", 1); + stack.setStackDisplayName("Useless Generator"); + stack.setItemDamage(9); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward(this.modId + ":Pink_Generator", 80, new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findItem(super.modId, "watering_can") != null) { + stack = GameRegistry.findItemStack(super.modId, "watering_can", 1); + stack.setItemDamage(2); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward(this.modId + ":Broken_Watering_Can", 30, new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findItem(super.modId, "drum") != null) { + stack = GameRegistry.findItemStack(super.modId, "drum", 1); + stack.setItemDamage(1); + IFluidContainerItem cont; + try { + cont = (IFluidContainerItem) stack.getItem(); + cont.fill(stack, new FluidStack(FluidRegistry.WATER, cont.getCapacity(stack)), true); + } catch (Exception e) { + e.printStackTrace(); + } + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward(this.modId + ":Bedrockium_Drum", 80, new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findItem(super.modId, "golden_bag") != null) { + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Golden_Bag", + 90, + new ItemRewardType(new ItemPart(GameRegistry.findItemStack(super.modId, "golden_bag", 1))))); + } + + if (GameRegistry.findItem(super.modId, "plant/ender_lilly") != null) { + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Ender_Lilly", + 65, + new ItemRewardType(new ItemPart(GameRegistry.findItemStack(super.modId, "plant/ender_lilly", 3))))); + } + + if (GameRegistry.findItem(super.modId, "endConstructor") != null) { + stack = GameRegistry.findItemStack(super.modId, "endConstructor", 10); + stack.setItemDamage(2); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward(this.modId + ":Ender_Flux_Crystal", 80, new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findItem(super.modId, "cobblestone_compressed") != null) { + stack = GameRegistry.findItemStack(super.modId, "cobblestone_compressed", 4); + stack.setItemDamage(5); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward(this.modId + ":Compressed_Cobble", 45, new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findBlock(super.modId, "spike_base") != null) { + OffsetBlock[] spikes = new OffsetBlock[34]; + int index = 0; + for (int x = 0; x < 5; x++) { + for (int z = 0; z < 5; z++) { + if (x == 0 || x == 4 || z == 0 | z == 4) { + spikes[index] = new OffsetBlock( + x - 2, + 0, + z - 2, + GameRegistry.findBlock(super.modId, "spike_base"), + false).setRelativeToPlayer(true); + spikes[index].setData((byte) (x == 0 ? 5 : x == 4 ? 4 : z == 0 ? 3 : 2)); + index++; + } else { + spikes[index] = new OffsetBlock( + x - 2, + -1, + z - 2, + GameRegistry.findBlock(super.modId, "spike_base"), + false).setRelativeToPlayer(true); + spikes[index].setData((byte) 1); + index++; + spikes[index] = new OffsetBlock( + x - 2, + 2, + z - 2, + GameRegistry.findBlock(super.modId, "spike_base"), + false).setRelativeToPlayer(true); + index++; + } + + } + } + ChanceCubeRegistry.INSTANCE + .registerReward(new BasicReward(this.modId + ":Spikes", -40, new BlockRewardType(spikes))); + } + + if (GameRegistry.findBlock(super.modId, "cursedearthside") != null) { + OffsetBlock[] cursedEarth = new OffsetBlock[49]; + int index = 0; + for (int x = 0; x < 7; x++) { + for (int z = 0; z < 7; z++) { + cursedEarth[index] = new OffsetBlock( + x - 3, + 0, + z - 3, + GameRegistry.findBlock(super.modId, "cursedearthside"), + false).setRelativeToPlayer(true); + index++; + } + } + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Cursed", + -60, + new BlockRewardType(cursedEarth), + new CommandRewardType(new CommandPart("/time set 15000")))); + } + } +} diff --git a/src/main/java/chanceCubes/hookins/mods/ThaumCraftModHook.java b/src/main/java/chanceCubes/hookins/mods/ThaumCraftModHook.java new file mode 100644 index 0000000..000320b --- /dev/null +++ b/src/main/java/chanceCubes/hookins/mods/ThaumCraftModHook.java @@ -0,0 +1,13 @@ +package chanceCubes.hookins.mods; + +public class ThaumCraftModHook extends BaseModHook { + + public ThaumCraftModHook(String modId) { + super("THAUMCRAFT"); + } + + @Override + public void loadRewards() { + + } +} diff --git a/src/main/java/chanceCubes/hookins/mods/ThermalExpansionModHook.java b/src/main/java/chanceCubes/hookins/mods/ThermalExpansionModHook.java new file mode 100644 index 0000000..d9fcf75 --- /dev/null +++ b/src/main/java/chanceCubes/hookins/mods/ThermalExpansionModHook.java @@ -0,0 +1,90 @@ +package chanceCubes.hookins.mods; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.BasicReward; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.rewards.type.ItemRewardType; +import chanceCubes.rewards.type.MessageRewardType; +import cpw.mods.fml.common.registry.GameRegistry; + +public class ThermalExpansionModHook extends BaseModHook { + + public ThermalExpansionModHook() { + super("ThermalExpansion"); + loadRewards(); + } + + @Override + public void loadRewards() { + ItemStack stack; + + if (GameRegistry.findItem(super.modId, "florb") != null) { + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":florbs", + 60, + new MessageRewardType(new MessagePart("Florbs!!")), + new ItemRewardType(new ItemPart(GameRegistry.findItemStack(super.modId, "florb", 2))) { + + @Override + public void trigger(ItemPart s, World world, int x, int y, int z, EntityPlayer player) { + NBTTagCompound nbt; + for (int i = 0; i < 5; i++) { + nbt = new NBTTagCompound(); + nbt.setString( + "Fluid", + ChanceCubeRegistry.getRandomFluid() + .getName()); + s.getItemStack().stackTagCompound = nbt; + super.spawnStack(s, world, x, y, z, player); + } + } + })); + } + + if (GameRegistry.findItem(super.modId, "pump") != null) { + stack = GameRegistry.findItemStack(super.modId, "pump", 1); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":flui-vac", + 60, + new MessageRewardType(new MessagePart("Well this sucks.....")), + new ItemRewardType(new ItemPart(stack)))); + } + + if (GameRegistry.findItem(super.modId, "igniter") != null + && GameRegistry.findItem(super.modId, "chiller") != null) { + stack = GameRegistry.findItemStack(super.modId, "igniter", 1); + stack.setStackDisplayName("Flint and Steel 2.0"); + ItemStack stack2 = GameRegistry.findItemStack(super.modId, "chiller", 1); + stack2.setStackDisplayName("Snowman in a wand"); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Flux_Chill&Ignite", + 30, + new MessageRewardType(new MessagePart("Fire and Ice")), + new ItemRewardType(new ItemPart(stack), new ItemPart(stack2)))); + } + + if (GameRegistry.findItem(super.modId, "capacitor") != null) { + stack = GameRegistry.findItemStack(super.modId, "capacitor", 1); + stack.setItemDamage(1); + NBTTagCompound nbt = stack.stackTagCompound; + if (nbt == null) nbt = new NBTTagCompound(); + nbt.setInteger("Energy", stack.getMaxDamage()); + stack.stackTagCompound = nbt; + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Tuberous_Capacitor", + 25, + new MessageRewardType(new MessagePart("It's a potato!!")), + new ItemRewardType(new ItemPart(stack)))); + } + } +} diff --git a/src/main/java/chanceCubes/hookins/mods/ThermalFoundationModHook.java b/src/main/java/chanceCubes/hookins/mods/ThermalFoundationModHook.java new file mode 100644 index 0000000..f96f377 --- /dev/null +++ b/src/main/java/chanceCubes/hookins/mods/ThermalFoundationModHook.java @@ -0,0 +1,52 @@ +package chanceCubes.hookins.mods; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; + +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.BasicReward; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.rewards.type.ItemRewardType; +import chanceCubes.rewards.type.MessageRewardType; +import cpw.mods.fml.common.registry.GameRegistry; + +public class ThermalFoundationModHook extends BaseModHook { + + private String[] rodTypes = { "Platinum", "Electrum", "Invar", "Tin", "Lead", "Nickel", "Silver", "Bronze", + "Copper" }; + + public ThermalFoundationModHook() { + super("ThermalFoundation"); + loadRewards(); + } + + @Override + public void loadRewards() { + ItemStack stack; + + if (GameRegistry.findItem(super.modId, "material") != null) { + stack = GameRegistry.findItemStack(super.modId, "material", 4); + stack.setItemDamage(12); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":Grind_Gears", + 10, + new MessageRewardType(new MessagePart("You really grind my gears ;)")), + new ItemRewardType(new ItemPart(stack)))); + } + + List avialable = new ArrayList(); + for (String s : this.rodTypes) if (GameRegistry.findItem(super.modId, "tool.fishingRod" + s) != null) + avialable.add(new ItemPart(GameRegistry.findItemStack(super.modId, "tool.fishingRod" + s, 1))); + ChanceCubeRegistry.INSTANCE.registerReward( + new BasicReward( + this.modId + ":fishing", + 5, + new MessageRewardType(new MessagePart("Hey! Let's open a fishing store!")), + new ItemRewardType(avialable.toArray(new ItemPart[avialable.size()])))); + } + +} diff --git a/src/main/java/chanceCubes/hookins/nei/NEIChanceCubesConfig.java b/src/main/java/chanceCubes/hookins/nei/NEIChanceCubesConfig.java new file mode 100644 index 0000000..b931b00 --- /dev/null +++ b/src/main/java/chanceCubes/hookins/nei/NEIChanceCubesConfig.java @@ -0,0 +1,26 @@ +package chanceCubes.hookins.nei; + +import net.minecraft.item.ItemStack; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import codechicken.nei.api.API; +import codechicken.nei.api.IConfigureNEI; + +public class NEIChanceCubesConfig implements IConfigureNEI { + + @Override + public void loadConfig() { + API.hideItem(new ItemStack(CCubesBlocks.chanceGiantCube)); + } + + @Override + public String getName() { + return "Chance Cubes"; + } + + @Override + public String getVersion() { + return CCubesCore.MODID; + } +} diff --git a/src/main/java/chanceCubes/items/BaseChanceCubesItem.java b/src/main/java/chanceCubes/items/BaseChanceCubesItem.java new file mode 100644 index 0000000..29ce26c --- /dev/null +++ b/src/main/java/chanceCubes/items/BaseChanceCubesItem.java @@ -0,0 +1,40 @@ +package chanceCubes.items; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import com.google.common.collect.Lists; + +import chanceCubes.CCubesCore; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BaseChanceCubesItem extends Item { + + private String itemName = "Chance_Cube_Unnamed"; + private List lore = Lists.newArrayList(); + + public BaseChanceCubesItem(String name) { + itemName = name; + this.setUnlocalizedName(name); + this.setTextureName(CCubesCore.MODID + ":" + name); + this.setCreativeTab(CCubesCore.modTab); + } + + public String getItemName() { + return this.itemName; + } + + public void addLore(String info) { + lore.add(info); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + list.addAll(lore); + } +} diff --git a/src/main/java/chanceCubes/items/CCubesItems.java b/src/main/java/chanceCubes/items/CCubesItems.java new file mode 100644 index 0000000..43e7c7b --- /dev/null +++ b/src/main/java/chanceCubes/items/CCubesItems.java @@ -0,0 +1,29 @@ +package chanceCubes.items; + +import cpw.mods.fml.common.registry.GameRegistry; + +public class CCubesItems { + + public static BaseChanceCubesItem chancePendantT1; + public static BaseChanceCubesItem chancePendantT2; + public static BaseChanceCubesItem chancePendantT3; + + public static BaseChanceCubesItem silkPendant; + public static BaseChanceCubesItem creativePendant; + public static BaseChanceCubesItem rewardSelectorPendant; + + public static BaseChanceCubesItem scanner; + + public static void loadItems() { + GameRegistry.registerItem(chancePendantT1 = new ItemChancePendant(1, 10), chancePendantT1.getItemName()); + GameRegistry.registerItem(chancePendantT2 = new ItemChancePendant(2, 25), chancePendantT2.getItemName()); + GameRegistry.registerItem(chancePendantT3 = new ItemChancePendant(3, 50), chancePendantT3.getItemName()); + + GameRegistry.registerItem(silkPendant = new ItemSilkTouchPendant(), silkPendant.getItemName()); + GameRegistry.registerItem(creativePendant = new ItemCreativePendant(), creativePendant.getItemName()); + GameRegistry + .registerItem(rewardSelectorPendant = new ItemRewardSelectorPendant(), rewardSelectorPendant.getItemName()); + + GameRegistry.registerItem(scanner = new ItemScanner(), scanner.getItemName()); + } +} diff --git a/src/main/java/chanceCubes/items/ItemChanceCube.java b/src/main/java/chanceCubes/items/ItemChanceCube.java new file mode 100644 index 0000000..9c26a0e --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemChanceCube.java @@ -0,0 +1,71 @@ +package chanceCubes.items; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.tileentities.TileChanceD20; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemChanceCube extends ItemBlock { + + public ItemChanceCube(Block b) { + super(b); + } + + public void setChance(ItemStack stack, int chance) { + if (chance > 100 || chance < -101) chance = -101; + NBTTagCompound nbt = stack.stackTagCompound; + if (nbt == null) nbt = new NBTTagCompound(); + nbt.setInteger("Chance", chance); + stack.setTagCompound(nbt); + } + + public int getChance(ItemStack stack) { + if (stack.stackTagCompound == null) return -101; + return stack.stackTagCompound.hasKey("Chance") ? stack.stackTagCompound.getInteger("Chance") : -101; + } + + public String getChanceAsStringValue(ItemStack stack) { + if (stack.stackTagCompound == null) return "Random"; + return stack.stackTagCompound.hasKey("Chance") ? stack.stackTagCompound.getInteger("Chance") == -101 ? "Random" + : "" + stack.stackTagCompound.getInteger("Chance") : "Random"; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + if (!stack.getItem() + .equals(CCubesBlocks.chanceCubeDispenser)) { + String chance = this.getChanceAsStringValue(stack); + list.add("Chance Value: " + chance); + } + } + + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, + float hitX, float hitY, float hitZ, int metadata) { + boolean placed = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata); + + TileEntity te = world.getTileEntity(x, y, z); + if (te != null) { + if (te instanceof TileChanceCube) { + int chance = this.getChance(stack); + if (chance != -101) ((TileChanceCube) te).setChance(chance); + } else if (te instanceof TileChanceD20) { + int chance = this.getChance(stack); + if (chance != -101) ((TileChanceD20) te).setChance(chance); + } + } + + return placed; + } +} diff --git a/src/main/java/chanceCubes/items/ItemChancePendant.java b/src/main/java/chanceCubes/items/ItemChancePendant.java new file mode 100644 index 0000000..a8746c1 --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemChancePendant.java @@ -0,0 +1,46 @@ +package chanceCubes.items; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CCubesSettings; + +public class ItemChancePendant extends BaseChanceCubesItem { + + private int chanceIncrease; + private String itemName = ""; + + public ItemChancePendant(int tier, int chancebonus) { + super("Chance_Cube_Unnamed"); + itemName = "chancePendantTier" + tier; + this.setUnlocalizedName(itemName); + this.setTextureName(CCubesCore.MODID + ":PendantT" + tier); + this.setMaxStackSize(1); + this.setMaxDamage(CCubesSettings.pendantUses); + super.showDurabilityBar(new ItemStack(this)); + chanceIncrease = chancebonus; + super.addLore("Increases the chance of Chance Cubes by:"); + super.addLore(" +" + chanceIncrease + " when the block is broken"); + super.addLore("Only needs to be in the players inventory to work"); + super.addLore("Note, this is NOT a percentage increase."); + } + + public int getChanceIncrease() { + return chanceIncrease; + } + + public void damage(ItemStack stack) { + stack.setItemDamage(stack.getItemDamage() + 1); + } + + public boolean getIsRepairable(ItemStack stack, ItemStack repairStack) { + if (stack.getItem() instanceof ItemChancePendant && repairStack.getItem() + .equals(Blocks.lapis_block)) return true; + return false; + } + + public String getItemName() { + return this.itemName; + } +} diff --git a/src/main/java/chanceCubes/items/ItemCreativePendant.java b/src/main/java/chanceCubes/items/ItemCreativePendant.java new file mode 100644 index 0000000..b1096f4 --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemCreativePendant.java @@ -0,0 +1,31 @@ +package chanceCubes.items; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.client.gui.CCubesGuiHandler; +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; + +public class ItemCreativePendant extends BaseChanceCubesItem { + + public ItemCreativePendant() { + super("creativePendant"); + this.setMaxStackSize(1); + super.addLore("Right click to change the chance"); + super.addLore("of the inserted cubes."); + } + + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + FMLNetworkHandler.openGui( + player, + CCubesCore.instance, + CCubesGuiHandler.CREATIVE_PENDANT_ID, + world, + (int) player.posX, + (int) player.posY, + (int) player.posZ); + return stack; + } +} diff --git a/src/main/java/chanceCubes/items/ItemRewardSelectorPendant.java b/src/main/java/chanceCubes/items/ItemRewardSelectorPendant.java new file mode 100644 index 0000000..74ead0d --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemRewardSelectorPendant.java @@ -0,0 +1,62 @@ +package chanceCubes.items; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.client.gui.RewardSelectorPendantGui; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.registry.GiantCubeRegistry; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.tileentities.TileGiantCube; +import chanceCubes.util.GiantCubeUtil; +import cpw.mods.fml.common.FMLCommonHandler; + +public class ItemRewardSelectorPendant extends BaseChanceCubesItem { + + public ItemRewardSelectorPendant() { + super("rewardSelectorPendant"); + this.setMaxStackSize(1); + super.addLore("Shift right click to change the reward."); + super.addLore("Right click a Chance Cube to summon the reward."); + } + + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + if (player.isSneaking() && world.isRemote) FMLCommonHandler.instance() + .showGuiScreen(new RewardSelectorPendantGui(player, stack)); + return stack; + } + + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, + float hitX, float hitY, float hitZ) { + if (world.isRemote || player.isSneaking()) return false; + if (stack.getTagCompound() != null && stack.getTagCompound() + .hasKey("Reward")) { + if (world.getBlock(x, y, z) + .equals(CCubesBlocks.chanceCube)) { + world.setBlockToAir(x, y, z); + IChanceCubeReward reward = ChanceCubeRegistry.INSTANCE.getRewardByName( + stack.getTagCompound() + .getString("Reward")); + if (reward != null) reward.trigger(world, x, y, z, player); + else player.addChatMessage(new ChatComponentText("That reward does not exist for this cube!")); + } else if (world.getBlock(x, y, z) + .equals(CCubesBlocks.chanceGiantCube)) { + TileEntity ent = world.getTileEntity(x, y, z); + if (ent == null || !(ent instanceof TileGiantCube)) return false; + TileGiantCube giant = (TileGiantCube) ent; + IChanceCubeReward reward = GiantCubeRegistry.INSTANCE.getRewardByName( + stack.getTagCompound() + .getString("Reward")); + if (reward != null) + reward.trigger(world, giant.getMasterX(), giant.getMasterY(), giant.getMasterZ(), player); + else player.addChatMessage(new ChatComponentText("That reward does not exist for this cube!")); + GiantCubeUtil.removeStructure(giant.getMasterX(), giant.getMasterY(), giant.getMasterZ(), world); + } + } + return true; + } +} diff --git a/src/main/java/chanceCubes/items/ItemScanner.java b/src/main/java/chanceCubes/items/ItemScanner.java new file mode 100644 index 0000000..d58e958 --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemScanner.java @@ -0,0 +1,93 @@ +package chanceCubes.items; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.client.listeners.RenderEvent; +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.network.PacketCubeScan; +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.tileentities.TileChanceD20; + +public class ItemScanner extends BaseChanceCubesItem { + + public ItemScanner() { + super("scanner"); + this.setMaxStackSize(1); + } + + public EnumAction getItemUseAction(ItemStack p_77661_1_) { + return EnumAction.block; + } + + public int getMaxItemUseDuration(ItemStack stack) { + return 72000; + } + + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); + return stack; + } + + public void onUpdate(ItemStack stack, World world, Entity entity, int p_77663_4_, boolean p_77663_5_) { + if (!world.isRemote) return; + RenderEvent.setLookingAt(false); + if (entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) entity; + if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem() + .equals(stack) + && player.getItemInUse() != null + && player.getItemInUse() + .equals(stack)) { + MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true); + + if (movingobjectposition == null) return; + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + boolean flag = false; + if (world.getBlock(i, j, k) + .equals(CCubesBlocks.chanceCube)) { + TileChanceCube te = ((TileChanceCube) world.getTileEntity(i, j, k)); + te.setScanned(true); + CCubesPacketHandler.INSTANCE.sendToServer(new PacketCubeScan(te.xCoord, te.yCoord, te.zCoord)); + flag = true; + RenderEvent.setLookingAtChance(te.getChance()); + } else if (world.getBlock(i, j, k) + .equals(CCubesBlocks.chanceIcosahedron)) { + TileChanceD20 te = ((TileChanceD20) world.getTileEntity(i, j, k)); + te.setScanned(true); + CCubesPacketHandler.INSTANCE + .sendToServer(new PacketCubeScan(te.xCoord, te.yCoord, te.zCoord)); + flag = true; + RenderEvent.setLookingAtChance(te.getChance()); + } else if (world.getBlock(i, j, k) + .equals(CCubesBlocks.chanceGiantCube)) { + flag = false; + RenderEvent.setLookingAtChance(-201); + RenderEvent.setLookingAt(true); + RenderEvent.setChanceIncrease(0); + } + + if (flag) { + RenderEvent.setLookingAt(true); + int chanceInc = 0; + for (ItemStack s : player.inventory.mainInventory) { + if (s != null && s.getItem() instanceof ItemChancePendant) { + chanceInc += ((ItemChancePendant) s.getItem()).getChanceIncrease(); + break; + } + } + RenderEvent.setChanceIncrease(chanceInc); + } + } + } + } + } +} diff --git a/src/main/java/chanceCubes/items/ItemSilkTouchPendant.java b/src/main/java/chanceCubes/items/ItemSilkTouchPendant.java new file mode 100644 index 0000000..67bbb82 --- /dev/null +++ b/src/main/java/chanceCubes/items/ItemSilkTouchPendant.java @@ -0,0 +1,21 @@ +package chanceCubes.items; + +import net.minecraft.item.ItemStack; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemSilkTouchPendant extends BaseChanceCubesItem { + + public ItemSilkTouchPendant() { + super("silkTouchPendant"); + this.setMaxStackSize(1); + super.addLore("Use this pendant to retrieve Chance Cubes"); + super.addLore("Player must hold this in hand to get the cube!"); + } + + @SideOnly(Side.CLIENT) + public boolean hasEffect(ItemStack stack) { + return true; + } +} diff --git a/src/main/java/chanceCubes/listeners/PlayerConnectListener.java b/src/main/java/chanceCubes/listeners/PlayerConnectListener.java new file mode 100644 index 0000000..423d0a2 --- /dev/null +++ b/src/main/java/chanceCubes/listeners/PlayerConnectListener.java @@ -0,0 +1,28 @@ +package chanceCubes.listeners; + +import chanceCubes.CCubesCore; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.CustomUserReward; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent; + +public class PlayerConnectListener { + + boolean hasChecked = false; + + @SubscribeEvent + public void onPlayerLogin(PlayerLoggedInEvent event) { + if (event.player.worldObj.isRemote) return; + + new CustomUserReward(event.player); + } + + @SubscribeEvent + public void onPlayerLogin(PlayerLoggedOutEvent event) { + if (event.player.worldObj.isRemote) return; + + ChanceCubeRegistry.INSTANCE + .unregisterReward(CCubesCore.MODID + ":Custom_Reward_For_" + event.player.getCommandSenderName()); + } +} diff --git a/src/main/java/chanceCubes/listeners/TickListener.java b/src/main/java/chanceCubes/listeners/TickListener.java new file mode 100644 index 0000000..8fe08f7 --- /dev/null +++ b/src/main/java/chanceCubes/listeners/TickListener.java @@ -0,0 +1,16 @@ +package chanceCubes.listeners; + +import chanceCubes.util.Scheduler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Type; +import cpw.mods.fml.relauncher.Side; + +public class TickListener { + + @SubscribeEvent + public void onTick(ServerTickEvent event) { + if (event.side == Side.SERVER && event.type == Type.SERVER && event.phase == Phase.START) Scheduler.tickTasks(); + } +} diff --git a/src/main/java/chanceCubes/listeners/WorldGen.java b/src/main/java/chanceCubes/listeners/WorldGen.java new file mode 100644 index 0000000..95e9ac8 --- /dev/null +++ b/src/main/java/chanceCubes/listeners/WorldGen.java @@ -0,0 +1,60 @@ +package chanceCubes.listeners; + +import java.util.Random; + +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenMinable; +import net.minecraftforge.event.terraingen.PopulateChunkEvent; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.config.CCubesSettings; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class WorldGen { + + @SubscribeEvent + public void onGenerate(PopulateChunkEvent.Pre event) { + if (CCubesSettings.isBlockedWorld( + event.world.getWorldInfo() + .getWorldName()) + || CCubesSettings.isBlockedWorld("" + event.world.provider.dimensionId)) return; + if (CCubesSettings.oreGeneration) generateOre(event.world, new Random(), event.chunkX * 16, event.chunkZ * 16); + + if (CCubesSettings.surfaceGeneration) + generateSurface(event.world, new Random(), event.chunkX * 16, event.chunkZ * 16); + } + + private void generateOre(World world, Random rand, int x, int z) { + for (int k = 0; k < CCubesSettings.oreGenAmount; k++) { + int firstBlockXCoord = x + rand.nextInt(16); + int firstBlockYCoord = rand.nextInt(100); + int firstBlockZCoord = z + rand.nextInt(16); + + (new WorldGenMinable(CCubesBlocks.chanceCube, 3)) + .generate(world, rand, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord); + } + } + + public void generateSurface(World world, Random rand, int x, int z) { + if (rand.nextInt(100) < CCubesSettings.surfaceGenAmount) { + int xCord = x + rand.nextInt(16); + int zCord = z + rand.nextInt(16); + int yCord = world.getTopSolidOrLiquidBlock(xCord, zCord); + + if (world.getBlock(xCord, yCord - 1, zCord) + .equals(Blocks.bedrock)) { + for (int y = 0; y < yCord; y++) { + + if (world.getBlock(xCord, y - 1, zCord) + .isBlockSolid(world, xCord, y, zCord, 1) && world.isAirBlock(xCord, y, zCord)) { + yCord = y; + return; + } + } + } + + world.setBlock(xCord, yCord, zCord, CCubesBlocks.chanceCube); + } + } +} diff --git a/src/main/java/chanceCubes/network/CCubesPacketHandler.java b/src/main/java/chanceCubes/network/CCubesPacketHandler.java new file mode 100644 index 0000000..2bec786 --- /dev/null +++ b/src/main/java/chanceCubes/network/CCubesPacketHandler.java @@ -0,0 +1,20 @@ +package chanceCubes.network; + +import chanceCubes.CCubesCore; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.relauncher.Side; + +public class CCubesPacketHandler { + + public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(CCubesCore.MODID); + private static int id = 0; + + public static void init() { + INSTANCE.registerMessage(PacketCreativePendant.Handler.class, PacketCreativePendant.class, id++, Side.SERVER); + INSTANCE.registerMessage(PacketRewardSelector.Handler.class, PacketRewardSelector.class, id++, Side.SERVER); + INSTANCE.registerMessage(PacketTriggerD20.Handler.class, PacketTriggerD20.class, id++, Side.CLIENT); + INSTANCE.registerMessage(PacketParticle.Handler.class, PacketParticle.class, id++, Side.CLIENT); + INSTANCE.registerMessage(PacketCubeScan.Handler.class, PacketCubeScan.class, id++, Side.SERVER); + } +} diff --git a/src/main/java/chanceCubes/network/PacketCreativePendant.java b/src/main/java/chanceCubes/network/PacketCreativePendant.java new file mode 100644 index 0000000..e21f922 --- /dev/null +++ b/src/main/java/chanceCubes/network/PacketCreativePendant.java @@ -0,0 +1,70 @@ +package chanceCubes.network; + +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; + +import org.apache.logging.log4j.Level; + +import chanceCubes.CCubesCore; +import chanceCubes.containers.CreativePendantContainer; +import chanceCubes.items.ItemChanceCube; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class PacketCreativePendant implements IMessage { + + private String playerName; + private int chancevalue; + + public PacketCreativePendant() {} + + public PacketCreativePendant(String player, int chance) { + this.playerName = player; + this.chancevalue = chance; + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, playerName); + buf.writeInt(chancevalue); + + } + + @Override + public void fromBytes(ByteBuf buf) { + this.playerName = ByteBufUtils.readUTF8String(buf); + this.chancevalue = buf.readInt(); + + } + + public static final class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketCreativePendant message, MessageContext ctx) { + Container c; + try { + c = MinecraftServer.getServer() + .getEntityWorld() + .getPlayerEntityByName(message.playerName).openContainer; + } catch (Exception NullPointerException) { + CCubesCore.logger.log( + Level.ERROR, + "Chance Cubes has failed to set the chance of a cube due to a packet failure! Please Inform Turkey of this!"); + return null; + } + + if (c instanceof CreativePendantContainer) { + CreativePendantContainer container = (CreativePendantContainer) c; + ItemStack ccubes = container.getChanceCubesInPendant(); + if (ccubes != null && ccubes.getItem() instanceof ItemChanceCube) + ((ItemChanceCube) ccubes.getItem()).setChance(ccubes, message.chancevalue); + } + return null; + } + } + +} diff --git a/src/main/java/chanceCubes/network/PacketCubeScan.java b/src/main/java/chanceCubes/network/PacketCubeScan.java new file mode 100644 index 0000000..7471a67 --- /dev/null +++ b/src/main/java/chanceCubes/network/PacketCubeScan.java @@ -0,0 +1,57 @@ +package chanceCubes.network; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; + +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.tileentities.TileChanceD20; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class PacketCubeScan implements IMessage { + + public int x; + public int y; + public int z; + + public PacketCubeScan() {} + + public PacketCubeScan(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + + } + + @Override + public void fromBytes(ByteBuf buf) { + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + + } + + public static final class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketCubeScan message, MessageContext ctx) { + TileEntity te = MinecraftServer.getServer() + .getEntityWorld() + .getTileEntity(message.x, message.y, message.z); + if (te instanceof TileChanceCube) ((TileChanceCube) te).setScanned(true); + else if (te instanceof TileChanceD20) ((TileChanceD20) te).setScanned(true); + + return null; + } + } + +} diff --git a/src/main/java/chanceCubes/network/PacketParticle.java b/src/main/java/chanceCubes/network/PacketParticle.java new file mode 100644 index 0000000..f7308dd --- /dev/null +++ b/src/main/java/chanceCubes/network/PacketParticle.java @@ -0,0 +1,65 @@ +package chanceCubes.network; + +import chanceCubes.CCubesCore; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class PacketParticle implements IMessage { + + public String particle; + + public double x; + public double y; + public double z; + + public double vX; + public double vY; + public double vZ; + + public PacketParticle() {} + + public PacketParticle(String particle, double x, double y, double z, double vX, double vY, double vZ) { + this.particle = particle; + this.x = x; + this.y = y; + this.z = z; + this.vX = vX; + this.vY = vY; + this.vZ = vZ; + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, this.particle); + buf.writeDouble(x); + buf.writeDouble(y); + buf.writeDouble(z); + buf.writeDouble(vX); + buf.writeDouble(vY); + buf.writeDouble(vZ); + } + + @Override + public void fromBytes(ByteBuf buf) { + this.particle = ByteBufUtils.readUTF8String(buf); + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + this.vX = buf.readDouble(); + this.vY = buf.readDouble(); + this.vZ = buf.readDouble(); + } + + public static final class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketParticle message, MessageContext ctx) { + CCubesCore.proxy.getClientPlayer().worldObj + .spawnParticle(message.particle, message.x, message.y, message.z, message.vX, message.vY, message.vZ); + return null; + } + } +} diff --git a/src/main/java/chanceCubes/network/PacketRewardSelector.java b/src/main/java/chanceCubes/network/PacketRewardSelector.java new file mode 100644 index 0000000..d02e66f --- /dev/null +++ b/src/main/java/chanceCubes/network/PacketRewardSelector.java @@ -0,0 +1,58 @@ +package chanceCubes.network; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; + +import chanceCubes.items.CCubesItems; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class PacketRewardSelector implements IMessage { + + private String playerName; + private String reward; + + public PacketRewardSelector() {} + + public PacketRewardSelector(String player, String reward) { + this.playerName = player; + this.reward = reward; + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, playerName); + ByteBufUtils.writeUTF8String(buf, reward); + + } + + @Override + public void fromBytes(ByteBuf buf) { + this.playerName = ByteBufUtils.readUTF8String(buf); + this.reward = ByteBufUtils.readUTF8String(buf); + + } + + public static final class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketRewardSelector message, MessageContext ctx) { + ItemStack stack = MinecraftServer.getServer() + .getEntityWorld() + .getPlayerEntityByName(message.playerName).inventory.getCurrentItem(); + if (stack != null && stack.getItem() + .equals(CCubesItems.rewardSelectorPendant)) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) nbt = new NBTTagCompound(); + nbt.setString("Reward", message.reward); + stack.setTagCompound(nbt); + } + return null; + } + } + +} diff --git a/src/main/java/chanceCubes/network/PacketTriggerD20.java b/src/main/java/chanceCubes/network/PacketTriggerD20.java new file mode 100644 index 0000000..5a265fc --- /dev/null +++ b/src/main/java/chanceCubes/network/PacketTriggerD20.java @@ -0,0 +1,56 @@ +package chanceCubes.network; + +import net.minecraft.tileentity.TileEntity; + +import chanceCubes.CCubesCore; +import chanceCubes.tileentities.TileChanceD20; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class PacketTriggerD20 implements IMessage { + + public int x; + public int y; + public int z; + + public PacketTriggerD20() {} + + public PacketTriggerD20(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + } + + @Override + public void fromBytes(ByteBuf buf) { + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + } + + public static final class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(PacketTriggerD20 message, MessageContext ctx) { + TileEntity ico; + + if ((ico = CCubesCore.proxy.getClientPlayer().worldObj.getTileEntity(message.x, message.y, message.z)) + != null) + if (ico instanceof TileChanceD20) + ((TileChanceD20) ico).startBreaking(CCubesCore.proxy.getClientPlayer()); + + return null; + + } + } + +} diff --git a/src/main/java/chanceCubes/proxy/ClientProxy.java b/src/main/java/chanceCubes/proxy/ClientProxy.java new file mode 100644 index 0000000..68bffc5 --- /dev/null +++ b/src/main/java/chanceCubes/proxy/ClientProxy.java @@ -0,0 +1,39 @@ +package chanceCubes.proxy; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.MinecraftForge; + +import chanceCubes.client.listeners.RenderEvent; +import chanceCubes.config.CCubesSettings; +import chanceCubes.renderer.SpecialRendererD20; +import chanceCubes.renderer.TileChanceD20Renderer; +import chanceCubes.renderer.TileCubeDispenserRenderer; +import chanceCubes.tileentities.TileChanceD20; +import chanceCubes.tileentities.TileCubeDispenser; +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.client.registry.RenderingRegistry; + +public class ClientProxy extends CommonProxy { + + @Override + public boolean isClient() { + return true; + } + + public void registerRenderings() { + ClientRegistry.bindTileEntitySpecialRenderer(TileChanceD20.class, new TileChanceD20Renderer()); + CCubesSettings.d20RenderID = RenderingRegistry.getNextAvailableRenderId(); + RenderingRegistry.registerBlockHandler(CCubesSettings.d20RenderID, new SpecialRendererD20()); + ClientRegistry.bindTileEntitySpecialRenderer(TileCubeDispenser.class, new TileCubeDispenserRenderer()); + } + + public void registerEvents() { + MinecraftForge.EVENT_BUS.register(new RenderEvent()); + } + + @Override + public EntityPlayer getClientPlayer() { + return Minecraft.getMinecraft().thePlayer; + } +} diff --git a/src/main/java/chanceCubes/proxy/CommonProxy.java b/src/main/java/chanceCubes/proxy/CommonProxy.java new file mode 100644 index 0000000..03f3e8f --- /dev/null +++ b/src/main/java/chanceCubes/proxy/CommonProxy.java @@ -0,0 +1,26 @@ +package chanceCubes.proxy; + +import net.minecraft.entity.player.EntityPlayer; + +public class CommonProxy { + + public boolean isClient() { + return false; + } + + public void registerGuis() { + + } + + public void registerRenderings() { + + } + + public void registerEvents() { + + } + + public EntityPlayer getClientPlayer() { + return null; + } +} diff --git a/src/main/java/chanceCubes/registry/ChanceCubeRegistry.java b/src/main/java/chanceCubes/registry/ChanceCubeRegistry.java new file mode 100644 index 0000000..3ba4e9e --- /dev/null +++ b/src/main/java/chanceCubes/registry/ChanceCubeRegistry.java @@ -0,0 +1,998 @@ +package chanceCubes.registry; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import javax.annotation.Nullable; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.oredict.OreDictionary; + +import org.apache.logging.log4j.Level; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.config.CCubesSettings; +import chanceCubes.config.ConfigLoader; +import chanceCubes.items.ItemChancePendant; +import chanceCubes.rewards.defaultRewards.AnvilRain; +import chanceCubes.rewards.defaultRewards.BasicReward; +import chanceCubes.rewards.defaultRewards.BlindnessFightReward; +import chanceCubes.rewards.defaultRewards.BookOfMemesReward; +import chanceCubes.rewards.defaultRewards.CakeIsALieReward; +import chanceCubes.rewards.defaultRewards.ChargedCreeperReward; +import chanceCubes.rewards.defaultRewards.ClearInventoryReward; +import chanceCubes.rewards.defaultRewards.CookieMonsterReward; +import chanceCubes.rewards.defaultRewards.CreeperSurroundedReward; +import chanceCubes.rewards.defaultRewards.CustomUserReward; +import chanceCubes.rewards.defaultRewards.DiscoReward; +import chanceCubes.rewards.defaultRewards.EnderCrystalTimerReward; +import chanceCubes.rewards.defaultRewards.FiveProngReward; +import chanceCubes.rewards.defaultRewards.HerobrineReward; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.defaultRewards.InventoryBombReward; +import chanceCubes.rewards.defaultRewards.ItemOfDestinyReward; +import chanceCubes.rewards.defaultRewards.ItemRenamer; +import chanceCubes.rewards.defaultRewards.JukeBoxReward; +import chanceCubes.rewards.defaultRewards.MathReward; +import chanceCubes.rewards.defaultRewards.MazeReward; +import chanceCubes.rewards.defaultRewards.NukeReward; +import chanceCubes.rewards.defaultRewards.OneIsLuckyReward; +import chanceCubes.rewards.defaultRewards.QuestionsReward; +import chanceCubes.rewards.defaultRewards.RandomTeleportReward; +import chanceCubes.rewards.defaultRewards.RemoveUsefulThingsReward; +import chanceCubes.rewards.defaultRewards.RottenFoodReward; +import chanceCubes.rewards.defaultRewards.SkyblockReward; +import chanceCubes.rewards.defaultRewards.SurroundedReward; +import chanceCubes.rewards.defaultRewards.TableFlipReward; +import chanceCubes.rewards.defaultRewards.ThrownInAirReward; +import chanceCubes.rewards.defaultRewards.TorchesToCreepers; +import chanceCubes.rewards.defaultRewards.TrollHoleReward; +import chanceCubes.rewards.defaultRewards.TrollTNTReward; +import chanceCubes.rewards.defaultRewards.WaitForItReward; +import chanceCubes.rewards.defaultRewards.WitherReward; +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.rewards.rewardparts.EntityPart; +import chanceCubes.rewards.rewardparts.ExpirencePart; +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.OffsetTileEntity; +import chanceCubes.rewards.rewardparts.ParticlePart; +import chanceCubes.rewards.rewardparts.PotionPart; +import chanceCubes.rewards.rewardparts.SoundPart; +import chanceCubes.rewards.type.BlockRewardType; +import chanceCubes.rewards.type.CommandRewardType; +import chanceCubes.rewards.type.EntityRewardType; +import chanceCubes.rewards.type.ExperienceRewardType; +import chanceCubes.rewards.type.ItemRewardType; +import chanceCubes.rewards.type.MessageRewardType; +import chanceCubes.rewards.type.ParticleEffectRewardType; +import chanceCubes.rewards.type.PotionRewardType; +import chanceCubes.rewards.type.SoundRewardType; +import chanceCubes.util.RewardsUtil; + +public class ChanceCubeRegistry implements IRewardRegistry { + + private static Random random = new Random(); + public static ChanceCubeRegistry INSTANCE = new ChanceCubeRegistry(); + + private Map nameToReward = Maps.newHashMap(); + private List sortedRewards = Lists.newArrayList(); + private Map disabledNameToReward = Maps.newHashMap(); + + private static List oredicts = new ArrayList(); + private static String[] possibleModOres = new String[] { "oreAluminum", "oreCopper", "oreMythril", "oreLead", + "orePlutonium", "oreQuartz", "oreRuby", "oreSalt", "oreSapphire", "oreSilver", "oreTin", "oreUranium", + "oreZinc" }; + private static List fluids = new ArrayList(); + + private static IChanceCubeReward lastReward = null; + + /** + * loads the default rewards of the Chance Cube + */ + public static void loadDefaultRewards() { + oredicts.add("oreGold"); + oredicts.add("oreIron"); + oredicts.add("oreLapis"); + oredicts.add("oreDiamond"); + oredicts.add("oreRedstone"); + oredicts.add("oreEmerald"); + oredicts.add("oreQuartz"); + oredicts.add("oreCoal"); + + for (String oreDict : possibleModOres) if (OreDictionary.doesOreNameExist(oreDict)) oredicts.add(oreDict); + + for (String s : FluidRegistry.getRegisteredFluids() + .keySet()) fluids.add(s); + + if (!CCubesSettings.enableHardCodedRewards) return; + + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Tnt_Structure", + -30, + new BlockRewardType( + RewardsUtil.addBlocksLists( + RewardsUtil.fillArea(3, 1, 3, Blocks.tnt, -1, 0, -1, true, 0, false, false), + RewardsUtil.fillArea(3, 1, 3, Blocks.redstone_block, -1, 1, -1, true, 30, false, false))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":BedRock", + -20, + new BlockRewardType(new OffsetBlock(0, 0, 0, Blocks.bedrock, false)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Redstone_Diamond", + 10, + new ItemRewardType( + new ItemPart(new ItemStack(Items.redstone)), + new ItemPart(new ItemStack(Items.diamond))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Sethbling_Reward", + 30, + new MessageRewardType(new MessagePart("Welcome back, SethBling here :)").setRange(32)), + new ItemRewardType( + new ItemPart(new ItemStack(Items.redstone, 32)), + new ItemPart(new ItemStack(Items.repeater, 3)), + new ItemPart(new ItemStack(Items.comparator, 3)), + new ItemPart(new ItemStack(Blocks.redstone_lamp, 3)), + new ItemPart(new ItemStack(Blocks.redstone_torch, 3))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":EXP", + 40, + new ExperienceRewardType(new ExpirencePart(100).setNumberofOrbs(10)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":EXP_Shower", + 40, + new ExperienceRewardType( + new ExpirencePart(10), + new ExpirencePart(10, 10), + new ExpirencePart(10, 10), + new ExpirencePart(10, 20), + new ExpirencePart(10, 30), + new ExpirencePart(10, 40), + new ExpirencePart(10, 50), + new ExpirencePart(10, 60), + new ExpirencePart(10, 70), + new ExpirencePart(10, 80), + new ExpirencePart(10, 90), + new ExpirencePart(10, 100), + new ExpirencePart(10, 110), + new ExpirencePart(10, 120), + new ExpirencePart(10, 130), + new ExpirencePart(10, 140), + new ExpirencePart(10, 150)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Poison", + -15, + new PotionRewardType(new PotionPart(new PotionEffect(Potion.poison.id, 500))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":ChatMessage", + 0, + new MessageRewardType( + new MessagePart("You have escaped the wrath of the Chance Cubes.........").setRange(32), + new MessagePart("For now......").setRange(32)))); + // INSTANCE.registerReward(new BasicReward(CCubesCore.MODID+":Command", 15, new CommandRewardType(" /give + // %player minecraft:painting 1 0 {display:{Name:\"Wylds Bestest friend\",Lore:[\"You know you love me, + // \"]}}"))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Hearts", + 0, + new ParticleEffectRewardType(RewardsUtil.spawnXParticles("heart", 5)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Explosion", + 0, + new ParticleEffectRewardType(new ParticlePart("hugeexplosion")), + new SoundRewardType(new SoundPart("random.explode")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Wool", + 25, + new ItemRewardType( + new ItemPart(new ItemStack(Blocks.wool, 4, 0)), + new ItemPart(new ItemStack(Blocks.wool, 4, 1)), + new ItemPart(new ItemStack(Blocks.wool, 4, 2)), + new ItemPart(new ItemStack(Blocks.wool, 4, 3)), + new ItemPart(new ItemStack(Blocks.wool, 4, 4)), + new ItemPart(new ItemStack(Blocks.wool, 4, 5)), + new ItemPart(new ItemStack(Blocks.wool, 4, 6)), + new ItemPart(new ItemStack(Blocks.wool, 4, 7)), + new ItemPart(new ItemStack(Blocks.wool, 4, 8)), + new ItemPart(new ItemStack(Blocks.wool, 4, 9)), + new ItemPart(new ItemStack(Blocks.wool, 4, 10)), + new ItemPart(new ItemStack(Blocks.wool, 4, 11)), + new ItemPart(new ItemStack(Blocks.wool, 4, 12)), + new ItemPart(new ItemStack(Blocks.wool, 4, 13)), + new ItemPart(new ItemStack(Blocks.wool, 4, 14)), + new ItemPart(new ItemStack(Blocks.wool, 4, 15))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Beacon", + 90, + new ItemRewardType(new ItemPart(new ItemStack(Blocks.beacon))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Enchanting", + 80, + new ItemRewardType(new ItemPart(new ItemStack(Blocks.enchanting_table))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Bookshelves", + 60, + new ItemRewardType(new ItemPart(new ItemStack(Blocks.bookshelf, 8))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Ores_Galore", + 50, + new ItemRewardType( + new ItemPart(new ItemStack(Items.coal)), + new ItemPart(new ItemStack(Items.redstone)), + new ItemPart(new ItemStack(Items.iron_ingot)), + new ItemPart(new ItemStack(Items.gold_ingot)), + new ItemPart(new ItemStack(Items.diamond)), + new ItemPart(new ItemStack(Items.emerald))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Have_Another", + 0, + new ItemRewardType(new ItemPart(new ItemStack(CCubesBlocks.chanceCube, 3))), + new MessageRewardType( + new MessagePart("I hear you like Chance Cubes.").setRange(32), + new MessagePart("So I put some Chance Cubes in your Chance Cubes!").setRange(32)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Icsahedron", + 0, + new ItemRewardType(new ItemPart(new ItemStack(CCubesBlocks.chanceIcosahedron))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Saplings", + 35, + new MessageRewardType(new MessagePart("Seems you have purchased the saplings DLC").setRange(32)), + new ItemRewardType( + new ItemPart(new ItemStack(Blocks.sapling, 4, 0)), + new ItemPart(new ItemStack(Blocks.sapling, 4, 1)), + new ItemPart(new ItemStack(Blocks.sapling, 4, 2)), + new ItemPart(new ItemStack(Blocks.sapling, 4, 3)), + new ItemPart(new ItemStack(Blocks.sapling, 4, 4)), + new ItemPart(new ItemStack(Blocks.sapling, 4, 5))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Farmer", + 35, + new MessageRewardType(new MessagePart("Time to farm!").setRange(32)), + new ItemRewardType( + new ItemPart(new ItemStack(Items.iron_hoe)), + new ItemPart(new ItemStack(Items.bucket)), + new ItemPart(new ItemStack(Items.wheat_seeds, 16))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Rancher", + 60, + new ItemRewardType( + new ItemPart(new ItemStack(Blocks.fence, 32)), + new ItemPart(new ItemStack(Items.spawn_egg, 1, 90)), + new ItemPart(new ItemStack(Items.spawn_egg, 1, 91)), + new ItemPart(new ItemStack(Items.spawn_egg, 1, 92))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Fighter", + 25, + new MessageRewardType(new MessagePart("SPARTAAA!!!").setRange(32)), + new ItemRewardType( + new ItemPart(new ItemStack(Items.iron_sword)), + new ItemPart(new ItemStack(Items.iron_helmet)), + new ItemPart(new ItemStack(Items.iron_chestplate)), + new ItemPart(new ItemStack(Items.iron_leggings)), + new ItemPart(new ItemStack(Items.iron_boots))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":pssst", + -5, + new MessageRewardType(new MessagePart("Pssssst.... Over here!").setRange(32)), + new EntityRewardType(new EntityPart(EntityRewardType.getBasicNBTForEntity("Creeper"))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Explorer", + 30, + new MessageRewardType(new MessagePart("Lets go on a journey!").setRange(32)), + new ItemRewardType( + new ItemPart(new ItemStack(Items.compass)), + new ItemPart(new ItemStack(Items.clock)), + new ItemPart(new ItemStack(Blocks.torch, 64)), + new ItemPart(new ItemStack(Items.iron_pickaxe))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Mitas", + 50, + new ItemRewardType( + new ItemPart(new ItemStack(Items.gold_nugget, 32)), + new ItemPart(new ItemStack(Items.gold_ingot, 8)), + new ItemPart(new ItemStack(Items.golden_carrot, 16)), + new ItemPart(new ItemStack(Items.golden_helmet))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Horde", + -25, + new MessageRewardType(new MessagePart("Release the horde!").setRange(32)), + new EntityRewardType(RewardsUtil.spawnXEntities(EntityRewardType.getBasicNBTForEntity("Zombie"), 15)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Lava_Ring", + -40, + new BlockRewardType( + new OffsetBlock(1, -1, 0, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(1, -1, 1, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(0, -1, 1, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(-1, -1, 1, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(-1, -1, 0, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(-1, -1, -1, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(0, -1, -1, Blocks.lava, false).setRelativeToPlayer(true), + new OffsetBlock(1, -1, -1, Blocks.lava, false).setRelativeToPlayer(true)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Rain", + -5, + new CommandRewardType( + new CommandPart("/weather thunder 20000"), + new CommandPart("/time set day", 40)))); + // INSTANCE.registerReward(new BasicReward(CCubesCore.MODID + ":House", 75, new + // SchematicRewardType("house.schematic", 3, true, false))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Silverfish_Surround", + -20, + new BlockRewardType( + new OffsetBlock(1, 0, 0, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(1, 1, 0, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, 0, 1, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, 1, 1, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(-1, 0, 0, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(-1, 1, 0, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, 0, -1, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, 1, -1, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, 2, 0, Blocks.monster_egg, false).setRelativeToPlayer(true), + new OffsetBlock(0, -1, 0, Blocks.monster_egg, false).setRelativeToPlayer(true)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Fish_Dog", + 20, + new ItemRewardType( + new ItemPart(new ItemStack(Items.fish, 5)), + new ItemPart(new ItemStack(Items.spawn_egg, 1, 95))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Bone_Cat", + 20, + new ItemRewardType( + new ItemPart(new ItemStack(Items.bone, 5)), + new ItemPart(new ItemStack(Items.spawn_egg, 1, 98))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":XP_Crystal", + -60, + new CommandRewardType( + new CommandPart("/summon EnderCrystal %x %y %z {Value:1,Riding:{id:\"XPOrb\"}}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":TNT_Cat", + -25, + new CommandRewardType( + new CommandPart( + "/summon PrimedTnt %x %y %z {Fuse:80,Riding:{id:\"Ozelot\",CatType:0,Sitting:0}}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":SlimeMan", + 10, + new CommandRewardType( + new CommandPart( + "/summon Slime %x %y %z {CustomName:\"SlimeMan\",CustomNameVisible:1,Size:1,Riding:{id:\"Slime\",Size:2,Riding:{id:\"Slime\",Size:3}}}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Sail_Away", + 5, + new BlockRewardType(new OffsetBlock(0, -1, 0, Blocks.water, false)), + new CommandRewardType(new CommandPart("/summon Boat %x %y %z")), + new MessageRewardType(new MessagePart("Come sail away!")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Witch", + -15, + new CommandRewardType(new CommandPart("/summon Witch %x %y %z ")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Spawn_Cluckington", + 40, + new CommandRewardType( + new CommandPart( + "/summon Zombie ~ ~1 ~ {CustomName:\"Wyld\",CustomNameVisible:1,IsVillager:0,IsBaby:1,Equipment:[{id:267,Count:1,tag:{ench:[{id:16,lvl:3}]}},{id:301,Count:1,tag:{ench:[{id:0,lvl:3}],display:{color:16711867}}},{id:300,Count:1,tag:{ench:[{id:0,lvl:1}],display:{color:16711867}}},{id:299,Count:1,tag:{ench:[{id:0,lvl:3}],display:{color:16711867}}},{id:298,Count:1,tag:{ench:[{id:0,lvl:3}],display:{color:16711867}}}],DropChances:[0.0F,0.0F,0.0F,0.0F,0.0F],Riding:{id:\"Chicken\",CustomName:\"Cluckington\",CustomNameVisible:1,IsChickenJockey:1,ActiveEffects:[{Id:1,Amplifier:3,Duration:199980,ShowParticles:0b}]}}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Spawn_Jerry", + 40, + new CommandRewardType( + new CommandPart("/summon Slime %x %y %z {Size:1,CustomName:\"Jerry\",CustomNameVisible:1}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Spawn_Glenn", + 40, + new CommandRewardType( + new CommandPart("/summon Zombie %x %y %z {CustomName:\"Glenn\",CustomNameVisible:1}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Spawn_Dr_Trayaurus", + 40, + new CommandRewardType( + new CommandPart( + "/summon Villager %x %y %z {CustomName:\"Dr Trayaurus\",CustomNameVisible:1,Profession:1}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Spawn_Pickles", + 40, + new CommandRewardType( + new CommandPart("/summon MushroomCow ~ ~1 ~ {Age:-10000,CustomName:\"Pickles\"}")), + new MessageRewardType( + new MessagePart("Why is his name pickles? The world may never know").setRange(32)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Want_To_Build_A_Snowman", + 20, + new MessageRewardType(new MessagePart("Do you want to build a snowman?")), + new ItemRewardType( + new ItemPart(new ItemStack(Blocks.snow, 2)), + new ItemPart(new ItemStack(Blocks.pumpkin))))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Diamond_Block", + 75, + new BlockRewardType(new OffsetBlock(0, 0, 0, Blocks.diamond_block, true, 200)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":TNT_Diamond", + -35, + new BlockRewardType( + new OffsetBlock(0, 1, 0, Blocks.diamond_block, false), + new OffsetBlock(0, -1, 0, Blocks.diamond_block, false), + new OffsetBlock(1, 0, 0, Blocks.diamond_block, false), + new OffsetBlock(-1, 0, 0, Blocks.diamond_block, false), + new OffsetBlock(0, 0, 1, Blocks.diamond_block, false), + new OffsetBlock(0, 0, -1, Blocks.diamond_block, false)), + new CommandRewardType(RewardsUtil.executeXCommands("/summon PrimedTnt %x %y %z {Fuse:40}", 3, 5)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Anti_Slab", + -15, + new BlockRewardType(RewardsUtil.fillArea(3, 1, 3, Blocks.obsidian, -1, 2, -1, false, 0, false, true)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Fake_TNT", + 0, + new SoundRewardType( + new SoundPart("game.tnt.primed"), + new SoundPart("game.tnt.primed"), + new SoundPart("game.tnt.primed"), + new SoundPart("random.explode").setDelay(120) + .setAtPlayersLocation(true)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Invisible_Ghasts", + 0, + new SoundRewardType( + new SoundPart("mob.ghast.scream").setServerWide(true), + new SoundPart("mob.ghast.moan").setServerWide(true), + new SoundPart("mob.ghast.moan").setServerWide(true)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":No", + 0, + new BlockRewardType(new OffsetBlock(0, 0, 0, CCubesBlocks.chanceCube, false)), + new MessageRewardType(new MessagePart("No").setRange(32)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Invisible_Creeper", + -30, + new CommandRewardType( + new CommandPart( + "/summon Creeper %x %y %z {ActiveEffects:[{Id:14,Amplifier:0,Duration:200,ShowParticles:0b}]}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Knockback_Zombie", + -35, + new CommandRewardType( + new CommandPart( + "/summon Zombie ~ ~1 ~ {CustomName:\"Leonidas\",IsBaby:1,Equipment:[{id:280,Count:1,tag:{ench:[{id:19,lvl:20}]}},{},{},{},{}],DropChances:[0.0F,0.085F,0.085F,0.085F,0.085F]}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Actual_Invisible_Ghast", + -80, + new CommandRewardType( + new CommandPart( + "/summon Ghast ~ ~10 ~ {ActiveEffects:[{Id:14,Amplifier:0,Duration:2000,ShowParticles:0b}]}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Giant_Chance_Cube", + -45, + new BlockRewardType( + RewardsUtil.fillArea(3, 3, 3, CCubesBlocks.chanceCube, -1, 0, -1, false, 0, true, false))), + false); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Fireworks", + 0, + new CommandRewardType( + RewardsUtil.executeXCommands( + "/summon FireworksRocketEntity ~0 ~0 ~0 {LifeTime:5,Motion:[0.00,0.10,0.00],FireworksItem:{id:401,Count:1,tag:{Fireworks:{Explosions:[{Type:1,Flicker:0,Trail:1,Colors:[16711680],FadeColors:[16777215]}]}}}}", + 4)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":STRING!", + 7, + new BlockRewardType(RewardsUtil.fillArea(11, 5, 11, Blocks.tripwire, -5, 0, -5, false, 0, false, true)), + new MessageRewardType(new MessagePart("STRING!!!!").setRange(32)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":TNT_Bats", + -50, + new CommandRewardType( + RewardsUtil.executeXCommands("/summon PrimedTnt %x %y %z {Fuse:80,Riding:{id:\"Bat\"}}", 10)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Nether_Jelly_Fish", + -40, + new CommandRewardType( + RewardsUtil.executeXCommands( + "/summon LavaSlime ~ ~1 ~ {CustomName:\"Nether Jelly Fish\",CustomNameVisible:1,Size:3,Riding:{id:\"Bat\"}}", + 10)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Pig_Of_Destiny", + 15, + new CommandRewardType( + new CommandPart( + "/summon Pig ~ ~1 ~ {CustomName:\"The Pig of Destiny\",CustomNameVisible:1,Equipment:[{},{id:301,Count:1,tag:{ench:[{id:7,lvl:100}]}},{id:300,Count:1,tag:{ench:[{id:7,lvl:100}]}},{id:299,Count:1,tag:{ench:[{id:7,lvl:100}]}},{id:298,Count:1,tag:{ench:[{id:7,lvl:100}]}}],DropChances:[0.085F,0.0F,0.0F,0.0F,0.0F]}")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Squid_Horde", + 5, + new MessageRewardType( + new MessagePart("Release the horde!").setRange(32), + new MessagePart("Of squids!!").setDelay(20) + .setRange(32)), + new EntityRewardType(RewardsUtil.spawnXEntities(EntityRewardType.getBasicNBTForEntity("Squid"), 15)), + new BlockRewardType(RewardsUtil.fillArea(3, 2, 3, Blocks.water, -1, 0, -1, false, 5, true, false)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":D-rude_SandStorm", + -10, + new BlockRewardType(RewardsUtil.fillArea(5, 3, 5, Blocks.sand, -2, 0, -2, true, 0, false, true)), + new MessageRewardType(new MessagePart("Well that was D-rude").setDelay(40)))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":DIY_Pie", + 5, + new BlockRewardType( + new OffsetBlock(1, 0, 0, Blocks.pumpkin, false), + new OffsetBlock(1, 1, 0, Blocks.reeds, false)), + new CommandRewardType( + new CommandPart("/summon Chicken ~ ~1 ~ {CustomName:\"Zeeth_Kyrah\",CustomNameVisible:1}")), + new MessageRewardType(new MessagePart("Do it yourself Pumpkin Pie!")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Watch_World_Burn", + -5, + new BlockRewardType(RewardsUtil.fillArea(7, 1, 7, Blocks.fire, -3, 0, -3, false, 0, true, true)), + new MessageRewardType(new MessagePart("Some people just want to watch the world burn.")))); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Coal_To_Diamonds", + -35, + new BlockRewardType( + new OffsetBlock(0, 1, 0, Blocks.coal_block, false), + new OffsetBlock(0, -1, 0, Blocks.coal_block, false), + new OffsetBlock(1, 0, 0, Blocks.coal_block, false), + new OffsetBlock(-1, 0, 0, Blocks.coal_block, false), + new OffsetBlock(0, 0, 1, Blocks.coal_block, false), + new OffsetBlock(0, 0, -1, Blocks.coal_block, false)), + new CommandRewardType(RewardsUtil.executeXCommands("/summon PrimedTnt %x %y %z {Fuse:40}", 3, 5)), + new ItemRewardType(new ItemPart(new ItemStack(Items.diamond, 5), 50)))); + + ItemStack stack; + NBTTagCompound nbt; + + stack = new ItemStack(Items.stick); + stack.addEnchantment(Enchantment.sharpness, 5); + stack.setStackDisplayName("A Big Stick"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Roosevelt's_Stick", 70, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.fishing_rod); + stack.setItemDamage(stack.getMaxDamage() / 2); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Half_Fishingrod", 5, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.golden_apple, 1, 1); + stack.setStackDisplayName("Notch"); + INSTANCE + .registerReward(new BasicReward(CCubesCore.MODID + ":Notch", 70, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.nether_star); + stack.setStackDisplayName("North Star"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Nether_Star", 100, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.diamond_sword); + stack.addEnchantment(Enchantment.sharpness, 10); + stack.addEnchantment(Enchantment.unbreaking, 10); + stack.setItemDamage(stack.getMaxDamage() - 2); + stack.setStackDisplayName("The Divine Sword"); + INSTANCE + .registerReward(new BasicReward(CCubesCore.MODID + ":Divine", 85, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.wooden_pickaxe); + stack.addEnchantment(Enchantment.efficiency, 10); + stack.addEnchantment(Enchantment.fortune, 3); + stack.setStackDisplayName("Giga Breaker"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Giga_Breaker", 70, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.bow); + stack.setItemDamage(stack.getMaxDamage()); + stack.addEnchantment(Enchantment.power, 5); + stack.addEnchantment(Enchantment.punch, 3); + stack.addEnchantment(Enchantment.flame, 2); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":One_Shot", + 75, + new ItemRewardType(new ItemPart(stack), new ItemPart(new ItemStack(Items.arrow, 1))))); + + stack = new ItemStack(Items.fish, 1, 2); + stack.setStackDisplayName("Nemo"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Finding_Nemo", 10, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Items.fish, 1, 2); + stack.setStackDisplayName("Marlin"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Finding_Marlin", 10, new ItemRewardType(new ItemPart(stack)))); + + stack = new ItemStack(Blocks.fire, 1); + stack.addEnchantment(Enchantment.fireAspect, 2); + stack.setStackDisplayName("Why not?"); + INSTANCE.registerReward( + new BasicReward(CCubesCore.MODID + ":Fire_Aspect_Fire", 60, new ItemRewardType(new ItemPart(stack)))); + + TileEntitySign sign = new TileEntitySign(); + sign.signText[0] = "The broken path"; + sign.signText[1] = "to succeed"; + nbt = new NBTTagCompound(); + ((TileEntity) sign).writeToNBT(nbt); + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Path_To_Succeed", + 0, + new BlockRewardType( + new OffsetTileEntity(0, 0, -5, Blocks.standing_sign, nbt, true, 20), + new OffsetBlock(0, -1, 0, Blocks.cobblestone, true, 0), + new OffsetBlock(0, -1, -1, Blocks.cobblestone, true, 4), + new OffsetBlock(0, -1, -2, Blocks.cobblestone, true, 8), + new OffsetBlock(0, -1, -3, Blocks.cobblestone, true, 12), + new OffsetBlock(0, -1, -4, Blocks.cobblestone, true, 16), + new OffsetBlock(0, -1, -5, Blocks.cobblestone, true, 20)))); + + OffsetTileEntity[] signs = new OffsetTileEntity[4]; + OffsetTileEntity temp; + for (int i = 0; i < signs.length; i++) { + sign = new TileEntitySign(); + sign.signText[0] = "Help Me!"; + nbt = new NBTTagCompound(); + ((TileEntity) sign).writeToNBT(nbt); + temp = new OffsetTileEntity( + i == 2 ? -2 : i == 3 ? 2 : 0, + 1, + i == 0 ? -2 : i == 1 ? 2 : 0, + Blocks.wall_sign, + nbt, + false, + 5); + temp.setData((byte) (i + 2)); + signs[i] = temp; + } + + INSTANCE.registerReward( + new BasicReward( + CCubesCore.MODID + ":Help_Me", + 0, + new BlockRewardType( + RewardsUtil.addBlocksLists( + RewardsUtil.fillArea(3, 1, 3, Blocks.stonebrick, -1, -1, -1, false, 0, true, false), + RewardsUtil.fillArea(3, 3, 3, Blocks.iron_bars, -1, 0, -1, false, 0, true, false), + RewardsUtil.fillArea(1, 3, 1, Blocks.air, 0, 0, 0, false, 1, true, false), + signs)), + new EntityRewardType( + new EntityPart(EntityRewardType.getBasicNBTForEntity("Villager")).setRemovedBlocks(false) + .setDelay(5)), + new CommandRewardType(new CommandPart("/summon PrimedTnt %x %y %z {Fuse:80}", 5)))); + + OffsetBlock[] blocks = new OffsetBlock[35]; + int i = 0; + for (int y = 0; y < 2; y++) { + for (int x = 0; x < 5; x++) { + for (int z = 0; z < 5; z++) { + if (y == 1 && (x == 0 || x == 4 || z == 0 || z == 4)) continue; + blocks[i] = new OffsetBlock(x - 2, y, z - 2, Blocks.iron_block, true, i * 5); + i++; + } + } + } + blocks[i] = new OffsetBlock(0, 2, 0, Blocks.beacon, true, 200); + INSTANCE.registerReward(new BasicReward(CCubesCore.MODID + ":Beacon_Build", 100, new BlockRewardType(blocks))); + + ChanceCubeRegistry.INSTANCE.registerReward(new BasicReward(CCubesCore.MODID + ":No_Exp", -40) { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.experienceLevel = 0; + player.experienceTotal = 0; + player.addChatMessage(new ChatComponentText("Screw you last stand")); + } + }); + + ChanceCubeRegistry.INSTANCE.registerReward(new BasicReward(CCubesCore.MODID + ":Smite", -10) { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + world.addWeatherEffect(new EntityLightningBolt(world, player.posX, player.posY, player.posZ)); + player.addChatMessage(new ChatComponentText("Thou has been smitten!")); + } + }); + + INSTANCE.registerReward(new NukeReward()); + INSTANCE.registerReward(new FiveProngReward()); + INSTANCE.registerReward(new AnvilRain()); + INSTANCE.registerReward(new HerobrineReward()); + INSTANCE.registerReward(new SurroundedReward()); + INSTANCE.registerReward(new CreeperSurroundedReward()); + INSTANCE.registerReward(new RandomTeleportReward()); + INSTANCE.registerReward(new TrollHoleReward()); + INSTANCE.registerReward(new CookieMonsterReward()); + INSTANCE.registerReward(new BlindnessFightReward()); + INSTANCE.registerReward(new WitherReward()); + INSTANCE.registerReward(new TrollTNTReward()); + INSTANCE.registerReward(new EnderCrystalTimerReward()); + INSTANCE.registerReward(new WaitForItReward()); + INSTANCE.registerReward(new ChargedCreeperReward()); + // INSTANCE.registerReward(new ZombieCopyCatReward()); + // INSTANCE.registerReward(new InventoryChestReward()); + INSTANCE.registerReward(new ItemOfDestinyReward()); + INSTANCE.registerReward(new ThrownInAirReward()); + INSTANCE.registerReward(new DiscoReward()); + INSTANCE.registerReward(new InventoryBombReward()); + INSTANCE.registerReward(new ClearInventoryReward(), false); + INSTANCE.registerReward(new JukeBoxReward()); + INSTANCE.registerReward(new BookOfMemesReward()); + INSTANCE.registerReward(new RemoveUsefulThingsReward()); + INSTANCE.registerReward(new TableFlipReward()); + INSTANCE.registerReward(new TorchesToCreepers()); + INSTANCE.registerReward(new MazeReward()); + INSTANCE.registerReward(new RottenFoodReward()); + INSTANCE.registerReward(new OneIsLuckyReward()); + INSTANCE.registerReward(new SkyblockReward()); + INSTANCE.registerReward(new CakeIsALieReward()); + INSTANCE.registerReward(new ItemRenamer()); + + INSTANCE.registerReward(new BasicReward(CCubesCore.MODID + ":Half_Heart", -30) { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.setHealth(1f); + } + }); + + MathReward math = new MathReward(); + MinecraftForge.EVENT_BUS.register(math); + INSTANCE.registerReward(math); + + QuestionsReward question = new QuestionsReward(); + MinecraftForge.EVENT_BUS.register(question); + INSTANCE.registerReward(question); + } + + public static void loadCustomUserRewards() { + ArrayList allp = new ArrayList(); + Iterator iterator; + + for (int i = 0; i < MinecraftServer.getServer().worldServers.length; i++) { + iterator = MinecraftServer.getServer().worldServers[i].playerEntities.listIterator(); + while (iterator.hasNext()) allp.add((EntityPlayerMP) iterator.next()); + } + + for (EntityPlayerMP player : allp) new CustomUserReward(player); + } + + @Override + public void registerReward(IChanceCubeReward reward) { + this.registerReward(reward, true); + } + + public void registerReward(IChanceCubeReward reward, boolean enabledDefault) { + if (ConfigLoader.config.getBoolean(reward.getName(), ConfigLoader.rewardCat, enabledDefault, "") + && !this.nameToReward.containsKey(reward.getName())) { + nameToReward.put(reward.getName(), reward); + redoSort(reward); + } else { + this.disabledNameToReward.put(reward.getName(), reward); + } + } + + public boolean enableReward(String reward) { + if (this.disabledNameToReward.containsKey(reward)) + return this.enableReward(this.disabledNameToReward.get(reward)); + return false; + } + + public boolean enableReward(IChanceCubeReward reward) { + this.disabledNameToReward.remove(reward.getName()); + nameToReward.put(reward.getName(), reward); + redoSort(reward); + return true; + } + + @Override + public boolean unregisterReward(String name) { + IChanceCubeReward reward = nameToReward.remove(name); + if (reward != null) { + this.disabledNameToReward.put(name, reward); + return sortedRewards.remove(reward); + } + return false; + } + + @Override + public IChanceCubeReward getRewardByName(String name) { + return nameToReward.get(name); + } + + @Override + public void triggerRandomReward(World world, int x, int y, int z, EntityPlayer player, int chance) { + if (this.sortedRewards.size() == 0) { + CCubesCore.logger + .log(Level.WARN, "There are no registered rewards with ChanceCubes and no reward was able to be given"); + return; + } + + if (CCubesSettings.doesHolidayRewardTrigger && CCubesSettings.holidayReward != null) { + CCubesSettings.holidayReward.trigger(world, x, y, z, player); + CCubesSettings.doesHolidayRewardTrigger = false; + CCubesSettings.holidayRewardTriggered = true; + ConfigLoader.config + .get( + ConfigLoader.genCat, + "HolidayRewardTriggered", + false, + "Don't touch! Well I mean you can touch it, if you want. I can't stop you. I'm only text.") + .setValue(true); + ConfigLoader.config.save(); + return; + } + + if (player != null) { + for (int i = 0; i < player.inventory.mainInventory.length; i++) { + ItemStack stack = player.inventory.mainInventory[i]; + if (stack != null && stack.getItem() instanceof ItemChancePendant) { + ItemChancePendant pendant = (ItemChancePendant) stack.getItem(); + pendant.damage(stack); + if (stack.getItemDamage() >= CCubesSettings.pendantUses) + player.inventory.setInventorySlotContents(i, null); + chance += pendant.getChanceIncrease(); + if (chance > 100) chance = 100; + break; + } + } + } + + int lowerIndex = 0; + int upperIndex = sortedRewards.size() - 1; + int lowerRange = chance - CCubesSettings.rangeMin < -100 ? -100 : chance - CCubesSettings.rangeMin; + int upperRange = chance + CCubesSettings.rangeMax > 100 ? 100 : chance + CCubesSettings.rangeMax; + + while (sortedRewards.get(lowerIndex) + .getChanceValue() < lowerRange) { + lowerIndex++; + if (lowerIndex >= sortedRewards.size()) { + lowerIndex--; + break; + } + } + while (sortedRewards.get(upperIndex) + .getChanceValue() > upperRange) { + upperIndex--; + if (upperIndex < 0) { + upperIndex++; + break; + } + } + int range = upperIndex - lowerIndex > 0 ? upperIndex - lowerIndex : 1; + int pick = random.nextInt(range) + lowerIndex; + IChanceCubeReward pickedReward = sortedRewards.get(pick); + if (lastReward != null) { + byte atempts = 0; + while (atempts < 5 && lastReward.getName() + .equals(pickedReward.getName())) { + pick = random.nextInt(range) + lowerIndex; + pickedReward = sortedRewards.get(pick); + atempts++; + } + } + CCubesCore.logger.log(Level.INFO, "Triggered the reward with the name of: " + pickedReward.getName()); + pickedReward.trigger(world, x, y, z, player); + lastReward = pickedReward; + } + + private void redoSort(@Nullable IChanceCubeReward newReward) { + if (newReward != null) sortedRewards.add(newReward); + + Collections.sort(sortedRewards, new Comparator() { + + public int compare(IChanceCubeReward o1, IChanceCubeReward o2) { + return o1.getChanceValue() - o2.getChanceValue(); + }; + }); + } + + public void ClearRewards() { + this.sortedRewards.clear(); + this.nameToReward.clear(); + this.disabledNameToReward.clear(); + } + + public static String getRandomOreDict() { + return ChanceCubeRegistry.oredicts.get(random.nextInt(ChanceCubeRegistry.oredicts.size())); + } + + public static Fluid getRandomFluid() { + Fluid f = FluidRegistry + .getFluid(ChanceCubeRegistry.fluids.get(random.nextInt(ChanceCubeRegistry.fluids.size()))); + while (f == null || f.getBlock() == null) + f = FluidRegistry.getFluid(ChanceCubeRegistry.fluids.get(random.nextInt(ChanceCubeRegistry.fluids.size()))); + return f; + } + + public int getNumOfRewards() { + return this.sortedRewards.size(); + } +} diff --git a/src/main/java/chanceCubes/registry/GiantCubeRegistry.java b/src/main/java/chanceCubes/registry/GiantCubeRegistry.java new file mode 100644 index 0000000..750b310 --- /dev/null +++ b/src/main/java/chanceCubes/registry/GiantCubeRegistry.java @@ -0,0 +1,112 @@ +package chanceCubes.registry; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import org.apache.logging.log4j.Level; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CCubesSettings; +import chanceCubes.config.ConfigLoader; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.giantRewards.ChunkFlipReward; +import chanceCubes.rewards.giantRewards.ChunkReverserReward; +import chanceCubes.rewards.giantRewards.FloorIsLavaReward; +import chanceCubes.rewards.giantRewards.FluidTowerReward; +import chanceCubes.rewards.giantRewards.OrePillarReward; +import chanceCubes.rewards.giantRewards.OreSphereReward; +import chanceCubes.rewards.giantRewards.PotionsReward; +import chanceCubes.rewards.giantRewards.TNTSlingReward; +import chanceCubes.rewards.giantRewards.ThrowablesReward; + +public class GiantCubeRegistry implements IRewardRegistry { + + public static GiantCubeRegistry INSTANCE = new GiantCubeRegistry(); + + private Map nameToReward = Maps.newHashMap(); + private List sortedRewards = Lists.newArrayList(); + + /** + * loads the default rewards of the Chance Cube + */ + public static void loadDefaultRewards() { + if (!CCubesSettings.enableHardCodedRewards) return; + + INSTANCE.registerReward(new BioDomeReward()); + INSTANCE.registerReward(new TNTSlingReward()); + INSTANCE.registerReward(new ThrowablesReward()); + INSTANCE.registerReward(new OrePillarReward()); + INSTANCE.registerReward(new ChunkReverserReward()); + INSTANCE.registerReward(new FloorIsLavaReward()); + INSTANCE.registerReward(new ChunkFlipReward()); + INSTANCE.registerReward(new OreSphereReward()); + INSTANCE.registerReward(new PotionsReward()); + INSTANCE.registerReward(new FluidTowerReward()); + } + + @Override + public void registerReward(IChanceCubeReward reward) { + if (ConfigLoader.config.getBoolean(reward.getName(), ConfigLoader.giantRewardCat, true, "") + && !this.nameToReward.containsKey(reward.getName())) { + nameToReward.put(reward.getName(), reward); + redoSort(reward); + } + } + + @Override + public boolean unregisterReward(String name) { + Object o = nameToReward.remove(name); + if (o != null) return sortedRewards.remove(o); + return false; + } + + @Override + public IChanceCubeReward getRewardByName(String name) { + return nameToReward.get(name); + } + + @Override + public void triggerRandomReward(World world, int x, int y, int z, EntityPlayer player, int chance) { + if (this.sortedRewards.size() == 0) { + CCubesCore.logger.log( + Level.WARN, + "There are no registered rewards with the Giant Chance Cubes and no reward was able to be given"); + return; + } + + int pick = world.rand.nextInt(sortedRewards.size()); + CCubesCore.logger.log( + Level.INFO, + "Triggered the reward with the name of: " + sortedRewards.get(pick) + .getName()); + sortedRewards.get(pick) + .trigger(world, x, y, z, player); + } + + private void redoSort(@Nullable IChanceCubeReward newReward) { + if (newReward != null) sortedRewards.add(newReward); + + Collections.sort(sortedRewards, new Comparator() { + + public int compare(IChanceCubeReward o1, IChanceCubeReward o2) { + return o1.getChanceValue() - o2.getChanceValue(); + }; + }); + } + + public void ClearRewards() { + this.sortedRewards.clear(); + this.nameToReward.clear(); + } +} diff --git a/src/main/java/chanceCubes/registry/IRewardRegistry.java b/src/main/java/chanceCubes/registry/IRewardRegistry.java new file mode 100644 index 0000000..3793d11 --- /dev/null +++ b/src/main/java/chanceCubes/registry/IRewardRegistry.java @@ -0,0 +1,47 @@ +package chanceCubes.registry; + +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; + +public interface IRewardRegistry { + + /** + * Registers the given reward as a possible outcome + * + * @param reward + * to register + */ + void registerReward(IChanceCubeReward reward); + + /** + * Unregisters a reward with the given name + * + * @param name + * of the reward to remove + * @return true is a reward was successfully removed, false if a reward was not removed + */ + boolean unregisterReward(String name); + + @Nullable + IChanceCubeReward getRewardByName(String name); + + /** + * Triggers a random reward in the given world at the given location + * + * @param world + * The world object + * @param pos + * The position of the block + * @param player + * The player receiving the reward + * @param luck + * The chance of the block + * @param luckBounds + * Min and max chance values + */ + void triggerRandomReward(World world, int x, int y, int z, EntityPlayer player, int chance); +} diff --git a/src/main/java/chanceCubes/renderer/SpecialRendererD20.java b/src/main/java/chanceCubes/renderer/SpecialRendererD20.java new file mode 100644 index 0000000..11685c9 --- /dev/null +++ b/src/main/java/chanceCubes/renderer/SpecialRendererD20.java @@ -0,0 +1,54 @@ +package chanceCubes.renderer; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.world.IBlockAccess; + +import org.lwjgl.opengl.GL11; + +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.config.CCubesSettings; +import chanceCubes.tileentities.TileChanceD20; +import chanceCubes.util.RenderUtil; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; + +public class SpecialRendererD20 implements ISimpleBlockRenderingHandler { + + private static final TileChanceD20 DUMMY_TILE = new TileChanceD20(); + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { + if (block != CCubesBlocks.chanceIcosahedron) return; + + DUMMY_TILE.setWorldObj(Minecraft.getMinecraft().theWorld); + DUMMY_TILE.blockType = block; + DUMMY_TILE.blockMetadata = metadata; + + GL11.glPushMatrix(); + + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + TileEntityRendererDispatcher.instance + .renderTileEntityAt(DUMMY_TILE, 0.0D, 0.0D, 0.0D, RenderUtil.getTimer().renderPartialTicks); + + GL11.glPopMatrix(); + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, + RenderBlocks renderer) { + return false; + } + + @Override + public boolean shouldRender3DInInventory(int modelId) { + return true; + } + + @Override + public int getRenderId() { + return CCubesSettings.d20RenderID; + } +} diff --git a/src/main/java/chanceCubes/renderer/TileChanceD20Renderer.java b/src/main/java/chanceCubes/renderer/TileChanceD20Renderer.java new file mode 100644 index 0000000..11b5974 --- /dev/null +++ b/src/main/java/chanceCubes/renderer/TileChanceD20Renderer.java @@ -0,0 +1,121 @@ +package chanceCubes.renderer; + +import java.awt.Color; +import java.util.Random; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.AdvancedModelLoader; +import net.minecraftforge.client.model.IModelCustom; + +import org.lwjgl.opengl.GL11; + +import chanceCubes.tileentities.TileChanceD20; +import chanceCubes.util.RenderUtil; + +public class TileChanceD20Renderer extends TileEntitySpecialRenderer { + + private IModelCustom model; + private ResourceLocation texture; + + private static final float BASE_COLOR_SPEED = 75F; + private static final float HOVER_SPEED = 12F; + + private static final Random random = new Random(); + + public TileChanceD20Renderer() { + model = AdvancedModelLoader.loadModel(new ResourceLocation("chancecubes", "models/blocks/d20.obj")); + texture = new ResourceLocation("chancecubes", "textures/models/d20.png"); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double posX, double posY, double posZ, float partialTick) { + TileChanceD20 d20 = (TileChanceD20) tileEntity; + + random.setSeed(RenderUtil.getCoordinateRandom(d20.xCoord, d20.yCoord, d20.zCoord)); + + int stage = d20.getStage(); + + float wave = stage == 0 ? MathHelper.sin( + (((tileEntity.getWorldObj() + .getTotalWorldTime() % (HOVER_SPEED * 1000F) + partialTick) / (HOVER_SPEED * 1000F)) + + random.nextFloat()) * 360F) + : ((stage + partialTick) / 10f); + float rot = d20.rotation + (d20.rotationDelta * partialTick); + float color = (tileEntity.getWorldObj() + .getTotalWorldTime() % BASE_COLOR_SPEED + partialTick) / BASE_COLOR_SPEED; + + GL11.glPushMatrix(); + + GL11.glTranslated(posX + 0.5F, posY + 0.5F + wave * 0.1F, posZ + 0.5F); + GL11.glRotatef(rot, 0F, 1F, 0F); + Color tmpClr = new Color(Color.HSBtoRGB(color + random.nextFloat(), 1F, 1F)); + GL11.glColor3f(tmpClr.getRed() / 255F, tmpClr.getGreen() / 255F, tmpClr.getBlue() / 255F); + + Minecraft.getMinecraft().renderEngine.bindTexture(texture); + model.renderAll(); + + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + + GL11.glTranslated(posX + 0.5F, posY + 1.5F + wave * 0.1F, posZ + 2.5F); + Tessellator tessellator = Tessellator.instance; + RenderHelper.disableStandardItemLighting(); + float f1 = ((float) tileEntity.getWorldObj() + .getTotalWorldTime() % 750 + partialTick) / 750.0F; + float f2 = 0F; + + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glDepthMask(false); + GL11.glPushMatrix(); + GL11.glTranslatef(0.0F, -1.0F, -2.0F); + random.setSeed(432L); + + for (int i = 0; i < (16 + (stage / 10)); ++i) { + GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(random.nextFloat() * 360.0F + f1 * 360.0F, 0.0F, 0.0F, 1.0F); + tessellator.startDrawing(6); + float f3 = random.nextFloat() * 20.0F + 5.0F + f2 * 10.0F; + float f4 = random.nextFloat() * 2.0F + 1.0F + f2 * 2.0F; + + f3 *= 0.1F; + f4 *= 0.1F; + + tessellator.setColorRGBA_I(tmpClr.getRGB(), (int) (255.0F * (1.0F - f2))); + tessellator.addVertex(0.0D, 0.0D, 0.0D); + tessellator.setColorRGBA_I(tmpClr.getRGB(), 0); + tessellator.addVertex(-0.866D * (double) f4, (double) f3, (double) (-0.5F * f4)); + tessellator.addVertex(0.866D * (double) f4, (double) f3, (double) (-0.5F * f4)); + tessellator.addVertex(0.0D, (double) f3, (double) (1.0F * f4)); + tessellator.addVertex(-0.866D * (double) f4, (double) f3, (double) (-0.5F * f4)); + tessellator.draw(); + } + + GL11.glPopMatrix(); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_BLEND); + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_ALPHA_TEST); + RenderHelper.enableStandardItemLighting(); + + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/chanceCubes/renderer/TileCubeDispenserRenderer.java b/src/main/java/chanceCubes/renderer/TileCubeDispenserRenderer.java new file mode 100644 index 0000000..4643b84 --- /dev/null +++ b/src/main/java/chanceCubes/renderer/TileCubeDispenserRenderer.java @@ -0,0 +1,59 @@ +package chanceCubes.renderer; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +import chanceCubes.tileentities.TileCubeDispenser; + +public class TileCubeDispenserRenderer extends TileEntitySpecialRenderer { + + private static final float ROTATE_SPEED = 0.3F; + private static final float WAVE_SPEED = 0.1F; + + private RenderBlocks renderer; + + public TileCubeDispenserRenderer() { + + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double posX, double posY, double posZ, float partialTick) { + World world = tileEntity.getWorldObj(); + + if (this.renderer == null) this.renderer = new RenderBlocks(world); + + int x = tileEntity.xCoord; + int y = tileEntity.yCoord; + int z = tileEntity.zCoord; + + int meta = world.getBlockMetadata(x, y, z); + TileCubeDispenser te = ((TileCubeDispenser) tileEntity); + EntityItem entity = te.getRenderEntityItem(meta); + + GL11.glPushMatrix(); + te.wave += WAVE_SPEED; + te.wave %= 125; + float yy = MathHelper.sin((te.wave) / 10.0F + entity.hoverStart) * 0.1F + 0.1F; + GL11.glTranslated(posX + 0.5f, posY + yy + 1.25f, posZ + 0.5f); + entity.getEntityItem().stackSize = 1; + entity.age = 0; + entity.rotationYaw = 0; + te.rot += ROTATE_SPEED; + te.rot %= 360; + GL11.glRotatef(te.rot, 0.0F, 1.0F, 0.0F); + entity.setLocationAndAngles(posX + 0.5f, posY + yy + 1.25f, posZ + 0.5f, 0.0F, 0.0F); + RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); + GL11.glPopMatrix(); + } + + public void func_147496_a(World world) { + + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/BasicTreesBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/BasicTreesBiome.java new file mode 100644 index 0000000..a722328 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/BasicTreesBiome.java @@ -0,0 +1,133 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityPig; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class BasicTreesBiome implements IBioDomeBiome { + + private Random rand = new Random(); + + public List addTree(int x, int y, int z, int delay) { + List blocks = new ArrayList(); + + for (int yy = 1; yy < 6; yy++) { + blocks.add(new OffsetBlock(x, y + yy, z, Blocks.log, false, delay)); + delay++; + } + + for (int xx = -2; xx < 3; xx++) { + for (int zz = -2; zz < 3; zz++) { + for (int yy = 0; yy < 2; yy++) { + if ((xx != 0 || zz != 0)) { + blocks.add(new OffsetBlock(x + xx, y + 4 + yy, z + zz, Blocks.leaves, false, delay)); + delay++; + } + } + } + } + + blocks.add(new OffsetBlock(x + 1, y + 6, z, Blocks.leaves, false, delay)); + delay++; + blocks.add(new OffsetBlock(x - 1, y + 6, z, Blocks.leaves, false, delay)); + delay++; + blocks.add(new OffsetBlock(x, y + 6, z + 1, Blocks.leaves, false, delay)); + delay++; + blocks.add(new OffsetBlock(x, y + 6, z - 1, Blocks.leaves, false, delay)); + delay++; + blocks.add(new OffsetBlock(x, y + 6, z, Blocks.leaves, false, delay)); + delay++; + + return blocks; + } + + @Override + public void spawnEntities(int centerX, int centerY, int centerZ, World world) { + for (int i = 0; i < rand.nextInt(10) + 5; i++) { + int ri = rand.nextInt(5); + + if (ri == 0) { + EntityChicken chicken = new EntityChicken(world); + chicken.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(chicken); + } else if (ri == 1) { + EntityCow cow = new EntityCow(world); + cow.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(cow); + } else if (ri == 2) { + EntityHorse horse = new EntityHorse(world); + horse.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(horse); + } else if (ri == 3) { + EntityPig pig = new EntityPig(world); + pig.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(pig); + } else if (ri == 4) { + EntitySheep sheep = new EntitySheep(world); + sheep.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(sheep); + } + } + } + + @Override + public Block getFloorBlock() { + return Blocks.grass; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y != 0) return; + if (dist < 0 && rand.nextInt(5) == 0) { + OffsetBlock osb = new OffsetBlock( + x, + y + 1, + z, + Blocks.tallgrass, + false, + (delay / BioDomeReward.delayShorten)); + osb.setData((byte) 1); + blocks.add(osb); + } else if (dist < -5 && rand.nextInt(100) == 0) { + List treeblocks = this.addTree(x, y, z, (delay / BioDomeReward.delayShorten)); + blocks.addAll(treeblocks); + } + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/DesertBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/DesertBiome.java new file mode 100644 index 0000000..6210c5e --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/DesertBiome.java @@ -0,0 +1,59 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class DesertBiome implements IBioDomeBiome { + + @Override + public void spawnEntities(int centerX, int centerY, int centerZ, World world) { + + } + + @Override + public Block getFloorBlock() { + return Blocks.sandstone; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y != 0) return; + + if (dist < 0 && rand.nextInt(50) == 0) { + delay++; + OffsetBlock osb = new OffsetBlock(x, y, z, Blocks.sand, false, (delay / BioDomeReward.delayShorten) + 1); + blocks.add(osb); + osb = new OffsetBlock(x, y - 1, z, Blocks.sandstone, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + osb = new OffsetBlock(x, y + 1, z, Blocks.deadbush, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + } + + if (dist < 0 && rand.nextInt(60) == 0) { + delay++; + OffsetBlock osb = new OffsetBlock(x, y, z, Blocks.sand, false, (delay / BioDomeReward.delayShorten) + 1); + blocks.add(osb); + osb = new OffsetBlock(x, y - 1, z, Blocks.sandstone, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + osb = new OffsetBlock(x, y + 1, z, Blocks.cactus, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + osb = new OffsetBlock(x, y + 2, z, Blocks.cactus, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + osb = new OffsetBlock(x, y + 3, z, Blocks.cactus, false, (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + } + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/EndBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/EndBiome.java new file mode 100644 index 0000000..c701029 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/EndBiome.java @@ -0,0 +1,61 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class EndBiome implements IBioDomeBiome { + + private Random rand = new Random(); + + public List addTower(int x, int y, int z, int delay) { + List blocks = new ArrayList(); + + for (int yy = 0; yy < 10; yy++) { + for (int xx = -1; xx < 2; xx++) { + for (int zz = -1; zz < 2; zz++) { + blocks.add(new OffsetBlock(x + xx, y + yy, z + zz, Blocks.obsidian, false, delay)); + delay++; + } + } + } + blocks.add(new OffsetBlock(x, y + 10, z, Blocks.bedrock, false, delay)); + return blocks; + } + + @Override + public void spawnEntities(int centerX, int centerY, int centerZ, World world) { + for (int i = 0; i < rand.nextInt(10) + 5; i++) { + EntityEnderman enderman = new EntityEnderman(world); + enderman.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(enderman); + } + } + + @Override + public Block getFloorBlock() { + return Blocks.end_stone; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y != 0) return; + if (dist < -5 && rand.nextInt(200) == 0) { + List treeblocks = this.addTower(x, y, z, (delay / BioDomeReward.delayShorten)); + blocks.addAll(treeblocks); + } + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/IBioDomeBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/IBioDomeBiome.java new file mode 100644 index 0000000..d723488 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/IBioDomeBiome.java @@ -0,0 +1,18 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public interface IBioDomeBiome { + + public void spawnEntities(int centerX, int centerY, int centerZ, World world); + + public Block getFloorBlock(); + + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay); +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/NetherBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/NetherBiome.java new file mode 100644 index 0000000..629af14 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/NetherBiome.java @@ -0,0 +1,80 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.entity.monster.EntityPigZombie; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class NetherBiome implements IBioDomeBiome { + + private Random rand = new Random(); + + @Override + public void spawnEntities(int centerX, int centerY, int centerZ, World world) { + for (int i = 0; i < rand.nextInt(10) + 5; i++) { + int ri = rand.nextInt(5); + + if (ri == 0) { + EntityGhast ghast = new EntityGhast(world); + ghast.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 5, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(ghast); + } else { + EntityPigZombie pigman = new EntityPigZombie(world); + pigman.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(pigman); + } + } + } + + @Override + public Block getFloorBlock() { + return Blocks.netherrack; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y != 0) return; + + if (dist < 0 && rand.nextInt(50) == 0) { + OffsetBlock osb = new OffsetBlock( + x, + y - 1, + z, + Blocks.netherrack, + false, + (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + delay++; + osb = new OffsetBlock(x, y, z, Blocks.lava, false, (delay / BioDomeReward.delayShorten) + 1); + blocks.add(osb); + delay++; + } else if (dist < 0 && rand.nextInt(20) == 0) { + OffsetBlock osb = new OffsetBlock( + x, + y, + z, + Blocks.soul_sand, + false, + (delay / BioDomeReward.delayShorten) + 1); + blocks.add(osb); + delay++; + } + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/OceanBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/OceanBiome.java new file mode 100644 index 0000000..4ff0aa1 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/OceanBiome.java @@ -0,0 +1,43 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.passive.EntitySquid; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class OceanBiome implements IBioDomeBiome { + + private Random rand = new Random(); + + @Override + public void spawnEntities(int centerX, int centerY, int centerZ, World world) { + for (int i = 0; i < rand.nextInt(10) + 5; i++) { + EntitySquid squid = new EntitySquid(world); + squid.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + squid.setCustomNameTag("Mango"); + world.spawnEntityInWorld(squid); + } + } + + @Override + public Block getFloorBlock() { + return Blocks.clay; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y == 0 || dist >= 0) return; + blocks.add(new OffsetBlock(x, y, z, Blocks.water, false, delay / BioDomeReward.delayShorten)); + } +} diff --git a/src/main/java/chanceCubes/rewards/biodomeGen/SnowGlobeBiome.java b/src/main/java/chanceCubes/rewards/biodomeGen/SnowGlobeBiome.java new file mode 100644 index 0000000..6d9fe2f --- /dev/null +++ b/src/main/java/chanceCubes/rewards/biodomeGen/SnowGlobeBiome.java @@ -0,0 +1,74 @@ +package chanceCubes.rewards.biodomeGen; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.entity.projectile.EntitySnowball; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.rewards.giantRewards.BioDomeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class SnowGlobeBiome implements IBioDomeBiome { + + private Random rand = new Random(); + + @Override + public void spawnEntities(final int centerX, final int centerY, final int centerZ, final World world) { + for (int i = 0; i < rand.nextInt(10) + 5; i++) { + EntitySnowman snowman = new EntitySnowman(world); + snowman.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(snowman); + } + + Scheduler.scheduleTask(new Task("SnowGlobe Snow", 20) { + + @Override + public void callback() { + for (int i = 0; i < 100; i++) { + EntitySnowball snowball = new EntitySnowball(world); + snowball.motionX = -1 + (Math.random() * 2); + snowball.motionY = 0.8; + snowball.motionZ = -1 + (Math.random() * 2); + snowball.setLocationAndAngles( + centerX + (rand.nextInt(31) - 15), + centerY + 1, + centerZ + (rand.nextInt(31) - 15), + 0, + 0); + world.spawnEntityInWorld(snowball); + } + } + }); + } + + @Override + public Block getFloorBlock() { + return Blocks.snow; + } + + @Override + public void getRandomGenBlock(float dist, Random rand, int x, int y, int z, List blocks, int delay) { + if (y != 0) return; + if (dist < 0 && rand.nextInt(5) == 0) { + OffsetBlock osb = new OffsetBlock( + x, + y + 1, + z, + Blocks.snow_layer, + false, + (delay / BioDomeReward.delayShorten)); + blocks.add(osb); + } + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/AnvilRain.java b/src/main/java/chanceCubes/rewards/defaultRewards/AnvilRain.java new file mode 100644 index 0000000..9511286 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/AnvilRain.java @@ -0,0 +1,79 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class AnvilRain implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + int x1 = x + (rand.nextInt(9) - 4); + int z1 = z + (rand.nextInt(9) - 4); + + int x2 = x + (rand.nextInt(9) - 4); + int z2 = z + (rand.nextInt(9) - 4); + + int x3 = x + (rand.nextInt(9) - 4); + int z3 = z + (rand.nextInt(9) - 4); + + int x4 = x + (rand.nextInt(9) - 4); + int z4 = z + (rand.nextInt(9) - 4); + + int x5 = x + (rand.nextInt(9) - 4); + int z5 = z + (rand.nextInt(9) - 4); + + int yy = 0; + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x, y + yy, z); + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x1, y + yy, z1); + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x2, y + yy, z2); + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x3, y + yy, z3); + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x4, y + yy, z4); + for (yy = 0; yy < 25; yy++) RewardsUtil.placeBlock(Blocks.air, world, x5, y + yy, z5); + for (yy = 0; yy < 25; yy++) + RewardsUtil.placeBlock(Blocks.air, world, (int) player.posX, y + yy, (int) player.posZ); + + RewardsUtil.placeBlock(Blocks.anvil, world, x, y + 25, z); + RewardsUtil.placeBlock(Blocks.anvil, world, x1, y + 25, z1); + RewardsUtil.placeBlock(Blocks.anvil, world, x2, y + 25, z2); + RewardsUtil.placeBlock(Blocks.anvil, world, x3, y + 25, z3); + RewardsUtil.placeBlock(Blocks.anvil, world, x4, y + 25, z4); + RewardsUtil.placeBlock(Blocks.anvil, world, x5, y + 25, z5); + RewardsUtil.placeBlock(Blocks.anvil, world, (int) player.posX, y + 25, (int) player.posZ); + + for (int xx = 0; xx < 2; xx++) { + int xxx = xx == 1 ? x + 5 : x - 5; + for (int zz = -5; zz < 6; zz++) { + for (int yyy = 0; yyy < 3; yyy++) { + RewardsUtil.placeBlock(Blocks.cobblestone, world, xxx, yyy + y, zz + z); + } + } + } + + for (int xx = -5; xx < 6; xx++) { + for (int zz = 0; zz < 2; zz++) { + int zzz = zz == 1 ? z + 5 : z - 5; + for (int yyy = 0; yyy < 3; yyy++) { + RewardsUtil.placeBlock(Blocks.cobblestone, world, xx + x, yyy + y, zzz); + } + } + } + } + + @Override + public int getChanceValue() { + return -45; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":AnvilRain"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/BasicReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/BasicReward.java new file mode 100644 index 0000000..71a69c8 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/BasicReward.java @@ -0,0 +1,35 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.type.IRewardType; + +public class BasicReward implements IChanceCubeReward { + + private String name; + private int chance; + private IRewardType[] rewards; + + public BasicReward(String name, int chance, IRewardType... rewards) { + this.name = name; + this.chance = chance; + this.rewards = rewards; + } + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + if (!world.isRemote && rewards != null) + for (IRewardType reward : rewards) reward.trigger(world, x, y, z, player); + } + + @Override + public int getChanceValue() { + return this.chance; + } + + @Override + public String getName() { + return this.name; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/BlindnessFightReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/BlindnessFightReward.java new file mode 100644 index 0000000..0cca01e --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/BlindnessFightReward.java @@ -0,0 +1,45 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class BlindnessFightReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.addPotionEffect(new PotionEffect(Potion.blindness.id, 100, 2)); + player.addChatMessage(new ChatComponentText("Fight!!!")); + + for (int xx = -2; xx < 3; xx++) { + for (int zz = -2; zz < 3; zz++) { + RewardsUtil.placeBlock(Blocks.air, world, x + xx, y, z + zz); + RewardsUtil.placeBlock(Blocks.air, world, x + xx, y + 1, z + zz); + } + } + + for (int i = 0; i < 6; i++) { + EntitySkeleton skele = new EntitySkeleton(world); + skele.onSpawnWithEgg(null); + skele.setPosition(x + 0.5, y, z + 0.5); + world.spawnEntityInWorld(skele); + } + } + + @Override + public int getChanceValue() { + return -65; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Blindness_Fight"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/BookOfMemesReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/BookOfMemesReward.java new file mode 100644 index 0000000..c8394f1 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/BookOfMemesReward.java @@ -0,0 +1,65 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class BookOfMemesReward implements IChanceCubeReward { + + private Random random = new Random(); + private List memes = new ArrayList(); + + public BookOfMemesReward() { + memes.add( + "Sodium, atomic number 11, was first isolated by Peter Dager in 1807. A chemical component of salt, he named it Na in honor of the saltiest region on earth, North America."); + memes.add("(╯°□°)╯︵ ┻━┻ \n ༼ᕗຈل͜ຈ༽ᕗ RAISE YOUR DONGERS ༼ᕗຈل͜ຈ༽ᕗ"); + memes.add("Darude- status \n ☐ Not Sandstorm \n ☑ Sandstorm"); + memes.add( + "( ͡° ͜ʖ ͡°) Every 60 seconds in Africa, a minute passes. Together we can stop this. Please spread the word ( ͡° ͜ʖ ͡°) "); + memes.add( + "YESTERDAY YOU SAID TOMMOROW, Don't let your dreams be memes, Don't meme your dreams be beams, Jet fuel won't melt tomorrow's memes, DON'T LET YOUR STEEL MEMES BE JET DREAMS"); + memes.add("If the human body is 75% water, how can you be 100% salt?"); + memes.add( + " ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ \n Sorry, I've dropped my bag of Doritos™ brand chips▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ► ▼ ◄ ◄ ▲▲ ► ▼ ◄▼ ◄ ◄ ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ► ▼ ◄ ▲ ►"); + memes.add("Hey Chat....... \n \n \n \n 123"); + } + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + String meme = memes.get(random.nextInt(memes.size())); + + ItemStack stack = new ItemStack(Items.written_book); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("title", "Book of Memes"); + nbt.setString("author", "Chance Cubes"); + NBTTagList pages = new NBTTagList(); + pages.appendTag(new NBTTagString(meme)); + nbt.setTag("pages", pages); + stack.stackTagCompound = (NBTTagCompound) nbt.copy(); + Entity itemEnt = new EntityItem(world, x, y, z, stack.copy()); + world.spawnEntityInWorld(itemEnt); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Book_Of_Memes"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/CakeIsALieReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/CakeIsALieReward.java new file mode 100644 index 0000000..8ca34d4 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/CakeIsALieReward.java @@ -0,0 +1,80 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesAchievements; +import chanceCubes.util.Location3I; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class CakeIsALieReward implements IChanceCubeReward { + + private Random random = new Random(); + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + RewardsUtil.sendMessageToNearPlayers(world, x, y, z, 32, "But is it a lie?"); + + RewardsUtil.placeBlock(Blocks.cake, world, x, y, z); + + if (random.nextInt(3) == 1) { + Task task = new Task("Cake_Is_A_Lie", 20) { + + @Override + public void callback() { + update(0, world, new Location3I(x, y, z), player); + } + }; + Scheduler.scheduleTask(task); + } + } + + @Override + public int getChanceValue() { + return 20; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Cake"; + } + + public void update(final int iteration, final World world, final Location3I loc, final EntityPlayer player) { + if (world.getBlockMetadata(loc.getX(), loc.getY(), loc.getZ()) > 0) { + RewardsUtil.placeBlock(Blocks.air, world, loc.getX(), loc.getY(), loc.getZ()); + RewardsUtil.sendMessageToNearPlayers(world, loc.getX(), loc.getY(), loc.getZ(), 32, "It's a lie!!!"); + EntityCreeper creeper = new EntityCreeper(world); + creeper.setLocationAndAngles(loc.getX(), loc.getY(), loc.getZ(), loc.getX() == 1 ? 90 : -90, 0); + if (random.nextInt(10) == 1) creeper.getDataWatcher() + .updateObject(17, Byte.valueOf((byte) 1)); + creeper.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 9999, 2)); + creeper.addPotionEffect(new PotionEffect(Potion.resistance.id, 60, 999)); + world.spawnEntityInWorld(creeper); + player.triggerAchievement(CCubesAchievements.itsALie); + return; + } + + if (iteration == 300) { + world.setBlockToAir(loc.getX(), loc.getY(), loc.getZ()); + return; + } + + Task task = new Task("Cake_Is_A_Lie", 20) { + + @Override + public void callback() { + update(iteration + 1, world, loc, player); + } + }; + Scheduler.scheduleTask(task); + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ChargedCreeperReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/ChargedCreeperReward.java new file mode 100644 index 0000000..81e4712 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ChargedCreeperReward.java @@ -0,0 +1,48 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ChargedCreeperReward implements IChanceCubeReward { + + @Override + public void trigger(final World world, final int x, final int y, final int z, EntityPlayer player) { + RewardsUtil.placeBlock(Blocks.air, world, x, y + 1, z); + EntityCreeper ent = new EntityCreeper(world); + ent.setLocationAndAngles(x + 0.5, y + .5, z + 0.5, 0, 0); + ent.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 99, true)); + ent.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 10, 99, true)); + world.spawnEntityInWorld(ent); + + Task task = new Task("Charged Creeper Reward", 2) { + + @Override + public void callback() { + world.addWeatherEffect(new EntityLightningBolt(world, x, y, z)); + } + }; + + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return -40; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Charged_Creeper"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ClearInventoryReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/ClearInventoryReward.java new file mode 100644 index 0000000..10e37aa --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ClearInventoryReward.java @@ -0,0 +1,56 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.items.ItemChanceCube; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ClearInventoryReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + boolean cubes = false; + final ItemStack[] inv = player.inventory.mainInventory.clone(); + final ItemStack[] armorinv = player.inventory.armorInventory.clone(); + for (int slotNum = 0; slotNum < player.inventory.getSizeInventory(); slotNum++) { + if (player.inventory.getStackInSlot(slotNum) != null && player.inventory.getStackInSlot(slotNum) + .getItem() instanceof ItemChanceCube) cubes = true; + else player.inventory.setInventorySlotContents(slotNum, null); + } + + world.playSoundEffect(x, y, z, "random.burp", 1, 1); + player.addChatMessage(new ChatComponentText("I hope you didn't have anything of value with you :)")); + if (cubes) player.addChatMessage(new ChatComponentText("Don't worry, I left the cubes for you!")); + + if (world.rand.nextInt(5) == 1) { + Task task = new Task("Replace_Inventory", 200) { + + @Override + public void callback() { + player.inventory.mainInventory = inv; + player.inventory.armorInventory = armorinv; + player.addChatMessage(new ChatComponentText("AHHHHHH JK!! You should have seen your face!")); + } + + }; + + Scheduler.scheduleTask(task); + } + } + + @Override + public int getChanceValue() { + return -100; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Clear_Inventory"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/CookieMonsterReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/CookieMonsterReward.java new file mode 100644 index 0000000..7318f78 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/CookieMonsterReward.java @@ -0,0 +1,57 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class CookieMonsterReward implements IChanceCubeReward { + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + if (!world.isRemote) { + RewardsUtil.sendMessageToNearPlayers(world, x, y, z, 32, "Here have some cookies!"); + Entity itemEnt = new EntityItem(world, x, y, z, new ItemStack(Items.cookie, 8)); + world.spawnEntityInWorld(itemEnt); + + Task task = new Task("Cookie Monster", 30) { + + @Override + public void callback() { + SpawnCM(); + } + + private void SpawnCM() { + EntityZombie cm = new EntityZombie(world); + cm.setPosition(x + 0.5, y, z + 0.5); + cm.setChild(true); + cm.setCustomNameTag("Cookie Monster"); + RewardsUtil.sendMessageToNearPlayers(world, x, y, z, 32, "[Cookie Monster] Hey! Those are mine!"); + world.spawnEntityInWorld(cm); + } + + }; + + Scheduler.scheduleTask(task); + } + + } + + @Override + public int getChanceValue() { + return -5; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Cookie_Monster"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/CreeperSurroundedReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/CreeperSurroundedReward.java new file mode 100644 index 0000000..8fbdc5d --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/CreeperSurroundedReward.java @@ -0,0 +1,80 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class CreeperSurroundedReward implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + int px = (int) player.posX; + int pz = (int) player.posZ; + player.addPotionEffect(new PotionEffect(Potion.blindness.id, 100, 1, true)); + boolean skip = false; + EntityCreeper creeper; + for (int xx = 0; xx < 2; xx++) { + for (int zz = -4; zz < 5; zz++) { + if (!skip) { + int xxx = xx == 1 ? px + 4 : px - 4; + if (!world.getBlock(xxx, y, pz + zz) + .isOpaqueCube() + && !world.getBlock(xxx, y + 1, pz + zz) + .isOpaqueCube() + && !world.getBlock(xxx, y + 2, pz + zz) + .isOpaqueCube()) { + creeper = new EntityCreeper(world); + creeper.setLocationAndAngles(xxx, y, pz + zz, xx == 1 ? 90 : -90, 0); + if (rand.nextInt(10) == 1) creeper.getDataWatcher() + .updateObject(17, Byte.valueOf((byte) 1)); + creeper.addPotionEffect(new PotionEffect(Potion.resistance.id, 60, 5)); + world.spawnEntityInWorld(creeper); + } + } + skip = !skip; + } + } + + for (int xx = -4; xx < 5; xx++) { + for (int zz = 0; zz < 2; zz++) { + if (!skip) { + int zzz = zz == 1 ? pz + 4 : pz - 4; + if (world.getBlock(px + xx, y, zzz) + .equals(Blocks.air) + && world.getBlock(px + xx, y + 1, zzz) + .equals(Blocks.air) + && world.getBlock(px + xx, y + 2, zzz) + .equals(Blocks.air)) { + creeper = new EntityCreeper(world); + creeper.setLocationAndAngles(px + xx, y, zzz, zz == 1 ? 180 : 0, 0); + if (rand.nextInt(10) == 1) creeper.getDataWatcher() + .updateObject(17, Byte.valueOf((byte) 1)); + creeper.addPotionEffect(new PotionEffect(Potion.resistance.id, 60, 5)); + world.spawnEntityInWorld(creeper); + } + } + skip = !skip; + } + } + } + + @Override + public int getChanceValue() { + return -85; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Surrounded_Creeper"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/CustomUserReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/CustomUserReward.java new file mode 100644 index 0000000..0971acb --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/CustomUserReward.java @@ -0,0 +1,150 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import net.minecraftforge.common.UsernameCache; + +import org.apache.logging.log4j.Level; + +import com.google.gson.JsonElement; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.config.CCubesSettings; +import chanceCubes.config.CustomRewardsLoader; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.util.HTTPUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class CustomUserReward implements IChanceCubeReward { + + private String userName = ""; + private UUID uuid = null; + private String type; + + private List customRewards = new ArrayList(); + + public CustomUserReward(EntityPlayer player) { + if (!CCubesSettings.userSpecificRewards) return; + + JsonElement users; + try { + users = HTTPUtil + .getWebFile("https://api.theprogrammingturkey.com/chance_cubes/custom_rewards/UserList.json"); + } catch (Exception e) { + CCubesCore.logger.log(Level.ERROR, "Chance Cubes failed to get the list of users with custom rewards!"); + return; + } + + UUID uuidTemp = this.getPlayerUUID(player.getCommandSenderName()); + if (uuidTemp == null) { + CCubesCore.logger.log(Level.ERROR, "Chance Cubes failed to get the uuid of the user!"); + return; + } + for (JsonElement user : users.getAsJsonArray()) { + if (user.getAsJsonObject() + .get("UUID") + .getAsString() + .equalsIgnoreCase(uuidTemp.toString())) { + userName = user.getAsJsonObject() + .get("Name") + .getAsString(); + uuid = uuidTemp; + type = user.getAsJsonObject() + .get("Type") + .getAsString(); + } + } + + if (userName.equals("")) { + CCubesCore.logger.log(Level.INFO, "No custom rewards detected for the current user!"); + return; + } + + JsonElement userRewards; + + try { + userRewards = HTTPUtil.getWebFile( + "https://api.theprogrammingturkey.com/chance_cubes/custom_rewards/users/" + userName + ".json"); + } catch (Exception e) { + CCubesCore.logger.log(Level.ERROR, "Chance Cubes failed to get the custom list for " + userName + "!"); + CCubesCore.logger.log(Level.ERROR, e.getMessage()); + return; + } + + for (Entry reward : userRewards.getAsJsonObject() + .entrySet()) { + customRewards.add( + CustomRewardsLoader.instance.parseReward(reward) + .getKey()); + } + + ChanceCubeRegistry.INSTANCE.registerReward(this); + player.addChatMessage( + new ChatComponentText("Seems you have some custom Chance Cubes rewards " + this.userName + "....")); + player.addChatMessage(new ChatComponentText("Let the fun begin! >:)")); + } + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + if (!UsernameCache.getLastKnownUsername(uuid) + .equalsIgnoreCase(player.getCommandSenderName())) { + player.addChatMessage( + new ChatComponentText("Hey you aren't " + this.userName + "! You can't have their reward! Try again!")); + Entity itemEnt = new EntityItem(world, x, y, z, new ItemStack(CCubesBlocks.chanceCube, 1)); + world.spawnEntityInWorld(itemEnt); + return; + } + + player.addChatMessage( + new ChatComponentText("Selecting best (possibly deadly) reward for " + this.type + " " + this.userName)); + + Task task = new Task("Custom Reward", 100) { + + @Override + public void callback() { + triggerAcutalReward(world, x, y, z, player); + } + }; + + Scheduler.scheduleTask(task); + } + + public void triggerAcutalReward(World world, int x, int y, int z, EntityPlayer player) { + this.customRewards.get(world.rand.nextInt(this.customRewards.size())) + .trigger(world, x, y, z, player); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":CR_" + this.userName; + } + + public UUID getPlayerUUID(String username) { + for (Map.Entry entry : UsernameCache.getMap() + .entrySet()) { + if (entry.getValue() + .equalsIgnoreCase(username)) { + return entry.getKey(); + } + } + return null; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/DiscoReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/DiscoReward.java new file mode 100644 index 0000000..be39d1f --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/DiscoReward.java @@ -0,0 +1,45 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.util.RewardsUtil; + +public class DiscoReward implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int xx = -4; xx < 5; xx++) for (int zz = -4; zz < 5; zz++) + RewardsUtil.placeBlock(Blocks.wool, world, x + xx, y - 1, z + zz, rand.nextInt(16)); + + for (int i = 0; i < 10; i++) { + EntitySheep sheep = new EntitySheep(world); + sheep.setCustomNameTag("jeb_"); + sheep.setLocationAndAngles(x, y + 1, z, 0, 0); + world.spawnEntityInWorld(sheep); + } + + RewardsUtil.placeBlock(CCubesBlocks.chanceIcosahedron, world, x, y + 3, z); + + RewardsUtil.sendMessageToNearPlayers(world, x, y, z, 32, "Disco Party!!!!"); + } + + @Override + public int getChanceValue() { + return 40; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Disco"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/EnderCrystalTimerReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/EnderCrystalTimerReward.java new file mode 100644 index 0000000..0ccdaf1 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/EnderCrystalTimerReward.java @@ -0,0 +1,38 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.item.EntityEnderCrystal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class EnderCrystalTimerReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int i = 30; i > 0; i--) RewardsUtil.placeBlock(Blocks.air, world, x, y + i, z); + + EntityEnderCrystal ent = new EntityEnderCrystal(world); + ent.setLocationAndAngles(x + 0.5, y, z + 0.5, 0, 0); + world.spawnEntityInWorld(ent); + + EntityArrow arrow = new EntityArrow(world, x + 0.5, y + 29, z + 0.5); + arrow.motionX = 0; + arrow.motionY = -0.25f; + arrow.motionZ = 0; + world.spawnEntityInWorld(arrow); + } + + @Override + public int getChanceValue() { + return -90; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Ender_Crystal_Timer"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/FiveProngReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/FiveProngReward.java new file mode 100644 index 0000000..0263ef0 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/FiveProngReward.java @@ -0,0 +1,44 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.util.RewardsUtil; + +public class FiveProngReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int xx = x - 3; xx <= x + 3; xx++) for (int zz = z - 3; zz <= z + 3; zz++) + for (int yy = y; yy <= y + 4; yy++) RewardsUtil.placeBlock(Blocks.air, world, xx, yy, zz); + + RewardsUtil.placeBlock(Blocks.quartz_block, world, x, y, z); + RewardsUtil.placeBlock(Blocks.quartz_block, world, x, y + 1, z); + RewardsUtil.placeBlock(CCubesBlocks.chanceIcosahedron, world, x, y + 2, z); + + RewardsUtil.placeBlock(Blocks.quartz_block, world, x - 3, y, z - 3); + RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x - 3, y + 1, z - 3); + + RewardsUtil.placeBlock(Blocks.quartz_block, world, x - 3, y, z + 3); + RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x - 3, y + 1, z + 3); + + RewardsUtil.placeBlock(Blocks.quartz_block, world, x + 3, y, z - 3); + RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x + 3, y + 1, z - 3); + + RewardsUtil.placeBlock(Blocks.quartz_block, world, x + 3, y, z + 3); + RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x + 3, y + 1, z + 3); + } + + @Override + public int getChanceValue() { + return -10; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":5_Prongs"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/HerobrineReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/HerobrineReward.java new file mode 100644 index 0000000..c23d82b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/HerobrineReward.java @@ -0,0 +1,95 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesAchievements; +import chanceCubes.util.CCubesCommandSender; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class HerobrineReward implements IChanceCubeReward { + + private String[] leaveSayings = new String[] { "I will be back for you.", "Another day, another time.", + "No, you are not ready for my wrath.", "Perhaps tomorrow you will be worthy of my challenge", + "I sense that I am needed else where. You escape..... For now....", "If only you were worth my time." }; + private String[] staySayings = new String[] { "Today is the day.", "May the other world have mercy on your soul.", + "MUWAHAHAHAHAHAHAH", "Time to feast!!", "How fast can your run boy!", + "It's a shame this will end so quickly for you.", "My presence alone will be your end" }; + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + update(world, x, y, z, player, 0, world.rand.nextInt(5) == 1); + } + + private void schedule(final World world, final int x, final int y, final int z, final EntityPlayer player, + final int stage, final boolean staying) { + Task task = new Task("Herobrine Reward", 40) { + + @Override + public void callback() { + update(world, x, y, z, player, stage, staying); + } + + }; + + Scheduler.scheduleTask(task); + } + + private void update(World world, int x, int y, int z, EntityPlayer player, int stage, boolean staying) { + switch (stage) { + case 0: { + RewardsUtil.sendMessageToAllPlayers(world, EnumChatFormatting.YELLOW + "Herobrine joined the game."); + break; + } + case 1: { + if (staying) RewardsUtil.sendMessageToAllPlayers( + world, + " " + staySayings[world.rand.nextInt(staySayings.length)]); + else RewardsUtil.sendMessageToAllPlayers( + world, + " " + leaveSayings[world.rand.nextInt(leaveSayings.length)]); + break; + } + case 2: { + if (staying) { + RewardsUtil.placeBlock(Blocks.air, world, x, y + 1, z); + Boolean rule = MinecraftServer.getServer().worldServers[0].getGameRules() + .getGameRuleBooleanValue("commandBlockOutput"); + MinecraftServer.getServer().worldServers[0].getGameRules() + .setOrCreateGameRule("commandBlockOutput", "false"); + String command = "/summon Zombie ~ ~ ~ {CustomName:\"Herobrine\",CustomNameVisible:1,IsVillager:0,IsBaby:0,CanBreakDoors:1,Equipment:[{id:276,Count:1,tag:{ench:[{id:16,lvl:10},{id:20,lvl:2}]}},{id:313,Count:1,tag:{ench:[{id:0,lvl:10}]}},{id:312,Count:1,tag:{ench:[{id:0,lvl:10}]}},{id:311,Count:1,tag:{ench:[{id:0,lvl:10}]}},{id:379,Damage:3,Count:1,tag:{SkullOwner:Herobrine}}],DropChances:[0.0F,0.0F,0.0F,0.0F,0.0F],Attributes:[{Name:generic.maxHealth,Base:500}],HealF:500}"; + CCubesCommandSender sender = new CCubesCommandSender(player, x, y, z); + MinecraftServer.getServer() + .getCommandManager() + .executeCommand(sender, command); + MinecraftServer.getServer().worldServers[0].getGameRules() + .setOrCreateGameRule("commandBlockOutput", rule.toString()); + player.triggerAchievement(CCubesAchievements.herobrine); + } else { + RewardsUtil.sendMessageToAllPlayers(world, EnumChatFormatting.YELLOW + "Herobrine left the game."); + } + break; + } + } + + stage++; + + if (stage < 3) schedule(world, x, y, z, player, stage, staying); + } + + @Override + public int getChanceValue() { + return -60; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Herobrine"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/IChanceCubeReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/IChanceCubeReward.java new file mode 100644 index 0000000..c54e679 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/IChanceCubeReward.java @@ -0,0 +1,28 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IChanceCubeReward { + + /** + * What occurs when the block is "opened" + * + * @param world + * @param x + * @param y + * @param z + * @param player Player who triggered the block + */ + public void trigger(World world, int x, int y, int z, EntityPlayer player); + + /** + * @return How "lucky" this block is (can be negative). 0 would indicate an "average" reward. + */ + public int getChanceValue(); + + /** + * @return Unique name for reward (suggested to pre-pend MODID). + */ + public String getName(); +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/InventoryBombReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/InventoryBombReward.java new file mode 100644 index 0000000..b39f6cc --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/InventoryBombReward.java @@ -0,0 +1,68 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class InventoryBombReward implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (ItemStack stack : player.inventory.mainInventory) { + if (stack == null) continue; + EntityItem ient = new EntityItem(world, x, y, z, stack); + ient.motionY = rand.nextInt(1) - 0.5; + ient.delayBeforeCanPickup = 40; + world.spawnEntityInWorld(ient); + } + for (ItemStack stack : player.inventory.armorInventory) { + if (stack == null) continue; + EntityItem ient = new EntityItem(world, x, y, z, stack); + ient.motionY = rand.nextInt(1) - 0.5; + ient.delayBeforeCanPickup = 40; + world.spawnEntityInWorld(ient); + } + + player.inventory.openInventory(); + + for (int i = 0; i < player.inventory.mainInventory.length; i++) + player.inventory.mainInventory[i] = new ItemStack(Blocks.deadbush, 64); + + for (int i = 0; i < player.inventory.armorInventory.length; i++) { + ItemStack stack = new ItemStack(Blocks.deadbush, 64); + if (i == 0) { + stack.setStackDisplayName("ButtonBoy"); + stack.stackSize = 13; + } else if (i == 1) { + stack.setStackDisplayName("TheBlackswordsman"); + stack.stackSize = 13; + } + player.inventory.armorInventory[i] = stack; + } + + player.inventory.closeInventory(); + + player.addChatMessage(new ChatComponentText("Inventory Bomb!!!!")); + + } + + @Override + public int getChanceValue() { + return -65; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Inventory_Bomb"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/InventoryChestReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/InventoryChestReward.java new file mode 100644 index 0000000..d843a26 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/InventoryChestReward.java @@ -0,0 +1,64 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class InventoryChestReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + final List stacks = new ArrayList(); + for (ItemStack stack : player.inventory.mainInventory.clone()) if (stack != null) stacks.add(stack); + + ItemStack[] armor = player.inventory.armorInventory.clone(); + player.inventory.clearInventory(null, -1); + player.inventory.armorInventory = armor; + + player.addChatMessage(new ChatComponentText("At least i didnt delete your items...")); + + RewardsUtil.placeBlock(Blocks.chest, world, x, y, z); + RewardsUtil.placeBlock(Blocks.chest, world, x + 1, y, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x, y - 1, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 1, y - 1, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x - 1, y, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 2, y, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x, y, z + 1); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 1, y, z + 1); + RewardsUtil.placeBlock(Blocks.obsidian, world, x, y, z - 1); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 1, y, z - 1); + RewardsUtil.placeBlock(Blocks.obsidian, world, x, y - 1, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 1, y - 1, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x, y + 1, z); + RewardsUtil.placeBlock(Blocks.obsidian, world, x + 1, y + 1, z); + + TileEntityChest chest = (TileEntityChest) world.getTileEntity(x, y, z); + + for (int i = 0; i < stacks.size(); i++) { + if (i > chest.getSizeInventory() * 2) return; + else if (i > chest.getSizeInventory()) chest = (TileEntityChest) world.getTileEntity(x + 1, y, z); + + chest.setInventorySlotContents(i % chest.getSizeInventory(), stacks.get(i)); + } + } + + @Override + public int getChanceValue() { + return -70; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Inventory_Chest"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ItemOfDestinyReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/ItemOfDestinyReward.java new file mode 100644 index 0000000..7449b20 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ItemOfDestinyReward.java @@ -0,0 +1,114 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ItemOfDestinyReward implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + final EntityItem item = new EntityItem(world, x, y, z, new ItemStack(this.randomItem(), 1)); + item.delayBeforeCanPickup = 100000; + world.spawnEntityInWorld(item); + player.addChatMessage(new ChatComponentText("Selecting random item")); + Task task = new Task("Item_Of_Destiny_Reward", 5) { + + @Override + public void callback() { + changeItem(item, 0, player); + } + }; + Scheduler.scheduleTask(task); + } + + private void changeItem(final EntityItem item, final int iteration, final EntityPlayer player) { + Task task = new Task("Item_Of_Destiny_Reward", 5) { + + @Override + public void callback() { + if (iteration + 1 > 17) { + player.addChatMessage(new ChatComponentText("Random item selected")); + player.addChatMessage(new ChatComponentText("Selecting number of enchants to give item")); + changeEnchantAmount(item, player); + } else { + item.setEntityItemStack(new ItemStack(randomItem(), 1)); + changeItem(item, iteration + 1, player); + } + } + }; + Scheduler.scheduleTask(task); + } + + private void changeEnchantAmount(final EntityItem item, final EntityPlayer player) { + Task task = new Task("Item_Of_Destiny_Reward", 50) { + + @Override + public void callback() { + int i = rand.nextInt(9); + int amount = i < 5 ? 1 : i < 8 ? 2 : 3; + player.addChatMessage(new ChatComponentText(amount + " random enchants will be added!")); + player.addChatMessage(new ChatComponentText("Selecting random enchant to give to the item")); + changeEnchants(item, amount, 0, player); + } + }; + Scheduler.scheduleTask(task); + } + + private void changeEnchants(final EntityItem item, final int enchants, final int iteration, + final EntityPlayer player) { + Task task = new Task("Item_Of_Destiny_Reward", 50) { + + @Override + public void callback() { + if (iteration < enchants) { + Enchantment ench = randomEnchantment(); + int level = ench.getMinLevel() + rand.nextInt(ench.getMaxLevel()); + item.getEntityItem() + .addEnchantment(ench, level); + player.addChatMessage( + new ChatComponentText(ench.getTranslatedName(level) + " Has been added to the item!")); + changeEnchants(item, enchants, iteration + 1, player); + } else { + player.addChatMessage(new ChatComponentText("Your item of destiny is complete! Enjoy!")); + item.delayBeforeCanPickup = 0; + } + } + }; + Scheduler.scheduleTask(task); + } + + public Item randomItem() { + Item item = Item.getItemById(256 + rand.nextInt(166)); + while (item == null) item = Item.getItemById(256 + rand.nextInt(166)); + return item; + } + + public Enchantment randomEnchantment() { + Enchantment ench = Enchantment.enchantmentsList[rand.nextInt(Enchantment.enchantmentsList.length)]; + while (ench == null) ench = Enchantment.enchantmentsList[rand.nextInt(Enchantment.enchantmentsList.length)]; + return ench; + } + + @Override + public int getChanceValue() { + return 40; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Item_Of_Destiny"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ItemRenamer.java b/src/main/java/chanceCubes/rewards/defaultRewards/ItemRenamer.java new file mode 100644 index 0000000..9a2951b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ItemRenamer.java @@ -0,0 +1,72 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesAchievements; + +public class ItemRenamer implements IChanceCubeReward { + + private Random rand = new Random(); + + // @formatter:off + private String[] names = {"Turkey", "qnxb", "Darkosto", "Wyld", "Funwayguy", "ButtonBoy", "SlothMonster", + "Vash", "Cazador", "KiwiFails", "Matrixis", "FlameGoat", "iChun", "tibbzeh", "Reninsane", + "PulpJohnFiction", "Zeek", "Sevadus", "Bob Ross", "T-loves", "Headwounds", "JonBams"}; + + private String[] adjectives = {"Destroyer", "Terror", "Wrath", "Smasher", "P90", "Wisdom", "Savior", + "Lightning Bringer", "Rage", "Happiness", "Shocker", " Slayer", "Sunshine", "Blade", + "Tamer", "Order", "Sharp Edge", "Noodle", "Diamond", "Rod", "Big Giant Sharp Pokey Thing"}; + + // @formatter:on + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + List stacks = new ArrayList(); + for (ItemStack stack : player.inventory.mainInventory) if (stack != null) stacks.add(stack); + + for (ItemStack stack : player.inventory.armorInventory) if (stack != null) stacks.add(stack); + + if (stacks.size() == 0) { + ItemStack dirt = new ItemStack(Blocks.dirt); + dirt.setStackDisplayName("A lonley piece of dirt"); + player.inventory.addItemStackToInventory(dirt); + player.triggerAchievement(CCubesAchievements.lonelyDirt); + return; + } + + for (int i = 0; i < 3; i++) { + String name = names[rand.nextInt(names.length)]; + String adj = adjectives[rand.nextInt(adjectives.length)]; + + if (name.substring(name.length() - 1) + .equalsIgnoreCase("s")) name += "'"; + else name += "'s"; + String newName = name + " " + adj; + stacks.get(rand.nextInt(stacks.size())) + .setStackDisplayName(newName); + } + + player.addChatMessage(new ChatComponentText("Those items of yours need a little personality!")); + + } + + @Override + public int getChanceValue() { + return -35; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Item_Rename"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/JukeBoxReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/JukeBoxReward.java new file mode 100644 index 0000000..c3eb761 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/JukeBoxReward.java @@ -0,0 +1,43 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.block.BlockJukebox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class JukeBoxReward implements IChanceCubeReward { + + private Random random = new Random(); + private ItemStack[] discs = new ItemStack[] { new ItemStack(Items.record_11), new ItemStack(Items.record_13), + new ItemStack(Items.record_blocks), new ItemStack(Items.record_cat), new ItemStack(Items.record_chirp), + new ItemStack(Items.record_far), new ItemStack(Items.record_mall), new ItemStack(Items.record_mellohi), + new ItemStack(Items.record_stal), new ItemStack(Items.record_strad), new ItemStack(Items.record_wait), + new ItemStack(Items.record_ward) }; + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + ItemStack disc = discs[random.nextInt(discs.length)]; + RewardsUtil.placeBlock(Blocks.jukebox, world, x, y, z); + ((BlockJukebox) Blocks.jukebox).func_149926_b(world, x, y, z, disc); + world.playAuxSFXAtEntity((EntityPlayer) null, 1005, x, y, z, Item.getIdFromItem(disc.getItem())); + } + + @Override + public int getChanceValue() { + return 5; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Juke_Box"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/MathReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/MathReward.java new file mode 100644 index 0000000..41ceda4 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/MathReward.java @@ -0,0 +1,169 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import net.minecraftforge.event.ServerChatEvent; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesDamageSource; +import chanceCubes.util.Location3I; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class MathReward implements IChanceCubeReward { + + private Map inQuestion = new HashMap(); + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + if (inQuestion.containsKey(player)) return; + + int num1 = world.rand.nextInt(100); + int num2 = world.rand.nextInt(100); + + player.addChatMessage(new ChatComponentText("Quick, what's " + num1 + "+" + num2 + "?")); + + List boxBlocks = new ArrayList(); + for (int xx = -2; xx < 3; xx++) { + for (int zz = -2; zz < 3; zz++) { + for (int yy = 1; yy < 5; yy++) { + if (xx == -2 || xx == 2 || zz == -2 || zz == 2 || yy == 1 || yy == 4) { + RewardsUtil.placeBlock( + Blocks.bedrock, + world, + (int) player.posX + xx, + (int) player.posY + yy, + (int) player.posZ + zz); + boxBlocks.add( + new Location3I((int) player.posX + xx, (int) player.posY + yy, (int) player.posZ + zz)); + } else if (((xx == -1 || xx == 1) && (zz == -1 || zz == 1) && yy == 2)) { + RewardsUtil.placeBlock( + Blocks.glowstone, + world, + (int) player.posX + xx, + (int) player.posY + yy, + (int) player.posZ + zz); + boxBlocks.add( + new Location3I((int) player.posX + xx, (int) player.posY + yy, (int) player.posZ + zz)); + } + } + } + } + + player.setPositionAndUpdate((int) player.posX, ((int) player.posY) + 2, (int) player.posZ); + + if (!world.isRemote) { + List tnt = new ArrayList(); + for (int i = 0; i < 5; i++) { + EntityTNTPrimed entitytntprimed = new EntityTNTPrimed( + world, + player.posX, + player.posY + 1D, + player.posZ, + player); + world.spawnEntityInWorld(entitytntprimed); + world.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F); + entitytntprimed.fuse = 140; + tnt.add(entitytntprimed); + } + + inQuestion.put(player, new RewardInfo(num1 + num2, tnt, boxBlocks)); + } + + Task task = new Task("Math", 100) { + + @Override + public void callback() { + timeUp(player, false); + } + + }; + + Scheduler.scheduleTask(task); + } + + private void timeUp(EntityPlayer player, boolean correct) { + if (!inQuestion.containsKey(player)) return; + + RewardInfo info = inQuestion.get(player); + if (correct) { + player.addChatMessage(new ChatComponentText("Correct!")); + } else { + player.worldObj.createExplosion(player, player.posX, player.posY, player.posZ, 1.0F, false); + player.attackEntityFrom(CCubesDamageSource.mathfail, Float.MAX_VALUE); + } + + for (Entity tnt : info.getTnt()) tnt.setDead(); + + for (Location3I b : info.getBlocks()) + RewardsUtil.placeBlock(Blocks.air, player.worldObj, b.getX(), b.getY(), b.getZ()); + + inQuestion.remove(player); + + } + + @Override + public int getChanceValue() { + return -30; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Math"; + } + + @SubscribeEvent + public void onMessage(ServerChatEvent event) { + EntityPlayer player = event.player; + + if (inQuestion.containsKey(player)) { + int answer = 0; + try { + answer = Integer.parseInt(event.message); + } catch (NumberFormatException e) { + player.addChatMessage(new ChatComponentText("Incorrect!")); + } + + if (inQuestion.get(player) + .getAnswer() == answer) this.timeUp(player, true); + else player.addChatMessage(new ChatComponentText("Incorrect!")); + event.setCanceled(true); + } + } + + private class RewardInfo { + + private int answer; + private List tnt; + private List blocks; + + public RewardInfo(int answer, List tnt, List blocks) { + this.answer = answer; + this.tnt = tnt; + this.blocks = blocks; + } + + public int getAnswer() { + return answer; + } + + public List getTnt() { + return tnt; + } + + public List getBlocks() { + return blocks; + } + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/MazeReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/MazeReward.java new file mode 100644 index 0000000..a2590f9 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/MazeReward.java @@ -0,0 +1,89 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesDamageSource; +import chanceCubes.util.Location3I; +import chanceCubes.util.MazeGenerator; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class MazeReward implements IChanceCubeReward { + + @Override + public void trigger(final World world, int x, int y, int z, final EntityPlayer player) { + player.addChatMessage(new ChatComponentText("Generating maze..... May be some lag...")); + final MazeGenerator gen = new MazeGenerator(); + gen.generate(world, x, y, z, 20, 20); + final int px = (int) player.posX; + final int py = (int) player.posY; + final int pz = (int) player.posZ; + player.setPositionAndUpdate(x - 8.5, y, z - 8.5); + + Task task = new Task("Maze_Reward_Update", 20) { + + @Override + public void callback() { + update(0, gen, world, player, new Location3I(px, py, pz)); + } + }; + Scheduler.scheduleTask(task); + + player.addChatMessage(new ChatComponentText("Beat the maze and find the sign!")); + player.addChatMessage(new ChatComponentText("You have 45 seconds!")); + } + + @Override + public int getChanceValue() { + return -25; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Maze"; + } + + public void update(final int iteration, final MazeGenerator gen, final World world, final EntityPlayer player, + final Location3I playerLoc) { + if (iteration == 46) { + gen.endMaze(world); + return; + } + if (iteration == 45) { + player.setPositionAndUpdate(playerLoc.getX(), playerLoc.getY(), playerLoc.getZ()); + player.attackEntityFrom(CCubesDamageSource.mazefail, Float.MAX_VALUE); + } else if (!world + .getBlock(gen.endBlockWorldCords.getX(), gen.endBlockWorldCords.getY(), gen.endBlockWorldCords.getZ()) + .equals(Blocks.standing_sign)) { + player.addChatMessage(new ChatComponentText("Hey! You won!")); + gen.endMaze(world); + player.setPositionAndUpdate(playerLoc.getX(), playerLoc.getY(), playerLoc.getZ()); + return; + } else if (iteration == 15) { + player.addChatMessage(new ChatComponentText("30 seconds left!!")); + } else if (iteration == 40) { + player.addChatMessage(new ChatComponentText("5...")); + } else if (iteration == 41) { + player.addChatMessage(new ChatComponentText("4...")); + } else if (iteration == 42) { + player.addChatMessage(new ChatComponentText("3...")); + } else if (iteration == 43) { + player.addChatMessage(new ChatComponentText("2...")); + } else if (iteration == 44) { + player.addChatMessage(new ChatComponentText("1!")); + } + + Task task = new Task("Maze_Reward_Update", 20) { + + @Override + public void callback() { + update(iteration + 1, gen, world, player, playerLoc); + } + }; + Scheduler.scheduleTask(task); + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/NukeReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/NukeReward.java new file mode 100644 index 0000000..32990a2 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/NukeReward.java @@ -0,0 +1,43 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class NukeReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.addChatMessage(new ChatComponentText("May death rain upon them")); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 6, y + 65, z - 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 2, y + 65, z - 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 2, y + 65, z - 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 6, y + 65, z - 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 6, y + 65, z - 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 2, y + 65, z - 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 2, y + 65, z - 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 6, y + 65, z - 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 6, y + 65, z + 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 2, y + 65, z + 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 2, y + 65, z + 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 6, y + 65, z + 2, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 6, y + 65, z + 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x - 2, y + 65, z + 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 2, y + 65, z + 6, null)); + world.spawnEntityInWorld(new EntityTNTPrimed(world, x + 6, y + 65, z + 6, null)); + } + + @Override + public int getChanceValue() { + return -75; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Nuke"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/OneIsLuckyReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/OneIsLuckyReward.java new file mode 100644 index 0000000..b3e18d3 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/OneIsLuckyReward.java @@ -0,0 +1,81 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.tileentities.TileChanceCube; +import chanceCubes.util.Location3I; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class OneIsLuckyReward implements IChanceCubeReward { + + private Random random = new Random(); + + @Override + public void trigger(final World world, final int x, final int y, final int z, EntityPlayer player) { + RewardsUtil.sendMessageToNearPlayers(world, x, y, z, 32, "A Lucky Block Salute"); + TileEntitySign sign = new TileEntitySign(); + sign.signText[0] = "One is lucky"; + sign.signText[1] = "One is not"; + sign.signText[3] = "#OGLuckyBlocks"; + boolean leftLucky = random.nextBoolean(); + TileChanceCube leftCube = new TileChanceCube(leftLucky ? 100 : -100); + TileChanceCube rightCube = new TileChanceCube(!leftLucky ? 100 : -100); + + if (RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x - 1, y, z)) + world.setTileEntity(x - 1, y, z, leftCube); + if (RewardsUtil.placeBlock(Blocks.standing_sign, world, x, y, z)) world.setTileEntity(x, y, z, sign); + if (RewardsUtil.placeBlock(CCubesBlocks.chanceCube, world, x + 1, y, z)) + world.setTileEntity(x + 1, y, z, rightCube); + + Task task = new Task("One_Is_Lucky_Reward", 10) { + + @Override + public void callback() { + update(0, world, new Location3I(x, y, z)); + } + }; + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":One_Is_Lucky"; + } + + public void update(final int iteration, final World world, final Location3I loc) { + boolean flag = false; + + if (world.isAirBlock(loc.getX() - 1, loc.getY(), loc.getZ()) + || world.isAirBlock(loc.getX() + 1, loc.getY(), loc.getZ())) flag = true; + + if (iteration == 600 || flag) { + world.setBlockToAir(loc.getX() - 1, loc.getY(), loc.getZ()); + world.setBlockToAir(loc.getX(), loc.getY(), loc.getZ()); + world.setBlockToAir(loc.getX() + 1, loc.getY(), loc.getZ()); + return; + } + + Task task = new Task("One_Is_Lucky_Reward", 10) { + + @Override + public void callback() { + update(iteration + 1, world, loc); + } + }; + Scheduler.scheduleTask(task); + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/QuestionsReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/QuestionsReward.java new file mode 100644 index 0000000..9c3c211 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/QuestionsReward.java @@ -0,0 +1,108 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import net.minecraftforge.event.ServerChatEvent; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesDamageSource; +import chanceCubes.util.CustomEntry; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class QuestionsReward implements IChanceCubeReward { + + private Map inQuestion = new HashMap(); + + private List> questionsAndAnswers = new ArrayList>(); + + public QuestionsReward() { + this.addQuestionAnswer("What is the username of the creator of Chance Cubes?", "Turkey -or- Turkey2349"); + this.addQuestionAnswer("How many sides does the sparkly, shiny, colorful, spinny Chance Cube have?", "20"); + this.addQuestionAnswer("What is 9 + 10", "19 -or- 21"); + this.addQuestionAnswer("What year was minecraft officially released", "2011"); + } + + public void addQuestionAnswer(String q, String a) { + questionsAndAnswers.add(new CustomEntry(q, a)); + } + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + if (inQuestion.containsKey(player)) return; + + int question = world.rand.nextInt(questionsAndAnswers.size()); + + player.addChatMessage( + new ChatComponentText( + questionsAndAnswers.get(question) + .getKey())); + player.addChatMessage(new ChatComponentText("You have 45 seconds to answer! (Answer is not case sensitive)")); + + if (!world.isRemote) { + inQuestion.put( + player, + questionsAndAnswers.get(question) + .getValue()); + } + + Task task = new Task("Question", 900) { + + @Override + public void callback() { + timeUp(player, false); + } + + }; + + Scheduler.scheduleTask(task); + } + + private void timeUp(EntityPlayer player, boolean correct) { + if (!inQuestion.containsKey(player)) return; + + if (correct) { + player.addChatMessage(new ChatComponentText("Correct!")); + } else { + player.addChatMessage(new ChatComponentText("Incorrect! The answer was " + this.inQuestion.get(player))); + player.worldObj.createExplosion(player, player.posX, player.posY, player.posZ, 1.0F, false); + player.attackEntityFrom(CCubesDamageSource.questionfail, Float.MAX_VALUE); + } + + inQuestion.remove(player); + + } + + @Override + public int getChanceValue() { + return -30; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Question"; + } + + @SubscribeEvent + public void onMessage(ServerChatEvent event) { + EntityPlayer player = event.player; + + if (inQuestion.containsKey(player)) { + String answer = event.message; + boolean correct = false; + for (String s : inQuestion.get(player) + .split("-or-")) + if (s.trim() + .equalsIgnoreCase(answer.trim())) correct = true; + this.timeUp(player, correct); + event.setCanceled(true); + } + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/RandomTeleportReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/RandomTeleportReward.java new file mode 100644 index 0000000..c2d5d8b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/RandomTeleportReward.java @@ -0,0 +1,40 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class RandomTeleportReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + int xChange = ((world.rand.nextInt(50) + 20) + x) - 35; + int zChange = ((world.rand.nextInt(50) + 20) + z) - 35; + + int yChange = -1; + + for (int yy = 0; yy <= world.getActualHeight(); yy++) { + if (world.getBlock(xChange, yy, zChange) + .isAir(world, xChange, yy, zChange) + && world.getBlock(xChange, yy + 1, zChange) + .isAir(world, xChange, yy + 1, zChange)) { + yChange = yy; + break; + } + } + if (yChange == -1) return; + + player.setPositionAndUpdate(xChange, yChange, zChange); + } + + @Override + public int getChanceValue() { + return -15; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Random_Teleport"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/RemoveUsefulThingsReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/RemoveUsefulThingsReward.java new file mode 100644 index 0000000..4664e2a --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/RemoveUsefulThingsReward.java @@ -0,0 +1,71 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class RemoveUsefulThingsReward implements IChanceCubeReward { + + List removables = new ArrayList(); + + public RemoveUsefulThingsReward() { + removables.add(Blocks.torch); + removables.add(Blocks.stone_slab); + removables.add(Blocks.furnace); + removables.add(Blocks.glowstone); + removables.add(Blocks.chest); + } + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + int removed = 0; + for (int yy = -5; yy <= 5; yy++) { + for (int xx = -5; xx <= 5; xx++) { + for (int zz = -5; zz <= 5; zz++) { + if (removables.contains(world.getBlock(x + xx, y + yy, z + zz))) { + world.setBlock(x + xx, y + yy, z + zz, Blocks.air); + removed++; + } + } + } + } + if (removed > 3) { + player.addChatMessage(new ChatComponentText("Look at all these useful things! #RIP")); + } else { + player.addChatMessage(new ChatComponentText("Wow, only " + removed + " useful things around?")); + player.addChatMessage(new ChatComponentText("Here, let me give you a helping hand!")); + + for (int yy = -2; yy <= 2; yy++) { + for (int xx = -5; xx <= 5; xx++) { + for (int zz = -5; zz <= 5; zz++) { + if (world.getBlock(x + xx, y + yy, z + zz) + .isOpaqueCube() + && world.getBlock(x + xx, y + yy + 1, z + zz) + .equals(Blocks.air)) { + world.setBlock(x + xx, y + yy, z + zz, Blocks.torch); + world.setBlockMetadataWithNotify(x + xx, y + yy, z + zz, 0, 2); + } + } + } + } + } + } + + @Override + public int getChanceValue() { + return -55; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Remove_Useful_Stuff"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/RottenFoodReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/RottenFoodReward.java new file mode 100644 index 0000000..e4fb3e3 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/RottenFoodReward.java @@ -0,0 +1,36 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class RottenFoodReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int i = 0; i < player.inventory.mainInventory.length; i++) { + ItemStack stack = player.inventory.mainInventory[i]; + if (stack != null && stack.getItem() instanceof ItemFood) + player.inventory.mainInventory[i] = new ItemStack(Items.rotten_flesh, stack.stackSize); + } + + player.addChatMessage(new ChatComponentText("Ewwww it's all rotten")); + + } + + @Override + public int getChanceValue() { + return -30; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Rotten_Food"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/SkyblockReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/SkyblockReward.java new file mode 100644 index 0000000..2ab63df --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/SkyblockReward.java @@ -0,0 +1,73 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenTrees; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class SkyblockReward implements IChanceCubeReward { + + // @formatter:off + + ItemStack[] chestStuff = { + new ItemStack(Items.string, 12), new ItemStack(Items.lava_bucket), new ItemStack(Items.bone), new ItemStack(Items.reeds), + new ItemStack(Blocks.red_mushroom), new ItemStack(Blocks.ice, 2), new ItemStack(Items.pumpkin_seeds), new ItemStack(Blocks.sapling), + new ItemStack(Blocks.brown_mushroom), new ItemStack(Items.melon), new ItemStack(Blocks.cactus), new ItemStack(Blocks.log, 6) + }; + + // @formatter:on + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + int skyblockHeight = world.getActualHeight() - 16; + if (world.provider.hasNoSky) { + skyblockHeight = y; + } + Block b = Blocks.dirt; + for (int i = 0; i < 3; i++) { + if (i == 2) b = Blocks.grass; + for (int c = 0; c < 3; c++) { + int xOffset = c == 0 ? -1 : 2; + int zOffset = c == 2 ? 2 : -1; + for (int xx = 0; xx < 3; xx++) { + for (int zz = 0; zz < 3; zz++) { + RewardsUtil.placeBlock(b, world, x + xOffset + xx, skyblockHeight + i, z + zOffset + zz); + } + } + } + } + RewardsUtil.placeBlock(Blocks.bedrock, world, x, skyblockHeight + 1, z); + + WorldGenTrees treeGen = new WorldGenTrees(true, 4, 0, 0, false); + treeGen.generate(world, new Random(), x + 4, skyblockHeight + 3, z + 4); + + RewardsUtil.placeBlock(Blocks.chest, world, x - 1, skyblockHeight + 3, z); + world.setBlockMetadataWithNotify(x - 1, skyblockHeight + 3, z, 5, 3); + TileEntityChest chest = (TileEntityChest) world.getTileEntity(x - 1, skyblockHeight + 3, z); + for (int i = 0; i < chestStuff.length; i++) { + int slot = ((i < 4 ? 0 : i < 8 ? 1 : 2) * 9) + i % 4; + chest.setInventorySlotContents(slot, chestStuff[i].copy()); + } + + player.setPositionAndUpdate(x, skyblockHeight + 3, z); + } + + @Override + public int getChanceValue() { + return 10; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":SkyBlock"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/SurroundedReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/SurroundedReward.java new file mode 100644 index 0000000..3a96857 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/SurroundedReward.java @@ -0,0 +1,58 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; + +public class SurroundedReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + EntityEnderman enderman; + for (int xx = 0; xx < 2; xx++) { + for (int zz = -4; zz < 5; zz++) { + int xxx = xx == 1 ? x + 4 : x - 4; + if (!world.getBlock(xxx, y, z + zz) + .isOpaqueCube() + && !world.getBlock(xxx, y + 1, z + zz) + .isOpaqueCube() + && !world.getBlock(xxx, y + 2, z + zz) + .isOpaqueCube()) { + enderman = new EntityEnderman(world); + enderman.setLocationAndAngles(xxx, y, z + zz, xx == 1 ? 90 : -90, 0); + world.spawnEntityInWorld(enderman); + } + } + } + + for (int xx = -4; xx < 5; xx++) { + for (int zz = 0; zz < 2; zz++) { + int zzz = zz == 1 ? z + 4 : z - 4; + if (world.getBlock(x + xx, y, zzz) + .equals(Blocks.air) + && world.getBlock(x + xx, y + 1, zzz) + .equals(Blocks.air) + && world.getBlock(x + xx, y + 2, zzz) + .equals(Blocks.air)) { + enderman = new EntityEnderman(world); + enderman.setLocationAndAngles(x + xx, y, zzz, zz == 1 ? 180 : 0, 0); + world.spawnEntityInWorld(enderman); + } + } + } + } + + @Override + public int getChanceValue() { + return -45; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Surrounded"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/TableFlipReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/TableFlipReward.java new file mode 100644 index 0000000..66e206c --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/TableFlipReward.java @@ -0,0 +1,100 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class TableFlipReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.addChatMessage(new ChatComponentText("(╯°□°)╯︵ ┻━┻)")); + this.nextStep(0, world, x, y, z); + } + + public void nextStep(final int stage, final World world, final int x, final int y, final int z) { + Task task = new Task("Table_Flip", 10) { + + @Override + public void callback() { + switch (stage) { + case 0: { + RewardsUtil.placeBlock(Blocks.wooden_slab, world, x, y, z); + world.setBlockMetadataWithNotify(x, y, z, 8, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x + 1, y, z); + world.setBlockMetadataWithNotify(x + 1, y, z, 5, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x - 1, y, z); + world.setBlockMetadataWithNotify(x + 1, y, z, 12, 3); + break; + } + case 1: { + RewardsUtil.placeBlock(Blocks.air, world, x, y, z); + RewardsUtil.placeBlock(Blocks.air, world, x + 1, y, z); + RewardsUtil.placeBlock(Blocks.air, world, x - 1, y, z); + RewardsUtil.placeBlock(Blocks.wooden_slab, world, x, y + 1, z); + world.setBlockMetadataWithNotify(x, y + 1, z, 8, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x + 1, y + 1, z); + world.setBlockMetadataWithNotify(x + 1, y + 1, z, 5, 3); + + world.setBlockMetadataWithNotify(x - 1, y + 1, z, 12, 3); + break; + } + case 2: { + RewardsUtil.placeBlock(Blocks.air, world, x, y + 1, z); + RewardsUtil.placeBlock(Blocks.air, world, x + 1, y + 1, z); + RewardsUtil.placeBlock(Blocks.air, world, x - 1, y + 1, z); + RewardsUtil.placeBlock(Blocks.wooden_slab, world, x, y + 2, z + 1); + world.setBlockMetadataWithNotify(x, y + 2, z + 1, 8, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x + 1, y + 2, z + 1); + world.setBlockMetadataWithNotify(x + 1, y + 2, z + 1, 5, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x - 1, y + 2, z + 1); + world.setBlockMetadataWithNotify(x - 1, y + 2, z + 1, 12, 3); + break; + } + case 3: { + RewardsUtil.placeBlock(Blocks.air, world, x, y + 2, z + 1); + RewardsUtil.placeBlock(Blocks.air, world, x + 1, y + 2, z + 1); + RewardsUtil.placeBlock(Blocks.air, world, x - 1, y + 2, z + 1); + RewardsUtil.placeBlock(Blocks.wooden_slab, world, x, y + 1, z + 2); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x + 1, y + 1, z + 2); + world.setBlockMetadataWithNotify(x + 1, y + 1, z + 2, 1, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x - 1, y + 1, z + 2); + break; + } + case 4: { + RewardsUtil.placeBlock(Blocks.air, world, x, y + 1, z + 2); + RewardsUtil.placeBlock(Blocks.air, world, x + 1, y + 1, z + 2); + RewardsUtil.placeBlock(Blocks.air, world, x - 1, y + 1, z + 2); + RewardsUtil.placeBlock(Blocks.wooden_slab, world, x, y, z + 2); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x + 1, y, z + 2); + world.setBlockMetadataWithNotify(x + 1, y, z + 2, 1, 3); + RewardsUtil.placeBlock(Blocks.oak_stairs, world, x - 1, y, z + 2); + break; + } + } + + if (stage < 4) nextStep(stage + 1, world, x, y, z); + } + + }; + + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Table_Flip"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ThrownInAirReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/ThrownInAirReward.java new file mode 100644 index 0000000..9a151d1 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ThrownInAirReward.java @@ -0,0 +1,48 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.network.play.server.S12PacketEntityVelocity; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ThrownInAirReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + int px = (int) Math.floor(player.posX); + int py = (int) Math.floor(player.posY) + 1; + int pz = (int) Math.floor(player.posZ); + + for (int yy = 0; yy < 40; yy++) for (int xx = -1; xx < 2; xx++) + for (int zz = -1; zz < 2; zz++) RewardsUtil.placeBlock(Blocks.air, world, px + xx, py + yy, pz + zz); + + Task task = new Task("Item_Of_Destiny_Reward", 5) { + + @Override + public void callback() { + player.isAirBorne = true; + player.motionY = 20; + ((EntityPlayerMP) player).playerNetServerHandler.sendPacket( + new S12PacketEntityVelocity(player.getEntityId(), player.motionX, player.motionY, player.motionZ)); + } + }; + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return -35; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Thrown_In_Air"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/TorchesToCreepers.java b/src/main/java/chanceCubes/rewards/defaultRewards/TorchesToCreepers.java new file mode 100644 index 0000000..6659d10 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/TorchesToCreepers.java @@ -0,0 +1,44 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.block.Block; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; + +public class TorchesToCreepers implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int yy = -32; yy <= 32; yy++) { + for (int xx = -32; xx <= 32; xx++) { + for (int zz = -32; zz <= 32; zz++) { + Block b = world.getBlock(x + xx, y + yy, z + zz); + if (b.getLightValue() > 0 && b != Blocks.lava + && !b.hasTileEntity(world.getBlockMetadata(x, y, z))) { + RewardsUtil.placeBlock(Blocks.air, world, x + xx, y + yy, z + zz); + EntityCreeper creeper = new EntityCreeper(world); + creeper.setLocationAndAngles(x + xx + 0.5, y + yy, z + zz + 0.5, 0, 0); + world.spawnEntityInWorld(creeper); + } + } + } + } + player.addChatMessage(new ChatComponentText("Those lights seem a little weird.... O.o")); + } + + @Override + public int getChanceValue() { + return -40; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Torches_To_Creepers"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/TrollHoleReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/TrollHoleReward.java new file mode 100644 index 0000000..0ed66f7 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/TrollHoleReward.java @@ -0,0 +1,64 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.Location3I; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class TrollHoleReward implements IChanceCubeReward { + + @Override + public void trigger(final World world, int x, int y, int z, final EntityPlayer player) { + + final Map storedBlocks = new HashMap(); + final int px = (int) Math.floor(player.posX); + final int py = (int) Math.floor(player.posY) - 1; + final int pz = (int) Math.floor(player.posZ); + + for (int yy = 0; yy < 75; yy++) { + for (int xx = -2; xx < 3; xx++) { + for (int zz = -2; zz < 3; zz++) { + storedBlocks.put(new Location3I(xx, yy, zz), world.getBlock(px + xx, py - yy, pz + zz)); + world.setBlockToAir(px + xx, py - yy, pz + zz); + } + } + } + + Task task = new Task("TrollHole", 35) { + + @Override + public void callback() { + fillHole(world, player, px, py, pz, storedBlocks); + } + + }; + + Scheduler.scheduleTask(task); + } + + public void fillHole(World world, EntityPlayer player, int x, int y, int z, Map storedBlocks) { + for (Location3I loc : storedBlocks.keySet()) + world.setBlock(x + loc.getX(), y - loc.getY(), z + loc.getZ(), storedBlocks.get(loc)); + + player.setPositionAndUpdate(x, y + 1, z); + player.motionY = 0; + player.fallDistance = 0; + } + + @Override + public int getChanceValue() { + return -20; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":TrollHole"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/TrollTNTReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/TrollTNTReward.java new file mode 100644 index 0000000..512555f --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/TrollTNTReward.java @@ -0,0 +1,63 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class TrollTNTReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + for (int xx = -1; xx < 2; xx++) { + for (int zz = -1; zz < 2; zz++) { + RewardsUtil + .placeBlock(Blocks.web, world, (int) player.posX + xx, (int) player.posY, (int) player.posZ + zz); + } + } + + final EntityTNTPrimed entitytntprimed = new EntityTNTPrimed( + world, + player.posX + 1D, + player.posY + 1D, + player.posZ, + player); + world.spawnEntityInWorld(entitytntprimed); + world.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F); + + if (world.rand.nextInt(5) != 1) { + Task task = new Task("TrollTNT", 80) { + + @Override + public void callback() { + timeUp(entitytntprimed, player); + } + + }; + + Scheduler.scheduleTask(task); + } + } + + private void timeUp(Entity ent, EntityPlayer player) { + player.addChatMessage(new ChatComponentText("BOOM")); + ent.setDead(); + } + + @Override + public int getChanceValue() { + return -5; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":TrollTNT"; + } +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/WaitForItReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/WaitForItReward.java new file mode 100644 index 0000000..77cee2b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/WaitForItReward.java @@ -0,0 +1,61 @@ +package chanceCubes.rewards.defaultRewards; + +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class WaitForItReward implements IChanceCubeReward { + + private final Random rand = new Random(); + + @Override + public void trigger(final World world, int x, int y, int z, final EntityPlayer player) { + player.addChatMessage(new ChatComponentText("Wait for it.......")); + + Task task = new Task("Wait For It", rand.nextInt(4000) + 1000) { + + @Override + public void callback() { + triggerRealReward(); + } + + private void triggerRealReward() { + int reward = rand.nextInt(3); + player.addChatMessage(new ChatComponentText("NOW!")); + + if (reward == 0) { + world.spawnEntityInWorld(new EntityTNTPrimed(world, player.posX, player.posY, player.posZ, null)); + } else if (reward == 1) { + Entity ent = new EntityCreeper(world); + ent.setLocationAndAngles(player.posX, player.posY, player.posZ, 0, 0); + world.spawnEntityInWorld(ent); + } else if (reward == 2) { + world.setBlock((int) player.posX, (int) player.posY, (int) player.posZ, Blocks.bedrock); + } + } + }; + + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return -30; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Wait_For_It"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/WitherReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/WitherReward.java new file mode 100644 index 0000000..9c4986b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/WitherReward.java @@ -0,0 +1,62 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.boss.EntityWither; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.CCubesAchievements; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class WitherReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + final EntityWither wither = new EntityWither(world); + wither.setLocationAndAngles((double) x + 0.5D, (double) y + 1D, (double) z + 1.5D, 90.0F, 0.0F); + wither.renderYawOffset = 90.0F; + wither.func_82206_m(); + wither.setCustomNameTag("Kiwi"); + world.spawnEntityInWorld(wither); + + RewardsUtil.sendMessageToNearPlayers( + world, + x, + y, + z, + 32, + "\"You've got to ask yourself one question: 'Do I feel lucky?' Well, do ya, punk?\""); + + Task task = new Task("Wither Reward", 180) { + + @Override + public void callback() { + if (!removeEnts(wither)) player.triggerAchievement(CCubesAchievements.wither); + } + }; + + Scheduler.scheduleTask(task); + } + + private boolean removeEnts(Entity ent) { + if (ent.worldObj.rand.nextInt(10) != 1) { + ent.setDead(); + return true; + } + return false; + } + + @Override + public int getChanceValue() { + return -100; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Wither"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/defaultRewards/ZombieCopyCatReward.java b/src/main/java/chanceCubes/rewards/defaultRewards/ZombieCopyCatReward.java new file mode 100644 index 0000000..177be63 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/defaultRewards/ZombieCopyCatReward.java @@ -0,0 +1,85 @@ +package chanceCubes.rewards.defaultRewards; + +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ZombieCopyCatReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, final EntityPlayer player) { + EntityZombie zombie = new EntityZombie(world); + zombie.setLocationAndAngles(x, y, z, 0, 0); + ItemStack weapon = null; + int swordSlot = 0; + for (int i = 0; i < 9; i++) { + ItemStack stack = player.inventory.mainInventory[i]; + if (stack != null && stack.getItem() instanceof ItemSword) { + weapon = stack.copy(); + swordSlot = i; + } + } + if (weapon == null && player.getCurrentEquippedItem() != null) { + weapon = player.getCurrentEquippedItem() + .copy(); + swordSlot = player.inventory.currentItem; + } + + zombie.setCurrentItemOrArmor(0, weapon); + zombie.setEquipmentDropChance(0, 2); + + if (player.inventory.armorInventory[0] != null) { + zombie.setCurrentItemOrArmor(1, player.inventory.armorInventory[0].copy()); + zombie.setEquipmentDropChance(1, 2); + } + if (player.inventory.armorInventory[1] != null) { + zombie.setCurrentItemOrArmor(2, player.inventory.armorInventory[1].copy()); + zombie.setEquipmentDropChance(2, 2); + } + /* + * if(player.inventory.armorInventory[2] != null) + * { + * zombie.setCurrentItemOrArmor(3, player.inventory.armorInventory[2].copy()); + * zombie.setEquipmentDropChance(3, 2); + * } + */ + if (player.inventory.armorInventory[3] != null) { + zombie.setCurrentItemOrArmor(4, player.inventory.armorInventory[3].copy()); + zombie.setEquipmentDropChance(4, 2); + } + + final int slotToSet = swordSlot; + Task task = new Task("Copycat zombie reward", 1) { + + @Override + public void callback() { + player.inventory.setInventorySlotContents(slotToSet, null); + player.setCurrentItemOrArmor(1, null); + player.setCurrentItemOrArmor(2, null); + // player.setCurrentItemOrArmor(3, null); + player.setCurrentItemOrArmor(4, null); + } + + }; + + Scheduler.scheduleTask(task); + + world.spawnEntityInWorld(zombie); + } + + @Override + public int getChanceValue() { + return -25; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Copy_Cat_Zombie"; + } +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/BioDomeReward.java b/src/main/java/chanceCubes/rewards/giantRewards/BioDomeReward.java new file mode 100644 index 0000000..fd1b345 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/BioDomeReward.java @@ -0,0 +1,110 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.biodomeGen.BasicTreesBiome; +import chanceCubes.rewards.biodomeGen.DesertBiome; +import chanceCubes.rewards.biodomeGen.EndBiome; +import chanceCubes.rewards.biodomeGen.IBioDomeBiome; +import chanceCubes.rewards.biodomeGen.NetherBiome; +import chanceCubes.rewards.biodomeGen.OceanBiome; +import chanceCubes.rewards.biodomeGen.SnowGlobeBiome; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.util.Location3I; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class BioDomeReward implements IChanceCubeReward { + + private Random rand = new Random(); + + private IBioDomeBiome[] biomes = new IBioDomeBiome[] { new BasicTreesBiome(), new DesertBiome(), new EndBiome(), + new OceanBiome(), new SnowGlobeBiome(), new NetherBiome() }; + + public static final int delayShorten = 10; + + @Override + public void trigger(final World world, final int x, final int y, final int z, EntityPlayer player) { + // player.addChatMessage(new ChatComponentText("Hey! I can be a Pandora's Box to!")); + + final IBioDomeBiome spawnedBiome = biomes[rand.nextInt(biomes.length)]; + this.genDome(x, y, z, world, spawnedBiome); + } + + public void genDome(final int centerX, final int centerY, final int centerZ, final World world, + final IBioDomeBiome spawnedBiome) { + this.genDomePart(0, -25, centerX, centerY, centerZ, world, spawnedBiome); + } + + public void genDomePart(final int yinc, final int xinc, final int centerX, final int centerY, final int centerZ, + final World world, final IBioDomeBiome spawnedBiome) { + List blocks = new ArrayList(); + int delay = 0; + for (int z = -25; z <= 25; z++) { + Location3I loc = new Location3I(xinc, yinc, z); + float dist = Math.abs(loc.length()) - 25; + if (dist < 1) { + if (dist >= 0) { + blocks.add(new OffsetBlock(xinc, yinc, z, Blocks.glass, false, (delay / delayShorten))); + delay++; + } else if (yinc == 0) { + blocks.add( + new OffsetBlock(xinc, yinc, z, spawnedBiome.getFloorBlock(), false, (delay / delayShorten))); + delay++; + } + spawnedBiome.getRandomGenBlock(dist, rand, xinc, yinc, z, blocks, delay); + } + } + + final int nextXinc = xinc + 1 > 25 ? (-25) : xinc + 1; + int Yinctemp = yinc; + if (nextXinc == -25) { + Yinctemp = Yinctemp + 1 > 25 ? -1 : Yinctemp + 1; + } + + if (Yinctemp == -1) { + Scheduler.scheduleTask(new Task("Entity_Delays", delay) { + + @Override + public void callback() { + spawnedBiome.spawnEntities(centerX, centerY, centerZ, world); + } + }); + return; + } + + final int nextYinc = Yinctemp; + + for (OffsetBlock b : blocks) b.spawnInWorld(world, centerX, centerY, centerZ); + + Task task = new Task("BioDome Reward", (delay / delayShorten)) { + + @Override + public void callback() { + genDomePart(nextYinc, nextXinc, centerX, centerY, centerZ, world, spawnedBiome); + } + + }; + + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":BioDome"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/ChunkFlipReward.java b/src/main/java/chanceCubes/rewards/giantRewards/ChunkFlipReward.java new file mode 100644 index 0000000..9ec09ac --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/ChunkFlipReward.java @@ -0,0 +1,67 @@ +package chanceCubes.rewards.giantRewards; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ChunkFlipReward implements IChanceCubeReward { + + public ChunkFlipReward() { + + } + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + int zBase = z - (z % 16); + int xBase = x - (x % 16); + + moveLayer(world, xBase, 0, zBase, player); + + world.playSoundEffect(x, y, z, CCubesCore.MODID + ":giant_Cube_Spawn", 1, 1); + player.addChatMessage(new ChatComponentText("Inception!!!!")); + } + + public void moveLayer(final World world, final int x, int y, final int z, final EntityPlayer player) { + if (y >= world.getActualHeight() / 2) return; + + for (int zz = 0; zz < 16; zz++) { + for (int xx = 0; xx < 16; xx++) { + Block b = world.getBlock(x + xx, y, z + zz); + Block b2 = world.getBlock(x + xx, world.getActualHeight() - y, z + zz); + if (!b.equals(Blocks.gravel) && !b.equals(CCubesBlocks.chanceGiantCube)) { + world.setBlock(x + xx, y, z + zz, b2, 0, 2); + world.setBlock(x + xx, world.getActualHeight() - y, z + zz, b, 0, 2); + } + } + } + + final int nextY = y + 1; + Task task = new Task("Chunk_Flip_Delay", 5) { + + public void callback() { + moveLayer(world, x, nextY, z, player); + } + }; + + Scheduler.scheduleTask(task); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Chunk_Flip"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/ChunkReverserReward.java b/src/main/java/chanceCubes/rewards/giantRewards/ChunkReverserReward.java new file mode 100644 index 0000000..602f728 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/ChunkReverserReward.java @@ -0,0 +1,89 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.util.CustomEntry; + +public class ChunkReverserReward implements IChanceCubeReward { + + private List> swappedMap = new ArrayList>(); + + public ChunkReverserReward() { + swappedMap.add(new CustomEntry(Blocks.stone, Blocks.dirt)); + swappedMap.add(new CustomEntry(Blocks.dirt, Blocks.cobblestone)); + swappedMap.add(new CustomEntry(Blocks.grass, Blocks.stone)); + swappedMap.add(new CustomEntry(Blocks.gravel, Blocks.sand)); + swappedMap.add(new CustomEntry(Blocks.iron_ore, Blocks.gold_ore)); + swappedMap.add(new CustomEntry(Blocks.coal_ore, Blocks.diamond_ore)); + swappedMap.add(new CustomEntry(Blocks.diamond_ore, Blocks.coal_ore)); + swappedMap.add(new CustomEntry(Blocks.gold_ore, Blocks.iron_ore)); + swappedMap.add(new CustomEntry(Blocks.lava, Blocks.water)); + swappedMap.add(new CustomEntry(Blocks.water, Blocks.lava)); + swappedMap.add(new CustomEntry(Blocks.log, Blocks.leaves)); + swappedMap.add(new CustomEntry(Blocks.log2, Blocks.leaves2)); + swappedMap.add(new CustomEntry(Blocks.leaves, Blocks.log)); + swappedMap.add(new CustomEntry(Blocks.leaves2, Blocks.log2)); + } + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.addChatMessage(new ChatComponentText("Initiating Block Inverter")); + List blocks = new ArrayList(); + int delay = 0; + for (int yy = 256; yy > 0; yy--) { + int xx = 0, zz = 0, dx = 0, dy = -1; + int t = 16; + int maxI = t * t; + + for (int i = 0; i < maxI; i++) { + if ((-16 / 2 <= xx) && (xx <= 16 / 2) && (-16 / 2 <= zz) && (zz <= 16 / 2)) { + Block blockAt = world.getBlock(x + xx, yy, z + zz); + Block toSwapTo = null; + for (Entry blockSwap : swappedMap) { + if (blockSwap.getKey() + .equals(blockAt)) { + toSwapTo = blockSwap.getValue(); + } + } + if (toSwapTo != null) { + blocks.add(new OffsetBlock(xx, yy - y, zz, toSwapTo, false, delay / 5)); + delay++; + } + } + + if ((xx == zz) || ((xx < 0) && (xx == -zz)) || ((xx > 0) && (xx == 1 - zz))) { + t = dx; + dx = -dy; + dy = t; + } + xx += dx; + zz += dy; + } + } + + player.addChatMessage(new ChatComponentText("Inverting " + blocks.size() + " Blocks... May take a minute...")); + for (OffsetBlock b : blocks) b.spawnInWorld(world, x, y, z); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Chuck_Reverse"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/FloorIsLavaReward.java b/src/main/java/chanceCubes/rewards/giantRewards/FloorIsLavaReward.java new file mode 100644 index 0000000..0b63a55 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/FloorIsLavaReward.java @@ -0,0 +1,60 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class FloorIsLavaReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + player.addChatMessage(new ChatComponentText("Quick! The Floor is lava!")); + List blocks = new ArrayList(); + int delay = 0; + for (int yy = y + 5; yy > y - 5; yy--) { + int xx = 0, zz = 0, dx = 0, dy = -1; + int t = 32; + int maxI = t * t; + + for (int i = 0; i < maxI; i++) { + if ((-16 / 2 <= xx) && (xx <= 16 / 2) && (-16 / 2 <= zz) && (zz <= 16 / 2)) { + Block blockAt = world.getBlock(x + xx, yy, z + zz); + if (!blockAt.equals(Blocks.air)) { + blocks.add(new OffsetBlock(xx, yy - y, zz, Blocks.lava, false, delay)); + delay++; + } + } + + if ((xx == zz) || ((xx < 0) && (xx == -zz)) || ((xx > 0) && (xx == 1 - zz))) { + t = dx; + dx = -dy; + dy = t; + } + xx += dx; + zz += dy; + } + } + + for (OffsetBlock b : blocks) b.spawnInWorld(world, x, y, z); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Floor_Is_Lava"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/FluidTowerReward.java b/src/main/java/chanceCubes/rewards/giantRewards/FluidTowerReward.java new file mode 100644 index 0000000..c0f4c5c --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/FluidTowerReward.java @@ -0,0 +1,34 @@ +package chanceCubes.rewards.giantRewards; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.util.RewardsUtil; + +public class FluidTowerReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + for (int i = 0; i < 25; i++) RewardsUtil.placeBlock( + ChanceCubeRegistry.getRandomFluid() + .getBlock(), + world, + x, + y + i, + z); + } + + @Override + public int getChanceValue() { + return 15; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Fluid_Tower"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/OrePillarReward.java b/src/main/java/chanceCubes/rewards/giantRewards/OrePillarReward.java new file mode 100644 index 0000000..3232348 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/OrePillarReward.java @@ -0,0 +1,58 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +import chanceCubes.CCubesCore; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class OrePillarReward implements IChanceCubeReward { + + private Random rand = new Random(); + + public OrePillarReward() { + + } + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + List blocks = new ArrayList(); + int delay = 0; + for (int i = 0; i < rand.nextInt(4) + 2; i++) { + int xx = rand.nextInt(30) - 15; + int zz = rand.nextInt(30) - 15; + for (int yy = 1; yy < 255; yy++) { + ArrayList ores = OreDictionary.getOres(ChanceCubeRegistry.getRandomOreDict()); + if (ores.size() == 0) continue; + ItemStack chosenStack = ores.get(rand.nextInt(ores.size())); + Block b = Block.getBlockFromItem(chosenStack.getItem()); + OffsetBlock osb = new OffsetBlock(xx, yy - y, zz, b, false, delay / 3); + osb.setData((byte) chosenStack.getItemDamage()); + blocks.add(osb); + delay++; + } + } + + for (OffsetBlock b : blocks) b.spawnInWorld(world, x, y, z); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Ore_Pillars"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/OreSphereReward.java b/src/main/java/chanceCubes/rewards/giantRewards/OreSphereReward.java new file mode 100644 index 0000000..8c43cc9 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/OreSphereReward.java @@ -0,0 +1,70 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; + +import chanceCubes.CCubesCore; +import chanceCubes.registry.ChanceCubeRegistry; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.util.Location3I; + +public class OreSphereReward implements IChanceCubeReward { + + private Random rand = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + List blocks = new ArrayList(); + + ArrayList ores = OreDictionary.getOres(ChanceCubeRegistry.getRandomOreDict()); + Block ore = null; + int meta = 0; + if (ores.size() == 0) ore = Blocks.coal_ore; + else { + ItemStack stack = ores.get(rand.nextInt(ores.size())); + ore = Block.getBlockFromItem(stack.getItem()); + meta = stack.getItemDamage(); + } + + int delay = 0; + for (int i = 0; i < 5; i++) { + for (int yy = -5; yy < 6; yy++) { + for (int zz = -5; zz < 6; zz++) { + for (int xx = -5; xx < 6; xx++) { + Location3I loc = new Location3I(xx, yy, zz); + float dist = Math.abs(loc.length()); + if (dist <= i && dist > i - 1) { + OffsetBlock osb = new OffsetBlock(xx, yy, zz, ore, false, delay); + osb.setData((byte) meta); + blocks.add(osb); + delay++; + } + } + } + } + delay += 10; + } + + for (OffsetBlock b : blocks) b.spawnInWorld(world, x, y, z); + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Ore_Sphere"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/PotionsReward.java b/src/main/java/chanceCubes/rewards/giantRewards/PotionsReward.java new file mode 100644 index 0000000..7786e2a --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/PotionsReward.java @@ -0,0 +1,99 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityPotion; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class PotionsReward implements IChanceCubeReward { + + private int[] metas = new int[] { 16385, 16450, 16419, 16420, 16452, 16453, 16422, 16424, 16393, 16426, 16428, + 16460, 16461, 16430 }; + private Random rand = new Random(); + + private EntityPotion pot; + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + player.addChatMessage(new ChatComponentText("It's called art! Look it up!")); + throwPoitonCircle(0, world, x, y, z, player); + + Scheduler.scheduleTask(new Task("Potion Circle", 140) { + + @Override + public void callback() { + throwPoiton(0, world, x, y, z, player); + } + }); + } + + private void throwPoitonCircle(final int itteration, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + for (double rad = -Math.PI; rad <= Math.PI; rad += (Math.PI / 20)) { + pot = new EntityPotion( + world, + player, + new ItemStack(Items.potionitem, 1, metas[rand.nextInt(metas.length)])); + pot.setLocationAndAngles(x + 0.5, y, z + 0.5, 0, 0); + pot.motionX = Math.cos(rad) * (0.1 + (0.05 * itteration)); + pot.motionY = 1; + pot.motionZ = Math.sin(rad) * (0.1 + (0.05 * itteration)); + world.spawnEntityInWorld(pot); + } + + if (itteration < 5) { + Scheduler.scheduleTask(new Task("Potion Circle", 20) { + + @Override + public void callback() { + throwPoitonCircle(itteration + 1, world, x, y, z, player); + } + }); + } + } + + private void throwPoiton(final int itteration, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + for (double yy = -0.2; yy <= 1; yy += 0.1) { + pot = new EntityPotion( + world, + player, + new ItemStack(Items.potionitem, 1, metas[rand.nextInt(metas.length)])); + pot.setLocationAndAngles(x + 0.5, y, z + 0.5, 0, 0); + pot.motionX = Math.cos(itteration * (Math.PI / 30)); + pot.motionY = yy; + pot.motionZ = Math.sin(itteration * (Math.PI / 30)); + world.spawnEntityInWorld(pot); + } + + if (itteration < 200) { + Scheduler.scheduleTask(new Task("Potion Circle", 2) { + + @Override + public void callback() { + throwPoiton(itteration + 1, world, x, y, z, player); + } + }); + } + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Raining_Potions"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/TNTSlingReward.java b/src/main/java/chanceCubes/rewards/giantRewards/TNTSlingReward.java new file mode 100644 index 0000000..abcc125 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/TNTSlingReward.java @@ -0,0 +1,61 @@ +package chanceCubes.rewards.giantRewards; + +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class TNTSlingReward implements IChanceCubeReward { + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + this.throwTNT(0, world, x, y, z); + } + + public void throwTNT(final int count, final World world, final int x, final int y, final int z) { + EntityTNTPrimed tnt = new EntityTNTPrimed(world, x, y + 1D, z, null); + world.spawnEntityInWorld(tnt); + tnt.fuse = 60; + tnt.motionX = -1 + (Math.random() * 2); + tnt.motionY = Math.random(); + tnt.motionZ = -1 + (Math.random() * 2); + + if (count < 25) { + Task task = new Task("Throw TNT", 10) { + + @Override + public void callback() { + throwTNT(count + 1, world, x, y, z); + } + + }; + Scheduler.scheduleTask(task); + } else { + for (double xx = 1; xx > -1; xx -= 0.25) { + for (double zz = 1; zz > -1; zz -= 0.25) { + tnt = new EntityTNTPrimed(world, x, y + 1D, z, null); + world.spawnEntityInWorld(tnt); + tnt.fuse = 60; + tnt.motionX = xx; + tnt.motionY = Math.random(); + tnt.motionZ = zz; + } + } + } + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":TNT_Throw"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/giantRewards/ThrowablesReward.java b/src/main/java/chanceCubes/rewards/giantRewards/ThrowablesReward.java new file mode 100644 index 0000000..eb59bb0 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/giantRewards/ThrowablesReward.java @@ -0,0 +1,75 @@ +package chanceCubes.rewards.giantRewards; + +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityEgg; +import net.minecraft.entity.projectile.EntityLargeFireball; +import net.minecraft.entity.projectile.EntityWitherSkull; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.defaultRewards.IChanceCubeReward; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ThrowablesReward implements IChanceCubeReward { + + private Random random = new Random(); + + @Override + public void trigger(World world, int x, int y, int z, EntityPlayer player) { + this.throwThing(0, world, x, y, z); + } + + public void throwThing(final int count, final World world, final int x, final int y, final int z) { + int entChoice = random.nextInt(5); + Entity throwEnt; + if (entChoice == 0) { + throwEnt = new EntityArrow(world); + } else if (entChoice == 1) { + throwEnt = new EntityLargeFireball(world); + ((EntityLargeFireball) throwEnt).accelerationX = 0.1f * (-1 + (Math.random() * 2)); + ((EntityLargeFireball) throwEnt).accelerationY = 0.1f * (-1 + (Math.random() * 2)); + ((EntityLargeFireball) throwEnt).accelerationZ = 0.1f * (-1 + (Math.random() * 2)); + } else if (entChoice == 2) { + throwEnt = new EntityEgg(world); + } else if (entChoice == 3) { + throwEnt = new EntityWitherSkull(world); + } else { + throwEnt = new EntityTNTPrimed(world); + ((EntityTNTPrimed) throwEnt).fuse = 20; + } + throwEnt.setLocationAndAngles(x, y, z, 0, 0); + throwEnt.motionX = -1 + (Math.random() * 2); + throwEnt.motionY = -1 + (Math.random() * 2); + throwEnt.motionZ = -1 + (Math.random() * 2); + world.spawnEntityInWorld(throwEnt); + + if (count < 50) { + Task task = new Task("Throw TNT", 5) { + + @Override + public void callback() { + throwThing(count + 1, world, x, y, z); + } + + }; + Scheduler.scheduleTask(task); + } + } + + @Override + public int getChanceValue() { + return 0; + } + + @Override + public String getName() { + return CCubesCore.MODID + ":Trowables"; + } + +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/ChestChanceItem.java b/src/main/java/chanceCubes/rewards/rewardparts/ChestChanceItem.java new file mode 100644 index 0000000..f0a001f --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/ChestChanceItem.java @@ -0,0 +1,45 @@ +package chanceCubes.rewards.rewardparts; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import cpw.mods.fml.common.registry.GameRegistry; + +public class ChestChanceItem { + + public static String[] elements = new String[] { "item:I", "chance:I", "meta:I", "amountMin:I", "amountMax:I" }; + private static Random rand = new Random(); + private String mod; + private String item; + private int meta; + private int amountMin; + private int amountMax; + private int chance; + + public ChestChanceItem(String item, int meta, int chance, int amountMin, int amountMax) { + this.mod = item.substring(0, item.indexOf(":")); + this.item = item.substring(item.indexOf(":") + 1); + this.meta = meta; + this.chance = chance; + this.amountMin = amountMin; + this.amountMax = amountMax; + } + + public Item getItem() { + Block b = GameRegistry.findBlock(mod, item); + if (b != null) return Item.getItemFromBlock(b); + else return GameRegistry.findItem(mod, item); + } + + public ItemStack getRandomItemStack() { + int amount = rand.nextInt(amountMax - amountMin) + amountMin; + return new ItemStack(this.getItem(), amount, meta); + } + + public int getChance() { + return this.chance; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/CommandPart.java b/src/main/java/chanceCubes/rewards/rewardparts/CommandPart.java new file mode 100644 index 0000000..b4d899e --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/CommandPart.java @@ -0,0 +1,47 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public class CommandPart { + + public static String[] elements = new String[] { "command:S", "delay:I" }; + + private String command; + + private int delay = 0; + + public CommandPart(String command) { + this.command = command; + } + + public CommandPart(String command, int delay) { + this.command = command; + this.delay = delay; + } + + public String getRawCommand() { + return command; + } + + public int getDelay() { + return delay; + } + + public void setDelay(int delay) { + this.delay = delay; + } + + public String getParsedCommand(World world, int x, int y, int z, EntityPlayer player) { + String parsedCommand = command; + parsedCommand = parsedCommand.replace("%player", player.getCommandSenderName()); + parsedCommand = parsedCommand.replace("%x", "" + x); + parsedCommand = parsedCommand.replace("%y", "" + y); + parsedCommand = parsedCommand.replace("%z", "" + z); + parsedCommand = parsedCommand.replace("%px", "" + player.posX); + parsedCommand = parsedCommand.replace("%py", "" + player.posY); + parsedCommand = parsedCommand.replace("%pz", "" + player.posZ); + + return parsedCommand; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/EntityPart.java b/src/main/java/chanceCubes/rewards/rewardparts/EntityPart.java new file mode 100644 index 0000000..5af1f15 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/EntityPart.java @@ -0,0 +1,50 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; + +public class EntityPart { + + public static String[] elements = new String[] { "entity:S", "delay:I" }; + + private NBTTagCompound nbtData; + + private int delay = 0; + + private boolean removedBlocks = true; + + public EntityPart(NBTTagCompound nbtData) { + this.nbtData = nbtData; + } + + public EntityPart(String nbtRaw) { + try { + this.nbtData = (NBTTagCompound) JsonToNBT.func_150315_a(nbtRaw); + } catch (NBTException e) { + e.printStackTrace(); + } + } + + public NBTTagCompound getNBT() { + return nbtData; + } + + public int getDelay() { + return delay; + } + + public EntityPart setDelay(int delay) { + this.delay = delay; + return this; + } + + public boolean shouldRemovedBlocks() { + return removedBlocks; + } + + public EntityPart setRemovedBlocks(boolean removedBlocks) { + this.removedBlocks = removedBlocks; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/ExpirencePart.java b/src/main/java/chanceCubes/rewards/rewardparts/ExpirencePart.java new file mode 100644 index 0000000..299e1a2 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/ExpirencePart.java @@ -0,0 +1,41 @@ +package chanceCubes.rewards.rewardparts; + +public class ExpirencePart { + + public static String[] elements = new String[] { "experienceAmount:I", "delay:I", "numberOfOrbs:I" }; + + private int amount; + private int orbs = 1; + + private int delay = 0; + + public ExpirencePart(int amount) { + this.amount = amount; + } + + public ExpirencePart(int amount, int delay) { + this.amount = amount; + this.delay = delay; + } + + public int getAmount() { + return amount; + } + + public int getDelay() { + return delay; + } + + public void setDelay(int delay) { + this.delay = delay; + } + + public int getNumberofOrbs() { + return orbs; + } + + public ExpirencePart setNumberofOrbs(int orbs) { + this.orbs = orbs; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/ItemPart.java b/src/main/java/chanceCubes/rewards/rewardparts/ItemPart.java new file mode 100644 index 0000000..a87dc06 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/ItemPart.java @@ -0,0 +1,34 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.item.ItemStack; + +public class ItemPart { + + public static String[] elements = new String[] { "item:S", "delay:I" }; + + private ItemStack stack; + + private int delay = 0; + + public ItemPart(ItemStack stack) { + this.stack = stack; + } + + public ItemPart(ItemStack stack, int delay) { + this.stack = stack; + this.delay = delay; + } + + public ItemStack getItemStack() { + return stack; + } + + public int getDelay() { + return delay; + } + + public ItemPart setDelay(int delay) { + this.delay = delay; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/MessagePart.java b/src/main/java/chanceCubes/rewards/rewardparts/MessagePart.java new file mode 100644 index 0000000..1d23429 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/MessagePart.java @@ -0,0 +1,48 @@ +package chanceCubes.rewards.rewardparts; + +public class MessagePart { + + public static String[] elements = new String[] { "message:S", "delay:I", "serverWide:B", "range:I" }; + + private String message; + + private int delay = 0; + + private boolean serverWide = false; + private int range = 32; + + public MessagePart(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public int getDelay() { + return delay; + } + + public MessagePart setDelay(int delay) { + this.delay = delay; + return this; + } + + public boolean isServerWide() { + return serverWide; + } + + public MessagePart setServerWide(boolean serverWide) { + this.serverWide = serverWide; + return this; + } + + public int getRange() { + return range; + } + + public MessagePart setRange(int range) { + this.range = range; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/OffsetBlock.java b/src/main/java/chanceCubes/rewards/rewardparts/OffsetBlock.java new file mode 100644 index 0000000..24773f0 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/OffsetBlock.java @@ -0,0 +1,154 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; + +import chanceCubes.blocks.BlockFallingCustom; +import chanceCubes.config.CCubesSettings; +import chanceCubes.util.RewardsUtil; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class OffsetBlock { + + public static String[] elements = new String[] { "XOffSet:I", "YOffSet:I", "ZOffSet:I", "Block:S", "Falling:B", + "delay:I", "RelativeToPlayer:B" }; + + protected boolean relativeToPlayer = false; + public int xOff; + public int yOff; + public int zOff; + + protected byte data = 0; + + protected boolean falling; + protected int delay = 0; + + protected Block block; + + protected boolean causeUpdate = false; + + public OffsetBlock(int x, int y, int z, Block b, boolean falling) { + this.xOff = x; + this.yOff = y; + this.zOff = z; + this.block = b; + this.falling = falling; + } + + public OffsetBlock(int x, int y, int z, Block b, boolean falling, int delay) { + this.xOff = x; + this.yOff = y; + this.zOff = z; + this.block = b; + this.falling = falling; + this.delay = delay; + } + + public void spawnInWorld(final World world, final int x, final int y, final int z) { + if (!falling) { + if (delay != 0) { + Task task = new Task("Delayed_Block_At_(" + xOff + "," + yOff + "," + zOff + ")", delay) { + + @Override + public void callback() { + placeInWorld(world, x, y, z, true); + } + }; + Scheduler.scheduleTask(task); + } else { + placeInWorld(world, x, y, z, true); + } + } else { + if (delay != 0) { + Task task = new Task("Falling_Block_At_(" + xOff + "," + yOff + "," + zOff + ")", delay) { + + @Override + public void callback() { + spawnFallingBlock(world, x, y, z); + } + }; + Scheduler.scheduleTask(task); + } else { + spawnFallingBlock(world, x, y, z); + } + } + } + + protected void spawnFallingBlock(World world, int x, int y, int z) { + double yy = (((double) (y + yOff + CCubesSettings.dropHeight)) + 0.5) >= 256 ? 255 + : (((double) (y + yOff + CCubesSettings.dropHeight)) + 0.5); + for (int yyy = (int) yy; yyy >= y + yOff; yyy--) + RewardsUtil.placeBlock(Blocks.air, world, (x + xOff), yyy, (z + zOff)); + BlockFallingCustom entityfallingblock = new BlockFallingCustom( + world, + ((double) (x + xOff)) + 0.5, + yy, + ((double) (z + zOff)) + 0.5, + block, + data, + y + yOff, + this); + world.spawnEntityInWorld(entityfallingblock); + } + + public void setDelay(int delay) { + this.delay = delay; + } + + public void setData(byte d) { + this.data = d; + } + + public OffsetBlock setRelativeToPlayer(boolean relative) { + this.relativeToPlayer = relative; + return this; + } + + public boolean isRelativeToPlayer() { + return this.relativeToPlayer; + } + + public int getDelay() { + return this.delay; + } + + public OffsetBlock setCausesBlockUpdate(boolean flag) { + this.causeUpdate = flag; + return this; + } + + public void placeInWorld(World world, int x, int y, int z, boolean offset) { + int xx = x; + int yy = y; + int zz = z; + if (offset) { + xx += xOff; + yy += yOff; + zz += zOff; + } + RewardsUtil.placeBlock(block, world, xx, yy, zz, data, causeUpdate ? 3 : 2); + world.setBlock(xx, yy, zz, block, data, causeUpdate ? 3 : 2); + Block bSurface = world.getBlock(xx, yy - 1, zz); + world.playSoundEffect( + (double) ((float) xx + 0.5F), + (double) ((float) yy + 0.5F), + (double) ((float) zz + 0.5F), + bSurface.stepSound.func_150496_b(), + (bSurface.stepSound.getVolume() + 1.0F) / 2.0F, + bSurface.stepSound.getPitch() * 0.5F); + } + + public Block getBlock() { + return this.block; + } + + public boolean isFalling() { + return this.falling; + } + + public byte getData() { + return data; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/OffsetTileEntity.java b/src/main/java/chanceCubes/rewards/rewardparts/OffsetTileEntity.java new file mode 100644 index 0000000..dbe83ea --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/OffsetTileEntity.java @@ -0,0 +1,66 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.block.Block; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class OffsetTileEntity extends OffsetBlock { + + private NBTTagCompound nbt; + + public OffsetTileEntity(int x, int y, int z, Block block, NBTTagCompound nbt, boolean falling) { + this(x, y, z, block, nbt, falling, 0); + } + + public OffsetTileEntity(int x, int y, int z, Block block, NBTTagCompound nbt, boolean falling, int delay) { + super(x, y, z, block, falling, delay); + this.nbt = nbt; + } + + public void spawnInWorld(final World world, final int x, final int y, final int z) { + if (!falling) { + if (delay != 0) { + Task task = new Task("Delayed_Block_At_(" + xOff + "," + yOff + "," + zOff + ")", delay) { + + @Override + public void callback() { + placeInWorld(world, x, y, z, true); + } + }; + Scheduler.scheduleTask(task); + } else { + placeInWorld(world, x, y, z, true); + } + } else { + if (delay != 0) { + Task task = new Task("Falling_Block_At_(" + xOff + "," + yOff + "," + zOff + ")", delay) { + + @Override + public void callback() { + spawnFallingBlock(world, x, y, z); + } + }; + Scheduler.scheduleTask(task); + } else { + spawnFallingBlock(world, x, y, z); + } + } + } + + public void placeInWorld(World world, int x, int y, int z, boolean offset) { + super.placeInWorld(world, x, y, z, offset); + TileEntity te = TileEntity.createAndLoadEntity(nbt); + te.blockMetadata = this.data; + if (offset) world.setTileEntity(x + xOff, y + yOff, z + zOff, te); + else world.setTileEntity(x, y, z, te); + te.markDirty(); + } + + public void seFalling(boolean falling) { + this.falling = falling; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/ParticlePart.java b/src/main/java/chanceCubes/rewards/rewardparts/ParticlePart.java new file mode 100644 index 0000000..d154e63 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/ParticlePart.java @@ -0,0 +1,26 @@ +package chanceCubes.rewards.rewardparts; + +public class ParticlePart { + + public static String[] elements = new String[] { "particle:S", "x:I", "y:I", "z:I", "delay:I" }; + + private String particle; + + private int delay = 0; + + public ParticlePart(String particle) { + this.particle = particle; + } + + public String getParticle() { + return particle; + } + + public int getDelay() { + return delay; + } + + public void setDelay(int delay) { + this.delay = delay; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/PotionPart.java b/src/main/java/chanceCubes/rewards/rewardparts/PotionPart.java new file mode 100644 index 0000000..d553b3e --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/PotionPart.java @@ -0,0 +1,28 @@ +package chanceCubes.rewards.rewardparts; + +import net.minecraft.potion.PotionEffect; + +public class PotionPart { + + public static String[] elements = new String[] { "potionid:I", "duration:I", "delay:I" }; + + private PotionEffect effect; + + private int delay = 0; + + public PotionPart(PotionEffect effect) { + this.effect = effect; + } + + public PotionEffect getEffect() { + return effect; + } + + public int getDelay() { + return delay; + } + + public void setDelay(int delay) { + this.delay = delay; + } +} diff --git a/src/main/java/chanceCubes/rewards/rewardparts/SoundPart.java b/src/main/java/chanceCubes/rewards/rewardparts/SoundPart.java new file mode 100644 index 0000000..d16c846 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/rewardparts/SoundPart.java @@ -0,0 +1,78 @@ +package chanceCubes.rewards.rewardparts; + +public class SoundPart { + + public static String[] elements = new String[] { "sound:S", "delay:I", "serverWide:B", "range:I" }; + + private String sound; + + private int delay = 0; + + private boolean serverWide = false; + private int range = 16; + + private int volume = 1; + private int pitch = 1; + + private boolean atPlayersLocation = false; + + public SoundPart(String sound) { + this.sound = sound; + } + + public String getSound() { + return sound; + } + + public int getDelay() { + return delay; + } + + public SoundPart setDelay(int delay) { + this.delay = delay; + return this; + } + + public boolean isServerWide() { + return serverWide; + } + + public SoundPart setServerWide(boolean serverWide) { + this.serverWide = serverWide; + return this; + } + + public int getRange() { + return range; + } + + public SoundPart setRange(int range) { + this.range = range; + return this; + } + + public int getVolume() { + return volume; + } + + public void setVolume(int volume) { + this.volume = volume; + } + + public int getPitch() { + return pitch; + } + + public void setPitch(int pitch) { + this.pitch = pitch; + } + + public boolean playAtPlayersLocation() { + return atPlayersLocation; + } + + public SoundPart setAtPlayersLocation(boolean atPlayersLocation) { + this.atPlayersLocation = atPlayersLocation; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/type/BaseRewardType.java b/src/main/java/chanceCubes/rewards/type/BaseRewardType.java new file mode 100644 index 0000000..1df340e --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/BaseRewardType.java @@ -0,0 +1,20 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public abstract class BaseRewardType implements IRewardType { + + protected T[] rewards; + + protected BaseRewardType(T... rewards) { + this.rewards = rewards; + } + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + for (T t : rewards) trigger(t, world, x, y, z, player); + } + + protected abstract void trigger(T obj, World world, int x, int y, int z, EntityPlayer player); +} diff --git a/src/main/java/chanceCubes/rewards/type/BlockRewardType.java b/src/main/java/chanceCubes/rewards/type/BlockRewardType.java new file mode 100644 index 0000000..1f2bd3b --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/BlockRewardType.java @@ -0,0 +1,30 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.util.RewardsUtil; + +public class BlockRewardType extends BaseRewardType { + + public BlockRewardType(OffsetBlock... blocks) { + super(blocks); + } + + @Override + protected void trigger(OffsetBlock block, World world, int x, int y, int z, EntityPlayer player) { + if (block == null) return; + if (block.isRelativeToPlayer() && !RewardsUtil.isBlockUnbreakable( + world, + (int) Math.floor(player.posX), + (int) Math.floor(player.posY), + (int) Math.floor(player.posZ))) + block.spawnInWorld( + world, + (int) Math.floor(player.posX), + (int) Math.floor(player.posY), + (int) Math.floor(player.posZ)); + else if (!RewardsUtil.isBlockUnbreakable(world, x, y + 3, z)) block.spawnInWorld(world, x, y, z); + } +} diff --git a/src/main/java/chanceCubes/rewards/type/ChestRewardType.java b/src/main/java/chanceCubes/rewards/type/ChestRewardType.java new file mode 100644 index 0000000..c85f9c9 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/ChestRewardType.java @@ -0,0 +1,58 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.ChestChanceItem; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ChestRewardType extends BaseRewardType { + + private TileEntityChest chest; + + private int delay = 0; + + public ChestRewardType(ChestChanceItem... items) { + super(items); + } + + @Override + public void trigger(final World world, final int x, final int y, final int z, final EntityPlayer player) { + if (delay != 0) { + Task task = new Task("Chest Reward Delay", delay) { + + @Override + public void callback() { + world.setBlock(x, y, z, Blocks.chest); + chest = (TileEntityChest) world.getTileEntity(x, y, z); + + for (ChestChanceItem item : rewards) trigger(item, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + world.setBlock(x, y, z, Blocks.chest); + chest = (TileEntityChest) world.getTileEntity(x, y, z); + + for (ChestChanceItem item : rewards) trigger(item, world, x, y, z, player); + } + + } + + @Override + protected void trigger(ChestChanceItem item, World world, int x, int y, int z, EntityPlayer player) { + boolean addToChest = world.rand.nextInt(100) < item.getChance(); + if (addToChest) { + int slot = world.rand.nextInt(chest.getSizeInventory()); + chest.setInventorySlotContents(slot, item.getRandomItemStack()); + } + } + + public ChestRewardType setDelay(int delay) { + this.delay = delay; + return this; + } +} diff --git a/src/main/java/chanceCubes/rewards/type/CommandRewardType.java b/src/main/java/chanceCubes/rewards/type/CommandRewardType.java new file mode 100644 index 0000000..9980ee4 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/CommandRewardType.java @@ -0,0 +1,50 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.util.CCubesCommandSender; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class CommandRewardType extends BaseRewardType { + + public CommandRewardType(CommandPart... commands) { + super(commands); + } + + @Override + public void trigger(final CommandPart command, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (command.getDelay() != 0) { + Task task = new Task("Command Reward Delay", command.getDelay()) { + + @Override + public void callback() { + triggerCommand(command, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + triggerCommand(command, world, x, y, z, player); + } + } + + public void triggerCommand(CommandPart command, World world, int x, int y, int z, EntityPlayer player) { + String commandToRun = command.getParsedCommand(world, x, y, z, player); + + CCubesCommandSender sender = new CCubesCommandSender(player, x, y, z); + + Boolean rule = MinecraftServer.getServer().worldServers[0].getGameRules() + .getGameRuleBooleanValue("commandBlockOutput"); + MinecraftServer.getServer().worldServers[0].getGameRules() + .setOrCreateGameRule("commandBlockOutput", "false"); + MinecraftServer.getServer() + .getCommandManager() + .executeCommand(sender, commandToRun); + MinecraftServer.getServer().worldServers[0].getGameRules() + .setOrCreateGameRule("commandBlockOutput", rule.toString()); + } +} diff --git a/src/main/java/chanceCubes/rewards/type/EntityRewardType.java b/src/main/java/chanceCubes/rewards/type/EntityRewardType.java new file mode 100644 index 0000000..3443cb2 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/EntityRewardType.java @@ -0,0 +1,62 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import org.apache.logging.log4j.Level; + +import chanceCubes.CCubesCore; +import chanceCubes.rewards.rewardparts.EntityPart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class EntityRewardType extends BaseRewardType { + + public EntityRewardType(EntityPart... entities) { + super(entities); + } + + @Override + public void trigger(final EntityPart part, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (part.getDelay() != 0) { + Task task = new Task("Entity Reward Delay", part.getDelay()) { + + @Override + public void callback() { + spawnEntity(part, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + spawnEntity(part, world, x, y, z, player); + } + } + + public void spawnEntity(EntityPart part, World world, int x, int y, int z, EntityPlayer player) { + if (part.shouldRemovedBlocks()) for (int yy = 0; yy < 4; yy++) for (int xx = -1; xx < 2; xx++) + for (int zz = -1; zz < 2; zz++) world.setBlock(x + xx, y + yy, z + zz, Blocks.air); + + Entity newEnt = EntityList.createEntityFromNBT(part.getNBT(), world); + newEnt.setPosition(x + 0.5, y, z + 0.5); + world.spawnEntityInWorld(newEnt); + } + + public static NBTTagCompound getBasicNBTForEntity(String entity) { + String json = "{id:" + entity + "}"; + NBTTagCompound nbt = null; + try { + nbt = (NBTTagCompound) JsonToNBT.func_150315_a(json); + } catch (NBTException e) { + CCubesCore.logger.log(Level.ERROR, "Failed to create a simple NBTTagCompound from " + entity); + return null; + } + return nbt; + } +} diff --git a/src/main/java/chanceCubes/rewards/type/ExperienceRewardType.java b/src/main/java/chanceCubes/rewards/type/ExperienceRewardType.java new file mode 100644 index 0000000..6b17487 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/ExperienceRewardType.java @@ -0,0 +1,41 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.ExpirencePart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ExperienceRewardType extends BaseRewardType { + + public ExperienceRewardType(ExpirencePart... levels) { + super(levels); + } + + @Override + public void trigger(final ExpirencePart levels, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (levels.getDelay() != 0) { + Task task = new Task("Expirence Reward Delay", levels.getDelay()) { + + @Override + public void callback() { + triggerExpirence(levels, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + triggerExpirence(levels, world, x, y, z, player); + } + } + + public void triggerExpirence(ExpirencePart levels, World world, int x, int y, int z, EntityPlayer player) { + for (int i = 0; i < levels.getNumberofOrbs(); i++) { + Entity newEnt = new EntityXPOrb(world, x, y + 1, z, (levels.getAmount() / levels.getNumberofOrbs())); + world.spawnEntityInWorld(newEnt); + } + } +} diff --git a/src/main/java/chanceCubes/rewards/type/IRewardType.java b/src/main/java/chanceCubes/rewards/type/IRewardType.java new file mode 100644 index 0000000..38343ee --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/IRewardType.java @@ -0,0 +1,17 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public interface IRewardType { + + /** + * What occurs when the this Reward type is triggered + * + * @param world + * @param x + * @param y + * @param z + */ + public void trigger(World world, int x, int y, int z, EntityPlayer player); +} diff --git a/src/main/java/chanceCubes/rewards/type/ItemRewardType.java b/src/main/java/chanceCubes/rewards/type/ItemRewardType.java new file mode 100644 index 0000000..f10c604 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/ItemRewardType.java @@ -0,0 +1,45 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.ItemPart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class ItemRewardType extends BaseRewardType { + + public ItemRewardType(ItemPart... items) { + super(items); + } + + @Override + public void trigger(final ItemPart part, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (part.getDelay() != 0) { + Task task = new Task("ItemStack Reward Delay", part.getDelay()) { + + @Override + public void callback() { + spawnStack(part, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + spawnStack(part, world, x, y, z, player); + } + } + + public void spawnStack(ItemPart part, World world, int x, int y, int z, EntityPlayer player) { + Entity itemEnt = new EntityItem( + world, + x + 0.5, + y + 0.5, + z + 0.5, + part.getItemStack() + .copy()); + world.spawnEntityInWorld(itemEnt); + } +} diff --git a/src/main/java/chanceCubes/rewards/type/MessageRewardType.java b/src/main/java/chanceCubes/rewards/type/MessageRewardType.java new file mode 100644 index 0000000..503e887 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/MessageRewardType.java @@ -0,0 +1,50 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.MessagePart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class MessageRewardType extends BaseRewardType { + + public MessageRewardType(MessagePart... messages) { + super(messages); + } + + @Override + public void trigger(final MessagePart message, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (message.getDelay() != 0) { + Task task = new Task("Message Reward Delay", message.getDelay()) { + + @Override + public void callback() { + sendMessage(message, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + sendMessage(message, world, x, y, z, player); + } + + } + + public void sendMessage(MessagePart message, World world, int x, int y, int z, EntityPlayer player) { + for (int i = 0; i < world.playerEntities.size(); ++i) { + EntityPlayer entityplayer = (EntityPlayer) world.playerEntities.get(i); + + if (entityplayer.equals(player)) { + entityplayer.addChatMessage(new ChatComponentText(message.getMessage())); + } else { + double dist = Math.sqrt( + Math.pow(x - entityplayer.posX, 2) + Math.pow(y - entityplayer.posY, 2) + + Math.pow(z - entityplayer.posZ, 2)); + if (dist <= message.getRange() || message.isServerWide()) + entityplayer.addChatMessage(new ChatComponentText(message.getMessage())); + } + } + } +} diff --git a/src/main/java/chanceCubes/rewards/type/ParticleEffectRewardType.java b/src/main/java/chanceCubes/rewards/type/ParticleEffectRewardType.java new file mode 100644 index 0000000..57864f9 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/ParticleEffectRewardType.java @@ -0,0 +1,23 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.network.CCubesPacketHandler; +import chanceCubes.network.PacketParticle; +import chanceCubes.rewards.rewardparts.ParticlePart; +import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; + +public class ParticleEffectRewardType extends BaseRewardType { + + public ParticleEffectRewardType(ParticlePart... effects) { + super(effects); + } + + @Override + public void trigger(ParticlePart part, World world, int x, int y, int z, EntityPlayer player) { + CCubesPacketHandler.INSTANCE.sendToAllAround( + new PacketParticle(part.getParticle(), x + Math.random(), y + Math.random(), z + Math.random(), 0, 0, 0), + new TargetPoint(world.provider.dimensionId, x, y, z, 50)); + } +} diff --git a/src/main/java/chanceCubes/rewards/type/PotionRewardType.java b/src/main/java/chanceCubes/rewards/type/PotionRewardType.java new file mode 100644 index 0000000..6cde02c --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/PotionRewardType.java @@ -0,0 +1,58 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityPotion; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.PotionPart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class PotionRewardType extends BaseRewardType { + + public PotionRewardType(PotionPart... effects) { + super(effects); + } + + @Override + public void trigger(final PotionPart part, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (part.getDelay() != 0) { + Task task = new Task("Potion Reward Delay", part.getDelay()) { + + @Override + public void callback() { + triggerPotion(part, world, x, y, z, player); + } + }; + Scheduler.scheduleTask(task); + } else { + triggerPotion(part, world, x, y, z, player); + } + } + + public void triggerPotion(PotionPart part, World world, int x, int y, int z, EntityPlayer player) { + ItemStack potion = new ItemStack(Items.potionitem); + NBTTagList effects = new NBTTagList(); + NBTTagCompound effectData = new NBTTagCompound(); + part.getEffect() + .writeCustomPotionEffectToNBT(effectData); + effects.appendTag(effectData); + potion.stackTagCompound = new NBTTagCompound(); + potion.stackTagCompound.setTag("CustomPotionEffects", effects); + + EntityPotion entity = new EntityPotion(world, player, potion); + entity.posX = player.posX; + entity.posY = player.posY + 2; + entity.posZ = player.posZ; + entity.motionX = 0; + entity.motionY = 0.1; + entity.motionZ = 0; + + world.spawnEntityInWorld(entity); + } +} diff --git a/src/main/java/chanceCubes/rewards/type/SchematicRewardType.java b/src/main/java/chanceCubes/rewards/type/SchematicRewardType.java new file mode 100644 index 0000000..5ac3fd0 --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/SchematicRewardType.java @@ -0,0 +1,128 @@ +package chanceCubes.rewards.type; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import org.apache.logging.log4j.Level; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CustomRewardsLoader; +import chanceCubes.config.CustomRewardsLoader.Schematic; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.OffsetTileEntity; + +public class SchematicRewardType extends BaseRewardType { + + private String schemName; + private Schematic schem; + private int delay; + private boolean falling; + private boolean relativeToPlayer; + + /** + * + * @param schematic + * @param delay + * @param falling + * @param relative + * to the player + */ + public SchematicRewardType(String schemName, int delay, boolean falling, boolean rtp) { + this.schemName = schemName; + try { + this.schem = CustomRewardsLoader.instance.parseSchematic(schemName, true); + } catch (IOException e) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to load a hardcoded schematic called " + this.schemName + ". It seems to be dead :("); + return; + } + this.delay = delay; + this.falling = falling; + this.relativeToPlayer = rtp; + List blocks = this.loadSchematicReward(); + if (blocks == null) return; + super.rewards = blocks.toArray(new OffsetBlock[blocks.size()]); + } + + @Override + protected void trigger(OffsetBlock block, World world, int x, int y, int z, EntityPlayer player) { + if (rewards == null) return; + if (block.isRelativeToPlayer()) + block.spawnInWorld(world, (int) player.posX, (int) player.posY, (int) player.posZ); + else block.spawnInWorld(world, x, y, z); + } + + public List loadSchematicReward() { + List blocks = new ArrayList(); + + if (schem == null) { + CCubesCore.logger.log( + Level.ERROR, + "Failed to load a hardcoded schematic called " + this.schemName + ". It seems to be dead :("); + return null; + } + + int i = 0; + short halfLength = (short) (schem.length / 2); + short halfWidth = (short) (schem.width / 2); + + for (int yy = 0; yy < schem.height; yy++) { + for (int zz = 0; zz < schem.length; zz++) { + for (int xx = 0; xx < schem.width; xx++) { + + int j = schem.blocks[i]; + if (j < 0) { + j = 128 + (128 + j); + } + + Block b = Block.getBlockById(j); + + if (schem.tileentities != null) { + for (int i1 = 0; i1 < schem.tileentities.tagCount(); ++i1) { + NBTTagCompound nbttagcompound4 = schem.tileentities.getCompoundTagAt(i1); + if (nbttagcompound4.getInteger("x") == xx && nbttagcompound4.getInteger("y") == yy + && nbttagcompound4.getInteger("z") == zz) { + TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound4); + if (tileentity != null) { + tileentity.blockType = b; + OffsetTileEntity block = new OffsetTileEntity( + tileentity.xCoord, + tileentity.yCoord, + tileentity.zCoord, + b, + nbttagcompound4, + falling); + block.setRelativeToPlayer(this.relativeToPlayer); + block.setDelay(i * delay); + block.setData(schem.data[i]); + blocks.add(block); + continue; + } + } + } + } + + if (b != Blocks.air) { + OffsetBlock block = new OffsetBlock(halfWidth - xx, yy, halfLength - zz, b, falling); + block.setRelativeToPlayer(this.relativeToPlayer); + block.setDelay(i * delay); + block.setData(schem.data[i]); + blocks.add(block); + } + + i++; + } + } + } + return blocks; + } +} diff --git a/src/main/java/chanceCubes/rewards/type/SoundRewardType.java b/src/main/java/chanceCubes/rewards/type/SoundRewardType.java new file mode 100644 index 0000000..7aa8c0c --- /dev/null +++ b/src/main/java/chanceCubes/rewards/type/SoundRewardType.java @@ -0,0 +1,48 @@ +package chanceCubes.rewards.type; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.SoundPart; +import chanceCubes.util.Scheduler; +import chanceCubes.util.Task; + +public class SoundRewardType extends BaseRewardType { + + public SoundRewardType(SoundPart... sounds) { + super(sounds); + } + + @Override + public void trigger(final SoundPart sound, final World world, final int x, final int y, final int z, + final EntityPlayer player) { + if (sound.getDelay() != 0) { + Task task = new Task("Message Reward Delay", sound.getDelay()) { + + @Override + public void callback() { + if (sound.playAtPlayersLocation()) world.playSoundEffect( + player.posX, + player.posY, + player.posZ, + sound.getSound(), + sound.getVolume(), + sound.getPitch()); + else world.playSoundEffect(x, y, z, sound.getSound(), sound.getVolume(), sound.getPitch()); + } + }; + Scheduler.scheduleTask(task); + } else { + if (sound.playAtPlayersLocation()) world.playSoundEffect( + player.posX, + player.posY, + player.posZ, + sound.getSound(), + sound.getVolume(), + sound.getPitch()); + else world.playSoundEffect(x, y, z, sound.getSound(), sound.getVolume(), sound.getPitch()); + } + + } + +} diff --git a/src/main/java/chanceCubes/tileentities/TileChanceCube.java b/src/main/java/chanceCubes/tileentities/TileChanceCube.java new file mode 100644 index 0000000..ec27472 --- /dev/null +++ b/src/main/java/chanceCubes/tileentities/TileChanceCube.java @@ -0,0 +1,76 @@ +package chanceCubes.tileentities; + +import java.util.Random; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; + +public class TileChanceCube extends TileEntity { + + private static Random random = new Random(); + + private int chance; + private boolean isScanned = false; + + public TileChanceCube() { + this(Math.round((float) (random.nextGaussian() * 40))); + } + + public TileChanceCube(int initialChance) { + while (initialChance > 100 || initialChance < -100) + initialChance = Math.round((float) (random.nextGaussian() * 40)); + + this.chance = initialChance; + } + + public void setChance(int newChance) { + this.chance = newChance; + } + + public int getChance() { + return this.chance; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + this.writeSyncableDataToNBT(nbt); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.readSyncableDataFromNBT(nbt); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound syncData = new NBTTagCompound(); + this.writeSyncableDataToNBT(syncData); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, syncData); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + readSyncableDataFromNBT(pkt.func_148857_g()); + } + + private void writeSyncableDataToNBT(NBTTagCompound syncData) { + syncData.setInteger("chance", this.getChance()); + } + + private void readSyncableDataFromNBT(NBTTagCompound nbt) { + this.chance = nbt.getInteger("chance"); + } + + public boolean isScanned() { + return isScanned; + } + + public void setScanned(boolean isScanned) { + this.isScanned = isScanned; + } +} diff --git a/src/main/java/chanceCubes/tileentities/TileChanceD20.java b/src/main/java/chanceCubes/tileentities/TileChanceD20.java new file mode 100644 index 0000000..d141dcd --- /dev/null +++ b/src/main/java/chanceCubes/tileentities/TileChanceD20.java @@ -0,0 +1,138 @@ +package chanceCubes.tileentities; + +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; + +import chanceCubes.CCubesCore; +import chanceCubes.config.CCubesSettings; +import chanceCubes.registry.ChanceCubeRegistry; + +public class TileChanceD20 extends TileEntity { + + private static final float BASE_SPIN_SPEED = 0.5F; + + private Random random = new Random(); + + private boolean breaking = false; + private int stage = 0; + public float rotation = 0, rotationDelta = 0; + private EntityPlayer player; + + private int chance; + private boolean isScanned = false; + + public TileChanceD20() { + if (!CCubesSettings.d20UseNormalChances) { + this.chance = random.nextBoolean() ? -100 : 100; + } else { + this.chance = Math.round((float) (random.nextGaussian() * 40)); + while (this.chance > 100 || this.chance < -100) + this.chance = Math.round((float) (random.nextGaussian() * 40)); + } + } + + public TileChanceD20(int initialChance) { + this.chance = initialChance; + } + + public void setChance(int newChance) { + this.chance = newChance; + } + + public int getChance() { + return this.chance; + } + + @Override + public AxisAlignedBB getRenderBoundingBox() { + // Expand to cover rising animation and rays + return super.getRenderBoundingBox().addCoord(xCoord, yCoord + 3, zCoord) + .expand(5, 5, 5); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + this.writeSyncableDataToNBT(nbt); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.readSyncableDataFromNBT(nbt); + } + + public void updateEntity() { + if (!breaking) return; + stage++; + if (stage > 200) { + breaking = false; + if (!this.worldObj.isRemote) { + this.worldObj.setBlockToAir(this.xCoord, this.yCoord, this.zCoord); + this.worldObj.removeTileEntity(this.xCoord, this.yCoord, this.zCoord); + ChanceCubeRegistry.INSTANCE.triggerRandomReward( + this.worldObj, + this.xCoord, + this.yCoord, + this.zCoord, + player, + this.getChance()); + } + } else if (worldObj.isRemote) { + rotationDelta = (float) (BASE_SPIN_SPEED + Math.pow(1.02, getStage() + 1)); + rotation += (float) (BASE_SPIN_SPEED + Math.pow(1.02, getStage())); + } + } + + public void startBreaking(EntityPlayer player) { + if (!breaking) { + if (!player.worldObj.isRemote) { + player.worldObj + .playSoundEffect(this.xCoord, this.yCoord, this.zCoord, CCubesCore.MODID + ":d20_Break", 1, 1); + this.player = player; + } + breaking = true; + stage = 0; + + } + } + + public int getStage() { + return this.stage; + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound syncData = new NBTTagCompound(); + this.writeSyncableDataToNBT(syncData); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, syncData); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + readSyncableDataFromNBT(pkt.func_148857_g()); + } + + private void writeSyncableDataToNBT(NBTTagCompound syncData) { + syncData.setInteger("chance", this.getChance()); + } + + private void readSyncableDataFromNBT(NBTTagCompound nbt) { + this.chance = nbt.getInteger("chance"); + } + + public boolean isScanned() { + return isScanned; + } + + public void setScanned(boolean isScanned) { + this.isScanned = isScanned; + } +} diff --git a/src/main/java/chanceCubes/tileentities/TileCubeDispenser.java b/src/main/java/chanceCubes/tileentities/TileCubeDispenser.java new file mode 100644 index 0000000..c3e17ff --- /dev/null +++ b/src/main/java/chanceCubes/tileentities/TileCubeDispenser.java @@ -0,0 +1,67 @@ +package chanceCubes.tileentities; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import chanceCubes.blocks.CCubesBlocks; + +public class TileCubeDispenser extends TileEntity { + + private EntityItem entityItem; + private int currentMeta = 0; + + public float rot = 0; + public float wave = 0; + + public EntityItem getRenderEntityItem(int meta) { + if (entityItem == null) this.entityItem = new EntityItem( + this.worldObj, + xCoord, + yCoord, + zCoord, + new ItemStack(CCubesBlocks.chanceCube, 1)); + if (this.currentMeta != meta) { + this.currentMeta = meta; + if (meta == 1) this.entityItem.setEntityItemStack(new ItemStack(CCubesBlocks.chanceIcosahedron, 1)); + else if (meta == 2) + this.entityItem.setEntityItemStack(new ItemStack(CCubesBlocks.chanceCompactGiantCube, 1)); + else this.entityItem.setEntityItemStack(new ItemStack(CCubesBlocks.chanceCube, 1)); + } + + return this.entityItem; + } + + public EntityItem getNewEntityItem(int meta) { + EntityItem ent; + + if (meta == 1) ent = new EntityItem( + this.worldObj, + xCoord, + yCoord, + zCoord, + new ItemStack(CCubesBlocks.chanceIcosahedron, 1)); + else if (meta == 2) ent = new EntityItem( + this.worldObj, + xCoord, + yCoord, + zCoord, + new ItemStack(CCubesBlocks.chanceCompactGiantCube, 1)); + else ent = new EntityItem(this.worldObj, xCoord, yCoord, zCoord, new ItemStack(CCubesBlocks.chanceCube, 1)); + + return ent; + } + + public Block getCurrentBlock(int meta) { + Block b = Blocks.air; + if (entityItem == null || this.currentMeta != meta) { + if (meta == 1) b = CCubesBlocks.chanceIcosahedron; + else if (meta == 2) b = CCubesBlocks.chanceCompactGiantCube; + else b = CCubesBlocks.chanceCube; + } + + return b; + } +} diff --git a/src/main/java/chanceCubes/tileentities/TileGiantCube.java b/src/main/java/chanceCubes/tileentities/TileGiantCube.java new file mode 100644 index 0000000..d514249 --- /dev/null +++ b/src/main/java/chanceCubes/tileentities/TileGiantCube.java @@ -0,0 +1,103 @@ +package chanceCubes.tileentities; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import chanceCubes.util.GiantCubeUtil; + +public class TileGiantCube extends TileEntity { + + private boolean hasMaster, isMaster; + private int masterX, masterY, masterZ; + + @Override + public void updateEntity() { + super.updateEntity(); + if (!worldObj.isRemote) { + if (hasMaster()) { + if (isMaster()) { + // Put stuff you want the multiblock to do here! + } + } else { + // Constantly check if structure is formed until it is. + if (!GiantCubeUtil.checkMultiBlockForm(masterX, masterY, masterZ, worldObj, false)) + GiantCubeUtil.resetStructure(masterX, masterY, masterZ, worldObj); + } + } + } + + /** Reset method to be run when the master is gone or tells them to */ + public void reset() { + masterX = 0; + masterY = 0; + masterZ = 0; + hasMaster = false; + isMaster = false; + } + + /** Check that the master exists */ + public boolean checkForMaster() { + TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ); + return (tile != null && (tile instanceof TileGiantCube)); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + data.setInteger("masterX", masterX); + data.setInteger("masterY", masterY); + data.setInteger("masterZ", masterZ); + data.setBoolean("hasMaster", hasMaster); + data.setBoolean("isMaster", isMaster); + if (hasMaster() && isMaster()) { + // Any other values should ONLY BE SAVED TO THE MASTER + } + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + masterX = data.getInteger("masterX"); + masterY = data.getInteger("masterY"); + masterZ = data.getInteger("masterZ"); + hasMaster = data.getBoolean("hasMaster"); + isMaster = data.getBoolean("isMaster"); + if (hasMaster() && isMaster()) { + // Any other values should ONLY BE READ BY THE MASTER + } + } + + public boolean hasMaster() { + return hasMaster; + } + + public boolean isMaster() { + return isMaster; + } + + public int getMasterX() { + return masterX; + } + + public int getMasterY() { + return masterY; + } + + public int getMasterZ() { + return masterZ; + } + + public void setHasMaster(boolean bool) { + hasMaster = bool; + } + + public void setIsMaster(boolean bool) { + isMaster = bool; + } + + public void setMasterCoords(int x, int y, int z) { + masterX = x; + masterY = y; + masterZ = z; + } +} diff --git a/src/main/java/chanceCubes/util/CCubesAchievements.java b/src/main/java/chanceCubes/util/CCubesAchievements.java new file mode 100644 index 0000000..d9b2c79 --- /dev/null +++ b/src/main/java/chanceCubes/util/CCubesAchievements.java @@ -0,0 +1,63 @@ +package chanceCubes.util; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; +import net.minecraftforge.common.AchievementPage; + +import chanceCubes.blocks.CCubesBlocks; + +public class CCubesAchievements { + + public static AchievementPage page; + public static Achievement chanceIcosahedron; + public static Achievement GiantChanceCube; + public static Achievement lonelyDirt; + public static Achievement wither; + public static Achievement herobrine; + public static Achievement itsALie; + + public static void loadAchievements() { + chanceIcosahedron = new Achievement( + "chancecubes.chanceIcosahedron", + "chancecubes.chanceIcosahedron", + 0, + 0, + CCubesBlocks.chanceIcosahedron, + null).registerStat(); + GiantChanceCube = new Achievement( + "chancecubes.GiantChanceCube", + "chancecubes.GiantChanceCube", + 1, + 0, + CCubesBlocks.chanceCompactGiantCube, + null).registerStat(); + lonelyDirt = new Achievement("chancecubes.lonelyDirt", "chancecubes.lonelyDirt", 0, -1, Blocks.dirt, null) + .registerStat(); + wither = new Achievement( + "chancecubes.wither", + "chancecubes.wither", + 1, + -1, + new ItemStack(Items.skull, 1, 1), + null).registerStat(); + herobrine = new Achievement( + "chancecubes.herobrine", + "chancecubes.herobrine", + 2, + -1, + new ItemStack(Items.skull, 1, 2), + null).registerStat(); + itsALie = new Achievement("chancecubes.itsALie", "chancecubes.itsALie", 0, 1, Items.cake, null).registerStat(); + page = new AchievementPage( + "Chance Cubes", + chanceIcosahedron, + GiantChanceCube, + lonelyDirt, + wither, + herobrine, + itsALie); + AchievementPage.registerAchievementPage(page); + } +} diff --git a/src/main/java/chanceCubes/util/CCubesCommandSender.java b/src/main/java/chanceCubes/util/CCubesCommandSender.java new file mode 100644 index 0000000..3ab1a16 --- /dev/null +++ b/src/main/java/chanceCubes/util/CCubesCommandSender.java @@ -0,0 +1,67 @@ +package chanceCubes.util; + +import net.minecraft.command.server.CommandBlockLogic; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; + +public class CCubesCommandSender extends CommandBlockLogic { + + EntityPlayer harvester; + ChunkCoordinates blockLoc; + + public CCubesCommandSender(EntityPlayer player, int x, int y, int z) { + blockLoc = new ChunkCoordinates(x, y, z); + harvester = player; + } + + @Override + public boolean canCommandSenderUseCommand(int level, String command) { + return level <= 2; + } + + @Override + public String getCommandSenderName() { + return CCubesCore.NAME; + } + + @Override + public IChatComponent func_145748_c_() { + return new ChatComponentText(this.getCommandSenderName()); + } + + @Override + public void addChatMessage(IChatComponent p_145747_1_) { + if (this.getEntityWorld() != null && !this.getEntityWorld().isRemote) this.getEntityWorld() + .markBlockForUpdate(blockLoc.posX, blockLoc.posY, blockLoc.posZ); + } + + @Override + public ChunkCoordinates getPlayerCoordinates() { + return blockLoc; + } + + @Override + public World getEntityWorld() { + return harvester != null ? harvester.worldObj : null; + } + + public void func_145756_e() {} + + @SideOnly(Side.CLIENT) + public int func_145751_f() { + return 0; // Unknown purpose + } + + @SideOnly(Side.CLIENT) + public void func_145757_a(ByteBuf p_145757_1_) {}; + + public void func_145750_b(IChatComponent p_145750_1_) {} +} diff --git a/src/main/java/chanceCubes/util/CCubesDamageSource.java b/src/main/java/chanceCubes/util/CCubesDamageSource.java new file mode 100644 index 0000000..a9ec525 --- /dev/null +++ b/src/main/java/chanceCubes/util/CCubesDamageSource.java @@ -0,0 +1,16 @@ +package chanceCubes.util; + +import net.minecraft.util.DamageSource; + +public class CCubesDamageSource extends DamageSource { + + public static CCubesDamageSource mathfail = new CCubesDamageSource("mathdeath"); + public static CCubesDamageSource questionfail = new CCubesDamageSource("questiondeath"); + public static CCubesDamageSource mazefail = new CCubesDamageSource("mazedeath"); + + public CCubesDamageSource(String id) { + super(id); + super.setDamageBypassesArmor(); + } + +} diff --git a/src/main/java/chanceCubes/util/CustomEntry.java b/src/main/java/chanceCubes/util/CustomEntry.java new file mode 100644 index 0000000..93a2ffa --- /dev/null +++ b/src/main/java/chanceCubes/util/CustomEntry.java @@ -0,0 +1,31 @@ +package chanceCubes.util; + +import java.util.Map; + +public class CustomEntry implements Map.Entry { + + private final K key; + private V value; + + public CustomEntry(K key, V value) { + this.key = key; + this.value = value; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V value) { + V old = this.value; + this.value = value; + return old; + } +} diff --git a/src/main/java/chanceCubes/util/CustomSchematic.java b/src/main/java/chanceCubes/util/CustomSchematic.java new file mode 100644 index 0000000..767d676 --- /dev/null +++ b/src/main/java/chanceCubes/util/CustomSchematic.java @@ -0,0 +1,41 @@ +package chanceCubes.util; + +import java.util.List; + +import chanceCubes.rewards.rewardparts.OffsetBlock; + +public class CustomSchematic { + + private List blocks; + private int xSize; + private int ySize; + private int zSize; + private boolean relativeToPlayer; + + public CustomSchematic(List blocks, int xSize, int ySize, int zSize, boolean relativeToPlayer) { + this.blocks = blocks; + this.xSize = xSize; + this.ySize = ySize; + this.zSize = zSize; + } + + public List getBlocks() { + return this.blocks; + } + + public int getXSize() { + return this.xSize; + } + + public int getYSize() { + return this.ySize; + } + + public int getZSize() { + return this.zSize; + } + + public boolean isRelativeToPlayer() { + return relativeToPlayer; + } +} diff --git a/src/main/java/chanceCubes/util/FileUtil.java b/src/main/java/chanceCubes/util/FileUtil.java new file mode 100644 index 0000000..746b306 --- /dev/null +++ b/src/main/java/chanceCubes/util/FileUtil.java @@ -0,0 +1,150 @@ +package chanceCubes.util; + +import java.io.BufferedReader; +import java.io.Closeable; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.URI; +import java.util.Deque; +import java.util.LinkedList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import javax.annotation.Nonnull; + +import org.apache.commons.io.FileUtils; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +import chanceCubes.CCubesCore; + +/** + * Code Referenced and sourced from the EnderCore and CustomThings mods. All referenced sources and code belong to their + * original authors and is used with their permission. + */ + +public class FileUtil { + + private static JsonParser jsonParser = new JsonParser(); + + @Nonnull + public static File writeToFile(String filepath, String json) { + File file = new File(filepath); + + try { + file.createNewFile(); + FileWriter fw = new FileWriter(file); + fw.write(json); + fw.flush(); + fw.close(); + return file; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static JsonElement readJsonfromFile(String filepath) { + String result = ""; + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filepath)))); + String line = ""; + while ((line = reader.readLine()) != null) { + result += line; + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + return jsonParser.parse(result); + } + + public static void writeNewFile(File file, String defaultText) throws IOException { + FileUtil.safeDelete(file); + file.delete(); + file.getParentFile() + .mkdirs(); + file.createNewFile(); + + FileWriter fw = new FileWriter(file); + fw.write(defaultText); + fw.flush(); + fw.close(); + } + + @Nonnull + public static void safeDelete(File file) { + try { + file.delete(); + } catch (Exception e) { + CCubesCore.logger.error("Deleting file " + file.getAbsolutePath() + " failed."); + } + } + + @Nonnull + public static void safeDeleteDirectory(File file) { + try { + FileUtils.deleteDirectory(file); + } catch (Exception e) { + CCubesCore.logger.error("Deleting directory " + file.getAbsolutePath() + " failed."); + } + } + + @SuppressWarnings("resource") + public static void zipFolderContents(File directory, File zipfile) throws IOException { + URI base = directory.toURI(); + Deque queue = new LinkedList(); + queue.push(directory); + OutputStream out = new FileOutputStream(zipfile); + Closeable res = out; + try { + ZipOutputStream zout = new ZipOutputStream(out); + res = zout; + while (!queue.isEmpty()) { + directory = queue.pop(); + for (File child : directory.listFiles()) { + String name = base.relativize(child.toURI()) + .getPath(); + if (child.isDirectory()) { + queue.push(child); + name = name.endsWith("/") ? name : name + "/"; + zout.putNextEntry(new ZipEntry(name)); + } else { + zout.putNextEntry(new ZipEntry(name)); + copy(child, zout); + zout.closeEntry(); + } + } + } + } finally { + res.close(); + } + } + + private static void copy(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + while (true) { + int readCount = in.read(buffer); + if (readCount < 0) { + break; + } + out.write(buffer, 0, readCount); + } + } + + private static void copy(File file, OutputStream out) throws IOException { + InputStream in = new FileInputStream(file); + try { + copy(in, out); + } finally { + in.close(); + } + } +} diff --git a/src/main/java/chanceCubes/util/GiantCubeUtil.java b/src/main/java/chanceCubes/util/GiantCubeUtil.java new file mode 100644 index 0000000..96f9dfc --- /dev/null +++ b/src/main/java/chanceCubes/util/GiantCubeUtil.java @@ -0,0 +1,115 @@ +package chanceCubes.util; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import chanceCubes.CCubesCore; +import chanceCubes.blocks.CCubesBlocks; +import chanceCubes.tileentities.TileGiantCube; + +public class GiantCubeUtil { + + /** + * Check that structure is properly formed + * + * @param xCoord + * @param yCoord + * @param zCoord + * @param world + * @param build if the giant cube should be built if the structure is valid + * @return if there is a valid 3x3x3 configuration + */ + public static boolean checkMultiBlockForm(int xCoord, int yCoord, int zCoord, World world, boolean build) { + Location3I bottomLeft = findBottomCorner(xCoord, yCoord, zCoord, world); + int cx = bottomLeft.getX(); + int cy = bottomLeft.getY(); + int cz = bottomLeft.getZ(); + + int i = 0; + // Scan a 3x3x3 area, starting with the bottom left corner + for (int x = cx; x < cx + 3; x++) + for (int y = cy; y < cy + 3; y++) for (int z = cz; z < cz + 3; z++) if (world.getBlock(x, y, z) + .equals(CCubesBlocks.chanceCube)) i++; + // check if there are 27 blocks present (3*3*3) and if a giant cube should be built + if (build) { + if (i > 26) { + setupStructure(cx, cy, cz, world, true); + return true; + } + return false; + } else { + return i > 26; + } + } + + /** Setup all the blocks in the structure */ + public static void setupStructure(int xCoord, int yCoord, int zCoord, World world, boolean areCoordsCorrect) { + int cx = xCoord; + int cy = yCoord; + int cz = zCoord; + + if (!areCoordsCorrect) { + Location3I bottomLeft = findBottomCorner(xCoord, yCoord, zCoord, world); + cx = bottomLeft.getX(); + cy = bottomLeft.getY(); + cz = bottomLeft.getZ(); + } + + int i = 0; + for (int x = cx; x < cx + 3; x++) { + for (int z = cz; z < cz + 3; z++) { + for (int y = cy; y < cy + 3; y++) { + i++; + RewardsUtil.placeBlock(CCubesBlocks.chanceGiantCube, world, x, y, z, 0, i == 27 ? 3 : 2); + TileEntity tile = world.getTileEntity(x, y, z); + boolean master = (x == cx && y == cy + 1 && z == cz); + if (tile != null && (tile instanceof TileGiantCube)) { + ((TileGiantCube) tile).setMasterCoords(cx + 1, cy + 1, cz + 1); + ((TileGiantCube) tile).setHasMaster(true); + ((TileGiantCube) tile).setIsMaster(master); + } + } + } + } + world.playSoundEffect(xCoord, yCoord, zCoord, CCubesCore.MODID + ":giant_Cube_Spawn", 1, 1); + } + + public static Location3I findBottomCorner(int xCoord, int yCoord, int zCoord, World world) { + int cx = xCoord; + int cy = yCoord; + int cz = zCoord; + while (world.getBlock(cx, cy - 1, cz) + .equals(CCubesBlocks.chanceCube)) cy--; + while (world.getBlock(cx - 1, cy, cz) + .equals(CCubesBlocks.chanceCube)) cx--; + while (world.getBlock(cx, cy, cz - 1) + .equals(CCubesBlocks.chanceCube)) cz--; + return new Location3I(cx, cy, cz); + } + + /** Reset all the parts of the structure */ + public static void resetStructure(int xCoord, int yCoord, int zCoord, World world) { + for (int x = xCoord - 1; x < xCoord + 2; x++) + for (int y = yCoord - 1; y < yCoord + 2; y++) for (int z = zCoord - 1; z < zCoord + 2; z++) { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile != null && (tile instanceof TileGiantCube)) { + ((TileGiantCube) tile).reset(); + world.removeTileEntity(x, y, z); + world.setBlock(x, y, z, CCubesBlocks.chanceCube); + } + } + } + + /** Reset all the parts of the structure */ + public static void removeStructure(int xCoord, int yCoord, int zCoord, World world) { + for (int x = xCoord - 1; x < xCoord + 2; x++) + for (int y = yCoord - 1; y < yCoord + 2; y++) for (int z = zCoord - 1; z < zCoord + 2; z++) { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile != null && (tile instanceof TileGiantCube)) { + ((TileGiantCube) tile).reset(); + world.removeTileEntity(x, y, z); + world.setBlockToAir(x, y, z); + } + } + } +} diff --git a/src/main/java/chanceCubes/util/HTTPUtil.java b/src/main/java/chanceCubes/util/HTTPUtil.java new file mode 100644 index 0000000..0d058df --- /dev/null +++ b/src/main/java/chanceCubes/util/HTTPUtil.java @@ -0,0 +1,64 @@ +package chanceCubes.util; + +import java.io.BufferedInputStream; +import java.io.DataOutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.apache.logging.log4j.Level; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +import chanceCubes.CCubesCore; + +public class HTTPUtil { + + private static JsonParser json = new JsonParser(); + + @SafeVarargs + public static JsonElement getWebFile(String link, CustomEntry... extras) throws Exception { + HttpURLConnection con = (HttpURLConnection) new URL(link).openConnection(); + con.setDoOutput(true); + con.setReadTimeout(20000); + con.setRequestProperty("Connection", "keep-alive"); + con.setRequestProperty( + "User-Agent", + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0"); + ((HttpURLConnection) con).setRequestMethod("GET"); + con.setConnectTimeout(5000); + + StringBuilder builder = new StringBuilder(); + + for (CustomEntry property : extras) { + builder.append(property.getKey()); + builder.append("="); + builder.append(property.getValue()); + builder.append("&"); + } + + if (builder.length() > 0) builder.deleteCharAt(builder.length() - 1); + + DataOutputStream wr = new DataOutputStream(con.getOutputStream()); + wr.writeBytes(builder.toString()); + wr.flush(); + wr.close(); + + BufferedInputStream in = new BufferedInputStream(con.getInputStream()); + int responseCode = con.getResponseCode(); + + if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_MOVED_PERM) + CCubesCore.logger.log( + Level.WARN, + "Update request returned response code: " + responseCode + " " + con.getResponseMessage()); + else if (responseCode == HttpURLConnection.HTTP_MOVED_PERM) throw new Exception(); + + StringBuffer buffer = new StringBuffer(); + int chars_read; + while ((chars_read = in.read()) != -1) buffer.append((char) chars_read); + + String page = buffer.toString(); + + return json.parse(page); + } +} diff --git a/src/main/java/chanceCubes/util/Location2I.java b/src/main/java/chanceCubes/util/Location2I.java new file mode 100644 index 0000000..0ef4034 --- /dev/null +++ b/src/main/java/chanceCubes/util/Location2I.java @@ -0,0 +1,61 @@ +package chanceCubes.util; + +public class Location2I { + + private int x; + private int y; + + public Location2I(int xloc, int yloc) { + x = xloc; + y = yloc; + } + + public enum Direction { + North, + South, + East, + West; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public void setXY(int x, int y) { + this.x = x; + this.y = y; + } + + public Location2I add(int xa, int ya) { + return new Location2I(x + xa, y + ya); + } + + public Location2I subtract(int xa, int ya) { + return new Location2I(x - xa, y - ya); + } + + public Location2I multiply(int xa, int ya) { + return new Location2I(x * xa, y * ya); + } + + public Location2I divide(int xa, int ya) { + return new Location2I(x / xa, y / ya); + } + + public boolean equals(Location2I loc) { + if (x == loc.getX() && y == loc.getY()) return true; + return false; + } +} diff --git a/src/main/java/chanceCubes/util/Location3I.java b/src/main/java/chanceCubes/util/Location3I.java new file mode 100644 index 0000000..5eb147c --- /dev/null +++ b/src/main/java/chanceCubes/util/Location3I.java @@ -0,0 +1,44 @@ +package chanceCubes.util; + +public class Location3I { + + private int x; + private int y; + private int z; + + public Location3I() { + this.x = 0; + this.y = 0; + this.z = 0; + } + + public Location3I(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + + public float length() { + return (float) Math.sqrt(x * x + y * y + z * z); + } + + public boolean equals(Location3I loc) { + return loc.getX() == x && loc.getY() == y && loc.getZ() == z; + } + + public Location3I add(int x, int y, int z) { + return new Location3I(this.x + x, this.y + y, this.z + z); + } +} diff --git a/src/main/java/chanceCubes/util/MazeGenerator.java b/src/main/java/chanceCubes/util/MazeGenerator.java new file mode 100644 index 0000000..3a4971a --- /dev/null +++ b/src/main/java/chanceCubes/util/MazeGenerator.java @@ -0,0 +1,212 @@ +package chanceCubes.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.world.World; + +public class MazeGenerator { + + private int width; + private int height; + private int[][] map; + private ArrayList walls = new ArrayList(); + private Map> blockStorgae = new HashMap>(); + private Map tileStorgae = new HashMap(); + private Random r = new Random(); + + private int currentX = 1; + private int currentY = 1; + + private final int nonWall = 0; + private final int wall = 1; + + private Location2I endBlock; + public Location3I endBlockWorldCords; + + /** + * + * @param multiple + * @param x1 + * @param y1 + * @param x2 + * @param y2 + */ + public void generate(World world, int x1, int y1, int z1, int width, int height) { + this.width = width; + this.height = height; + map = new int[width][height]; + for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) map[x][y] = wall; + + map[1][1] = nonWall; + currentX = 1; + currentY = 1; + Location2I current = new Location2I(currentX, currentY); + Location2I north = current.add(0, -1); + Location2I east = current.add(1, 0); + Location2I south = current.add(0, 1); + Location2I west = current.add(-1, 0); + + if ((north.getY() > 0) && (map[(int) north.getX()][(int) north.getY()] == wall)) { + if (map[(int) north.getX()][(int) (north.getY() - 1)] == wall) walls.add(north); + } + if ((east.getX() < width) && (map[(int) east.getX()][(int) east.getY()] == wall)) { + if (map[(int) (east.getX() + 1)][(int) east.getY()] == wall) walls.add(east); + } + if ((south.getY() < height) && (map[(int) south.getX()][(int) south.getY()] == wall)) { + if (map[(int) south.getX()][(int) (south.getY() + 1)] == wall) walls.add(south); + } + if ((west.getX() > 0) && (map[(int) west.getX()][(int) west.getY()] == wall)) { + if (map[(int) (west.getX() - 1)][(int) west.getY()] == wall) walls.add(west); + } + + int randomLoc = 0; + while (walls.size() > 0) { + randomLoc = r.nextInt(walls.size()); + currentX = (int) ((Location2I) walls.get(randomLoc)).getX(); + currentY = (int) ((Location2I) walls.get(randomLoc)).getY(); + current.setXY(currentX, currentY); + north = current.add(0, -1); + east = current.add(1, 0); + south = current.add(0, 1); + west = current.add(-1, 0); + + if (!checkwalls(current)) { + map[currentX][currentY] = nonWall; + walls.remove(randomLoc); + + if ((north.getY() - 1 > 0) && (map[(int) north.getX()][(int) north.getY()] == wall)) { + if (map[(int) north.getX()][(int) (north.getY() - 1)] == wall) walls.add(north); + } + if ((east.getX() + 1 < width) && (map[(int) east.getX()][(int) east.getY()] == wall)) { + if (map[(int) (east.getX() + 1)][(int) east.getY()] == wall) walls.add(east); + } + if ((south.getY() + 1 < height) && (map[(int) south.getX()][(int) south.getY()] == wall)) { + if (map[(int) south.getX()][(int) (south.getY() + 1)] == wall) walls.add(south); + } + if ((west.getX() - 1 > 0) && (map[(int) west.getX()][(int) west.getY()] == wall)) { + if (map[(int) (west.getX() - 1)][(int) west.getY()] == wall) walls.add(west); + } + } else { + walls.remove(randomLoc); + } + } + int endBlockX = width - 1; + int endBlockZ = height - 1; + boolean run = true; + int i = 0; + int xx = 0; + int zz = 0; + while (run) { + for (xx = 0; xx <= i; xx++) { + for (zz = i; zz >= 0; zz--) { + if (this.map[endBlockX - xx][endBlockZ - zz] == this.nonWall && run) { + endBlock = new Location2I(endBlockX - xx, endBlockZ - zz); + run = false; + } + } + } + i++; + } + + placeBlocks(world, x1, y1, z1); + } + + private boolean checkwalls(Location2I loc) { + Location2I north = loc.add(0, -1); + Location2I east = loc.add(1, 0); + Location2I south = loc.add(0, 1); + Location2I west = loc.add(-1, 0); + + int yes = 0; + if (north.getY() >= 0 && map[north.getX()][north.getY()] == nonWall) yes++; + if (east.getX() < width && map[east.getX()][east.getY()] == nonWall) yes++; + if (south.getY() < height && map[south.getX()][south.getY()] == nonWall) yes++; + if (west.getX() >= 0 && map[west.getX()][west.getY()] == nonWall) yes++; + return yes > 1; + } + + private void placeBlocks(World world, int x, int y, int z) { + int xoff = (x - (this.width / 2)); + int zoff = (z - (this.height / 2)); + + TileEntity temp; + NBTTagCompound nbt = new NBTTagCompound(); + for (int xx = 0; xx < this.width; xx++) { + for (int zz = 0; zz < this.height; zz++) { + if (this.map[xx][zz] == 0) { + for (int yy = -1; yy < 3; yy++) { + blockStorgae.put( + new Location3I(xoff + xx, y + yy, zoff + zz), + new CustomEntry( + world.getBlock(xoff + xx, y + yy, zoff + zz), + world.getBlockMetadata(xoff + xx, y + yy, zoff + zz))); + temp = world.getTileEntity(xoff + xx, y + yy, zoff + zz); + if (temp != null) { + temp.writeToNBT(nbt); + this.tileStorgae.put(new Location3I(xoff + xx, y + yy, zoff + zz), nbt); + } + } + + world.setBlock(xoff + xx, y - 1, zoff + zz, Blocks.bedrock); + world.setBlock(xoff + xx, y, zoff + zz, Blocks.torch); + world.setBlockMetadataWithNotify(xoff + xx, y, zoff + zz, 0, 3); + world.setBlockToAir(xoff + xx, y + 1, zoff + zz); + world.setBlock(xoff + xx, y + 2, zoff + zz, Blocks.bedrock); + } else { + for (int yy = -1; yy < 3; yy++) { + blockStorgae.put( + new Location3I(xoff + xx, y + yy, zoff + zz), + new CustomEntry( + world.getBlock(xoff + xx, y + yy, zoff + zz), + world.getBlockMetadata(xoff + xx, y + yy, zoff + zz))); + temp = world.getTileEntity(xoff + xx, y + yy, zoff + zz); + if (temp != null) { + temp.writeToNBT(nbt); + this.tileStorgae.put(new Location3I(xoff + xx, y + yy, zoff + zz), nbt); + } + } + world.setBlockToAir(xoff + xx, y - 1, zoff + zz); + world.setBlock(xoff + xx, y, zoff + zz, Blocks.bedrock); + world.setBlock(xoff + xx, y + 1, zoff + zz, Blocks.bedrock); + world.setBlockToAir(xoff + xx, y + 2, zoff + zz); + } + } + } + + endBlockWorldCords = new Location3I(xoff + this.endBlock.getX(), y, zoff + this.endBlock.getY()); + world.setBlock(xoff + this.endBlock.getX(), y, zoff + this.endBlock.getY(), Blocks.standing_sign, 6, 2); + temp = world.getTileEntity(xoff + this.endBlock.getX(), y, zoff + this.endBlock.getY()); + if (temp instanceof TileEntitySign) { + TileEntitySign sign = (TileEntitySign) temp; + sign.signText[0] = "Break me"; + sign.signText[1] = "To beat the"; + sign.signText[2] = "Maze"; + } + } + + public void endMaze(World world) { + for (Location3I loc : this.blockStorgae.keySet()) world.setBlock( + loc.getX(), + loc.getY(), + loc.getZ(), + this.blockStorgae.get(loc) + .getKey(), + this.blockStorgae.get(loc) + .getValue(), + 2); + + for (Location3I loc : this.tileStorgae.keySet()) world.setTileEntity( + loc.getX(), + loc.getY(), + loc.getZ(), + TileEntity.createAndLoadEntity(this.tileStorgae.get(loc))); + } +} diff --git a/src/main/java/chanceCubes/util/RenderUtil.java b/src/main/java/chanceCubes/util/RenderUtil.java new file mode 100644 index 0000000..e3c872a --- /dev/null +++ b/src/main/java/chanceCubes/util/RenderUtil.java @@ -0,0 +1,47 @@ +package chanceCubes.util; + +import java.lang.reflect.Field; + +import javax.annotation.Nullable; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.Timer; + +import chanceCubes.CCubesCore; +import cpw.mods.fml.relauncher.ReflectionHelper; + +public class RenderUtil { + + private static Field timerField = initTimer(); + + private static Field initTimer() { + Field f = null; + try { + f = ReflectionHelper.findField(Minecraft.class, "field_71428_T", "timer", "Q"); + f.setAccessible(true); + } catch (Exception e) { + CCubesCore.logger.error("Failed to initialize timer reflection."); + e.printStackTrace(); + } + return f; + } + + @Nullable + public static Timer getTimer() { + if (timerField == null) return null; + + try { + return (Timer) timerField.get(Minecraft.getMinecraft()); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static long getCoordinateRandom(int x, int y, int z) { + // MC 1.8 code... + long l = (x * 3129871) ^ z * 116129781L ^ y; + l = l * l * 42317861L + l * 11L; + return l; + } +} diff --git a/src/main/java/chanceCubes/util/RewardsUtil.java b/src/main/java/chanceCubes/util/RewardsUtil.java new file mode 100644 index 0000000..7dfa918 --- /dev/null +++ b/src/main/java/chanceCubes/util/RewardsUtil.java @@ -0,0 +1,128 @@ +package chanceCubes.util; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import chanceCubes.rewards.rewardparts.CommandPart; +import chanceCubes.rewards.rewardparts.EntityPart; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.ParticlePart; + +public class RewardsUtil { + + /** + * * + * + * @param xSize + * @param ySize + * @param zSize + * @param block + * @param xOff + * @param yOff + * @param zOff + * @param falling + * @param delay + * @param causeUpdate + * @param relativeToPlayer + * @return + */ + public static OffsetBlock[] fillArea(int xSize, int ySize, int zSize, Block block, int xOff, int yOff, int zOff, + boolean falling, int delay, boolean causeUpdate, boolean relativeToPlayer) { + List toReturn = new ArrayList(); + + for (int y = 0; y < ySize; y++) for (int z = 0; z < zSize; z++) for (int x = 0; x < xSize; x++) toReturn.add( + new OffsetBlock(x + xOff, y + yOff, z + zOff, block, falling, delay).setCausesBlockUpdate(causeUpdate) + .setRelativeToPlayer(relativeToPlayer)); + + return toReturn.toArray(new OffsetBlock[toReturn.size()]); + } + + public static OffsetBlock[] addBlocksLists(OffsetBlock[]... lists) { + int size = 0; + for (OffsetBlock[] list : lists) size += list.length; + + OffsetBlock[] toReturn = new OffsetBlock[size]; + + int i = 0; + for (OffsetBlock[] list : lists) { + for (OffsetBlock osb : list) { + toReturn[i] = osb; + i++; + } + } + + return toReturn; + } + + public static EntityPart[] spawnXEntities(NBTTagCompound entityNbt, int amount) { + EntityPart[] toReturn = new EntityPart[amount]; + for (int i = 0; i < amount; i++) toReturn[i] = new EntityPart(entityNbt); + return toReturn; + } + + public static CommandPart[] executeXCommands(String command, int amount) { + CommandPart[] toReturn = new CommandPart[amount]; + for (int i = 0; i < amount; i++) toReturn[i] = new CommandPart(command); + return toReturn; + } + + public static CommandPart[] executeXCommands(String command, int amount, int delay) { + CommandPart[] toReturn = new CommandPart[amount]; + for (int i = 0; i < amount; i++) { + CommandPart part = new CommandPart(command); + part.setDelay(delay); + toReturn[i] = part; + } + return toReturn; + } + + public static ParticlePart[] spawnXParticles(String particle, int amount) { + ParticlePart[] toReturn = new ParticlePart[amount]; + for (int i = 0; i < amount; i++) toReturn[i] = new ParticlePart(particle); + return toReturn; + } + + public static void sendMessageToNearPlayers(World world, int x, int y, int z, int distance, String message) { + for (int i = 0; i < world.playerEntities.size(); ++i) { + EntityPlayer entityplayer = (EntityPlayer) world.playerEntities.get(i); + double dist = Math.sqrt( + Math.pow(x - entityplayer.posX, 2) + Math.pow(y - entityplayer.posY, 2) + + Math.pow(z - entityplayer.posZ, 2)); + if (dist <= distance) entityplayer.addChatMessage(new ChatComponentText(message)); + } + } + + public static void sendMessageToAllPlayers(World world, String message) { + for (int i = 0; i < world.playerEntities.size(); ++i) { + EntityPlayer entityplayer = (EntityPlayer) world.playerEntities.get(i); + entityplayer.addChatMessage(new ChatComponentText(message)); + } + } + + public static boolean placeBlock(Block b, World world, int x, int y, int z) { + return RewardsUtil.placeBlock(b, world, x, y, z, 0); + } + + public static boolean placeBlock(Block b, World world, int x, int y, int z, int meta) { + return RewardsUtil.placeBlock(b, world, x, y, z, meta, 3); + } + + public static boolean placeBlock(Block b, World world, int x, int y, int z, int meta, int update) { + if (!RewardsUtil.isBlockUnbreakable(world, x, y, z)) { + world.setBlock(x, y, z, b, meta, update); + return true; + } + return false; + } + + public static boolean isBlockUnbreakable(World world, int x, int y, int z) { + return world.getBlock(x, y, z) + .getBlockHardness(world, x, y, z) == -1; + } +} diff --git a/src/main/java/chanceCubes/util/Scheduler.java b/src/main/java/chanceCubes/util/Scheduler.java new file mode 100644 index 0000000..c2495b7 --- /dev/null +++ b/src/main/java/chanceCubes/util/Scheduler.java @@ -0,0 +1,25 @@ +package chanceCubes.util; + +import java.util.ArrayList; +import java.util.List; + +public class Scheduler { + + private static List tasks = new ArrayList(); + + public static boolean scheduleTask(Task task) { + return tasks.add(task); + } + + public static void tickTasks() { + int numTasks = tasks.size(); + + for (int i = numTasks - 1; i >= 0; i--) { + Task task = tasks.get(i); + if (task.tickTask()) { + task.callback(); + tasks.remove(i); + } + } + } +} diff --git a/src/main/java/chanceCubes/util/SchematicUtil.java b/src/main/java/chanceCubes/util/SchematicUtil.java new file mode 100644 index 0000000..661cd16 --- /dev/null +++ b/src/main/java/chanceCubes/util/SchematicUtil.java @@ -0,0 +1,233 @@ +package chanceCubes.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; + +import chanceCubes.config.ConfigLoader; +import chanceCubes.rewards.rewardparts.OffsetBlock; +import chanceCubes.rewards.rewardparts.OffsetTileEntity; +import cpw.mods.fml.common.registry.GameData; +import cpw.mods.fml.common.registry.GameRegistry; + +public class SchematicUtil { + + private static Gson gson = new GsonBuilder().setPrettyPrinting() + .create(); + + public static Location3I[] selectionPoints = new Location3I[2]; + + public static void createCustomSchematic(World world, Location3I loc1, Location3I loc2, String fileName) { + List blocks = new ArrayList(); + List> blockDataIds = new ArrayList>(); + List>> tileEntityData = new ArrayList>>(); + int largeX = loc1.getX() > loc2.getX() ? loc1.getX() : loc2.getX(); + int smallX = loc1.getX() < loc2.getX() ? loc1.getX() : loc2.getX(); + int largeY = loc1.getY() > loc2.getY() ? loc1.getY() : loc2.getY(); + int smallY = loc1.getY() < loc2.getY() ? loc1.getY() : loc2.getY(); + int largeZ = loc1.getZ() > loc2.getZ() ? loc1.getZ() : loc2.getZ(); + int smallZ = loc1.getZ() < loc2.getZ() ? loc1.getZ() : loc2.getZ(); + for (int y = smallY; y < largeY; y++) { + for (int x = smallX; x < largeX; x++) { + for (int z = smallZ; z < largeZ; z++) { + Block b = world.getBlock(x, y, z); + String blockData = GameData.getBlockRegistry() + .getNameForObject(b); + blockData += ":" + world.getBlockMetadata(x, y, z); + int id = -1; + for (CustomEntry data : blockDataIds) { + if (blockData.equalsIgnoreCase(data.getValue())) { + id = data.getKey(); + } + } + if (id == -1) { + id = blockDataIds.size(); + blockDataIds.add(new CustomEntry(id, blockData)); + } + blocks.add(id); + + if (world.getTileEntity(x, y, z) != null) { + TileEntity te = world.getTileEntity(x, y, z); + NBTTagCompound nbt = new NBTTagCompound(); + te.writeToNBT(nbt); + for (CustomEntry> data : tileEntityData) { + if (nbt.toString() + .equalsIgnoreCase(data.getKey())) { + data.getValue() + .add(blocks.size() - 1); + break; + } + } + List list = new ArrayList(); + list.add(blocks.size() - 1); + tileEntityData.add(new CustomEntry>(nbt.toString(), list)); + } + } + } + } + + JsonObject json = new JsonObject(); + + JsonArray blockArray = new JsonArray(); + + for (int i : blocks) { + blockArray.add(new JsonPrimitive(i)); + } + + json.add("Blocks", blockArray); + + JsonArray blockDataArray = new JsonArray(); + for (CustomEntry i : blockDataIds) { + JsonObject index = new JsonObject(); + index.addProperty(i.getValue(), i.getKey()); + blockDataArray.add(index); + } + json.add("Block Data", blockDataArray); + + JsonArray tileEntityDataArray = new JsonArray(); + for (CustomEntry> i : tileEntityData) { + JsonObject index = new JsonObject(); + JsonArray tileEntityBlockIds = new JsonArray(); + for (int id : i.getValue()) tileEntityBlockIds.add(new JsonPrimitive(id)); + index.add(i.getKey(), tileEntityBlockIds); + tileEntityDataArray.add(index); + } + json.add("TileEntities", tileEntityDataArray); + + JsonObject info = new JsonObject(); + info.addProperty("xSize", largeX - smallX); + info.addProperty("ySize", largeY - smallY); + info.addProperty("zSize", largeZ - smallZ); + json.add("Schematic Data", info); + + FileUtil.writeToFile( + ConfigLoader.folder.getAbsolutePath() + "/CustomRewards/Schematics/" + fileName, + gson.toJson(json)); + } + + public static CustomSchematic loadCustomSchematic(String file, int xOffSet, int yOffSet, int zOffSet, float delay, + boolean falling, boolean relativeToPlayer) { + JsonElement elem = FileUtil + .readJsonfromFile(ConfigLoader.folder.getAbsolutePath() + "/CustomRewards/Schematics/" + file); + if (elem == null) return null; + JsonObject json = elem.getAsJsonObject(); + List offsetBlocks = new ArrayList(); + JsonObject info = json.get("Schematic Data") + .getAsJsonObject(); + int xSize = info.get("xSize") + .getAsInt(); + int ySize = info.get("ySize") + .getAsInt(); + int zSize = info.get("zSize") + .getAsInt(); + List> blockDataIds = new ArrayList>(); + + JsonArray blockDataArray = json.get("Block Data") + .getAsJsonArray(); + for (JsonElement i : blockDataArray) { + JsonObject index = i.getAsJsonObject(); + for (Entry obj : index.entrySet()) blockDataIds.add( + new CustomEntry( + obj.getValue() + .getAsInt(), + obj.getKey())); + } + + float delayTotal = 0; + int index = 0; + JsonArray blockArray = json.get("Blocks") + .getAsJsonArray(); + for (int yOff = 0; yOff < ySize; yOff++) { + for (int xOff = (xSize / 2) - xSize; xOff < (xSize / 2); xOff++) { + for (int zOff = (zSize / 2) - zSize; zOff < (zSize / 2); zOff++) { + JsonElement element = blockArray.get(index); + int id = element.getAsInt(); + String blockData = ""; + for (CustomEntry entry : blockDataIds) { + if (entry.getKey() == id) { + blockData = entry.getValue(); + break; + } + } + String[] dataParts = blockData.split(":"); + Block b = GameRegistry.findBlock(dataParts[0], dataParts[1]); + OffsetBlock osb = new OffsetBlock( + xOff + xOffSet, + yOff + yOffSet, + zOff + zOffSet, + b, + falling, + (int) delayTotal); + osb.setData(Byte.parseByte(dataParts[2])); + offsetBlocks.add(osb); + if (!b.equals(Blocks.air)) delayTotal += delay; + index++; + } + } + } + + JsonArray teArray = json.get("TileEntities") + .getAsJsonArray(); + for (JsonElement i : teArray) { + for (Entry obj : i.getAsJsonObject() + .entrySet()) { + String teData = obj.getKey(); + for (JsonElement ids : obj.getValue() + .getAsJsonArray()) { + int id = ids.getAsInt(); + OffsetBlock osb = offsetBlocks.get(id); + OffsetTileEntity oste = OffsetBlockToTileEntity(osb, teData); + if (oste != null) offsetBlocks.set(id, oste); + } + } + } + + for (int i = offsetBlocks.size() - 1; i >= 0; i--) { + OffsetBlock osb = offsetBlocks.get(i); + if (osb.getBlock() + .equals(Blocks.air)) offsetBlocks.remove(i); + } + + return new CustomSchematic(offsetBlocks, xSize, ySize, zSize, relativeToPlayer); + } + + public static OffsetTileEntity OffsetBlockToTileEntity(OffsetBlock osb, String nbt) { + try { + return OffsetBlockToTileEntity(osb, (NBTTagCompound) JsonToNBT.func_150315_a(nbt)); + } catch (NBTException e) { + e.printStackTrace(); + return null; + } + } + + public static OffsetTileEntity OffsetBlockToTileEntity(OffsetBlock osb, NBTTagCompound nbt) { + OffsetTileEntity oste = new OffsetTileEntity( + osb.xOff, + osb.yOff, + osb.zOff, + osb.getBlock(), + nbt, + osb.isFalling(), + osb.getDelay()); + oste.setData(osb.getData()); + oste.setDelay(osb.getDelay()); + oste.setRelativeToPlayer(osb.isRelativeToPlayer()); + oste.seFalling(osb.isFalling()); + return oste; + } +} diff --git a/src/main/java/chanceCubes/util/Task.java b/src/main/java/chanceCubes/util/Task.java new file mode 100644 index 0000000..fec4774 --- /dev/null +++ b/src/main/java/chanceCubes/util/Task.java @@ -0,0 +1,19 @@ +package chanceCubes.util; + +public abstract class Task { + + public String name; + public int delayLeft; + + public Task(String name, int delay) { + this.name = name; + this.delayLeft = delay; + } + + public abstract void callback(); + + public boolean tickTask() { + this.delayLeft--; + return this.delayLeft <= 0; + } +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/main/resources/assets/chancecubes/lang/en_US.lang b/src/main/resources/assets/chancecubes/lang/en_US.lang new file mode 100644 index 0000000..89e98a9 --- /dev/null +++ b/src/main/resources/assets/chancecubes/lang/en_US.lang @@ -0,0 +1,37 @@ +itemGroup.chancecubes=Chance Cubes + +tile.Chance_Cube.name=Chance Cube +item.Chance_Cube.name=Chance Cube +tile.Chance_Icosahedron.name=Chance Icosahedron +item.Chance_Icosahedron.name=Chance Icosahedron +tile.Giant_Chance_Cube.name=Giant Chance Cube +tile.Compact_Giant_Chance_Cube.name=Compact Giant Chance Cube +tile.Cube_Dispenser.name=Chance Cube Dispenser + +item.chancePendantTier1.name=Tier 1 Chance Pendant +item.chancePendantTier2.name=Tier 2 Chance Pendant +item.chancePendantTier3.name=Tier 3 Chance Pendant + +item.creativePendant.name=Creative Chance Pendant +item.rewardSelectorPendant.name=Reward Selector Pendant + +item.silkTouchPendant.name=Silk Touch Chance Pendant + +item.scanner.name=Chance Cube Scanner + +death.attack.mathdeath=%1$s's mind exploded from the power of math. +death.attack.mazedeath=%1$s was forever lost in the Chance Cube maze. +death.attack.questiondeath=%1$s suffered the consequences of the wrong answer. + +achievement.chancecubes.chanceIcosahedron=Disco Ball! +achievement.chancecubes.chanceIcosahedron.desc=Open a Chance Icosahedron +achievement.chancecubes.GiantChanceCube=BWWWWAAAAAMMMMM! +achievement.chancecubes.GiantChanceCube.desc=Break a Giant Chance Cube +achievement.chancecubes.lonelyDirt=Lonely Dirt +achievement.chancecubes.lonelyDirt.desc=Obtain the Lonely Piece of Dirt +achievement.chancecubes.wither=It's Real?? +achievement.chancecubes.wither.desc=Have the Kiwi wither actually spawn +achievement.chancecubes.herobrine=He's Real?? +achievement.chancecubes.herobrine.desc=Have the Herobrine actually spawn +achievement.chancecubes.itsALie=It's a Lie! +achievement.chancecubes.itsALie.desc=Yes, the cake is a lie \ No newline at end of file diff --git a/src/main/resources/assets/chancecubes/lang/zh_CN.lang b/src/main/resources/assets/chancecubes/lang/zh_CN.lang new file mode 100644 index 0000000..7805a67 --- /dev/null +++ b/src/main/resources/assets/chancecubes/lang/zh_CN.lang @@ -0,0 +1,37 @@ +itemGroup.chancecubes=Chance Cubes + +tile.Chance_Cube.name=机会方块 +item.Chance_Cube.name=机会方块 +tile.Chance_Icosahedron.name=机会二十面体 +item.Chance_Icosahedron.name=机会二十面体 +tile.Giant_Chance_Cube.name=巨型机会方块 +tile.Compact_Giant_Chance_Cube.name=紧凑巨型机会方块 +tile.Cube_Dispenser.name=机会方块分配器 + +item.chancePendantTier1.name=一级机会项坠 +item.chancePendantTier2.name=二级机会项坠 +item.chancePendantTier3.name=三级机会项坠 + +item.creativePendant.name=创造机会项坠 +item.rewardSelectorPendant.name=奖励选择项坠 + +item.silkTouchPendant.name=精准采集机会项坠 + +item.scanner.name=机会方块扫描仪 + +death.attack.mathdeath=%1$s的意志被数学的力量爆炸了。 +death.attack.mazedeath=%1$s永远的迷失在了机会方块里面。 +death.attack.questiondeath=%1$s承受了错误答案的后果。 + +achievement.chancecubes.chanceIcosahedron=迪斯科球! +achievement.chancecubes.chanceIcosahedron.desc=打开一个机会二十面体 +achievement.chancecubes.GiantChanceCube=BWWWWAAAAAMMMMM! +achievement.chancecubes.GiantChanceCube.desc=打破一个巨型机会方块 +achievement.chancecubes.lonelyDirt=孤独的泥土 +achievement.chancecubes.lonelyDirt.desc=获得一块孤独的泥土 +achievement.chancecubes.wither=这是真的么?? +achievement.chancecubes.wither.desc=生成一个kiwi凋零 +achievement.chancecubes.herobrine=他是真的?? +achievement.chancecubes.herobrine.desc=生成一个Herobrine +achievement.chancecubes.itsALie=这是谎言! +achievement.chancecubes.itsALie.desc=是的,蛋糕是个谎言 \ No newline at end of file diff --git a/src/main/resources/assets/chancecubes/models/blocks/d20.obj b/src/main/resources/assets/chancecubes/models/blocks/d20.obj new file mode 100644 index 0000000..d00a65e --- /dev/null +++ b/src/main/resources/assets/chancecubes/models/blocks/d20.obj @@ -0,0 +1,39 @@ +# Blender v2.73 (sub 0) OBJ File: '' +# www.blender.org +o Icosphere +v 0.000000 -0.625000 -0.000000 +v 0.452250 -0.279509 0.328575 +v -0.172741 -0.279509 0.531650 +v 0.452250 -0.279509 -0.328575 +v -0.559015 -0.279509 -0.000000 +v -0.172741 -0.279509 -0.531650 +v 0.559015 0.279509 0.000000 +v 0.172741 0.279509 0.531650 +v -0.452250 0.279509 0.328575 +v -0.452250 0.279509 -0.328575 +v 0.172741 0.279509 -0.531650 +v 0.000000 0.625000 0.000000 +vt 0.500000 1.000000 +vt -0.000000 0.000000 +vt 1.000000 0.000000 +s off +f 1/1 2/2 3/3 +f 2/3 1/1 4/2 +f 1/1 3/2 5/3 +f 1/1 5/2 6/3 +f 1/1 6/2 4/3 +f 2/2 4/3 7/1 +f 3/2 2/3 8/1 +f 5/2 3/3 9/1 +f 6/2 5/3 10/1 +f 4/2 6/3 11/1 +f 2/1 7/2 8/3 +f 3/1 8/2 9/3 +f 5/1 9/2 10/3 +f 6/1 10/2 11/3 +f 4/1 11/2 7/3 +f 8/2 7/3 12/1 +f 9/2 8/3 12/1 +f 10/2 9/3 12/1 +f 11/2 10/3 12/1 +f 7/2 11/3 12/1 diff --git a/src/main/resources/assets/chancecubes/schematics/house.schematic b/src/main/resources/assets/chancecubes/schematics/house.schematic new file mode 100644 index 0000000..62bbe07 Binary files /dev/null and b/src/main/resources/assets/chancecubes/schematics/house.schematic differ diff --git a/src/main/resources/assets/chancecubes/sounds.json b/src/main/resources/assets/chancecubes/sounds.json new file mode 100644 index 0000000..4e9a756 --- /dev/null +++ b/src/main/resources/assets/chancecubes/sounds.json @@ -0,0 +1,4 @@ +{ + "d20_Break": {"catagory": "master", "sounds": [{"name": "d20_Break", "stream": false}]}, + "giant_Cube_Spawn": {"catagory": "master", "sounds": [{"name": "giant_Cube_Spawn", "stream": false}]} +} \ No newline at end of file diff --git a/src/main/resources/assets/chancecubes/sounds/d20_Break.ogg b/src/main/resources/assets/chancecubes/sounds/d20_Break.ogg new file mode 100644 index 0000000..b1583a1 Binary files /dev/null and b/src/main/resources/assets/chancecubes/sounds/d20_Break.ogg differ diff --git a/src/main/resources/assets/chancecubes/sounds/giant_Cube_Spawn.ogg b/src/main/resources/assets/chancecubes/sounds/giant_Cube_Spawn.ogg new file mode 100644 index 0000000..d72d330 Binary files /dev/null and b/src/main/resources/assets/chancecubes/sounds/giant_Cube_Spawn.ogg differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCube.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCube.png new file mode 100644 index 0000000..d50260e Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCube.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_1.png new file mode 100644 index 0000000..300842e Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_2.png new file mode 100644 index 0000000..42df29a Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_3.png new file mode 100644 index 0000000..d8cb9a7 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_4.png new file mode 100644 index 0000000..4258249 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_5.png new file mode 100644 index 0000000..c792ef2 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_6.png new file mode 100644 index 0000000..54c80e2 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeEaster_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_1.png new file mode 100644 index 0000000..2338cc8 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_2.png new file mode 100644 index 0000000..c42166d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_3.png new file mode 100644 index 0000000..c42166d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_4.png new file mode 100644 index 0000000..c42166d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_5.png new file mode 100644 index 0000000..c42166d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_6.png new file mode 100644 index 0000000..2338cc8 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHalloween_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_1.png new file mode 100644 index 0000000..3818a2b Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_2.png new file mode 100644 index 0000000..c225999 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_3.png new file mode 100644 index 0000000..c225999 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_4.png new file mode 100644 index 0000000..c225999 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_5.png new file mode 100644 index 0000000..c225999 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_6.png new file mode 100644 index 0000000..3818a2b Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeHolidays_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_1.png new file mode 100644 index 0000000..cd51cd5 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_2.png new file mode 100644 index 0000000..6e86dd7 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_3.png new file mode 100644 index 0000000..1a623e5 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_4.png new file mode 100644 index 0000000..880b8cc Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_5.png new file mode 100644 index 0000000..2944c31 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_6.png new file mode 100644 index 0000000..40a9d4b Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeStPatricks_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_1.png new file mode 100644 index 0000000..70ce1b1 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_2.png new file mode 100644 index 0000000..6bd38cc Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_3.png new file mode 100644 index 0000000..7044aa7 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_4.png new file mode 100644 index 0000000..360a551 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_5.png new file mode 100644 index 0000000..052c1ef Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_6.png new file mode 100644 index 0000000..0e64af2 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chanceCubeValentines_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_1.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_1.png new file mode 100644 index 0000000..217a9b0 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_2.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_2.png new file mode 100644 index 0000000..2586637 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_3.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_3.png new file mode 100644 index 0000000..baaafe5 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_4.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_4.png new file mode 100644 index 0000000..98591ee Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_5.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_5.png new file mode 100644 index 0000000..56d3036 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_5.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_6.png b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_6.png new file mode 100644 index 0000000..671bdaf Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/chancecube_face_6.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Side.png b/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Side.png new file mode 100644 index 0000000..212f0b9 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Side.png differ diff --git a/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Top.png b/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Top.png new file mode 100644 index 0000000..de40913 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/blocks/cubeDispenser_Top.png differ diff --git a/src/main/resources/assets/chancecubes/textures/gui/container/guiCreativePendant.png b/src/main/resources/assets/chancecubes/textures/gui/container/guiCreativePendant.png new file mode 100644 index 0000000..1053c86 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/gui/container/guiCreativePendant.png differ diff --git a/src/main/resources/assets/chancecubes/textures/gui/container/guiRewardSelectorPendant.png b/src/main/resources/assets/chancecubes/textures/gui/container/guiRewardSelectorPendant.png new file mode 100644 index 0000000..e2d7843 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/gui/container/guiRewardSelectorPendant.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/PendantT1.png b/src/main/resources/assets/chancecubes/textures/items/PendantT1.png new file mode 100644 index 0000000..9332264 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/PendantT1.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/PendantT2.png b/src/main/resources/assets/chancecubes/textures/items/PendantT2.png new file mode 100644 index 0000000..19d300d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/PendantT2.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/PendantT3.png b/src/main/resources/assets/chancecubes/textures/items/PendantT3.png new file mode 100644 index 0000000..073080d Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/PendantT3.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/PendantT4.png b/src/main/resources/assets/chancecubes/textures/items/PendantT4.png new file mode 100644 index 0000000..d6206ab Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/PendantT4.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/creativePendant.png b/src/main/resources/assets/chancecubes/textures/items/creativePendant.png new file mode 100644 index 0000000..823efcc Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/creativePendant.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/rewardSelectorPendant.png b/src/main/resources/assets/chancecubes/textures/items/rewardSelectorPendant.png new file mode 100644 index 0000000..b0c773c Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/rewardSelectorPendant.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/scanner.png b/src/main/resources/assets/chancecubes/textures/items/scanner.png new file mode 100644 index 0000000..177e9f5 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/scanner.png differ diff --git a/src/main/resources/assets/chancecubes/textures/items/silkTouchPendant.png b/src/main/resources/assets/chancecubes/textures/items/silkTouchPendant.png new file mode 100644 index 0000000..2699c0e Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/items/silkTouchPendant.png differ diff --git a/src/main/resources/assets/chancecubes/textures/models/d20.png b/src/main/resources/assets/chancecubes/textures/models/d20.png new file mode 100644 index 0000000..2daf417 Binary files /dev/null and b/src/main/resources/assets/chancecubes/textures/models/d20.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..ea50c75 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,19 @@ +{ + "modListVersion": 2, + "modList": [ + { + "modid": "${modId}", + "name": "${modName}", + "description": "A Game of Chance and Skill", + "version": "${modVersion}", + "mcversion": "${minecraftVersion}", + "url": "https://github.com/Project-Diana/ChanceCubes", + "updateUrl": "", + "authorList": ["Turkey2349"], + "credits": "Funwayguy for the Icosahderon model and awesome rendering effects! https://twitter.com/Funwayguy", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } + ] +}