├── .gitattributes ├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── LICENSE.md ├── README.md ├── generator ├── .gitignore ├── package-lock.json ├── package.json ├── src │ ├── components.ts │ ├── events.ts │ ├── identifiers.ts │ ├── index.ts │ ├── methods.ts │ ├── template.ts │ └── type.ts ├── template │ ├── client │ │ └── types │ │ │ ├── client_events.generated.d.ts │ │ │ ├── client_system.generated.d.ts │ │ │ └── client_system_events.generated.d.ts │ └── server │ │ └── types │ │ ├── server_component.generated.d.ts │ │ ├── server_component_names.generated.d.ts │ │ ├── server_events.generated.d.ts │ │ ├── server_system.generated.d.ts │ │ ├── server_system_components.generated.d.ts │ │ └── server_system_events.generated.d.ts ├── tsconfig.json └── typing-overrides.json ├── lerna.json ├── package.json └── packages ├── client ├── index.d.ts ├── package-lock.json ├── package.json ├── tsconfig.json └── types │ ├── client.d.ts │ ├── client_component.generated.d.ts │ ├── client_component_names.generated.d.ts │ ├── client_events.generated.d.ts │ ├── client_system.d.ts │ ├── client_system.generated.d.ts │ ├── client_system_components.generated.d.ts │ └── client_system_events.generated.d.ts ├── server ├── index.d.ts ├── package-lock.json ├── package.json ├── tsconfig.json └── types │ ├── server.d.ts │ ├── server_component.generated.d.ts │ ├── server_component_names.generated.d.ts │ ├── server_events.generated.d.ts │ ├── server_system.d.ts │ ├── server_system.generated.d.ts │ ├── server_system_components.generated.d.ts │ └── server_system_events.generated.d.ts └── shared ├── index.d.ts ├── package-lock.json ├── package.json ├── tsconfig.json └── types ├── block.d.ts ├── component.d.ts ├── entity.d.ts ├── event.d.ts ├── item_stack.d.ts ├── level.d.ts ├── minecraft_object.d.ts ├── particle_effects.d.ts ├── query.d.ts ├── system.d.ts ├── ticking_area.d.ts └── types.d.ts /.gitattributes: -------------------------------------------------------------------------------- 1 | # Declare files that will always have LF line endings on checkout. 2 | *.ts text eol=lf 3 | *.json text eol=lf 4 | .gitattributes text eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules/ 3 | 4 | *.log 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceFolder}/generator\\src\\index.ts", 12 | "cwd": "${workspaceFolder}/generator/", 13 | "smartStep": true, 14 | "outFiles": [ 15 | "${workspaceFolder}/**/*.js" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "Minecraft", 4 | "triggerable" 5 | ] 6 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## creative commons 2 | 3 | # Attribution-NonCommercial-ShareAlike 3.0 Unported 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE. 6 | 7 | *License* 8 | 9 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. 10 | 11 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. 12 | 13 | ### 1. Definitions 14 | 15 | a. __"Adaptation"__ means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License. 16 | 17 | b. __"Collection"__ means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License. 18 | 19 | c. __"Distribute"__ means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership. 20 | 21 | d. __"License Elements"__ means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike. 22 | 23 | e. __"Licensor"__ means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License. 24 | 25 | f. __"Original Author"__ means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast. 26 | 27 | g. __"Work"__ means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work. 28 | 29 | h. __"You"__ means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. 30 | 31 | i. __"Publicly Perform"__ means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images. 32 | 33 | j. __"Reproduce"__ means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium. 34 | 35 | ### 2. Fair Dealing Rights 36 | 37 | Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws. 38 | 39 | ### 3. License Grant 40 | 41 | Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below: 42 | 43 | a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections; 44 | 45 | b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified."; 46 | 47 | c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and, 48 | 49 | d. to Distribute and Publicly Perform Adaptations. 50 | 51 | The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e). 52 | 53 | ### 4. Restrictions 54 | 55 | The license granted in Section 3 above is expressly made subject to and limited by the following restrictions: 56 | 57 | a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested. 58 | 59 | b. You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License. 60 | 61 | c. You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works. 62 | 63 | d. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties. 64 | 65 | e. For the avoidance of doubt: 66 | 67 | 1. __Non-waivable Compulsory License Schemes.__ In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; 68 | 69 | 2. __Waivable Compulsory License Schemes.__ In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and, 70 | 71 | 3. __Voluntary License Schemes.__ The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c). 72 | 73 | f. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise. 74 | 75 | ### 5. Representations, Warranties and Disclaimer 76 | 77 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU. 78 | 79 | ### 6. Limitation on Liability 80 | 81 | EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 82 | 83 | ### 7. Termination 84 | 85 | a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. 86 | 87 | b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 88 | 89 | ### 8. Miscellaneous 90 | 91 | a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. 92 | 93 | b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License. 94 | 95 | c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 96 | 97 | d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. 98 | 99 | e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. 100 | 101 | f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law. 102 | 103 | > Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor. 104 | > 105 | > Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this License. 106 | > 107 | > Creative Commons may be contacted at https://creativecommons.org/. 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minecraft-scripting-types 2 | __This branch is targeting Minecraft Bedrock Edition 1.9.0.4 (beta)__ 3 | 4 | ***This API is still in development and may break with updates until things stabilize*** 5 | 6 | ***Licensing for the project is still under consideration. It is currently distributed as [CC-BY-NC-SA-3.0](https://creativecommons.org/licenses/by-nc-sa/3.0/), which is the only license available compatible with it's source from the wiki. Note however that this license forbids commercial use. We aim to get a more permissive license if possible.*** 7 | 8 | Mojang provides modding capabilities via JavaScript. This project aims to bring the Type safety of TypeScript to the Bedrock Scripting Engine 9 | 10 | This readme is not a replacement for the API documentation, which should still be your primary source of information. See: [https://minecraft.gamepedia.com/Bedrock_Beta_Script_Documentation](https://minecraft.gamepedia.com/Bedrock_Beta_Script_Documentation) 11 | 12 | ## Pre-Requisites 13 | 14 | So you want to make your own Scripts? That's awesome! In this section you will find the list of minimum and recommended software you will need. 15 | 16 | | Software | Minimum | Recommended | 17 | | ----------- | ------------------------------------------- | --------------------------------------------------------- | 18 | | Code Editor | Visual Studio Code or any plain-text editor | Visual Studio Community 2017 with the following components installed: 'JavaScript diagnostics', 'JavaScript and TypeScript language support', 'Just-In-Time debugger' | 19 | | Debugger | N/A | Visual Studio Community 2017 | 20 | | Minecraft | Minecraft on your Windows 10 device | Minecraft on your Windows 10 device | 21 | | Other | Vanilla Behavior Pack available from https://aka.ms/MinecraftBetaBehaviors | Vanilla Behavior Pack available from https://aka.ms/MinecraftBetaBehaviors | 22 | | Storage | 1.0 GB of free space for text editor, game, and scripts | 3.0 GB of free space for Visual Studio, game, and scripts | 23 | | Node.js | 8.x | 10.x | 24 | 25 | ## Getting Started 26 | First you will need to download the latest Vanilla Behavior Pack. You can get this from the following link: 27 | 28 | https://aka.ms/MinecraftBetaBehaviors 29 | 30 | Once you have downloaded the Behavior Pack, unzip it to a folder. Inside the Behavior Pack you will find the scripts folder which contains all the scripting files you want to run. 31 | 32 | In the scripts folder you will find two folders: one for client scripts and one for server scripts. 33 | 34 | -Server Scripts: These scripts run on the server side of the game. This includes spawning new entities, adding components, or modifying components on an entity. 35 | 36 | -Client Scripts: These scripts run on each individual player's side of the game. This is a good place to respond to events and manage anything specific to the player. 37 | 38 | Once you have chosen whether you are making a client or server script, simply add a new blank text file with .js extension to the appropriate folder, and open it in your preferred code editor. Then code away! You can have as many or as few JavaScript files as you want here (the name of the files doesn't matter) and they will all be run independently of each other! 39 | 40 | NOTE: For scripts to be run by the game, you need to enable Experimental Gameplay on the world where you will run scripts on. This will be necessary while scripting is still in beta. 41 | 42 | ### Folder Structure 43 | * vanilla_behavior_pack 44 | * scripts 45 | * client 46 | * myClientScript.js 47 | * server 48 | * myServerScript.js 49 | * manifest.json 50 | * pack_icon.png 51 | 52 | ## Adding TypeScript support 53 | To add support for compiling with TypeScript, you'll need to create an NPM module, you can do this on the command line by navigating to your mod's directory and typing 54 | 55 | ``` 56 | npm init 57 | ``` 58 | 59 | This will guide you through creating an NPM module, but an absolute minimum module should look something like this: 60 | 61 | ```json 62 | { 63 | "private": "true" 64 | } 65 | ``` 66 | 67 | This is a node module that is not intended to be published, but can be used for dependency management. 68 | 69 | Now add TypeScript and minecraft-scripting-types (this project) using NPM 70 | 71 | ```cmd 72 | npm install --save-dev TypeScript 73 | npm install --save-dev minecraft-scripting-types-client minecraft-scripting-types-server 74 | ``` 75 | 76 | Next we just need to add a script to compile the project, which can be done by adding a "compile" script with the command `tsc -p .` which compiles the current project. 77 | 78 | #### Example package.json 79 | The final package.json should look something like this: 80 | ```json 81 | { 82 | "private": "true", 83 | "scripts": { 84 | "compile": "tsc -p ." 85 | }, 86 | "dependencies": { 87 | "minecraft-scripting-types-client": "^0.1.0", 88 | "minecraft-scripting-types-server": "^0.1.0", 89 | "typescript": "^3.1.3" 90 | } 91 | } 92 | ``` 93 | 94 | The project will not compile however until we add a tsconfig.json file, here is an example one that was used to write Beanstalk 95 | 96 | #### Example tsconfig.json 97 | ```json 98 | { 99 | "compilerOptions": { 100 | "module": "ES6", 101 | "noImplicitAny": true 102 | }, 103 | "include": [ 104 | "scripts/client/*", 105 | "scripts/server/*", 106 | ], 107 | "exclude": [ 108 | "node_modules" 109 | ] 110 | } 111 | ``` 112 | 113 | The last step will be to rename the `.js` files in `scripts/**/*.js` to `.ts` files. 114 | 115 | You should now be able to build your project using 116 | ``` 117 | npm run compile 118 | ``` 119 | It will generate .js files next to the typescript files which Minecraft will happily load. 120 | 121 | ## API Differences when using this typing 122 | 123 | Below we will detail the differences (and benefits that using these typings provide) 124 | 125 | ### Namespace your client and server systems 126 | 127 | You should make use of TypeScript namespaces in order to prevent TypeScript from thinking that your client and servers scripts from thinking that they both exist in the same global space. If you do not namespace your project, you may see unusual errors caused by variable or type collisions. 128 | 129 | namespacing should be as simple as wrapping your script like this: 130 | 131 | ```typescript 132 | /// 133 | 134 | namespace Server { 135 | ... 136 | /// Your code goes here 137 | ... 138 | } 139 | ``` 140 | 141 | ### Getting type information for an extended system 142 | 143 | The Mojang demonstrations create a system and them assigns additional methods to them in such a way that TypeScript does not detect methods being available on the system. 144 | 145 | If you do not intend to use this behaviour (perhaps your logic will be in methods, loose in the namespace you defined with the above hint), then you can simply register a plain system: 146 | 147 | ```typescript 148 | namespace Server { 149 | const system = server.registerSystem(0, 0); 150 | } 151 | ``` 152 | 153 | If you need to declare additional methods or properties on your system, you can subclass `IServerSystem` in order to pre-define the shape of your system. 154 | 155 | Note: although the demos from Mojang do this, we do not recommend it. 156 | 157 | ```typescript 158 | /// 159 | 160 | namespace Server { 161 | interface IMyCustomModSystem extends IServerSystem { 162 | // defining a pretend variable "this" with the type of your system will help TypeScript to 163 | // know that you can use "this." to get at the properties. 164 | notifyPlayer(this: IMyCustomModSystem, player: IEntityObject): void; 165 | players: IEntityObject[]; 166 | } 167 | 168 | const system: IMyCustomModSystem = server.registerSystem(0, 0); 169 | 170 | system.initialize = function() { 171 | //... initialze 172 | } 173 | 174 | system.notifyPlayer = function(player: IEntityObject): void { 175 | this.players.push(player); 176 | // If you don't want to define "this: IMyCustomModSystem" in the declaration, you can always just refer to the 177 | // registered system: 178 | 179 | //system.players.push(player); 180 | } 181 | 182 | //... continue adding more code 183 | } 184 | ``` 185 | 186 | You can subclass `IClientSystem` in a similiar way. 187 | 188 | ### Improved type detection for built-in components and events 189 | 190 | Minecraft's built-in components have all been defined in the `MinecraftComponent` enum, when you use one of these enum values with an API such as `getComponent()` you will be given an appropriate definition for the component that you are asking for. 191 | 192 | ```typescript 193 | system.update = function() { 194 | const player = //... resolving player here 195 | const position = this.getComponent(player, MinecraftComponent.Position); 196 | // position will be IPositionComponent 197 | server.log(`x: ${position.x}, y: ${position.y}, z: ${position.z}`) 198 | } 199 | ``` 200 | 201 | For custom components, overloads for specific components will not be available and you will need to specify the expected return type. 202 | 203 | ```typescript 204 | interface IAwesomeComponent { 205 | isAwesome: bool; 206 | } 207 | 208 | system.update = function() { 209 | const player = //... resolving player here 210 | const awesomeComponent = this.getComponent(player, "demo_mod:awesome_component"); 211 | 212 | // awesomeComponent will be IAwesomeComponent 213 | server.log(`isAwesome: ${awesomeComponent.isAwesome}`); 214 | } 215 | ``` 216 | 217 | these overloads will also be available for events in the near future, but are not yet implemented. 218 | 219 | ### Source Mapping 220 | Source mapping is not currently available, you will unfortunately need to get used to debugging with the compiled JavaScript files. 221 | 222 | A feedback item is pending approval for this feature. 223 | 224 | -------------------------------------------------------------------------------- /generator/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | out/ 3 | -------------------------------------------------------------------------------- /generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-typings-generator", 3 | "private": true, 4 | "main": "out/index.js", 5 | "scripts": { 6 | "compile": "tsc -p .", 7 | "start": "tsc -p . && node ." 8 | }, 9 | "author": "abc-55", 10 | "dependencies": { 11 | "@types/pump": "^1.0.1", 12 | "gulp-insert": "^0.5.0", 13 | "gulp-replace": "^1.0.0", 14 | "minecraft-documentation-extractor": "^1.1.1-alpha", 15 | "pump": "^3.0.0", 16 | "vinyl": "^2.2.0", 17 | "vinyl-fs": "^3.0.3" 18 | }, 19 | "devDependencies": { 20 | "@types/cheerio": "^0.22.10", 21 | "@types/gulp-insert": "^0.5.7", 22 | "@types/gulp-replace": "0.0.31", 23 | "@types/lodash": "^4.14.120", 24 | "@types/node": "^10.12.18", 25 | "@types/vinyl-fs": "^2.4.9", 26 | "typescript": "^3.2.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /generator/src/components.ts: -------------------------------------------------------------------------------- 1 | import { MinecraftScriptDocumentation, isArrayType, isWellKnownType } from "minecraft-documentation-extractor"; 2 | import { getTypeAsString } from "./type"; 3 | import { minecraftIdentifierToCamelCase } from "./identifiers"; 4 | 5 | export default function extractComponents(documentation: MinecraftScriptDocumentation, values: { [name: string]: string }) { 6 | 7 | const componentEnum: string[] = []; 8 | const interfaces: string[] = []; 9 | 10 | const functions: { [name: string]: string[] } = { 11 | "createComponent": [], 12 | "getComponent": [] 13 | }; 14 | 15 | for (const component of documentation.components.sort((a, b) => a.name.localeCompare(b.name))) { 16 | const enumName = minecraftIdentifierToCamelCase(component.name); 17 | 18 | componentEnum.push(`\ 19 | /** 20 | * ${component.description} 21 | */ 22 | ${enumName} = "${component.name}"`); 23 | 24 | const interfaceName = `I${enumName}Component`; 25 | 26 | if (!(isWellKnownType(component.type) || (isArrayType(component.type) && isWellKnownType(component.type.type)))) { 27 | const componentBody = component.type ? getTypeAsString((isArrayType(component.type) ? component.type.type : component.type), `component(${enumName})`) : ""; 28 | interfaces.push(`\ 29 | /** 30 | * ${component.description} 31 | */ 32 | declare interface ${interfaceName} ${componentBody}`); 33 | } else { 34 | let componentDataType : string; 35 | if (isArrayType(component.type)) { 36 | componentDataType = `${getTypeAsString(component.type.type, `component(${enumName})`)}[]`; 37 | } else { 38 | componentDataType = getTypeAsString(component.type, `component(${enumName})`); 39 | } 40 | 41 | interfaces.push(`\ 42 | /** 43 | * ${component.description} 44 | */ 45 | declare type ${interfaceName} = ${componentDataType}`); 46 | } 47 | 48 | const x = `(entity: IEntity, componentName: MinecraftComponent.${enumName}): IComponent<${interfaceName}> | null;`; 49 | Object.keys(functions).forEach(name => { 50 | functions[name].push(name + x); 51 | }); 52 | } 53 | 54 | values.componentEnum = componentEnum.join(",\n"); 55 | values.componentInterfaces = interfaces.join("\n\n"); 56 | Object.keys(functions).forEach(name => { 57 | values[name] = functions[name].join("\n"); 58 | }); 59 | }; 60 | -------------------------------------------------------------------------------- /generator/src/events.ts: -------------------------------------------------------------------------------- 1 | import { Event, isWellKnownType, Type } from "minecraft-documentation-extractor"; 2 | import getType, { getTypeAsString } from "./type"; 3 | import { minecraftIdentifierToCamelCase } from "./identifiers"; 4 | 5 | export enum ClientServer { 6 | Client = "Client", Server = "Server" 7 | } 8 | 9 | export function extractTriggerableEvents(events: Event[], values: { [name: string]: string }, clientOrServer: ClientServer) { 10 | const eventEnum: string[] = []; 11 | const interfaces: string[] = []; 12 | const broadcastFunctions: string[] = []; 13 | const createEventDataFunctions: string[] = []; 14 | 15 | for (const event of events.sort((a, b) => a.name.localeCompare(b.name))) { 16 | eventEnum.push(defineEnumEntry(event)); 17 | 18 | const eventDataType = getEventType(event, "Parameters", clientOrServer); 19 | if (eventDataType.interfaceDefinition != null) { 20 | interfaces.push(eventDataType.interfaceDefinition); 21 | } 22 | 23 | const enumName = `SendToMinecraft${clientOrServer}`; 24 | const enumValueName = minecraftIdentifierToCamelCase(event.name); 25 | broadcastFunctions.push( 26 | defineFunction( 27 | "broadcastEvent", 28 | event.description, 29 | [ 30 | `eventIdentifier: ${enumName}.${enumValueName}`, 31 | `eventData: IEventData<${eventDataType.type}>` 32 | ], 33 | "boolean | null" 34 | ) 35 | ); 36 | 37 | createEventDataFunctions.push( 38 | defineFunction( 39 | "createEventData", 40 | event.description, 41 | [ 42 | `eventIdentifier: ${enumName}.${enumValueName}` 43 | ], 44 | `IEventData<${eventDataType.type}> | null` 45 | ) 46 | ); 47 | } 48 | 49 | const resultVariableName = `${clientOrServer.toLowerCase()}Triggerable` 50 | values[resultVariableName + "EventEnum"] = eventEnum.join(",\n"); 51 | values[resultVariableName + "EventInterfaces"] = interfaces.join("\n\n"); 52 | values[`broadcastEvent${clientOrServer}`] = broadcastFunctions.join("\n"); 53 | values[`createEventData${clientOrServer}`] = createEventDataFunctions.join("\n"); 54 | }; 55 | 56 | export function extractListeningEvents(events: Event[], values: { [name: string]: string }, clientOrServer: ClientServer) { 57 | const eventEnum: string[] = []; 58 | const interfaces: string[] = []; 59 | const functions: string[] = []; 60 | 61 | for (const event of events.sort((a, b) => a.name.localeCompare(b.name))) { 62 | eventEnum.push(defineEnumEntry(event)); 63 | 64 | const eventDataType = getEventType(event, "EventData", clientOrServer); 65 | if (eventDataType.interfaceDefinition != null) { 66 | interfaces.push(eventDataType.interfaceDefinition); 67 | } 68 | 69 | const enumName = `ReceiveFromMinecraft${clientOrServer}`; 70 | const enumValueName = minecraftIdentifierToCamelCase(event.name); 71 | 72 | functions.push( 73 | defineFunction( 74 | "listenForEvent", 75 | event.description, 76 | [ 77 | `eventIdentifier: ${enumName}.${enumValueName}`, 78 | `callback: (eventData: IEventData<${eventDataType.type}>) => void` 79 | ], 80 | `boolean | null` 81 | ) 82 | ); 83 | } 84 | 85 | const resultVariableName = `${clientOrServer.toLowerCase()}Listening`; 86 | const functionVariableName = `listenForEvent${clientOrServer}`; 87 | 88 | values[resultVariableName + "EventEnum"] = eventEnum.join(",\n"); 89 | values[resultVariableName + "EventInterfaces"] = interfaces.join("\n\n"); 90 | values[functionVariableName] = functions.join("\n"); 91 | }; 92 | 93 | function getEventType(event: Event, interfaceSuffix: string, clientOrServer: ClientServer) { 94 | if (event.type) { 95 | const enumValueName = minecraftIdentifierToCamelCase(event.name); 96 | const interfaceName = `I${enumValueName}${interfaceSuffix}`; 97 | if (isWellKnownType(event.type)) { 98 | return { 99 | type: getType(event.type, event.name), 100 | interfaceDefinition: null 101 | }; 102 | } else { 103 | return { 104 | type: interfaceName, 105 | interfaceDefinition: defineInterface(interfaceName, event.description, event.type, `${clientOrServer}-event(${enumValueName})`) 106 | }; 107 | } 108 | } 109 | return { 110 | type: "any", 111 | interfaceDefinition: null 112 | } 113 | } 114 | 115 | function defineEnumEntry(event: Event) { 116 | return `\ 117 | ${formatComment(event.description)} 118 | ${minecraftIdentifierToCamelCase(event.name)} = "${event.name}"`; 119 | } 120 | 121 | function defineInterface(name: string, description: string, type: Type, context: string) { 122 | const eventBody = getTypeAsString(type, context); 123 | 124 | return(`\ 125 | ${formatComment(description)} 126 | declare interface ${name} ${eventBody}`); 127 | } 128 | 129 | function defineFunction(name: string, description: string, parameters: string[], returnType: string) { 130 | return `\ 131 | ${formatComment(description)} 132 | ${name}(${parameters.join(", ")}): ${returnType};` 133 | } 134 | 135 | function formatComment(description: string) { 136 | return `\ 137 | /** 138 | * ${description.replace(/\n/g, "\n * ")} 139 | */` 140 | } -------------------------------------------------------------------------------- /generator/src/identifiers.ts: -------------------------------------------------------------------------------- 1 | const capitalizationFixes = [ 2 | 'UI', 3 | 'LookAt' 4 | ] 5 | const capitalizationFixMap = new Map(); 6 | capitalizationFixes.forEach(x => capitalizationFixMap.set(x.toLowerCase(), x)); 7 | 8 | const specialIdentifiers = new Map(); 9 | specialIdentifiers.set("minecraft:display_chat_event", "DisplayChat"); 10 | 11 | export function minecraftIdentifierToCamelCase(identifier: string): string { 12 | if (specialIdentifiers.has(identifier)) return specialIdentifiers.get(identifier)!; 13 | return identifier.replace(/^minecraft:/, "_").replace(/_([a-z]+)/g, (x, identifierPart) => { 14 | if (capitalizationFixMap.has(identifierPart)) return capitalizationFixMap.get(identifierPart); 15 | return identifierPart[0].toUpperCase() + identifierPart.substring(1); 16 | }); 17 | } -------------------------------------------------------------------------------- /generator/src/index.ts: -------------------------------------------------------------------------------- 1 | import template from "./template"; 2 | import * as fs from "fs"; 3 | import extractComponents from "./components"; 4 | import { extractListeningEvents, extractTriggerableEvents} from "./events"; 5 | import { ClientServer } from "./events"; 6 | import { debugPrintTypeNames } from "./type"; 7 | import { MinecraftScriptDocumentation, applyOverrides, IScriptingDocumentationOverrides } from "minecraft-documentation-extractor"; 8 | import extractMethods from "./methods"; 9 | 10 | const sourceFile = "./Documentation_Scripting.html"; 11 | const templateFiles = "./template/**"; 12 | const outputDir = "../packages"; 13 | 14 | (async () => { 15 | const documentation = await MinecraftScriptDocumentation.fromFile(sourceFile, { sort: true, fix: true }); 16 | const overrides = JSON.parse(await fs.promises.readFile("./typing-overrides.json", "utf8")); 17 | applyOverrides(documentation, overrides); 18 | const values = {}; 19 | 20 | extractMethods(documentation, values); 21 | 22 | extractComponents(documentation, values); 23 | 24 | extractListeningEvents(documentation.events.client.listening, values, ClientServer.Client); 25 | extractTriggerableEvents(documentation.events.client.triggerable, values, ClientServer.Client); 26 | extractListeningEvents(documentation.events.server.listening, values, ClientServer.Server); 27 | extractTriggerableEvents(documentation.events.server.triggerable, values, ClientServer.Server); 28 | 29 | await template(templateFiles, outputDir, values); 30 | 31 | debugPrintTypeNames(); 32 | })(); 33 | -------------------------------------------------------------------------------- /generator/src/methods.ts: -------------------------------------------------------------------------------- 1 | import { MinecraftScriptDocumentation, isArrayType, isWellKnownType, System, Method } from "minecraft-documentation-extractor"; 2 | import { getTypeAsString } from "./type"; 3 | import { isObject } from "util"; 4 | 5 | export default function extractMethods(documentation: MinecraftScriptDocumentation, values: { [name: string]: string }) { 6 | 7 | const serverSystemMethods: string[] = []; 8 | const clientSystemMethods: string[] = []; 9 | 10 | const sortSystemMethods = (a: Method, b:Method) => { 11 | return (a.category || "").localeCompare((b.category || "")) || 12 | a.name.localeCompare(b.name); 13 | } 14 | 15 | let currentCategory = null; 16 | for (const method of documentation.systemMethods.sort(sortSystemMethods)) { 17 | var parameters: string[] = [] 18 | var parameterDocumentation: string[] = []; 19 | var returnDocumentation: string[] = []; 20 | if (method.parameters !== undefined) { 21 | for (const parameter of method.parameters) { 22 | let pName = parameter.name.split(" ").map(n => n[0].toUpperCase() + n.substring(1)).join(""); 23 | 24 | pName = pName[0].toLowerCase() + pName.substring(1) + (parameter.isOptional ? "?" : ""); 25 | const pType = getTypeAsString(parameter.type, `${method.name}(${parameter.name})`) 26 | const pDefault = !!parameter.defaultValue ? ` = ${parameter.defaultValue}` : "" 27 | parameters.push(`${pName}: ${pType}${pDefault}`) 28 | if (parameter.description) { 29 | parameterDocumentation.push(`@param ${pName} ${parameter.description}`) 30 | } 31 | } 32 | } 33 | 34 | var parameterString = parameters.join(", "); 35 | let returnType = "void"; 36 | if (method.returnTypes !== undefined) { 37 | returnType = method.returnTypes.map(rt => { 38 | if (rt.description) { 39 | returnDocumentation.push(`@return ${rt.value} ${rt.description}`) 40 | } 41 | if (rt.value == "object" || isObject(rt.type)) { 42 | return getTypeAsString(rt.type, `${method.name}(returnType)`); 43 | } 44 | if (rt.value !== undefined && !!rt.value) { 45 | return rt.value; 46 | } 47 | return "any"; 48 | }).join(" | "); 49 | } 50 | var description = ` * ${method.description.replace("\n", "\n * ")}` 51 | let methodDefinition = ""; 52 | if (currentCategory != method.category) { 53 | currentCategory = method.category; 54 | methodDefinition = `\ 55 | 56 | //////////////////////////////////////////////// 57 | // ${currentCategory} 58 | //////////////////////////////////////////////// 59 | ` 60 | } 61 | methodDefinition = methodDefinition + `\ 62 | /** 63 | ${description}${parameterDocumentation ? "\n * " + parameterDocumentation.join("\n * ") : ""}${returnDocumentation ? "\n * " + returnDocumentation.join("\n * ") : ""} 64 | */ 65 | ${method.name}(${parameterString}): ${returnType};` 66 | 67 | if (method.system == System.Server || method.system == System.Both) { 68 | serverSystemMethods.push(methodDefinition); 69 | } 70 | if (method.system == System.Client || method.system == System.Both) { 71 | clientSystemMethods.push(methodDefinition); 72 | } 73 | } 74 | 75 | values.serverSystemMethods = serverSystemMethods.join("\n"); 76 | values.clientSystemMethods = clientSystemMethods.join("\n"); 77 | }; 78 | -------------------------------------------------------------------------------- /generator/src/template.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs"; 2 | import * as path from "path"; 3 | import { promisify } from "util"; 4 | import { src, dest } from "vinyl-fs"; 5 | import * as pump from "pump"; 6 | import * as replace from "gulp-replace"; 7 | import { prepend } from "gulp-insert"; 8 | 9 | const promisifiedPump: (...streams: pump.Stream[]) => Promise = promisify(pump); 10 | 11 | const FILE_HEADER = `\ 12 | ////////////////////////////////////////////////////////////// 13 | // This file is generated from the Minecraft documentation. // 14 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 15 | ////////////////////////////////////////////////////////////// 16 | 17 | `; 18 | 19 | export default async function (templateFiles: string | string[], outputDir: string, values: { [name: string]: string }) { 20 | const regex = /^([ \t]*)\$\$(.*)\$\$/gm; 21 | const replaceFunction: any = (text: string, indent: string, name: string) => { 22 | if (!values[name]) throw new Error(`Variable with name "${name}" doesn't exist`); 23 | return values[name].replace(/^/gm, indent); 24 | }; 25 | await promisifiedPump( 26 | src(templateFiles), 27 | replace(regex, replaceFunction), 28 | prepend(FILE_HEADER), 29 | dest(outputDir)); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /generator/src/type.ts: -------------------------------------------------------------------------------- 1 | import { Type, isWellKnownType, isArrayType, isUnionType, Field } from "minecraft-documentation-extractor"; 2 | 3 | const typeMap: Map = new Map(Object.entries({ 4 | "string": "string", 5 | "decimal": "number", 6 | "integer": "number", 7 | "boolean": "boolean", 8 | "json object": "any", 9 | "array": "any[]", 10 | "list": "any[]", 11 | "range [a, b]": "Range", 12 | "vector [a, b, c]": "VectorArray", 13 | "vector {x, y, z}": "VectorXYZ", 14 | "minecraft filter": "MinecraftFilter", 15 | "block js api object": "IBlock", 16 | "component js api object": "IComponent", 17 | "entity js api object": "IEntity", 18 | "entity ticking area js api object": "IEntityTickingArea", 19 | "itemstack js api object": "IItemStack", 20 | "minecraft trigger object": "MinecraftTrigger", 21 | "minecraft trigger": "MinecraftTrigger | string", 22 | "sound identifier": "string", 23 | "ticking area js api object": "ITickingArea", 24 | "entity identifier": "string", 25 | "particle identifier": "ParticleEffect", 26 | "dimension name": "Dimension", 27 | "null": "null", 28 | 29 | "execute command callback": "(callback: IExecuteCommandCallback) => void" 30 | })); 31 | 32 | const allTypeNames = new Set(); 33 | 34 | export default function getType(typeName: string, context: string): string { 35 | allTypeNames.add(typeName); 36 | let type = typeMap.get(typeName.toLowerCase()); 37 | if (!type) { 38 | console.warn(`[${context}] Unexpected type encountered: ${typeName.toLowerCase()}`); 39 | return "any"; 40 | } 41 | return type; 42 | } 43 | 44 | export function debugPrintTypeNames() { 45 | console.log(allTypeNames); 46 | } 47 | 48 | export function getField(field: Field, parameterPath: string, indent: number): string { 49 | let name = field.name; 50 | if (field.isOptional) { 51 | name = `${name}?`; 52 | } 53 | 54 | let defaultComment = ""; 55 | if (field.defaultValue) { 56 | defaultComment = `\n\t * @default ${field.defaultValue}`; 57 | } 58 | 59 | const type = getTypeAsString(field.type, `${parameterPath.substring(0, parameterPath.length - 1)}.${field.name})`, indent + 1) 60 | 61 | return ` 62 | \t/** 63 | \t * ${field.description.replace(/\n/g, "\n\t * ")}${defaultComment} 64 | \t */ 65 | \t${name}: ${type};`.replace(/\t/g, " ".repeat(indent)); 66 | } 67 | 68 | export function getTypeAsString(type: Type, parameterPath: string, indent: number = 1): string { 69 | if (!type) return ""; 70 | if (isWellKnownType(type)) { 71 | return getType(type, parameterPath); 72 | } 73 | if (isArrayType(type)) { 74 | const innerType = getTypeAsString(type.type, parameterPath, indent); 75 | return `${innerType}[]`; 76 | } 77 | if (isUnionType(type)) { 78 | return type.unionTypes 79 | .map(ut => getTypeAsString(ut, parameterPath, indent)) 80 | .join(" | "); 81 | } 82 | const childParameters = type.fields 83 | .sort((a, b) => a.name.localeCompare(b.name)) 84 | .map(p => getField(p, `${parameterPath.substring(0, parameterPath.length - 1)}.${p.name})`, indent)) 85 | .join(""); 86 | return `{${childParameters}\n${" ".repeat(indent - 1)}}`; 87 | } 88 | -------------------------------------------------------------------------------- /generator/template/client/types/client_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * (Client-side) Events that can be sent to Minecraft to achieve an effect. 3 | */ 4 | declare const enum SendToMinecraftClient { 5 | $$clientTriggerableEventEnum$$ 6 | } 7 | 8 | /** 9 | * (Client-side) Events that can be received from Minecraft 10 | */ 11 | declare const enum ReceiveFromMinecraftClient { 12 | $$clientListeningEventEnum$$ 13 | } 14 | 15 | $$clientTriggerableEventInterfaces$$ 16 | 17 | $$clientListeningEventInterfaces$$ 18 | -------------------------------------------------------------------------------- /generator/template/client/types/client_system.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare interface IClientSystem { 4 | $$clientSystemMethods$$ 5 | } 6 | -------------------------------------------------------------------------------- /generator/template/client/types/client_system_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare interface IVanillaClientSystemBase { 4 | /////////////////////////// 5 | // createEventData overloads 6 | 7 | $$createEventDataClient$$ 8 | 9 | /////////////////////////// 10 | // broadcastEvent overloads 11 | 12 | $$broadcastEventClient$$ 13 | 14 | /////////////////////////// 15 | // listenForEvent overloads 16 | 17 | $$listenForEventClient$$ 18 | 19 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 20 | // Generic method for other custom events 21 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * Registers the Event to the script engine. This allows you to create Event Data by calling createEventData and have it initialized with the correct default data and fields. Only custom events need to be registered. 25 | * 26 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 27 | * @param eventData The JavaScript object with the correct fields and default values for the event 28 | */ 29 | registerEventData(eventIdentifier: string, eventData: TEventDataType): true | null; 30 | 31 | /** 32 | * Creates an object with all the required fields and default data for the specified event. If the event is a custom event, it needs to have been previously registered. 33 | * 34 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 35 | */ 36 | createEventData(eventIdentifier: string): IEventData | null; 37 | 38 | /** 39 | * 40 | * @param eventIdentifier Allows you to trigger an event with the desired data from script. 41 | * Anything that signed up to listen for the event will be notified and the given data delivered to them. 42 | * @param eventData The data for the event. You can create a new JavaScript Object with the parameters you want to pass in to the listener and the engine will take care of delivering the data to them 43 | */ 44 | broadcastEvent(eventIdentifier: string, eventData: IEventData): boolean | null; 45 | 46 | /** 47 | * Allows you to register a JavaScript object that gets called whenever the specified event is broadcast. The event can either be a built-in event or an event specified in script. 48 | * @param eventIdentifier This is the name of the event to which we want to react. Can be the identifier of a built-in event or a custom one from script 49 | * @param eventData The name of the JavaScript object that will get called whenever the event is broadcast 50 | */ 51 | listenForEvent(eventIdentifier: string, callback: (eventData: IEventData) => void): boolean | null; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /generator/template/server/types/server_component.generated.d.ts: -------------------------------------------------------------------------------- 1 | $$componentInterfaces$$ 2 | -------------------------------------------------------------------------------- /generator/template/server/types/server_component_names.generated.d.ts: -------------------------------------------------------------------------------- 1 | declare const enum MinecraftComponent { 2 | $$componentEnum$$ 3 | } 4 | -------------------------------------------------------------------------------- /generator/template/server/types/server_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * (Server-side) Events that can be sent to Minecraft to achieve an effect. 3 | */ 4 | declare const enum SendToMinecraftServer { 5 | $$serverTriggerableEventEnum$$ 6 | } 7 | 8 | /** 9 | * (Server-side) Events that can be received from Minecraft 10 | */ 11 | declare const enum ReceiveFromMinecraftServer { 12 | $$serverListeningEventEnum$$ 13 | } 14 | 15 | $$serverListeningEventInterfaces$$ 16 | 17 | $$serverTriggerableEventInterfaces$$ 18 | -------------------------------------------------------------------------------- /generator/template/server/types/server_system.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | declare interface IServerSystem { 5 | $$serverSystemMethods$$ 6 | } 7 | -------------------------------------------------------------------------------- /generator/template/server/types/server_system_components.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | declare interface IVanillaServerSystemBase { 5 | $$createComponent$$ 6 | 7 | $$getComponent$$ 8 | 9 | /** 10 | * Creates a component of the specified name and adds it to the entity. This should only be used with custom components which need 11 | * to be registered first. If the entity already has the component, this will retrieve the component already there instead. 12 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 13 | * @param componentName The name of the component to add to the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 14 | * @returns An object with all the fields as defined in the component, or null if something went wrong when creating the component 15 | */ 16 | createComponent(entity: IEntity, componentName: string): IComponent | null; 17 | 18 | /** 19 | * Looks for the specified component in the entity. If it exists, retrieves the data from the component and returns it. 20 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 21 | * @param componentIdentifier The name of the component to retrieve from the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 22 | * @returns An object containing the data of the component as described in the component itself, or null if the entity did not have the component or something went wrong when getting the component 23 | */ 24 | getComponent(entity: IEntity, componentIdentifier: MinecraftComponent | string): IComponent | null; 25 | } 26 | -------------------------------------------------------------------------------- /generator/template/server/types/server_system_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare interface IVanillaServerSystemBase { 4 | /////////////////////////// 5 | // createEventData overloads 6 | 7 | $$createEventDataServer$$ 8 | 9 | /////////////////////////// 10 | // broadcastEvent overloads 11 | 12 | $$broadcastEventServer$$ 13 | 14 | /////////////////////////// 15 | // listenForEvent overloads 16 | 17 | $$listenForEventServer$$ 18 | 19 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 20 | // Generic method for other custom events 21 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * Registers the Event to the script engine. This allows you to create Event Data by calling createEventData and have it initialized with the correct default data and fields. Only custom events need to be registered. 25 | * 26 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 27 | * @param eventData The JavaScript object with the correct fields and default values for the event 28 | */ 29 | registerEventData(eventIdentifier: string, eventData: TEventDataType): true | null; 30 | 31 | /** 32 | * Creates an object with all the required fields and default data for the specified event. If the event is a custom event, it needs to have been previously registered. 33 | * 34 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 35 | */ 36 | createEventData(eventIdentifier: string): IEventData | null; 37 | 38 | /** 39 | * 40 | * @param eventIdentifier Allows you to trigger an event with the desired data from script. 41 | * Anything that signed up to listen for the event will be notified and the given data delivered to them. 42 | * @param eventData The data for the event. You can create a new JavaScript Object with the parameters you want to pass in to the listener and the engine will take care of delivering the data to them 43 | */ 44 | broadcastEvent(eventIdentifier: string, eventData: IEventData): boolean | null; 45 | 46 | /** 47 | * Allows you to register a JavaScript object that gets called whenever the specified event is broadcast. The event can either be a built-in event or an event specified in script. 48 | * @param eventIdentifier This is the name of the event to which we want to react. Can be the identifier of a built-in event or a custom one from script 49 | * @param eventData The name of the JavaScript object that will get called whenever the event is broadcast 50 | */ 51 | listenForEvent(eventIdentifier: string, callback: (eventData: IEventData) => void): boolean | null; 52 | } 53 | -------------------------------------------------------------------------------- /generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "lib": [ 5 | "es2018" 6 | ], 7 | "module": "commonjs", 8 | "sourceMap": true, 9 | "outDir": "./out", 10 | "strict": true, 11 | "resolveJsonModule": true 12 | }, 13 | "include": [ 14 | "src/*" 15 | ] 16 | } -------------------------------------------------------------------------------- /generator/typing-overrides.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/minecraft-addon-tools/minecraft-documentation-extractor/9b1c9537b061aeb8f0839272d9738d408ae7e21e/src/type-overrides.schema.json", 3 | "version": { 4 | "major": 1, 5 | "minor": 12, 6 | "revision": 0, 7 | "build": 9 8 | }, 9 | "overrides": { 10 | "systemMethods": { 11 | "registerComponent": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 12 | "createComponent": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 13 | "getComponent": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 14 | "applyComponentChanges": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 15 | 16 | "registerEventData": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 17 | "createEventData": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 18 | "listenForEvent": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 19 | "broadcastEvent": { "_operation": "remove", "_comment": "Removed to make use of generics" }, 20 | 21 | "executeCommand": { 22 | "findByParameters": ["Command", "Callback"], 23 | "override": { 24 | "parameters": { 25 | "Callback": { 26 | "type": "Execute Command Callback" 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "1.0.0" 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "devDependencies": { 5 | "lerna": "^3.5.1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/client/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | -------------------------------------------------------------------------------- /packages/client/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-client", 3 | "version": "1.0.0-alpha.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "typescript": { 8 | "version": "3.2.1", 9 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.1.tgz", 10 | "integrity": "sha512-jw7P2z/h6aPT4AENXDGjcfHTu5CSqzsbZc6YlUIebTyBAq8XaKp78x7VcSh30xwSCcsu5irZkYZUSFP1MrAMbg==", 11 | "dev": true 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-client", 3 | "version": "1.0.0", 4 | "description": "Client-side TypeScript definitions for Minecraft Bedrock Edition's scripting engine", 5 | "contributors": [ 6 | "AtomicBlom", 7 | "abc55" 8 | ], 9 | "homepage": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 10 | "repository": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 11 | "license": "CC-BY-NC-SA-3.0", 12 | "dependencies": { 13 | "minecraft-scripting-types-shared": "^1.0.0" 14 | }, 15 | "devDependencies": { 16 | "typescript": "^3.1.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/client/tsconfig.json: -------------------------------------------------------------------------------- 1 | // This file keeps IDEs happy, it is not used for compilation 2 | { 3 | "compilerOptions": { 4 | "module": "ES6", 5 | "noImplicitAny": true, 6 | "rootDir": "./types", 7 | "target": "es5" 8 | } 9 | } -------------------------------------------------------------------------------- /packages/client/types/client.d.ts: -------------------------------------------------------------------------------- 1 | declare const client: IClient; 2 | 3 | declare interface IClient { 4 | registerSystem = IVanillaClientSystem>(majorVersion: number, minorVersion: number): TSystem; 5 | log(message: string): void; 6 | } 7 | -------------------------------------------------------------------------------- /packages/client/types/client_component.generated.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The MoLang component gives access to the MoLang variables in an entity. To learn more about MoLang varibles review the add-on documentation. In scripts, you can get and set these varibles that are defined in the entity's JSON files. Because of how the MoLang variables are formatted (entity.isgrazing for example) you must use the [] operator on the object to access the variable. The example below shows how to use the [] operator to access the variable. 3 | */ 4 | declare interface IMoLangComponent { 5 | [key: string]: any; 6 | } -------------------------------------------------------------------------------- /packages/client/types/client_component_names.generated.d.ts: -------------------------------------------------------------------------------- 1 | declare const enum MinecraftComponent { 2 | /** 3 | * The MoLang component gives access to the MoLang variables in an entity. To learn more about MoLang varibles review the add-on documentation. In scripts, you can get and set these varibles that are defined in the entity's JSON files. Because of how the MoLang variables are formatted (entity.isgrazing for example) you must use the [] operator on the object to access the variable. The example below shows how to use the [] operator to access the variable. 4 | */ 5 | MoLang = "minecraft:molang", 6 | 7 | } -------------------------------------------------------------------------------- /packages/client/types/client_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /** 7 | * (Client-side) Events that can be sent to Minecraft to achieve an effect. 8 | */ 9 | declare const enum SendToMinecraftClient { 10 | /** 11 | * This event is used to display a chat message to the specific player that is running the client script. The event data is the message to be displayed in plain text. Special formatting is supported the same way it would be if a player was sending the message. 12 | */ 13 | DisplayChat = "minecraft:display_chat_event", 14 | /** 15 | * This event is used to show a UI screen to the specific player running the client script. This event will add the UI screen to the top of the UI screen stack. The screen will be shown immediately after the event is triggered. Only screens defined in a HTML file can be shown using this event. 16 | */ 17 | LoadUI = "minecraft:load_ui", 18 | /** 19 | * This event is used to turn various levels of logging on and off for client scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL client scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 20 | */ 21 | ScriptLoggerConfig = "minecraft:script_logger_config", 22 | /** 23 | * This event is used to send UI events to the UI Engine for the specific player running the script. After the event is triggered, the UI event will be sent immediately. 24 | * Custom UI is based on HTML 5. Review the scripting demo for an example of a custom UI file. 25 | */ 26 | SendUIEvent = "minecraft:send_ui_event", 27 | /** 28 | * This event is used to create a particle effect that will follow an entity around. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 29 | */ 30 | SpawnParticleAttachedEntity = "minecraft:spawn_particle_attached_entity", 31 | /** 32 | * This event is used to create a static particle effect in the world. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. Unlike the server version of the event, the client version will spawn the particle in the dimension the player is currently in. 33 | */ 34 | SpawnParticleInWorld = "minecraft:spawn_particle_in_world", 35 | /** 36 | * This event is used to remove a UI screen from the stack of the specific player running the client script. The event data contains the name of the screen to remove as a string. After the event is triggered the screen will be scheduled to be removed from the stack the next time the UI Engine can do so. Only screens defined in a HTML file can be removed using this event. 37 | */ 38 | UnloadUI = "minecraft:unload_ui" 39 | } 40 | 41 | /** 42 | * (Client-side) Events that can be received from Minecraft 43 | */ 44 | declare const enum ReceiveFromMinecraftClient { 45 | /** 46 | * This event is fired whenever a player joins the world. The event data contains the player entity object. 47 | */ 48 | ClientEnteredWorld = "minecraft:client_entered_world", 49 | /** 50 | * This event is triggered whenever the reticle changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 51 | */ 52 | HitResultChanged = "minecraft:hit_result_changed", 53 | /** 54 | * This event is triggered every update and tells you what entity the reticle is pointing to in the world up to 1000 blocks away. 55 | */ 56 | HitResultContinuous = "minecraft:hit_result_continuous", 57 | /** 58 | * This event is triggered whenever the mouse pointer changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 59 | */ 60 | PickHitResultChanged = "minecraft:pick_hit_result_changed", 61 | /** 62 | * This event is triggered every update and tells you what entity the mouse pointer is pointing to in the world up to 1000 blocks away. 63 | */ 64 | PickHitResultContinuous = "minecraft:pick_hit_result_continuous", 65 | /** 66 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 67 | */ 68 | UIEvent = "minecraft:ui_event" 69 | } 70 | 71 | /** 72 | * This event is used to display a chat message to the specific player that is running the client script. The event data is the message to be displayed in plain text. Special formatting is supported the same way it would be if a player was sending the message. 73 | */ 74 | declare interface IDisplayChatParameters { 75 | /** 76 | * The chat message that will be displayed 77 | */ 78 | message: string; 79 | } 80 | 81 | /** 82 | * This event is used to show a UI screen to the specific player running the client script. This event will add the UI screen to the top of the UI screen stack. The screen will be shown immediately after the event is triggered. Only screens defined in a HTML file can be shown using this event. 83 | */ 84 | declare interface ILoadUIParameters { 85 | /** 86 | * You can define the following options for the screen by setting their value to true or false: 87 | */ 88 | options?: { 89 | /** 90 | * If true, input will not be passed down to any other screens underneath 91 | */ 92 | absorbs_input?: boolean; 93 | /** 94 | * If true, the screen will always accept and process input for as long as it is in the stack, even if other custom UI screens appear on top of it 95 | */ 96 | always_accepts_input?: boolean; 97 | /** 98 | * If true, this screen will be rendered even if another screen is on top of it and will render over them, including the HUD 99 | */ 100 | force_render_below?: boolean; 101 | /** 102 | * If true, the screen will be treated as the pause menu and the pause menu won't be allowed to show on top of this screen 103 | */ 104 | is_showing_menu?: boolean; 105 | /** 106 | * If true, the game will continue to be rendered underneath this screen 107 | */ 108 | render_game_behind?: boolean; 109 | /** 110 | * If true, this screen will only be rendered if it is the screen at the top of the stack 111 | */ 112 | render_only_when_topmost?: boolean; 113 | /** 114 | * If true, the screen will capture the mouse pointer and limit its movement to the UI screen 115 | */ 116 | should_steal_mouse?: boolean; 117 | }; 118 | /** 119 | * The file path to the screen's HTML file 120 | */ 121 | path: string; 122 | } 123 | 124 | /** 125 | * This event is used to turn various levels of logging on and off for client scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL client scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 126 | */ 127 | declare interface IScriptLoggerConfigParameters { 128 | /** 129 | * Set to true to log any scripting errors that occur on the client 130 | * @default false 131 | */ 132 | log_errors: boolean; 133 | /** 134 | * Set to true to log any general scripting information that occurs on the client. This includes any logging done with client.log() 135 | * @default false 136 | */ 137 | log_information: boolean; 138 | /** 139 | * Set to true to log any scripting warnings that occur on the client 140 | * @default false 141 | */ 142 | log_warnings: boolean; 143 | } 144 | 145 | /** 146 | * This event is used to send UI events to the UI Engine for the specific player running the script. After the event is triggered, the UI event will be sent immediately. 147 | * Custom UI is based on HTML 5. Review the scripting demo for an example of a custom UI file. 148 | */ 149 | declare interface ISendUIEventParameters { 150 | /** 151 | * The data for the UI event being triggered 152 | */ 153 | data: string; 154 | /** 155 | * The identifier of the UI event 156 | */ 157 | eventIdentifier: string; 158 | } 159 | 160 | /** 161 | * This event is used to create a particle effect that will follow an entity around. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 162 | */ 163 | declare interface ISpawnParticleAttachedEntityParameters { 164 | /** 165 | * The identifier of the particle effect you want to attach to the entity. This is the same name you gave the effect in its JSON file 166 | */ 167 | effect: ParticleEffect; 168 | /** 169 | * The entity object you want to attach the effect to 170 | */ 171 | entity: IEntity; 172 | /** 173 | * The offset from the entity's "center" where you want to spawn the effect 174 | * @default [0, 0, 0] 175 | */ 176 | offset: VectorArray; 177 | } 178 | 179 | /** 180 | * This event is used to create a static particle effect in the world. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. Unlike the server version of the event, the client version will spawn the particle in the dimension the player is currently in. 181 | */ 182 | declare interface ISpawnParticleInWorldParameters { 183 | /** 184 | * The identifier of the particle effect you want to attach to spawn. This is the same name you gave the effect in its JSON file 185 | */ 186 | effect: ParticleEffect; 187 | /** 188 | * The position in the world where you want to spawn the effect 189 | * @default [0, 0, 0] 190 | */ 191 | position: VectorArray; 192 | } 193 | 194 | /** 195 | * This event is used to remove a UI screen from the stack of the specific player running the client script. The event data contains the name of the screen to remove as a string. After the event is triggered the screen will be scheduled to be removed from the stack the next time the UI Engine can do so. Only screens defined in a HTML file can be removed using this event. 196 | */ 197 | declare interface IUnloadUIParameters { 198 | /** 199 | * The file path to the screen's HTML file 200 | */ 201 | path: string; 202 | } 203 | 204 | /** 205 | * This event is fired whenever a player joins the world. The event data contains the player entity object. 206 | */ 207 | declare interface IClientEnteredWorldEventData { 208 | /** 209 | * the player entering the world 210 | */ 211 | player: IEntity; 212 | } 213 | 214 | /** 215 | * This event is triggered whenever the reticle changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 216 | */ 217 | declare interface IHitResultChangedEventData { 218 | /** 219 | * The entity that was hit or null if it fired when moving off of an entity 220 | */ 221 | entity: IEntity; 222 | /** 223 | * The position of the entity that was hit or null if it fired when moving off an entity 224 | */ 225 | position: VectorXYZ | null; 226 | } 227 | 228 | /** 229 | * This event is triggered every update and tells you what entity the reticle is pointing to in the world up to 1000 blocks away. 230 | */ 231 | declare interface IHitResultContinuousEventData { 232 | /** 233 | * The entity that was hit or null if it not pointing at an entity 234 | */ 235 | entity: IEntity; 236 | /** 237 | * The position of the entity that was hit or block that was hit 238 | */ 239 | position: VectorXYZ; 240 | } 241 | 242 | /** 243 | * This event is triggered whenever the mouse pointer changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 244 | */ 245 | declare interface IPickHitResultChangedEventData { 246 | /** 247 | * The entity that was hit or null if it fired when moving off of an entity 248 | */ 249 | entity: IEntity; 250 | /** 251 | * The position of the entity that was hit or null if it fired when moving off an entity 252 | */ 253 | position: VectorXYZ | null; 254 | } 255 | 256 | /** 257 | * This event is triggered every update and tells you what entity the mouse pointer is pointing to in the world up to 1000 blocks away. 258 | */ 259 | declare interface IPickHitResultContinuousEventData { 260 | /** 261 | * The entity that was hit or null if it not pointing at an entity 262 | */ 263 | entity: IEntity; 264 | /** 265 | * The position of the entity that was hit or block that was hit 266 | */ 267 | position: VectorXYZ; 268 | } 269 | -------------------------------------------------------------------------------- /packages/client/types/client_system.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This interface is used to include the generated methods on the IClientSystem in a way that the generic variants do not 3 | * take precidence over the specific, generated versions. 4 | */ 5 | 6 | declare interface IVanillaClientSystemBase { 7 | /** 8 | * Allows you to register a query that will only show entities that have the given component and define which fields of that component will be used as a filter when getting the entities from the query. 9 | * 10 | * This is the identifier of the component that will be used to filter entities when 11 | * @param componentField1 This is the name of the first field of the component that we want to filter entities by. By default this is set to x. If the component you used doesn't have the field you defined here, the field will be ignored 12 | * @param componentField2 This is the name of the second field of the component that we want to filter entities by. By default this is set to y. If the component you used doesn't have the field you defined here, the field will be ignored 13 | * @param componentField3 This is the name of the third field of the component that we want to filter entities by. By default this is set to z. If the component you used doesn't have the field you defined here, the field will be ignored 14 | */ 15 | registerQuery(component: MinecraftComponent | string, componentField1?: string, componentField2?: string, componentField3?: string): IQuery; 16 | 17 | /** 18 | * Allows you to register a query. A query will contain all entities that meet the filter requirement. 19 | * No filters are added by default when you register a query so it will capture all entities. 20 | */ 21 | //Ideally this would be in system.d.ts, but it seems to conflict with the parameterized version 22 | registerQuery(): IQuery | null; 23 | } 24 | 25 | declare interface IClientSystem extends ISystem, IVanillaClientSystemBase { 26 | 27 | } 28 | 29 | /** 30 | * a utility interface that defines a system that is not being actively extended 31 | */ 32 | declare interface IVanillaClientSystem extends IClientSystem { 33 | 34 | } -------------------------------------------------------------------------------- /packages/client/types/client_system.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /// 7 | 8 | declare interface IClientSystem { 9 | 10 | //////////////////////////////////////////////// 11 | // Blocks 12 | //////////////////////////////////////////////// 13 | /** 14 | * Allows you to get a block from the world when provided an x, y, and z position. The block must be within a ticking area. 15 | * @param tickingArea The ticking area the block is in 16 | * @param x The x position of the block you want 17 | * @param y The y position of the block you want 18 | * @param z The z position of the block you want 19 | * @return object An object containing the block 20 | * @return null Something went wrong when retrieving the block 21 | */ 22 | getBlock(tickingArea: ITickingArea, x: number, y: number, z: number): IBlock | null; 23 | /** 24 | * Allows you to get a block from the world when provided a JavaScript object containing a position. The block must be within a ticking area. 25 | * @param tickingArea The ticking area the block is in 26 | * @param positionObject A JavaScript object with the x, y, and z position of the block you want 27 | * @return object An object containing the block 28 | * @return null Something went wrong when retrieving the block 29 | */ 30 | getBlock(tickingArea: ITickingArea, positionObject: VectorXYZ): IBlock | null; 31 | /** 32 | * Allows you to get an array of blocks from the world when provided a minimum and maximum x, y, and z position. The blocks must be within a ticking area. 33 | * @param tickingArea The ticking area the blocks are in 34 | * @param xMin The minimum x position of the blocks you want 35 | * @param yMin The minimum y position of the blocks you want 36 | * @param zMin The minimum z position of the blocks you want 37 | * @param xMax The maximum x position of the blocks you want 38 | * @param yMax The maximum y position of the blocks you want 39 | * @param zMax The maximum z position of the blocks you want 40 | * @return undefined A 3D array of block objects. Indexs are the blocks positions relative to the min position given 41 | * @return null Something went wrong when retrieving the blocks 42 | */ 43 | getBlocks(tickingArea: ITickingArea, xMin: number, yMin: number, zMin: number, xMax: number, yMax: number, zMax: number): IBlock[][] | null; 44 | /** 45 | * Allows you to get an array of blocks from the world when provided a minimum and maximum position. The blocks must be within a ticking area. 46 | * @param tickingArea The ticking area the blocks are in 47 | * @param minimumPositionObject A JavaScript object with the minimum x, y, and z position of the blocks you want 48 | * @param maximumPositionObject A JavaScript object with the maximum x, y, and z position of the blocks you want 49 | * @return undefined A 3D array of block objects. Indexs are the blocks positions relative to the min position given 50 | * @return null Something went wrong when retrieving the blocks 51 | */ 52 | getBlocks(tickingArea: ITickingArea, minimumPositionObject: VectorXYZ, maximumPositionObject: VectorXYZ): IBlock[][] | null; 53 | 54 | //////////////////////////////////////////////// 55 | // Components 56 | //////////////////////////////////////////////// 57 | /** 58 | * Removes the specified component from the given entity. If the entity has the component, it will be removed. Currently this only works with custom components and can't be used to remove components defined for an entity in JSON. 59 | * @param entityObject The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 60 | * @param componentIdentifier The identifier of the component to remove from the entity. This is either the identifier of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 61 | * @return true The component was successfully removed from the entity 62 | * @return null The entity did not have the component or something went wrong when removing the component 63 | */ 64 | destroyComponent(entityObject: IEntity, componentIdentifier: string): true | null; 65 | /** 66 | * Checks if the given entity has the specified component. 67 | * @param entityObject The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 68 | * @param componentIdentifier The identifier of the component to check on the entity. This is either the identifier of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 69 | * @return true The EntityObject has the component 70 | * @return false The EntityObject doesn't have the component 71 | * @return null An unknown component was passed in or something else went wrong when checking if the EntityObject had the component 72 | */ 73 | hasComponent(entityObject: IEntity, componentIdentifier: string): true | false | null; 74 | 75 | //////////////////////////////////////////////// 76 | // Entities 77 | //////////////////////////////////////////////// 78 | /** 79 | * Creates an empty entity with no components and does not place it in the world. The empty entity will be of type custom and have a blank identifier. This is NOT a valid entity that exists in the world, just an empty one that only scripts know about. 80 | * 81 | NOTE: Entities are created first on the server, with the client notified of new entities afterwards. Be aware that if you send the result object to the client right away, the created entity might not exist on the client yet. 82 | * 83 | * @return object An object representing the newly created entity 84 | * @return null Something went wrong when creating the entity 85 | */ 86 | createEntity(): IEntity | null; 87 | /** 88 | * Creates an entity and applies the specified template as defined in JSON. This allows you to quickly create an entity from the applied Behavior Packs as the base for an entity created in scripting. The entity will be spawned into the world with all the components, component groups, and event triggers that are defined in the JSON file of the identifier specified. Only works on scripts registered on the server.NOTE: Entities are created first on the server, with the client notified of new entities afterwards. Be aware that if you send the result object to the client right away, the created entity might not exist on the client yet. 89 | * @param type Specifies the type of the entity that is being created by the template. Valid inputs are `entity` and `item_entity` 90 | * @param templateIdentifier This can be any of the entity identifiers from the applied Behavior Packs. For example specifying minecraft:cow here will make the provided entity a cow as defined in JSON 91 | * @return object An object representing the newly created entity 92 | * @return null Something went wrong when creating the entity 93 | */ 94 | createEntity(type: string, templateIdentifier: string): IEntity | null; 95 | /** 96 | * Destroys an entity identified by the EntityObject. If the entity exists in the world this will remove it from the world and destroy it. This also makes the EntityObject no longer valid - you should only destroy an entity after you are done with it and no longer need to reference it again. This does NOT kill the entity. There won't be an event for its death: it will be removed. 97 | * @param entityObject The object that was retrieved from a call to createEntity() or retrieved from an entity event 98 | * @return true The entity was successfully destroyed 99 | * @return null Something went wrong when destroying the entity 100 | */ 101 | destroyEntity(entityObject: IEntity): true | null; 102 | /** 103 | * Checks if the given EntityObject corresponds to a valid entity. 104 | * @param entityObject The object that was retrieved from a call to createEntity() or retrieved from an entity event 105 | * @return true The entity is in the Script Engine's database of entities 106 | * @return false The entity is not in the Script Engine's database of entities 107 | * @return null Something went wrong when validating the entity 108 | */ 109 | isValidEntity(entityObject: IEntity): true | false | null; 110 | } 111 | -------------------------------------------------------------------------------- /packages/client/types/client_system_components.generated.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | declare interface IVanillaClientSystemBase { 5 | 6 | createComponent(entity: IEntity, componentName: MinecraftComponent.MoLang): IComponent | null; 7 | 8 | getComponent(entity: IEntity, componentName: MinecraftComponent.MoLang): IComponent | null; 9 | 10 | /** 11 | * Creates a component of the specified name and adds it to the entity. This should only be used with custom components which need 12 | * to be registered first. If the entity already has the component, this will retrieve the component already there instead. 13 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 14 | * @param componentName The name of the component to add to the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 15 | * @returns An object with all the fields as defined in the component 16 | */ 17 | createComponent(entity: IEntity, componentName: string): IComponent | null; 18 | 19 | /** 20 | * Looks for the specified component in the entity. If it exists, retrieves the data from the component and returns it. 21 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 22 | * @param componentIdentifier The name of the component to retrieve from the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 23 | * @returns An object containing the data of the component as described in the component itself, or null if the entity did not have the component or something went wrong when getting the component 24 | */ 25 | getComponent(entity: IEntity, componentIdentifier: string): IComponent | null; 26 | } -------------------------------------------------------------------------------- /packages/client/types/client_system_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /// 7 | 8 | declare interface IVanillaClientSystemBase { 9 | /////////////////////////// 10 | // createEventData overloads 11 | 12 | /** 13 | * This event is used to display a chat message to the specific player that is running the client script. The event data is the message to be displayed in plain text. Special formatting is supported the same way it would be if a player was sending the message. 14 | */ 15 | createEventData(eventIdentifier: SendToMinecraftClient.DisplayChat): IEventData | null; 16 | /** 17 | * This event is used to show a UI screen to the specific player running the client script. This event will add the UI screen to the top of the UI screen stack. The screen will be shown immediately after the event is triggered. Only screens defined in a HTML file can be shown using this event. 18 | */ 19 | createEventData(eventIdentifier: SendToMinecraftClient.LoadUI): IEventData | null; 20 | /** 21 | * This event is used to turn various levels of logging on and off for client scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL client scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 22 | */ 23 | createEventData(eventIdentifier: SendToMinecraftClient.ScriptLoggerConfig): IEventData | null; 24 | /** 25 | * This event is used to send UI events to the UI Engine for the specific player running the script. After the event is triggered, the UI event will be sent immediately. 26 | * Custom UI is based on HTML 5. Review the scripting demo for an example of a custom UI file. 27 | */ 28 | createEventData(eventIdentifier: SendToMinecraftClient.SendUIEvent): IEventData | null; 29 | /** 30 | * This event is used to create a particle effect that will follow an entity around. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 31 | */ 32 | createEventData(eventIdentifier: SendToMinecraftClient.SpawnParticleAttachedEntity): IEventData | null; 33 | /** 34 | * This event is used to create a static particle effect in the world. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. Unlike the server version of the event, the client version will spawn the particle in the dimension the player is currently in. 35 | */ 36 | createEventData(eventIdentifier: SendToMinecraftClient.SpawnParticleInWorld): IEventData | null; 37 | /** 38 | * This event is used to remove a UI screen from the stack of the specific player running the client script. The event data contains the name of the screen to remove as a string. After the event is triggered the screen will be scheduled to be removed from the stack the next time the UI Engine can do so. Only screens defined in a HTML file can be removed using this event. 39 | */ 40 | createEventData(eventIdentifier: SendToMinecraftClient.UnloadUI): IEventData | null; 41 | 42 | /////////////////////////// 43 | // broadcastEvent overloads 44 | 45 | /** 46 | * This event is used to display a chat message to the specific player that is running the client script. The event data is the message to be displayed in plain text. Special formatting is supported the same way it would be if a player was sending the message. 47 | */ 48 | broadcastEvent(eventIdentifier: SendToMinecraftClient.DisplayChat, eventData: IEventData): boolean | null; 49 | /** 50 | * This event is used to show a UI screen to the specific player running the client script. This event will add the UI screen to the top of the UI screen stack. The screen will be shown immediately after the event is triggered. Only screens defined in a HTML file can be shown using this event. 51 | */ 52 | broadcastEvent(eventIdentifier: SendToMinecraftClient.LoadUI, eventData: IEventData): boolean | null; 53 | /** 54 | * This event is used to turn various levels of logging on and off for client scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL client scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 55 | */ 56 | broadcastEvent(eventIdentifier: SendToMinecraftClient.ScriptLoggerConfig, eventData: IEventData): boolean | null; 57 | /** 58 | * This event is used to send UI events to the UI Engine for the specific player running the script. After the event is triggered, the UI event will be sent immediately. 59 | * Custom UI is based on HTML 5. Review the scripting demo for an example of a custom UI file. 60 | */ 61 | broadcastEvent(eventIdentifier: SendToMinecraftClient.SendUIEvent, eventData: IEventData): boolean | null; 62 | /** 63 | * This event is used to create a particle effect that will follow an entity around. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 64 | */ 65 | broadcastEvent(eventIdentifier: SendToMinecraftClient.SpawnParticleAttachedEntity, eventData: IEventData): boolean | null; 66 | /** 67 | * This event is used to create a static particle effect in the world. This particle effect is only visible to the specific player that is running the client script where you fired the event. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. Unlike the server version of the event, the client version will spawn the particle in the dimension the player is currently in. 68 | */ 69 | broadcastEvent(eventIdentifier: SendToMinecraftClient.SpawnParticleInWorld, eventData: IEventData): boolean | null; 70 | /** 71 | * This event is used to remove a UI screen from the stack of the specific player running the client script. The event data contains the name of the screen to remove as a string. After the event is triggered the screen will be scheduled to be removed from the stack the next time the UI Engine can do so. Only screens defined in a HTML file can be removed using this event. 72 | */ 73 | broadcastEvent(eventIdentifier: SendToMinecraftClient.UnloadUI, eventData: IEventData): boolean | null; 74 | 75 | /////////////////////////// 76 | // listenForEvent overloads 77 | 78 | /** 79 | * This event is fired whenever a player joins the world. The event data contains the player entity object. 80 | */ 81 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.ClientEnteredWorld, callback: (eventData: IEventData) => void): boolean | null; 82 | /** 83 | * This event is triggered whenever the reticle changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 84 | */ 85 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.HitResultChanged, callback: (eventData: IEventData) => void): boolean | null; 86 | /** 87 | * This event is triggered every update and tells you what entity the reticle is pointing to in the world up to 1000 blocks away. 88 | */ 89 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.HitResultContinuous, callback: (eventData: IEventData) => void): boolean | null; 90 | /** 91 | * This event is triggered whenever the mouse pointer changes from pointing at a block or air to pointing at an entity and the other way around. Up to 1000 blocks away. 92 | */ 93 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.PickHitResultChanged, callback: (eventData: IEventData) => void): boolean | null; 94 | /** 95 | * This event is triggered every update and tells you what entity the mouse pointer is pointing to in the world up to 1000 blocks away. 96 | */ 97 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.PickHitResultContinuous, callback: (eventData: IEventData) => void): boolean | null; 98 | /** 99 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 100 | */ 101 | listenForEvent(eventIdentifier: ReceiveFromMinecraftClient.UIEvent, callback: (eventData: IEventData) => void): boolean | null; 102 | 103 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 104 | // Generic method for other custom events 105 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 106 | 107 | /** 108 | * Registers the Event to the script engine. This allows you to create Event Data by calling createEventData and have it initialized with the correct default data and fields. Only custom events need to be registered. 109 | * 110 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 111 | * @param eventData The JavaScript object with the correct fields and default values for the event 112 | */ 113 | registerEventData(eventIdentifier: string, eventData: TEventDataType): true | null; 114 | 115 | /** 116 | * Creates an object with all the required fields and default data for the specified event. If the event is a custom event, it needs to have been previously registered. 117 | * 118 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 119 | */ 120 | createEventData(eventIdentifier: string): IEventData | null; 121 | 122 | /** 123 | * 124 | * @param eventIdentifier Allows you to trigger an event with the desired data from script. 125 | * Anything that signed up to listen for the event will be notified and the given data delivered to them. 126 | * @param eventData The data for the event. You can create a new JavaScript Object with the parameters you want to pass in to the listener and the engine will take care of delivering the data to them 127 | */ 128 | broadcastEvent(eventIdentifier: string, eventData: IEventData): boolean | null; 129 | 130 | /** 131 | * Allows you to register a JavaScript object that gets called whenever the specified event is broadcast. The event can either be a built-in event or an event specified in script. 132 | * @param eventIdentifier This is the name of the event to which we want to react. Can be the identifier of a built-in event or a custom one from script 133 | * @param eventData The name of the JavaScript object that will get called whenever the event is broadcast 134 | */ 135 | listenForEvent(eventIdentifier: string, callback: (eventData: IEventData) => void): boolean | null; 136 | 137 | } 138 | -------------------------------------------------------------------------------- /packages/server/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | -------------------------------------------------------------------------------- /packages/server/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-server", 3 | "version": "1.0.0-alpha.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "typescript": { 8 | "version": "3.2.1", 9 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.1.tgz", 10 | "integrity": "sha512-jw7P2z/h6aPT4AENXDGjcfHTu5CSqzsbZc6YlUIebTyBAq8XaKp78x7VcSh30xwSCcsu5irZkYZUSFP1MrAMbg==", 11 | "dev": true 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-server", 3 | "version": "1.0.0", 4 | "description": "Server-side TypeScript definitions for Minecraft Bedrock Edition's scripting engine", 5 | "contributors": [ 6 | "AtomicBlom", 7 | "abc55" 8 | ], 9 | "homepage": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 10 | "repository": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 11 | "license": "CC-BY-NC-SA-3.0", 12 | "dependencies": { 13 | "minecraft-scripting-types-shared": "^1.0.0" 14 | }, 15 | "devDependencies": { 16 | "typescript": "^3.1.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/server/tsconfig.json: -------------------------------------------------------------------------------- 1 | // This file keeps IDEs happy, it is not used for compilation 2 | { 3 | "compilerOptions": { 4 | "module": "ES6", 5 | "noImplicitAny": true, 6 | "rootDir": "./types", 7 | "target": "es5" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/server/types/server.d.ts: -------------------------------------------------------------------------------- 1 | declare const server: IServer; 2 | 3 | declare interface IServer { 4 | registerSystem = IVanillaServerSystem>(majorVersion: number, minorVersion: number): TSystem; 5 | log(message: string): void; 6 | } 7 | 8 | declare interface IExecuteCommandCallback { 9 | command: string; 10 | data: { 11 | message: string; 12 | statusCode: number; 13 | } 14 | } -------------------------------------------------------------------------------- /packages/server/types/server_component.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /** 7 | * This component represents the armor contents of an entity. The component contains an array of ItemStack JS API Objects representing each slot in the armor container. NOTE: Currently items and containers are read-only. Slots are ordered from head to feet. 8 | */ 9 | declare type IArmorContainerComponent = IItemStack[] 10 | 11 | /** 12 | * This component controls the Attack Damage attribute from the entity. It allows you to change the current minimum and maximum values. Once the changes are applied, the current attack of the entity will be reset to the minimum specified. With the minimum and maximum changed to the values specified. Any buffs or debuffs will be left intact. 13 | */ 14 | declare interface IAttackComponent { 15 | /** 16 | * Range of the random amount of damage the melee attack deals. A negative value can heal the entity instead of hurting it 17 | */ 18 | damage: { 19 | /** 20 | * The maximum amount of damage the entity will deal 21 | * @default 0.0 22 | */ 23 | range_max: number; 24 | /** 25 | * The minimum amount of damage the entity will deal 26 | * @default 0.0 27 | */ 28 | range_min: number; 29 | }; 30 | } 31 | 32 | /** 33 | * Controls the collision box of the entity. When changes to the component are applied the entity's collision box is immediately updated to reflect the new dimensions. WARNING: If the change of the collision box dimensions would cause the entity to be inside a block, the entity might become stuck there and start suffocating. 34 | */ 35 | declare interface ICollisionBoxComponent { 36 | /** 37 | * Height of the collision box in blocks. A negative value will be assumed to be 0 38 | * @default 1.0 39 | */ 40 | height: number; 41 | /** 42 | * Width and Depth of the collision box in blocks. A negative value will be assumed to be 0 43 | * @default 1.0 44 | */ 45 | width: number; 46 | } 47 | 48 | /** 49 | * Defines an array of damages and how the entity reacts to them - including whether the entity ignores that damage or not. Currently Minecraft triggers can't be properly serialized so any existing triggers will be completely replaced when applyComponentChanges(). 50 | */ 51 | declare interface IDamageSensorComponent { 52 | /** 53 | * Type of damage that triggers this set of events 54 | */ 55 | cause: string; 56 | /** 57 | * If true, the damage dealt to the entity will take away health from it, set to false to make the entity ignore that damage 58 | * @default true 59 | */ 60 | deals_damage: boolean; 61 | /** 62 | * List of triggers with the events to call when taking this specific kind of damage, allows specifying filters for entity definitions and events 63 | */ 64 | on_damage: MinecraftTrigger[]; 65 | } 66 | 67 | /** 68 | * Defines the loot table the entity uses to defines its equipment. Once the changes are applied, the equipment is re-rolled and a new set of equipment is chosen for the entity. 69 | */ 70 | declare interface IEquipmentComponent { 71 | /** 72 | * A list of slots with the chance to drop an equipped item from that slot 73 | */ 74 | slot_drop_chance: { 75 | /** 76 | * The chance that the item in this slot will be dropped 77 | */ 78 | drop_chance: number; 79 | /** 80 | * The slot number 81 | */ 82 | slot: number; 83 | }[]; 84 | /** 85 | * The file path to the equipment table, relative to the behavior pack's root 86 | */ 87 | table: string; 88 | } 89 | 90 | /** 91 | * Defines how many and what items the entity can be equipped with. 92 | */ 93 | declare interface IEquippableComponent { 94 | /** 95 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 96 | */ 97 | slots: { 98 | /** 99 | * The list of items that can go in this slot 100 | */ 101 | accepted_items: string[]; 102 | /** 103 | * Text to be displayed when the entity can be equipped with this item when playing with Touch-screen controls 104 | */ 105 | interact_text: string; 106 | /** 107 | * Event to trigger when this entity is equipped with this item 108 | */ 109 | on_equip: MinecraftTrigger | string; 110 | /** 111 | * Event to trigger when this item is removed from this entity 112 | */ 113 | on_unequip: MinecraftTrigger | string; 114 | /** 115 | * The slot number of this slot 116 | */ 117 | slot: number; 118 | }[]; 119 | } 120 | 121 | /** 122 | * Controls the entity's explosion, timer until the explosion, and whether the timer is counting down or not. 123 | */ 124 | declare interface IExplodeComponent { 125 | /** 126 | * If true, the explosion will destroy blocks in the explosion radius 127 | * @default true 128 | */ 129 | breaks_blocks: boolean; 130 | /** 131 | * If true, blocks in the explosion radius will be set on fire 132 | * @default false 133 | */ 134 | causesFire: boolean; 135 | /** 136 | * If true, whether the explosion breaks blocks is affected by the mob griefing game rule 137 | * @default false 138 | */ 139 | destroyAffectedByGriefing: boolean; 140 | /** 141 | * If true, whether the explosion causes fire is affected by the mob griefing game rule 142 | * @default false 143 | */ 144 | fireAffectedByGriefing: boolean; 145 | /** 146 | * The range for the random amount of time the fuse will be lit before exploding, a negative value means the explosion will be immediate 147 | * @default [0.0, 0.0] 148 | */ 149 | fuseLength: Range; 150 | /** 151 | * If true, the fuse is already lit when this component is added to the entity 152 | * @default false 153 | */ 154 | fuseLit: boolean; 155 | /** 156 | * A blocks explosion resistance will be capped at this value when an explosion occurs 157 | * @default Infinite 158 | */ 159 | maxResistance: number; 160 | /** 161 | * The radius of the explosion in blocks and the amount of damage the explosion deals 162 | * @default 3.0 163 | */ 164 | power: number; 165 | } 166 | 167 | /** 168 | * This component represents the contents of an entity's hands. The component contains an array of ItemStack JS API Objects representing each slot in the hand container. NOTE: Currently items and containers are read-only. Slot 0 is main-hand Slot 1 is off-hand. 169 | */ 170 | declare type IHandContainerComponent = IItemStack[] 171 | 172 | /** 173 | * Defines how the entity can be healed by the player. This doesn't control how much health the entity can have; you must use the Health component for that instead. 174 | */ 175 | declare interface IHealableComponent { 176 | /** 177 | * The filter group that defines the conditions for this trigger 178 | */ 179 | filters?: MinecraftFilter; 180 | /** 181 | * Determines if item can be used regardless of entity being at full health 182 | * @default false 183 | */ 184 | force_use: boolean; 185 | /** 186 | * The array of items that can be used to heal this entity 187 | */ 188 | items: { 189 | /** 190 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 191 | */ 192 | effects: { 193 | /** 194 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 195 | */ 196 | amplifier: number; 197 | /** 198 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 199 | */ 200 | chance: number; 201 | /** 202 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 203 | */ 204 | duration: number; 205 | /** 206 | * FIXME - UNDOCUMENTED - NO DESCRIPTION FROM MOJANG 207 | */ 208 | name: string; 209 | }[]; 210 | /** 211 | * The filter group that defines the conditions for using this item to heal the entity 212 | */ 213 | filters?: MinecraftFilter; 214 | /** 215 | * The amount of health this entity gains when fed this item 216 | * @default 1 217 | */ 218 | heal_amount: number; 219 | /** 220 | * Item identifier that can be used to heal this entity 221 | */ 222 | item: string; 223 | }[]; 224 | } 225 | 226 | /** 227 | * Defines the current and maximum possible health of the entity. Upon applying the component back to the entity the health will change. If it reaches 0 or below the entity will die. 228 | */ 229 | declare interface IHealthComponent { 230 | /** 231 | * The maximum health the entity can heal 232 | * @default 10 233 | */ 234 | max: number; 235 | /** 236 | * Current health of the entity 237 | * @default 1 238 | */ 239 | value: number; 240 | } 241 | 242 | /** 243 | * This component represents the hotbar contents of a player. The component contains an array of ItemStack JS API Objects representing each slot in the hotbar. NOTE: Currently items and containers are read-only. Slots are ordered left to right. 244 | */ 245 | declare type IHotbarContainerComponent = IItemStack[] 246 | 247 | /** 248 | * Defines the ways the player can interact with the entity to which this component is applied. 249 | */ 250 | declare interface IInteractComponent { 251 | /** 252 | * Loot table with items to add to the player's inventory upon successful interaction 253 | */ 254 | add_items: { 255 | /** 256 | * File path, relative to the behavior pack's path, to the loot table file 257 | */ 258 | table: string; 259 | }; 260 | /** 261 | * Time in seconds before this entity can be interacted with again 262 | * @default 0.0 263 | */ 264 | cooldown: number; 265 | /** 266 | * The amount of damage the item will take when used to interact with this entity. A value of 0 means the item won't lose durability 267 | * @default 0 268 | */ 269 | hurt_item: number; 270 | /** 271 | * Text to show when the player is able to interact in this way with this entity when playing with Touch-screen controls 272 | */ 273 | interact_text: string; 274 | /** 275 | * An event identifier to fire when the interaction occurs 276 | */ 277 | on_interact: MinecraftTrigger | string; 278 | /** 279 | * Particle effect that will be triggered at the start of the interaction 280 | */ 281 | particle_on_start: { 282 | /** 283 | * Whether or not the particle will appear closer to who performed the interaction 284 | * @default false 285 | */ 286 | particle_offset_towards_interactor: boolean; 287 | /** 288 | * The type of particle that will be spawned 289 | */ 290 | particle_type: string; 291 | /** 292 | * Will offset the particle this amount in the y direction 293 | * @default 0.0 294 | */ 295 | particle_y_offset: number; 296 | }; 297 | /** 298 | * An array of sound identifiers to play when the interaction occurs 299 | */ 300 | play_sounds: string[]; 301 | /** 302 | * An array of entity identifiers to spawn when the interaction occurs 303 | */ 304 | spawn_entities: string[]; 305 | /** 306 | * Loot table with items to drop on the ground upon successful interaction 307 | */ 308 | spawn_items: { 309 | /** 310 | * File path, relative to the behavior pack's path, to the loot table file 311 | */ 312 | table: string; 313 | }; 314 | /** 315 | * If true, the player will do the 'swing' animation when interacting with this entity 316 | * @default false 317 | */ 318 | swing: boolean; 319 | /** 320 | * The item used will transform to this item upon successful interaction. Format: itemName:auxValue 321 | */ 322 | transform_to_item?: string; 323 | /** 324 | * If true, the interaction will use an item 325 | * @default false 326 | */ 327 | use_item: boolean; 328 | } 329 | 330 | /** 331 | * Defines the entity's inventory (size, restrictions, etc.). Currently this does not allow changing the entity's inventory contents. 332 | */ 333 | declare interface IInventoryComponent { 334 | /** 335 | * Number of slots that this entity can gain per extra strength 336 | * @default 0 337 | */ 338 | additional_slots_per_strength: number; 339 | /** 340 | * If true, the contents of this inventory can be removed by a hopper 341 | * @default false 342 | */ 343 | can_be_siphoned_from: boolean; 344 | /** 345 | * Type of container this entity has. Can be horse, minecart_chest, minecart_hopper, inventory, container or hopper 346 | * @default none 347 | */ 348 | container_type: string; 349 | /** 350 | * Number of slots the container has 351 | * @default 5 352 | */ 353 | inventory_size: number; 354 | /** 355 | * If true, only the entity can access the inventory 356 | * @default false 357 | */ 358 | private: boolean; 359 | /** 360 | * If true, the entity's inventory can only be accessed by its owner or itself 361 | * @default false 362 | */ 363 | restrict_to_owner: boolean; 364 | } 365 | 366 | /** 367 | * This component represents the inventory contents of an entity. The component contains an array of ItemStack JS API Objects representing each slot in the inventory. NOTE: Currently items and containers are read-only.Slot 0-8 is the hotbar, 9-16 is the top row of the player's inventory, 17-24 is the middle row, 25-32 is the bottom row 368 | */ 369 | declare type IInventoryContainerComponent = IItemStack[] 370 | 371 | /** 372 | * Makes the entity look at another entity. Once applied, if an entity of the specified type is nearby and can be targeted the entity will turn towards it. 373 | */ 374 | declare interface ILookAtComponent { 375 | /** 376 | * Defines the entities that can trigger this component 377 | * @default player 378 | */ 379 | filters?: MinecraftFilter; 380 | /** 381 | * The range for the random amount of time during which the entity is 'cooling down' and won't get angered or look for a target 382 | * @default [0.0, 0.0] 383 | */ 384 | look_cooldown: Range; 385 | /** 386 | * The event identifier to run when the entities specified in filters look at this entity 387 | */ 388 | look_event: MinecraftTrigger | string; 389 | /** 390 | * If true, invulnerable entities (e.g. Players in creative mode) are considered valid targets 391 | * @default false 392 | */ 393 | mAllowInvulnerable: boolean; 394 | /** 395 | * Maximum distance this entity will look for another entity looking at it 396 | * @default 10.0 397 | */ 398 | searchRadius: number; 399 | /** 400 | * If true, this entity will set the attack target as the entity that looked at it 401 | * @default true 402 | */ 403 | setTarget: boolean; 404 | } 405 | 406 | /** 407 | * Nameable component describes an entity's ability to be named using a nametag and whether the name shows up or not once applied. Additionally, scripting allows setting the name of the entity directly with the property 'name'. 408 | */ 409 | declare interface INameableComponent { 410 | /** 411 | * If true, this entity can be renamed with name tags 412 | * @default true 413 | */ 414 | allowNameTagRenaming: boolean; 415 | /** 416 | * If true, the name will always be shown 417 | * @default false 418 | */ 419 | alwaysShow: boolean; 420 | /** 421 | * Trigger to run when the entity gets named 422 | */ 423 | default_trigger: MinecraftTrigger | string; 424 | /** 425 | * The current name of the entity, empty if the entity hasn't been named yet, making this non-empty will apply the name to the entity 426 | */ 427 | name: string; 428 | /** 429 | * Describes the special names for this entity and the events to call when the entity acquires those names 430 | */ 431 | name_actions: { 432 | /** 433 | * List of special names that will cause the events defined in 'on_named' to fire 434 | */ 435 | name_filter: string[]; 436 | /** 437 | * Event to be called when this entity acquires the name specified in 'name_filter' 438 | */ 439 | on_named: MinecraftTrigger | string; 440 | }[]; 441 | } 442 | 443 | /** 444 | * This component allows you to control an entity's current position in the world. Once applied the entity will be teleported to the new position specified. 445 | */ 446 | declare interface IPositionComponent { 447 | /** 448 | * Position along the X-Axis (east-west) of the entity 449 | * @default 0.0 450 | */ 451 | x: number; 452 | /** 453 | * Position along the Y-Axis (height) of the entity 454 | * @default 0.0 455 | */ 456 | y: number; 457 | /** 458 | * Position along the Z-Axis (north-south) of the entity 459 | * @default 0.0 460 | */ 461 | z: number; 462 | } 463 | 464 | /** 465 | * This component allows you to control an entity's current rotation in the world as well as the entity's head rotation. Once applied, the entity will be rotated as specified. 466 | */ 467 | declare interface IRotationComponent { 468 | /** 469 | * Controls the head rotation looking up and down 470 | * @default 0.0 471 | */ 472 | x: number; 473 | /** 474 | * Controls the body rotation parallel to the floor 475 | * @default 0.0 476 | */ 477 | y: number; 478 | } 479 | 480 | /** 481 | * Defines the entity's ranged attacks. This doesn't allow the entity to use a ranged attack: it only defines what kind of projectile it shoots. 482 | */ 483 | declare interface IShooterComponent { 484 | /** 485 | * ID of the Potion effect to be applied on hit 486 | * @default -1 487 | */ 488 | auxVal: number; 489 | /** 490 | * Entity identifier to use as projectile for the ranged attack. The entity must have the projectile component to be able to be shot as a projectile 491 | */ 492 | def: string; 493 | } 494 | 495 | /** 496 | * Controls the entity's ability to spawn an entity or an item. This is similar to the chicken's ability to lay eggs after a set amount of time. 497 | */ 498 | declare interface ISpawnEntityComponent { 499 | /** 500 | * If present, the specified entity will only spawn if the filter evaluates to true 501 | */ 502 | filters?: MinecraftFilter; 503 | /** 504 | * Maximum amount of time to randomly wait in seconds before another entity is spawned 505 | * @default 600 506 | */ 507 | max_wait_time: number; 508 | /** 509 | * Minimum amount of time to randomly wait in seconds before another entity is spawned 510 | * @default 300 511 | */ 512 | min_wait_time: number; 513 | /** 514 | * The number of entities of this type to spawn each time that this triggers 515 | * @default 1 516 | */ 517 | num_to_spawn: number; 518 | /** 519 | * If true, this the spawned entity will be leashed to the parent 520 | * @default false 521 | */ 522 | should_leash: boolean; 523 | /** 524 | * If true, this component will only ever spawn the specified entity once 525 | * @default false 526 | */ 527 | single_use: boolean; 528 | /** 529 | * Identifier of the entity to spawn, leave empty to spawn the item defined above instead 530 | */ 531 | spawn_entity: string; 532 | /** 533 | * Event to call when the entity is spawned 534 | * @default minecraft:entity_born 535 | */ 536 | spawn_event: string; 537 | /** 538 | * Item identifier of the item to spawn 539 | * @default egg 540 | */ 541 | spawn_item: string; 542 | /** 543 | * Method to use to spawn the entity 544 | * @default born 545 | */ 546 | spawn_method: string; 547 | /** 548 | * Identifier of the sound effect to play when the entity is spawned 549 | * @default plop 550 | */ 551 | spawn_sound: string; 552 | } 553 | 554 | /** 555 | * This controls the entity's ability to teleport itself (similar to the Enderman). If you wish to teleport the entity once use the Position component instead. 556 | */ 557 | declare interface ITeleportComponent { 558 | /** 559 | * Modifies the chance that the entity will teleport if the entity is in darkness 560 | * @default 0.01 561 | */ 562 | darkTeleportChance: number; 563 | /** 564 | * Modifies the chance that the entity will teleport if the entity is in daylight 565 | * @default 0.01 566 | */ 567 | lightTeleportChance: number; 568 | /** 569 | * Maximum amount of time in seconds between random teleports 570 | * @default 20.0 571 | */ 572 | maxRandomTeleportTime: number; 573 | /** 574 | * Minimum amount of time in seconds between random teleports 575 | * @default 0.0 576 | */ 577 | minRandomTeleportTime: number; 578 | /** 579 | * Entity will teleport to a random position within the area defined by this cube 580 | * @default [32.0, 16.0, 32.0] 581 | */ 582 | randomTeleportCube: VectorArray; 583 | /** 584 | * If true, the entity will teleport randomly 585 | * @default true 586 | */ 587 | randomTeleports: boolean; 588 | /** 589 | * The chance that the entity will teleport between 0.0 and 1.0. 1.0 means 100% 590 | * @default 1.0 591 | */ 592 | target_teleport_chance: number; 593 | /** 594 | * Maximum distance the entity will teleport when chasing a target 595 | * @default 16.0 596 | */ 597 | targetDistance: number; 598 | } 599 | 600 | /** 601 | * The tick world component is a read-only component that allows users to access the ticking areas on entities as well as the ticking area's data. 602 | */ 603 | declare interface ITickWorldComponent { 604 | /** 605 | * distance_to_players 606 | */ 607 | distance_to_players: number; 608 | /** 609 | * Whether or not this ticking area will despawn when a player is out of range 610 | */ 611 | never_despawn: boolean; 612 | /** 613 | * The radius in chunks of the ticking area 614 | */ 615 | radius: number; 616 | /** 617 | * The ticking area entity that is attached to this entity 618 | */ 619 | ticking_area: IEntityTickingArea; 620 | } 621 | -------------------------------------------------------------------------------- /packages/server/types/server_component_names.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | declare const enum MinecraftComponent { 7 | /** 8 | * This component represents the armor contents of an entity. The component contains an array of ItemStack JS API Objects representing each slot in the armor container. NOTE: Currently items and containers are read-only. Slots are ordered from head to feet. 9 | */ 10 | ArmorContainer = "minecraft:armor_container", 11 | /** 12 | * This component controls the Attack Damage attribute from the entity. It allows you to change the current minimum and maximum values. Once the changes are applied, the current attack of the entity will be reset to the minimum specified. With the minimum and maximum changed to the values specified. Any buffs or debuffs will be left intact. 13 | */ 14 | Attack = "minecraft:attack", 15 | /** 16 | * Controls the collision box of the entity. When changes to the component are applied the entity's collision box is immediately updated to reflect the new dimensions. WARNING: If the change of the collision box dimensions would cause the entity to be inside a block, the entity might become stuck there and start suffocating. 17 | */ 18 | CollisionBox = "minecraft:collision_box", 19 | /** 20 | * Defines an array of damages and how the entity reacts to them - including whether the entity ignores that damage or not. Currently Minecraft triggers can't be properly serialized so any existing triggers will be completely replaced when applyComponentChanges(). 21 | */ 22 | DamageSensor = "minecraft:damage_sensor", 23 | /** 24 | * Defines the loot table the entity uses to defines its equipment. Once the changes are applied, the equipment is re-rolled and a new set of equipment is chosen for the entity. 25 | */ 26 | Equipment = "minecraft:equipment", 27 | /** 28 | * Defines how many and what items the entity can be equipped with. 29 | */ 30 | Equippable = "minecraft:equippable", 31 | /** 32 | * Controls the entity's explosion, timer until the explosion, and whether the timer is counting down or not. 33 | */ 34 | Explode = "minecraft:explode", 35 | /** 36 | * This component represents the contents of an entity's hands. The component contains an array of ItemStack JS API Objects representing each slot in the hand container. NOTE: Currently items and containers are read-only. Slot 0 is main-hand Slot 1 is off-hand. 37 | */ 38 | HandContainer = "minecraft:hand_container", 39 | /** 40 | * Defines how the entity can be healed by the player. This doesn't control how much health the entity can have; you must use the Health component for that instead. 41 | */ 42 | Healable = "minecraft:healable", 43 | /** 44 | * Defines the current and maximum possible health of the entity. Upon applying the component back to the entity the health will change. If it reaches 0 or below the entity will die. 45 | */ 46 | Health = "minecraft:health", 47 | /** 48 | * This component represents the hotbar contents of a player. The component contains an array of ItemStack JS API Objects representing each slot in the hotbar. NOTE: Currently items and containers are read-only. Slots are ordered left to right. 49 | */ 50 | HotbarContainer = "minecraft:hotbar_container", 51 | /** 52 | * Defines the ways the player can interact with the entity to which this component is applied. 53 | */ 54 | Interact = "minecraft:interact", 55 | /** 56 | * Defines the entity's inventory (size, restrictions, etc.). Currently this does not allow changing the entity's inventory contents. 57 | */ 58 | Inventory = "minecraft:inventory", 59 | /** 60 | * This component represents the inventory contents of an entity. The component contains an array of ItemStack JS API Objects representing each slot in the inventory. NOTE: Currently items and containers are read-only.Slot 0-8 is the hotbar, 9-16 is the top row of the player's inventory, 17-24 is the middle row, 25-32 is the bottom row 61 | */ 62 | InventoryContainer = "minecraft:inventory_container", 63 | /** 64 | * Makes the entity look at another entity. Once applied, if an entity of the specified type is nearby and can be targeted the entity will turn towards it. 65 | */ 66 | LookAt = "minecraft:lookat", 67 | /** 68 | * Nameable component describes an entity's ability to be named using a nametag and whether the name shows up or not once applied. Additionally, scripting allows setting the name of the entity directly with the property 'name'. 69 | */ 70 | Nameable = "minecraft:nameable", 71 | /** 72 | * This component allows you to control an entity's current position in the world. Once applied the entity will be teleported to the new position specified. 73 | */ 74 | Position = "minecraft:position", 75 | /** 76 | * This component allows you to control an entity's current rotation in the world as well as the entity's head rotation. Once applied, the entity will be rotated as specified. 77 | */ 78 | Rotation = "minecraft:rotation", 79 | /** 80 | * Defines the entity's ranged attacks. This doesn't allow the entity to use a ranged attack: it only defines what kind of projectile it shoots. 81 | */ 82 | Shooter = "minecraft:shooter", 83 | /** 84 | * Controls the entity's ability to spawn an entity or an item. This is similar to the chicken's ability to lay eggs after a set amount of time. 85 | */ 86 | SpawnEntity = "minecraft:spawn_entity", 87 | /** 88 | * This controls the entity's ability to teleport itself (similar to the Enderman). If you wish to teleport the entity once use the Position component instead. 89 | */ 90 | Teleport = "minecraft:teleport", 91 | /** 92 | * The tick world component is a read-only component that allows users to access the ticking areas on entities as well as the ticking area's data. 93 | */ 94 | TickWorld = "minecraft:tick_world" 95 | } 96 | -------------------------------------------------------------------------------- /packages/server/types/server_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /** 7 | * (Server-side) Events that can be sent to Minecraft to achieve an effect. 8 | */ 9 | declare const enum SendToMinecraftServer { 10 | /** 11 | * This event is used to send a chat message from the server to the players. The event data is the message being sent as a string. Special formatting is supported the same way it would be if a player was sending the message. 12 | */ 13 | DisplayChat = "minecraft:display_chat_event", 14 | /** 15 | * This event is used to execute a slash command on the server with the World Owner permission level. The event data contains the slash command as a string. The slash command will be processed and will run after the event is sent. 16 | */ 17 | ExecuteCommand = "minecraft:execute_command", 18 | /** 19 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 20 | */ 21 | PlaySound = "minecraft:play_sound", 22 | /** 23 | * This event is used to turn various levels of logging on and off for server scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL server scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 24 | */ 25 | ScriptLoggerConfig = "minecraft:script_logger_config", 26 | /** 27 | * This event is used to create a particle effect that will follow an entity around. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 28 | */ 29 | SpawnParticleAttachedEntity = "minecraft:spawn_particle_attached_entity", 30 | /** 31 | * This event is used to create a static particle effect in the world. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. 32 | */ 33 | SpawnParticleInWorld = "minecraft:spawn_particle_in_world" 34 | } 35 | 36 | /** 37 | * (Server-side) Events that can be received from Minecraft 38 | */ 39 | declare const enum ReceiveFromMinecraftServer { 40 | /** 41 | * This event is triggered whenever a player starts to destroy a block. 42 | */ 43 | BlockDestructionStarted = "minecraft:block_destruction_started", 44 | /** 45 | * This event is triggered whenever a player stops destroying a block. 46 | */ 47 | BlockDestructionStopped = "minecraft:block_destruction_stopped", 48 | /** 49 | * This event is triggered whenever a player interacts with a block. 50 | */ 51 | BlockInteractedWith = "minecraft:block_interacted_with", 52 | /** 53 | * This event is triggered whenever an entity acquires an item. 54 | */ 55 | EntityAcquiredItem = "minecraft:entity_acquired_item", 56 | /** 57 | * This event is triggered whenever an entity changes the item carried in their hand. 58 | */ 59 | EntityCarriedItemChanged = "minecraft:entity_carried_item_changed", 60 | /** 61 | * This event is triggered whenever an entity is added to the world. 62 | */ 63 | EntityCreated = "minecraft:entity_created", 64 | /** 65 | * This event is triggered whenever an entity dies. This won't be triggered when an entity is removed (such as when using destroyEntity). 66 | */ 67 | EntityDeath = "minecraft:entity_death", 68 | /** 69 | * This event is triggered whenever an entity drops an item. 70 | */ 71 | EntityDroppedItem = "minecraft:entity_dropped_item", 72 | /** 73 | * This event is triggered whenever an entity equips an item in their armor slots. 74 | */ 75 | EntityEquippedArmor = "minecraft:entity_equipped_armor", 76 | /** 77 | * This event is triggered whenever an entity becomes a rider on another entity. 78 | */ 79 | EntityStartRiding = "minecraft:entity_start_riding", 80 | /** 81 | * This event is triggered whenever an entity stops riding another entity. 82 | */ 83 | EntityStopRiding = "minecraft:entity_stop_riding", 84 | /** 85 | * This event is triggered whenever an entity is ticked. This event will not fire when a player is ticked. 86 | */ 87 | EntityTick = "minecraft:entity_tick", 88 | /** 89 | * This event is triggered whenever an entity uses an item. 90 | */ 91 | EntityUseItem = "minecraft:entity_use_item", 92 | /** 93 | * This event is triggered whenever a piston moves a block. 94 | */ 95 | PistonMovedBlock = "minecraft:piston_moved_block", 96 | /** 97 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 98 | */ 99 | PlaySound = "minecraft:play_sound", 100 | /** 101 | * This event is triggered whenever a player attacks an entity. 102 | */ 103 | PlayerAttackedEntity = "minecraft:player_attacked_entity", 104 | /** 105 | * This event is triggered whenever a player destroys a block. 106 | */ 107 | PlayerDestroyedBlock = "minecraft:player_destroyed_block", 108 | /** 109 | * This event is triggered whenever a player places a block. 110 | */ 111 | PlayerPlacedBlock = "minecraft:player_placed_block", 112 | /** 113 | * This event is triggered whenever the weather changes. It contains information about the weather it is changing to. 114 | */ 115 | WeatherChanged = "minecraft:weather_changed" 116 | } 117 | 118 | /** 119 | * This event is triggered whenever a player starts to destroy a block. 120 | */ 121 | declare interface IBlockDestructionStartedEventData { 122 | /** 123 | * The position of the block that is being destroyed 124 | */ 125 | block_position: VectorXYZ; 126 | /** 127 | * The player that started destoying the block 128 | */ 129 | player: IEntity; 130 | } 131 | 132 | /** 133 | * This event is triggered whenever a player stops destroying a block. 134 | */ 135 | declare interface IBlockDestructionStoppedEventData { 136 | /** 137 | * The position of the block that was being destroyed 138 | */ 139 | block_position: VectorXYZ; 140 | /** 141 | * How far along the destruction was before it was stopped (0 - 1 range) 142 | */ 143 | destruction_progress: number; 144 | /** 145 | * The player that stopped destoying the block 146 | */ 147 | player: IEntity; 148 | } 149 | 150 | /** 151 | * This event is triggered whenever a player interacts with a block. 152 | */ 153 | declare interface IBlockInteractedWithEventData { 154 | /** 155 | * The position of the block that is being interacted with 156 | */ 157 | block_position: VectorXYZ; 158 | /** 159 | * The player that interacted with the block 160 | */ 161 | player: IEntity; 162 | } 163 | 164 | /** 165 | * This event is triggered whenever an entity acquires an item. 166 | */ 167 | declare interface IEntityAcquiredItemEventData { 168 | /** 169 | * The total number of items acquired by the entity during this event 170 | */ 171 | acquired_amount: number; 172 | /** 173 | * The way the entity acquired the item 174 | */ 175 | acquisition_method: string; 176 | /** 177 | * The entity who acquired the item 178 | */ 179 | entity: IEntity; 180 | /** 181 | * The item that was acquired 182 | */ 183 | item_stack: IItemStack; 184 | /** 185 | * If it exists, the entity that affected the item before it was acquired. Example: A player completes a trade with a villager. The `entity` property would be the player and the `secondary_entity` would be the villager 186 | */ 187 | secondary_entity: IEntity; 188 | } 189 | 190 | /** 191 | * This event is triggered whenever an entity changes the item carried in their hand. 192 | */ 193 | declare interface IEntityCarriedItemChangedEventData { 194 | /** 195 | * The item that is now in the entities hands 196 | */ 197 | carried_item: IItemStack; 198 | /** 199 | * The entity that changed what they were carrying 200 | */ 201 | entity: IEntity; 202 | /** 203 | * The item that was previously in the entities hands 204 | */ 205 | previous_carried_item: IItemStack; 206 | } 207 | 208 | /** 209 | * This event is triggered whenever an entity is added to the world. 210 | */ 211 | declare interface IEntityCreatedEventData { 212 | /** 213 | * The entity that was just created 214 | */ 215 | entity: IEntity; 216 | } 217 | 218 | /** 219 | * This event is triggered whenever an entity dies. This won't be triggered when an entity is removed (such as when using destroyEntity). 220 | */ 221 | declare interface IEntityDeathEventData { 222 | /** 223 | * The entity that died 224 | */ 225 | entity: IEntity; 226 | } 227 | 228 | /** 229 | * This event is triggered whenever an entity drops an item. 230 | */ 231 | declare interface IEntityDroppedItemEventData { 232 | /** 233 | * The entity who dropped the item 234 | */ 235 | entity: IEntity; 236 | /** 237 | * The item that was dropped 238 | */ 239 | item_stack: IItemStack; 240 | } 241 | 242 | /** 243 | * This event is triggered whenever an entity equips an item in their armor slots. 244 | */ 245 | declare interface IEntityEquippedArmorEventData { 246 | /** 247 | * The entity who is equipping the armor 248 | */ 249 | entity: IEntity; 250 | /** 251 | * The armor that is being equipped 252 | */ 253 | item_stack: IItemStack; 254 | } 255 | 256 | /** 257 | * This event is triggered whenever an entity becomes a rider on another entity. 258 | */ 259 | declare interface IEntityStartRidingEventData { 260 | /** 261 | * The rider 262 | */ 263 | entity: IEntity; 264 | /** 265 | * The entity being ridden 266 | */ 267 | ride: IEntity; 268 | } 269 | 270 | /** 271 | * This event is triggered whenever an entity stops riding another entity. 272 | */ 273 | declare interface IEntityStopRidingEventData { 274 | /** 275 | * The entity that was riding another entity 276 | */ 277 | entity: IEntity; 278 | /** 279 | * If true, the rider stopped riding because they are now dead 280 | */ 281 | entity_is_being_destroyed: boolean; 282 | /** 283 | * If true, the rider stopped riding by their own decision 284 | */ 285 | exit_from_rider: boolean; 286 | /** 287 | * If true, the rider stopped riding because they are now riding a different entity 288 | */ 289 | switching_rides: boolean; 290 | } 291 | 292 | /** 293 | * This event is triggered whenever an entity is ticked. This event will not fire when a player is ticked. 294 | */ 295 | declare interface IEntityTickEventData { 296 | /** 297 | * The entity that was ticked 298 | */ 299 | entity: IEntity; 300 | } 301 | 302 | /** 303 | * This event is triggered whenever an entity uses an item. 304 | */ 305 | declare interface IEntityUseItemEventData { 306 | /** 307 | * The entity who is using the item 308 | */ 309 | entity: IEntity; 310 | /** 311 | * The item that is being used 312 | */ 313 | item_stack: IItemStack; 314 | /** 315 | * The way the entity used the item 316 | */ 317 | use_method: string; 318 | } 319 | 320 | /** 321 | * This event is triggered whenever a piston moves a block. 322 | */ 323 | declare interface IPistonMovedBlockEventData { 324 | /** 325 | * The position of the block that was moved 326 | */ 327 | block_position: VectorXYZ; 328 | /** 329 | * The action the piston took, "extended" or "retracted" 330 | */ 331 | piston_action: string; 332 | /** 333 | * The position of the piston that moved the block 334 | */ 335 | piston_position: VectorXYZ; 336 | } 337 | 338 | /** 339 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 340 | */ 341 | declare interface IPlaySoundEventData { 342 | /** 343 | * The pitch of the sound effect. A value of 1.0 will play the sound effect with regular pitch 344 | * @default 1.0 345 | */ 346 | pitch: number; 347 | /** 348 | * The position in the world we want to play the sound at 349 | * @default [0, 0, 0] 350 | */ 351 | position: VectorArray; 352 | /** 353 | * The identifier of the sound you want to play. Only sounds defined in the applied resource packs can be played 354 | */ 355 | sound: string; 356 | /** 357 | * The volume of the sound effect. A value of 1.0 will play the sound effect at the volume it was recorded at 358 | * @default 1.0 359 | */ 360 | volume: number; 361 | } 362 | 363 | /** 364 | * This event is triggered whenever a player attacks an entity. 365 | */ 366 | declare interface IPlayerAttackedEntityEventData { 367 | /** 368 | * The entity that was attacked by the player 369 | */ 370 | attacked_entity: IEntity; 371 | /** 372 | * The player that attacked an entity 373 | */ 374 | player: IEntity; 375 | } 376 | 377 | /** 378 | * This event is triggered whenever a player destroys a block. 379 | */ 380 | declare interface IPlayerDestroyedBlockEventData { 381 | /** 382 | * The identifier of the block that was destroyed 383 | */ 384 | block_identifier: string; 385 | /** 386 | * The position of the block that was destroyed 387 | */ 388 | block_position: VectorXYZ; 389 | /** 390 | * The player that destroyed the block 391 | */ 392 | player: IEntity; 393 | } 394 | 395 | /** 396 | * This event is triggered whenever a player places a block. 397 | */ 398 | declare interface IPlayerPlacedBlockEventData { 399 | /** 400 | * The position of the block that was placed 401 | */ 402 | block_position: VectorXYZ; 403 | /** 404 | * The player that placed the block 405 | */ 406 | player: IEntity; 407 | } 408 | 409 | /** 410 | * This event is triggered whenever the weather changes. It contains information about the weather it is changing to. 411 | */ 412 | declare interface IWeatherChangedEventData { 413 | /** 414 | * The name of the dimension where the weather change happened 415 | */ 416 | dimension: Dimension; 417 | /** 418 | * Tells if the new weather has lightning 419 | */ 420 | lightning: boolean; 421 | /** 422 | * Tells if the new weather has rain 423 | */ 424 | raining: boolean; 425 | } 426 | 427 | /** 428 | * This event is used to send a chat message from the server to the players. The event data is the message being sent as a string. Special formatting is supported the same way it would be if a player was sending the message. 429 | */ 430 | declare interface IDisplayChatParameters { 431 | /** 432 | * The chat message that will be displayed 433 | */ 434 | message: string; 435 | } 436 | 437 | /** 438 | * This event is used to execute a slash command on the server with the World Owner permission level. The event data contains the slash command as a string. The slash command will be processed and will run after the event is sent. 439 | */ 440 | declare interface IExecuteCommandParameters { 441 | /** 442 | * The command that will be run 443 | */ 444 | command: string; 445 | } 446 | 447 | /** 448 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 449 | */ 450 | declare interface IPlaySoundParameters { 451 | /** 452 | * The pitch of the sound effect. A value of 1.0 will play the sound effect with regular pitch 453 | * @default 1.0 454 | */ 455 | pitch: number; 456 | /** 457 | * The position in the world we want to play the sound at 458 | * @default [0, 0, 0] 459 | */ 460 | position: VectorArray; 461 | /** 462 | * The identifier of the sound you want to play. Only sounds defined in the applied resource packs can be played 463 | */ 464 | sound: string; 465 | /** 466 | * The volume of the sound effect. A value of 1.0 will play the sound effect at the volume it was recorded at 467 | * @default 1.0 468 | */ 469 | volume: number; 470 | } 471 | 472 | /** 473 | * This event is used to turn various levels of logging on and off for server scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL server scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 474 | */ 475 | declare interface IScriptLoggerConfigParameters { 476 | /** 477 | * Set to true to log any scripting errors that occur on the server 478 | * @default false 479 | */ 480 | log_errors: boolean; 481 | /** 482 | * Set to true to log any general scripting information that occurs on the server. This includes any logging done with server.log() 483 | * @default false 484 | */ 485 | log_information: boolean; 486 | /** 487 | * Set to true to log any scripting warnings that occur on the server 488 | * @default false 489 | */ 490 | log_warnings: boolean; 491 | } 492 | 493 | /** 494 | * This event is used to create a particle effect that will follow an entity around. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 495 | */ 496 | declare interface ISpawnParticleAttachedEntityParameters { 497 | /** 498 | * The identifier of the particle effect you want to attach to the entity. This is the same identifier you gave the effect in its JSON file 499 | */ 500 | effect: ParticleEffect; 501 | /** 502 | * The entity object you want to attach the effect to 503 | */ 504 | entity: IEntity; 505 | /** 506 | * The offset from the entity's "center" where you want to spawn the effect 507 | * @default [0, 0, 0] 508 | */ 509 | offset: VectorArray; 510 | } 511 | 512 | /** 513 | * This event is used to create a static particle effect in the world. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. 514 | */ 515 | declare interface ISpawnParticleInWorldParameters { 516 | /** 517 | * The dimension in which you want to spawn the effect. Can be "overworld", "nether", or "the end" 518 | * @default overworld 519 | */ 520 | dimension: string; 521 | /** 522 | * The identifier of the particle effect you want to attach to spawn. This is the same name you gave the effect in its JSON file 523 | */ 524 | effect: ParticleEffect; 525 | /** 526 | * The position in the world where you want to spawn the effect 527 | * @default [0, 0, 0] 528 | */ 529 | position: VectorArray; 530 | } 531 | -------------------------------------------------------------------------------- /packages/server/types/server_system.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This interface is used to include the generated methods on the IServerSystem in a way that the generic variants do not 3 | * take precedence over the specific, generated versions. 4 | */ 5 | declare interface IVanillaServerSystemBase { 6 | 7 | } 8 | 9 | declare interface IServerSystem extends ISystem, IVanillaServerSystemBase { 10 | /** 11 | * Looks for the specified component in the entity. If it exists, retrieves the data from the component and returns it. 12 | * @param entity The `IEntityObject` that was retrieved from a call to `createEntity()` or retrieved from an event 13 | * @param componentIdentifier The identifier of the component to check on the entity. This is either the identifier of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 14 | * @returns true if the component is present, false if it is not, or null if an unknown component was passed in or something else went wrong when checking if the EntityObject had the component 15 | */ 16 | hasComponent(entity: IEntity, componentIdentifier: MinecraftComponent | string): boolean | null; 17 | 18 | /** 19 | * Allows you to register a query that will only show entities that have the given component and define which fields of that component will be used as a filter when getting the entities from the query. 20 | * 21 | * This is the identifier of the component that will be used to filter entities when 22 | * @param componentField1 This is the name of the first field of the component that we want to filter entities by. By default this is set to x. If the component you used doesn't have the field you defined here, the field will be ignored 23 | * @param componentField2 This is the name of the second field of the component that we want to filter entities by. By default this is set to y. If the component you used doesn't have the field you defined here, the field will be ignored 24 | * @param componentField3 This is the name of the third field of the component that we want to filter entities by. By default this is set to z. If the component you used doesn't have the field you defined here, the field will be ignored 25 | */ 26 | registerQuery(component: MinecraftComponent | string, componentField1?: string, componentField2?: string, componentField3?: string): IQuery | null; 27 | 28 | /** 29 | * Allows you to register a query. A query will contain all entities that meet the filter requirement. 30 | * No filters are added by default when you register a query so it will capture all entities. 31 | */ 32 | //Ideally this would be in system.d.ts, but it seems to conflict with the parameterized version 33 | registerQuery(): IQuery | null; 34 | } 35 | 36 | /** 37 | * a utility interface that defines a system that is not being actively extended 38 | */ 39 | declare interface IVanillaServerSystem extends IServerSystem { 40 | 41 | } -------------------------------------------------------------------------------- /packages/server/types/server_system.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /// 7 | /// 8 | 9 | declare interface IServerSystem { 10 | 11 | //////////////////////////////////////////////// 12 | // Blocks 13 | //////////////////////////////////////////////// 14 | /** 15 | * Allows you to get a block from the world when provided an x, y, and z position. The block must be within a ticking area. 16 | * @param tickingArea The ticking area the block is in 17 | * @param x The x position of the block you want 18 | * @param y The y position of the block you want 19 | * @param z The z position of the block you want 20 | * @return object An object containing the block 21 | * @return null Something went wrong when retrieving the block 22 | */ 23 | getBlock(tickingArea: ITickingArea, x: number, y: number, z: number): IBlock | null; 24 | /** 25 | * Allows you to get a block from the world when provided a JavaScript object containing a position. The block must be within a ticking area. 26 | * @param tickingArea The ticking area the block is in 27 | * @param positionObject A JavaScript object with the x, y, and z position of the block you want 28 | * @return object An object containing the block 29 | * @return null Something went wrong when retrieving the block 30 | */ 31 | getBlock(tickingArea: ITickingArea, positionObject: VectorXYZ): IBlock | null; 32 | /** 33 | * Allows you to get an array of blocks from the world when provided a minimum and maximum x, y, and z position. The blocks must be within a ticking area. 34 | * @param tickingArea The ticking area the blocks are in 35 | * @param xMin The minimum x position of the blocks you want 36 | * @param yMin The minimum y position of the blocks you want 37 | * @param zMin The minimum z position of the blocks you want 38 | * @param xMax The maximum x position of the blocks you want 39 | * @param yMax The maximum y position of the blocks you want 40 | * @param zMax The maximum z position of the blocks you want 41 | * @return undefined A 3D array of block objects. Indexs are the blocks positions relative to the min position given 42 | * @return null Something went wrong when retrieving the blocks 43 | */ 44 | getBlocks(tickingArea: ITickingArea, xMin: number, yMin: number, zMin: number, xMax: number, yMax: number, zMax: number): IBlock[][] | null; 45 | /** 46 | * Allows you to get an array of blocks from the world when provided a minimum and maximum position. The blocks must be within a ticking area. 47 | * @param tickingArea The ticking area the blocks are in 48 | * @param minimumPositionObject A JavaScript object with the minimum x, y, and z position of the blocks you want 49 | * @param maximumPositionObject A JavaScript object with the maximum x, y, and z position of the blocks you want 50 | * @return undefined A 3D array of block objects. Indexs are the blocks positions relative to the min position given 51 | * @return null Something went wrong when retrieving the blocks 52 | */ 53 | getBlocks(tickingArea: ITickingArea, minimumPositionObject: VectorXYZ, maximumPositionObject: VectorXYZ): IBlock[][] | null; 54 | 55 | //////////////////////////////////////////////// 56 | // Commands 57 | //////////////////////////////////////////////// 58 | /** 59 | * Allows you to execute a Slash Command on the server. The command will be queried and executed at the end of the current frame. All data output from the command will be compiled on a JavaScript Object and sent to the Callback object specified in the second parameter. 60 | * @param command The slash command to run 61 | * @param callback The JavaScript object that will be called after the command executes 62 | * 63 | */ 64 | executeCommand(command: string, callback: (callback: IExecuteCommandCallback) => void): void; 65 | 66 | //////////////////////////////////////////////// 67 | // Components 68 | //////////////////////////////////////////////// 69 | /** 70 | * Removes the specified component from the given entity. If the entity has the component, it will be removed. Currently this only works with custom components and can't be used to remove components defined for an entity in JSON. 71 | * @param entityObject The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 72 | * @param componentIdentifier The identifier of the component to remove from the entity. This is either the identifier of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 73 | * @return true The component was successfully removed from the entity 74 | * @return null The entity did not have the component or something went wrong when removing the component 75 | */ 76 | destroyComponent(entityObject: IEntity, componentIdentifier: string): true | null; 77 | /** 78 | * Checks if the given entity has the specified component. 79 | * @param entityObject The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 80 | * @param componentIdentifier The identifier of the component to check on the entity. This is either the identifier of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 81 | * @return true The EntityObject has the component 82 | * @return false The EntityObject doesn't have the component 83 | * @return null An unknown component was passed in or something else went wrong when checking if the EntityObject had the component 84 | */ 85 | hasComponent(entityObject: IEntity, componentIdentifier: string): true | false | null; 86 | 87 | //////////////////////////////////////////////// 88 | // Entities 89 | //////////////////////////////////////////////// 90 | /** 91 | * Creates an empty entity with no components and does not place it in the world. The empty entity will be of type custom and have a blank identifier. This is NOT a valid entity that exists in the world, just an empty one that only scripts know about. 92 | * 93 | NOTE: Entities are created first on the server, with the client notified of new entities afterwards. Be aware that if you send the result object to the client right away, the created entity might not exist on the client yet. 94 | * 95 | * @return object An object representing the newly created entity 96 | * @return null Something went wrong when creating the entity 97 | */ 98 | createEntity(): IEntity | null; 99 | /** 100 | * Creates an entity and applies the specified template as defined in JSON. This allows you to quickly create an entity from the applied Behavior Packs as the base for an entity created in scripting. The entity will be spawned into the world with all the components, component groups, and event triggers that are defined in the JSON file of the identifier specified. Only works on scripts registered on the server.NOTE: Entities are created first on the server, with the client notified of new entities afterwards. Be aware that if you send the result object to the client right away, the created entity might not exist on the client yet. 101 | * @param type Specifies the type of the entity that is being created by the template. Valid inputs are `entity` and `item_entity` 102 | * @param templateIdentifier This can be any of the entity identifiers from the applied Behavior Packs. For example specifying minecraft:cow here will make the provided entity a cow as defined in JSON 103 | * @return object An object representing the newly created entity 104 | * @return null Something went wrong when creating the entity 105 | */ 106 | createEntity(type: string, templateIdentifier: string): IEntity | null; 107 | /** 108 | * Destroys an entity identified by the EntityObject. If the entity exists in the world this will remove it from the world and destroy it. This also makes the EntityObject no longer valid - you should only destroy an entity after you are done with it and no longer need to reference it again. This does NOT kill the entity. There won't be an event for its death: it will be removed. 109 | * @param entityObject The object that was retrieved from a call to createEntity() or retrieved from an entity event 110 | * @return true The entity was successfully destroyed 111 | * @return null Something went wrong when destroying the entity 112 | */ 113 | destroyEntity(entityObject: IEntity): true | null; 114 | /** 115 | * Checks if the given EntityObject corresponds to a valid entity. 116 | * @param entityObject The object that was retrieved from a call to createEntity() or retrieved from an entity event 117 | * @return true The entity is in the Script Engine's database of entities 118 | * @return false The entity is not in the Script Engine's database of entities 119 | * @return null Something went wrong when validating the entity 120 | */ 121 | isValidEntity(entityObject: IEntity): true | false | null; 122 | } 123 | -------------------------------------------------------------------------------- /packages/server/types/server_system_components.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /// 7 | /// 8 | 9 | declare interface IVanillaServerSystemBase { 10 | createComponent(entity: IEntity, componentName: MinecraftComponent.ArmorContainer): IComponent | null; 11 | createComponent(entity: IEntity, componentName: MinecraftComponent.Attack): IComponent | null; 12 | createComponent(entity: IEntity, componentName: MinecraftComponent.CollisionBox): IComponent | null; 13 | createComponent(entity: IEntity, componentName: MinecraftComponent.DamageSensor): IComponent | null; 14 | createComponent(entity: IEntity, componentName: MinecraftComponent.Equipment): IComponent | null; 15 | createComponent(entity: IEntity, componentName: MinecraftComponent.Equippable): IComponent | null; 16 | createComponent(entity: IEntity, componentName: MinecraftComponent.Explode): IComponent | null; 17 | createComponent(entity: IEntity, componentName: MinecraftComponent.HandContainer): IComponent | null; 18 | createComponent(entity: IEntity, componentName: MinecraftComponent.Healable): IComponent | null; 19 | createComponent(entity: IEntity, componentName: MinecraftComponent.Health): IComponent | null; 20 | createComponent(entity: IEntity, componentName: MinecraftComponent.HotbarContainer): IComponent | null; 21 | createComponent(entity: IEntity, componentName: MinecraftComponent.Interact): IComponent | null; 22 | createComponent(entity: IEntity, componentName: MinecraftComponent.Inventory): IComponent | null; 23 | createComponent(entity: IEntity, componentName: MinecraftComponent.InventoryContainer): IComponent | null; 24 | createComponent(entity: IEntity, componentName: MinecraftComponent.LookAt): IComponent | null; 25 | createComponent(entity: IEntity, componentName: MinecraftComponent.Nameable): IComponent | null; 26 | createComponent(entity: IEntity, componentName: MinecraftComponent.Position): IComponent | null; 27 | createComponent(entity: IEntity, componentName: MinecraftComponent.Rotation): IComponent | null; 28 | createComponent(entity: IEntity, componentName: MinecraftComponent.Shooter): IComponent | null; 29 | createComponent(entity: IEntity, componentName: MinecraftComponent.SpawnEntity): IComponent | null; 30 | createComponent(entity: IEntity, componentName: MinecraftComponent.Teleport): IComponent | null; 31 | createComponent(entity: IEntity, componentName: MinecraftComponent.TickWorld): IComponent | null; 32 | 33 | getComponent(entity: IEntity, componentName: MinecraftComponent.ArmorContainer): IComponent | null; 34 | getComponent(entity: IEntity, componentName: MinecraftComponent.Attack): IComponent | null; 35 | getComponent(entity: IEntity, componentName: MinecraftComponent.CollisionBox): IComponent | null; 36 | getComponent(entity: IEntity, componentName: MinecraftComponent.DamageSensor): IComponent | null; 37 | getComponent(entity: IEntity, componentName: MinecraftComponent.Equipment): IComponent | null; 38 | getComponent(entity: IEntity, componentName: MinecraftComponent.Equippable): IComponent | null; 39 | getComponent(entity: IEntity, componentName: MinecraftComponent.Explode): IComponent | null; 40 | getComponent(entity: IEntity, componentName: MinecraftComponent.HandContainer): IComponent | null; 41 | getComponent(entity: IEntity, componentName: MinecraftComponent.Healable): IComponent | null; 42 | getComponent(entity: IEntity, componentName: MinecraftComponent.Health): IComponent | null; 43 | getComponent(entity: IEntity, componentName: MinecraftComponent.HotbarContainer): IComponent | null; 44 | getComponent(entity: IEntity, componentName: MinecraftComponent.Interact): IComponent | null; 45 | getComponent(entity: IEntity, componentName: MinecraftComponent.Inventory): IComponent | null; 46 | getComponent(entity: IEntity, componentName: MinecraftComponent.InventoryContainer): IComponent | null; 47 | getComponent(entity: IEntity, componentName: MinecraftComponent.LookAt): IComponent | null; 48 | getComponent(entity: IEntity, componentName: MinecraftComponent.Nameable): IComponent | null; 49 | getComponent(entity: IEntity, componentName: MinecraftComponent.Position): IComponent | null; 50 | getComponent(entity: IEntity, componentName: MinecraftComponent.Rotation): IComponent | null; 51 | getComponent(entity: IEntity, componentName: MinecraftComponent.Shooter): IComponent | null; 52 | getComponent(entity: IEntity, componentName: MinecraftComponent.SpawnEntity): IComponent | null; 53 | getComponent(entity: IEntity, componentName: MinecraftComponent.Teleport): IComponent | null; 54 | getComponent(entity: IEntity, componentName: MinecraftComponent.TickWorld): IComponent | null; 55 | 56 | /** 57 | * Creates a component of the specified name and adds it to the entity. This should only be used with custom components which need 58 | * to be registered first. If the entity already has the component, this will retrieve the component already there instead. 59 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 60 | * @param componentName The name of the component to add to the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 61 | * @returns An object with all the fields as defined in the component, or null if something went wrong when creating the component 62 | */ 63 | createComponent(entity: IEntity, componentName: string): IComponent | null; 64 | 65 | /** 66 | * Looks for the specified component in the entity. If it exists, retrieves the data from the component and returns it. 67 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 68 | * @param componentIdentifier The name of the component to retrieve from the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 69 | * @returns An object containing the data of the component as described in the component itself, or null if the entity did not have the component or something went wrong when getting the component 70 | */ 71 | getComponent(entity: IEntity, componentIdentifier: MinecraftComponent | string): IComponent | null; 72 | } 73 | -------------------------------------------------------------------------------- /packages/server/types/server_system_events.generated.d.ts: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////// 2 | // This file is generated from the Minecraft documentation. // 3 | // DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! // 4 | ////////////////////////////////////////////////////////////// 5 | 6 | /// 7 | 8 | declare interface IVanillaServerSystemBase { 9 | /////////////////////////// 10 | // createEventData overloads 11 | 12 | /** 13 | * This event is used to send a chat message from the server to the players. The event data is the message being sent as a string. Special formatting is supported the same way it would be if a player was sending the message. 14 | */ 15 | createEventData(eventIdentifier: SendToMinecraftServer.DisplayChat): IEventData | null; 16 | /** 17 | * This event is used to execute a slash command on the server with the World Owner permission level. The event data contains the slash command as a string. The slash command will be processed and will run after the event is sent. 18 | */ 19 | createEventData(eventIdentifier: SendToMinecraftServer.ExecuteCommand): IEventData | null; 20 | /** 21 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 22 | */ 23 | createEventData(eventIdentifier: SendToMinecraftServer.PlaySound): IEventData | null; 24 | /** 25 | * This event is used to turn various levels of logging on and off for server scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL server scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 26 | */ 27 | createEventData(eventIdentifier: SendToMinecraftServer.ScriptLoggerConfig): IEventData | null; 28 | /** 29 | * This event is used to create a particle effect that will follow an entity around. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 30 | */ 31 | createEventData(eventIdentifier: SendToMinecraftServer.SpawnParticleAttachedEntity): IEventData | null; 32 | /** 33 | * This event is used to create a static particle effect in the world. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. 34 | */ 35 | createEventData(eventIdentifier: SendToMinecraftServer.SpawnParticleInWorld): IEventData | null; 36 | 37 | /////////////////////////// 38 | // broadcastEvent overloads 39 | 40 | /** 41 | * This event is used to send a chat message from the server to the players. The event data is the message being sent as a string. Special formatting is supported the same way it would be if a player was sending the message. 42 | */ 43 | broadcastEvent(eventIdentifier: SendToMinecraftServer.DisplayChat, eventData: IEventData): boolean | null; 44 | /** 45 | * This event is used to execute a slash command on the server with the World Owner permission level. The event data contains the slash command as a string. The slash command will be processed and will run after the event is sent. 46 | */ 47 | broadcastEvent(eventIdentifier: SendToMinecraftServer.ExecuteCommand, eventData: IEventData): boolean | null; 48 | /** 49 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 50 | */ 51 | broadcastEvent(eventIdentifier: SendToMinecraftServer.PlaySound, eventData: IEventData): boolean | null; 52 | /** 53 | * This event is used to turn various levels of logging on and off for server scripts. Note that turning logging on/off is not limited to the script that broadcasted the event. It will affect ALL server scripts including those in other Behavior Packs that are applied to the world. See the Debugging section for more information on logging. 54 | */ 55 | broadcastEvent(eventIdentifier: SendToMinecraftServer.ScriptLoggerConfig, eventData: IEventData): boolean | null; 56 | /** 57 | * This event is used to create a particle effect that will follow an entity around. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. MoLang variables defined in the JSON of the effect can then be used to control that effect by changing them in the entity to which it is attached. 58 | */ 59 | broadcastEvent(eventIdentifier: SendToMinecraftServer.SpawnParticleAttachedEntity, eventData: IEventData): boolean | null; 60 | /** 61 | * This event is used to create a static particle effect in the world. This particle effect is visible to all players. Any effect defined in a JSON file (both in your resource pack and in Minecraft) can be used here. Once the effect is spawned you won't be able to control it further. 62 | */ 63 | broadcastEvent(eventIdentifier: SendToMinecraftServer.SpawnParticleInWorld, eventData: IEventData): boolean | null; 64 | 65 | /////////////////////////// 66 | // listenForEvent overloads 67 | 68 | /** 69 | * This event is triggered whenever a player starts to destroy a block. 70 | */ 71 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.BlockDestructionStarted, callback: (eventData: IEventData) => void): boolean | null; 72 | /** 73 | * This event is triggered whenever a player stops destroying a block. 74 | */ 75 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.BlockDestructionStopped, callback: (eventData: IEventData) => void): boolean | null; 76 | /** 77 | * This event is triggered whenever a player interacts with a block. 78 | */ 79 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.BlockInteractedWith, callback: (eventData: IEventData) => void): boolean | null; 80 | /** 81 | * This event is triggered whenever an entity acquires an item. 82 | */ 83 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityAcquiredItem, callback: (eventData: IEventData) => void): boolean | null; 84 | /** 85 | * This event is triggered whenever an entity changes the item carried in their hand. 86 | */ 87 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityCarriedItemChanged, callback: (eventData: IEventData) => void): boolean | null; 88 | /** 89 | * This event is triggered whenever an entity is added to the world. 90 | */ 91 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityCreated, callback: (eventData: IEventData) => void): boolean | null; 92 | /** 93 | * This event is triggered whenever an entity dies. This won't be triggered when an entity is removed (such as when using destroyEntity). 94 | */ 95 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityDeath, callback: (eventData: IEventData) => void): boolean | null; 96 | /** 97 | * This event is triggered whenever an entity drops an item. 98 | */ 99 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityDroppedItem, callback: (eventData: IEventData) => void): boolean | null; 100 | /** 101 | * This event is triggered whenever an entity equips an item in their armor slots. 102 | */ 103 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityEquippedArmor, callback: (eventData: IEventData) => void): boolean | null; 104 | /** 105 | * This event is triggered whenever an entity becomes a rider on another entity. 106 | */ 107 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityStartRiding, callback: (eventData: IEventData) => void): boolean | null; 108 | /** 109 | * This event is triggered whenever an entity stops riding another entity. 110 | */ 111 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityStopRiding, callback: (eventData: IEventData) => void): boolean | null; 112 | /** 113 | * This event is triggered whenever an entity is ticked. This event will not fire when a player is ticked. 114 | */ 115 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityTick, callback: (eventData: IEventData) => void): boolean | null; 116 | /** 117 | * This event is triggered whenever an entity uses an item. 118 | */ 119 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.EntityUseItem, callback: (eventData: IEventData) => void): boolean | null; 120 | /** 121 | * This event is triggered whenever a piston moves a block. 122 | */ 123 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.PistonMovedBlock, callback: (eventData: IEventData) => void): boolean | null; 124 | /** 125 | * This event is used to play a sound effect. Currently, sounds can only be played at a fixed position in the world. Global sounds and sounds played by an entity will be supported in a later update. 126 | */ 127 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.PlaySound, callback: (eventData: IEventData) => void): boolean | null; 128 | /** 129 | * This event is triggered whenever a player attacks an entity. 130 | */ 131 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.PlayerAttackedEntity, callback: (eventData: IEventData) => void): boolean | null; 132 | /** 133 | * This event is triggered whenever a player destroys a block. 134 | */ 135 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.PlayerDestroyedBlock, callback: (eventData: IEventData) => void): boolean | null; 136 | /** 137 | * This event is triggered whenever a player places a block. 138 | */ 139 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.PlayerPlacedBlock, callback: (eventData: IEventData) => void): boolean | null; 140 | /** 141 | * This event is triggered whenever the weather changes. It contains information about the weather it is changing to. 142 | */ 143 | listenForEvent(eventIdentifier: ReceiveFromMinecraftServer.WeatherChanged, callback: (eventData: IEventData) => void): boolean | null; 144 | 145 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 146 | // Generic method for other custom events 147 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 148 | 149 | /** 150 | * Registers the Event to the script engine. This allows you to create Event Data by calling createEventData and have it initialized with the correct default data and fields. Only custom events need to be registered. 151 | * 152 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 153 | * @param eventData The JavaScript object with the correct fields and default values for the event 154 | */ 155 | registerEventData(eventIdentifier: string, eventData: TEventDataType): true | null; 156 | 157 | /** 158 | * Creates an object with all the required fields and default data for the specified event. If the event is a custom event, it needs to have been previously registered. 159 | * 160 | * @param eventIdentifier This is the identifier of the custom event we are registering. The namespace is required and can't be set to minecraft. 161 | */ 162 | createEventData(eventIdentifier: string): IEventData | null; 163 | 164 | /** 165 | * 166 | * @param eventIdentifier Allows you to trigger an event with the desired data from script. 167 | * Anything that signed up to listen for the event will be notified and the given data delivered to them. 168 | * @param eventData The data for the event. You can create a new JavaScript Object with the parameters you want to pass in to the listener and the engine will take care of delivering the data to them 169 | */ 170 | broadcastEvent(eventIdentifier: string, eventData: IEventData): boolean | null; 171 | 172 | /** 173 | * Allows you to register a JavaScript object that gets called whenever the specified event is broadcast. The event can either be a built-in event or an event specified in script. 174 | * @param eventIdentifier This is the name of the event to which we want to react. Can be the identifier of a built-in event or a custom one from script 175 | * @param eventData The name of the JavaScript object that will get called whenever the event is broadcast 176 | */ 177 | listenForEvent(eventIdentifier: string, callback: (eventData: IEventData) => void): boolean | null; 178 | } 179 | -------------------------------------------------------------------------------- /packages/shared/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | /// 12 | /// 13 | -------------------------------------------------------------------------------- /packages/shared/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-shared", 3 | "version": "1.0.0-alpha.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "typescript": { 8 | "version": "3.1.3", 9 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.3.tgz", 10 | "integrity": "sha512-+81MUSyX+BaSo+u2RbozuQk/UWx6hfG0a5gHu4ANEM4sU96XbuIyAB+rWBW1u70c6a5QuZfuYICn3s2UjuHUpA==", 11 | "dev": true 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/shared/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-types-shared", 3 | "version": "1.0.0", 4 | "description": "Shared TypeScript definitions for Minecraft Bedrock Edition's scripting engine", 5 | "contributors": [ 6 | "AtomicBlom", 7 | "abc55" 8 | ], 9 | "homepage": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 10 | "repository": "https://github.com/minecraft-addon-tools/minecraft-scripting-types", 11 | "license": "CC-BY-NC-SA-3.0", 12 | "devDependencies": { 13 | "typescript": "^3.1.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | // This file keeps IDEs happy, it is not used for compilation 2 | { 3 | "compilerOptions": { 4 | "module": "ES6", 5 | "noImplicitAny": true, 6 | "rootDir": "./types", 7 | "target": "es5" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/shared/types/block.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IBlock { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "block"; 6 | 7 | /** 8 | * The identifier of the block 9 | */ 10 | readonly __identifier__: string; 11 | 12 | /** 13 | * This is the ticking area object that was used to get this block 14 | */ 15 | readonly ticking_area: ITickingArea; 16 | 17 | /** 18 | * This is the position of the block. It also functions as part of its unique identifier 19 | */ 20 | readonly block_position: VectorXYZ; 21 | } -------------------------------------------------------------------------------- /packages/shared/types/component.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IComponent { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "component"; 6 | 7 | /** 8 | * The identifier of the component, e.g., "minecraft:position", or "minecraft:nameable" 9 | */ 10 | readonly __identifier__: string; 11 | 12 | data: T; 13 | } 14 | -------------------------------------------------------------------------------- /packages/shared/types/entity.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IEntity { 2 | /** 3 | * READ ONLY. The type of the entity 4 | */ 5 | readonly __type__: "entity" | "item_entity"; 6 | 7 | /** 8 | * The identifier of the entity, e.g., "minecraft:sheep", or "minecraft:pumpkin_seeds" 9 | */ 10 | readonly __identifier__: string; 11 | 12 | /** 13 | * READ ONLY. This is the unique identifier of the query 14 | */ 15 | readonly id: number; 16 | } 17 | -------------------------------------------------------------------------------- /packages/shared/types/event.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IEventData { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "event_data"; 6 | 7 | /** 8 | * The identifier of the event 9 | */ 10 | readonly __identifier__: string; 11 | 12 | data: T; 13 | } 14 | 15 | // TODO: move this stuff somewhere else 16 | declare const enum MinecraftDimension { 17 | Overworld = "overworld", 18 | Nether = "nether", 19 | End = "the end" 20 | } 21 | 22 | declare type Dimension = MinecraftDimension | string; 23 | declare type EntityId = number; -------------------------------------------------------------------------------- /packages/shared/types/item_stack.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IItemStack { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "item_stack"; 6 | 7 | /** 8 | * The identifier of the item stack 9 | */ 10 | readonly __identifier__: string; 11 | 12 | /** 13 | * The identifier of the item 14 | */ 15 | readonly item: string; 16 | 17 | /** 18 | * The number of items in the stack 19 | */ 20 | readonly count: number; 21 | } -------------------------------------------------------------------------------- /packages/shared/types/level.d.ts: -------------------------------------------------------------------------------- 1 | declare interface ILevel { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "level"; 6 | 7 | /** 8 | * READ ONLY. This is the unique identifier of the level 9 | */ 10 | readonly level_id: number; 11 | } -------------------------------------------------------------------------------- /packages/shared/types/minecraft_object.d.ts: -------------------------------------------------------------------------------- 1 | declare type IMinecraftObject = 2 | IEventData | IEntity | ILevel | IComponent | 3 | IQuery | IItemStack | IBlock | ITickingArea; 4 | -------------------------------------------------------------------------------- /packages/shared/types/particle_effects.d.ts: -------------------------------------------------------------------------------- 1 | declare type ParticleEffect = MinecraftParticleEffect | string; 2 | 3 | declare const enum MinecraftParticleEffect { 4 | /** 5 | * Beacon effects 6 | */ 7 | MobSpellAmbient = "minecraft:mobspellambient", 8 | /** 9 | * Attacking a villager in a village 10 | */ 11 | VillagerAngry = "minecraft:villagerangry", 12 | /** 13 | * Breaking blocks, sprinting, iron golems walking 14 | */ 15 | BlockBreak = "minecraft:blockbreak", 16 | /** 17 | * Breaking armor stands, falling 18 | */ 19 | BlockDust = "minecraft:blockdust", 20 | /** 21 | * Entities in water, guardian laser beams, fishing 22 | */ 23 | Bubble = "minecraft:bubble", 24 | /** 25 | * After jumping into water while on fire 26 | */ 27 | Evaporation = "minecraft:evaporation", 28 | /** 29 | * Critical hits, bows, evoker fangs 30 | */ 31 | CriticalHit = "minecraft:crit", 32 | /** 33 | * An ender dragon's breath and dragon fireballs 34 | */ 35 | DragonBreath = "minecraft:dragonbreath", 36 | /** 37 | * Dripping lava through blocks 38 | */ 39 | DripLava = "minecraft:driplava", 40 | /** 41 | * Dripping water through blocks, wet sponges, leaves when raining 42 | */ 43 | DripWater = "minecraft:dripwater", 44 | /** 45 | * Redstone ore, powered redstone dust, redstone torches, powered redstone repeaters 46 | */ 47 | RedstoneDust = "minecraft:reddust", 48 | /** 49 | * Splash potions, lingering potions, bottles o' enchanting, evokers. 50 | */ 51 | Spell = "minecraft:spell", 52 | /** 53 | * Elder Gardians 54 | * note: wiki has a question mark 55 | */ 56 | MobAppearance = "minecraft:mobappearance", 57 | /** 58 | * From bookshelves near an enchanting table. 59 | */ 60 | EnchantingTable = "minecraft:enchantingtable", 61 | /** 62 | * End rods, shulker bullets. 63 | */ 64 | EndRod = "minecraft:endrod", 65 | /** 66 | * Status effects, lingering potions, tipped arrows, trading, withered armor (linger potion particles decrease when the "minimal" particle setting is used). 67 | */ 68 | MobSpell = "minecraft:mobspell", 69 | /** 70 | * Explosions, ghast fireballs, wither skulls, ender dragon death, shearing mooshrooms. 71 | */ 72 | LargeExplosion = "minecraft:largeexplode", 73 | /** 74 | * Floating sand, gravel, concrete powder, and anvils. 75 | */ 76 | FallingDust = "minecraft:fallingdust", 77 | /** 78 | * Firework rocket trail and explosion (trail is not shown when the "minimal" particle setting is used), when dolphins track shipwrecks and underwater ruins. 79 | */ 80 | FireworksSpark = "minecraft:fireworksspark", 81 | /** 82 | * Fishing 83 | */ 84 | WaterWake = "minecraft:waterwake", 85 | /** 86 | * Torches, furnaces, magma cubes, spawners. 87 | */ 88 | Flame = "minecraft:flame", 89 | /** 90 | * Bone mealing a crop, trading with villagers, feeding baby animals, walking or jumping on turtle eggs. 91 | */ 92 | VillagerHappy = "minecraft:villagerhappy", 93 | /** 94 | * Breeding and taming animals. 95 | */ 96 | Heart = "minecraft:heart", 97 | /** 98 | * Explosions, ender dragon death. 99 | */ 100 | HugeExplosion = "minecraft:hugeexplosion", 101 | /** 102 | * Instant health/damage splash and lingering potions, spectral arrows. 103 | */ 104 | MobSpellInstantaneous = "minecraft:mobspellinstantaneous", 105 | /** 106 | * Eating, thrown eggs, splash potions, eyes of ender, breaking tools. 107 | */ 108 | IconCrack = "minecraft:iconcrack", 109 | /** 110 | * Jumping slimes. 111 | */ 112 | Slime = "minecraft:slime", 113 | /** 114 | * Thrown snowballs, creating withers, creating iron golems. 115 | */ 116 | SnowballPoof = "minecraft:snowballpoof", 117 | /** 118 | * Fire, minecart with furnace, blazes, water flowing into lava, lava flowing into water. 119 | */ 120 | LargeSmoke = "minecraft:largesmoke", 121 | /** 122 | * Lava 123 | */ 124 | Lava = "minecraft:lava", 125 | /** 126 | * Burning entities, blazes for example. 127 | */ 128 | MobFlame = "minecraft:mobflame", 129 | /** 130 | * Mycelium blocks. 131 | */ 132 | TownAura = "minecraft:townaura", 133 | /** 134 | * Activated Conduits. 135 | */ 136 | Nautilus = "minecraft:nautilus", 137 | /** 138 | * Emitted from note blocks and jukeboxes 139 | */ 140 | Note = "minecraft:note", 141 | /** 142 | * Explosions, death of mobs, mobs spawned from a spawner, silverfish infesting blocks. 143 | */ 144 | Explode = "minecraft:explode", 145 | /** 146 | * Nether portals, endermen, endermites, ender pearls, eyes of ender, ender chests, dragon eggs, teleporting from eating chorus fruits, end gateway portals. 147 | */ 148 | Portal = "minecraft:portal", 149 | /** 150 | * Rain 151 | */ 152 | RainSplash = "minecraft:rainsplash", 153 | /** 154 | * Torches, primed TNT, droppers, dispensers, end portals, brewing stands, spawners, furnaces, ghast fireballs, wither skulls, taming, withers, lava (when raining), placing an eye of ender in an end portal frame, redstone torches burning out. 155 | */ 156 | Smoke = "minecraft:smoke", 157 | /** 158 | * Entities in water, wolves shaking off after swimming, boats. 159 | */ 160 | WaterSplash = "minecraft:watersplash", 161 | /** 162 | * Produced by squids when attacked 163 | */ 164 | Ink = "minecraft:ink", 165 | /** 166 | * ? 167 | */ 168 | Terrain = "minecraft:terrain", 169 | /** 170 | * Activated totem of undying. 171 | */ 172 | Totem = "minecraft:totem", 173 | /** 174 | * ? 175 | */ 176 | TrackingEmitter = "minecraft:trackingemitter", 177 | /** 178 | * Witches. 179 | */ 180 | WitchSpell = "minecraft:witchspell" 181 | } -------------------------------------------------------------------------------- /packages/shared/types/query.d.ts: -------------------------------------------------------------------------------- 1 | declare interface IQuery { 2 | /** 3 | * The type of the object 4 | */ 5 | readonly __type__: "query"; 6 | 7 | /** 8 | * READ ONLY. This is the unique identifier of the query 9 | */ 10 | readonly query_id: number; 11 | } -------------------------------------------------------------------------------- /packages/shared/types/system.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | declare interface ISystem extends ISystemBase { 5 | /** 6 | * This is the first method that gets called immediately after the system is registered. It will run as soon as the script loads at world start. 7 | * You can use this to set up the environment for your script: register custom components and events, sign up event listeners, etc. This will run BEFORE the world is ready and the player has been added to it, so you shouldn't try to spawn any entities here! 8 | */ 9 | initialize?(this: TSystem): void; 10 | 11 | /** 12 | * This method gets called once every game tick. The server aims to be 200 times per second, while client aims to be 60, 13 | * but neither one is guaranteed and can vary with performance. This is a good place to get, check, and react to component changes. 14 | */ 15 | update?(this: TSystem): void; 16 | 17 | /** 18 | * This method gets called when the Minecraft Script Engine is shutting down. For the client this is when they leave the world; for the server this is after the last player has exited the world. 19 | */ 20 | shutdown?(this: TSystem): void; 21 | } 22 | 23 | declare interface ISystemBase { 24 | /** 25 | * Creates an empty entity with no components and does not place it in the world. 26 | */ 27 | createEntity(): IEntity | null; 28 | 29 | /** 30 | * Creates an entity and applies the specified template as defined in JSON. This allows you to quickly create an entity from the 31 | * applied Behavior Packs as the base for an entity created in scripting. The entity will be spawned into the world with all the 32 | * components, component groups, and event triggers that are defined in the JSON file of the identifier specified. 33 | * @param type Specifies the type of the entity that is being created by the template. Valid inputs are `entity` and `item_entity` 34 | * @param templateIdentifier This can be any of the entity identifiers from the applied Behavior Packs. For example specifying minecraft:cow here will make the provided entity a cow as defined in JSON 35 | */ 36 | createEntity(type: IEntity["__type__"], templateIdentifier: string): IEntity | null; 37 | 38 | /** 39 | * Destroys an entity identified by the EntityObject. If the entity exists in the world this will remove it from the world and 40 | * destroy it. This also makes the EntityObject no longer valid - you should only destroy an entity after you are done with it and 41 | * no longer need to reference it again. This does NOT kill the entity. There won't be an event for its death: it will be removed. 42 | * @param entity The IEntityObject that was retrieved from a call to createEntity() or retrieved from an event 43 | */ 44 | destroyEntity(entity: IEntity): true | null; 45 | 46 | /** 47 | * Checks if the given EntityObject corresponds to a valid entity. 48 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 49 | */ 50 | isValidEntity(entity: IEntity): boolean | null; 51 | 52 | /** 53 | * By default no filters are added. This will allow queries to capture all entities. 54 | * @param ComponentName This is the identifier of the component that will be added to the filter list. Only entities that have that component will be listed in the view 55 | */ 56 | addFilterToQuery(query: IQuery, ComponentName: string): void; 57 | 58 | /** 59 | * Allows you to fetch the entities captured by a query. 60 | * @param query This is the query you registered earlier using `registerQuery()` 61 | * @returns An array of IEntityObjects representing the entities found within the query 62 | */ 63 | getEntitiesFromQuery(query: IQuery): IEntity[]; 64 | 65 | /** 66 | * Allows you to fetch the entities captured by a spatial query. 67 | * @param query This is the query you created earlier using `registerQuery(...)` 68 | * @param componentField1Min The minimum value that the first component field needs to be on an entity for that entity to be included in the query 69 | * @param componentField2Min The minimum value that the second component field needs to be on an entity for that entity to be included in the query 70 | * @param componentField3Min The minimum value that the third component field needs to be on an entity for that entity to be included in the query 71 | * @param componentField1Max The maximum value that the first component field needs to be on an entity for that entity to be included in the query 72 | * @param componentField2Max The maximum value that the second component field needs to be on an entity for that entity to be included in the query 73 | * @param componentField3Max The maximum value that the third component field needs to be on an entity for that entity to be included in the query 74 | */ 75 | getEntitiesFromQuery(query: IQuery, 76 | componentField1Min: number, 77 | componentField2Min: number, 78 | componentField3Min: number, 79 | componentField1Max: number, 80 | componentField2Max: number, 81 | componentField3Max: number): IEntity[]; 82 | 83 | /** 84 | * User-Defined components are a special kind of component that can be defined in script and no built-in game system acts on it. 85 | * The component needs to be registered with the Script Engine by giving it a name and a set of fields in the format name:value. 86 | * Once applied, the component behaves like any of the built-in components: you can get it from an entity, modify its values, and 87 | * apply the changes. 88 | * Currently User-Defined components are the only components that can be dynamically added and removed from an entity using scripts. 89 | * They don't need to be previously defined in an entity's JSON file. In the current version these components will NOT be saved out or 90 | * loaded back in: they only exist while the entity is there and need to be added back when reloading the level. 91 | * @param componentIdentifier The name of the custom component. It is required to use a namespace so you can uniquely refer to it later without overlapping a name with a built-in component: for example 'myPack:myCustomComponent' 92 | * @param componentData A JavaScript Object that defines the name of the fields and the data each field holds inside the component. 93 | * @returns true if successful, null if an error occurred 94 | */ 95 | registerComponent(componentIdentifier: string, componentData: object): true | null; 96 | 97 | /** 98 | * Applies the component and any changes made to it in script back to the entity. What this means for each component can be slightly 99 | * different: it makes the component reload on the entity with the new data as if it had just been added to the entity. 100 | * @param component The component object retrieved from the entity that was returned by either createComponent() or getComponent() 101 | */ 102 | applyComponentChanges(entity: IEntity, component: IComponent): true | null; 103 | 104 | /** 105 | * Removes the specified component from the given entity. If the entity has the component, it will be removed. Currently this only works with custom components and can't be used to remove components defined for an entity in JSON. 106 | * @param entity The EntityObject that was retrieved from a call to createEntity() or retrieved from an event 107 | * @param componentIdentifier The name of the component to remove from the entity. This is either the name of a built-in component (check the Script Components section) or a custom component created with a call to registerComponent() 108 | */ 109 | destroyComponent(entity: IEntity, componentIdentifier: string): true | null; 110 | } -------------------------------------------------------------------------------- /packages/shared/types/ticking_area.d.ts: -------------------------------------------------------------------------------- 1 | type ITickingArea = IEntityTickingArea | ILevelTickingArea; 2 | 3 | declare interface IEntityTickingArea { 4 | /** 5 | * The type of the object 6 | */ 7 | readonly __type__: "entity_ticking_area"; 8 | 9 | /** 10 | * The unique identifier of the ticking area 11 | */ 12 | readonly entity_ticking_area_id: Int64; 13 | } 14 | 15 | declare interface ILevelTickingArea { 16 | /** 17 | * The type of the object 18 | */ 19 | readonly __type__: "level_ticking_area"; 20 | 21 | /** 22 | * The uuid of the ticking area 23 | */ 24 | readonly level_ticking_area_id: string; 25 | } 26 | -------------------------------------------------------------------------------- /packages/shared/types/types.d.ts: -------------------------------------------------------------------------------- 1 | declare type VectorArray = [number, number, number]; 2 | 3 | declare interface VectorXYZ { 4 | x: number; 5 | y: number; 6 | z: number; 7 | } 8 | 9 | declare interface Range { 10 | range_min: number; 11 | range_max: number; 12 | } 13 | 14 | declare interface Int64 { 15 | "64bit_low": number; 16 | "64bit_high": number; 17 | } 18 | 19 | declare interface MinecraftTrigger { 20 | event: string; 21 | filters: MinecraftFilter; 22 | target: string; 23 | } 24 | 25 | declare interface MinecraftFilter { 26 | all_of?: MinecraftFilter[]; 27 | any_of?: MinecraftFilter[]; 28 | 29 | test?: string; 30 | subject?: "other" | "parent" | "player" | "self" | "target"; 31 | operator?: "!=" | "<" | "<=" | "<>" | "=" | "==" | ">" | ">=" | "equals" | "not"; 32 | domain?: string; 33 | value?: any; 34 | } 35 | --------------------------------------------------------------------------------