diff --git a/.gitignore b/.gitignore index 1a768f054..d00d9cd16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ # Dependencies -/node_modules +node_modules/ # Production /build -/src/pages/api /innercore*-docs.pdf # Generated files diff --git a/.vscode/settings.json b/.vscode/settings.json index ed25a758b..b04e26dc1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,16 @@ { - "editor.defaultFormatter": "esbenp.prettier-vscode", "markdown.preferredMdPathExtensionStyle": "removeExtension", "markdown.validate.enabled": true, - "mdx.experimentalLanguageServer": true, + "markdown.validate.ignoredLinks": [ + "/images/**/*" + ], "search.exclude": { "**/node_modules": true, "**/package-lock.json": true, "**/.wireit": true, "**/build": true + }, + "[markdown]": { + "editor.defaultFormatter": "DavidAnson.vscode-markdownlint" } } diff --git a/README.md b/README.md index 089110419..c67085096 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,6 @@ I mean modding documentation for Inner Core of course, rewrited from zero to Typ Everything divided by categories, which also represents sidebar structure. Every markdown location described in **sidebars.js**, you can use it for auto-generation or manually provide required routes. -## API Reference - -New era of Core Engine documentation, generated into single webpage like everything here. See [Nernar/API](https://github.com/Nernar/API) repository for details. - -## Modding Examples - -Here represented most of legendary Core Engine mods with unique mechanics, that you can freely take into your content. - ## Libraries freely to use At beginning, it located by few locations: **libraries** where everything starts, **i18n** where localization performs and **static** where additional files is located. diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 000000000..18088f8a0 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,6 @@ +# Production +docs/ + +# Generated files +/declarations/core-engine.d.ts +/.wireit diff --git a/api/LICENSE b/api/LICENSE new file mode 100644 index 000000000..672f9658b --- /dev/null +++ b/api/LICENSE @@ -0,0 +1,924 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Inner Core API: Core Engine API Reference + Copyright (C) 2022 Nernar (https://github.com/nernar) + + 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 . + + Maintained and distributed by MaXFeeD (maxfeed.nernar@outlook.com) + +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: + + Inner Core API Copyright (C) 2022 Nernar (https://github.com/nernar) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + +--- + + This is the official Core Engine documentation repository + Copyright (C) 2020 #mineprogramming (https://github.com/mineprogramming) + + 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 . + + Distributed by IchZerowan and contributors (https://github.com/mineprogramming/innercore-docs) + +--- + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 Google Inc. + + 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. + +--- + +MIT License + +Copyright (c) Microsoft Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/api/core-engine/ActorRenderer.d.ts b/api/core-engine/ActorRenderer.d.ts new file mode 100644 index 000000000..654f2dc10 --- /dev/null +++ b/api/core-engine/ActorRenderer.d.ts @@ -0,0 +1,86 @@ +/** + * Class, upon which armor and attachments render is based + * It is a model that consists of parts, same as in {@link Render}, + * but more abstract, allows creating root parts instead of + * inheritance from old humanoid model. + * @since 2.2.0b75 + */ +declare class ActorRenderer { + /** + * Constructs new {@link ActorRenderer} object without parts. + */ + constructor(); + + /** + * Constructs new {@link ActorRenderer} object, + * based on one of default Minecraft render templates. + * @param templateName default template name + */ + constructor(templateName: DefaultRenderTemplate); + + getUniformSet(): ShaderUniformSet; + + setTexture(textureName: string): void; + + setMaterial(materialName: string): void; + + getPart(name: string): ActorRenderer.ModelPart; + + /** + * Adds a child model part of an existing one. + * @param name child model name + * @param parentName parent model name + */ + addPart(name: string, parentName: string, mesh?: RenderMesh): ActorRenderer.ModelPart; + + /** + * Adds a root model part. + */ + addPart(name: string, mesh?: RenderMesh): ActorRenderer.ModelPart; + +} + +declare namespace ActorRenderer { + + /** + * All methods of {@link ActorRenderer.ModelPart} build in such a way, + * that you can create full render in one chain of calls. + * @example + * ```js + * new ActorRenderer() + * .addPart("child", "parent") + * .addBox(-4, -4, -4, 4, 0, 4) + * .addPart("grandChild", "child") + * .addBox(-4, 0, -4, 4, 4, 4) + * .setOffset(0, 4, 0) + * .endPart(); + * ``` + */ + class ModelPart { + + endPart(): ActorRenderer; + + setTexture(textureName: string): ModelPart; + + setMaterial(materialName: string): ModelPart; + + setTextureSize(w: number, h: number): ModelPart; + + setOffset(x: number, y: number, z: number): ModelPart; + + setRotation(x: number, y: number, z: number): ModelPart; + + setPivot(x: number, y: number, z: number): ModelPart; + + setMirrored(isMirrored: boolean): ModelPart; + + /** + * @param inflate increases the box by a certain value in all directions + */ + addBox(x: number, y: number, z: number, sizeX: number, sizeY: number, sizeZ: number, inflate: number, u: number, v: number): ModelPart; + + clear(): ModelPart; + + } + +} \ No newline at end of file diff --git a/api/core-engine/AddonEntityRegistry.d.ts b/api/core-engine/AddonEntityRegistry.d.ts new file mode 100644 index 000000000..fda86d745 --- /dev/null +++ b/api/core-engine/AddonEntityRegistry.d.ts @@ -0,0 +1,48 @@ +/** + * Module used to manage custom entities added via add-ons. + * @since 2.0.1b18 + * @remarks + * Depends on local player dimension, highly recommended to replace it + * with {@link BlockSource.spawnEntity} and {@link Entity.getTypeName}. + */ +declare namespace AddonEntityRegistry { + /** + * Spawns an entity defined via add-on on the specified coordinates. + * @param nameID entity name ID, as defined from add-on + * @deprecated Client-side method, use {@link BlockSource.spawnEntity} instead. + */ + function spawn(x: number, y: number, z: number, nameID: string): number; + + /** + * Added entities stores in registry, so already spawned entity + * data may resolved again by requesting information by UID. + * @returns Add-on entity information by entity ID. + */ + function getEntityData(entity: number): AddonEntity; + + interface AddonEntity { + /** + * Entity unique ID. + */ + readonly id: number, + + /** + * Add-on defined entity name ID. + */ + readonly type: string, + + /** + * Executes command with the entity. + * @param command command to be executed + * @returns Error message or null if the command was run successfully. + */ + exec(command: string): Nullable; + + /** + * Executes command with the entity on the specified coordinates. + * @param command command to be executed + * @returns Error message or null if the command was run successfully. + */ + execAt(command: string, x: number, y: number, z: number): Nullable; + } +} diff --git a/api/core-engine/Animation.d.ts b/api/core-engine/Animation.d.ts new file mode 100644 index 000000000..b4dd3e253 --- /dev/null +++ b/api/core-engine/Animation.d.ts @@ -0,0 +1,258 @@ +/** + * Animations are used to display some 3d models in the world without use of + * entities. + * @remarks + * Rendering performs locally in client-side, use packets to transfer + * data between server and players. + */ +declare namespace Animation { + /** + * Base animations are used to display arbitrary model in the world. + */ + class Base { + /** + * Constructs a new Base animation on the specified coordinates. + */ + constructor(x: number, y: number, z: number); + + /** + * Changes the animation's position. + */ + setPos(x: number, y: number, z: number): void; + + /** + * @param enabled if true, animation position will be interpolated + * between tick calls + */ + setInterpolationEnabled(enabled: boolean): void; + + /** + * @deprecated Use {@link Animation.Base.setBlockLightPos setBlockLightPos} and related methods instead. + */ + setIgnoreBlocklight(ignore: boolean): void; + + /** + * Sets specified coordinates as light measuring position for the + * animation. In other words, animation lightning will be calculated + * as if animation was at the specified coordinates. + */ + setBlockLightPos(x: number, y: number, z: number): void; + + /** + * Resets light measuring position for the animation (to it's coordinates). + */ + resetBlockLightPos(): void; + + /** + * Sets light measuring position to always match day/night lightning, + * even when the animation is not directly illuminated. + */ + setSkylightMode(): void; + + /** + * Sets light measuring to match the animation coordinated. + */ + setBlocklightMode(): void; + + /** + * Makes the animation ignore light at all. + */ + setIgnoreLightMode(): void; + + /** + * @returns Object for current animation's render. + */ + transform(): Render.Transform; + + /** + * @returns Object for current animation's render. + * @since 2.0.2b20 + */ + getShaderUniforms(): ShaderUniformSet; + + /** + * Creates a set of transformations for the current animation. + * @param transformations + * @param noClear + */ + newTransform(transformations: { + /** + * Transformation function name, one of {@link Render.Transform} class member + * functions names. + */ + name: string, + /** + * Transformation function parameters, see {@link Render.Transform} functions + * for details. + */ + params: any[] + }[], noClear: boolean): void; + + /** + * Creates render if it was not previously created and applies all the + * parameters from animation description. + */ + createRenderIfNeeded(): void; + + /** + * Refreshes the animation. + */ + updateRender(): void; + + /** + * Loads animation in the world. + */ + load(): void; + + /** + * Loads animation in the world registering it as an {@link Updatable}. + * @param func function to be used as {@link Updatable.update} function + * @since 2.3.1b116 (client-side) + */ + loadCustom(func: () => void): void; + + /** + * @deprecated Backwards compatibility, render doesn't have attributes. + */ + getAge(): void; + + /** + * Refreshes the animation. + */ + refresh(): void; + + /** + * Describes animation parameters for the future use. Call {@link Animation.Base.load load} or + * {@link Animation.Base.loadCustom loadCustom} to actually launch the animation. + * @param description an object containing all the required data about + * animation + */ + describe(description: { + /** + * {@link RenderMesh} object to be displayed with animation. + * @since 2.0.2b20 + */ + mesh?: RenderMesh, + /** + * Numeric ID of the {@link Render} object to be displayed with animation. + * Can be obtained using {@link Render.getId} + */ + render?: number, + /** + * Name of the texture to be used as render's skin. + */ + skin?: string, + /** + * Animation scale. + * @default 1 + */ + scale?: number, + /** + * Animation material, can be used to apply custom materials to the + * animation. + * @since 2.0.2b20 + */ + material?: string + }): void; + + /** + * Destroys animation and releases all the resources. + */ + destroy(): void; + + /** + * @since 2.1.0b60 + */ + exists(): boolean; + } + + /** + * Item animations are used to display items or blocks models in the world. + */ + class Item extends Base { + /** + * Constructs a new Item animation on the specified coordinates. + */ + constructor(x: number, y: number, z: number); + + /** + * Describes item to be used for the animation. + * @param item item parameters object + */ + describeItem(item: { + /** + * Item ID. + */ + id: number, + /** + * Item count, will be transform to display an appropriate animation. + */ + count?: number, + /** + * Item data. + */ + data?: number, + /** + * Item extra. + */ + extra?: ItemExtraData, + /** + * Whether the item should be in glint state or not. + */ + glint?: boolean, + /** + * Item/block size. + * @default 0.5 + */ + size?: number, + /** + * If `true`, the position of the item will not be randomized. + */ + notRandomize?: boolean, + /** + * If string "x" is passed, the item is rotated 90 along x axis, if + * "z" is passed, the item is rotated 90 along z axis, otherwise the + * item is rotated according to the rotation array along all the three + * axes. + */ + rotation?: string | [number, number, number], + /** + * Skin name to be used for the render. If no skin is passed, default + * item skin is used. + */ + skin?: string, + /** + * Shader material name. + * @since 2.0.2b20 + */ + material?: string + }): void; + + /** + * @deprecated Consider using {@link Animation.Item.describeItem describeItem} instead. + */ + describeItemDefault(item: any): void; + + /** + * Resets all the transformations made via {@link Animation.Base.transform transform} calls. + */ + resetTransform(): void; + + /** + * Specifies item rotation along the three axes. + * @default x: 0, y: 0, z: 0 + */ + setItemRotation(x: number, y: number, z: number): void; + + /** + * Specifies item size. + * @default 0.5 + */ + setItemSize(size: number): void; + + /** + * Specifies item size and rotation via single function call. + */ + setItemSizeAndRotation(size: number, x: number, y: number, z: number): void; + } +} diff --git a/api/core-engine/Armor.d.ts b/api/core-engine/Armor.d.ts new file mode 100644 index 000000000..cb5542792 --- /dev/null +++ b/api/core-engine/Armor.d.ts @@ -0,0 +1,129 @@ +/** + * Module used to manage armor's behavior. + */ +declare namespace Armor { + + interface IArmorHurtParams { + /** + * Attacker entity or -1 if the damage was not + * caused by an entity. + */ + attacker: number; + /** + * Damage amount that was applied to the player. + */ + damage: number; + /** + * Damage type. + */ + type: number; + /** + * TODO: Unknown param! + */ + bool1: boolean; + /** + * TODO: Unknown param! + */ + bool2: boolean; + } + + interface IArmorJSCallback { + /** + * Called every tick if player wears the armor. + * @param slot current armor item instance + * @param index armor slot, one of the {@link EArmorType} values + * @param durability maximum damage the armor + * @returns `true`, if changes to the item parameter should be applied, + * `false` otherwise. + */ + tick(slot: ItemInstance, index: number, durability: number): boolean; + + /** + * Called when player deals damage if player wears the armor. + * @param params additional data about damage + * @param slot current armor item instance + * @param index armor slot, one of the {@link EArmorType} values + * @param durability maximum damage the armor + * @returns `true`, if changes to the item parameter should be applied, + * `false` otherwise. + */ + hurt(params: IArmorHurtParams, slot: ItemInstance, index: number, durability: number): boolean; + } + + /** + * Registers armor's hurt and tick functions. + * @param id armor item string or numeric ID + * @param funcs + * @deprecated Use multiplayer {@link Armor.registerOnHurtListener} and + * anothers or callbacks. + */ + function registerFuncs(id: number | string, funcs: Armor.IArmorJSCallback): void; + + /** + * Prevents armor from being damaged. + * @param id armor item string or numeric ID + */ + function preventDamaging(id: number | string): void; + + interface ArmorGeneralFunction { + (item: ItemInstance, slot: number, player: number): void + } + + /** + * This event is called every tick for every player that has this armor put on. + * @returns Item object to change armor item, if nothing is returned, + * armor will not be changed. + */ + function registerOnTickListener(id: number, func: ArmorGeneralFunction): void; + + /** + * This event is called every tick for local player that has this armor put on. + * @returns Item object to change armor item, if nothing is returned, + * armor will not be changed. + * @since 2.2.1b106 + */ + function registerOnLocalTickListener(id: number, func: ArmorGeneralFunction): void; + + interface ArmorHurtFunction { + (item: ItemInstance, slot: number, player: number, value: number, type: number, attacker: number, bool1: boolean, bool2: boolean): void + } + + /** + * This event is called when the damage is dealt to the player that has this armor put on. + * @returns Item object to change armor item, if nothing is returned, + * armor will not be changed. + */ + function registerOnHurtListener(id: number, func: ArmorHurtFunction): void; + + /** + * This event is called when player takes on this armor, or spawns with it. + */ + function registerOnTakeOnListener(id: number, func: ArmorGeneralFunction): void; + + /** + * This event is called when local player takes on this armor, or spawns with it. + * @since 2.2.1b106 + */ + function registerLocalOnTakeOnListener(id: number, func: ArmorGeneralFunction): void; + + /** + * This event is called when player takes off or changes this armor item. + */ + function registerOnTakeOffListener(id: number, func: ArmorGeneralFunction): void; + + /** + * This event is called when local player takes off or changes this armor item. + * @since 2.2.1b106 + */ + function registerLocalOnTakeOffListener(id: number, func: ArmorGeneralFunction): void; + + interface IArmorCallback { + tick(slot: ItemInstance, index: number, armorInfo: Armor.IArmorInfo): boolean; + hurt(params: IArmorHurtParams, slot: ItemInstance, index: number, armorInfo: Armor.IArmorInfo): boolean; + } + + interface IArmorInfo { + callback: IArmorCallback; + durability: number; + } +} diff --git a/api/core-engine/AttachableRender.d.ts b/api/core-engine/AttachableRender.d.ts new file mode 100644 index 000000000..2b2d296ef --- /dev/null +++ b/api/core-engine/AttachableRender.d.ts @@ -0,0 +1,33 @@ +/** + * Class used to attach attachables to entities. + * @since 2.2.0b75 + */ +declare class AttachableRender { + + static attachRendererToItem(id: number, renderer: AttachableRender, texture?: string, material?: string): void; + + static detachRendererFromItem(id: number): void; + + /** + * Constructs new {@link AttachableRender} object bind to given entity. + */ + constructor(actorUid: number); + + getUniformSet(): ShaderUniformSet; + + /** + * Sets the render, root render parts will be drawing + * together with mob's render parts with same names + * (names can be seen in json description of the model in resources). + */ + setRenderer(actorRenderer: ActorRenderer): AttachableRender; + + setTexture(textureName: string): AttachableRender; + + setMaterial(materialName: string): AttachableRender; + + destroy(): void; + + isAttached(): boolean; + +} \ No newline at end of file diff --git a/api/core-engine/Block.d.ts b/api/core-engine/Block.d.ts new file mode 100644 index 000000000..a7aba1501 --- /dev/null +++ b/api/core-engine/Block.d.ts @@ -0,0 +1,853 @@ +/** + * Module used to create and manipulate blocks. The difference between terms + * "block" and "tile" is in it's usage: blocks are used in the inventory, + * tiles are placed in the world and have different IDs for some vanilla blocks. + * Use {@link Block.convertBlockToItemId} and {@link Block.convertItemToBlockId} + * to perform conversion between block and it item variation. + */ +declare namespace Block { + /** + * @param id string ID of the block + * @returns Block numeric ID by it's string ID or just returns it's numeric ID + * if input was a numeric ID. + */ + function getNumericId(id: string | number): number; + + /** + * Creates new block using specified params. + * @param nameID string ID of the block. You should register it via + * {@link IDRegistry.genBlockID} call first + * @param defineData array containing all variations of the block. Each + * variation corresponds to block data value, data values are assigned + * according to variations order + * @param blockType {@link Block.SpecialType} object, either java-object returned by + * {@link Block.createSpecialType} or js-object with the required properties, + * you can also pass special type name, if the type was previously + * registered + */ + function createBlock(nameID: string, defineData: BlockVariation[], blockType?: SpecialType | string): void; + + /** + * Creates new block using specified params, creating four variations for + * each of the specified variations to be able to place it facing flayer + * with the front side and defines the appropriate behavior. Useful for + * different machines and mechanisms. + * @param nameID string ID of the block. You should register it via + * {@link IDRegistry.genBlockID} call first + * @param defineData array containing all variations of the block. Each + * variation corresponds to four block data values, data values are assigned + * according to variations order + * @param blockType {@link Block.SpecialType SpecialType} object, either java-object returned by + * {@link Block.createSpecialType} or js-object with the required properties, + * you can also pass special type name, if the type was previously + * registered + */ + function createBlockWithRotation(nameID: string, defineData: BlockVariation[], blockType?: SpecialType | string): void; + + /** + * Object used to represent single block variation. + */ + interface BlockVariation { + /** + * Variation name, displayed as item name everywhere. + * @default "Unknown Block" + */ + name?: string, + /** + * Variation textures, array containing pairs of texture name and data. + * Texture file should be located in items-opaque folder and it's name + * should be in the format: `"name_data"`, e.g. if the file name is + * `"ingot_copper_0"`, you should specify an array `["ingot_copper", 0]`. + * @remarks + * There should be from one to six texture pairs in the array, + * if less then six variations are specified, the last texture is used + * for missing textures. The sides go in the following order: + * ```js + * texture: [ + * ["name1", index1], // bottom (Y: -1) + * ["name2", index2], // top (Y: +1) + * ["name3", index3], // back (X: -1) + * ["name4", index4], // front (X: +1) + * ["name5", index5], // left (Z: -1) + * ["name6", index6] // right (Z: +1) + * ] + * ``` + */ + texture: [string, number][], + /** + * If `true`, block variation will be added to creative inventory. + * @default false + */ + inCreative?: boolean + } + + /** + * Creates new liquid block using specified params. + * @param nameID string ID of the block. You should register it via + * {@link IDRegistry.genBlockID} call first + * @param defineData object containing all needed params to describe your custom liquid block. + * There you can specify custom name IDs for static and dynamic liquid blocks separately, + * and if you do this, you have to register those name IDs + * via {@link IDRegistry.genBlockID} before using them + * @param blockType {@link Block.SpecialType SpecialType} object, either java-object returned by + * {@link Block.createSpecialType} or js-object with the required properties, + * you can also pass special type name, if the type was previously registered + * @since 2.2.1b102 + */ + function createLiquidBlock(nameID: string, defineData: LiquidDescriptor, blockType?: SpecialType | string): void; + + /** + * Object to specify needed params for custom liquid block. + * @since 2.2.1b102 + */ + interface LiquidDescriptor { + /** + * Name of the block to be displayed. + */ + name: string, + /** + * Delay between liquid spreading steps in ticks. + * @default 10 + */ + tickDelay?: number, + /** + * True if the liquid will be renewable, as water. + * @default false + * @since 2.2.1b103 + */ + isRenewable?: boolean, + /** + * Object to describe static liquid block + * texture, and name ID additionally. + */ + still: { + /** + * Optional, name ID for static liquid block. + * @default "nameId_still" + */ + id?: string, + /** + * For static liquid block, + * textures must be of standard block texture format. + */ + texture: [string, number] + }, + /** + * Object to describe dynamic liquid block + * texture, and name ID additionally. + */ + flowing: { + /** + * Optional, name ID for dynamic liquid block. + * @default "nameId" + */ + id?: string, + /** + * Unlike static liquid blocks, + * for dynamic ones, texture must look like + * `"texture.liquid.png"` (with no index). + */ + texture: [string, number] + }, + /** + * Optional section, if added, this will create fully + * functional (including dispensers) bucket items. + * @since 2.2.1b103 + */ + bucket?: { + /** + * Optional, name ID for bucket item. + * @default "nameId_bucket" + */ + id?: string, + /** + * Name of the filled with liquid bucket to be displayed. + */ + name?: string, + texture: { name: string, meta?: number }, + /** + * An item that can capture liquid (including when using + * a dispenser and obtaining it with your hand). + * @default 325 + * @since 2.3.1b116 + */ + emptyId?: number, + /** + * @default "bucket.fill_water" + */ + fillSound?: string, + /** + * @default "bucket.empty_water" + */ + emptySound?: string, + /** + * If `true`, bucket cannot be obtained from creative inventory. + */ + isTech?: boolean + }, + /** + * Whether to add liquid block to creative inventory. + * @default false + */ + inCreative?: boolean, + uiTextures?: string, + modelTextures?: string + } + + /** + * @param id numeric block ID + * @returns `true`, if the specified block ID is a vanilla block. + */ + function isNativeTile(id: number): boolean; + + /** + * Converts tile ID to the block ID. + * @param id numeric tile ID + * @returns Numeric block ID corresponding to the given tile ID. + */ + function convertBlockToItemId(id: number): number; + + /** + * Converts block ID to the tile ID. + * @param id numeric tile ID + * @returns Numeric tile ID corresponding to the given block ID. + */ + function convertItemToBlockId(id: number): number; + + /** + * Defines custom behavior when the player clicks on the block with definite ID. + * @param numericId block's numeric ID + * @param func function that will be called when the player clicks the block with given ID + * @since 2.2.1b103 (TODO: changelog says it 104) + */ + function registerClickFunctionForID(numericId: number, func: ClickFunction): void; + + /** + * Defines custom behavior when the player clicks on the block with definite ID. + * @param id block's numeric or string ID + * @param func function that will be called when the player clicks the block with given ID + * @since 2.2.1b103 (TODO: changelog says it 104) + */ + function registerClickFunction(id: string | number, func: ClickFunction): void; + + /** + * Function used to define how the block will behave when the player clicks on it. + * @param coords set of all coordinate values that can be useful to write + * custom logics on click + * @param item item that was in the player's hand when he touched the block + * @param block block that was touched + * @param player unique ID of the player entity + */ + interface ClickFunction { + (coords: Callback.ItemUseCoordinates, item: ItemInstance, block: Tile, player: number): void; + } + + /** + * Registers function used by Core Engine to determine block drop for the + * specified block ID. + * @param numericId tile numeric ID + * @param dropFunc function to be called to determine what will be dropped + * when the block is broken + * @param level if level is specified and is not 0, digging level of the + * block is additionally set + * @returns `true`, if specified string or numeric ID exists and the function + * was registered correctly, `false` otherwise. + */ + function registerDropFunctionForID(numericId: number, dropFunc: DropFunction, level?: number): boolean; + + /** + * Registers function used by Core Engine to determine block drop for the + * specified block ID. + * @param id tile string or numeric ID + * @param dropFunc function to be called to determine what will be dropped + * when the block is broken + * @param level if level is specified and is not 0, digging level of the + * block is additionally set + * @returns `true`, if specified string or numeric ID exists and the function + * was registered correctly, `false` otherwise. + */ + function registerDropFunction(id: string | number, dropFunc: DropFunction, level?: number): boolean; + + /** + * Function used to determine block drop. + * @param blockCoords coordinates where the block is destroyed and side from + * where it is destroyed + * @param blockID numeric tile ID + * @param blockData block data value + * @param diggingLevel level of the tool the block was dug with + * @param enchant enchant data of the tool held in player's hand + * @param item item stack held in player's hand + * @param region BlockSource object + * @returns Block drop, the array of arrays, each containing three or four values: + * ID, count, data and extra respectively. + */ + interface DropFunction { + (blockCoords: Callback.ItemUseCoordinates, blockID: number, blockData: number, diggingLevel: number, enchant: ToolAPI.EnchantData, item: ItemInstance, region: BlockSource): ItemInstanceArray[] + } + + /** + * Registered function used by Core Engine to determine block drop for the + * specified block ID. + * @param numericId tile numeric ID + * @param func function to be called when a block in the world is broken by + * environment (explosions, pistons, etc.) + * @returns `true`, if specified string or numeric ID exists and the function + * was registered correctly, `false` otherwise. + */ + function registerPopResourcesFunctionForID(numericId: number, func: PopResourcesFunction): boolean; + + /** + * Registered function used by Core Engine to determine block drop for the + * specified block ID. + * @param id tile string or numeric ID + * @param func function to be called when a block in the world is broken by + * environment (explosions, pistons, etc.) + * @returns `true`, if specified string or numeric ID exists and the function + * was registered correctly, `false` otherwise. + */ + function registerPopResourcesFunction(id: string | number, func: PopResourcesFunction): boolean; + + /** + * Function used to determine when block is broken by + * environment (explosions, pistons, etc.). + * @param blockCoords coordinates where the block is destroyed and side from + * where it is destroyed + * @param block information about block that is broken + * @param region BlockSource object + * @param i unknown parameter, supposed to always be zero + */ + interface PopResourcesFunction { + (blockCoords: Vector, block: Tile, region: BlockSource, explosionRadius: number, i: number): void + } + + /** + * Registers function on entity being inside the block. Can be used to create portals. + * @param numericId tile string or numeric ID + * @param func function to be called when entity is inside the block + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.0.2b26 + */ + function registerEntityInsideFunctionForID(numericId: number, func: EntityInsideFunction): boolean; + + /** + * Registers function on entity being inside the block. Can be used to create portals. + * @param id tile string or numeric ID + * @param func function to be called when entity is inside the block + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.0.2b26 + */ + function registerEntityInsideFunction(id: string | number, func: EntityInsideFunction): boolean; + + interface EntityInsideFunction { + (blockCoords: Vector, block: Tile, entity: number): void + } + + /** + * Registers function on entity step on the block. + * @param numericId tile numeric ID + * @param func function to be called when entity step on the block + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.3.1b116 (implemented in 2.0.2b26) + */ + function registerEntityStepOnFunctionForID(numericId: number, func: EntityStepOnFunction): boolean; + + /** + * Registers function on entity step on the block. + * @param id tile string or numeric ID + * @param func function to be called when entity step on the block + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.3.1b116 (implemented in 2.0.2b26) + */ + function registerEntityStepOnFunction(id: string | number, func: EntityStepOnFunction): boolean; + + interface EntityStepOnFunction { + (coords: Vector, block: Tile, entity: number): void + } + + /** + * Registers function on neighbour blocks updates. + * @param numericId tile numeric ID + * @param func function to be called when neighbour block updates + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.0.2b26 + */ + function registerNeighbourChangeFunctionForID(numericId: number, func: NeighbourChangeFunction): boolean; + + /** + * Registers function on neighbour blocks updates. + * @param id tile string or numeric ID + * @param func function to be called when neighbour block updates + * @returns `true`, if the function was registered correctly, `false` otherwise. + * @since 2.0.2b26 + */ + function registerNeighbourChangeFunction(id: string | number, func: NeighbourChangeFunction): boolean; + + /** + * Function used to check block's neighbours changes. + * @param coords coords vector of the block + * @param block Tile object of the block + * @param changedCoords coords vector of the neighbour block that was changed + * @param region BlockSource object + */ + interface NeighbourChangeFunction { + (coords: Vector, block: Tile, changedCoords: Vector, region: BlockSource): void + } + + /** + * @returns Drop function of the block with given numeric ID. + */ + function getDropFunction(id: number): Block.DropFunction; + + /** + * Registers a default destroy function for the specified block, considering + * it's digging level. + * @param numericId tile numeric ID + * @param level digging level of the block + * @param resetData if true, the block is dropped with data equals to 0 + */ + function setDestroyLevelForID(numericId: number, level: number, resetData?: boolean): void; + + /** + * Registers a default destroy function for the specified block, considering + * it's digging level. + * @param id tile string or numeric ID + * @param level digging level of the block + * @param resetData if true, the block is dropped with data equals to 0 + */ + function setDestroyLevel(id: string | number, level: number, resetData?: boolean): void; + + /** + * Sets destroy time for the block with specified ID. + * @param nameID string or numeric block ID + * @param time destroy time for the block, in ticks + */ + function setDestroyTime(nameID: string | number, time: number): void; + + /** + * @returns Given block's material numeric ID. + * @since 2.2.1b101 (TODO: fix in changelog) + */ + function getMaterial(id: number): number; + + /** + * @param numericId numeric block ID + * @returns `true`, if block is solid, `false` otherwise. + */ + function isSolid(numericId: number): boolean; + + /** + * @returns Whether the block of given ID can contain liquid inside. + * @since 2.2.1b95 + */ + function canContainLiquid(id: number): boolean; + + /** + * @returns Whether the block of given ID can be an extra block + * (it's the block that can be set inside of another blocks, for ex. water and other liquids). + * @since 2.2.1b95 + */ + function canBeExtraBlock(id: number): boolean; + + /** + * @param numericId numeric block ID + * @returns Destroy time of the block, in ticks. + */ + function getDestroyTime(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Explosion resistance of the block. + */ + function getExplosionResistance(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Friction of the block. + */ + function getFriction(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Translucency of the block. + */ + function getTranslucency(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Light level, emitted by block, from 0 to 15. + */ + function getLightLevel(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Light opacity of the block, from 0 to 15. + */ + function getLightOpacity(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Render layer of the block. + */ + function getRenderLayer(numericId: number): number; + + /** + * @param numericId numeric block ID + * @returns Render type of the block. + */ + function getRenderType(numericId: number): number; + + function getBlockAtlasTextureCoords(str: string, int: number): BlockAtlasTextureCoords; + + interface BlockAtlasTextureCoords { + u1: number, v1: number, u2: number, v2: number; + } + + /** + * Temporarily sets destroy time for block, saving the old value for the + * further usage. + * @param numericId numeric block ID + * @param time new destroy time in ticks + */ + function setTempDestroyTime(numericId: number, time: number): void; + + /** + * Registers material and digging level for the specified block. + * @param nameID block numeric or string ID + * @param material material name + * @param level block's digging level + * @returns `true` if specified string or numeric ID exists, `false` otherwise. + */ + function setBlockMaterial(nameID: string | number, material: string, level: number): boolean; + + /** + * @param id numeric block ID + * @returns Color specified block is displayed on the vanilla maps. + */ + function getMapColor(id: number): number; + + /** + * Makes block accept redstone signal. + * @param nameID block numeric or string ID + * @param data block data, currently not used + * @param isRedstone if true, the redstone changes at the block will notify + * the "RedstoneSignal" callback + * @deprecated Use {@link Block.setupAsRedstoneReceiver} and + * {@link Block.setupAsRedstoneEmitter} instead. + */ + function setRedstoneTile(nameID: string | number, data: number, isRedstone: boolean): void; + + /** + * Makes block receive redstone signals via "RedstoneSignal" callback. + * @param nameID block numeric or string ID + * @param connectToRedstone if true, redstone wires will connect to the block + * @since 2.0.2b23 + */ + function setupAsRedstoneReceiver(nameID: number | string, connectToRedstone: boolean): void; + + /** + * Makes block emit redstone signal. + * @param nameID block numeric or string ID + * @param connectToRedstone if true, redstone wires will connect to the block + * @since 2.0.2b23 + */ + function setupAsRedstoneEmitter(nameID: number | string, connectToRedstone: boolean): void; + + /** + * Removes all the redstone functionality from the block. + * @param nameID block numeric or string ID + * @since 2.0.2b23 + */ + function setupAsNonRedstoneTile(nameID: number | string): void; + + /** + * Gets drop for the specified block. Used mostly by Core Engine's + * {@link ToolAPI}, though, can be useful in the mods, too. + * @param block block info + * @param item item that was (or is going to be) used to break the block + * @param coords coordinates where the block was (or is going to be) broken + * @returns Block drop, the array of arrays, each containing three values: + * ID, count and data respectively. + */ + function getBlockDropViaItem(block: Tile, item: ItemInstance, coords: Vector, region: BlockSource): ItemInstanceArray[]; + + /** + * Registers function to be called when the block is placed in the world. + * @param numericId block numeric ID + * @param func function to be called when the block is placed in the world + */ + function registerPlaceFunctionForID(numericId: number, func: PlaceFunction): void; + + /** + * Registers function to be called when the block is placed in the world. + * @param id block numeric or string ID + * @param func function to be called when the block is placed in the world + */ + function registerPlaceFunction(id: string | number, func: PlaceFunction): void; + + /** + * @returns Place function of the block with given numeric ID, + * or undefined if it was not specified. + */ + function getPlaceFunc(id: number): Block.PlaceFunction; + + /** + * Function used to determine when block is placed in the world. + * @param coords set of all coordinate values that can be useful to write + * custom use logics + * @param item item that was in the player's hand when he touched the block + * @param block block that was touched + * @param player Player unique ID + * @param region BlockSource object + * @returns Coordinates where to actually place the block, or void for + * default placement. + */ + interface PlaceFunction { + (coords: Callback.ItemUseCoordinates, item: ItemInstance, block: Tile, player: number, region: BlockSource): Vector | void + } + + /** + * Sets block box shape, like {@link Block.setShape}, + * but in voxel objects for each coordinate. + * @param id block numeric ID + * @param pos1 block lower corner position + * @param pos2 block upper conner position + * @param data block optional data (or -1) + */ + function setBlockShape(id: number, pos1: Vector, pos2: Vector, data?: number): void; + + /** + * Sets block box shape via scalar coordinates, + * usually presented in voxels (1/16 of block). + * @param id block numeric ID + * @param data block optional data (or -1) + */ + function setShape(id: number, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, data?: number): void; + + /** + * Creates a new special type using specified params + * and optionally registers it by name. + * @param description special type properties + * @param name string name to register the special type + * @returns Special type name. + */ + function createSpecialType(description: SpecialType, name?: string): string; + + type ColorSource = "grass" | "leaves" | "water"; + + type Sound = "normal" + | "gravel" + | "wood" + | "grass" + | "metal" + | "stone" + | "cloth" + | "glass" + | "sand" + | "snow" + | "ladder" + | "anvil" + | "slime" + | "silent" + | "itemframe" + | "turtle_egg" + | "bamboo" + | "bamboo_sapling" + | "lantern" + | "scaffolding" + | "sweet_berry_bush" + | "default"; + + /** + * Special types are used to set properties to the block. Unlike items, + * blocks properties are defined using special types, due to old Inner + * Core's block IDs limitations. + */ + interface SpecialType { + /** + * Unique string identifier of the SpecialType. + */ + name?: string, + /** + * Vanilla block ID to inherit some of the properties. + * @default 0 + */ + base?: number, + /** + * Block material constant to be inherited. + * @default 3 + */ + material?: number, + /** + * If `true`, the block is not transparent. + * @default false + */ + solid?: boolean, + /** + * If `true`, all block faces are rendered, otherwise back faces are not + * rendered, like for glass. + * @default false + */ + renderallfaces?: boolean, + /** + * Sets render type of the block. Default is full block, use other + * values to change block's shape. + * @default 0 + */ + rendertype?: number, + /** + * Specifies the layer that is used to render the block. + * @default 4 + */ + renderlayer?: number, + /** + * If non-zero value is used, the block emits light of that value. + * Default is no lighting, use values from 1 to 15 to set light level. + * @default 0 + */ + lightlevel?: number, + /** + * Specifies how opaque the block is. Default is transparent, use values + * from 1 to 15 to make the block opaque. + * @default 0 + */ + lightopacity?: number, + /** + * Specifies how block resists to the explosions. + * @default 3 + */ + explosionres?: number, + /** + * Specifies how player walks on this block. The higher the friction is, + * the more difficult it is to change speed and direction. + * @default 0.6000000238418579 + */ + friction?: number, + /** + * Specifies the time required to destroy the block, in ticks. + */ + destroytime?: number, + /** + * If non-zero value is used, the shadows will be rendered on the block. + * Default is zero, allows float values from 0 to 1. + * @default 0 + */ + translucency?: number, + /** + * Block color when displayed on the vanilla maps. + * @since 2.0.2b23 + */ + mapcolor?: number, + /** + * Makes block use biome color source when displayed on the vanilla maps. + * @since 2.1.0b56 + */ + color_source?: ColorSource, + /** + * Specifies sounds of the block, one of {@link Block.Sound}. + * @since 2.0.2b25 + */ + sound?: Sound, + /** + * Whether or not block may filled by water bucket or + * other custom fillable liquids. + * @default false + * @since 2.2.1b95 + */ + can_contain_liquid?: boolean, + /** + * Whether or not block may overlay different block, + * like water overlapping fillable blocks. + * @default false + * @since 2.2.1b95 + */ + can_be_extra_block?: boolean + } + + /** + * Makes block invoke callback randomly depending on game speed. + * @param id block ID to register for random ticks + * @param callback function to be called on random block tick + */ + function setRandomTickCallback(id: number, callback: RandomTickFunction): void; + + /** + * Function used to track random block ticks. + */ + interface RandomTickFunction { + /** + * @param id block numeric identifier + * @param data block data + * @param region block source instance + */ + (x: number, y: number, z: number, id: number, data: number, region: BlockSource): void; + } + + /** + * Makes block invoke callback randomly depending on game speed. Occurs more + * often then {@link Block.setRandomTickCallback} and only if the block is not + * far away from player. + * @param id block ID to register + * @param callback function to be called + */ + function setAnimateTickCallback(id: number, callback: AnimateTickFunction): void; + + /** + * Function used to track random block animation ticks. + */ + interface AnimateTickFunction { + /** + * @param id block numeric identifier + * @param data block data + */ + (x: number, y: number, z: number, id: number, data: number): void; + } + + /** + * Once upon a time, a new way of registering blocks, however, + * in current state, either does not work or is undesirable to use. + */ + interface BlockLegacyPrototype extends Scriptable { + type: "createBlock" | "createBlockWithRotation", + init?: () => void, + getVariations: (item: null) => BlockVariation[], + getSpecialType?: (item: null) => Nullable, + /** + * Unused at all. + */ + getCategory?: (item: null) => Nullable, + /** + * Unused at all. + */ + getEnchant?: (item: null) => Nullable, + /** + * Unused at all. + */ + getProperties?: (item: null) => Nullable, + /** + * Unused at all. + */ + isStackedByData?: (item: null) => Nullable, + /** + * Unused at all. + */ + isEnchanted?: (item: null) => Nullable, + getMaterial?: (item: null) => Nullable, + getDestroyLevel?: (item: null) => Nullable, + getShape?: (item: null) => Nullable, + getDrop?: (coords: Vector, id: number, data: number, diggingLevel: number, enchant: any) => ItemInstanceArray[], + /** + * Incorrect function, it will considered as {@link BlockLegacyPrototype.getDrop} + */ + onPlaced?: (coords: Vector, item: ItemInstance, block: Tile) => void, + /** + * Unused at all. + */ + onItemUsed?: (coords: Vector, item: ItemInstance, block: Tile) => void + } + + /** + * @deprecated Better performance should be inherited by manually + * manipulation with properties and {@link Block.SpecialType special type}. + */ + function setPrototype(nameID: string, Prototype: BlockLegacyPrototype): void; +} diff --git a/api/core-engine/BlockRenderer.d.ts b/api/core-engine/BlockRenderer.d.ts new file mode 100644 index 000000000..840c0b5b3 --- /dev/null +++ b/api/core-engine/BlockRenderer.d.ts @@ -0,0 +1,300 @@ +/** + * Module used to create blocks with any custom model. + */ +declare namespace BlockRenderer { + /** + * Class representing model used by {@link BlockRenderer}. + */ + class Model { + /** + * Creates a new empty model. + */ + constructor(); + + /** + * Constructs new model using specified {@link RenderMesh}. + */ + constructor(mesh: RenderMesh); + + constructor(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, descr: ModelTextureSet); + + constructor(descr: ModelTextureSet); + + /** + * Constructs new block model with single box inside specified block shape. + * The width of the full block is 1x1x1 units. + * @param texName block texture name to be used with the model + * @param texId block texture meta to be used with the model + */ + constructor(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, texName: string, texId: number); + + /** + * Constructs new block model with single box of the normal block size. + * @param texName block texture name to be used with the model + * @param texId block texture meta to be used with the model + */ + constructor(texName: string, texId: number); + + /** + * Constructs new block model with single box inside specified block shape. + * The width of the full block is 1x1x1 units. Uses block ID and data to + * determine texture. + * @param id sample block ID + * @param data sample block data + */ + constructor(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, id: number, data: number); + + /** + * Constructs new block model with single box of the normal block size. + * The width of the full block is 1x1x1 units. Uses block ID and data to + * determine texture. + * @param id + * @param data + */ + constructor(id: number, data: number); + + /** + * Adds new box to the model using specified block's textures. + */ + addBox(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, id: number, data: number): void; + + /** + * Adds new box to the model using specified textures for the six sides + * of the box. + */ + addBox(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, descr: ModelTextureSet): void; + + /** + * Adds new box to the model using specified block texture name and ID. + */ + addBox(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, texName: string, texId: number): void; + + /** + * Adds new block with specified block's textures. + */ + addBox(id: number, data?: number): void; + + /** + * Adds new {@link RenderMesh} to the model. + */ + addMesh(mesh: RenderMesh): void; + } + + /** + * Type used to describe a new model for {@link BlockRenderer}. + */ + type ModelTextureSet = + [string, number][]; + + /** + * Creates a new empty block model. + * @returns Empty block model. + */ + function createModel(): BlockRenderer.Model; + + /** + * Constructs new block model of specified simple block shape with specified + * textures. + * @param descr texture set used for the box + */ + function createTexturedBox(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, descr: ModelTextureSet): BlockRenderer.Model; + + /** + * Constructs new block model of specified simple block of the normal block + * size shape with specified textures. + * @param descr texture set used for the box + */ + function createTexturedBlock(descr: ModelTextureSet): BlockRenderer.Model; + + /** + * Adds "CustomBlockTessellation" callback function for specified block ID. + * @param id block ID + * @param callback function to be called when the event occurs + */ + function addRenderCallback(id: number, callback: Callback.CustomBlockTessellationFunction): void; + + /** + * Forces block renders to be rebuilt immediately. + * @param mode if 0 is passed, only the specified block gets rebuilt, if + * 1 is passed, all the blocks along y axes are rebuilt + */ + function forceRenderRebuild(x: number, y: number, z: number, mode: number): void; + + /** + * Specifies custom collision shape for the block. + * @param id block ID + * @param data block data + * @param shape {@link ICRender.CollisionShape} object to be used as + * default collision shape for the specified block + * @since 2.1.0b59 + */ + function setCustomCollisionShape(id: number, data: number, shape: ICRender.CollisionShape): void; + + /** + * Specifies custom raycast shape for the block. + * @param id block ID + * @param data block data or -1 to map all the data values + * @param shape {@link ICRender.CollisionShape} object to be used as + * default raycast shape for the specified block + * @since 2.1.0b59 + */ + function setCustomRaycastShape(id: number, data: number, shape: ICRender.CollisionShape): void; + + /** + * Specifies custom collision and raycast shape for the block. + * @param id block ID + * @param data block data or -1 to map all the data values + * @param shape {@link ICRender.CollisionShape} object to be used as + * default collision and raycast shape for the specified block + * @since 2.1.0b59 + */ + function setCustomCollisionAndRaycastShape(id: number, data: number, shape: ICRender.CollisionShape): void; + + /** + * Enables custom rendering for the specified block. + * @param id block ID + * @param data block data or -1 to map all the data values + */ + function enableCustomRender(id: number, data: number): void; + + /** + * Disables custom rendering for the specified block. + * @param id block ID + * @param data block data or -1 to map all the data values + */ + function disableCustomRender(id: number, data: number): void; + + /** + * Sets static ICRender model as block render shape. + * @param id block ID + * @param data block data or -1 to map all the data values + * @param icRender {@link ICRender.Model} object to be used as static block shape + */ + function setStaticICRender(id: number, data: number, icRender: ICRender.Model): void; + + /** + * Enables block mapping for the specified block. + * @param id block ID + * @param data block data or -1 to map all the data values + * @param icRender default model for the block + */ + function enableCoordMapping(id: number, data: number, icRender: ICRender.Model): void; + + /** + * Changes shape of the block on the specified coordinates. + * @param icRender {@link ICRender.Model} object to be displayed at the coordinates + * @param preventRebuild if false or not specified, rebuild is performed immediately + */ + function mapAtCoords(x: number, y: number, z: number, icRender: ICRender.Model, preventRebuild?: boolean): void; + + /** + * Resets shape of the block to default on the specified coordinates. + * @param preventRebuild if false or not specified, rebuild is performed immediately + */ + function unmapAtCoords(x: number, y: number, z: number, preventRebuild?: boolean): void; + + /** + * Changes collision shape of the block on given coords in given dimension. + * @param shape {@link ICRender.CollisionShape} object to be used as new collision shape + * @since 2.1.0b59 + */ + function mapCollisionModelAtCoords(dimension: number, x: number, y: number, z: number, shape: ICRender.CollisionShape): void; + + /** + * Changes raycast shape of the block on given coords in given dimension. + * @param shape {@link ICRender.CollisionShape} object to be used as new raycast shape + * @since 2.1.0b59 + */ + function mapRaycastModelAtCoords(dimension: number, x: number, y: number, z: number, shape: ICRender.CollisionShape): void; + + /** + * Changes both collision and raycast shape of the block on given coords in given dimension. + * @param shape {@link ICRender.CollisionShape} object to be used as new collision and raycast shape + * @since 2.1.0b59 + */ + function mapCollisionAndRaycastModelAtCoords(dimension: number, x: number, y: number, z: number, shape: ICRender.CollisionShape): void; + + /** + * Resets collision shape of the block to default on given coords in given dimension. + * @since 2.1.0b59 + */ + function unmapCollisionModelAtCoords(dimension: number, x: number, y: number, z: number): void; + + /** + * Resets raycast shape of the block to default on given coords in given dimension. + * @since 2.1.0b59 + */ + function unmapRaycastModelAtCoords(dimension: number, x: number, y: number, z: number): void; + + /** + * Resets both collision and raycast shape of the block to default on given coords in given dimension. + * @since 2.1.0b59 + */ + function unmapCollisionAndRaycastModelAtCoords(dimension: number, x: number, y: number, z: number): void; + + /** + * Object used to manipulate rendered block during + * {@link Callback.CustomBlockTessellationFunction} calls. + */ + + interface RenderAPI { + /** + * @returns Pointer to native object instance of the following object, + * to be used in custom native code, etc. + */ + getAddr(): number; + /** + * Renders box at the specified coordinates of the specified size. + * @param id ID of the block to be used as texture source + * @param data data of the block to be used as texture source + */ + renderBoxId(x: number, y: number, z: number, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, id: number, data: number): void; + + /** + * Renders box at current block coordinates of the specified size. + * @param id ID of the block to be used as texture source + * @param data data of the block to be used as texture source + */ + renderBoxIdHere(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, id: number, data: number): void; + + /** + * Renders box at the specified coordinates of the specified size. + * @param texName block texture name + * @param texId block texture ID + */ + renderBoxTexture(x: number, y: number, z: number, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, texName: string, texId: number): void; + + /** + * Renders box at current block coordinates of the specified size. + * @param id ID of the block to be used as texture source + * @param data data of the block to be used as texture source + */ + renderBoxTextureHere(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, id: number, data: number): void; + + /** + * Renders full block at specified coordinates. + * @param blockId ID of the block to be used as texture source + * @param blockData data of the block to be used as texture source + */ + renderBlock(x: number, y: number, z: number, blockId: number, blockData: number): void; + + /** + * Renders full block at current block coordinates. + * @param blockId ID of the block to be used as texture source + * @param blockData data of the block to be used as texture source + */ + renderBlockHere(blockId: number, blockData: number): void; + + /** + * Renders block model at the specified coordinates. + * @param model block model to be rendered at the specified coordinates + */ + renderModel(x: number, y: number, z: number, model: BlockRenderer.Model): void; + + /** + * Renders block model at current block coordinates. + * @param model block model to be rendered at current block coordinates + */ + renderModelHere(model: BlockRenderer.Model): void; + } +} diff --git a/api/core-engine/BlockSource.d.ts b/api/core-engine/BlockSource.d.ts new file mode 100644 index 000000000..6c2e8cd10 --- /dev/null +++ b/api/core-engine/BlockSource.d.ts @@ -0,0 +1,428 @@ +declare namespace BlockSource { + interface BlockBreakResult { + items: ItemInstance[]; + experience: number; + } +} + +/** + * New class to work with world instead of some methods from {@link World} module. + */ +declare class BlockSource { + + /** + * @returns Interface to given dimension by default + * (`null` if given dimension is not loaded and this interface + * was not created yet). + */ + static getDefaultForDimension(dimension: number): Nullable; + + /** + * @returns Interface to the dimension where the given entity is + * (`null` if given entity does not exist or the dimension is not loaded + * and interface was not created). + */ + static getDefaultForActor(entityUid: number): Nullable; + + /** + * @returns BlockSource for world generation. + */ + static getCurrentWorldGenRegion(): Nullable; + + /** + * @returns BlockSource for the current client. + * @since 2.1.0b57 (caching since 2.3.1b115) + */ + static getCurrentClientRegion(): Nullable; + + /** + * + * @param pointer + */ + static getFromCallbackPointer(pointer: number): Nullable; + + /** + * + * @param pointer + * @since 2.3.1b115 + */ + static getFromServerCallbackPointer(pointer: number): Nullable; + + /** + * + */ + static resetDefaultBlockSources(): void; + + /** + * + */ + getPointer(): number; + + /** + * + * @param allowed + */ + setBlockUpdateAllowed(allowed: boolean): void; + + /** + * + */ + getBlockUpdateAllowed(): boolean; + + /** + * + * @param type + */ + setBlockUpdateType(type: number): void; + + /** + * + */ + getBlockUpdateType(): number; + + /** + * Whether or not particles must be emitted when destroying + * blocks with this source. + * @default true + * @since 2.2.1b102 + */ + setDestroyParticlesEnabled(enabled: boolean): void; + + /** + * @since 2.2.1b102 + */ + getDestroyParticlesEnabled(): boolean; + + /** + * @returns Block's ID at coords. + * @param x X coord of the block + * @param y Y coord of the block + * @param z Z coord of the block + */ + getBlockId(x: number, y: number, z: number): number; + + /** + * @returns Block's ID at coords. + * @param x X coord of the block + * @param y Y coord of the block + * @param z Z coord of the block + * @since 2.2.1b96 + */ + getBlockID(x: number, y: number, z: number): number; + + /** + * @returns Block's data at coords. + * @param x X coord of the block + * @param y Y coord of the block + * @param z Z coord of the block + */ + getBlockData(x: number, y: number, z: number): number; + + /** + * @param x X coord of the block + * @param y Y coord of the block + * @param z Z coord of the block + * @returns Object of the block on given coords + * or {@link Tile} object in Legacy pack. + * @since 2.1.0b59 + */ + getBlock(x: number, y: number, z: number): BlockState | Tile; + + /** + * @returns Object of the extra block on given coords. + * @since 2.2.1b95 + */ + getExtraBlock(x: number, y: number, z: number): BlockState; + + /** + * Sets block on coords. + * @param id ID of the block to set + * @param data data of the block to set + */ + setBlock(x: number, y: number, z: number, id: number, data: number): void; + + /** + * Sets block on coords. + * @param id ID of the block to set + * @since 2.2.1b95 + */ + setBlock(x: number, y: number, z: number, id: number): void; + + /** + * Sets block by given {@link BlockState} on coords. + */ + setBlock(x: number, y: number, z: number, state: BlockState): void; + + /** + * Sets extra block (for example, water inside another blocks), + * on given coords by given ID and data. + * @since 2.2.1b95 + */ + setExtraBlock(x: number, y: number, z: number, id: number, data?: number): void; + + /** + * Sets extra block (for example, water inside another blocks), + * on given coords by given {@link BlockState}. + * @since 2.2.1b95 + */ + setExtraBlock(x: number, y: number, z: number, state: BlockState): void; + + /** + * @since 2.2.1b102 + */ + addToTickingQueue(x: number, y: number, z: number, state: BlockState, delay: number, todo?: number): void; + + /** + * @since 2.2.1b102 + */ + addToTickingQueue(x: number, y: number, z: number, delay: number, todo?: number): void; + + /** + * + * @since 2.4.0b119 + */ + getRainLevel(): number; + + /** + * + * @param level + * @since 2.4.0b119 + */ + setRainLevel(level: number): void; + + /** + * + * @since 2.4.0b119 + */ + getLightningLevel(): number; + + /** + * + * @param level + * @since 2.4.0b119 + */ + setLightningLevel(level: number): void; + + /** + * Destroys block on coords producing appropriate drop + * and particles. Do not use for massive tasks due to particles being + * produced. + * @param drop whether to provide drop for the block or not + */ + destroyBlock(x: number, y: number, z: number, drop?: boolean): void; + + /** + * Destroys block on coords by entity using specified item or without it. + * @param allowDrop whether to provide drop for the block or not + * @param entityUid entity ID or -1 ID if entity is not specified + * @param item tool which broke block + * @since 2.2.0b83 + */ + breakBlock(x: number, y: number, z: number, allowDrop: boolean, entityUid?: number, item?: ItemInstance): void; + + /** + * Destroys block on coords by entity using specified item. + * @param allowDrop whether to provide drop for the block or not + * @param item tool which broke block + * @since 2.2.0b83 + */ + breakBlock(x: number, y: number, z: number, allowDrop: boolean, item: ItemInstance): void; + + /** + * Same as breakBlock, but returns object containing drop and experience. + * @param entityUid entity ID or -1 ID if entity is not specified + * @param item tool which broke block + * @since 2.2.0b83 + */ + breakBlockForJsResult(x: number, y: number, z: number, entityUid?: number, item?: ItemInstance): BlockSource.BlockBreakResult; + + /** + * Same as breakBlock, but returns object containing drop and experience. + * @param item tool which broke block + * @since 2.2.0b83 + */ + breakBlockForJsResult(x: number, y: number, z: number, item: ItemInstance): BlockSource.BlockBreakResult; + + /** + * Creates an explosion on coords. + * @param power defines how many blocks can the explosion destroy and what + * blocks can or cannot be destroyed + * @param fire if true, puts the crater on fire + */ + explode(x: number, y: number, z: number, power: number, fire: boolean): void; + + /** + * @param mode certain modes also working with actors + */ + clip(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, mode: number, output: number[]): number; + + /** + * @returns Dimension ID to which the following object belongs. + */ + getDimension(): number; + + /** + * @returns Interface to the vanilla TileEntity (chest, furnace, etc.) + * on the coords, and null if it's not found. + */ + getBlockEntity(x: number, y: number, z: number): Nullable; + + /** + * @param x X coord of the block + * @param z Z coord of the block + * @returns Biome ID. + */ + getBiome(x: number, z: number): number; + + /** + * Sets biome ID by coords. + * @param biomeID ID of the biome to set + */ + setBiome(chunkX: number, chunkZ: number, biomeID: number): void; + + /** + * @returns Temperature of the biome on coords. + */ + getBiomeTemperatureAt(x: number, y: number, z: number): number; + + /** + * @returns Downfall of the biome on coords. + * @since 2.2.1b96 + */ + getBiomeDownfallAt(x: number, y: number, z: number): number; + + /** + * @returns Grass color on chunk coords. + */ + getGrassColor(x: number, z: number): number; + + /** + * @param chunkX X coord of the chunk + * @param chunkZ Z coord of the chunk + * @returns `true` if chunk is loaded, `false` otherwise. + */ + isChunkLoaded(chunkX: number, chunkZ: number): boolean; + + /** + * @param x X coord of the position + * @param z Z coord of the position + * @returns `true` if chunk on the position is loaded, `false` otherwise. + */ + isChunkLoadedAt(x: number, z: number): boolean; + + /** + * @param chunkX X coord of the chunk + * @param chunkZ Z coord of the chunk + * @returns Loading state of the chunk by chunk coords. + */ + getChunkState(chunkX: number, chunkZ: number): number; + + /** + * @param x X coord of the position + * @param z Z coord of the position + * @returns Loading state of the chunk by coords. + */ + getChunkStateAt(x: number, z: number): number; + + /** + * @returns Light level on the specified coordinates, from 0 to 15. + * @since 2.1.0b69 + */ + getLightLevel(x: number, y: number, z: number): number; + + /** + * @returns Whether the sky can be seen from coords. + */ + canSeeSky(x: number, y: number, z: number): boolean; + + /** + * @param type entity type, since 2.3.1b115 could be used + * to fetch all entities via `0` or `256` + * @returns Iterator of entity IDs in given box, + * that are equal to the given type, if blacklist value is `false`, + * and all except the entities of the given type, if blacklist value is `true`. + */ + fetchEntitiesInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, type?: number, blacklist?: boolean): number[]; + + /** + * @param namespace entity namespace, e.g. "minecraft" + * @param type entity type, e.g. "chicken" + * @returns Iterator of entity IDs in given box, that are equal to the given type. + * @since 2.3.1b115 + */ + fetchEntitiesOfTypeInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, namespace: string, type: string): number[]; + + /** + * @param type namespaced entity type, e.g. "minecraft:chicken"; if there is + * no namespace, default "minecraft" will be used instead, e.g. "chicken" + * @returns Iterator of entity IDs in given box, that are equal to the given type. + * @since 2.3.1b115 + */ + fetchEntitiesOfTypeInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, type: string): number[]; + + /** + * @param type entity type, since 2.3.1b115 could be used + * to fetch all entities via `0` or `256` + * @returns List of entity IDs in given box, + * that are equal to the given type, if blacklist value is `false`, + * and all except the entities of the given type, if blacklist value is `true`. + */ + listEntitiesInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, type?: number, blacklist?: boolean): number[]; + + /** + * @param namespace entity namespace, e.g. "minecraft" + * @param type entity type, e.g. "chicken" + * @returns List of entity IDs in given box, that are equal to the given type. + * @since 2.3.1b115 + */ + listEntitiesOfTypeInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, namespace: string, type: string): number[]; + + /** + * @param type namespaced entity type, e.g. "minecraft:chicken"; if there is + * no namespace, default "minecraft" will be used instead, e.g. "chicken" + * @returns List of entity IDs in given box, that are equal to the given type. + * @since 2.3.1b115 + */ + listEntitiesOfTypeInAABB(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, type: string): number[]; + + /** + * Spawns entity of given numeric or namespaced type on coords. + * @param type numeric entity type, e.g. `EEntityType.CHICKEN` or + * namespaced type with possible ommitions, e.g. "minecraft:chicken:", + * "minecraft:chicken", "chicken" does same + * @example + * ```ts + * Callback.addCallback("ItemUse", (coords: ItemUseCoordinates, item: ItemInstance, block: Tile, isExternal: boolean, player: number) => + * BlockSource.getDefaultForActor(player)?.spawnEntity(coords.relative.x, coords.relative.y, coords.relative.z, EEntityType.CHICKEN)); + * ``` + */ + spawnEntity(x: number, y: number, z: number, type: number | string): number; + + /** + * Spawns entity of given namespace by string type on coords + * with optional spawn events data. + * @example + * ```ts + * Callback.addCallback("ItemUse", (coords: ItemUseCoordinates, item: ItemInstance, block: Tile, isExternal: boolean, player: number) => + * BlockSource.getDefaultForActor(player)?.spawnEntity(coords.relative.x, coords.relative.y, coords.relative.z, "minecraft", "chicken", "")); + * ``` + */ + spawnEntity(x: number, y: number, z: number, namespace: string, type: string, initData?: string): number; + + /** + * Creates dropped item and returns entity ID. + * @param id ID of the item to drop + * @param count count of the item to drop + * @param data data of the item to drop + * @param extra extra of the item to drop + * @returns Drop entity ID. + */ + spawnDroppedItem(x: number, y: number, z: number, id: number, count: number, data: number, extra?: ItemExtraData): number; + + /** + * Spawns experience orbs on coords. + * @param amount experience amount + */ + spawnExpOrbs(x: number, y: number, z: number, amount: number): void; + +} diff --git a/api/core-engine/BlockState.d.ts b/api/core-engine/BlockState.d.ts new file mode 100644 index 000000000..f1a9b485d --- /dev/null +++ b/api/core-engine/BlockState.d.ts @@ -0,0 +1,113 @@ +/** + * Class to work with vanilla blocks parameters. + * @since 2.2.1b89 + */ +declare class BlockState implements Tile { + + /** + * Data of the block. + */ + readonly data: number; + + /** + * Numeric ID of the block. + */ + readonly id: number; + + /** + * Constructs new BlockState object + * from given ID and data. + */ + constructor(id: number, data: number); + + /** + * Constructs new BlockState object + * from given ID and states object. + */ + constructor(id: number, scriptable: {[key: number]: number}); + + /** + * @returns ID of the block. + */ + getId(): number; + + /** + * @returns Data of the block. + */ + getData(): number; + + /** + * @returns ID of the blockstate in runtime. + */ + getRuntimeId(): number; + + /** + * @returns Whether the state is valid. + */ + isValidState(): boolean; + + /** + * @returns State of the given number + * if it's present in the following object. + */ + getState(state: number): number; + + /** + * @returns Whether the state by given number + * is present in the following object. + */ + hasState(state: number): boolean; + + /** + * Adds state to the following object. + * @returns BlockState object itself. + */ + addState(state: number, value: number): BlockState; + + /** + * Adds states to the following object + * from given map instance. + * @returns BlockState object itself. + * @since 2.2.1b102 + */ + addStatesMap(states: java.util.Map): BlockState; + + /** + * Adds states to the following object + * from given JS object instance. + * @returns BlockState object itself. + * @since 2.2.1b102 + */ + addStates(states: object): BlockState; + + /** + * @returns All states from following object + * in {@link java.util.Map} instance. + */ + getStates(): java.util.Map; + + /** + * @returns All named states from following object + * in {@link java.util.Map} instance. + */ + getNamedStates(): java.util.Map; + + /** + * @returns All states from following object + * in JS object instance. + */ + getStatesScriptable(): { [key: string]: number }; + + /** + * @returns All named states from following object + * in JS object instance. + */ + getNamedStatesScriptable(): { [key: string]: number }; + + /** + * @returns Whether the following object is equal to given, + * according to different parameters. + */ + equals(object: any): boolean; + +} diff --git a/api/core-engine/Callback.d.ts b/api/core-engine/Callback.d.ts new file mode 100644 index 000000000..ab349d796 --- /dev/null +++ b/api/core-engine/Callback.d.ts @@ -0,0 +1,1043 @@ +/** + * Module used to handle callbacks. Investigate details about the + * callback mechanism and the list of pre-defined callbacks. + */ +declare namespace Callback { + + /** + * Adds callback function for the specified callback name. Most of native + * events can be prevented using {@link Game.prevent} call. + * @param name callback name, should be one of the pre-defined or a custom + * name if invoked via {@link Callback.invokeCallback} + * @param func function to be called when an event occurs + * @param priority the more this value is, the earlier your callback handler + * will be called when an event occurs + */ + function addCallback(name: string, func: Function, priority?: number): void; + + /** + * Invokes callback with any name and up to 10 additional parameters. You + * should not generally call pre-defined callbacks until you really need to + * do so. If you want to trigger some event in your mod, use your own + * callback names. + * @param name callback name + */ + function invokeCallback(name: string, o1?: any, o2?: any, o3?: any, o4?: any, o5?: any, o6?: any, o7?: any, o8?: any, o9?: any, o10?: any): void; + + /** + * Function used in "DimensionLoaded" callback. + */ + interface DimensionLoadedFunction { + /** + * @param currentId vanilla dimension ID, one of the {@link EDimension} + * values, or custom dimension ID + * @param lastId previous unloaded dimension ID + */ + (currentId: number, lastId: number): void + } + + /** + * @since 2.0.4b37 + */ + function addCallback(name: "DimensionLoaded", func: DimensionLoadedFunction, priority?: number): void; + + /** + * Function used in "DimensionUnloaded" callback. + */ + interface DimensionUnloadedFunction { + (dimensionId: number): void + } + + /** + * @since 2.0.4b37 + */ + function addCallback(name: "DimensionUnloaded", func: DimensionUnloadedFunction, priority?: number): void; + + /** + * Function used in "LocalPlayerChangedDimension" and "PlayerChangedDimension" callback. + */ + interface PlayerChangedDimensionFunction { + /** + * @param playerUid player entity unique numeric ID + * @param currentId vanilla dimension ID, one of the {@link EDimension} + * values, or custom dimension ID + * @param lastId previous unloaded dimension ID + */ + (playerUid: number, currentId: number, lastId: number): void + } + + /** + * @since 2.2.1b106 + */ + function addCallback(name: "LocalPlayerChangedDimension", func: PlayerChangedDimensionFunction, priority?: number): void; + + function addCallback(name: "PlayerChangedDimension", func: PlayerChangedDimensionFunction, priority?: number): void; + + /** + * Function used in "CustomDimensionTransfer" callback. + */ + interface CustomDimensionTransferFunction { + /** + * @param entityUid entity that was transferred between dimensions + * @param from ID of the dimension the entity was transferred from + * @param to ID of the dimension the entity was transferred to + */ + (entityUid: number, from: number, to: number): void + } + + function addCallback(name: "CustomDimensionTransfer", func: CustomDimensionTransferFunction, priority?: number): void; + + function addCallback(name: "tick", func: { (): void }, priority?: number): void; + + function addCallback(name: "LocalTick", func: { (): void }, priority?: number): void; + + /** + * Function used in "LocalPlayerTick" and "ServerPlayerTick" callback. + */ + interface PlayerTickFunction { + /** + * @param playerUid player entity unique ID + * @param isDead is following player dead + */ + (playerUid: number, isDead: boolean): void + } + + /** + * @since 2.2.1b106 + */ + function addCallback(name: "LocalPlayerTick", func: PlayerTickFunction, priority?: number): void; + + function addCallback(name: "ServerPlayerTick", func: PlayerTickFunction, priority?: number): void; + + /** + * Object used in some callbacks for coordinate set with side information + * and relative coordinates set. + */ + interface ItemUseCoordinates extends BlockPosition { + /** + * Relative coordinates, coordinates of the block to the specified side + * of current block. + */ + relative: Vector, + /** + * Exact touch point, absolute point coordinates. Used only in "ItemUse" + * callback. + */ + vec?: Vector + } + + /** + * Function used in "ItemUse" and "ItemUseLocalServer" callbacks. + */ + interface LegacyItemUseFunction { + /** + * @param coords set of all coordinate values that can be useful to write + * custom use logics, relative and vectorized one + * @param item item that was in the player's hand when it touched the block + * @param block block that was touched + * @param isExternal received from external player on server + * @param playerUid player entity UID + */ + (coords: ItemUseCoordinates, item: ItemInstance, block: Tile, isExternal: boolean, playerUid: number): void + } + + function addCallback(name: "ItemUse", func: LegacyItemUseFunction, priority?: number): void; + + function addCallback(name: "ItemUseLocalServer", func: LegacyItemUseFunction, priority?: number): void; + + /** + * Function used in "ItemUseServer" and "ItemUseLocal" callbacks. + */ + interface ItemUseFunction { + /** + * @param coords set of all coordinate values that can be useful to write + * custom use logics + * @param item item that was in the player's hand when it touched the block + * @param block block that was touched + * @param playerUid player entity UID + */ + (coords: ItemUseCoordinates, item: ItemInstance, block: Tile, playerUid: number): void + } + + function addCallback(name: "ItemUseServer", func: ItemUseFunction, priority?: number): void; + + /** + * @since 2.1.0b57 + */ + function addCallback(name: "ItemUseLocal", func: ItemUseFunction, priority?: number): void; + + /** + * Function used in "ItemUseNoTarget" callback. + */ + interface ItemUseNoTargetFunction { + /** + * @param item item that was in the player's hand when the event occurred + */ + (item: ItemInstance, playerUid: number): void + } + + function addCallback(name: "ItemUseNoTarget", func: ItemUseNoTargetFunction, priority?: number): void; + + /** + * Function used in "ItemUsingReleased" callback. + */ + interface ItemUsingReleasedFunction { + /** + * @param item item that was in the player's hand when the event occurred + * @param ticks amount of ticks left to the specified max use duration value + */ + (item: ItemInstance, ticks: number, playerUid: number): void + } + + function addCallback(name: "ItemUsingReleased", func: ItemUsingReleasedFunction, priority?: number): void; + + /** + * Function used in "ItemUsingComplete" callback. + */ + interface ItemUsingCompleteFunction { + /** + * @param item item that was in the player's hand when the event occurred + */ + (item: ItemInstance, playerUid: number): void + } + + function addCallback(name: "ItemUsingComplete", func: ItemUsingCompleteFunction, priority?: number): void; + + /** + * Function used in "ItemDispensed" callback. + */ + interface ItemDispensedFunction { + /** + * @param coords full coords object, where the main coords are the position of the dispenser block, + * `relative` ones are the position of the block to which the dispenser is pointed, + * and `vec` are the coords for the item to be dropped at + * @param item item that was dispensed + * @param region BlockSource object + * @param slot numeric ID of the slot from which the item was dispensed + */ + (coords: Callback.ItemUseCoordinates, item: ItemInstance, region: BlockSource, slot: number): void + } + + function addCallback(name: "ItemDispensed", func: ItemDispensedFunction, priority?: number): void; + + /** + * Function used in "ItemIconOverride" callback. + */ + interface ItemIconOverrideFunction { + /** + * @param item information about item that is used in override function + * @param isModUi whether icon override is working in mod ui or in vanilla one + * @returns Nothing if used in callback, {@link Item.TextureData} if used in item + * override function to return texture that will be used for the item. + */ + (item: ItemInstance, isModUi: boolean): void | Item.TextureData + } + + function addCallback(name: "ItemIconOverride", func: ItemIconOverrideFunction, priority?: number): void; + + /** + * Function used in "ItemNameOverride" callback. + */ + interface ItemNameOverrideFunction { + /** + * @param item information about item that is used in override function + * @param translation translated item name + * @param name original item name + * @returns Nothing if used in callback, string if used in item override + * function to return new name that will be displayed. + */ + (item: ItemInstance, translation: string, name: string): void | string; + } + + function addCallback(name: "ItemNameOverride", func: ItemNameOverrideFunction, priority?: number): void; + + interface ExplosionParams { + /** + * Explosion power. + */ + power: number, + /** + * If explosion is produced by an entity, entity unique ID, -1 otherwise. + */ + entity: number, + /** + * If `true`, explosion produced the fire. + */ + onFire: boolean, + /** + * Should explosion break blocks or not. + */ + someBool: boolean, + /** + * Max block resistance. + */ + someFloat: number; + } + + /** + * Function used in "DestroyBlock" and "DestroyBlockStart" callbacks. + */ + interface DestroyBlockFunction { + /** + * @param coords coordinates where the block is destroyed and side from + * where it is destroyed + * @param block block that is destroyed + * @param playerUid player entity unique numeric ID + */ + (coords: ItemUseCoordinates, block: Tile, playerUid: number): void + } + + function addCallback(name: "DestroyBlock", func: DestroyBlockFunction, priority?: number): void; + + function addCallback(name: "DestroyBlockStart", func: DestroyBlockFunction, priority?: number): void; + + /** + * Function used in "DestroyBlockContinue" callback. + */ + interface DestroyBlockContinueFunction { + /** + * @param coords coordinates where the block is destroyed and side from + * where it is destroyed + * @param block block that is destroyed + * @param progress current fraction of breaking progress + */ + (coords: ItemUseCoordinates, block: Tile, progress: number): void + } + + function addCallback(name: "DestroyBlockContinue", func: DestroyBlockContinueFunction, priority?: number): void; + + /** + * Function used in "BuildBlock" callback. + */ + interface BuildBlockFunction { + /** + * @param coords coordinates where the block is placed and side from + * where it is placed + * @param block block that is placed + * @param playerUid player entity unique numeric ID + */ + (coords: ItemUseCoordinates, block: Tile, playerUid: number): void + } + + function addCallback(name: "BuildBlock", func: BuildBlockFunction, priority?: number): void; + + /** + * Function used in "BlockChanged" callback. + */ + interface BlockChangedFunction { + /** + * @param coords coordinates where block change occurred + * @param oldBlock the block that is being replaced + * @param newBlock replacement block + */ + (coords: Vector, oldBlock: Tile, newBlock: Tile, region: BlockSource): void + } + + function addCallback(name: "BlockChanged", func: BlockChangedFunction, priority?: number): void; + + /** + * Function used in "BreakBlock" callback. + */ + interface BreakBlockFunction { + /** + * @param coords coordinates where the block is placed and side from + * where it is placed + * @param block block that is placed + * @param playerUid player entity unique numeric ID + * @param item item that was in the player's hand when it breaked the block + */ + (region: BlockSource, coords: ItemUseCoordinates, block: Tile, dropAllowed: boolean, playerUid: number, item: ItemInstance): void + } + + /** + * @since 2.2.0b83 + */ + function addCallback(name: "BreakBlock", func: BreakBlockFunction, priority?: number): void; + + interface RedstoneSignalParams { + /** + * Redstone signal power. + */ + power: number, + /** + * Same as {@link RedstoneSignalParams.power}. + */ + signal: number, + /** + * `true` if it is loading change. + */ + onLoad: boolean + } + + /** + * Function used in "RedstoneSignal" callback. + */ + interface RedstoneSignalFunction { + /** + * @param coords coordinates where redstone signal changed + * @param params information about redstone signal + * @param block information about the block on the specified coordinates + */ + (coords: Vector, params: RedstoneSignalParams, block: Tile, region: BlockSource): void + } + + function addCallback(name: "RedstoneSignal", func: RedstoneSignalFunction, priority?: number): void; + + function addCallback(name: "BlockEventEntityInside", func: Block.EntityInsideFunction, priority?: number): void; + + function addCallback(name: "BlockEventEntityStepOn", func: Block.EntityStepOnFunction, priority?: number): void; + + function addCallback(name: "BlockEventNeighbourChange", func: Block.NeighbourChangeFunction, priority?: number): void; + + /** + * Function used in "PopBlockResources" callback. + */ + interface PopBlockResourcesFunction { + /** + * @param coords coordinates of the block that was broken + * @param block information about the block that was broken + * @param explosionRadius explosion power in case of exploding + * @param cause cause information, supposed to always be zero + */ + (coords: Vector, block: Tile, explosionRadius: number, cause: number, region: BlockSource): void + } + + function addCallback(name: "PopBlockResources", func: PopBlockResourcesFunction, priority?: number): void; + + /** + * Function used in "Explosion" callback. + */ + interface ExplosionFunction { + /** + * @param coords coordinates of the explosion + * @param params additional explosion data + */ + (coords: Vector, params: ExplosionParams): void + } + + function addCallback(name: "Explosion", func: ExplosionFunction, priority?: number): void; + + /** + * Function used in "CustomBlockTessellation" callback. + */ + interface CustomBlockTessellationFunction { + /** + * @param renderer object used to manipulate block rendering process + * @param coords rendering block coordinates + * @param block block information + */ + (renderer: BlockRenderer.RenderAPI, coords: Vector, block: Tile): void + } + + function addCallback(name: "CustomBlockTessellation", func: CustomBlockTessellationFunction, priority?: number): void; + + /** + * Function used in the "FoodEaten" callback. + */ + interface FoodEatenFunction { + /** + * You can use {@link Entity.getCarriedItem} to get info about food item. + * @param food food amount produced by eaten food + * @param ratio saturation ratio produced by food + * @param playerUid player entity UID + */ + (food: number, ratio: number, playerUid: number): void + } + + function addCallback(name: "FoodEaten", func: FoodEatenFunction, priority?: number): void; + + /** + * Function used in the "LocalPlayerEat" and "ServerPlayerEat" callback. + */ + interface PlayerEatFunction { + /** + * You can use {@link Entity.getCarriedItem} to get info about food item. + * @param playerUid player entity UID + * @param food food amount produced by eaten food + * @param ratio saturation ratio produced by food + */ + (playerUid: number, food: number, ratio: number): void + } + + /** + * @since 2.2.1b106 + */ + function addCallback(name: "LocalPlayerEat", func: PlayerEatFunction, priority?: number): void; + + /** + * @since 2.2.1b106 + */ + function addCallback(name: "ServerPlayerEat", func: PlayerEatFunction, priority?: number): void; + + /** + * Function used in "EntityAdded" callback. + */ + interface EntityFunction { + /** + * @param entityUid entity unique ID + */ + (entityUid: number): void + } + + function addCallback(name: "EntityAdded", func: EntityFunction, priority?: number): void; + + function addCallback(name: "EntityRemoved", func: EntityFunction, priority?: number): void; + + /** + * @since 2.2.1b93 + */ + function addCallback(name: "EntityAddedLocal", func: EntityFunction, priority?: number): void; + + /** + * @since 2.2.1b93 + */ + function addCallback(name: "EntityRemovedLocal", func: EntityFunction, priority?: number): void; + + /** + * Function used in "PlayerAttack" callback. + */ + interface PlayerAttackFunction { + /** + * @param attackerUid player entity unique ID + * @param victimUid attacked entity unique ID + */ + (attackerUid: number, victimUid: number): void + } + + function addCallback(name: "PlayerAttack", func: PlayerAttackFunction, priority?: number): void; + + /** + * Function used in "EntityHurt" callback. + */ + interface EntityHurtFunction { + /** + * @param attackerUid entity that caused damage, determines actor of damage source, `-1` otherwise + * @param damageValue produced damage value in half-hearts + * @param damageType existing {@link Entity.DamageSource} or any inclusive value between 25 and 32 + * @param armorReducesDamage if `true`, damage can be reduced by armor + */ + (attackerUid: number, entityUid: number, damageValue: number, damageType: Entity.DamageSource, armorReducesDamage: boolean): void + } + + function addCallback(name: "EntityHurt", func: EntityHurtFunction, priority?: number): void; + + /** + * Function used in "EntityDeath" callback. + */ + interface EntityDeathFunction { + /** + * @param attackerUid entity that caused damage, determines actor of damage source, `-1` otherwise + * @param damageType existing {@link Entity.DamageSource} or any inclusive value between 25 and 32 + */ + (entityUid: number, attackerUid: number, damageType: Entity.DamageSource): void + } + + function addCallback(name: "EntityDeath", func: EntityDeathFunction, priority?: number): void; + + /** + * Function used in "EntityInteract" callback. + */ + interface EntityInteractFunction { + /** + * @param entityUid entity unique ID + * @param playerUid player entity unique ID + * @param coords exact vector in which interaction happened + */ + (entityUid: number, playerUid: number, coords: Vector): void + } + + function addCallback(name: "EntityInteract", func: EntityInteractFunction, priority?: number): void; + + /** + * Function used in "EntityPickUpDrop" callback. + * @since 2.2.1b88 + */ + interface EntityPickUpDropFunction { + /** + * @param entityUid entity that picked up the item + * (this callback is currently called only for players) + * @param dropEntityUid dropped item's entity + * @param item ItemInstance of the drop entity + * @param count which count of item stack + */ + (entityUid: number, dropEntityUid: number, item: ItemInstance, count: number) + } + + /** + * @since 2.2.1b88 + */ + function addCallback(name: "EntityPickUpDrop", func: EntityPickUpDropFunction, priority?: number): void; + + /** + * Function used in "ExpAdd" callback. + */ + interface ExpAddFunction { + /** + * @param exp amount of experience to be added + * @param playerUid player's unique ID + */ + (exp: number, playerUid: number): void + } + + function addCallback(name: "ExpAdd", func: ExpAddFunction, priority?: number): void; + + /** + * Function used in "ExpLevelAdd" callback. + */ + interface ExpLevelAddFunction { + /** + * @param level amount of levels to be added + * @param playerUid player's uID + */ + (level: number, playerUid: number): void + } + + function addCallback(name: "ExpLevelAdd", func: ExpLevelAddFunction, priority?: number): void; + + /** + * Function used in "ExpOrbsSpawned" callback. + */ + interface ExpOrbsSpawnedFunction { + /** + * @param amount amount of experience to be added + * @param coords dropped orbs entity coordinates + * @param playerUid player entity unique numeric ID + */ + (region: BlockSource, amount: number, coords: Vector, playerUid: number): void + } + + function addCallback(name: "ExpOrbsSpawned", func: ExpOrbsSpawnedFunction, priority?: number): void; + + /** + * Function used in "ProjectileHit" callback. + */ + interface ProjectileHitFunction { + /** + * @param projectileUid projectile entity unique ID + * @param item projectile item + * @param target object containing hit coordinates and information about + * hit entity/block + */ + (projectileUid: number, item: ItemInstance, target: ProjectileHitTarget): void + } + + /** + * Object containing hit coordinates and information about hit entity/block. + */ + interface ProjectileHitTarget { + /** + * Exact hit position x. + */ + x: number, + /** + * Exact hit position y. + */ + y: number, + /** + * Exact hit position z. + */ + z: number, + /** + * If an entity was hit, entity unique ID, `-1` otherwise. + */ + entity: number, + /** + * Coordinates and side of the hit block or null if an entity was hit. + */ + coords: Nullable + } + + function addCallback(name: "ProjectileHit", func: ProjectileHitFunction, priority?: number): void; + + /** + * @since 2.4.0b122 + */ + function addCallback(name: "ChunkLoadingStateChanged", func: World.ChunkStateChangedFunction, priority?: number): void; + + /** + * @since 2.4.0b122 + */ + function addCallback(name: "LocalChunkLoadingStateChanged", func: World.ChunkStateChangedFunction, priority?: number): void; + + /** + * Function used in all generation callbacks. + */ + interface GenerateChunkFunction { + /** + * @param chunkX chunk X coordinate; multiply by 16 to receive + * corner block coordinates + * @param chunkZ chunk Z coordinate; multiply by 16 to receive + * corner block coordinates + * @param random random object that should be used for generation + * process; already seeded by appropriate values + * @param dimensionId current dimension's numeric ID + * @param chunkSeed chunk-specific seed to use in chunk random generation + * @param worldSeed world-specific seed to use in chunk generation + * @param dimensionSeed dimension-specific seed to use in chunk generation + */ + (chunkX: number, chunkZ: number, random: java.util.Random, + dimensionId: number, chunkSeed: number, worldSeed: number, dimensionSeed: number): void + } + + function addCallback(name: "GenerateChunk", func: GenerateChunkFunction, priority?: number): void; + + /** + * @deprecated Use "GenerateChunk" with condition instead. + */ + function addCallback(name: "GenerateChunkUnderground", func: GenerateChunkFunction, priority?: number): void; + + function addCallback(name: "GenerateNetherChunk", func: GenerateChunkFunction, priority?: number): void; + + function addCallback(name: "GenerateEndChunk", func: GenerateChunkFunction, priority?: number): void; + + function addCallback(name: "GenerateChunkUniversal", func: GenerateChunkFunction, priority?: number): void; + + /** + * Function used in "GenerateCustomDimensionChunk" callback. + */ + interface GenerateCustomDimensionChunkFunction { + /** + * @param chunkX chunk X coordinate; multiply by 16 to receive + * corner block coordinates + * @param chunkZ chunk Z coordinate; multiply by 16 to receive + * corner block coordinates + * @param random random object that should be used for generation + * process; already seeded by appropriate values + * @param dimensionId current dimension's numeric ID + */ + (chunkX: number, chunkZ: number, random: java.util.Random, dimensionId: number): void + } + + function addCallback(name: "GenerateCustomDimensionChunk", func: GenerateCustomDimensionChunkFunction, priority?: number): void; + + /** + * @since 2.0.1b11 + */ + function addCallback(name: "GenerateBiomeMap", func: GenerateChunkFunction, priority?: number): void; + + /** + * @since 2.2.0b84 + */ + function addCallback(name: "PreProcessChunk", func: GenerateChunkFunction, priority?: number): void; + + /** + * @since 2.2.0b84 + */ + function addCallback(name: "PostProcessChunk", func: GenerateChunkFunction, priority?: number): void; + + /** + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + function addCallback(name: "EnchantPostAttack", func: CustomEnchant.DamageCallback, priority?: number): void; + + /** + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + function addCallback(name: "EnchantGetProtectionBonus", func: CustomEnchant.ProtectionBonusProvider, priority?: number): void; + + /** + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + function addCallback(name: "EnchantGetDamageBonus", func: CustomEnchant.AttackDamageBonusProvider, priority?: number): void; + + /** + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + function addCallback(name: "EnchantPostHurt", func: CustomEnchant.DamageCallback, priority?: number): void; + + /** + * Function used in "NativeCommand" callback. + */ + interface NativeCommandFunction { + /** + * @param command command that was entered or `null` if + * no command was providen + */ + (command: Nullable): void + } + + function addCallback(name: "NativeCommand", func: NativeCommandFunction, priority?: number): void; + + /** + * Function used in "CraftRecipePreProvided" callback. + */ + interface CraftRecipePreProvidedFunction { + /** + * @param recipe object containing recipe information + * @param field object containing crafting field information + * @param playerUid player which caused craft, since 2.4.0b122 + */ + (recipe: Recipes.WorkbenchRecipe, field: Recipes.WorkbenchField, playerUid: number): void + } + + function addCallback(name: "CraftRecipePreProvided", func: CraftRecipePreProvidedFunction, priority?: number): void; + + /** + * Function used in "CraftRecipeProvided" callback. + */ + interface CraftRecipeProvidedFunction { + /** + * @param recipe object containing recipe information + * @param field object containing crafting field information + * @param isPrevented if `true`, recipe was prevented by craft function + * @param playerUid player which caused craft, since 2.4.0b122 + */ + (recipe: Recipes.WorkbenchRecipe, field: Recipes.WorkbenchField, isPrevented: boolean, playerUid: number): void + } + + function addCallback(name: "CraftRecipeProvidedFunction", func: CraftRecipeProvidedFunction, priority?: number): void; + + /** + * Function used in "VanillaWorkbenchCraft" and "VanillaWorkbenchPostCraft" + * callbacks. + */ + interface VanillaWorkbenchCraftFunction { + /** + * @param result recipe result item + * @param workbenchContainer workbench container instance + * @param playerUid player which caused craft + */ + (result: ItemInstance, workbenchContainer: UI.Container, playerUid: number): void + } + + function addCallback(name: "VanillaWorkbenchCraft", func: VanillaWorkbenchCraftFunction, priority?: number): void; + + function addCallback(name: "VanillaWorkbenchPostCraft", func: VanillaWorkbenchCraftFunction, priority?: number): void; + + /** + * Function used in "VanillaWorkbenchRecipeSelected" callback. + */ + interface VanillaWorkbenchRecipeSelectedFunction { + /** + * @param recipe object containing recipe information + * @param result recipe result item + * @param workbenchContainer workbench container instance + */ + (recipe: Recipes.WorkbenchRecipe, result: ItemInstance, workbenchContainer: UI.Container) + } + + function addCallback(name: "VanillaWorkbenchRecipeSelected", func: VanillaWorkbenchRecipeSelectedFunction, priority?: number): void; + + /** + * Function used in "TileEntityAdded" callback. + */ + interface TileEntityAddedFunction { + (updatable: Updatable | TileEntity, isTileEntity: boolean): void + } + + function addCallback(name: "TileEntityAdded", func: TileEntityAddedFunction, priority?: number): void; + + /** + * Function used in "TileEntityRemoved" callback. + */ + interface TileEntityRemovedFunction { + (updatable: Updatable | TileEntity): void + } + + function addCallback(name: "TileEntityRemoved", func: TileEntityRemovedFunction, priority?: number): void; + + /** + * Function used in "ContainerClosed" callback. + */ + interface ContainerClosedFunction { + /** + * @param container container that was closed + * @param window window that was loaded in the container + * @param byUser if `true`, container was closed by user, + * from the code otherwise + */ + (container: UI.Container, window: UI.IWindow, byUser: boolean): void + } + + function addCallback(name: "ContainerClosed", func: ContainerClosedFunction, priority?: number): void; + + /** + * Function used in "ContainerOpened" callback. + */ + interface ContainerOpenedFunction { + /** + * @param container container that was opened + * @param window window that was loaded in the container + */ + (container: UI.Container, window: UI.IWindow): void + } + + function addCallback(name: "ContainerOpened", func: ContainerOpenedFunction, priority?: number): void; + + /** + * Function used in "NativeGuiChanged" callback. + */ + interface NativeGuiChangedFunction { + /** + * @param screenName current screen name + * @param lastScreenName previous screen name + * @param isPushEvent if `true`, the new screen was pushed to + * the screen stack, popped from the stack otherwise + */ + (screenName: string, lastScreenName: string, isPushEvent: boolean): void + } + + function addCallback(name: "NativeGuiChanged", func: NativeGuiChangedFunction, priority?: number): void; + + /** + * Function used in "CustomWindowOpened" and "CustomWindowClosed" callbacks. + */ + interface CustomWindowFunction { + /** + * @param window window that was opened + */ + (window: UI.IWindow): void; + } + + function addCallback(name: "CustomWindowOpened", func: CustomWindowFunction, priority?: number): void; + + function addCallback(name: "CustomWindowClosed", func: CustomWindowFunction, priority?: number): void; + + function addCallback(name: "AddRuntimePacks", func: { (): void }, priority?: number): void; + + function addCallback(name: "PreBlocksDefined", func: { (): void }, priority?: number): void; + + function addCallback(name: "BlocksDefined", func: { (): void }, priority?: number): void; + + /** + * Function used in "CoreConfigured" callback. + */ + interface CoreConfiguredFunction { + /** + * @param config Inner Core default config instance + */ + (config: Config): void; + } + + function addCallback(name: "CoreConfigured", func: CoreConfiguredFunction, priority?: number): void; + + function addCallback(name: "PreLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "APILoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "ModsLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "PostLoaded", func: { (): void }, priority?: number): void; + + /** + * @since 2.4.0b122 + */ + function addCallback(name: "OptionsChanged", func: { (): void }, priority?: number): void; + + /** + * Function used in "LevelSelected" callback. + */ + interface LevelSelectedFunction { + /** + * @param worldName name of the selected world + * @param worldDir name of the directory where the world is stored; worlds + * directories are located at `games/horizon/packs/Inner_Core/worlds/` + */ + (worldName: string, worldDir: string): void + } + + function addCallback(name: "LevelSelected", func: LevelSelectedFunction, priority?: number): void; + + /** + * Function used in "ConnectingToHost" callback. + */ + interface ConnectingToHostFunction { + (host: string, minecraftPort: number, moddedPort: number): void + } + + /** + * @since 2.1.0b57 + */ + function addCallback(name: "ConnectingToHost", func: ConnectingToHostFunction, priority?: number): void; + + function addCallback(name: "LevelCreated", func: { (): void }, priority?: number): void; + + /** + * Function used in "LevelLoaded" and "LevelPreLoaded" callbacks. + */ + interface LevelLoadedFunction { + /** + * @param isServer server-side or remote level is loaded + */ + (isServer: boolean): void + } + + function addCallback(name: "LevelPreLoaded", func: LevelLoadedFunction, priority?: number): void; + + function addCallback(name: "LevelLoaded", func: LevelLoadedFunction, priority?: number): void; + + function addCallback(name: "LocalLevelLoaded", func: { (): void }, priority?: number): void; + + /** + * Function used in "LocalPlayerLoaded", "ServerPlayerLoaded" and "ServerPlayerLeft" callback. + */ + interface PlayerFunction { + /** + * @param playerUid unique ID of the player entity, that has been connected to server + */ + (playerUid: number): void + } + + /** + * @since 2.2.1b106 + */ + function addCallback(name: "LocalPlayerLoaded", func: PlayerFunction, priority?: number): void; + + function addCallback(name: "RemoteLevelLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "RemoteLevelPreLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerLevelLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerLevelPreLoaded", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerPlayerLoaded", func: PlayerFunction, priority?: number): void; + + function addCallback(name: "LevelDisplayed", func: { (): void }, priority?: number): void; + + /** + * Function used in "ReadSaves" and "WriteSaves" callbacks. + * Avoid modifying values directly, consider using {@link Saver} instead. + */ + interface SavesFunction { + (globalScope: object): void + } + + function addCallback(name: "ReadSaves", func: SavesFunction, priority?: number): void; + + function addCallback(name: "WriteSaves", func: SavesFunction, priority?: number): void; + + /** + * Function used in "SystemKeyEventDispatched" callback. + */ + interface SystemKeyEventDispatchedFunction { + /** + * @param code key code of pressed button + * @param state pressing state, such as down, etc. + */ + (code: number, state: number): void + } + + function addCallback(name: "SystemKeyEventDispatched", func: SystemKeyEventDispatchedFunction, priority?: number): void; + + function addCallback(name: "NavigationBackPressed", func: { (): void }, priority?: number): void; + + function addCallback(name: "GameLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "LevelPreLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "LevelLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "LocalLevelPreLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "LocalLevelLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerLevelPreLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerLevelLeft", func: { (): void }, priority?: number): void; + + function addCallback(name: "ServerPlayerLeft", func: PlayerFunction, priority?: number): void; + + function addCallback(name: "AppSuspended", func: { (): void }, priority?: number): void; + +} diff --git a/api/core-engine/Commands.d.ts b/api/core-engine/Commands.d.ts new file mode 100644 index 000000000..9807e54cf --- /dev/null +++ b/api/core-engine/Commands.d.ts @@ -0,0 +1,19 @@ +/** + * Namespace used to manipulate Minecraft commands. + */ +declare namespace Commands { + /** + * Executes specified command. + * @param command command to be executed + * @returns Error message or null if the command was run successfully. + */ + function exec(command: string): Nullable; + + /** + * Executes specified command using specified coordinates as command + * location for all relative calculations. + * @param command command to be executed + * @returns Error message or null if the command was run successfully. + */ + function execAt(command: string, x: number, y: number, z: number): Nullable; +} diff --git a/api/core-engine/Config.d.ts b/api/core-engine/Config.d.ts new file mode 100644 index 000000000..b300b4fe6 --- /dev/null +++ b/api/core-engine/Config.d.ts @@ -0,0 +1,131 @@ +/** + * Json configuration file reading/writing utility. + */ +declare class Config { + /** + * Creates new {@link Config} instance using specified file. + * @param file {@link java.io.File} instance of the file to use + */ + constructor(file: java.io.File); + /** + * Creates new {@link Config} instance using specified file. + * @param path path to configuration file + */ + constructor(path: string); + /** + * @since 2.2.1b96 + */ + getPath(): string; + /** + * @since 2.2.1b96 + */ + reload(): void; + /** + * Writes configuration JSON to the file. + */ + save(): void; + /** + * @returns Read-only ArrayList instance containing + * all the names in the current config file. + */ + getNames(): java.util.ArrayList; + /** + * Gets property from the config. + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Config instance with current config as parent if the + * property is object, {@link org.json.JSONArray} instance if the property is an + * array, raw type if the property is of that raw type, `null` otherwise. + * + * @example + * ```ts + * config.get("generation.ore_copper.max_height"); + * ``` + */ + get>(name: string): T; + /** + * Same as {@link Config.get}. + */ + access>(name: string): T; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Boolean config value specified in config or false if no value was + * specified. + */ + getBool(name: string): boolean; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Number object instance, containing numeric value by given name + * from the config, or `0` if no value was specified. + */ + getNumber(name: string): java.lang.Number; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Integer of value by given name from the config, or `0` if no value was specified. + */ + getInteger(name: string): number; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Floating-point number of value by given name from the config, or `0.0` if no value was specified. + */ + getFloat(name: string): number; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns Double number of value by given name from the config, or `0.0` if no value was specified. + */ + getDouble(name: string): number; + /** + * @param name option name, supports multi-layer calls, separated by **'.'** + * @returns String by given name from the config, or `null` if no value was specified. + */ + getString(name: string): Nullable; + /** + * Sets config value. Do not use {@link org.json.JSONObject} instances to create + * nested objects, consider using dot-separated names instead. + * @param name option name, supports multi-layer calls, separated by **'.'** + * @param val value, may be {@link org.json.JSONArray} instance, + * {@link org.json.JSONObject} instance or raw data type + */ + set(name: string, val: T): boolean; + /** + * @param path option name, supports multi-layer calls, separated by **'.'** + * @returns Editable {@link Config.ConfigValue} instance that can be used + * to manipulate this config option separately. + */ + getValue(path: string): Nullable; + /** + * Ensures that config has all the properties the data pattern contains, if + * not, puts default values to match the pattern. + * @param jsonstr string representation of JSON object representing the data pattern + */ + checkAndRestore(jsonstr: string): void; + /** + * Ensures that config has all the properties the data pattern contains, if + * not, puts default values to match the pattern. + * @param jsonobj javascript object representing the data pattern checkAndRestore + */ + checkAndRestore(jsonobj: Scriptable): void; + /** + * Ensures that config has all the properties the data pattern contains, if + * not, puts default values to match the pattern. + * @param json {@link org.json.JSONObject} instance to be used as data pattern + */ + checkAndRestore(json: org.json.JSONObject): void; +} + +declare namespace Config { + /** + * Class representing config value with it's path withing {@link Config} object. + */ + class ConfigValue { + /** + * Sets config value and saves configuration file. + * @param value value, may be {@link org.json.JSONArray} instance, + * {@link org.json.JSONObject} instance or raw data type. + */ + set(value: T): void; + /** + * @returns Config value, result is the same as the result of {@link Config.get} call. + */ + get>(): T; + } +} diff --git a/api/core-engine/CustomBiome.d.ts b/api/core-engine/CustomBiome.d.ts new file mode 100644 index 000000000..cebd1d36f --- /dev/null +++ b/api/core-engine/CustomBiome.d.ts @@ -0,0 +1,267 @@ +/** + * Class used to create custom biomes. Note that Minecraft has a limit of 256 biomes + * and there are already more than 100 vanilla biomes, so do not overuse + * this functionality. + */ +declare class CustomBiome { + + /** + * @returns Object instance, with all custom + * biomes registered by every mod. + * @since 2.2.1b93 + */ + static getAllCustomBiomes(): java.util.Map; + + /** + * Called when server detection packet received. + * @internal + * @since 2.3.1b116 + */ + static updateNativeId(json: org.json.JSONObject): void; + + /** + * Called when server stopped to cleanup biome synced IDs. + * @internal + * @since 2.3.1b116 + */ + static reset(): void; + + /** + * @returns Whether biome is invalid. + */ + isInvalid(): boolean; + + /** + * Crates a new custom biome with specified string identifier. + * @param name string identifier of the biome + */ + constructor(name: string); + + /** + * custom biome numeric ID. + */ + readonly id: number; + + /** + * Custom biome name. + */ + readonly name: string; + + /** + * Pointer to biome's native object, + * represented as long number. + */ + readonly pointer: number; + + /** + * Sets biome's grass color. Grass color is interpolated on the bounds of + * the biome. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setGrassColor(r: number, g: number, b: number): CustomBiome; + + /** + * Sets biome's grass color. Grass color is interpolated on the bounds of + * the biome. + * @param color integer color value (you can specify it using hex value) + * @returns Reference to itself to be used in sequential calls. + */ + setGrassColor(color: number): CustomBiome; + + /** + * Sets biome's sky color. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + * @since 2.4.0b120 + */ + setSkyColor(r: number, g: number, b: number): CustomBiome; + + /** + * Sets biome's sky color. + * @param color integer color value (you can specify it using hex value) + * @returns Reference to itself to be used in sequential calls. + */ + setSkyColor(color: number): CustomBiome; + + /** + * Sets biome's foliage color. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setFoliageColor(r: number, g: number, b: number): CustomBiome; + + /** + * Sets biome's foliage color. + * @param color integer color value (you can specify it using hex value) + * @returns Reference to itself to be used in sequential calls. + */ + setFoliageColor(color: number): CustomBiome; + + /** + * Sets biome's water color. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setWaterColor(r: number, g: number, b: number): CustomBiome; + + /** + * Sets biome's water color. + * @param color integer color value (you can specify it using hex value) + * @returns Reference to itself to be used in sequential calls. + */ + setWaterColor(color: number): CustomBiome; + + /** + * Sets biome's temperature and downfall. + * @param temperature temperature value, from 0 to 1 + * @param downfall downfall value, from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setTemperatureAndDownfall(temperature: number, downfall: number): CustomBiome; + + /** + * Specifies the block that will cover the biome; e.g., most of the biomes + * use grass as cover block, though some of the biomes use other blocks + * (sand, ice, etc.). + * @param id block's tile ID + * @param data block data + * @returns Reference to itself to be used in sequential calls. + */ + setCoverBlock(id: number, data: number): CustomBiome; + + /** + * Specifies the block that will be under the covering block of the biome; + * e.g., most of the biomes use dirt as cover block, + * though some of the biomes use other blocks. + * @param id block's tile ID + * @param data block data + * @returns Reference to itself to be used in sequential calls. + */ + setSurfaceBlock(id: number, data: number): CustomBiome; + + /** + * Sets the block that fills the terrain. Vanilla biomes use stone filling. + * @param id block's tile ID + * @param data block data + * @returns Reference to itself to be used in sequential calls. + */ + setFillingBlock(id: number, data: number): CustomBiome; + + /** + * Sets the block that fills the floor at the bottom of the sea or the ocean. + * Vanilla biomes use gravel or stone filling. + * @param id block's tile ID + * @param data block data + * @returns Reference to itself to be used in sequential calls. + * @since 2.2.0b1 pre-alpha + */ + setSeaFloorBlock(id: number, data: number): CustomBiome; + + /** + * Specifies the block that will cover the biome. E.g. most of the biomes + * use grass as cover block, though some of the biomes use other blocks + * (sand, ice, etc.). + * @param id block's tile ID + * @param data block data + * @returns Reference to itself to be used in sequential calls. + * @deprecated Use {@link CustomBiome.setSurfaceBlock} instead. + */ + setAdditionalBlock(id: number, data: number): CustomBiome; + + /** + * Sets the average depth of the sea floor in this biome. + * @param depth depth of the see floor by Y-axis. + * @returns Reference to itself to be used in sequential calls. + * @since 2.2.0b1 pre-alpha + */ + setSeaFloorDepth(depth: number): CustomBiome; + + /** + * Sets the average depth of the something in this biome. + * @param depth surface depth parameter. + * @returns Reference to itself to be used in sequential calls. + * @default 7 + * @deprecated Use {@link CustomBiome.setSeaFloorDepth} instead. + * @since 2.2.0b1 pre-alpha + */ + setSurfaceParam(depth: number): CustomBiome; + + /** + * Defines the server-side biome params from given JSON string. + * @returns Reference to itself to be used in sequential calls. + * @throws Java {@link java.lang.IllegalArgumentException} if the string cannot be parsed. + * + * @example + * Many thanks to DansZbar2 for the example! + * ```js + * const CHERRY_BIOME = new CustomBiome("environmental_cherry"); + * CHERRY_BIOME.setServerJson(JSON.stringify({ + * "minecraft:climate": { + * "downfall": 0.0, + * "snow_accumulation": [ 0.0, 0.0 ], + * "temperature": 2.0, + * "blue_spores": 0, + * "red_spores": 0, + * "white_ash": 0, + * "ash": 0 + * }, + * "minecraft:overworld_height": { + * "noise_type": "default" + * }, + * "animal": {}, + * "monster": {}, + * "overworld": {}, + * "environmental_cherry": {}, + * "minecraft:surface_parameters": { + * "top_material": "minecraft:grass", + * "mid_material": "minecraft:dirt", + * "foundation_material": "minecraft:stone", + * "sea_floor_material": "minecraft:clay", + * "sea_material": "minecraft:water", + * "sea_floor_depth": 7 + * }, + * "minecraft:overworld_generation_rules": { + * "hills_transformation": "jungle_hills", + * "generate_for_climates": [ + * [ "cold", 5 ], + * [ "medium", 20 ], + * [ "warm", 35 ] + * ] + * } + * })); + * ``` + * @since 2.2.0b1 pre-alpha + */ + setServerJson(json: string): CustomBiome; + + /** + * Defines the client-side biome params from given JSON string. + * @returns Reference to itself to be used in sequential calls. + * @throws Java {@link java.lang.IllegalArgumentException} if the string cannot be parsed. + * + * @example + * Many thanks to DansZbar2 for the example! + * ```js + * const CHERRY_BIOME = new CustomBiome("environmental_cherry"); + * CHERRY_BIOME.setClientJson(JSON.stringify({ + * "water_surface_color": "#d176e1", + * "water_fog_color": "#a35dc2", + * "water_surface_transparency": 0.7, + * "water_fog_distance": 11, + * // custom fog defined in the addon + * "fog_identifier": "environmental:environmental_cherry" + * })); + * ``` + * @since 2.2.0b1 pre-alpha + */ + setClientJson(json: string): CustomBiome; +} diff --git a/api/core-engine/CustomEnchant.d.ts b/api/core-engine/CustomEnchant.d.ts new file mode 100644 index 000000000..fa4b7094b --- /dev/null +++ b/api/core-engine/CustomEnchant.d.ts @@ -0,0 +1,144 @@ +/** + * Module to create custom enchantments. + * @since 2.2.1b105 + */ +declare namespace CustomEnchant { + + /** + * Object returned by {@link CustomEnchant.newEnchant} method. + * Used to configure different custom enchantment behaviors. + */ + interface EnchantSetupInterface { + + /** + * The numeric ID of the following enchantment + * to be used in different operations. + * This ID will not change after the first generation, + * same as it works with blocks' and items' IDs. + */ + readonly id: number; + + /** + * Sets the following enchantment frequency, possibly used in treasures. + * @default 3 + * @returns Reference to itself to be used in sequential calls. + */ + setFrequency(freq: number): EnchantSetupInterface; + + /** + * Sets whether the following enchantment will be able + * to be found in dungeon chests or not. + * @default true + * @returns Reference to itself to be used in sequential calls. + */ + setIsLootable(lootable: boolean): EnchantSetupInterface; + + /** + * Sets whether the following enchantment will be able + * to be received on the enchanting table or not. + * @default true + * @returns Reference to itself to be used in sequential calls. + */ + setIsDiscoverable(discoverable: boolean): EnchantSetupInterface; + + /** + * Sets whether the following enchantment will be able + * to be caught during fishing as a treasure, or not. + * @default false + * @returns Reference to itself to be used in sequential calls. + */ + setIsTreasure(treasure: boolean): EnchantSetupInterface; + + /** + * Sets the mask of items, that the following enchantment can be applied to, + * paired parameter for item is enchant slot. + * @returns Reference to itself to be used in sequential calls. + * @default -1 = 0xFFFFFFFF // all + */ + setMask(mask: number): EnchantSetupInterface; + + /** + * Sets minimum and maximum level, that the following enchantment + * will be able to have in legal conditions. + * @default min: 1, max: 5 + * @returns Reference to itself to be used in sequential calls. + */ + setMinMaxLevel(min: number, max: number): EnchantSetupInterface; + + /** + * Sets linear dependency of enchant cost by level, + * the formula is `level * b + c`. + * @returns Reference to itself to be used in sequential calls. + */ + setMinMaxCost(bMin: number, cMin: number, bMax: number, cMax: number): EnchantSetupInterface; + + /** + * Defines the function that will be called, when item with following enchantment is used for attack. + * The function must return bonus damage dealt to the victim. + * @returns Reference to itself to be used in sequential calls. + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + setAttackDamageBonusProvider(func: AttackDamageBonusProvider): EnchantSetupInterface; + + /** + * Defines the function that will be called after the item with following enchantment is used for attack. + * @returns Reference to itself to be used in sequential calls. + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + setPostAttackCallback(func: DamageCallback): EnchantSetupInterface; + + /** + * Defines the function that will be called, when the entity wearing item + * with following enchantment, is hit. + * The function must return bonus protection value. + * @returns Reference to itself to be used in sequential calls. + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + setProtectionBonusProvider(func: ProtectionBonusProvider): EnchantSetupInterface; + + /** + * Defines the function that will be called, when the entity wearing item + * with following enchantment, is hit. + * @returns Reference to itself to be used in sequential calls. + * @since 2.3.1b115 (implemented in 2.2.1b105) + */ + setPostHurtCallback(func: DamageCallback): EnchantSetupInterface; + + } + + /** + * Registers new custom enchantment from given name ID and displayed name. + * @param nameID internal string ID of the enchantment + * @param displayedName enchantment name that will be displayed in the + * tooltips of the items having this enchant. + * Use {@link Translation} module to make localization of the displayed name + * @returns Object to work with different enchantment behaviors. + */ + function newEnchant(nameID: string, displayedName: string): EnchantSetupInterface; + + /** + * Function interface used in + * {@link EnchantSetupInterface.setAttackDamageBonusProvider EnchantSetupInterface.setAttackDamageBonusProvider} method. + */ + interface AttackDamageBonusProvider { + (damage: number, entity: number): number; + } + + /** + * Function interface used in + * {@link EnchantSetupInterface.setPostAttackCallback EnchantSetupInterface.setPostAttackCallback} and + * {@link EnchantSetupInterface.setPostHurtCallback EnchantSetupInterface.setPostHurtCallback} methods. + */ + interface DamageCallback { + (item: ItemInstance, damage: number, entity1: number, entity2: number): void; + } + + /** + * Function interface used in + * {@link EnchantSetupInterface.setProtectionBonusProvider EnchantSetupInterface.setProtectionBonusProvider} method. + */ + interface ProtectionBonusProvider { + (damage: number, damageType: number, entity: number): number; + } + +} \ No newline at end of file diff --git a/api/core-engine/CustomEntity.d.ts b/api/core-engine/CustomEntity.d.ts new file mode 100644 index 000000000..2e32e092d --- /dev/null +++ b/api/core-engine/CustomEntity.d.ts @@ -0,0 +1,112 @@ +/** + * @deprecated Use behavior packs to creating entities. + */ +declare namespace MobRegistry { + function registerEntity(name: any): CustomEntity; + + function registerUpdatableAsEntity(updatable: any): void; + + function spawnEntityAsPrototype(typeName: any, coords: any, extraData: any): CustomEntity; + + function getEntityUpdatable(entity: number): CustomEntity; + + // /** + // * @deprecated Not implemented yet. + // */ + // function registerNativeEntity(entity: number): undefined; + + function registerEntityRemove(entity: number): void; + + function resetEngine(): void; +} + +/** + * @deprecated Use behavior packs to register spawning + * entities in server or use callbacks. + */ +declare namespace MobSpawnRegistry { + function registerSpawn(entityType: number, rarity: number, condition?: () => boolean, denyNaturalDespawn?: boolean): void; + + interface SpawnInterface { + type: number, + rarity: number, + condition: () => boolean, + denyNaturalDespawn?: boolean; + } + + function getRandomSpawn(rarityMultiplier: number): any; + + function getRandPosition(): { x: number, z: number }; + + function executeSpawn(spawn: SpawnInterface, position: { x: number, z: number }): void; +} + +/** + * @deprecated Use behavior packs instead. + */ +declare class CustomEntity { + readonly nameId: string; + readonly isInstance: boolean; + readonly entity: Nullable; + addController(name: string, basicPrototype: any): CustomEntity; + customizeController(name: string, customPrototype: object): void; + /** + * Customizes controller "event". + */ + customizeEvents(custom: object): void; + /** + * Customizes controller "description". + */ + customizeDescription(custom: object): void; + /** + * Customizes controller "visual". + */ + customizeVisual(custom: object): void; + /** + * Customizes controller "AI". + */ + customizeAI(custom: object): void; + setBaseType(type: number): void; + callControllerEvent(event: string, ...params: any[]): void; + setNativeEntity(entity: number): void; + recreateEntity(): void; + getPlayerDistance(): number; + denyDespawn(): void; + allowNaturalDespawn(): void; + destroy(): void; +} + +/** + * @deprecated Use resource packs or {@link Render} instead. + */ +declare class EntityModel { + constructor(parentModel?: EntityModel); + readonly isAnimated: boolean; + readonly animator: any; + /** + * @internal + */ + applyTextureResolution(): void; + setTexture(texture: Texture): EntityModel; + getTextureObj(): Texture; + getTexture(): string; + getTextureResolution(): number; + setRender(render: Render): void; + createAnimation(ticks: number, func: (tick: number, self: EntityModel) => Nullable, delay: number): EntityModel; + resetAnimation(token: number): void; + getTextureAndRender(token: number): { texture: Texture, render: number }; +} + +/** + * @deprecated Use resource packs to customize entities + * appearance or {@link Render} with {@link AttachableRender}. + */ +declare class EntityModelWatcher { + constructor(entity: number, model: EntityModel); + readonly model: EntityModel; + readonly entity: number; + readonly token: number; + update(): void; + resetAnimation(): void; + destroy(): void; +} diff --git a/api/core-engine/Debug.d.ts b/api/core-engine/Debug.d.ts new file mode 100644 index 000000000..0b6bf7765 --- /dev/null +++ b/api/core-engine/Debug.d.ts @@ -0,0 +1,63 @@ +/** + * Defines some useful methods for debugging. + */ +declare namespace Debug { + + /** + * @returns Current system time in milliseconds. + */ + function sysTime(): number; + + /** + * Spawns vanilla debug particle on the specified coordinates. + * @param id particle type ID, should be one of the {@link EParticleType} + * @param vx x velocity + * @param vy y velocity + * @param vz y velocity + * @param data additional particles data + */ + function addParticle(id: number, x: number, y: number, z: number, vx: number, vy: number, vz: number, data: number): void; + + /** + * Writes general debug message (in green) to local player in chat. + * @param message message to be displayed + */ + function message(message: any): void; + + /** + * Writes warning debug message (in gold) to local player in chat. + * @param message message to be displayed + */ + function warning(message: any): void; + + /** + * Writes error debug message (in red) to local player in chat. + * @param message message to be displayed + */ + function error(message: any): void; + + /** + * Writes several comma-separated values to local player in chat as + * a general debug message, serializing javascript objects if possible. + * @param args messages to be displayed + * @since 2.0.5b44 + */ + function m(...args: any[]): void; + + /** + * Displays an {@link android.app.AlertDialog} with given title and bitmap. + * @param bitmap android.graphics.Bitmap object of the bitmap to be + * displayed + * @param title title of the AlertDialog + */ + function bitmap(bitmap: android.graphics.Bitmap, title?: any): void; + + /** + * Writes several values in JSON format to the selectable + * alert window text view, serializing javascript objects if possible. + * @param args messages to be displayed + * @since 2.0.5b44 + */ + function big(...args: any[]): void; + +} diff --git a/api/core-engine/Dimensions.d.ts b/api/core-engine/Dimensions.d.ts new file mode 100644 index 000000000..b51e78cd2 --- /dev/null +++ b/api/core-engine/Dimensions.d.ts @@ -0,0 +1,508 @@ +/** + * Namespace used to create and manipulate custom dimensions. + */ +declare namespace Dimensions { + /** + * Class representing custom dimension. + */ + class CustomDimension { + /** + * Constructs a new dimension with specified name and preferred ID. + * @param name dimension name, can be used to get dimension via + * {@link Dimensions.getDimensionByName} call + * @param preferredId preferred dimension ID. If ID is already occupied + * by some another dimension, constructor will look for the next empty + * dimension ID and assign it to the current dimension + */ + constructor(name: string, preferredId: number); + + /** + * Custom dimension ID. + */ + id: number; + + /** + * Sets custom landscape generator. + * @param generator custom landscape generator used for current + * dimension + * @returns Reference to itself to be used in sequential calls. + */ + setGenerator(generator: CustomGenerator): CustomDimension; + + /** + * Specifies whether the sky produces light (like in overworld) or not + * (like in the End or Nether). + * @param hasSkyLight if true, the sky produces light in the dimension + * @returns Reference to itself to be used in sequential calls. + * @default true + */ + setHasSkyLight(hasSkyLight: boolean): CustomDimension; + + /** + * @returns Whether the sky produces light in the current dimension. + */ + hasSkyLight(): boolean; + + /** + * Sets sky color for the dimension in the RGB format. Default + * color is as in the Overworld. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setSkyColor(r: number, g: number, b: number): CustomDimension; + + /** + * Resets sky color to the default value. + * @returns Reference to itself to be used in sequential calls. + */ + resetSkyColor(): CustomDimension; + + /** + * Sets fog color for the dimension in the RGB format. Default + * color is as in the Overworld. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setFogColor(r: number, g: number, b: number): CustomDimension; + + /** + * Resets fog color to the default value. + * @returns Reference to itself to be used in sequential calls. + */ + resetFogColor(): CustomDimension; + + /** + * Sets clouds color for the dimension in the RGB format. Default + * color is as in the Overworld. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setCloudColor(r: number, g: number, b: number): CustomDimension; + + /** + * Resets clouds color to the default value. + * @returns Reference to itself to be used in sequential calls. + */ + resetCloudColor(): CustomDimension; + + /** + * Sets sunset sky color for the dimension in the RGB format. Default + * color is as in the Overworld. + * @param r red color component, value from 0 to 1 + * @param g green color component, value from 0 to 1 + * @param b blue color component, value from 0 to 1 + * @returns Reference to itself to be used in sequential calls. + */ + setSunsetColor(r: number, g: number, b: number): CustomDimension; + + /** + * Resets sunset sky color to the default value. + * @returns Reference to itself to be used in sequential calls. + */ + resetSunsetColor(): CustomDimension; + + /** + * Sets fog displaying distance. + * @param start nearest fog distance + * @param end farthest fog distance + * @returns Reference to itself to be used in sequential calls. + * @since 2.0.2b20 + */ + setFogDistance(start: number, end: number): CustomDimension; + + /** + * Resets fog displaying distance. + * @returns Reference to itself to be used in sequential calls. + * @since 2.0.2b20 + */ + resetFogDistance(): CustomDimension; + } + + /** + * Class representing landscape generator used for the dimension. + */ + class CustomGenerator { + /** + * Creates a new {@link Dimensions.CustomGenerator} instance using specified base type. + * @param baseType base generator type constant, can be from 0 to 4. 0 + * and 1 represent overworld generator, 2 represents flat world + * generator, 3 represents nether generator and 4 represents end + * generator + */ + constructor(baseType: number); + + /** + * Creates a new {@link Dimensions.CustomGenerator} instance using specified base type. + * @param baseType base generator type constant, can be one of the + * following: "overworld", "overworld1", "flat", "nether", "end" + */ + constructor(baseType: string); + + /** + * Specifies whether to use vanilla biome surface cover blocks (grass, + * sand, podzol, etc.). + * @param value if `true`, vanilla surface will be generated + * @default false + * @returns Reference to itself to be used in sequential calls. + */ + setBuildVanillaSurfaces(value: boolean): CustomGenerator; + + /** + * Specifies whether to generate minecraft vanilla structures. + * @param value if `true`, vanilla structures will be generated + * @default false + * @returns Reference to itself to be used in sequential calls. + */ + setGenerateVanillaStructures(value: boolean): CustomGenerator; + + /** + * Specifies whether to use mod's generation callbacks. + * @param value if `true`, mod generation will be used + * @default true + * @returns Reference to itself to be used in sequential calls. + */ + setGenerateModStructures(value: boolean): CustomGenerator; + + /** + * Determines whether the generator should generate underground + * and/or underwater caves as part of its result. + * Wworks only with the "overworld"1" and "flat" base types. + * @param caves generate caves + * @param underwaterCaves generate large caves and canyons + * @since 2.3.1b115 + */ + setGenerateCaves(caves: boolean, underwaterCaves?: boolean): CustomDimension; + + /** + * Sets terrain generator object used for the landscape generation. + * @param generator terrain generator to be used with current landscape + * generator or removes terrain generator, if the value is null + * @returns Reference to itself to be used in sequential calls. + */ + setTerrainGenerator(generator: Nullable): CustomGenerator; + + /** + * Specifies which of the generation {@link Callback Callbacks} to call, `-1` to call + * no mods generation, `0` to call overworld generation callback, `1` for nether, + * `2` for end generation callbacks. + * @param id generation callback to call + * @returns Reference to itself to be used in sequential calls. + */ + setModGenerationBaseDimension(id: number): CustomGenerator; + + /** + * Disables mods generation in current generator. + * @returns Reference to itself to be used in sequential calls. + */ + removeModGenerationBaseDimension(): CustomGenerator; + } + + /** + * Interface representing terrain generator. All terrain generators found + * in Inner Core API implement this interface. + */ + interface AbstractTerrainGenerator {} + + /** + * Class representing terrain that consists of single biome. + */ + class MonoBiomeTerrainGenerator implements AbstractTerrainGenerator { + /** + * Constructs new {@link Dimensions.MonoBiomeTerrainGenerator MonoBiomeTerrainGenerator} + * instance with no terrain layers. + */ + constructor(); + + addTerrainLayer(minY: number, maxY: number): TerrainLayer; + + /** + * Sets base biome for the current terrain. + * @param id ID of the biome to be used as a single biome of the terrain + * layer + */ + setBaseBiome(id: number): MonoBiomeTerrainGenerator; + } + + /** + * Class representing single terrain layer that may consist of several noise + * layers. + */ + interface TerrainLayer { + addNewMaterial(generator: NoiseGenerator, priority: number): TerrainMaterial; + + setHeightmapNoise(generator: NoiseGenerator): TerrainLayer; + + setMainNoise(generator: NoiseGenerator): TerrainLayer; + + setYConversion(conversion: NoiseConversion): TerrainLayer; + + getMainMaterial(): TerrainMaterial; + } + + /** + * Class representing material that is used to generate terrain layer. + */ + interface TerrainMaterial { + + setBase(id: number, data: number): TerrainMaterial; + + setCover(id: number, data: number): TerrainMaterial; + + setSurface(width: number, id: number, data: number): TerrainMaterial; + + setFilling(width: number, id: number, data: number): TerrainMaterial; + + setDiffuse(value: number): TerrainMaterial; + } + + /** + * Class representing noise conversion function. Used to define "density" of + * the landscape at a given height. Values between nodes are interpolated + * linearly. + */ + class NoiseConversion { + constructor(); + + /** + * Adds a new node to the noise conversion function. + * @param x value from 0 to 1 representing the height of the block in the + * terrain layer + * @param y landscape density at a given height, generally can be between + * -0.5 and 0.5. Values between nodes are interpolated linearly + */ + addNode(x: number, y: number): NoiseConversion; + } + + /** + * Class representing multi-layer noise generator. + */ + class NoiseGenerator { + constructor(); + + addLayer(layer: NoiseLayer): NoiseGenerator; + + setConversion(conversion: NoiseConversion): NoiseGenerator; + } + + /** + * Class representing single noise layer. + */ + class NoiseLayer { + constructor(); + + addOctave(octave: NoiseOctave): NoiseLayer; + + setConversion(conversion: NoiseConversion): NoiseLayer; + } + + type NoiseOctaveStringType = "perlin" | "gray" | "chess" | "sine_x" | "sine_y" | "sine_z" | "sine_xy" | "sine_yz" | "sine_xz" | "sine_xyz"; + /** + * Class representing noise octave. Each noise layer consists of multiple + * noise octaves of different scale and weight. + */ + class NoiseOctave { + /** + * Creates a new noise octave of specified type. + * @param type numeric type constant or one of the following strings: + * + * **"perlin"** (0) is a general-purpose noise generator. + * + * Used to generate noise of completely random nature + * **"gray"** (1) + * **"chess"** (2) + * + * The following sine noises are used to generate sinusoidal noise. + * Generally they should be used with some noise octaves of other types to avoid + * too mathematical landscapes + * **"sine_x"** (10) + * **"sine_y"** (11) + * **"sine_z"** (12) + * **"sine_xy"** (13) + * **"sine_yz"** (14) + * **"sine_xz"** (15) + * **"sine_xyz"** (16) + */ + constructor(type?: number | NoiseOctaveStringType); + + setTranslate(x: number, y: number, z: number): NoiseOctave; + + setScale(x: number, y: number, z: number): NoiseOctave; + + setWeight(weight: number): NoiseOctave; + + setSeed(x: number, y: number, z: number): NoiseOctave; + + setConversion(conversion: NoiseConversion): NoiseOctave; + } + + /** + * Overrides default generator of vanilla dimension. + * @param id vanilla dimension ID, one of the {@link EDimension} + * values + * @param generator custom landscape generator used for vanilla + * dimension + */ + function overrideGeneratorForVanillaDimension(id: number, generator: CustomGenerator): void; + + /** + * @param name dimension name + * @returns Dimension by it's string name specified in + * {@link Dimensions.CustomDimension CustomDimension} constructor. + */ + function getDimensionByName(name: string): CustomDimension; + + /** + * @param id dimension ID + * @returns Custom dimension by it's numeric ID. + */ + function getDimensionById(id: number): CustomDimension; + + /** + * @param id dimension ID + * @returns `true`, if dimension is a limbo dimension; limbo dimension is + * created by Horizon automatically if you try to teleport the player to + * non-existing dimension + */ + function isLimboId(id: number): boolean; + + /** + * Transfers specified entity to the dimension with specified ID. + * @param entity numeric ID of the + * @param dimensionId numeric ID of the dimension to transfer the entity to + */ + function transfer(entity: number, dimensionId: number): void; + + /** + * @returns JS object instance, containing all registered custom biomes. + * @since 2.2.1b93 + */ + function getAllRegisteredCustomBiomes(): { [key: string]: CustomBiome }; + + /** + * Function used to simplify the creation of terrain generator by passing + * a json-like structure as a single generator parameter. + * @param description object containing all the required generator information + */ + function newGenerator(description: { + /** + * Specifies base generator, see {@link Dimensions.CustomGenerator CustomGenerator} + * constructor for details. + */ + base?: number | string, + + /** + * Specifies whether to use vanilla biome surface cover blocks + * (grass, sand, podzol, etc.). + * + * See {@link Dimensions.CustomGenerator.setBuildVanillaSurfaces setBuildVanillaSurfaces} for details. + */ + buildVanillaSurfaces?: boolean, + + /** + * Specifies whether to generate minecraft vanilla structures. + * + * See {@link Dimensions.CustomGenerator.setGenerateVanillaStructures setGenerateVanillaStructures} for details. + */ + generateVanillaStructures?: boolean, + + /** + * Can be either string for an existing dimensions (**"overworld"**, + * **"nether"**, **"end"**) or -1 to disable mods generation. + * + * See {@link Dimensions.CustomGenerator.setModGenerationBaseDimension setModGenerationBaseDimension} for details. + */ + modWorldgenDimension?: number | string, + + /** + * Specifies what generator type to use. Default and the only currently + * available option is "mono", that is equivalent to creating a + * {@link MonoBiomeTerrainGenerator}. + */ + type?: string, + + /** + * Sets base biome for the current terrain, applicable only to **"mono"**. + */ + biome?: number, + + /** + * An array of terrain layers descriptions, each one representing it's + * own terrain layer. + * + * See {@link Dimensions.MonoBiomeTerrainGenerator.addTerrainLayer MonoBiomeTerrainGenerator.addTerrainLayer} for details. + */ + layers?: TerrainLayerParams[] + + }): CustomGenerator; + + interface TerrainLayerParams { + minY: number, + maxY: number, + noise?: NoiseOctaveParams | NoiseLayerParams | NoiseGeneratorParams, + heightmap?: NoiseOctaveParams | NoiseLayerParams | NoiseGeneratorParams, + yConversion?: NoiseConversionParams, + material?: TerrainMaterialParams, + materials?: TerrainMaterialParams[], + } + + interface TerrainMaterialParams { + noise?: NoiseOctaveParams | NoiseLayerParams | NoiseGeneratorParams, + base?: MaterialBlockData, + cover?: MaterialBlockData, + surface?: MaterialBlockData, + filling?: MaterialBlockData, + diffuse?: number + } + + interface NoiseGeneratorParams { + layers: NoiseLayerParams[], + conversion?: NoiseConversionParams, + } + + interface NoiseLayerParams { + octaves: NoiseOctaveParams[] | { + count?: number, + seed?: number, + weight?: number, + weight_factor?: number, + scale_factor?: number, + scale?: number + }, + conversion?: NoiseConversionParams + } + + interface NoiseOctaveParams { + /** + * Noise octave type, see {@link Dimensions.NoiseOctave} for details. + * @default "perlin" + */ + type?: number | string, + scale?: Vec3Data, + weight?: number, + seed?: number, + conversion?: NoiseConversionParams + } + + type NoiseConversionParams = string | Vec2Data[]; + + type MaterialBlockData = + [number, number?, number?] | + { id: number, data?: number, width?: number } | + number; + + type Vec3Data = + [number, number, number] | + { x: number, y: number, z: number } | + number; + + type Vec2Data = + [number, number] | + { x: number, y: number } | + number +} diff --git a/api/core-engine/ECS.d.ts b/api/core-engine/ECS.d.ts new file mode 100644 index 000000000..451a6c64e --- /dev/null +++ b/api/core-engine/ECS.d.ts @@ -0,0 +1,200 @@ +/** + * @since 2.3.1b115 + */ +declare namespace ECS { + function getEntityManager(): EcsEntityManager; + function getTypeName(id: number): string; + function getTypeId(name: string): number; + /** + * Same as {@link ECS_INVALID_ENTITY}. + */ + function getInvalidEntity(): number; + /** + * Same as {@link ECS_TAG_OBJECT}. + */ + function getTagComponentObject(): any; + + interface LocalTicking { + tick(queue: EcsActionQueue): void; + } + + interface ServerTicking { + tick(queue: EcsActionQueue): void; + } + + interface VariadicQueryConsumer { + (entity: number, components: any[]): void; + } + + interface FixedQueryConsumer0 { + (entity: number): void; + } + + interface FixedQueryConsumer1 { + (entity: number, query1: T1): void; + } + + interface FixedQueryConsumer2 { + (entity: number, query1: T1, query2: T2): void; + } + + interface FixedQueryConsumer3 { + (entity: number, query1: T1, query2: T2, query3: T3): void; + } + + interface FixedQueryConsumer4 { + (entity: number, query1: T1, query2: T2, query3: T3, query4: T4): void; + } + + interface FixedQueryConsumer5 { + (entity: number, query1: T1, query2: T2, query3: T3, query4: T4, query5: T5): void; + } + + interface FixedQueryConsumer6 { + (entity: number, query1: T1, query2: T2, query3: T3, query4: T4, query5: T5, query6: T6): void; + } +} + +/** + * @since 2.3.1b115 + */ +declare interface EcsEntityManager { + /* static */ INVALID_ENTITY: number; + /* static */ TAG: java.lang.Object; + createEntity(): number; + removeEntity(entity: number): void; + detachEntity(entity: number): EcsAddComponents; + extend(entity: number, components: EcsAddComponents): void; + shrink(entity: number, components: EcsRemoveComponents): void; + removeAllEntitiesWithComponents(query: EcsQuery): void; + performVariadicQuery(query: EcsQuery, consumer: ECS.VariadicQueryConsumer): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer0): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer1): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer2): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer3): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer4): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer5): void; + performQuery(query: EcsQuery, consumer: ECS.FixedQueryConsumer6): void; + getComponents(entity: number, query: EcsQuery): any[]; + getComponent(entity: number, index: number): any; +} + +/** + * @since 2.3.1b115 + */ +declare class IntFlatMap { + constructor(); + constructor(emptyKey: number); + get(key: number, defaultValue: number): number; + put(key: number, value: number): boolean; + remove(key: number): boolean; + clearNoDealloc(): void; + clear(): void; + reserve(newCount: number): void; +} + +/** + * @since 2.3.1b115 + */ +declare class EcsQuery { + constructor(...queries: object[]); +} + +/** + * @since 2.3.1b115 + */ +declare class EcsAddComponents { + constructor(); + addComponent(type: number | string, value: any): EcsAddComponents; + addComponent(type: java.lang.Class, value: T): EcsAddComponents; + setTypes(...types: number[] | string[]): EcsAddComponents; + setTypes(...types: java.lang.Class[]): EcsAddComponents; + setValues(...values: object[]): EcsAddComponents; + empty(): boolean; +} + +/** + * @since 2.3.1b115 + */ +declare class EcsRemoveComponents { + constructor(); + addComponent(type: number | string): EcsRemoveComponents; + addComponent(type: java.lang.Class): EcsRemoveComponents; + setTypes(...types: number[] | string[]): EcsRemoveComponents; + setTypes(...types: java.lang.Class[]): EcsRemoveComponents; + empty(): boolean; +} + +/** + * @since 2.3.1b115 + */ +declare class EcsActionQueue { + constructor(); + createEntity(): number; + getEntityCount(): number; + removeEntity(entity: number): EcsActionQueue; + addComponent(entity: number, type: number | string, value: any): EcsActionQueue; + addComponent(entity: number, type: java.lang.Class, value: any): EcsActionQueue; + extend(entity: number, components: EcsAddComponents): EcsActionQueue; + extend(entity: number, types: number[], values: any[], count: number): EcsActionQueue; + removeComponent(entity: number, type: number | string): EcsActionQueue; + removeComponent(entity: number, type: java.lang.Class): EcsActionQueue; + shrink(entity: number, components: EcsRemoveComponents): EcsActionQueue; + shrink(entity: number, types: number[], count: number): EcsActionQueue; + flush(): void; + clear(): void; + /** + * Does {@link flush}() and {@link clear}() at same time. + */ + flushNoClear(): void; + reserve(entityCount: number): void; +} + +/** + * @since 2.3.1b115 + */ +declare interface EcsComponent { + /* static */ COMPONENT_ID: number +} + +/** + * @since 2.3.1b115 + */ +declare interface EcsBlockComponent extends EcsComponent { + id: number; + nameId: string; + name: string; +} + +/** + * @since 2.3.1b115 + */ +declare interface EcsItemComponent extends EcsComponent { + id: number; + nameId: string; + name: string; +} + +/** + * @since 2.3.1b115 + */ +declare interface EcsArmorItemComponent extends EcsComponent, Armor.IArmorInfo { + slot: number; + protection: number; + kbResist: number; // knockback +} + +/** + * @since 2.3.1b115 + */ +declare const EntityManager: EcsEntityManager; + +/** + * @since 2.3.1b115 + */ +declare const ECS_INVALID_ENTITY: object; + +/** + * @since 2.3.1b115 + */ +declare const ECS_TAG_OBJECT: object; diff --git a/api/core-engine/Entity.d.ts b/api/core-engine/Entity.d.ts new file mode 100644 index 000000000..3360a64e8 --- /dev/null +++ b/api/core-engine/Entity.d.ts @@ -0,0 +1,1002 @@ +/** + * Module used to manipulate entities (mobs, drop, arrows, etc.) in the world. + * Every entity has it's unique numeric ID which is often used across this module + * as the first function parameter. + */ +declare namespace Entity { + /** + * @returns An array of all server entities UIDs. + */ + function getAll(): number[]; + + /** + * @returns An array of all server entities UIDs. + * @deprecated Consider using {@link Entity.getAll} instead. + */ + function getAllJS(): number[]; + + /** + * @returns An array of all client entities UIDs. + * @since 2.4.0b120 + */ + function getAllLocal(): number[]; + + /** + * @deprecated Use attributes instead, or {@link Saver}. + */ + function getExtra(entityUid: number, name: string): null; + + /** + * @deprecated Use attributes instead, or {@link Saver}. + */ + function putExtra(entityUid: number, name: string, extra?: object): void; + + /** + * @deprecated Use attributes instead, or {@link Saver}. + */ + function getExtraJson(entityUid: number, name: string): object; + + /** + * @deprecated Use attributes instead, or {@link Saver}. + */ + function putExtraJson(entityUid: number, name: string, obj: object): void; + + /** + * Adds an effect to entity. + * @param effectId effect ID, should be one one of {@link EPotionEffect} values + * @param effectData effect amplifier + * @param effectTime effect time in ticks + * @param ambience if true, particles are ambient + * @param particles if true, particles are not displayed + */ + function addEffect(entityUid: number, effectId: number, effectData: number, effectTime: number, ambience?: boolean, particles?: boolean): void; + + /** + * Adds an effect to entity. + * @param effectId effect ID, should be one one of {@link EPotionEffect} values + * @param effectData effect amplifier + * @param effectTime effect time in ticks + * @param ambience if true, particles are ambient + * @param particles if true, particles are not displayed + * @param effectAnimation if true, flashing are displayed + * @since 2.3.1b116 + */ + function addEffect(entityUid: number, effectId: number, effectData: number, effectTime: number, ambience: boolean, particles: boolean, effectAnimation: boolean): void; + + /** + * @param effectId numeric ID of the potion effect, + * one of {@link EPotionEffect} values + * @returns Whether the given entity is affected by the potion effect with given numeric ID. + * @since 2.2.1b102 + */ + function hasEffect(entity: number, effectId: number): boolean; + + /** + * @returns Object with duration and level of the potion effect with given numeric ID + * on the given entity. These fields are set to 0, if the given effect doesn't affect + * the given entity at the moment. + * @since 2.2.1b102 + */ + function getEffect(entity: number, effectId: number): EffectInstance; + + interface EffectInstance { + level: number; + duration: number; + } + + /** + * Clears effect, applied to the mob. + * @param id effect ID, should be one of the {@link EPotionEffect} + */ + function clearEffect(entityUid: number, id: number): void; + + /** + * Clears all effects of the mob. + */ + function clearEffects(entityUid: number): void; + + /** + * Damage sources, which are used to determine entity damage type: + * + * Type | Name | Message | Translation + * ---|---|---|--- + * 0 | Generic | "death.attack.generic" (fallback damage source) | * died + * 1 | Cactus | "death.attack.cactus" (only when standing on cactus) | * was pricked to death + * 2 | Mob | "death.attack.mob" | * was slain by * + * 3 | Impact | n/a + * 4 | In Wall | "death.attack.inWall" | * suffocated in a wall + * 5 | Fall | "death.attack.fall" OR "death.fell.accident.generic" | * hit the ground too hard OR * fell from a high place + * 6 | In Fire | "death.attack.inFire" | * went up in flames + * 7 | On Fire | "death.attack.onFire" | * burned to death + * 8 | Lava | "death.attack.lava" | * tried to swim in lava + * 9 | Drown | "death.attack.drown" | * drowned + * 10 | Explosion | "death.attack.explosion" | * blew up + * 11 | Explosion (Player) | "death.attack.explosion" | * was blown up by * + * 12 | Out Of World | "death.attack.outOfWorld" | * fell out of the world + * 13 | Command | n/a + * 14 | Magic | "death.attack.magic" | * was killed by magic + * 15 | Wither | "death.attack.wither" | * withered away + * 16 | Starve | "death.attack.starve" | * starved to death + * 17 | Anvil | "death.attack.anvil" | * was squashed by a falling anvil + * 18 | Thorns | "death.attack.thorns" | * was killed trying to hurt * + * 19 | Projectile | n/a + * 20 | Falling Block | "death.attack.fallingBlock" | * was squashed by a falling block + * 21 | Fly Into Wall | "death.attack.flyIntoWall" | * experienced kinetic energy + * 22 | Magma | "death.attack.magma" | * discovered floor was lava + * 23 | Fireworks | "death.attack.fireworks" | * went off with a bang + * 24 | Lightning Bolt | "death.attack.lightningBolt" | * was struck by lightning + */ + type DamageSource = number; + + /** + * Damages entity. + * @param damage damage value in half-hearts + * @param cause existing {@link DamageSource} or any inclusive value between 25 and 32 + * @param properties additional damage source properties + */ + function damageEntity(entityUid: number, damage: number, cause?: DamageSource, properties?: { + /** + * Entity that caused damage, determines actor of damage source. + */ + attacker?: number, + /** + * If `true`, damage can be reduced by armor. + */ + bool1?: boolean + }): void; + + /** + * Adds specified health amount to the entity. + * @param heal health to be added to entity, in half-hearts + */ + function healEntity(entityUid: number, heal: number): void; + + /** + * @returns Numeric entity type, one of the {@link EEntityType}. + */ + function getType(entityUid: number): number; + + /** + * @returns String entity type, like `minecraft:chicken<>` (`:[]`). + */ + function getTypeName(entityUid: number): string; + + /** + * @returns String type for entities defined via add-ons or numeric type for + * all the other entities. + */ + function getTypeUniversal(entityUid: number): number | string; + + /** + * @returns String type for entities defined via add-ons, otherwise `null`. + * @remarks + * Includes only entities spawned locally (with {@link Entity.spawnAddon}), + * test entities manually with {@link Entity.getTypeName} or use {@link BlockSource.listEntitiesInAABB} + * with appropriate arguments. + */ + function getTypeAddon(entityUid: number): Nullable; + + /** + * @returns Compound tag for the specified entity. + * @since 2.0.5b44 + */ + function getCompoundTag(entityUid: number): Nullable; + + /** + * Sets compound tag for the specified entity. + * @since 2.0.5b44 + */ + function setCompoundTag(entityUid: number, tag: NBT.CompoundTag): void; + + /** + * Sets hitbox to the entity. Hitboxes defines entity collisions + * between terrain and themselves (e.g. physics). + * @param w hitbox width and length + * @param h hitbox height + */ + function setHitbox(entityUid: number, w: number, h: number): void; + + /** + * @returns `true` if specified entity is loaded within any player chunks + * (not despawned or unloaded) and identifier is valid. + */ + function isExist(entityUid: number): boolean; + + /** + * @returns Current dimension numeric ID, one of the {@link EDimension} + * values or custom dimension ID. + * @since 2.0.4b35 + */ + function getDimension(entityUid: number): number; + + /** + * Spawns vanilla entity on the specified coordinates. + * @param type numeric entity type, one of the {@link EEntityType} + * @param skin skin to set for the entity. Leave empty or null to use + * default skin of the mob + * @returns Numeric ID of spawn entity or -1 if entity was not created. + * @deprecated Client-side method, use {@link BlockSource.spawnEntity} instead. + */ + function spawn(x: number, y: number, z: number, type: number, skin?: Nullable): number; + + /** + * Same as {@link Entity.spawn}, but uses {@link Vector} object to represent + * coordinates. + * @deprecated Client-side method, use {@link BlockSource.spawnEntity} instead. + */ + function spawnAtCoords(coords: Vector, type: number, skin?: string): void; + + /** + * Spawns custom entity on the specified coords. Allows to pass some values + * to controllers via extra param. + * @param name custom entity string ID + * @param extra object that contains some data for the controllers + * @deprecated You are should implement addon entity and spawn it with + * {@link BlockSource.spawnEntity} instead. + */ + function spawnCustom(name: string, x: number, y: number, z: number, extra?: object): CustomEntity; + + /** + * Same as {@link Entity.spawnCustom}, but uses {@link Vector} object to represent + * coordinates. + * @deprecated You are should implement addon entity and spawn it with + * {@link BlockSource.spawnEntity} instead. + */ + function spawnCustomAtCoords(name: string, coords: Vector, extra?: any): CustomEntity; + + /** + * Spawns custom entity defined in behavior packs or game itself. + * @returns Instance to performing commands on entity. + * @deprecated Client-side method, use {@link BlockSource.spawnEntity} instead. + */ + function spawnAddon(x: number, y: number, z: number, name: string): AddonEntityRegistry.AddonEntity; + + /** + * Same as {@link Entity.spawnAddon}, but uses {@link Vector} object to represent + * coordinates. + * @returns Instance to performing commands on entity. + * @deprecated Client-side method, use {@link BlockSource.spawnEntity} instead. + */ + function spawnAddonAtCoords(coords: Vector, name: string): AddonEntityRegistry.AddonEntity; + + /** + * @returns Instance to performing commands on requested addon + * entity if it spawned by Inner Core or `null` instead. + * @remarks + * Includes only entities spawned locally (with {@link Entity.spawnAddon}). + */ + function getAddonEntity(entity: number): Nullable; + + /** + * Removes entity from the world. + */ + function remove(entityUid: number): void; + + /** + * @returns Custom entity object by it's numeric entity UID. + * @deprecated Not supported anymore, use behavior packs. + */ + function getCustom(entityUid: number): CustomEntity; + + /** + * @deprecated Use attributes instead. + */ + function getAge(entityUid: number): number; + + /** + * @deprecated Use attributes instead. + */ + function setAge(entityUid: number, age: number): void; + + /** + * @deprecated Use NBT instead. + */ + function getSkin(entityUid: number): string; + + /** + * Sets mob skin. + * @param skin skin name, full path in the resourcepack (mod assets) + * @deprecated Use NBT or resource packs instead. + */ + function setSkin(entityUid: number, skin: string): void; + + /** + * Sets mob skin, uses {@link Texture} object. + * @deprecated Use NBT or resource packs instead. + */ + function setTexture(entityUid: number, texture: Texture): void; + + /** + * @returns Entity render type, should be one of the + * {@link EMobRenderType} values. + * @deprecated Use resource packs instead. + */ + function getRender(entityUid: number): number; + + /** + * Sets entity render type. + * @param render entity render type, should be one of the + * {@link EMobRenderType} values + * @deprecated Use resource packs instead. + */ + function setRender(entityUid: number, render: number): void; + + /** + * Makes rider ride entity. + * @param entityUid ridden entity + * @param riderUid rider entity + */ + function rideAnimal(entityUid: number, riderUid: number): void; + + /** + * @returns Entity name tag or player name. + * @since 2.2.1b97 (not working before) + */ + function getNameTag(entityUid: number): string; + + /** + * Sets custom entity name tag. Custom entity tags are + * displayed above the entities and can be set by player + * using label. + * @param tag name tag to be set to the entity + */ + function setNameTag(entityUid: number, tag: string): void; + + /** + * Gets the attack target of current entity. + * @returns Target entity's unique ID. + */ + function getTarget(entityUid: number): number; + + /** + * Sets the attack target for current entity. Works only for mobs that + * actually can attack. + * @param targetUid target entity's unique ID + */ + function setTarget(entityUid: number, targetUid: number): void; + + /** + * @returns `true`, if entity was immobilized. + * @since 2.3.1b116-3 + */ + function getMobile(entityUid: number): boolean; + + /** + * Sets entity's immobile state. + * @param mobile if `true`, entity can move, otherwise it is immobilized + */ + function setMobile(entityUid: number, mobile: boolean): void; + + /** + * @returns `true` if entity is sneaking, `false` otherwise. + */ + function getSneaking(entityUid: number): boolean; + + /** + * Sets entity's sneaking state, supported slightly + * entities, resource pack render controlling it. + * @param sneak if `true`, entity becomes sneaking, else not + */ + function setSneaking(entityUid: number, sneak: boolean): void; + + /** + * @returns Entity that is riding the specified entity. + */ + function getRider(entityUid: number): number; + + /** + * @returns Entity that is ridden by specified entity. + */ + function getRiding(entityUid: number): number; + + /** + * Puts entity on fire. + * @param fire duration (in ticks) of the fire + * @param force should always be true + */ + function setFire(entityUid: number, fire: number, force: boolean): void; + + /** + * @returns An object that allows to manipulate entity health. + * @deprecated Consider using {@link Entity.getHealth}, {@link Entity.setHealth}, + * {@link Entity.getMaxHealth} and {@link Entity.setMaxHealth} instead. + */ + function health(entityUid: number): EntityHealth; + + /** + * Class used to manipulate entity's health. + * @deprecated Consider using {@link Entity.getHealth}, {@link Entity.setHealth}, + * {@link Entity.getMaxHealth} and {@link Entity.setMaxHealth} instead. + */ + class EntityHealth { + /** + * @returns Entity's current health value. + * @throws No such method. + */ + get(): number; + + /** + * Sets entity's current health value. + * @param health health value to be set + * @throws No such method. + */ + set(health: number): void; + + /** + * @returns Entity's maximum health value. + * @throws No such method. + */ + getMax(): number; + + /** + * Sets entity's maximum health value. + * @throws No such method. + */ + setMax(maxHealth: number): void; + } + + /** + * @returns Entity's current health value. + */ + function getHealth(entityUid: number): number; + + /** + * Sets entity's current health value. + * @param health health value to be set + */ + function setHealth(entityUid: number, health: number): void; + + /** + * @returns Entity's maximum health value. + */ + function getMaxHealth(entityUid: number): number; + + /** + * Sets entity's maximum health value. + */ + function setMaxHealth(entityUid: number, health: number): void; + + /** + * Sets the specified coordinates as a new position for the entity. + * No checks are performed. + */ + function setPosition(entityUid: number, x: number, y: number, z: number): void; + + /** + * @returns Entity position. + */ + function getPosition(entityUid: number): Vector; + + /** + * Updates current entity position by specified coordinates. + */ + function addPosition(entityUid: number, x: number, y: number, z: number): void; + + /** + * Set current entity's velocity using velocity vector. + */ + function setVelocity(entityUid: number, x: number, y: number, z: number): void; + + /** + * Get current entity's velocity using velocity vector. + * @returns Containing current entity's velocity. + */ + function getVelocity(entityUid: number): Vector; + + /** + * Updates current entity's velocity by specified value. + */ + function addVelocity(entityUid: number, x: number, y: number, z: number): void; + + /** + * @returns Distance in blocks between the two coordinate sets. + */ + function getDistanceBetweenCoords(coords1: Vector, coords2: Vector): number; + + /** + * @returns Distance between specified entity and a fixed coordinate set. + */ + function getDistanceToCoords(entityUid: number, coords: Vector): number; + + /** + * @returns Distance in blocks between two entities. + */ + function getDistanceToEntity(ent1: number, ent2: number): number; + + /** + * @returns Distance between player and entity, counting only x and z values + * (y value is ignored). + */ + function getXZPlayerDis(entityUid: number): number; + + /** + * @returns Entity's look angle in radians. + */ + function getLookAngle(entityUid: number): LookAngle; + + /** + * Sets specified pitch and yaw as look angle for the entity. + * @param yaw look angle yaw in radians + * @param pitch look angle pitch in radians + */ + function setLookAngle(entityUid: number, yaw: number, pitch: number): void; + + /** + * Transforms look angle into look vector. + * @param angle look angle to transform into {@link Vector} + * @returns Transformation result. + */ + function getLookVectorByAngle(angle: LookAngle): Vector; + + /** + * @returns Look vector for the entity. + */ + function getLookVector(entityUid: number): Vector; + + /** + * @returns Look angle between entity and static coordinates. + */ + function getLookAt(entityUid: number, x: number, y: number, z: number): LookAngle; + + /** + * Sets entity look angle to look at specified coordinates. + */ + function lookAt(entityUid: number, x: number, y: number, z: number): void; + + /** + * Same as {@link Entity.lookAt} but uses Vector as param type. + * @param coords + */ + function lookAtCoords(entityUid: number, coords: Vector): void; + + /** + * Makes entity move to the target coordinates. + * @param params additional move parameters + */ + function moveToTarget(entityUid: number, target: Vector, params: MoveParams): void; + + /** + * Makes entity move using pitch/yaw angle to determine direction. + * @param angle angle to define entity's direction + * @param params additional move parameters + */ + function moveToAngle(entityUid: number, angle: LookAngle, params: MoveParams): void; + + /** + * Makes entity move towards it's current look angle. + * @param params additional move parameters + */ + function moveToLook(entityUid: number, params: MoveParams): void; + + /** + * Interface used to specify how entity should move. + */ + interface MoveParams { + /** + * Movement speed. + */ + speed?: number, + + /** + * If `true`, entity won't change it's Y velocity. + */ + denyY?: boolean, + + /** + * Y velocity (jump speed). + */ + jumpVel?: number + } + + /** + * Retrieves entity's current movement information. + * @returns Object that contains normalized moving vector, moving speed and + * moving xz speed (with no Y coordinate). + */ + function getMovingVector(entityUid: number): MovingVector; + + /** + * Interface used to return entity's current moving vector and some + * additional data. + */ + interface MovingVector { + /** + * Normalized vector X coordinate. + */ + x: number, + + /** + * Normalized vector Y coordinate. + */ + y: number, + + /** + * Normalized vector Z coordinate. + */ + z: number, + + /** + * Vector real length. + */ + size: number, + + /** + * Vector real length excluding Y coordinate. + */ + xzsize: number + } + + /** + * Retrieves entity look angle in the form of pitch/yaw angle. No other + * information included to the resulting object. + */ + function getMovingAngle(entityUid: number): LookAngle; + + /** + * @deprecated Nothing to perform here anymore. + */ + function getMovingAngleByPositions(pos1: any, pos2: any): undefined; + + /** + * Retrieves nearest to the coordinates entity of the specified entity type. + * @param coords search range center coordinates + * @param type entity type ID. Parameter is no longer supported and should + * be 0 in all cases + * @param maxRange if specified, determines search radius + * @remarks + * Overheating method, capture entities by {@link BlockSource.fetchEntitiesInAABB} + * and pass over them by checking radius between coords and entity. + */ + function findNearest(coords: Vector, type?: number, maxRange?: number): Nullable; + + /** + * Returns array of all entities numeric IDs in given range in blocks. + * @param coords search range center coordinates + * @param maxRange determines search radius + * @param type entity type ID + * @remarks + * Overheating method, capture entities by {@link BlockSource.fetchEntitiesInAABB} + * and pass over them by checking radius between coords and entity. + */ + function getAllInRange(coords: Vector, maxRange: number, type?: number): number[]; + + /** + * @deprecated Consider use {@link Entity.getCarriedItem} instead. + */ + function getInventory(entityUid: number, handleNames?: boolean, handleEnchant?: boolean): void; + + /** + * @param slot armor slot index, should be one of the {@link EArmorType} + * values + * @returns Armor slot contents for entity. + */ + function getArmorSlot(entityUid: number, slot: number): ItemInstance; + + /** + * Sets armor slot contents for the entity. + * @param slot armor slot index, should be one of the {@link EArmorType} + * values + * @param id item ID + * @param count item count + * @param data item data + * @param extra item extra + */ + function setArmorSlot(entityUid: number, slot: number, id: number, count: number, data: number, extra?: ItemExtraData): void; + + /** + * @returns Entity's current carried item information. + */ + function getCarriedItem(entityUid: number): ItemInstance; + + /** + * Sets current carried item for the entity. + * @param id item ID + * @param count item count + * @param data item data + * @param extra item extra + */ + function setCarriedItem(entityUid: number, id: number, count: number, data: number, extra?: ItemExtraData): void; + + /** + * @returns Entity's current offhand item information. + */ + function getOffhandItem(entityUid: number): ItemInstance; + + /** + * Sets current offhand item for the entity. + * @param id item ID + * @param count item count + * @param data item data + * @param extra item extra + * @since 2.2.1b93 (not working before) + */ + function setOffhandItem(entityUid: number, id: number, count: number, data: number, extra?: ItemExtraData): void; + + /** + * Gets item from specified drop entity + * @returns Instance that is in the dropped item. + */ + function getDroppedItem(entityUid: number): ItemInstance; + + /** + * Sets item to the specified drop entity + * @param id item ID + * @param count item count + * @param data item data + * @param extra item extra + */ + function setDroppedItem(entityUid: number, id: number, count: number, data: number, extra?: ItemExtraData): void; + + /** + * @deprecated Use callbacks and {@link Entity.getAll} instead. + */ + function getProjectileItem(projectile: number): ItemInstance; + + type Attribute = "minecraft:follow_range" | "minecraft:luck" | "minecraft:lava_movement" | "minecraft:underwater_movement" | "minecraft:movement" | "minecraft:knockback_resistance" | "minecraft:absorption" | "minecraft:health" | "minecraft:attack_damage" | "minecraft:jump_strength"; + + /** + * Creates an object used to change entity's attributes. + * @param entityUid entity uid + * @param attribute one of {@link Attribute} or your custom one + * @returns Object used to manipulate entity's attributes. + * @since 2.0.3b33 + */ + function getAttribute(entityUid: number, attribute: Attribute | string): AttributeInstance; + + /** + * Interface used to modify attribute values. + * @since 2.0.3b33 + */ + interface AttributeInstance { + + /** + * @returns Current attribute's value. + */ + getValue(): number; + + /** + * @returns Attribute's maximum value. + */ + getMaxValue(): number; + + /** + * @returns Attribute's minimum value. + */ + getMinValue(): number; + + /** + * @returns Attribute's default value + */ + getDefaultValue(): number; + + /** + * Sets current attribute's value. + */ + setValue(value: number): void; + + /** + * Sets attribute's maximum value. + */ + setMaxValue(value: number): void; + + /** + * Sets attribute's minimum value. + */ + setMinValue(value: number): void; + + /** + * Sets attribute's default value. + */ + setDefaultValue(value: number): void; + } + + /** + * Creates or gets an existing {@link Entity.PathNavigation} instance for the specified mob + * @returns Navigation used to control entity's target position and + * the way to get there. + * @since 2.0.3b33 + */ + function getPathNavigation(entityUid: number): PathNavigation; + + /** + * Object used to build path and move mobs to the required coordinates using + * specified parameters. All the setters return current {@link Entity.PathNavigation} + * instance to be able to produce chained calls. + * @since 2.0.3b33 + */ + interface PathNavigation { + /** + * Builds path to the specified coordinates. + * @param speed entity movement speed + */ + moveToCoords(x: number, y: number, z: number, speed: number): PathNavigation; + + /** + * Builds path to the specified entity. Note that current coordinates of + * entity are used, and are not updated. + * @param speed entity movement speed + */ + moveToEntity(entity: number, speed: number): PathNavigation; + + /** + * Sets function to be notified when path navigation is finished or aborted. + * @param callback function to be called when navigation is finished or aborted + */ + setResultFunction(callback: PathNavigationResultFunction): PathNavigation; + + /** + * @returns Whether the entity can pass doors. + */ + canPassDoors(): boolean; + /** + * Sets entity's door passing ability. + */ + setCanPassDoors(can: boolean): PathNavigation; + + isRiverFollowing(): boolean; + setIsRiverFollowing(follow: boolean): PathNavigation; + + /** + * @returns Whether the entity can open doors. + */ + canOpenDoors(): boolean; + /** + * Sets entity's door opening ability. + */ + setCanOpenDoors(can: boolean): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getAvoidSun(): boolean; + /** + * Sets entity's sun avoiding. + */ + setAvoidSun(avoid: boolean): PathNavigation; + + /** + * @returns Whether the entity avoids water. + */ + getAvoidWater(): boolean; + /** + * Sets entity's water avoiding. + */ + setAvoidWater(avoid: boolean): PathNavigation; + + setEndPathRadius(radius: number): PathNavigation; + + getCanSink(): boolean; + setCanSink(can: boolean): PathNavigation; + + getAvoidDamageBlocks(): boolean; + setAvoidDamageBlocks(avoid: boolean): PathNavigation; + + getCanFloat(): boolean; + setCanFloat(can: boolean): PathNavigation; + + isAmphibious(): boolean; + setIsAmphibious(amphibious: boolean): PathNavigation; + + getAvoidPortals(): boolean; + setAvoidPortals(avoid: boolean): PathNavigation; + + getCanBreach(): boolean; + setCanBreach(can: boolean): PathNavigation; + + /** + * @returns Whether entity can jump. + */ + getCanJump(): boolean; + + /** + * Enables or disables entity's jumping ability. + */ + setCanJump(can: boolean): PathNavigation; + + /** + * @returns Entity's speed value. + */ + getSpeed(): number; + + /** + * Sets entity's speed value. + */ + setSpeed(speed: number): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getCanPathOverLava(): boolean; + /** + * @since 2.2.1b93 + */ + setCanPathOverLava(can: boolean): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getCanWalkInLava(): boolean; + /** + * @since 2.2.1b93 + */ + setCanWalkInLava(can: boolean): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getCanOpenIronDoors(): boolean; + /** + * @since 2.2.1b93 + */ + setCanOpenIronDoors(can: boolean): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getHasEndPathRadius(): boolean; + /** + * @since 2.2.1b93 + */ + setHasEndPathRadius(has: boolean): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getTerminationThreshold(): number; + /** + * @since 2.2.1b93 + */ + getTerminationThreshold(threshold: number): PathNavigation; + + /** + * @since 2.2.1b93 + */ + getTickTimeout(): number; + /** + * @since 2.2.1b93 + */ + setTickTimeout(ticks: number): PathNavigation; + + /** + * @since 2.2.1b93 + */ + isStuck(ticks: number): boolean; + } + + /** + * Path navigation result, which is used in result callback: + * + * Result code | Meaning + * ---|--- + * 0 | Path successfully completed + * 1 | Cannot reach target, no available path + * 2 | Cannot reach target, out of range + * 3 | Entity has been unloaded or removed + * 4 | Cancelled by `stop()` or similar method + * 5 | Player left level or server closed + * 6 | Result function will be replaced + */ + type PathNavigationResultCode = 0 | 1 | 2 | 3 | 4 | 5 | 6; + + /** + * Occurs when path navigation is finished or aborted. + * @param navigation {@link Entity.PathNavigation} that the handler is attached to + * @param result result code, see {@link PathNavigationResultCode} for details + */ + interface PathNavigationResultFunction { + (navigation: PathNavigation, result: PathNavigationResultCode): void + } + + /** + * Returns array of all entities numeric IDs in given range in blocks. + * @param coords1 start search range coordinates + * @param coords2 end search range coordinates + * @param type entity type ID + * @default type: 255, flag: true + * @since 2.0.4b35 + * @remarks + * Local method, use {@link BlockSource.listEntitiesInAABB} instead. + */ + function getAllInsideBox(coords1: Vector, coords2: Vector, type?: number, flag?: boolean): number[]; + +} diff --git a/api/core-engine/EntityAI.d.ts b/api/core-engine/EntityAI.d.ts new file mode 100644 index 000000000..1d6d2d18c --- /dev/null +++ b/api/core-engine/EntityAI.d.ts @@ -0,0 +1,402 @@ +/** + * Class used to create new entity AI types. + * @deprecated + */ +declare class EntityAIClass implements EntityAIClass.EntityAIPrototype { + /** + * Creates new entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype); + + /** + * Sets execution timer time in ticks. AI will be executed specified + * number of ticks. + * @param timer execution time in ticks + */ + setExecutionTimer(timer: number): void; + + /** + * Resets execution timer so that AI is executed with no time limits. + */ + removeExecutionTimer(): void; + + /** + * If set to true, it is an instance of AI type, else the pattern + * (pattern should not be modified directly, AI controller calls + * instantiate to create instances of AI type). + */ + isInstance: boolean; + + /** + * Instantiated custom entity that uses this AI type + * instance or `null` if it is the pattern. + */ + parent?: CustomEntity; + + /** + * Numeric unique entity idenifier that uses this AI type + * instance or `null` if it is the pattern. + */ + entity?: number; + + /** + * Method that is called to create AI type instance using current + * instance as pattern. + */ + instantiate(parent: any, name: string): EntityAIClass; + + /** + * Occurs when entity this instance is assigned to this AI type + * instance, if you override this method, be sure to assign entity + * to {@link EntityAIClass.EntityAIPrototype}. + */ + aiEntityChanged(entity: number): void; + + /** + * Finishes AI execution and disables it in parent controller. + */ + finishExecution(): void; + + /** + * Changes own priority in parent's controller. + */ + changeSelfPriority(priority: number): void; + + /** + * Enables any AI by it's name in the controller. + * @param name AI name to be enables + * @param priority priority to be set to the enabled AI + * @param extra some extra data passed to + */ + enableAI(name: string, priority: number, extra: any): void; + + /** + * Disables any AI by it's name in the controller. + * @param name AI name to be disabled + */ + disableAI(name: string): void; + + /** + * Sets any AI priority by it's name in the controller. + * @param name AI name to change priority + * @param priority priority to be set to the AI + */ + setPriority(name: string, priority: number): void; + + /** + * Gets any AI object by it's name from the current controller. + * @param name AI name + */ + getAI(name: string): EntityAIClass; + + /** + * Gets any AI priority from the current controller by AI name. + * @param name AI name + */ + getPriority(name: string): number; + + /** + * @returns AI type's default name. + */ + setParams(params: object): void; + + /** + * All the parameters of the AI instance. + */ + params: object; + + /** + * Object containing the state of the AI type. + */ + data: object; +} + +/** + * @deprecated + */ +declare namespace EntityAIClass { + /** + * Object used to register entity AI prototypes. + */ + interface EntityAIPrototype { + /** + * @returns AI type's default priority. + */ + getDefaultPriority?(): number, + + /** + * @returns AI type's default name. + */ + getDefaultName?(): string, + + /** + * Default parameters set. + */ + params?: object, + + /** + * Called when AI type execution starts. + * @param extra additional data passed from {@link EntityAIClass.enableAI} + * method + */ + executionStarted?(extra?: any): void, + + /** + * Called when AI type execution ends. + */ + executionEnded?(): void, + + /** + * Called when AI type execution is paused. + */ + executionPaused?(): void, + + /** + * Called when AI type execution is resumed. + */ + executionResumed?(): void, + + /** + * Defines main logic of the AI type. + */ + execute?(): void, + + /** + * Object containing the state of the AI type. + */ + data?: object, + + /** + * Called when entity is attacked by player. + * @param attacker player that attacked this entity + */ + attackedBy?(attacker: number): void; + + /** + * Called when entity gets hurt. + * @param attacker entity that damaged this entity, or -1 if damage + * source is not an entity + * @param damage amount of damage + */ + hurtBy?(attacker: number, damage: number): void; + + /** + * Called when a projectile hits the entity. + * @param projectile projectile entity ID + */ + projectileHit?(projectile: number): void; + + /** + * Called when entity is dead. + * @param attacker entity that damaged this entity, or -1 if damage + * source is not an entity + */ + death?(attacker: number): void; + } + + /** + * Object used to register entity AI prototypes. + */ + interface WanderLikeAIPrototype extends EntityAIPrototype { + /** + * Entity movement speed when AI is executed. + */ + speed?: number; + /** + * Entity speed when turning. + */ + angular_speed?: number; + } + +} + +/** + * A set of predefined entity AI types. + * @deprecated + */ +declare namespace EntityAI { + /** + * Simple Idle AI type, entity just does nothing. + */ + class Idle extends EntityAIClass { + /** + * Creates Idle entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype); + } + + /** + * Follow AI type, entity follows it's target. Use another AI type to set + * target for this AI type. + */ + class Follow extends EntityAIClass { + /** + * Creates follow entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype & { + /** + * Entity movement speed when AI is executed. + * @default 0.2 + */ + speed?: number; + /** + * Jump (y) velocity. + * @default 0.45 + */ + jumpVel?: number; + /** + * Entity rotation speed. + * @default 0.4 + */ + rotateSpeed?: number; + /** + * How long will be the rotation path. + * @default 0.5 + */ + rotateRatio?: number; + /** + * If `true`, entity turns it's head to the target. + * @default true + */ + rotateHead?: boolean; + /** + * If `true`, entity won't change it's Y velocity. + * @default true + */ + denyY?: boolean; + /** + * Coordinates used as a target. + */ + target?: Vector; + /** + * Entity used as a target; when specified, target data is ignored. + */ + targetEntity?: number; + }); + } + + /** + * Panic AI type, entity just rushes around. + */ + class Panic extends EntityAIClass { + /** + * Creates panic entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.WanderLikeAIPrototype); + } + + /** + * Wander AI type, entity walks around making pauses. + */ + class Wander extends EntityAIClass { + /** + * Creates wander entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.WanderLikeAIPrototype & { + /** + * Part of the time entity is making pause. + * @default 0.3 + */ + delay_weight?: number; + }); + } + + /** + * Attack AI type, entity causes damage to the target entity. + */ + class Attack extends EntityAIClass { + /** + * Creates attack entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype & { + /** + * Damage amount. + * @default 5 + */ + attack_damage?: number; + /** + * Damage radius. + * @default 2.5 + */ + attack_range?: number; + /** + * Time between to attacks in ticks. + * @default 12 + */ + attack_rate?: number; + /** + * Target entity. + * @default null + */ + target?: Nullable; + }); + } + + /** + * Swim AI type, if the entity is in water, it swims. + */ + class Swim extends EntityAIClass { + /** + * Creates swim entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype & { + /** + * Swimming speed. + * @default 0.2 + */ + velocity?: number; + }); + } + + /** + * Panic AI watcher type, controls entity panic behavior after getting hurt. + */ + class PanicWatcher extends EntityAIWatcher { + /** + * Creates panic watcher entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype & { + /** + * Time the entity will be in panic. + * @default 200 + */ + panic_time?: number; + /** + * Panic AI priority when entity should be in panic. + * @default 5 + */ + priority_panic?: number; + /** + * Panic AI priority when entity should not be in panic. + * @default 1 + */ + priority_default?: number; + /** + * Panic AI priority when entity should not be in panic + * @default "panic" + */ + name?: string; + }); + } +} + +/** + * Parent class for {@link EntityAI.PanicWatcher}, does nothing + * like {@link EntityAI.Idle}. + * @deprecated + */ +declare class EntityAIWatcher extends EntityAIClass { + /** + * Creates watcher entity AI type. + * @param customPrototype AI type prototype + */ + constructor(customPrototype: EntityAIClass.EntityAIPrototype); +} diff --git a/api/core-engine/FileTools.d.ts b/api/core-engine/FileTools.d.ts new file mode 100644 index 000000000..e9281d94c --- /dev/null +++ b/api/core-engine/FileTools.d.ts @@ -0,0 +1,148 @@ +/** + * Module that provides methods to work with file system. + */ +declare namespace FileTools { + /** + * Defines path to mounted devices directory (e.g. *\/mnt*). + */ + const mntdir: string; + + /** + * Defines external user directory path with trailing slash (e.g. *\/sdcard\/*, *\/storage\/emulated\/0\/*). + */ + const root: string; + + /** + * Defines in-pack directory where modders alives with trailing slash (e.g. *\/storage\/emulated\/0\/games\/horizon\/packs\/Inner_Core_Test\/innercore\/mods\/*, *\/storage\/emulated\/0\/Android\/data\/com.zheka.horizon\/files\/games\/horizon\/packs\/Inner_Core_Test\/innercore\/mods\/*). + */ + const moddir: string; + + /** + * Creates directory by it's home-relative or absolute path, if one of the + * parent directories doesn't exist, creates them. + * @param dir path to the new directory + */ + function mkdir(dir: string): void; + + /** + * Creates Core Engine working directories. + * @internal + */ + function mkworkdirs(): void; + + /** + * Converts home-relative path to absolute. + * @param path input path + * @returns Same string if input string is an absolute path, an absolute + * path if input string is a home-relative path. + */ + function getFullPath(path: string): string; + + /** + * Verifies if specified home-relative or absolute path exists. + * @param path path to be verified + * @returns `true`, if specified path exists, `false` otherwise. + */ + function isExists(path: string): boolean; + + /** + * Writes text to the file. + * @param file home-relative or absolute path to the file + * @param text text to be written to the file + * @param add if `true`, appends text to the file, overrides it otherwise + * @default add: false + */ + function WriteText(file: string, text: string, add?: boolean): void; + + /** + * Reads text as-is from file, append `?.trim()` to drop trailing newlines. + * @param file home-relative or absolute path to the file + * @returns File contents or `null` if file does not exist or not accessible. + */ + function ReadText(file: string): Nullable; + + /** + * Writes bitmap to PNG (lossless and transparent extension) file. + * @param file home-relative or absolute path to the file + * @param bitmap {@link android.graphics.Bitmap} to be written to the file + */ + function WriteImage(file: string, bitmap: android.graphics.Bitmap): void; + + /** + * Reads high-resolution (as-is) bitmap from file. + * @param file home-relative or absolute path to the file + * @returns object of the bitmap that was read from + * file or null if file does not exist or is not accessible. + */ + function ReadImage(file: string): Nullable; + + /** + * Reads string from asset by it's full name. + * @param name asset name + * @returns Asset contents or `null` if asset doesn't exist. + */ + function ReadTextAsset(name: string): Nullable; + + /** + * Reads high-resolution (as-is) bitmap from asset by it's full name. + * @param name asset name + * @returns Object of the bitmap that was read from + * asset or null, if asset doesn't exist. + */ + function ReadImageAsset(name: string): Nullable; + + /** + * Reads bytes array from assets. + * @param name asset name + * @returns JArray of bytes read from assets or null if asset doesn't exist. + */ + function ReadBytesAsset(name: string): Nullable>; + + /** + * Lists children directories for the specified path. + * @param path home-relative or absolute path to the file + * @returns JArray of {@link java.io.File} instances of listed directories. + */ + function GetListOfDirs(path: string): java.io.File[]; + + /** + * Lists files in the specified directory. + * @param path path to directory to look for files in + * @param ext extension of the files to include to the output + * @returns JArray of {@link java.io.File} instances that match specified extension. + */ + function GetListOfFiles(path: string, ext?: string): java.io.File[]; + + /** + * Reads file as `:` pairs. + * @param dir home-relative or absolute path to the file + * @param specialSeparator separator between key and value, ":" by default + * @returns Object containing `:` pairs from file. + */ + function ReadKeyValueFile(dir: string, specialSeparator?: string): { + [key: string]: string + }; + + /** + * Writes `:` pairs to the file. + * @param dir home-relative or absolute path to the file + * @param data object to be written to the file as a set of key:value pairs + * @param specialSeparator separator between key and value, ":" by default + */ + function WriteKeyValueFile(dir: string, data: object, specialSeparator?: string): void; + + /** + * Reads JSON file without comments as object. + * @param dir home-relative or absolute path to the file + * @returns Object represents JSON value read from JSON file. + */ + function ReadJSON(dir: string): object; + + /** + * Writes object to file as JSON. + * @param dir home-relative or absolute path to the file + * @param obj object to be written to the file as JSON + * @param beautify if `true`, output JSON is beautified with tabs + */ + function WriteJSON(dir: string, obj: object, beautify?: boolean): void; +} diff --git a/api/core-engine/Game.d.ts b/api/core-engine/Game.d.ts new file mode 100644 index 000000000..91b75069e --- /dev/null +++ b/api/core-engine/Game.d.ts @@ -0,0 +1,199 @@ +/** + * Module that provides some general game-related functions. + */ +declare namespace Game { + /** + * `true` if developer mode was enabled in Inner Core config. + * @internal + */ + let isDeveloperMode: boolean; + + /** + * `true` if Inner Core config allows spending items in creative. + * @internal + */ + let spendItemsInCreative: boolean; + + /** + * Allows you to determine whether current instance of game has + * a client or not (clientless game requires a server core, e.g. + * [Zote Core (GitHub)](https://github.com/reider745/zotecoreloader)). + * @since 2.3.1b116 + */ + function isDedicatedServer(): boolean; + + /** + * Prevents current callback function from being called in Minecraft. + * For most callbacks it prevents default game behavior. + */ + function prevent(): void; + + /** + * @returns `true` if the current callback function has already been + * prevented from being called in Minecraft using {@link Game.prevent}, + * `false `otherwise. + */ + function isActionPrevented(): boolean; + + /** + * Writes message to the chat. + * Message can be formatted using {@link EColor} values. + * @param message message to be displayed + */ + function message(message: any): void; + + /** + * Writes message above the hot bar. + * Message can be formatted using {@link EColor} values. + * @param message message to be displayed + */ + function tipMessage(message: any): void; + + /** + * Displays {@link android.app.AlertDialog} with given message and dialog title. + * Message can be mixed with {@link android.text.Html.fromHtml HTML-like} formatting, + * for example `I'm a bold
I'm a italic`. + * @param message message to be displayed + * @param title title before message + */ + function dialogMessage(message: any, title: any): void; + + /** + * Sets game difficulty, one of {@link EGameDifficulty} values. + * @param difficulty game difficulty to be set + */ + function setDifficulty(difficulty: number): void; + + /** + * @returns Current game difficulty, one of the {@link EGameDifficulty} values. + */ + function getDifficulty(): number; + + /** + * Sets current level game mode. + * @param mode new game mode, should be one of the {@link EGameMode} + * values + */ + function setGameMode(mode: number): void; + + /** + * @returns Current level game mode, one of the {@link EGameMode} values. + */ + function getGameMode(): number; + + /** + * Option types, which can be used to determine option data: + * + * Type | Name | Description + * ---|---|--- + * 0 | None | Internal type, it cannot be used. + * 1 | Boolean | `true` or `false` switch. + * 2 | Float | Field with float value. + * 3 | Float Slider | Slider with float value in specified ranges. + * 4 | String | Field with string text value. + * 5 | Int | Field with integer value. + * 6 | Int Slider | Slider with integer value in specified ranges. + * @since 2.4.0b122 + */ + type OptionType = number; + + /** + * Option instance, which can be obtained via {@link Game.getOption}. + * @since 2.4.0b122 + */ + interface Option { + /** + * @internal + */ + getPointer(): number; + /** + * Gets numeric option type, which can be used to + * determine data type and retrieve proper value. + */ + getType(): OptionType; + /** + * Can option be changed in game settings. + */ + canModify(): boolean; + /** + * Gets boolean value of option, suitable for + * boolean {@link OptionType}. + */ + getBoolean(): boolean; + /** + * Gets boolean value of option, suitable for + * float and float slider {@link OptionType}s. + */ + getFloat(): number; + /** + * Gets minimum value in slider range, suitable + * for float slider {@link OptionType}. + */ + getFloatMin(): number; + /** + * Gets maximum value in slider range, suitable + * for float slider {@link OptionType}. + */ + getFloatMax(): number; + /** + * Gets boolean value of option, suitable for + * string {@link OptionType}. + */ + getString(): string; + /** + * Gets boolean value of option, suitable for + * int and int slider {@link OptionType}s. + */ + getInt(): number; + /** + * Gets minimum value in slider range, suitable + * for int slider {@link OptionType}. + */ + getIntMin(): number; + /** + * Gets maximum value in slider range, suitable + * for int slider {@link OptionType}. + */ + getIntMax(): number; + } + + /** + * Retrieves option by requested name, which instance + * could be used for getting values. + * @param name option name, suitable names could be found + * in your "options.txt" file or via {@link Game.getOptions} + * @since 2.4.0b122 + */ + function getOption(name: string): Nullable