Skip to content

Go: Custom dimensions

Functions

AddGeneratedDimension

Go
func AddGeneratedDimension(name, spec string, materials, biomes []string, fill func(*ChunkRequest) bool) (int32, error)

AddGeneratedDimension registers a dimension whose terrain fill writes, and returns its id.

fill runs on the host's chunk worker threads, several at once: it must be safe to run concurrently, give the same answer for the same chunk forever, and call nothing on this package but the request itself. Returning false leaves the chunk to air. materials[0] must be "minecraft:air". The function is kept for the dimension's whole life.

  • Parameters:
    • name : string
    • spec : string
    • materials : []string
    • biomes : []string
    • fill : func(*ChunkRequest) bool
  • Return type: (int32, error)
  • Slots: md_add_dimension_generated

DimensionsAvailable

Go
func DimensionsAvailable() (bool, error)

DimensionsAvailable reports whether this host can register custom dimensions.

AddDimension

Go
func AddDimension(name, spec string) (int32, error)

AddDimension registers a dimension from spec SNBT and returns its id.

  • Parameters:
    • name : string
    • spec : string
  • Return type: (int32, error)
  • Slots: md_add_dimension

DimensionID

Go
func DimensionID(name string) (int32, error)

DimensionID is the id of a registered dimension.

ListDimensions

Go
func ListDimensions() ([]string, error)

ListDimensions lists the registered custom dimensions.

SetDimensionRule

Go
func SetDimensionRule(dim, rule int32, allow bool) error

SetDimensionRule sets one rule, a PIER_DIMRULE_* value, for one dimension.

DimensionRule

Go
func DimensionRule(dim, rule int32) (allow, set bool, err error)

DimensionRule reads one rule; set is false when the dimension follows vanilla for it, which a host older than the rule also answers.

  • Parameters:
    • dim : int32
    • rule : int32
  • Return type: (allow, set bool, err error)
  • Slots: md_get_dimension_rule

ExistingDimensions

Go
func ExistingDimensions() ([]ExistingDimension, error)

ExistingDimensions lists every registered custom dimension.

AddDimensionPack

Go
func AddDimensionPack(name, configPath, specSNBT string) (int32, error)

AddDimensionPack adds a custom dimension whose terrain is a terrain pack: a directory with a config file and a binary built by tools/pier-pack. configPath is relative to the server root, with forward slashes, no .. and not absolute. A refusal is a *PackError.

  • Parameters:
    • name : string
    • configPath : string
    • specSNBT : string
  • Return type: (int32, error)
  • Slots: md_add_dimension_pack

InspectPack

Go
func InspectPack(configPath string) (string, error)

InspectPack reads what a terrain pack asks for, as a JSON document, without registering anything. A refusal is a *PackError.

  • Parameters:
    • configPath : string
  • Return type: (string, error)
  • Slots: md_pack_inspect

RetireDimension

Go
func RetireDimension(name string) (bool, error)

RetireDimension retires a custom dimension: it is dropped from the host's tables and from dimension_config.json, so nothing registers it on the next boot. The chunks it wrote stay. It reports whether one by that name was registered.

ClearDimensionRules

Go
func ClearDimensionRules(dim int32) error

ClearDimensionRules clears every rule of a dimension, for when its world was deleted.

SetDimensionCells

Go
func SetDimensionCells(dimID, cell, gap int32) error

SetDimensionCells gives a generated dimension the cell geometry its confinement rules use: cell is the edge of a cell and gap the space between cells, both in blocks. A cell of 0 removes the geometry.

NewPlotMerge

Go
func NewPlotMerge(x, z int32, north, east, south, west bool) PlotMerge

NewPlotMerge assembles a mask from the four directions in the order north, east, south, west.

  • Parameters:
    • x : int32
    • z : int32
    • north : bool
    • east : bool
    • south : bool
    • west : bool
  • Return type: PlotMerge

SetPlotMerges

Go
func SetPlotMerges(dim int32, merges []PlotMerge) error

SetPlotMerges replaces the merge marks of a dimension as a whole. Only plots that carry a marker need to be listed.

  • Parameters:
    • dim : int32
    • merges : []PlotMerge
  • Return type: error
  • Slots: md_set_plot_merges

PackError

Go
1
2
3
4
type PackError struct {
    Status   int32
    Problems string
}

PackError is the refusal of a terrain pack: the PIER_PACK_* status the host gave and, when it wrote one, its reasons.

PackError.Error

Go
func (e *PackError) Error() string
  • Return type: string

ChunkRequest

Go
1
2
3
4
5
6
type ChunkRequest struct {
    Dim, ChunkX, ChunkZ int32
    MinY, Height        int32
    Materials           []uint16
    Biomes              []uint16
}

ChunkRequest is one chunk a supplied-terrain generator fills. Materials has 256*Height entries indexed (x*16+z)*Height + (y-MinY), and Biomes 256, one per column; both hold indices into the palettes given at registration, and material 0 is air.

ExistingDimension

Go
1
2
3
4
5
type ExistingDimension struct {
    Name string `json:"name"`
    Dim  int32  `json:"dim"`
    SNBT string `json:"snbt"`
}

ExistingDimension is one custom dimension that has been registered.

PlotMerge

Go
1
2
3
4
5
type PlotMerge struct {
    X, Z int32
    // Mask is a bitset: 1 north, 2 east, 4 south, 8 west.
    Mask uint32
}

PlotMerge holds the merge marks of one plot.