Documentation ¶
Index ¶
- Variables
- func LoadBlocks()
- func Validate(v Version)
- type BoundingBox
- type BurgerData
- type ChunkPos
- type Color
- type Face
- type Kind
- type Pos
- func (p Pos) Add(x, y, z int32) Pos
- func (p Pos) AddX(amount int32) Pos
- func (p Pos) AddY(amount int32) Pos
- func (p Pos) AddZ(amount int32) Pos
- func (p Pos) AsLong() uint64
- func (p Pos) AsOldLong() uint64
- func (p Pos) ChunkPos() ChunkPos
- func (p Pos) ChunkRelPos() Pos
- func (p Pos) ChunkRelX() int32
- func (p Pos) ChunkRelY() int32
- func (p Pos) ChunkRelZ() int32
- func (p Pos) ChunkX() int32
- func (p Pos) ChunkY() int32
- func (p Pos) ChunkZ() int32
- func (p Pos) Distance(o Pos) float32
- func (p Pos) InChunk(c ChunkPos) bool
- func (p Pos) OffsetFace(face Face) Pos
- func (p Pos) WithX(x int32) Pos
- func (p Pos) WithY(y int32) Pos
- func (p Pos) WithZ(z int32) Pos
- type Property
- type Register
- type RegisterBase
- func (r *RegisterBase) AddProperty(p *Property)
- func (r *RegisterBase) BoundingBox(t *Type) BoundingBox
- func (r *RegisterBase) Color(bs *State) Color
- func (r *RegisterBase) DefaultProperties() map[string]string
- func (r *RegisterBase) Drops(w World, pos Pos) (string, int)
- func (r *RegisterBase) GetSettings() Settings
- func (r *RegisterBase) Name() string
- func (r *RegisterBase) Properties() []*Property
- func (r *RegisterBase) SetDefaultProperty(key, val string)
- func (r *RegisterBase) SetName(name string)
- func (r *RegisterBase) Settings(set Settings)
- func (r *RegisterBase) Sound(bs *State) string
- func (r *RegisterBase) Transparent(t *Type) bool
- func (r *RegisterBase) Versions() map[Version]map[string]uint32
- type Registry
- type Settings
- type State
- func (s *State) AllProperties() map[string]map[string]struct{}
- func (s *State) Pos() Pos
- func (s *State) Properties() map[string]string
- func (s *State) SetFromCommandString(name string)
- func (s *State) SetProperties(new_props map[string]string) error
- func (s *State) SetProperty(key string, val string) error
- func (s *State) SetType(new_type *Type) error
- func (s *State) State() uint32
- func (s *State) StateVersion(version Version) uint32
- func (s *State) Type() *Type
- func (s *State) X() int32
- func (s *State) Y() int32
- func (s *State) Z() int32
- type Tool
- type Type
- func (t *Type) BoundingBox() BoundingBox
- func (t *Type) CommandString() string
- func (t *Type) HasProperty(name string) bool
- func (t *Type) Kind() *Kind
- func (t *Type) Name() string
- func (t *Type) PossiblePropertyValues(name string) []string
- func (t *Type) PropString() string
- func (t *Type) Properties() map[string]string
- func (t *Type) Property(name string) string
- func (t *Type) State() uint32
- func (t *Type) StateVersion(version Version) uint32
- func (t *Type) String() string
- func (t *Type) Transparent() bool
- type Version
- type VersionRegistry
- func (r *VersionRegistry) Add(name string, item Register)
- func (r *VersionRegistry) Generate() (map[string]*Kind, []*Type)
- func (r *VersionRegistry) Get(name string) (item Register)
- func (r *VersionRegistry) GetOk(name string) (item Register, ok bool)
- func (r *VersionRegistry) InsertAfter(name, new_name string, item Register)
- func (r *VersionRegistry) List() []Register
- func (r *VersionRegistry) MoveAfter(name, new_name string)
- func (r *VersionRegistry) Remove(name string)
- func (r *VersionRegistry) Set(name string, item Register)
- func (r *VersionRegistry) String() string
- func (r *VersionRegistry) Validate() error
- type VersionsMap
- type World
Constants ¶
This section is empty.
Variables ¶
var BoundingBox_NONE = BoundingBox{
-1, -1, -1,
-1, -1, -1,
}
This is a shorthand for BoundBox{-1, -1, -1, -1, -1, -1} (an empty bounding box).
Functions ¶
func LoadBlocks ¶
func LoadBlocks()
This loads all blocks in the game, using the registry from CreateRegistry(). Once called, you cannot change the blocks anymore.
Types ¶
type BoundingBox ¶
This is the bounding box of the block. If all the values are 0, then this is a full block (same as 0, 0, 0, 1, 1, 1). If all values are -1, then this is an empty box. If any values are > 1 or < 0, and it's not an empty box, this is an invalid box.
type BurgerData ¶
type BurgerData struct { // List of all blocks in the game Blocks struct { // Alphebetical list of blocks. Most useful option, as it gives all blockstate ids. BlockList map[string]struct { // Display name DisplayName string `json:"display_name"` // Block name Name string `json:"text_id"` // Hardness Hardness float32 `json:"hardness"` // Resistance Resistance float32 `json:"resistance"` // Min blockstate id MinState int32 `json:"min_state_id"` // Max blockstate id MaxState int32 `json:"max_state_id"` // max - min + 1 NumStates int32 `json:"num_states"` // List of properties Properties []struct { // Property name Name string `json:"name"` // Property type. If it is int, then the // possible values are just 0-num_values. // If it is bool, then the possible values // are true, false. If it is anything else, // then the possible values are listed under // Values. Type string `json:"type"` // Number of possible values this property can have. NumValues int32 `json:"num_values"` // List of possible values. May be empty, // depending on Type. Values []string `json:"values"` } `json:"states"` } `json:"block"` } `json:"blocks"` }
type ChunkPos ¶
type ChunkPos struct {
X, Z int32
}
This is a chunk position. It is used to refer to chunk columns within a world. It is also used as a key for chunks within a world
func (ChunkPos) ForEachColumn ¶
This calls f for every column within the chunk. The position passed to f has X and Z set, but Y is 0. If f returns false, then the loop stops.
type Color ¶
type Color int
const ( Color_AIR Color = iota Color_GRASS Color_SAND Color_WOOL Color_TNT Color_ICE Color_IRON Color_FOLIAGE Color_SNOW Color_CLAY Color_DIRT Color_STONE Color_WATER Color_WOOD Color_QUARTZ Color_ORANGE Color_MAGENTA Color_LIGHT_BLUE Color_YELLOW Color_LIME Color_PINK Color_GRAY Color_LIGHT_GRAY Color_CYAN Color_PURPLE Color_BLUE Color_BROWN Color_GREEN Color_RED Color_BLACK Color_GOLD Color_DIAMOND Color_LAPIS Color_EMERALD Color_OBSIDIAN Color_NETHERRACK Color_WHITE_TERRACOTTA Color_ORANGE_TERRACOTTA Color_MAGENTA_TERRACOTTA Color_LIGHT_BLUE_TERRACOTTA Color_YELLOW_TERRACOTTA Color_LIME_TERRACOTTA Color_PINK_TERRACOTTA Color_GRAY_TERRACOTTA Color_LIGHT_GRAY_TERRACOTTA Color_CYAN_TERRACOTTA Color_PURPLE_TERRACOTTA Color_BLUE_TERRACOTTA Color_BROWN_TERRACOTTA Color_GREEN_TERRACOTTA Color_RED_TERRACOTTA Color_BLACK_TERRACOTTA Color_CRIMSON_NYLIUM Color_CRIMSON_STEM Color_CRIMSON_HYPHAE Color_WARPED_NYLIUM Color_WARPED_STEM Color_WARPED_HYPHAE Color_WARPED_WART )
type Face ¶
type Face int
func FaceFromString ¶
This gets the block face according to a string. Will return FACE_BOTTOM if the string is invalid.
func (Face) Invert ¶
The returns the opposite of the face. For example, bottom returns top. This returns the bottom face if the face is invalid.
func (Face) Left ¶
This gets the face that is one to the left of the given face. For example, north returns west. Bottom and top return themselves.
func (Face) Offset ¶
This returns the block offset of the face. For example, the bottom face returns 0, -1, 0. This returns 0, 0, 0 if the face is invalid.
func (Face) Right ¶
This gets the face that is one to the right of the given face. For example, north returns east. Bottom and top return themselves.
type Kind ¶
type Kind struct {
// contains filtered or unexported fields
}
singleton struct for each block type (not each block state)
func GetKind ¶
Returns a kind from a name. Will return nil if the block does not exist. Will panic if LoadBlocks() has not been called yet. If you need the info about another block during load, call registry.Get().
func (*Kind) AllProperties ¶
This returns all of the possible properties for the type. This does not return a copy, so editing this map will break things in terrible and unexpected ways.
func (*Kind) DefaultProperties ¶
This returns the default properties for the kind. This will copy all the properties, but because properties is usually a pretty short list, this is still fast.
func (*Kind) DefaultType ¶
This returns the default type of the kind. If the kind is nil, this will return air.
func (*Kind) Name ¶
Returns the name of the kind. This will call the registry's Name() function, which should always return the same value.
type Pos ¶
type Pos struct {
X, Y, Z int32
}
Block position. This should be used any time a block position in a world is needed. This only stores X, Y, Z, so you will need something else if you want to store the world along with a position.
func PosFromLong ¶
Converts a long into 3 ints, according to minecraft's position type. This is in the order X, Z, then Y. For versions 1.14+.
func PosFromOldLong ¶
Converts a long into 3 ints, according to minecraft's old position type. This is in the order X, Y, then Z. For versions 1.8 - 1.13. NOTE: During server packet handling, all longs will be in the new format. The proxy translates them correctly. So, this function should only be used on the proxy.
func (Pos) Add ¶
This adds the coorsponding x, y and z values to pos.X, pos.Y, and pos.Z. This new value is returned, and the original is not changed.
func (Pos) AddX ¶
Adds returns the current position with pos.X increased by x. Does not modify the original pos.
func (Pos) AddY ¶
Adds returns the current position with pos.Y increased by y. Does not modify the original pos.
func (Pos) AddZ ¶
Adds returns the current position with pos.Z increased by z. Does not modify the original pos.
func (Pos) ChunkRelPos ¶
This returns a new position, where the X and Z are relative to the chunk (between 0 and 15). Y is unchanged.
func (Pos) ChunkRelX ¶
This returns the block position relative to the chunk it's in. This will always be between 0 and 15.
func (Pos) ChunkRelY ¶
This returns the block position relative to the chunk it's in. This will always be between 0 and 15. NOTE: This function probably isn't very useful. It is only used internally when accessing individual chunk sections, which is all wrapped within world/chunk.Chunk. This function is not used in ChunkRelPos(), as typically this is not what you want.
func (Pos) ChunkRelZ ¶
This returns the block position relative to the chunk it's in. This will always be between 0 and 15.
func (Pos) ChunkX ¶
This returns the chunk that this block position is in. It just divides X by 16, but rounds down.
func (Pos) ChunkY ¶
This returns the chunk that this block position is in. It just divides Y by 16, but rounds down. Since chunks are usually accessed in columns, this function probably won't be very useful. ChunkPos() does not call this function, and you probably shouldn't either. It is only used internally within world/chunk.Chunk, when accessing chunk sections.
func (Pos) ChunkZ ¶
This returns the chunk that this block position is in. It just divides Z by 16, but rounds down.
func (Pos) OffsetFace ¶
This returns a new block position, which is offset one block in the direction of face.
func (Pos) WithX ¶
This copies p, sets X to x, then returns the copy. If you want to change only the X of a position, you can do this in the arguments of a function.
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
This is a property. Each blockstate is a possible combination of properties. So when all of the blocks are compiled into a blockstate map, all possible combinations of properties are given a unique id.
Each property can have one of three types: enum, int or bool. Read more about this in the NewProperty function.
func NewProperty ¶
This creates a new property. The first paramater must be a unique name for this property. For the next paramaters, the type infers which kind of property you would like.
In order to make this an enum type, just pass in two or more strings. The default value will be the first string passed.
In order to make this an int, just pass in an int type, which is the number of ints you want. For example, the redstone block uses an int for it's 'power' property. To create that, you would pass in 16. The default will be 0.
In order to create a bool type, pass in true or false. The value you pass in will be the default.
type Register ¶
type Register interface { Name() string SetName(name string) Properties() []*Property DefaultProperties() map[string]string Settings(set Settings) GetSettings() Settings Color(bs *State) Color Sound(bs *State) string BoundingBox(t *Type) BoundingBox Transparent(t *Type) bool Versions() map[Version]map[string]uint32 Drops(w World, pos Pos) (string, int) }
type RegisterBase ¶
type RegisterBase struct { V1_8_ID int // contains filtered or unexported fields }
Users create these, and pass them into Register() Once all blocks have been registered, these are all converted into *Kinds
func NewRegister ¶
func NewRegister() *RegisterBase
func (*RegisterBase) AddProperty ¶
func (r *RegisterBase) AddProperty(p *Property)
func (*RegisterBase) BoundingBox ¶
func (r *RegisterBase) BoundingBox(t *Type) BoundingBox
func (*RegisterBase) Color ¶
func (r *RegisterBase) Color(bs *State) Color
func (*RegisterBase) DefaultProperties ¶
func (r *RegisterBase) DefaultProperties() map[string]string
func (*RegisterBase) GetSettings ¶
func (r *RegisterBase) GetSettings() Settings
DO NOT USE THIS. This should only when you need to do something like copy all of the settings for a block (example: stairs copying all settings from planks). Otherwise, this should not be used, as the other specific methods can be overriten by other blocks. For example, a log changes color when it is place at a different angle. The settings is never updated, but the result from Color() is updated.
func (*RegisterBase) Name ¶
func (r *RegisterBase) Name() string
func (*RegisterBase) Properties ¶
func (r *RegisterBase) Properties() []*Property
func (*RegisterBase) SetDefaultProperty ¶
func (r *RegisterBase) SetDefaultProperty(key, val string)
func (*RegisterBase) SetName ¶
func (r *RegisterBase) SetName(name string)
func (*RegisterBase) Settings ¶
func (r *RegisterBase) Settings(set Settings)
Sets the settings for a block. Will panic if called twice.
func (*RegisterBase) Sound ¶
func (r *RegisterBase) Sound(bs *State) string
func (*RegisterBase) Transparent ¶
func (r *RegisterBase) Transparent(t *Type) bool
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
This is a global block registry. It is a small wrapper over VersionRegistry, which allows a registry to be copied to be used for a certain version.
func CreateRegistry ¶
func CreateRegistry() *Registry
This sets the main block registry to a new registry. If there is already a registry, it will be overriden.
func (*Registry) Add ¶
This adds a new block to the registry. The version should be a version >= 1.13. The order of Add calls only matters for the order of the block data. If you add a block to 1.14, then another to 1.13, the one from 1.13 will carry over to 1.14.
func (*Registry) Generate ¶
Generates a kinds and types map. This is what is used to convert all registered blocks into a usable blockstate map.
func (*Registry) Get ¶
This gets an item from the registry. The version can be any valid version, and this will act the same for all versions, with one caveat: if you call Update(), then this will return different items for different versions. Other than that, the version does not matter for this call.
type Settings ¶
type Settings struct { Tool Tool Hardness, Resistance float64 Color Color Sound string Versions VersionsMap BoundingBox BoundingBox Transparent bool }
This is basically a large struct which is used to declare what settings a block has. These settings cover all attributes that all blocks have: Hitbox, Properties, Sound, Color, Tool, etc.
type State ¶
type State struct {
// contains filtered or unexported fields
}
one for each block in the world
func NewStateFromID ¶
func (*State) AllProperties ¶
func (*State) Properties ¶
func (*State) SetFromCommandString ¶
the format minecraft:chest[facing=west]
func (*State) StateVersion ¶
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
One for each possible block state
func Air ¶
func Air() *Type
The default block in the game. The type returned can be compared against any block type to check if it's air.
func TypeFromID ¶
func TypeFromIDVersion ¶
func (*Type) BoundingBox ¶
func (t *Type) BoundingBox() BoundingBox
Returns the bounding box of the block. If this block does not have a bounding box, this will return BoundingBox_NONE.
func (*Type) CommandString ¶
func (*Type) HasProperty ¶
This returns true if the property exists, and false if otherwise.
func (*Type) PossiblePropertyValues ¶
This returns a list of all possible values for one property key.
func (*Type) PropString ¶
This generates a string in the format "minecraft:log axis=x". Properties will always be in alphabetical order. Used internally for property to type lookups.
func (*Type) Properties ¶
This copies all properties from type into a new map. This is slow, and probably shouldn't be used very much.
func (*Type) Property ¶
This gets the property for the given name. If the property does not exist, it will return an empty string.
func (*Type) StateVersion ¶
func (*Type) Transparent ¶
Returns true if this block is transparent to block light.
type Version ¶
type Version int32
This is a block versions. This is probably just an iota for every major version in the game. This allows older versions of blocks to be packed into an array, instead of a map to protocol versions.
type VersionRegistry ¶
type VersionRegistry struct {
// contains filtered or unexported fields
}
func NewVersionRegistryFrom ¶
func NewVersionRegistryFrom(other *VersionRegistry) *VersionRegistry
This creates a registry for a single version. If other is non-nil, then any actions made to other will also be applied to this version. So, if you have a 1.13 registry, then you can create a NewVersionRegistryFrom(v1.13) to create a 1.14 registry. Now, you can register things to the 1.13 registry, and they will be added to the 1.14 registry as well. Also, multiple registries may be based off of one version.
func (*VersionRegistry) Add ¶
func (r *VersionRegistry) Add(name string, item Register)
This registers a new item. id should be a constant, defined in user-space code (probably with iota). id is not used for sorting, the order of items depends on the order that Add is called. So, for packets, ID would be the grpc packet id, which doesn't need to be the same as any minecraft packet id. If id is -1, then this is treated as a placeholder, and nil will be inserted into the internal array.
func (*VersionRegistry) Get ¶
func (r *VersionRegistry) Get(name string) (item Register)
This gets the item at the id, and panics if the id is not within the registry.
func (*VersionRegistry) GetOk ¶
func (r *VersionRegistry) GetOk(name string) (item Register, ok bool)
This gets the item at the id, and returns false if the id is not within the registry. This does not return the internal index, as that value has no meaning.
func (*VersionRegistry) InsertAfter ¶
func (r *VersionRegistry) InsertAfter(name, new_name string, item Register)
This inserts item after name in the list. The item's name will be new_name.
func (*VersionRegistry) List ¶
func (r *VersionRegistry) List() []Register
This lists all elements added to the registry, in the order that they were addded.
func (*VersionRegistry) MoveAfter ¶
func (r *VersionRegistry) MoveAfter(name, new_name string)
This moves the item at name after new_name in the list.
func (*VersionRegistry) Remove ¶
func (r *VersionRegistry) Remove(name string)
Will remove an item from the registry. This will decrease all items that have a greater index down by one.
func (*VersionRegistry) Set ¶
func (r *VersionRegistry) Set(name string, item Register)
This overrides an item. Useful for if a packet slightly changes between versions.
The old id is infered, since this should only be used to override packets. If you call this function, and id is not in the registry, it will panic. To add a new item, use Add or Insert instead.
func (*VersionRegistry) String ¶
func (r *VersionRegistry) String() string
func (*VersionRegistry) Validate ¶
func (r *VersionRegistry) Validate() error