mcra

package
v0.0.0-...-f974f5f Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: BSD-1-Clause Imports: 4 Imported by: 0

README

mcra

Package mcra defines an API to query Minecraft world data. Specifically intended to tally and locate sets of specific resources.

This code has been run on a few really old worlds, as well as a brand new one generated in 1.8.3 and found to be working in all of them.

It should be noted that no attempts have been made at speed optimization' as far as block search performance goes. Specifically when searching all regions in a world, things can get rather slow.

The library operates directly on the world's region data. Nothing is cached or indexed in any way.

Usage

Loading a world and a specific region:

world, err := mcra.Open(WorldPath)
if err != nil {
	log.Fatal(err)
}

region, err = world.Region(mcra.DimensionOverworld, -1, 0)
defer region.Close()

Finding blocks in a region:

// Find only sand and sandstone blocks.
result := FindInRegion(region, NewInclusionQuery(
	item.Sand,
	item.Sandstone,
))

...

// Find everything, except Air and bedrock.
result := FindInRegion(region, NewExclusionQuery(
	item.Air,
	item.Bedrock,
))

// Find all redstone ore within a radius from a given point.
result := FindInRegion(region, NewRadiusQuery(
	Location{...},
	100,
	item.RedstoneOre,
	item.RedstoneOreGlowing,
))

Tallying redstone and diamond ores in a region:

tally := TallyInRegion(
	region,
	item.RedstoneOre,
	item.RedstoneOreGlowing,
	item.DiamondOre,
)

for k, v := range tally {
	fmt.Println(k, v)
}

// yields:
//
//     RedstoneOre 108
//     DiamondOre 25

Tally all resources in a region:

tally := TallyInRegion(region)
...

// yields:
//
//     Air 65184
//     Sandstone 29709
//     Sand 13629
//     Granite 3655
//     CoalOre 832
//     Andesite 3975
//     DiamondOre 25
//     DeadShrub 3
//     Bedrock 16043
//     LavaNoSpread 1200
//     Dirt 1765
//     IronOre 512
//     Grass 274
//     Diorite 3183
//     GoldOre 35
//     TallGrass 8
//     Stone 289207
//     WaterNoSpread 44
//     RedstoneOre 108
//     Gravel 671
//     LapisLazuliOre 16
//     Cactus 2

See it at work

This is a screenshot of a new (1.8.3) world in Vanilla MC. The output in the console shows the locations of diamond ores in region -1, 0 for a world with seed 2856811980450068479. This is the world data in the testdata/newworld directory.

screenshot

Documentation

Overview

Package mcra defines an API to query Minecraft world data. Specifically intended to tally and locate sets of specific resources.

This code has been run on a few really old worlds, as well as a brand new one generated in 1.8.3 and found to be working in all of them.

It should be noted that no attempts have been made at speed optimization' as far as block search performance goes. Specifically when searching all regions in a world, things can get rather slow.

The library operates directly on the world's region data. Nothing is cached or indexed in any way.

Usage example

Loading a world and a specific region:

world, err := mcra.Open(WorldPath)
if err != nil {
	log.Fatal(err)
}

region, err = world.Region(mcra.DimensionOverworld, -1, 0)
defer region.Close()

Finding blocks in a region:

// Find only sand and sandstone blocks.
result := FindInRegion(region, NewInclusionQuery(
	item.Sand,
	item.Sandstone,
))

...

// Find everything, except Air and bedrock.
result := FindInRegion(region, NewExclusionQuery(
	item.Air,
	item.Bedrock,
))

// Find all redstone ore within a radius from a given point.
result := FindInRegion(region, NewRadiusQuery(
	Location{...},
	100,
	item.RedstoneOre,
	item.RedstoneOreGlowing,
))

Tallying redstone and diamond ores in a region:

tally := TallyInRegion(
	region,
	item.RedstoneOre,
	item.RedstoneOreGlowing,
	item.DiamondOre,
)

for k, v := range tally {
	fmt.Println(k, v)
}

// yields:
//
//     RedstoneOre 108
//     DiamondOre 25

Tally all resources in a region:

tally := TallyInRegion(region)
...

// yields:
//
//     Air 65184
//     Sandstone 29709
//     Sand 13629
//     Granite 3655
//     CoalOre 832
//     Andesite 3975
//     DiamondOre 25
//     DeadShrub 3
//     Bedrock 16043
//     LavaNoSpread 1200
//     Dirt 1765
//     IronOre 512
//     Grass 274
//     Diorite 3183
//     GoldOre 35
//     TallGrass 8
//     Stone 289207
//     WaterNoSpread 44
//     RedstoneOre 108
//     Gravel 671
//     LapisLazuliOre 16
//     Cactus 2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindDungeons

func FindDungeons(r *anvil.Region) []*anvil.TileEntity

FindDungeons finds all dungeons by locating and returning all mob spawners.

Types

type Block

type Block struct {
	Id item.Id // Type of block at this location.
	Location
}

Block defines a block location in region, chunk and block coordinates.

func (Block) String

func (b Block) String() string

type BlockList

type BlockList []Block

BlockList defines a set of blocks.

func FindInChunk

func FindInChunk(c *anvil.Chunk, q Query) BlockList

FindInChunk locates all blocks in the specified chunk, matching the given query.

func FindInRegion

func FindInRegion(r *anvil.Region, q Query) BlockList

FindInRegion locates all blocks in the specified region, matching the given query.

func FindStrongholds

func FindStrongholds(r *anvil.Region) BlockList

FindStrongholds finds all strongholds by locating End Portal blocks.

func (BlockList) Len

func (s BlockList) Len() int

type ExclusionQuery

type ExclusionQuery []item.Id

ExclusionQuery defines an exclusion search. This means that the result set will contain only item types NOT included in this query.

func (ExclusionQuery) IsTarget

func (q ExclusionQuery) IsTarget(b Block) bool

IsTarget returns true if the given block should be included in the result set.

type InclusionQuery

type InclusionQuery []item.Id

InclusionQuery defines an inclusion search. This means that the result set will contain only item types included in this query.

func (InclusionQuery) IsTarget

func (q InclusionQuery) IsTarget(b Block) bool

IsTarget returns true if the given block should be included in the result set.

type Location

type Location struct {
	RX int8  // Region X.
	RZ int8  // Region Z.
	CX int8  // Chunk X in region.
	CZ int8  // Chunk Z in region.
	BX uint8 // Block X in chunk.
	BY uint8 // Block Y in chunk.
	BZ uint8 // Block Z in chunk.
}

Location defines a specific block location in a world.

func (Location) DistanceTo

func (l Location) DistanceTo(b Location) uint

DistanceTo returns the distance, in blocks, between the two given locations.

func (Location) String

func (l Location) String() string

type Query

type Query interface {
	// IsTarget returns true if the given block should be
	// included in the result set.
	IsTarget(Block) bool
}

Query defines a generic search query.

func NewExclusionQuery

func NewExclusionQuery(items ...item.Id) Query

NewExclusionQuery creates a new exclusion query.

func NewInclusionQuery

func NewInclusionQuery(items ...item.Id) Query

NewInclusionQuery creates a new inclusion query.

func NewRadiusQuery

func NewRadiusQuery(origin Location, radius uint, items ...item.Id) Query

NewRadiusQuery creates a new distance query for the given values, Origin is the point from which

type RadiusQuery

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

RadiusQuery finds all listed items within a given radius from a specific world location.

func (*RadiusQuery) IsTarget

func (q *RadiusQuery) IsTarget(b Block) bool

IsTarget returns true if the given block should be included in the result set.

type TallyResult

type TallyResult map[item.Id]uint64

TallyResult defines a table of unique item ids and the number of times they occur in a specific region or chunk.

func TallyInChunk

func TallyInChunk(c *anvil.Chunk, items ...item.Id) TallyResult

TallyInChunk counts the number of times each of the given items occurs in the specified chunk.

If the given item set is empty, all blocks will be counted.

func TallyInRegion

func TallyInRegion(r *anvil.Region, items ...item.Id) TallyResult

TallyInRegion counts the number of times each of the given items occurs in the specified region.

If the given item set is empty, all blocks will be counted.

Directories

Path Synopsis
Package recipe defines an interface and listing of all known Minecraft recipes and facilities to create recipe trees.
Package recipe defines an interface and listing of all known Minecraft recipes and facilities to create recipe trees.

Jump to

Keyboard shortcuts

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