func (t *LoginSuccess) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.UUID); err != nil {
		return err
	}
	if err = packets.WriteString(ww, t.Username); err != nil {
		return err
	}
	return
}
func (t *JoinGame) Encode(ww io.Writer) (err error) {
	if err = binary.Write(ww, binary.BigEndian, t.EntityID); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.Gamemode); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.Dimension); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.Difficulty); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.MaxPlayers); err != nil {
		return err
	}

	if err = packets.WriteString(ww, t.LevelType); err != nil {
		return err
	}
	if err = packets.WriteBool(ww, t.ReducedDebug); err != nil {
		return err
	}
	return
}
func (t *ClientPluginMessage) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Channel); err != nil {
		return err
	}
	if _, err = ww.Write(t.Data); err != nil {
		return err
	}
	return
}
func (t *LoginDisconnect) Encode(ww io.Writer) (err error) {
	var tmp0 []byte
	if tmp0, err = json.Marshal(&t.Reason); err != nil {
		return err
	}
	if err = packets.WriteString(ww, string(tmp0)); err != nil {
		return err
	}
	return
}
func (t *ShowScoreboard) Encode(ww io.Writer) (err error) {
	if err = binary.Write(ww, binary.BigEndian, t.Position); err != nil {
		return err
	}

	if err = packets.WriteString(ww, t.Name); err != nil {
		return err
	}
	return
}
func (t *StatusResponse) Encode(ww io.Writer) (err error) {
	var tmp0 []byte
	if tmp0, err = json.Marshal(&t.Status); err != nil {
		return err
	}
	if err = packets.WriteString(ww, string(tmp0)); err != nil {
		return err
	}
	return
}
func (t *ScoreboardObjective) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Name); err != nil {
		return err
	}
	if err = binary.Write(ww, binary.BigEndian, t.Mode); err != nil {
		return err
	}

	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.Value); err != nil {
			return err
		}
	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.Type); err != nil {
			return err
		}
	}
	return
}
func (t *UpdateScore) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Name); err != nil {
		return err
	}
	if err = binary.Write(ww, binary.BigEndian, t.Action); err != nil {
		return err
	}

	if err = packets.WriteString(ww, t.ObjectiveName); err != nil {
		return err
	}
	if t.Action != 1 {
		tmp0 := make([]byte, binary.MaxVarintLen64)
		tmp1 := packets.PutVarint(tmp0, int64(t.Value))
		if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
			return err
		}

	}
	return
}
func (t *ServerTabComplete) Encode(ww io.Writer) (err error) {
	tmp0 := make([]byte, binary.MaxVarintLen64)
	tmp1 := packets.PutVarint(tmp0, int64(len(t.Matches)))
	if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
		return err
	}

	for tmp2 := range t.Matches {
		if err = packets.WriteString(ww, t.Matches[tmp2]); err != nil {
			return err
		}
	}
	return
}
func (t *ServerMessage) Encode(ww io.Writer) (err error) {
	var tmp0 []byte
	if tmp0, err = json.Marshal(&t.Data); err != nil {
		return err
	}
	if err = packets.WriteString(ww, string(tmp0)); err != nil {
		return err
	}
	if err = binary.Write(ww, binary.BigEndian, t.Position); err != nil {
		return err
	}

	return
}
func (t *ClientTabComplete) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Text); err != nil {
		return err
	}
	if err = packets.WriteBool(ww, t.HasPosition); err != nil {
		return err
	}
	if t.HasPosition {
		if err = binary.Write(ww, binary.BigEndian, t.LookedAtBlock); err != nil {
			return err
		}

	}
	return
}
func (t *Teams) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Name); err != nil {
		return err
	}
	if err = binary.Write(ww, binary.BigEndian, t.Mode); err != nil {
		return err
	}

	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.Display); err != nil {
			return err
		}
	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.Prefix); err != nil {
			return err
		}
	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.Suffix); err != nil {
			return err
		}
	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = binary.Write(ww, binary.BigEndian, t.FriendlyFire); err != nil {
			return err
		}

	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = packets.WriteString(ww, t.NameTagVisibility); err != nil {
			return err
		}
	}
	if t.Mode == 0 || t.Mode == 2 {
		if err = binary.Write(ww, binary.BigEndian, t.Color); err != nil {
			return err
		}

	}
	if t.Mode == 0 || t.Mode == 3 || t.Mode == 4 {
		tmp0 := make([]byte, binary.MaxVarintLen64)
		tmp1 := packets.PutVarint(tmp0, int64(len(t.Players)))
		if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
			return err
		}

		for tmp2 := range t.Players {
			if err = packets.WriteString(ww, t.Players[tmp2]); err != nil {
				return err
			}
		}
	}
	return
}
func (t *Respawn) Encode(ww io.Writer) (err error) {
	if err = binary.Write(ww, binary.BigEndian, t.Dimension); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.Difficulty); err != nil {
		return err
	}

	if err = binary.Write(ww, binary.BigEndian, t.Gamemode); err != nil {
		return err
	}

	if err = packets.WriteString(ww, t.LevelType); err != nil {
		return err
	}
	return
}
Exemple #14
0
func (t *Handshake) Encode(ww io.Writer) (err error) {
	tmp0 := make([]byte, binary.MaxVarintLen64)
	tmp1 := packets.PutVarint(tmp0, int64(t.ProtocolVersion))
	if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
		return err
	}

	if err = packets.WriteString(ww, t.Address); err != nil {
		return err
	}
	if err = binary.Write(ww, binary.BigEndian, t.Port); err != nil {
		return err
	}

	tmp2 := make([]byte, binary.MaxVarintLen64)
	tmp3 := packets.PutVarint(tmp2, int64(t.NextState))
	if err = binary.Write(ww, binary.BigEndian, tmp2[:tmp3]); err != nil {
		return err
	}

	return
}
func (t *EncryptionRequest) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.ServerID); err != nil {
		return err
	}
	tmp0 := make([]byte, binary.MaxVarintLen64)
	tmp1 := packets.PutVarint(tmp0, int64(len(t.PublicKey)))
	if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
		return err
	}

	if _, err = ww.Write(t.PublicKey); err != nil {
		return err
	}
	tmp2 := make([]byte, binary.MaxVarintLen64)
	tmp3 := packets.PutVarint(tmp2, int64(len(t.VerifyToken)))
	if err = binary.Write(ww, binary.BigEndian, tmp2[:tmp3]); err != nil {
		return err
	}

	if _, err = ww.Write(t.VerifyToken); err != nil {
		return err
	}
	return
}
func (t *PlayerListItem) Encode(ww io.Writer) (err error) {
	tmp0 := make([]byte, binary.MaxVarintLen64)
	tmp1 := packets.PutVarint(tmp0, int64(t.Action))
	if err = binary.Write(ww, binary.BigEndian, tmp0[:tmp1]); err != nil {
		return err
	}

	tmp2 := make([]byte, binary.MaxVarintLen64)
	tmp3 := packets.PutVarint(tmp2, int64(t.NumPlayers))
	if err = binary.Write(ww, binary.BigEndian, tmp2[:tmp3]); err != nil {
		return err
	}

	tmp4 := make([]byte, binary.MaxVarintLen64)
	tmp5 := packets.PutVarint(tmp4, int64(len(t.Players)))
	if err = binary.Write(ww, binary.BigEndian, tmp4[:tmp5]); err != nil {
		return err
	}

	for tmp6 := range t.Players {
		if err = binary.Write(ww, binary.BigEndian, t.Players[tmp6].UUID[:]); err != nil {
			return err
		}

		if err = packets.WriteString(ww, t.Players[tmp6].Name); err != nil {
			return err
		}
		tmp7 := make([]byte, binary.MaxVarintLen64)
		tmp8 := packets.PutVarint(tmp7, int64(len(t.Players[tmp6].Properties)))
		if err = binary.Write(ww, binary.BigEndian, tmp7[:tmp8]); err != nil {
			return err
		}

		for tmp9 := range t.Players[tmp6].Properties {
			if err = packets.WriteString(ww, t.Players[tmp6].Properties[tmp9].Name); err != nil {
				return err
			}
			if err = packets.WriteString(ww, t.Players[tmp6].Properties[tmp9].Value); err != nil {
				return err
			}
			if err = packets.WriteBool(ww, t.Players[tmp6].Properties[tmp9].Signed); err != nil {
				return err
			}
			if t.Players[tmp6].Properties[tmp9].Signed {
				if err = packets.WriteString(ww, t.Players[tmp6].Properties[tmp9].Signature); err != nil {
					return err
				}
			}
		}
		tmp10 := make([]byte, binary.MaxVarintLen64)
		tmp11 := packets.PutVarint(tmp10, int64(t.Players[tmp6].Gamemode))
		if err = binary.Write(ww, binary.BigEndian, tmp10[:tmp11]); err != nil {
			return err
		}

		tmp12 := make([]byte, binary.MaxVarintLen64)
		tmp13 := packets.PutVarint(tmp12, int64(t.Players[tmp6].Ping))
		if err = binary.Write(ww, binary.BigEndian, tmp12[:tmp13]); err != nil {
			return err
		}

		if err = packets.WriteBool(ww, t.Players[tmp6].HasDisplayName); err != nil {
			return err
		}
		if t.Players[tmp6].HasDisplayName {
			var tmp14 []byte
			if tmp14, err = json.Marshal(&t.Players[tmp6].DisplayName); err != nil {
				return err
			}
			if err = packets.WriteString(ww, string(tmp14)); err != nil {
				return err
			}
		}
	}
	return
}
func (t *ClientMessage) Encode(ww io.Writer) (err error) {
	if err = packets.WriteString(ww, t.Message); err != nil {
		return err
	}
	return
}