This commit is contained in:
Tnze
2022-06-14 13:15:57 +08:00
parent 780260c3bf
commit 44703ce940
12 changed files with 70 additions and 57 deletions

View File

@ -1,9 +1,10 @@
package basic
import (
"github.com/google/uuid"
"time"
"github.com/google/uuid"
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/chat"
"github.com/Tnze/go-mc/data/packetid"

View File

@ -1,7 +1,6 @@
package basic
import (
"golang.org/x/exp/slices"
"unsafe"
"github.com/Tnze/go-mc/data/packetid"
@ -49,7 +48,7 @@ type Dimension struct {
} `nbt:"element"`
}
type DimensionCodec struct {
// What is Below? (wik.vg)
// What is Below? (wiki.vg)
ChatType struct {
Type string `nbt:"type"`
Value []struct {
@ -173,11 +172,10 @@ func (p *Player) handleLoginPacket(packet pk.Packet) error {
// p.WorldNames[i] = string(v)
// }
p.WorldNames = *(*[]string)(unsafe.Pointer(&WorldNames))
index := slices.IndexFunc(p.DimensionCodec.DimensionType.Value, func(d Dimension) bool {
return d.Name == string(currentDimension)
})
if index != -1 {
p.Dimension = p.DimensionCodec.DimensionType.Value[index]
for _, d := range p.DimensionCodec.DimensionType.Value {
if d.Name == string(currentDimension) {
p.Dimension = d
}
}
err = p.c.Conn.WritePacket(pk.Marshal( //PluginMessage packet
@ -221,11 +219,10 @@ func (p *Player) handleRespawnPacket(packet pk.Packet) error {
if err != nil {
return Error{err}
}
index := slices.IndexFunc(p.DimensionCodec.DimensionType.Value, func(d Dimension) bool {
return d.Name == string(currentDimension)
})
if index != -1 {
p.Dimension = p.DimensionCodec.DimensionType.Value[index]
for _, d := range p.DimensionCodec.DimensionType.Value {
if d.Name == string(currentDimension) {
p.Dimension = d
}
}
return nil
}