format repo with "gofumpt" tool
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
"unsafe"
|
||||
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
@ -148,6 +149,7 @@ func (p *Player) handleLoginPacket(packet pk.Packet) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Player) handleRespawnPacket(packet pk.Packet) error {
|
||||
var copyMeta bool
|
||||
err := packet.Scan(
|
||||
|
@ -79,7 +79,9 @@ func (p *PlayerMessage) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
var timestamp pk.Long
|
||||
var unsignedContent chat.Message
|
||||
n, err = pk.Tuple{
|
||||
&hasMsgSign, pk.Opt{Has: &hasMsgSign,
|
||||
&hasMsgSign,
|
||||
pk.Opt{
|
||||
Has: &hasMsgSign,
|
||||
Field: (*pk.ByteArray)(&p.signature),
|
||||
},
|
||||
(*pk.UUID)(&p.sender),
|
||||
@ -88,7 +90,9 @@ func (p *PlayerMessage) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
×tamp,
|
||||
(*pk.Long)(&p.salt),
|
||||
pk.Array(&p.prevMessages),
|
||||
&hasUnsignedContent, pk.Opt{Has: &hasUnsignedContent,
|
||||
&hasUnsignedContent,
|
||||
pk.Opt{
|
||||
Has: &hasUnsignedContent,
|
||||
Field: &unsignedContent,
|
||||
},
|
||||
(*pk.VarInt)(&p.filterType),
|
||||
|
@ -35,12 +35,14 @@ func (e *Events) AddGeneric(listeners ...PacketHandler) {
|
||||
}
|
||||
}
|
||||
|
||||
type PacketHandlerFunc func(p pk.Packet) error
|
||||
type PacketHandler struct {
|
||||
type (
|
||||
PacketHandlerFunc func(p pk.Packet) error
|
||||
PacketHandler struct {
|
||||
ID packetid.ClientboundPacketID
|
||||
Priority int
|
||||
F func(p pk.Packet) error
|
||||
}
|
||||
)
|
||||
|
||||
// handlerHeap is PriorityQueue<PacketHandlerFunc>
|
||||
type handlerHeap []PacketHandler
|
||||
|
@ -1,9 +1,9 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"log"
|
||||
|
||||
"encoding/hex"
|
||||
"github.com/Tnze/go-mc/offline"
|
||||
"github.com/Tnze/go-mc/yggdrasil"
|
||||
)
|
||||
@ -33,10 +33,7 @@ func ExampleClient_JoinServer_offline() {
|
||||
log.Println("Login success")
|
||||
|
||||
// Register event handlers
|
||||
// c.Events.GameStart = onGameStartFunc
|
||||
// c.Events.ChatMsg = onChatMsgFunc
|
||||
// c.Events.Disconnect = onDisconnectFunc
|
||||
// ...
|
||||
// c.Events.AddListener(...)
|
||||
|
||||
// JoinGame
|
||||
err = c.HandleGame()
|
||||
|
@ -22,8 +22,10 @@ import (
|
||||
)
|
||||
|
||||
// ProtocolVersion is the protocol version number of minecraft net protocol
|
||||
const ProtocolVersion = 760
|
||||
const DefaultPort = mcnet.DefaultPort
|
||||
const (
|
||||
ProtocolVersion = 760
|
||||
DefaultPort = mcnet.DefaultPort
|
||||
)
|
||||
|
||||
// JoinServer connect a Minecraft server for playing the game.
|
||||
// Using roughly the same way to parse address as minecraft.
|
||||
|
@ -207,6 +207,7 @@ var fmtCode = map[byte]string{
|
||||
'o': "3",
|
||||
'r': "0",
|
||||
}
|
||||
|
||||
var colors = map[string]string{
|
||||
Black: "30",
|
||||
DarkBlue: "34",
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
// This program can automatically download language.json file and convert into .go
|
||||
@ -17,9 +18,8 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var (
|
||||
// language=gohtml
|
||||
langTmpl = `// Code generated by downloader.go; DO NOT EDIT.
|
||||
var langTmpl = `// Code generated by downloader.go; DO NOT EDIT.
|
||||
package {{.Name}}
|
||||
{{if ne .Name "en_us"}}
|
||||
import "github.com/Tnze/go-mc/chat"
|
||||
@ -28,7 +28,6 @@ func init() { chat.SetLanguage(Map) }
|
||||
{{end}}
|
||||
var Map = {{.LangMap | printf "%#v"}}
|
||||
`
|
||||
)
|
||||
|
||||
//go:generate go run $GOFILE
|
||||
//go:generate go fmt ./...
|
||||
@ -112,12 +111,12 @@ func readLang(name string, r io.Reader) {
|
||||
pName := strings.ReplaceAll(name, "_", "-")
|
||||
|
||||
// mkdir
|
||||
err = os.Mkdir(pName, 0777)
|
||||
err = os.Mkdir(pName, 0o777)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(filepath.Join(pName, name+".go"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
|
||||
f, err := os.OpenFile(filepath.Join(pName, name+".go"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -2,9 +2,10 @@ package packetid
|
||||
|
||||
//go:generate stringer -type ClientboundPacketID
|
||||
//go:generate stringer -type ServerboundPacketID
|
||||
|
||||
type ClientboundPacketID int32
|
||||
type ServerboundPacketID int32
|
||||
type (
|
||||
ClientboundPacketID int32
|
||||
ServerboundPacketID int32
|
||||
)
|
||||
|
||||
// Login Clientbound
|
||||
const (
|
||||
|
@ -71,7 +71,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = os.WriteFile("blockentitytype/blockentitytype.go", formattedSource, 0666)
|
||||
err = os.WriteFile("blockentitytype/blockentitytype.go", formattedSource, 0o666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
botchat "github.com/Tnze/go-mc/bot/chat"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@ -9,6 +8,7 @@ import (
|
||||
|
||||
"github.com/Tnze/go-mc/bot"
|
||||
"github.com/Tnze/go-mc/bot/basic"
|
||||
botchat "github.com/Tnze/go-mc/bot/chat"
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
_ "github.com/Tnze/go-mc/data/lang/en-us"
|
||||
"github.com/Tnze/go-mc/data/packetid"
|
||||
|
@ -21,16 +21,20 @@ import (
|
||||
"github.com/Tnze/go-mc/level"
|
||||
)
|
||||
|
||||
var address = flag.String("address", "127.0.0.1", "The server address")
|
||||
var name = flag.String("name", "Daze", "The player's name")
|
||||
var playerID = flag.String("uuid", "", "The player's UUID")
|
||||
var accessToken = flag.String("token", "", "AccessToken")
|
||||
var (
|
||||
address = flag.String("address", "127.0.0.1", "The server address")
|
||||
name = flag.String("name", "Daze", "The player's name")
|
||||
playerID = flag.String("uuid", "", "The player's UUID")
|
||||
accessToken = flag.String("token", "", "AccessToken")
|
||||
)
|
||||
|
||||
var client *bot.Client
|
||||
var player *basic.Player
|
||||
var chatHandler *botchat.Chat
|
||||
var worldManager *world.World
|
||||
var screenManager *screen.Manager
|
||||
var (
|
||||
client *bot.Client
|
||||
player *basic.Player
|
||||
chatHandler *botchat.Chat
|
||||
worldManager *world.World
|
||||
screenManager *screen.Manager
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
@ -18,10 +18,12 @@ import (
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
var address = flag.String("address", "127.0.0.1", "The server address")
|
||||
var client *bot.Client
|
||||
var player *basic.Player
|
||||
var screenManager *screen.Manager
|
||||
var (
|
||||
address = flag.String("address", "127.0.0.1", "The server address")
|
||||
client *bot.Client
|
||||
player *basic.Player
|
||||
screenManager *screen.Manager
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@ -62,8 +64,7 @@ func onCommands(p pk.Packet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
}
|
||||
type Node struct{}
|
||||
|
||||
func (n Node) ReadFrom(r io.Reader) (int64, error) {
|
||||
var Flags pk.Byte
|
||||
@ -71,7 +72,7 @@ func (n Node) ReadFrom(r io.Reader) (int64, error) {
|
||||
var Redirect pk.VarInt
|
||||
var Name pk.String
|
||||
var Parser pk.Identifier
|
||||
var Properties = Prop{Type: &Parser}
|
||||
Properties := Prop{Type: &Parser}
|
||||
var SuggestionsType pk.Identifier
|
||||
m, err := pk.Tuple{
|
||||
&Flags,
|
||||
|
@ -8,8 +8,10 @@ import (
|
||||
"github.com/Tnze/go-mc/yggdrasil"
|
||||
)
|
||||
|
||||
var user = flag.String("user", "", "Can be an email address or player name for unmigrated accounts")
|
||||
var pswd = flag.String("password", "", "Your password")
|
||||
var (
|
||||
user = flag.String("user", "", "Can be an email address or player name for unmigrated accounts")
|
||||
pswd = flag.String("password", "", "Your password")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
@ -13,8 +13,10 @@ import (
|
||||
"github.com/Tnze/go-mc/save/region"
|
||||
)
|
||||
|
||||
var decomp = flag.Bool("x", false, "decompress each chunk to NBT format")
|
||||
var repack = flag.Bool("p", false, "repack .mcc file to .mca")
|
||||
var (
|
||||
decomp = flag.Bool("x", false, "decompress each chunk to NBT format")
|
||||
repack = flag.Bool("p", false, "repack .mcc file to .mca")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
@ -91,7 +93,7 @@ func unpack(f, o string) {
|
||||
checkerr(err)
|
||||
}
|
||||
|
||||
cf, err := os.OpenFile(filepath.Join(o, fn), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0666)
|
||||
cf, err := os.OpenFile(filepath.Join(o, fn), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0o666)
|
||||
checkerr(err)
|
||||
|
||||
_, err = io.Copy(cf, r)
|
||||
|
@ -20,8 +20,10 @@ import (
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
)
|
||||
|
||||
var protocol = flag.Int("p", 578, "The protocol version number sent during ping")
|
||||
var favicon = flag.String("f", "", "If specified, the server's icon will be save to")
|
||||
var (
|
||||
protocol = flag.Int("p", 578, "The protocol version number sent during ping")
|
||||
favicon = flag.String("f", "", "If specified, the server's icon will be save to")
|
||||
)
|
||||
|
||||
type status struct {
|
||||
Description chat.Message
|
||||
|
@ -13,8 +13,10 @@ import (
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
)
|
||||
|
||||
var address = flag.String("address", "127.0.0.1", "The server address")
|
||||
var number = flag.Int("number", 1023, "The number of clients")
|
||||
var (
|
||||
address = flag.String("address", "127.0.0.1", "The server address")
|
||||
number = flag.Int("number", 1023, "The number of clients")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
@ -11,8 +11,10 @@ import (
|
||||
"github.com/Tnze/go-mc/offline"
|
||||
)
|
||||
|
||||
const ProtocolVersion = 578
|
||||
const MaxPlayer = 200
|
||||
const (
|
||||
ProtocolVersion = 578
|
||||
MaxPlayer = 200
|
||||
)
|
||||
|
||||
// Packet IDs
|
||||
const (
|
||||
|
@ -13,8 +13,10 @@ import (
|
||||
"github.com/Tnze/go-mc/offline"
|
||||
)
|
||||
|
||||
const ProtocolVersion = 756
|
||||
const MaxPlayer = 200
|
||||
const (
|
||||
ProtocolVersion = 756
|
||||
MaxPlayer = 200
|
||||
)
|
||||
|
||||
// Packet IDs
|
||||
const (
|
||||
|
@ -2,11 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
"github.com/Tnze/go-mc/net"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
"github.com/google/uuid"
|
||||
"log"
|
||||
)
|
||||
|
||||
func acceptListPing(conn net.Conn) {
|
||||
|
@ -8,8 +8,10 @@ import (
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
const indexOutOfBounds = "index out of bounds"
|
||||
const valueOutOfBounds = "value out of bounds"
|
||||
const (
|
||||
indexOutOfBounds = "index out of bounds"
|
||||
valueOutOfBounds = "value out of bounds"
|
||||
)
|
||||
|
||||
// BitStorage implement the compacted data array used in chunk storage and heightmaps.
|
||||
// You can think of this as a []intN whose N is called "bits" in NewBitStorage.
|
||||
|
@ -1,14 +1,17 @@
|
||||
package level
|
||||
|
||||
import (
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
var data = []uint64{0x0020863148418841, 0x01018A7260F68C87}
|
||||
var want = []int{1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12, 0, 2}
|
||||
var (
|
||||
data = []uint64{0x0020863148418841, 0x01018A7260F68C87}
|
||||
want = []int{1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12, 0, 2}
|
||||
)
|
||||
|
||||
func TestBitStorage_Get(t *testing.T) {
|
||||
bs := NewBitStorage(5, 24, data)
|
||||
|
@ -20,18 +20,22 @@ type Block interface {
|
||||
//go:embed block_states.nbt
|
||||
var blockStates []byte
|
||||
|
||||
var ToStateID map[Block]StateID
|
||||
var StateList []Block
|
||||
var (
|
||||
ToStateID map[Block]StateID
|
||||
StateList []Block
|
||||
)
|
||||
|
||||
// BitsPerBlock indicates how many bits are needed to represent all possible
|
||||
// block states. This value is used to determine the size of the global palette.
|
||||
var BitsPerBlock int
|
||||
|
||||
type StateID int
|
||||
type State struct {
|
||||
type (
|
||||
StateID int
|
||||
State struct {
|
||||
Name string
|
||||
Properties nbt.RawMessage
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
var states []State
|
||||
|
@ -70,7 +70,7 @@ func genSourceFile(states []State) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.WriteFile("blocks.go", formattedSource, 0666)
|
||||
err = os.WriteFile("blocks.go", formattedSource, 0o666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
err = os.WriteFile("properties_enum.go", formattedSource, 0666)
|
||||
err = os.WriteFile("properties_enum.go", formattedSource, 0o666)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
@ -406,6 +406,7 @@ type Section struct {
|
||||
func (s *Section) GetBlock(i int) BlocksState {
|
||||
return s.States.Get(i)
|
||||
}
|
||||
|
||||
func (s *Section) SetBlock(i int, v BlocksState) {
|
||||
if block.IsAir(s.States.Get(i)) {
|
||||
s.BlockCount--
|
||||
|
@ -13,8 +13,10 @@ import (
|
||||
type State interface {
|
||||
~int
|
||||
}
|
||||
type BlocksState = block.StateID
|
||||
type BiomesState int
|
||||
type (
|
||||
BlocksState = block.StateID
|
||||
BiomesState int
|
||||
)
|
||||
|
||||
type PaletteContainer[T State] struct {
|
||||
bits int
|
||||
@ -206,6 +208,7 @@ func (b biomesCfg) bits(bits int) int {
|
||||
return biome.BitsPerBiome
|
||||
}
|
||||
}
|
||||
|
||||
func (b biomesCfg) create(bits int) palette[BiomesState] {
|
||||
switch bits {
|
||||
case 0:
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestUnmarshal_string(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09,
|
||||
0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
}
|
||||
@ -38,7 +38,7 @@ func TestUnmarshal_string(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshal_simple(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x0a, 0x00, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x08, 0x00,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x09, 0x42,
|
||||
@ -388,7 +388,7 @@ func TestDecoder_Decode_bool(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDecoder_Decode_ErrorString(t *testing.T) {
|
||||
var data = []byte{
|
||||
data := []byte{
|
||||
0x08, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0xFF, 0xFE,
|
||||
0x42, 0x61, 0x6e, 0x61, 0x6e, 0x72, 0x61, 0x6d, 0x61,
|
||||
}
|
||||
@ -401,7 +401,6 @@ func TestDecoder_Decode_ErrorString(t *testing.T) {
|
||||
t.Error("should return a error if len < 0")
|
||||
}
|
||||
t.Log(err)
|
||||
|
||||
}
|
||||
|
||||
type TextBool bool
|
||||
@ -409,6 +408,7 @@ type TextBool bool
|
||||
func (b TextBool) MarshalText() (text []byte, err error) {
|
||||
return []byte(strconv.FormatBool(bool(b))), nil
|
||||
}
|
||||
|
||||
func (b *TextBool) UnmarshalText(text []byte) (err error) {
|
||||
*((*bool)(b)), err = strconv.ParseBool(string(text))
|
||||
return
|
||||
|
@ -390,7 +390,8 @@ func (e *Encoder) writeInt32(n int32) error {
|
||||
func (e *Encoder) writeInt64(n int64) error {
|
||||
_, err := e.w.Write([]byte{
|
||||
byte(n >> 56), byte(n >> 48), byte(n >> 40), byte(n >> 32),
|
||||
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
||||
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@ import (
|
||||
func TestEncoder_Encode_intArray(t *testing.T) {
|
||||
// Test marshal pure Int array
|
||||
v := []int32{0, -10, 3}
|
||||
out := []byte{TagIntArray, 0x00, 0x00, 0, 0, 0, 3,
|
||||
out := []byte{
|
||||
TagIntArray, 0x00, 0x00, 0, 0, 0, 3,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xf6,
|
||||
0x00, 0x00, 0x00, 0x03,
|
||||
@ -27,7 +28,8 @@ func TestEncoder_Encode_intArray(t *testing.T) {
|
||||
v2 := struct {
|
||||
Ary []int32 `nbt:"ary"`
|
||||
}{[]int32{0, -10, 3}}
|
||||
out = []byte{TagCompound, 0x00, 0x00,
|
||||
out = []byte{
|
||||
TagCompound, 0x00, 0x00,
|
||||
TagIntArray, 0x00, 0x03, 'a', 'r', 'y', 0, 0, 0, 3,
|
||||
0x00, 0x00, 0x00, 0x00, // 0
|
||||
0xff, 0xff, 0xff, 0xf6, // -10
|
||||
@ -72,7 +74,8 @@ func TestEncoder_encodeBool(t *testing.T) {
|
||||
func TestEncoder_Encode_floatArray(t *testing.T) {
|
||||
// Test marshal pure Int array
|
||||
v := []float32{0.3, -100, float32(math.NaN())}
|
||||
out := []byte{TagList, 0x00, 0x00, TagFloat, 0, 0, 0, 3,
|
||||
out := []byte{
|
||||
TagList, 0x00, 0x00, TagFloat, 0, 0, 0, 3,
|
||||
0x3e, 0x99, 0x99, 0x9a, // 0.3
|
||||
0xc2, 0xc8, 0x00, 0x00, // -100
|
||||
0x7f, 0xc0, 0x00, 0x00, // NaN
|
||||
@ -86,8 +89,10 @@ func TestEncoder_Encode_floatArray(t *testing.T) {
|
||||
|
||||
func TestEncoder_Encode_string(t *testing.T) {
|
||||
v := "Test"
|
||||
out := []byte{TagString, 0x00, 0x00, 0, 4,
|
||||
'T', 'e', 's', 't'}
|
||||
out := []byte{
|
||||
TagString, 0x00, 0x00, 0, 4,
|
||||
'T', 'e', 's', 't',
|
||||
}
|
||||
|
||||
if data, err := Marshal(v); err != nil {
|
||||
t.Error(err)
|
||||
|
@ -62,7 +62,7 @@ func ExampleDecoder_Decode_singleTagString() {
|
||||
}
|
||||
|
||||
func ExampleEncoder_Encode_tagCompound() {
|
||||
var value = struct {
|
||||
value := struct {
|
||||
Name string `nbt:"name"`
|
||||
}{"Tnze"}
|
||||
|
||||
|
@ -66,6 +66,7 @@ func TestSNBT_compound(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSNBT_list(t *testing.T) {
|
||||
goods := []string{
|
||||
`[]`, `[a, 'b', "c", d]`, // List of string
|
||||
|
@ -1,5 +1,4 @@
|
||||
//From https://play.golang.org/p/LTbId4b6M2
|
||||
|
||||
// Package CFB8 is copied from https://play.golang.org/p/LTbId4b6M2
|
||||
package CFB8
|
||||
|
||||
import "crypto/cipher"
|
||||
|
@ -37,6 +37,7 @@ func TestVarInt_WriteTo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVarInt_ReadFrom(t *testing.T) {
|
||||
for i, v := range PackedVarInts {
|
||||
var vi pk.VarInt
|
||||
@ -51,7 +52,7 @@ func TestVarInt_ReadFrom(t *testing.T) {
|
||||
|
||||
func TestVarInt_ReadFrom_tooLongData(t *testing.T) {
|
||||
var vi pk.VarInt
|
||||
var data = []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}
|
||||
data := []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}
|
||||
if _, err := vi.ReadFrom(bytes.NewReader(data)); err != nil {
|
||||
t.Logf("unpack \"% x\" error: %v", data, err)
|
||||
} else {
|
||||
@ -87,6 +88,7 @@ func TestVarLong_WriteTo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVarLong_ReadFrom(t *testing.T) {
|
||||
for i, v := range PackedVarLongs {
|
||||
var vi pk.VarLong
|
||||
|
@ -3,10 +3,11 @@ package packet
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
)
|
||||
|
||||
@ -77,8 +78,10 @@ type (
|
||||
BitSet []int64
|
||||
)
|
||||
|
||||
const MaxVarIntLen = 5
|
||||
const MaxVarLongLen = 10
|
||||
const (
|
||||
MaxVarIntLen = 5
|
||||
MaxVarLongLen = 10
|
||||
)
|
||||
|
||||
func (b Boolean) WriteTo(w io.Writer) (int64, error) {
|
||||
var v byte
|
||||
@ -245,7 +248,7 @@ func (l *Long) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
}
|
||||
|
||||
func (v VarInt) WriteTo(w io.Writer) (n int64, err error) {
|
||||
var vi = make([]byte, 0, MaxVarIntLen)
|
||||
vi := make([]byte, 0, MaxVarIntLen)
|
||||
num := uint32(v)
|
||||
for {
|
||||
b := num & 0x7F
|
||||
@ -282,7 +285,7 @@ func (v *VarInt) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
}
|
||||
|
||||
func (v VarLong) WriteTo(w io.Writer) (n int64, err error) {
|
||||
var vi = make([]byte, 0, MaxVarLongLen)
|
||||
vi := make([]byte, 0, MaxVarLongLen)
|
||||
num := uint64(v)
|
||||
for {
|
||||
b := num & 0x7F
|
||||
|
@ -3,8 +3,9 @@ package packet_test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
"testing"
|
||||
|
||||
pk "github.com/Tnze/go-mc/net/packet"
|
||||
)
|
||||
|
||||
func ExampleAry_WriteTo() {
|
||||
@ -34,12 +35,12 @@ func ExampleAry_ReadFrom() {
|
||||
|
||||
func TestAry_ReadFrom(t *testing.T) {
|
||||
var ary []pk.String
|
||||
var bin = []byte{
|
||||
bin := []byte{
|
||||
0, 0, 0, 2,
|
||||
4, 'T', 'n', 'z', 'e',
|
||||
0,
|
||||
}
|
||||
var data = pk.Ary[pk.Int]{Ary: &ary}
|
||||
data := pk.Ary[pk.Int]{Ary: &ary}
|
||||
if _, err := data.ReadFrom(bytes.NewReader(bin)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ package offline
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// NameToUUID return the UUID from player name in offline mode
|
||||
func NameToUUID(name string) uuid.UUID {
|
||||
var version = 3
|
||||
version := 3
|
||||
h := md5.New()
|
||||
h.Write([]byte("OfflinePlayer:"))
|
||||
h.Write([]byte(name))
|
||||
|
@ -49,7 +49,7 @@ func (r *Realms) Worlds() ([]Server, error) {
|
||||
// Server returns a single server listing about a server.
|
||||
// you must be the owner of the server.
|
||||
func (r *Realms) Server(ID int) (s Server, err error) {
|
||||
var resp = struct {
|
||||
resp := struct {
|
||||
*Server
|
||||
*Error
|
||||
}{Server: &s}
|
||||
@ -124,7 +124,7 @@ func (r *Realms) Ops(s Server) (ops []string, err error) {
|
||||
|
||||
// SubscriptionLife returns the current life of a server subscription.
|
||||
func (r *Realms) SubscriptionLife(s Server) (startDate int64, daysLeft int, Type string, err error) {
|
||||
var resp = struct {
|
||||
resp := struct {
|
||||
StartDate *int64
|
||||
DaysLeft *int
|
||||
SubscriptionType *string
|
||||
|
@ -1,8 +1,9 @@
|
||||
package save
|
||||
|
||||
import (
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
"io"
|
||||
|
||||
"github.com/Tnze/go-mc/nbt"
|
||||
)
|
||||
|
||||
type PlayerData struct {
|
||||
|
@ -37,7 +37,7 @@ func At(cx, cz int) (int, int) {
|
||||
// Open a .mca file and read the head.
|
||||
// Close the Region after used.
|
||||
func Open(name string) (r *Region, err error) {
|
||||
f, err := os.OpenFile(name, os.O_RDWR, 0666)
|
||||
f, err := os.OpenFile(name, os.O_RDWR, 0o666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -85,7 +85,7 @@ func Load(f io.ReadWriteSeeker) (r *Region, err error) {
|
||||
|
||||
// Create open .mca file with os.O_CREATE|os. O_EXCL, and init the region
|
||||
func Create(name string) (*Region, error) {
|
||||
f, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0666)
|
||||
f, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0o666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ func TestReadRegion(t *testing.T) {
|
||||
// t.Log(b)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFindSpace(t *testing.T) {
|
||||
|
@ -10,8 +10,10 @@ import (
|
||||
|
||||
// Packet758 is a packet in protocol 757.
|
||||
// We are using type system to force programmers to update packets.
|
||||
type Packet758 pk.Packet
|
||||
type Packet757 pk.Packet
|
||||
type (
|
||||
Packet758 pk.Packet
|
||||
Packet757 pk.Packet
|
||||
)
|
||||
|
||||
type WritePacketError struct {
|
||||
Err error
|
||||
|
@ -70,8 +70,10 @@ type Node struct {
|
||||
Parser Parser
|
||||
Run HandlerFunc
|
||||
}
|
||||
type Literal Node
|
||||
type Argument Node
|
||||
type (
|
||||
Literal Node
|
||||
Argument Node
|
||||
)
|
||||
|
||||
func (n *Node) parse(cmd string) (left string, value ParsedData, err error) {
|
||||
switch n.kind & 0x03 {
|
||||
|
@ -1,4 +1,6 @@
|
||||
package server
|
||||
|
||||
type Pos struct{ X, Y, Z float64 }
|
||||
type Rot struct{ Yaw, Pitch float32 }
|
||||
type (
|
||||
Pos struct{ X, Y, Z float64 }
|
||||
Rot struct{ Yaw, Pitch float32 }
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ package bvh
|
||||
import (
|
||||
"container/heap"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
@ -194,12 +195,14 @@ func TouchBound[B interface{ Touch(B) bool }](other B) func(bound B) bool {
|
||||
}
|
||||
}
|
||||
|
||||
type searchHeap[I constraints.Float, V any] []searchItem[I, V]
|
||||
type searchItem[I constraints.Float, V any] struct {
|
||||
type (
|
||||
searchHeap[I constraints.Float, V any] []searchItem[I, V]
|
||||
searchItem[I constraints.Float, V any] struct {
|
||||
pointer *V
|
||||
parentTo **V
|
||||
inheritedCost I
|
||||
}
|
||||
)
|
||||
|
||||
func (h searchHeap[I, V]) Len() int { return len(h) }
|
||||
func (h searchHeap[I, V]) Less(i, j int) bool { return h[i].inheritedCost < h[j].inheritedCost }
|
||||
|
@ -1,8 +1,9 @@
|
||||
package bvh
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/constraints"
|
||||
"math"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type Vec2[I constraints.Signed | constraints.Float] [2]I
|
||||
@ -22,6 +23,7 @@ type Vec3[I constraints.Signed | constraints.Float] [3]I
|
||||
func (v Vec3[I]) Add(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{v[0] + other[0], v[1] + other[1], v[2] + other[2]}
|
||||
}
|
||||
|
||||
func (v Vec3[I]) Sub(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{v[0] - other[0], v[1] - other[1], v[2] - other[2]}
|
||||
}
|
||||
@ -29,6 +31,7 @@ func (v Vec3[I]) Mul(i I) Vec3[I] { return Vec3[I]{v[0] * i, v[1] * i, v[2] * i}
|
||||
func (v Vec3[I]) Max(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{max(v[0], other[0]), max(v[1], other[1]), max(v[2], other[2])}
|
||||
}
|
||||
|
||||
func (v Vec3[I]) Min(other Vec3[I]) Vec3[I] {
|
||||
return Vec3[I]{min(v[0], other[0]), min(v[1], other[1]), min(v[2], other[2])}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ func (a *Access) AvailableProfiles() []Profile {
|
||||
func (a *Access) SetTokens(tokens Tokens) {
|
||||
a.ar.Tokens = tokens
|
||||
}
|
||||
|
||||
func (a *Access) GetTokens() Tokens {
|
||||
return a.ar.Tokens
|
||||
}
|
||||
|
Reference in New Issue
Block a user