Documentation ¶
Index ¶
- Constants
- func ParseVarInt(data []byte) (int32, int32)
- func ReadVarInt(r io.Reader) (int32, int32)
- func ToVarInt(value int32) []byte
- type Buffer
- func (b *Buffer) GetData() []byte
- func (b *Buffer) GetRawData() []byte
- func (b *Buffer) Length() int32
- func (b *Buffer) WriteBool(value bool)
- func (b *Buffer) WriteByte(value byte)
- func (b *Buffer) WriteByteArray(value []byte)
- func (b *Buffer) WriteDouble(value float64)
- func (b *Buffer) WriteFloat(value float32)
- func (b *Buffer) WriteInt(value int32)
- func (b *Buffer) WriteIntArray(value []int32)
- func (b *Buffer) WriteLittleEndianShort(value uint16)
- func (b *Buffer) WriteLong(value uint64)
- func (b *Buffer) WriteLongArray(value []uint64)
- func (b *Buffer) WriteNullString(value string)
- func (b *Buffer) WriteOldPosition(pos block.Pos)
- func (b *Buffer) WritePosition(pos block.Pos)
- func (b *Buffer) WriteShort(value uint16)
- func (b *Buffer) WriteString(value string)
- func (b *Buffer) WriteUUID(value UUID)
- func (b *Buffer) WriteVarInt(value int32)
- type Chat
- func (c *Chat) AddLink(text, address string)
- func (c *Chat) AddLinkColor(text, color, address string)
- func (c *Chat) AddSection(text string)
- func (c *Chat) AddSectionColor(text string, color string)
- func (c *Chat) AddSectionFormatted(text, color string, bold, italic, underlined bool)
- func (c *Chat) JSONObject() interface{}
- func (c *Chat) String() string
- func (c *Chat) ToFormatCodes() string
- func (c *Chat) ToJSON() string
- type FastRand
- type LayeredNoise
- type Noise
- type NoiseSampler
- type RandomGrid
- type RandomGridPoint
- type UUID
- type Voronoi
- type WarpedVoronoi
Constants ¶
const ( PERLIN_SIZE = 0x10 PERLIN_REPEAT_SIZE = PERLIN_SIZE * PERLIN_SIZE )
Variables ¶
This section is empty.
Functions ¶
func ParseVarInt ¶
Will parse a varint. Returns the number, and the number of bytes that it read.
func ReadVarInt ¶
Will parse a varint from the given reader. If the reader returns an error, this will return -1, -1. Otherwise, this will return the number, and the number of bytes read.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
This is a custom buffer, optimized for minecraft packets. This is used whenever the proxy sends a packet.
func NewBufferFromSlice ¶
This creates a new buffer, which points to the given slice. If the slice is big enough, the buffer will not allocate any more memory. It will just start writing into the slice at the given index.
func (*Buffer) GetData ¶
This returns a slice which goes from the very start of the buffer passed in, to the most recently written byte. So if you started writing at index 10, and wrote 5 bytes, this would return a slice that is 15 bytes long.
func (*Buffer) GetRawData ¶
This just gives you the buffer that was originally passed into NewBufferFromSlice, or the buffer that it created in NewBuffer().
func (*Buffer) Length ¶
Returns the length of the buffer. If the buffer started being written at index 10, and you wrote 5 bytes, this would return 15.
func (*Buffer) WriteBool ¶
Writes a bool into the buffer. Will write 0x01 if the bool is true, and 0x00 if it was false.
func (*Buffer) WriteByte ¶
This writes a single byte into the buffer. All other functions that write a single byte call this one. This will either overwrite a single byte in the internal slice, or append a single byte.
func (*Buffer) WriteByteArray ¶
This writes a byte array into the buffer. All other functions that write multiple bytes call this one. If there is enough space in the internal buffer, then it will just copy the values passed in. If there is some space, but not enough for the whole array, it will copy the first section, then append the second section. Otherwise, it will just append the slice passed in. You can see examples of this in buffer_test.go.
func (*Buffer) WriteDouble ¶
This writes a double, encoded in IEEE 754 binary format.
func (*Buffer) WriteFloat ¶
This writes a float, encoded in IEEE 754 binary format.
func (*Buffer) WriteIntArray ¶
This writes an array of ints.
func (*Buffer) WriteLittleEndianShort ¶
This writes a short, encoded in little endian.
func (*Buffer) WriteLongArray ¶
This writes an array of longs.
func (*Buffer) WriteNullString ¶
This writes a null terminated string.
func (*Buffer) WriteOldPosition ¶
This writes a minecraft block position, for versions before 1.14. This is a long, where 3 values are encoded. It starts with the x value, encoded as a 26 bit integer, followed by the y value, which is a 12 bit integer, followed by the z value, which is a 26 bit integer.
func (*Buffer) WritePosition ¶
This writes a minecraft block position. This is a long, where 3 values are encoded. It starts with the x value, encoded as a 26 bit integer, followed by the z value, which is a 26 bit integer. followed by the y value, which is a 12 bit integer,
func (*Buffer) WriteShort ¶
This writes a short, encoded in big endian.
func (*Buffer) WriteString ¶
This writes a length prefixed string.
func (*Buffer) WriteVarInt ¶
This writes a varint, according to minecraft's format. This means that the number of bytes it writes can change, and it can be anywhere between 1 and 5 bytes. All negative numbers are encoded in 5 bytes, so it is still useful to be able to write 4 byte ints.
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
func NewChatFromString ¶
func NewChatFromStringColor ¶
func (*Chat) AddLinkColor ¶
func (*Chat) AddSection ¶
func (*Chat) AddSectionColor ¶
func (*Chat) AddSectionFormatted ¶
func (*Chat) JSONObject ¶
func (c *Chat) JSONObject() interface{}
This returns an object that can be passed into json.Marshal, to produce a chat message.
func (*Chat) ToFormatCodes ¶
This returns the chat messages, formatted using the legacy color codes. This format is more compact, but is deprecated (even though it still works after years).
type FastRand ¶
type FastRand struct {
// contains filtered or unexported fields
}
This is an implementation of wyhash64. It uses a uint64 as it's state, and will use math.bits to perform 128 bit integer multiplication. After benchmarking this, it appears to be ~4 times faster than math/rand.
func NewFastRand ¶
Creates a new FastRand random number generators, and seeds it with the given seed.
type LayeredNoise ¶
type LayeredNoise struct {
// contains filtered or unexported fields
}
This is a multi octave noise generator.
func NewLayeredNoise ¶
func NewLayeredNoise(source rand.Source, octaves int) *LayeredNoise
func (*LayeredNoise) Sample ¶
func (l *LayeredNoise) Sample(x, y float64) float64
Will always return a value between -1 and 1
type Noise ¶
type Noise struct {
// contains filtered or unexported fields
}
This is a perlin noise generator
type NoiseSampler ¶
type NoiseSampler interface { // This should sample a noise or layered noise map. Sample(x, y float64) float64 }
Noise sampler interface.
type RandomGrid ¶
type RandomGrid struct {
// contains filtered or unexported fields
}
func NewRandomGrid ¶
func NewRandomGrid(source rand.Source, dist int, min_dist float32) *RandomGrid
This creates a new random point grid. A random point grid is a grid where every cell (usually) has a point in it. Dist is the size of each grid cell, and min_dist is the minimum required distance between points. If min_dist is too large, then more cells will no longer have points. Each time a cell needs a point, it will try to generate one 10 times, before giving up and leaving the point empty.
func (*RandomGrid) ClosestPoint ¶
func (r *RandomGrid) ClosestPoint(x, y int) (ret RandomGridPoint)
func (*RandomGrid) ContainsPoint ¶
func (r *RandomGrid) ContainsPoint(x, y int) bool
x and y are absolute coordinates, which corrospond to a point in the grid. If the grid dist is 4, then x and y should be divided by 4 to find the actual square that they are searching. This returns true if the point in that square lies within the smaller square coordinates that were passed in.
This is used in terrain generation, by passing in absolute block coordinates. If the function returns true, a tree is placed at that position.
func (*RandomGrid) PointsInArea ¶
func (r *RandomGrid) PointsInArea(x1, y1, x2, y2 int) []RandomGridPoint
This returns a list of absolute coordinates, which are all points that lie within the given rectangle. The points are in the same coordinate space as the coordinates passed into ContainsPoint
type RandomGridPoint ¶
This is a point in absolute coordinates
type UUID ¶
type UUID [16]byte
This is a UUID, used for player account ids. This is passed around by value in most situations. Internally, this is a big endian array of 16 bytes.
func NewUUIDFromBytes ¶
Creates a new UUID from a byte array.
func NewUUIDFromProto ¶
Creates a new UUID from a UUID protobuf. Used in the server when decoding the UUID sent from the proxy.
func NewUUIDFromRand ¶
func NewUUIDFromRand() UUID
Creates a UUID by reading 16 bytes from math/rand. Use NewUUIDFromReader if you need crypto/rand.
func NewUUIDFromReader ¶
Creates a UUID by reading 16 bytes from the given reader.
func NewUUIDFromString ¶
Creates a UUID from a hex string. Will panic if the string is not 32 characters. (Does not work with dashed UUIDS)
func (UUID) ToDashedString ¶
Returns the hex string of the UUID, with dashes inserted.
type Voronoi ¶
type Voronoi struct { // Point grid for the voronoi map. *RandomGrid }
This is a small layer ontop of a RandomGrid.
func NewVoronoi ¶
Creates an empty voronoi map.
type WarpedVoronoi ¶
type WarpedVoronoi struct { // Underlying voronoi map *Voronoi // contains filtered or unexported fields }
This adds two noise maps to a voronoi map, which distort it in the x and y axis.
func NewWarpedVoronoi ¶
func NewWarpedVoronoi(source rand.Source, scale int, noise_strength float64) *WarpedVoronoi
Creates an empty voronoi map.
func (*WarpedVoronoi) Get ¶
func (v *WarpedVoronoi) Get(x, y int) int
This returns a unique id for each voronoi section.