UNPKG

hytopia

Version:

The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.

347 lines (160 loc) 4.33 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [BlockType](./server.blocktype.md) ## BlockType class Represents a block type definition. When to use: defining new block types (textures, colliders, liquid behavior). Do NOT use for: placing blocks directly; use `ChunkLattice.setBlock`<!-- -->. **Signature:** ```typescript export default class BlockType extends EventRouter implements protocol.Serializable ``` **Extends:** [EventRouter](./server.eventrouter.md) **Implements:** protocol.Serializable ## Remarks Block types are created as instances and registered with a `BlockTypeRegistry` for a specific world. Liquids are treated as sensors in physics. <h2>Events</h2> This class is an EventRouter, and instances of it emit events with payloads listed under `BlockTypeEventPayloads`<!-- -->. ## Example ```typescript const stoneBlockTypeId = 10; world.blockTypeRegistry.registerBlockType(new BlockType({ id: stoneBlockTypeId, textureUri: 'textures/stone.png', name: 'Stone', })); // Create a stone block at coordinate 0, 1, 0 world.chunkLattice.setBlock({ x: 0, y: 1, z: 0 }, stoneBlockTypeId); ``` \*\*Category:\*\* Blocks ## Constructors <table><thead><tr><th> Constructor </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [(constructor)(options)](./server.blocktype._constructor_.md) </td><td> </td><td> Creates a new block type instance. Use for: defining a block type before registering it with a `BlockTypeRegistry`<!-- -->. </td></tr> </tbody></table> ## Properties <table><thead><tr><th> Property </th><th> Modifiers </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> [colliderOptions](./server.blocktype.collideroptions.md) </td><td> `readonly` </td><td> [VoxelsColliderOptions](./server.voxelscollideroptions.md) \| [TrimeshColliderOptions](./server.trimeshcollideroptions.md) </td><td> The collider options for the block type. \*\*Category:\*\* Blocks </td></tr> <tr><td> [id](./server.blocktype.id.md) </td><td> `readonly` </td><td> number </td><td> The unique identifier for the block type. \*\*Category:\*\* Blocks </td></tr> <tr><td> [isLiquid](./server.blocktype.isliquid.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the block type is a liquid. \*\*Category:\*\* Blocks </td></tr> <tr><td> [isMeshable](./server.blocktype.ismeshable.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the block type is meshable (voxel-based). \*\*Category:\*\* Blocks </td></tr> <tr><td> [isTrimesh](./server.blocktype.istrimesh.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the block type uses a trimesh collider. \*\*Category:\*\* Blocks </td></tr> <tr><td> [isVoxel](./server.blocktype.isvoxel.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the block type uses a voxel collider. \*\*Category:\*\* Blocks </td></tr> <tr><td> [lightLevel](./server.blocktype.lightlevel.md) </td><td> `readonly` </td><td> number </td><td> The light emission level (0-15). \*\*Category:\*\* Blocks </td></tr> <tr><td> [name](./server.blocktype.name.md) </td><td> `readonly` </td><td> string </td><td> The name of the block type. \*\*Category:\*\* Blocks </td></tr> <tr><td> [textureUri](./server.blocktype.textureuri.md) </td><td> `readonly` </td><td> string </td><td> The URI of the texture for the block type. \*\*Category:\*\* Blocks </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [interact(player, raycastHit)](./server.blocktype.interact.md) </td><td> </td><td> Triggers an interaction on the block type from a player. Use for: programmatic interactions that should mimic player clicks. </td></tr> </tbody></table>