Scrap !!
This commit is contained in:
@@ -42,19 +42,20 @@ showed. These events fire for **every** player's actions, since they all go thro
|
||||
|
||||
## The Events
|
||||
|
||||
| Event | Before | After | Fields |
|
||||
| ---------------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `block_break` | ✓ | ✓ | `player`, `block` (with its tile `data`), `item` held |
|
||||
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `hit` where on it (0-1 each axis), `item` held |
|
||||
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` held. Before fires for every right click on a block, after only when a component's `on_interact` handled it |
|
||||
| `chat_send` | ✓ | ✓ | `player`, `message`. Before handlers can change `message` |
|
||||
| `entity_damage` | ✓ | ✓ | `entity`, `player`, `amount`, `cause`, `bypasses_invulnerability`. See below |
|
||||
| `player_death` | | ✓ | `player`, `cause`. They've dropped what they carried and respawn right after |
|
||||
| `player_join` | | ✓ | `player` |
|
||||
| `player_leave` | | ✓ | `player` |
|
||||
| `server_start` | | ✓ | none. Every mod's server phase has run |
|
||||
| `tick` | | ✓ | `dt`, in seconds. 20 times a second |
|
||||
| `new_day` | | ✓ | `day`. At 06:00, after every block's `on_new_day` |
|
||||
| Event | Before | After | Fields |
|
||||
| ----------------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `block_break` | ✓ | ✓ | `player`, `block` (with its tile `data`), `item` held |
|
||||
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `hit` where on it (0-1 each axis), `item` held |
|
||||
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` held. Before fires for every right click on a block, after only when a component's `on_interact` handled it |
|
||||
| `entity_interact` | ✓ | | `player`, `entity` right clicked, `item` held. Cancelling it stops the held item being used, see [Interacting](../entities/index.md#interacting) |
|
||||
| `chat_send` | ✓ | ✓ | `player`, `message`. Before handlers can change `message` |
|
||||
| `entity_damage` | ✓ | ✓ | `entity`, `player`, `amount`, `cause`, `bypasses_invulnerability`. See below |
|
||||
| `player_death` | | ✓ | `player`, `cause`. They've dropped what they carried and respawn right after |
|
||||
| `player_join` | | ✓ | `player` |
|
||||
| `player_leave` | | ✓ | `player` |
|
||||
| `server_start` | | ✓ | none. Every mod's server phase has run |
|
||||
| `tick` | | ✓ | `dt`, in seconds. 20 times a second |
|
||||
| `new_day` | | ✓ | `day`. At 06:00, after every block's `on_new_day` |
|
||||
|
||||
`cause` is `"fall"`, `"void"`, `"starve"`, `"mob_attack"`, or whatever a mod passed to `damage(amount, cause)`.
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ and players. Mods define new kinds in their `entities/` folder, and draw them wi
|
||||
| Field | Default | Meaning |
|
||||
| -------------------- | ---------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| `id` | required | The entity's id. |
|
||||
| `texture` | required | Any texture, stretched over the model's `texture_width` and `texture_height`. |
|
||||
| `texture` | required | Any texture, stretched over the model's `texture_width` and `texture_height`. An object needs none. |
|
||||
| `model` | none | An [entity model](#entity-models). Without one it's drawn as its texture, facing the camera. |
|
||||
| `behavior` | `"animal"` | `"animal"`, `"monster"`, `"scripted"`, or a [custom behavior](#custom-behaviors)'s id. |
|
||||
| `behavior` | `"animal"` | `"animal"`, `"monster"`, `"scripted"`, `"object"`, or a [custom behavior](#custom-behaviors)'s id. |
|
||||
| `scale` | `1` | How much bigger it's drawn than its model, texture or item. Its box stays `width` and `height`. |
|
||||
| `category` | see below | `"monster"` or `"creature"`, see [Natural Spawning](#natural-spawning). |
|
||||
| `width`, `height` | required | Its collision box in blocks, up to 16. `width` is for both x and z. Its eyes are at 85% of the height. |
|
||||
| `max_health` | `10` | In half hearts. |
|
||||
@@ -92,6 +93,49 @@ the world, so a script never finds one it doesn't know about after a restart. Th
|
||||
}
|
||||
```
|
||||
|
||||
**Objects** lie around like a dropped item, holding one: they fall, slide and float in water the same way, but nobody
|
||||
picks them up by walking into them, and they never despawn or merge. They can't be hurt, don't think, don't stop blocks
|
||||
being placed where they are, and are saved with the world with what they hold. Without a `model`, an object is drawn as
|
||||
its item: the item's [model](../resources/models.md#entity-models-as-items) at the size it's made, times `scale`, turned
|
||||
the way the object faces.
|
||||
|
||||
An item lies around as an object instead of a dropped item when it names one as its
|
||||
[`entity`](../items/index.md#properties), like NeoForge's `hasCustomEntity`. Every way an item ends up in the world
|
||||
spawns the object holding it: thrown, dropped when its holder dies or when it doesn't fit, popped out of a broken block,
|
||||
or a script's `spawn_item` or `drop_item`. Dangerous Business's scrap is one, picked up by right clicking it (see
|
||||
[Interacting](#interacting)):
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"entity": {
|
||||
"id": "dangerous_business:scrap",
|
||||
"behavior": "object",
|
||||
"width": 0.7,
|
||||
"height": 0.7,
|
||||
"scale": 0.7
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Interacting
|
||||
|
||||
Right clicking an entity from up to 3 blocks away fires [`before.entity_interact`](../concepts/events.md#the-events),
|
||||
like NeoForge's `PlayerInteractEvent.EntityInteract`. Its handlers do whatever the click does and cancel it, otherwise
|
||||
the held item is used as if clicking nothing. A handler can also leave the entity be, like scrap with nowhere to go:
|
||||
|
||||
```ts
|
||||
ctx.events.before.entity_interact.subscribe((event) => {
|
||||
if (event.entity.type !== "dangerous_business:scrap") return;
|
||||
event.cancel = true;
|
||||
const item = event.entity.get_item();
|
||||
const slot = [0, 1, 2, 3].find((slot) => event.player.inventory.get(slot) === undefined);
|
||||
if (!item || slot === undefined) return;
|
||||
event.player.inventory.set(slot, item);
|
||||
event.entity.remove();
|
||||
});
|
||||
```
|
||||
|
||||
## Custom Behaviors
|
||||
|
||||
A mob can get its goals from a script instead, like NeoForge's `registerGoals`. Its json names a behavior id, and the
|
||||
@@ -288,8 +332,8 @@ interface EntityRef {
|
||||
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
|
||||
get_item(): ItemStack | undefined; // for an item lying around or what an object holds, a copy
|
||||
set_item(item: ItemStack | undefined): void; // undefined takes an item lying around away, an object holds nothing
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ down to 0 is gone.
|
||||
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
|
||||
| `model` | none | A [model](../resources/models.md#item-models) it's drawn with instead of its texture, or an [entity model](../resources/models.md#entity-models-as-items). |
|
||||
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
|
||||
| `entity` | none | An [object](../entities/index.md#behaviors) it lies in the world as instead of a dropped item, holding the stack. |
|
||||
| `targets_fluids` | `false` | Players holding it aim at fluids, like buckets and fishing rods. Others aim through. |
|
||||
| `fluid_container` | none | Makes it hold a fluid, like a bucket, see [Fluids](../resources/fluids.md#containers). |
|
||||
| `layers` | none | Textures drawn over its own, each in a color, see [below](#layers). |
|
||||
|
||||
Reference in New Issue
Block a user