Skip to content

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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wiki/events/BlockEvents/placed/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "BlockEvents.placed"
description: "Called when block placed by player"
28 changes: 28 additions & 0 deletions wiki/events/BlockEvents/placed/page.kubedoc
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.
2 changes: 2 additions & 0 deletions wiki/events/ClientEvents/leftDebugInfo/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "ClientEvents.leftDebugInfo"
description: "Adding, removing, and modifying debug info"
29 changes: 29 additions & 0 deletions wiki/events/ClientEvents/leftDebugInfo/page.kubedoc
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)
<<<
2 changes: 2 additions & 0 deletions wiki/events/ClientEvents/rightDebugInfo/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "ClientEvents.rightDebugInfo"
description: "Adding, removing, and modifying debug info"
2 changes: 2 additions & 0 deletions wiki/events/ClientEvents/rightDebugInfo/page.kubedoc
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]]]
21 changes: 17 additions & 4 deletions wiki/events/ServerEvents/basicCommand/page.kubedoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# Available Event Fields
- `event.player` - player entity
- `event.input` - string (Only 1.21+)
This event allows regestry of basic chat commands.

# Example
## Syntax
|> 1.21
```js
ServerEvents.basicCommand('<command name>', event => {
event.player // player who executed the command
event.input // string provided as command arguments (ONLY 1.21+)
})
```
<||> 1.20.1
```js
ServerEvents.customCommand('<command name>', event => {
event.player // player who executed the command
})
```
<|

## Usage example
|> 1.21
```js
ServerEvents.basicCommand('icons', event => {
Expand Down
2 changes: 2 additions & 0 deletions wiki/events/ServerEvents/recipes/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "ServerEvents.recipes"
description: "Adding, removing, and modifying recipes"
6 changes: 6 additions & 0 deletions wiki/events/ServerEvents/recipes/page.kubedoc
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
<<<
2 changes: 2 additions & 0 deletions wiki/events/ServerEvents/tags/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "ServerEvents.tags"
description: "Adding, removing, and modifying tags"
67 changes: 67 additions & 0 deletions wiki/events/ServerEvents/tags/page.kubedoc
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.
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]]]
5 changes: 5 additions & 0 deletions wiki/tutorials/recipes/page.kubedoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,8 @@ ServerEvents.recipes(event => {
## Looping

In addition to helper functions, you can also loop through an array to perform an action on every item in the array.

>>> info
[[[/events/ServerEvents/recipes]]]
View event page for more reference
<<<
7 changes: 6 additions & 1 deletion wiki/tutorials/tags/page.kubedoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ ServerEvents.tags('block', event => {
// Add tall grass to the climbable tag. This does make it climbable!
event.add('minecraft:climbable', 'minecraft:tall_grass')
})
```
```

>>> info
[[[/events/ServerEvents/tags]]]
View event page for more reference including list of vanilla registries
<<<