Example #1
0
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
}
Example #2
0
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
}
Example #3
0
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
}