block

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FNV1_32_INIT  uint32 = 0x811C9DC5
	FNV1_PRIME_32 uint32 = 0x01000193
)

Variables

This section is empty.

Functions

func ComputeBlockHash

func ComputeBlockHash(blockName string, blockStates map[string]any) uint32

ComputeBlockHash compute the hash of block whose name is blockName, and states is blockStates. This implement is edited from https://gist.github.com/Alemiz112/504d0f79feac7ef57eda174b668dd345.

func Fnv1a_32

func Fnv1a_32(data []byte) uint32

Fnv1a_32 compute the fnv1a_32 hash of data.

func MarshalInternalData

func MarshalInternalData(key string, value any) []byte

MarshalInternalData marshal map[string]any{key: value} to its NBT represent. Note that only the internal results are returned, and the outer ones are not included.

For example, if key is "12" whose bytes is []byte{49, 50}, and value is int32(7), then the return result is []byte{3, 2, 0, 49, 50, 7, 0, 0, 0} but not []byte{10, 0, 0, 3, 2, 0, 49, 50, 7, 0, 0, 0, 0}.

The explanation of the example:

  • 3 => The type of value is TAG_Int (3)
  • 2, 0 => The length of key ("12") is 2 (little endian represent)
  • 49, 50 => The content of key ("12")
  • 7, 0, 0, 0 => The little endian represent of value (7)

Types

type BlockEntry

type BlockEntry struct {
	Block     define.BlockState
	RuntimeID uint32
}

BlockEntry holds a block with its runtime id.

type BlockRuntimeIDTable

type BlockRuntimeIDTable struct {
	// contains filtered or unexported fields
}

BlockRuntimeIDTable is a block runtime ID table that supports converting blocks between blocks themselves and their runtime IDs description.

func NewBlockRuntimeIDTable

func NewBlockRuntimeIDTable(useNetworkIDHashes bool) *BlockRuntimeIDTable

NewBlockRuntimeIDTable returns a new BlockRuntimeIDTable. useNetworkIDHashes indicates whether the runtime IDs are the network ID hashes.

func NewBlockRuntimeIDTableFromStates

func NewBlockRuntimeIDTableFromStates(blockStates []define.BlockState, useNetworkIDHashes bool) *BlockRuntimeIDTable

NewBlockRuntimeIDTableFromStates returns a new BlockRuntimeIDTable from the provided block states. The block states must be ordered by their runtime IDs. useNetworkIDHashes indicates whether the runtime IDs are the network ID hashes.

func NewEmptyBlockRuntimeIDTable

func NewEmptyBlockRuntimeIDTable(useNetworkIDHashes bool) *BlockRuntimeIDTable

NewEmptyBlockRuntimeIDTable returns a new empty BlockRuntimeIDTable. useNetworkIDHashes indicates whether the runtime IDs are the network ID hashes.

func (*BlockRuntimeIDTable) AirRuntimeID

func (b *BlockRuntimeIDTable) AirRuntimeID() (runtimeID uint32)

AirRuntimeID returns the runtime ID of the air block.

func (*BlockRuntimeIDTable) FinaliseRegister

func (b *BlockRuntimeIDTable) FinaliseRegister()

FinaliseRegister is called after blocks have finished registering and the palette can be sorted and hashed.

func (*BlockRuntimeIDTable) RegisterCustomBlock

func (b *BlockRuntimeIDTable) RegisterCustomBlock(block define.BlockState) error

RegisterCustomBlock registers a new custom block to the table. The function returns error if the block was already registered. Note that you MUST call FinaliseRegister atfer register all custom blocks.

func (*BlockRuntimeIDTable) RegisterPermutation

func (b *BlockRuntimeIDTable) RegisterPermutation(blockName string, blockVersion int32, stateEnums []StateEnum) error

RegisterMultipleStates registers all block states of a custom block to the table.

stateEnums is a list of state enums that the block can have. Each element means a state key and its possible values.

The function returns error if any of the states was already registered.

Note that you MUST call FinaliseRegister after register all custom blocks.

func (*BlockRuntimeIDTable) RuntimeIDToState

func (b *BlockRuntimeIDTable) RuntimeIDToState(runtimeID uint32) (name string, properties map[string]any, found bool)

RuntimeIDToState converts a runtime ID to a name and its state properties.

func (*BlockRuntimeIDTable) StateToRuntimeID

func (b *BlockRuntimeIDTable) StateToRuntimeID(name string, properties map[string]any) (runtimeID uint32, found bool)

StateToRuntimeID converts a name and its state properties to a runtime ID.

func (*BlockRuntimeIDTable) UseNetworkIDHashes

func (b *BlockRuntimeIDTable) UseNetworkIDHashes() bool

UseNetworkIDHashes returns if the block runtime IDs are using network hashes or not.

type StateEnum

type StateEnum struct {
	StateKeyName   string
	PossibleValues []any
}

StateEnum holds a single block property key and its possible values.

Directories

Path Synopsis
Package intintmap is a fast int64 key -> int64 value map.
Package intintmap is a fast int64 key -> int64 value map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL