-
Notifications
You must be signed in to change notification settings - Fork 39
Event docs (5 events now) #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
denisJaved
wants to merge
8
commits into
KubeJS-Mods:main
Choose a base branch
from
StoryAnvil:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aa35252
Documented ServerEvents.tags
denisJaved 04504e5
Documented BlockEvents.placed
denisJaved 60070c8
Documented ClientEvents.leftDebugInfo & Client.Events.rightDebugInfo
denisJaved 1f5aa24
Fixed codeblocks
denisJaved 66ae46e
Changed ServerEvents.basicCommand for consistancy
denisJaved dd8b87d
Fixing spacings
denisJaved b6030e5
Created redirect for ServerEvents.recipe
denisJaved 2f11560
Merge branch 'main' into main
denisJaved File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: "BlockEvents.placed" | ||
| description: "Called when block placed by player" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| This event called each time block is placed by entity or a dispenser. | ||
|
|
||
| ## Syntax | ||
| ```js | ||
| BlockEvents.placed(event => { | ||
| event.cancel(); // cancels event by preventing block placement | ||
| event.getLevel(); // returns level block placed in | ||
| event.getEntity(); // returns entity that placed the block. Could be null if block placed by dispenser | ||
| event.getBlock(); // returns block which was placed | ||
|
|
||
| // Inherited from KubeEntityEvent | ||
| event.getPlayer(); // returns player that placed the block. Could be null if block placed by dispenser OR entity that placed the block isn't player | ||
|
|
||
| // Inherited from KubeLevelEvent | ||
| event.getServer(); // returns server block placed in. | ||
| event.getRegistries(); // returns regestry access of level block was placed in | ||
| }) | ||
| ``` | ||
|
|
||
| ## Usage example | ||
| ```js | ||
| BlockEvents.placed(event => { | ||
| if (even.getEntity() == null) { | ||
| event.cancel(); | ||
| } | ||
| }) | ||
| ``` | ||
| Code above will prevent dispensers from placing blocks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: "ClientEvents.leftDebugInfo" | ||
| description: "Adding, removing, and modifying debug info" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| This event called each frame when debug info (avalible by pressing F3) is rendered. | ||
|
|
||
| >>> warning | ||
| This event called every frame meaning any heavy operations here will result in lags! | ||
| <<< | ||
|
|
||
| ## Syntax | ||
| ```js | ||
| ClientEvents.leftDebugInfo(event => { // or ClientEvents.rightDebugInfo | ||
| event.getLines(); // returns array of strings. This array represents lines of text in one side of F3 menu | ||
| event.getShowDebug() // returns true if debug menu should be rendered. | ||
| }); | ||
| ``` | ||
|
|
||
| >>> warning | ||
| Mutating array returned by `event.getLines()` will change text rendered in F3 screen. | ||
| <<< | ||
|
|
||
| ## Usage example | ||
| ```js | ||
| ClientEvents.leftDebugInfo(event => { | ||
| event.getLines().push("I love KUBEJSSS"); | ||
| }); | ||
| ``` | ||
| Code above will add text `I love KUBEJSSS` in bottom of left side in F3 screen. | ||
|
|
||
| >>> info | ||
| `event.getLines()` returns javascript array. You can find information about them at [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) | ||
| <<< | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: "ClientEvents.rightDebugInfo" | ||
| description: "Adding, removing, and modifying debug info" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| This event works exactly the same as `ClientEvents.leftDebugInfo` does but for right side on debug screen. Visit it's docs for information. | ||
| [[[/events/ClientEvents/leftDebugInfo]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: "ServerEvents.recipes" | ||
| description: "Adding, removing, and modifying recipes" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| This event used to create new or modify existing recipes. | ||
|
|
||
| >>> info | ||
| [[[/tutorials/recipes]]] | ||
| Please see tutorial page for more information | ||
| <<< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: "ServerEvents.tags" | ||
| description: "Adding, removing, and modifying tags" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| This event used to create new or modify existing [tags](https://minecraft.wiki/w/Tag). | ||
|
|
||
| >>> info | ||
| Tags used for grouping different registry objects (for example: tag `#minecraft:logs` groups all of the tree logs). | ||
|
|
||
| Tags commonly used by mods and recipes for example instead of making bunch of [stick's](https://minecraft.wiki/w/Stick) recipes for each wood type you can create just one that uses tags. | ||
| Because when tags being used as recipe ingredient they can be replaced by any of tagged items. | ||
| <<< | ||
|
|
||
| ## Syntax | ||
| ```js | ||
| ServerEvents.tags("<registry>", event => { | ||
| event.add("<tag>", "<registry object>"); | ||
| event.add("<tag>", "#<tag>"); | ||
| event.remove("<tag>", "<registry object>"); | ||
| event.removeAll("<tag>"); | ||
| event.removeAllTagsFrom("<tag>"); | ||
| event.get("<tag>"); | ||
| }) | ||
| ``` | ||
|
|
||
| `<regestry>` can be any of registries even modded ones! For modded registries you must include namespace. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo here, it should be <registry> |
||
| List of vanilla registries avalible at [minecraft wiki](https://minecraft.wiki/w/Resource_location#Registries_and_registry_objects); | ||
|
|
||
|
|
||
| ### event.add | ||
| `event.add` function adds specified regestry object or tag to another tag. For example: | ||
| ```js | ||
| event.add('forge:cobblestone', 'minecraft:diamond_ore') | ||
| ``` | ||
| will add `minecraft:diamond_ore` to `#forge:cobblestone` tag. | ||
|
|
||
| Adding tag to different tag will add all of the objects in child tag to parent one. | ||
| ```js | ||
| event.add('c:stones', '#forge:stone') | ||
| ``` | ||
| so this will add **all** of regestry objects that are tagged now or will tagged later `#c:stones` in `#forge:stone` tag. | ||
|
|
||
|
|
||
| ### event.remove | ||
| `event.remove` function does exactly opposite of previous function. So, | ||
| ```js | ||
| event.remove('forge:cobblestone', 'minecraft:mossy_cobblestone') | ||
| ``` | ||
| will remove `minecraft:mossy_cobblestone` from `#forge:cobblestone` tag. | ||
|
|
||
| ### event.removeAll | ||
| This function removes all entries from the tag. For example: | ||
| ```js | ||
| event.removeAll('forge:ingots/copper') | ||
| ``` | ||
| will remove everything from `#forge:ingots/copper` tag. | ||
|
|
||
| ### event.removeAllTagsFrom | ||
| This function is really similar to `event.removeAll` but it removes only other tags that are in tag. | ||
|
|
||
| ### event.get | ||
| This function returns tag object. | ||
|
|
||
| For example this can be used to get list of all tag entries. | ||
| ``` | ||
| const stones = event.get('forge:stone').getObjectIds() | ||
| ``` | ||
| this code will put list of resource locations that are in `#forge:stone` tag into stones varible | ||
|
|
||
| ## Usage example | ||
| [[[/tutorials/tags]]] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight inacurracy - It's actually a Java
ListofStrings, but Rhino makes it so that the integration between Java and JS is almost seamless - JS treats theListlike a JS array (can be indexed like one), but keep in mind it isn't exactly a JS array - it's handled a bit differently.https://github.com/KubeJS-Mods/KubeJS/blob/99655ced4fbb3627ed5d2a50745cc525a4161c7c/src/main/java/dev/latvian/mods/kubejs/client/DebugInfoKubeEvent.java#L26