add types
parent
f37669a011
commit
15cc54fd68
|
@ -3,34 +3,25 @@ package commands
|
|||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"minetest_client/types"
|
||||
)
|
||||
|
||||
type BlockPos struct {
|
||||
PosX int16
|
||||
PosY int16
|
||||
PosZ int16
|
||||
}
|
||||
|
||||
func (bp BlockPos) String() string {
|
||||
return fmt.Sprintf("{Blockpos %d/%d/%d}", bp.PosX, bp.PosY, bp.PosZ)
|
||||
}
|
||||
|
||||
type ClientGotBlocks struct {
|
||||
Blocks []BlockPos
|
||||
Blocks []types.BlockPos
|
||||
}
|
||||
|
||||
func NewClientGotBlocks() *ClientGotBlocks {
|
||||
return &ClientGotBlocks{
|
||||
Blocks: make([]BlockPos, 0),
|
||||
Blocks: make([]types.BlockPos, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ClientGotBlocks) AddBlock(pos BlockPos) {
|
||||
func (p *ClientGotBlocks) AddBlock(pos types.BlockPos) {
|
||||
p.Blocks = append(p.Blocks, pos)
|
||||
}
|
||||
|
||||
func (p *ClientGotBlocks) AddBlockPos(x, y, z int16) {
|
||||
p.AddBlock(BlockPos{
|
||||
p.AddBlock(types.BlockPos{
|
||||
PosX: x,
|
||||
PosY: y,
|
||||
PosZ: z,
|
||||
|
|
|
@ -3,12 +3,11 @@ package commands
|
|||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"minetest_client/types"
|
||||
)
|
||||
|
||||
type ServerBlockData struct {
|
||||
PosX int16
|
||||
PosY int16
|
||||
PosZ int16
|
||||
Pos types.BlockPos
|
||||
}
|
||||
|
||||
func (p *ServerBlockData) GetCommandId() uint16 {
|
||||
|
@ -20,13 +19,14 @@ func (p *ServerBlockData) MarshalPacket() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (p *ServerBlockData) UnmarshalPacket(payload []byte) error {
|
||||
p.PosX = int16(binary.BigEndian.Uint16(payload[0:]))
|
||||
p.PosY = int16(binary.BigEndian.Uint16(payload[2:]))
|
||||
p.PosZ = int16(binary.BigEndian.Uint16(payload[4:]))
|
||||
blockpos := types.BlockPos{}
|
||||
blockpos.PosX = int16(binary.BigEndian.Uint16(payload[0:]))
|
||||
blockpos.PosY = int16(binary.BigEndian.Uint16(payload[2:]))
|
||||
blockpos.PosZ = int16(binary.BigEndian.Uint16(payload[4:]))
|
||||
p.Pos = blockpos
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ServerBlockData) String() string {
|
||||
return fmt.Sprintf("{ServerBlockData pos=%d/%d/%d}",
|
||||
p.PosX, p.PosY, p.PosZ)
|
||||
return fmt.Sprintf("{ServerBlockData pos=%s}", p.Pos)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
type BlockPos struct {
|
||||
PosX int16
|
||||
PosY int16
|
||||
PosZ int16
|
||||
}
|
||||
|
||||
func (bp BlockPos) String() string {
|
||||
return fmt.Sprintf("{Blockpos %d/%d/%d}", bp.PosX, bp.PosY, bp.PosZ)
|
||||
}
|
Loading…
Reference in New Issue