Death
This commit is contained in:
@@ -73,6 +73,7 @@ the block and the component.
|
||||
| `on_state_change(block, params, before)` | Its own states change without it being replaced, by `set_state` or a rule. See [Changes](#changes). | |
|
||||
| `on_scheduled_tick(block, params)` | A tick it asked for comes. See [Scheduled Ticks](#scheduled-ticks). | |
|
||||
| `on_entity_stand(block, params, entity)` | An entity standing on it moves, every tick it does. See [Entities on It](#entities-on-it). | |
|
||||
| `on_entity_inside(block, params, entity)` | An entity whose box is in it moves, every tick it does. See [Entities on It](#entities-on-it). | |
|
||||
| `fluid_handler(block, params, face?)` | Something reaches for its tanks from `face`. See [Fluid Handlers](../resources/fluids.md#fluid-handlers). | a `FluidHandler`, or `undefined` |
|
||||
| `export_data(block, params)` | It goes into a schematic. See [Schematics](../misc/schematics.md#block-data). | its data for the schematic |
|
||||
|
||||
@@ -98,6 +99,21 @@ ctx.components.register_block("create:basin", {
|
||||
});
|
||||
```
|
||||
|
||||
`on_entity_inside` runs every tick an entity moves while its box is in the block, like NeoForge's `entityInside`, for
|
||||
each block its box is in. Players move on their own clients, so for them it runs after each move their client sends, and
|
||||
they come as an `EntityRef` of type `cubi:player`: `ctx.players.get(entity.id)` gives the
|
||||
[`Player`](../entities/players.md). Being against a block's side isn't being in it. It runs whatever the block's shape,
|
||||
so a block that only cares about part of itself checks the entity's `position`. Dangerous Business's death block kills
|
||||
whatever walks or falls into it:
|
||||
|
||||
```ts
|
||||
ctx.components.register_block("dangerous_business:death", {
|
||||
on_entity_inside(_block, _params, entity) {
|
||||
entity.kill("death_block");
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Changes
|
||||
|
||||
`on_neighbor_change` is the server's side of the [rule](#neighbors) with the same name, like NeoForge's
|
||||
|
||||
@@ -155,6 +155,7 @@ interface EntityRef {
|
||||
teleport(x: number, y: number, z: number): void;
|
||||
push(x: number, y: number, z: number): void; // adds to its velocity
|
||||
remove(): void;
|
||||
kill(cause?: string): void; // players and mobs die, anything else is removed
|
||||
get_item(): ItemStack | undefined; // for an item lying around, a copy
|
||||
set_item(item: ItemStack | undefined): void; // for an item lying around, undefined takes it away
|
||||
}
|
||||
@@ -163,6 +164,10 @@ interface EntityRef {
|
||||
Once an entity is removed, by a script or anything else, it stays removed, and teleporting it does nothing. Check
|
||||
`removed` before relying on one you kept from earlier.
|
||||
|
||||
`kill` is like NeoForge's `Entity.kill`: a player or a mob dies even when it's invulnerable, the way falling out of the
|
||||
world hurts it, and `cause` goes to `entity_damage` and the death message like [`damage`](players.md)'s does. Mods'
|
||||
`before.entity_damage` can still cancel it. Anything that can't die, like an item lying around, is removed instead.
|
||||
|
||||
`push` adds to how fast it's moving, like Minecraft's `Entity.push`: a fan blowing it along does it every tick. Players
|
||||
have a `push` too, see [Players](players.md#pushing).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user