BlockRegistry

Registry to get, set and break blocks.

Block IDs are resource locations, where the namespace is the ID of a block registry, for example craftengine:default/palm_log. IDs without namespace or with the mimic namespace are searched over all registries.

Implementations work with IDs without the registry namespace. A plugin's own namespace becomes the first path segment: default:palm_log ->default/palm_log.

Methods changing blocks should be called from the server thread. They fire no place or break events and make no protection checks, the caller is responsible for both. Block physics is applied as usual, so neighboring blocks are updated.

Since

0.9.0

Properties

Link copied to clipboard
abstract val knownIds: Collection<String>

Returns currently known block IDs. They may change while plugins load or reload their data.

Inherited properties

Link copied to clipboard
open val id: String

Returns the ID of the service. It should match regex [a-z0-9._-].

Link copied to clipboard
open val isEnabled: Boolean

Returns true if the service is initialized may be used. Default implementation always returns true.

Functions

Link copied to clipboard
open fun breakBlock(block: BlockT): Boolean

Breaks the given block with a suitable tool, dropping items on the ground.

open fun breakBlock(block: BlockT, tool: ItemStackT?): Boolean

Breaks the given block with the tool, dropping items on the ground.

abstract fun breakBlock(block: BlockT, tool: ItemStackT? = null, dropsConsumer: DropsConsumer<ItemStackT>): Boolean

Breaks the given block with the tool and passes the dropped items to the dropsConsumer.

Link copied to clipboard
abstract fun getBlockId(block: BlockT): String?

Returns ID of the given block, or null if the block doesn't belong to this registry.

Link copied to clipboard
abstract fun getBlockIdFromItem(blockItem: ItemStackT): String?

Returns ID of the block placed by the given blockItem, or null if it doesn't belong to this registry.

Link copied to clipboard
abstract fun isBlockExists(blockId: String): Boolean

Returns true if a block with the given blockId exists.

Link copied to clipboard
open fun isSameBlock(block: BlockT, blockId: String): Boolean

Returns true if the given block has the given blockId.

Link copied to clipboard
open fun isSameBlockItem(blockItem: ItemStackT, blockId: String): Boolean

Returns true if the given blockItem places the block with the given blockId.

Link copied to clipboard
open fun setBlock(block: BlockT, blockId: String): Boolean

Sets the block with the given blockId in place of the empty block.

abstract fun setBlock(block: BlockT, blockId: String, payload: Any?): Boolean

Sets the block with the given blockId configured with the payload in place of the empty block. To replace a block, break it first, so its registry can clean up.