LogoLogo
  • Get Started
  • Getting Started
    • Initial Setup
    • Create Your First Game
    • API Reference
    • Build Your First World Map
    • Multiplayer Testing
    • Use Templates & Examples
    • Styling & Assets
      • Modeling Guidelines
      • Texturing Guidelines
      • Default Assets
  • Build Faster With AI Tools
  • SDK Guides
    • Assets
    • Audio & SFX
      • Audio Manager
    • Blocks & Chunks
      • Block Types
      • Block Type Registry
      • Chunks
      • Chunk Lattice
    • Camera
    • Chat & Commands
    • Debugging
    • Entities
      • Animations
      • Block Entities
      • Colliders & Hitbox
      • Child Entities
      • Entity Controllers
        • Base Entity Controller
        • Pathfinding Entity Controller
        • DefaultPlayer Entity Controller
        • Simple Entity Controller
      • Entity Manager
      • Model Entities
      • Movement & Pathfinding
      • Player Controlled Entities
    • Events
    • Input & Controls
    • Lighting
      • Ambient Light
      • Light Manager
      • Point Lights
      • Spot Lights
      • Sun Light (Directional)
    • Mobile
    • Persisted Data
    • Players
      • Player Manager
      • Persisted Player Data
    • Plugins
    • Physics
      • Colliders
      • Collision Groups
      • Debugging
      • Gravity
      • Raycasts
      • Rigid Bodies
    • User Interface
      • Overlay UI
      • Scene UIs
      • Scene UI Manager
    • Worlds
      • Map Data Format
  • Helpful Resources
    • HYTOPIA Architecture & Platform Overview
    • Useful Third-Party Tools
Powered by GitBook
On this page
  • Accessing A BlockTypeRegistry
  • Registering Block Types
  • Other BlockTypeRegistry Usage
  • Diving Deeper
Export as PDF
  1. SDK Guides
  2. Blocks & Chunks

Block Type Registry

Most games will have many block types, and keeping track of those block types is important for your own game systems and internal HYTOPIA systems.

This is where the BlockTypeRegistry comes into play. Allowing us to register, unregister, retrieve and iterate known BlockType instances of our world.

Accessing A BlockTypeRegistry

The BlockTypeRegistry is used as a singleton and automatically created for a given world instance.

You can access the block type registry for a world like this:

world.blockTypeRegistry

Registering Block Types

Before a block type can be set as a block at a coordinate in the world through world.chunkLattice.setBlock() or chunk.setBlock(), the block type must have been previously registered with the world.blockTypeRegistry through world.blockTypeRegistry.registerBlockType() or world.blockTypeRegistry.registerGenericBlockType().

In this example, let's dive into how to register a block type, as well as the difference between registerBlockType() and registerGenericBlockType()

// This usage of world.blockTypeRegistry.registerGenericBlockType()
const dirtBlock = world.blockTypeRegistry.registerGenericBlockType({
  id: 1,
  textureUri: 'blocks/dirt.png',
  name: 'Dirt'
});

// Is equivalent too this
const dirtBlock = new BlockType({
  id: 1,
  textureUri: 'blocks/dirt.png',
  name: 'Dirt'
});

world.blockTypeRegistry.registerBlockType(dirtBlock);

// Using either is a matter of preference and 
// convenience, internally they result in
// the same outcome.

Other BlockTypeRegistry Usage

The BlockTypeRegistry exposes ways to iterate known block types, or get registered block types by ID. Here's an example:

// Returns an array of all block types
// for the world
world.blockTypeRegistry.getAllBlockTypes();

// Returns the block type for the provided ID,
// or throws if the provide ID is not registered.
const id = 15
world.blockTypeRegistry.getBlockType(id);

Diving Deeper

PreviousBlock TypesNextChunks

Last updated 4 months ago

The BlockTypeRegistry class is constantly evolving. You can find the latest .

If there are features that we don't currently support for BlockTypeRegistry that you'd like to see added to the HYTOPIA SDK, you can .

BlockTypeRegistry API Reference here
submit a feature request here