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 BlockList ¶
type BlockList []Block
BlockList defines a set of blocks.
func FindInChunk ¶
FindInChunk locates all blocks in the specified chunk, matching the given query.
func FindInRegion ¶
FindInRegion locates all blocks in the specified region, matching the given query.
func FindStrongholds ¶
FindStrongholds finds all strongholds by locating End Portal blocks.
type ExclusionQuery ¶
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 ¶
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 ¶
DistanceTo returns the distance, in blocks, between the two given locations.
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 ¶
NewExclusionQuery creates a new exclusion query.
func NewInclusionQuery ¶
NewInclusionQuery creates a new inclusion query.
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 ¶
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.