Fix some warnings and typos
This commit is contained in:
@ -75,7 +75,7 @@ type eventBroker struct {
|
||||
// The default handler will run only if pass == false.
|
||||
ReceivePacket func(p pk.Packet) (pass bool, err error)
|
||||
|
||||
// PrePhysics will be called before a phyiscs tick.
|
||||
// PrePhysics will be called before a physics tick.
|
||||
PrePhysics func() error
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ func ExampleClient_JoinServer_offline() {
|
||||
}
|
||||
log.Println("Login success")
|
||||
|
||||
// Regist event handlers
|
||||
// Register event handlers
|
||||
// c.Events.GameStart = onGameStartFunc
|
||||
// c.Events.ChatMsg = onChatMsgFunc
|
||||
// c.Events.Disconnect = onDisconnectFunc
|
||||
@ -63,7 +63,7 @@ func ExampleClient_JoinServer_online() {
|
||||
}
|
||||
log.Println("Login success")
|
||||
|
||||
// Regist event handlers
|
||||
// Register event handlers
|
||||
// c.Events.GameStart = onGameStartFunc
|
||||
// c.Events.ChatMsg = onChatMsgFunc
|
||||
// c.Events.Disconnect = onDisconnectFunc
|
||||
|
16
bot/login.go
16
bot/login.go
@ -34,11 +34,11 @@ func OfflineUUID(name string) uuid.UUID {
|
||||
h.Reset()
|
||||
h.Write([]byte("OfflinePlayer:" + name))
|
||||
s := h.Sum(nil)
|
||||
var uuid uuid.UUID
|
||||
copy(uuid[:], s)
|
||||
uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
|
||||
uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
|
||||
return uuid
|
||||
var id uuid.UUID
|
||||
copy(id[:], s)
|
||||
id[6] = (id[6] & 0x0f) | uint8((version&0xf)<<4)
|
||||
id[8] = (id[8] & 0x3f) | 0x80 // RFC 4122 variant
|
||||
return id
|
||||
}
|
||||
|
||||
// 加密请求
|
||||
@ -140,7 +140,7 @@ func authDigest(serverID string, sharedSecret, publicKey []byte) string {
|
||||
func twosComplement(p []byte) []byte {
|
||||
carry := true
|
||||
for i := len(p) - 1; i >= 0; i-- {
|
||||
p[i] = byte(^p[i])
|
||||
p[i] = ^p[i]
|
||||
if carry {
|
||||
carry = p[i] == 0xff
|
||||
p[i]++
|
||||
@ -202,7 +202,9 @@ func loginAuth(AsTk, name, UUID string, shareSecret []byte, er encryptionRequest
|
||||
// AES/CFB8 with random key
|
||||
func newSymmetricEncryption() (key []byte, encoStream, decoStream cipher.Stream) {
|
||||
key = make([]byte, 16)
|
||||
rand.Read(key) //生成密钥
|
||||
if _, err := rand.Read(key); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
b, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
|
@ -202,7 +202,7 @@ func (s *State) applyPosInputs(input path.Inputs, acceleration, inertia float64)
|
||||
}
|
||||
|
||||
func (s *State) tickPosition(w World) {
|
||||
player, newVel := s.computeCollisionYXZ(s.BB(), s.BB().Offset(s.Vel.X, s.Vel.Y, s.Vel.Z), s.Vel, w)
|
||||
p, newVel := s.computeCollisionYXZ(s.BB(), s.BB().Offset(s.Vel.X, s.Vel.Y, s.Vel.Z), s.Vel, w)
|
||||
|
||||
if s.onGround || (s.Vel.Y != newVel.Y && s.Vel.Y < 0) {
|
||||
bb := s.BB()
|
||||
@ -236,15 +236,15 @@ func (s *State) tickPosition(w World) {
|
||||
if oldMove >= newMove || outVel.Y <= (0.000002-stepHeight) {
|
||||
// fmt.Println("nope")
|
||||
} else {
|
||||
player = bb
|
||||
p = bb
|
||||
newVel = outVel
|
||||
}
|
||||
}
|
||||
|
||||
// Update flags.
|
||||
s.Pos.X = player.X.Min + playerWidth/2
|
||||
s.Pos.Y = player.Y.Min
|
||||
s.Pos.Z = player.Z.Min + playerWidth/2
|
||||
s.Pos.X = p.X.Min + playerWidth/2
|
||||
s.Pos.Y = p.Y.Min
|
||||
s.Pos.Z = p.Z.Min + playerWidth/2
|
||||
s.collision.horizontal = newVel.X != s.Vel.X || newVel.Z != s.Vel.Z
|
||||
s.collision.vertical = newVel.Y != s.Vel.Y
|
||||
s.onGround = s.collision.vertical && s.Vel.Y < 0
|
||||
|
@ -4,21 +4,21 @@ package world
|
||||
// values. If the next value does not fit into remaining space, the remaining
|
||||
// space of a uint64 is unused.
|
||||
type bitArray struct {
|
||||
width uint // bit width of each value
|
||||
valsPerElement uint // number of values which fit into a single uint64.
|
||||
width uint // bit width of each value
|
||||
valuesPerElement uint // number of values which fit into a single uint64.
|
||||
|
||||
data []uint64
|
||||
}
|
||||
|
||||
// Size returns the number of elements that can fit into the bit array.
|
||||
func (b *bitArray) Size() int {
|
||||
return int(b.valsPerElement) * len(b.data)
|
||||
return int(b.valuesPerElement) * len(b.data)
|
||||
}
|
||||
|
||||
func (b *bitArray) Set(idx, val uint) {
|
||||
var (
|
||||
arrayIdx = idx / b.valsPerElement
|
||||
startBit = (idx % b.valsPerElement) * b.width
|
||||
arrayIdx = idx / b.valuesPerElement
|
||||
startBit = (idx % b.valuesPerElement) * b.width
|
||||
mask = ^uint64((1<<b.width - 1) << startBit) // set for all bits except target
|
||||
)
|
||||
b.data[arrayIdx] = (b.data[arrayIdx] & mask) | uint64(val<<startBit)
|
||||
@ -26,13 +26,13 @@ func (b *bitArray) Set(idx, val uint) {
|
||||
|
||||
func (b *bitArray) Get(idx uint) uint {
|
||||
var (
|
||||
arrayIdx = idx / b.valsPerElement
|
||||
offset = (idx % b.valsPerElement) * b.width
|
||||
arrayIdx = idx / b.valuesPerElement
|
||||
offset = (idx % b.valuesPerElement) * b.width
|
||||
mask = uint64((1<<b.width - 1) << offset) // set for just the target
|
||||
)
|
||||
return uint(b.data[arrayIdx]&mask) >> offset
|
||||
}
|
||||
|
||||
func valsPerBitArrayElement(bitsPerValue uint) uint {
|
||||
func valuesPerBitArrayElement(bitsPerValue uint) uint {
|
||||
return uint(64 / bitsPerValue)
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
|
||||
func TestBitArrayBasic(t *testing.T) {
|
||||
a := bitArray{
|
||||
width: 5,
|
||||
valsPerElement: valsPerBitArrayElement(5),
|
||||
data: make([]uint64, 5),
|
||||
width: 5,
|
||||
valuesPerElement: valuesPerBitArrayElement(5),
|
||||
data: make([]uint64, 5),
|
||||
}
|
||||
|
||||
if got, want := a.Size(), 12*5; got != want {
|
||||
@ -32,9 +32,9 @@ func TestBitArrayHardcoded(t *testing.T) {
|
||||
d2, _ := hex.DecodeString("01018A7260F68C87")
|
||||
|
||||
a := bitArray{
|
||||
width: 5,
|
||||
valsPerElement: valsPerBitArrayElement(5),
|
||||
data: []uint64{binary.BigEndian.Uint64(d1), binary.BigEndian.Uint64(d2)},
|
||||
width: 5,
|
||||
valuesPerElement: valuesPerBitArrayElement(5),
|
||||
data: []uint64{binary.BigEndian.Uint64(d1), binary.BigEndian.Uint64(d2)},
|
||||
}
|
||||
|
||||
if got, want := a.Size(), 12*2; got != want {
|
||||
|
@ -92,9 +92,9 @@ func readSection(data pk.DecodeReader) (s Section, err error) {
|
||||
width := perBits(byte(bpb))
|
||||
sec := directSection{
|
||||
bitArray{
|
||||
width: width,
|
||||
valsPerElement: valsPerBitArrayElement(width),
|
||||
data: dataArray,
|
||||
width: width,
|
||||
valuesPerElement: valuesPerBitArrayElement(width),
|
||||
data: dataArray,
|
||||
},
|
||||
}
|
||||
if bpb <= maxPaletteBits {
|
||||
@ -133,12 +133,12 @@ func (d *directSection) clone(bpb uint) *directSection {
|
||||
}
|
||||
|
||||
func newSectionWithSize(bpb uint) *directSection {
|
||||
valsPerElement := valsPerBitArrayElement(bpb)
|
||||
valuesPerElement := valuesPerBitArrayElement(bpb)
|
||||
return &directSection{
|
||||
bitArray{
|
||||
width: bpb,
|
||||
valsPerElement: valsPerElement,
|
||||
data: make([]uint64, int(math.Ceil(16*16*16/float64(valsPerElement)))),
|
||||
width: bpb,
|
||||
valuesPerElement: valuesPerElement,
|
||||
data: make([]uint64, int(math.Ceil(16*16*16/float64(valuesPerElement)))),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -84,9 +84,13 @@ func (s Slot) Encode() []byte {
|
||||
b.Write(pk.Byte(s.Count).Encode())
|
||||
|
||||
if s.NBT != nil {
|
||||
nbt.NewEncoder(&b).Encode(s.NBT)
|
||||
if err := nbt.NewEncoder(&b).Encode(s.NBT); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
b.Write([]byte{nbt.TagEnd})
|
||||
if _, err := b.Write([]byte{nbt.TagEnd}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return b.Bytes()
|
||||
|
@ -24,7 +24,7 @@ func (w *World) PlayerEntities() []entity.Entity {
|
||||
}
|
||||
|
||||
// OnSpawnEntity should be called when a SpawnEntity packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnSpawnEntity(pkt ptypes.SpawnEntity) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -53,7 +53,7 @@ func (w *World) OnSpawnEntity(pkt ptypes.SpawnEntity) error {
|
||||
}
|
||||
|
||||
// OnSpawnLivingEntity should be called when a SpawnLivingEntity packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnSpawnLivingEntity(pkt ptypes.SpawnLivingEntity) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -81,7 +81,7 @@ func (w *World) OnSpawnLivingEntity(pkt ptypes.SpawnLivingEntity) error {
|
||||
}
|
||||
|
||||
// OnSpawnPlayer should be called when a SpawnPlayer packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnSpawnPlayer(pkt ptypes.SpawnPlayer) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -100,7 +100,7 @@ func (w *World) OnSpawnPlayer(pkt ptypes.SpawnPlayer) error {
|
||||
}
|
||||
|
||||
// OnEntityPosUpdate should be called when an EntityPosition packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnEntityPosUpdate(pkt ptypes.EntityPosition) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -118,7 +118,7 @@ func (w *World) OnEntityPosUpdate(pkt ptypes.EntityPosition) error {
|
||||
}
|
||||
|
||||
// OnEntityPosLookUpdate should be called when an EntityPositionLook packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnEntityPosLookUpdate(pkt ptypes.EntityPositionLook) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -137,7 +137,7 @@ func (w *World) OnEntityPosLookUpdate(pkt ptypes.EntityPositionLook) error {
|
||||
}
|
||||
|
||||
// OnEntityLookUpdate should be called when an EntityRotation packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnEntityLookUpdate(pkt ptypes.EntityRotation) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
@ -153,7 +153,7 @@ func (w *World) OnEntityLookUpdate(pkt ptypes.EntityRotation) error {
|
||||
}
|
||||
|
||||
// OnEntityDestroy should be called when a DestroyEntities packet
|
||||
// is recieved.
|
||||
// is received.
|
||||
func (w *World) OnEntityDestroy(eIDs []pk.VarInt) error {
|
||||
w.entityLock.Lock()
|
||||
defer w.entityLock.Unlock()
|
||||
|
Reference in New Issue
Block a user