Skip to content

Commit c58dd9a

Browse files
use mt-types pkg
1 parent c7d5b07 commit c58dd9a

File tree

7 files changed

+38
-50
lines changed

7 files changed

+38
-50
lines changed

commandclient/debughandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func DebugHandler(cc *CommandClient) error {
1919
gotblocks := commands.NewClientGotBlocks()
2020
gotblocks.AddBlock(cmd.Pos)
2121

22-
//fmt.Printf("Got block: %s\n", cmd.Pos)
22+
fmt.Printf("Got block: %s\n", &cmd.Pos)
2323
err := cc.SendCommand(gotblocks)
2424
if err != nil {
2525
return err

commands/client_got_blocks.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@ import (
44
"encoding/binary"
55
"fmt"
66

7-
"github.com/minetest-go/minetest_client/types"
7+
"github.com/minetest-go/types"
88
)
99

1010
type ClientGotBlocks struct {
11-
Blocks []types.BlockPos
11+
Blocks []types.Pos
1212
}
1313

1414
func NewClientGotBlocks() *ClientGotBlocks {
1515
return &ClientGotBlocks{
16-
Blocks: make([]types.BlockPos, 0),
16+
Blocks: make([]types.Pos, 0),
1717
}
1818
}
1919

20-
func (p *ClientGotBlocks) AddBlock(pos types.BlockPos) {
20+
func (p *ClientGotBlocks) AddBlock(pos types.Pos) {
2121
p.Blocks = append(p.Blocks, pos)
2222
}
2323

24-
func (p *ClientGotBlocks) AddBlockPos(x, y, z int16) {
25-
p.AddBlock(types.BlockPos{
26-
PosX: x,
27-
PosY: y,
28-
PosZ: z,
29-
})
24+
func (p *ClientGotBlocks) AddBlockPos(x, y, z int) {
25+
p.AddBlock(types.Pos{x, y, z})
3026
}
3127

3228
func (p *ClientGotBlocks) GetCommandId() uint16 {
@@ -38,11 +34,11 @@ func (p *ClientGotBlocks) MarshalPacket() ([]byte, error) {
3834
buf[0] = uint8(len(p.Blocks))
3935
offset := 1
4036
for _, bp := range p.Blocks {
41-
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.PosX))
37+
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.X()))
4238
offset += 2
43-
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.PosY))
39+
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.Y()))
4440
offset += 2
45-
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.PosZ))
41+
binary.BigEndian.PutUint16(buf[offset:], uint16(bp.Z()))
4642
offset += 2
4743
}
4844

@@ -54,5 +50,5 @@ func (p *ClientGotBlocks) UnmarshalPacket([]byte) error {
5450
}
5551

5652
func (p *ClientGotBlocks) String() string {
57-
return fmt.Sprintf("{ClientGotBlocks blocks=%s}", p.Blocks)
53+
return fmt.Sprintf("{ClientGotBlocks blocks=%v}", p.Blocks)
5854
}

commands/server_block_data.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"encoding/binary"
55
"fmt"
66

7-
"github.com/minetest-go/minetest_client/types"
7+
"github.com/minetest-go/types"
88
)
99

1010
type ServerBlockData struct {
11-
Pos types.BlockPos
11+
Pos types.Pos
1212
}
1313

1414
func (p *ServerBlockData) GetCommandId() uint16 {
@@ -20,14 +20,15 @@ func (p *ServerBlockData) MarshalPacket() ([]byte, error) {
2020
}
2121

2222
func (p *ServerBlockData) UnmarshalPacket(payload []byte) error {
23-
blockpos := types.BlockPos{}
24-
blockpos.PosX = int16(binary.BigEndian.Uint16(payload[0:]))
25-
blockpos.PosY = int16(binary.BigEndian.Uint16(payload[2:]))
26-
blockpos.PosZ = int16(binary.BigEndian.Uint16(payload[4:]))
23+
blockpos := types.Pos{
24+
int(int16(binary.BigEndian.Uint16(payload[0:]))),
25+
int(int16(binary.BigEndian.Uint16(payload[2:]))),
26+
int(int16(binary.BigEndian.Uint16(payload[4:]))),
27+
}
2728
p.Pos = blockpos
2829
return nil
2930
}
3031

3132
func (p *ServerBlockData) String() string {
32-
return fmt.Sprintf("{ServerBlockData pos=%s}", p.Pos)
33+
return fmt.Sprintf("{ServerBlockData pos=%s}", &p.Pos)
3334
}

commands/server_block_data_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestServerBlockData(t *testing.T) {
2525
err = pkg.UnmarshalPacket(payload[0x37:])
2626
assert.NoError(t, err)
2727

28-
assert.Equal(t, int16(32), pkg.Pos.PosX)
29-
assert.Equal(t, int16(-2), pkg.Pos.PosY)
30-
assert.Equal(t, int16(12), pkg.Pos.PosZ)
28+
assert.Equal(t, 32, pkg.Pos.X())
29+
assert.Equal(t, -2, pkg.Pos.Y())
30+
assert.Equal(t, 12, pkg.Pos.Z())
3131
}

go.mod

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
module github.com/minetest-go/minetest_client
22

3-
go 1.22
3+
go 1.22.4
44

5-
require github.com/stretchr/testify v1.7.1
5+
toolchain go1.23.0
6+
7+
require github.com/stretchr/testify v1.9.0
8+
9+
require github.com/minetest-go/types v1.0.4
610

711
require (
8-
github.com/davecgh/go-spew v1.1.0 // indirect
12+
github.com/davecgh/go-spew v1.1.1 // indirect
913
github.com/pmezard/go-difflib v1.0.0 // indirect
1014
golang.org/x/text v0.3.7
11-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
15+
gopkg.in/yaml.v3 v3.0.1 // indirect
1216
)

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/minetest-go/types v1.0.4 h1:SuM1UPXM2ocngJqZwlxZjnQVJEFxeMyk4bqlEw1BAj4=
4+
github.com/minetest-go/types v1.0.4/go.mod h1:QS2q8tKAiuBe2Rin880ARFt9VokYIJNZV4Z4kHAChU0=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
7-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
8+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
89
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
910
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
10-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
1111
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1212
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
14-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
14+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

types/blockpos.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)