Move decode of complex packets into their own package

This commit is contained in:
Tom
2020-09-12 21:13:37 -07:00
parent b58d959b93
commit d3bb141fcd
7 changed files with 409 additions and 254 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/Tnze/go-mc/data"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/Tnze/go-mc/net/ptypes"
)
// SwingArm swing player's arm.
@ -83,12 +84,11 @@ func (c *Client) Chat(msg string) error {
}
// PluginMessage is used by mods and plugins to send their data.
func (c *Client) PluginMessage(channal string, msg []byte) error {
return c.conn.WritePacket(pk.Marshal(
data.CustomPayloadServerbound,
pk.Identifier(channal),
pluginMessageData(msg),
))
func (c *Client) PluginMessage(channel string, msg []byte) error {
return c.conn.WritePacket((&ptypes.PluginMessage{
Channel: pk.Identifier(channel),
Data: ptypes.PluginData(msg),
}).Encode())
}
// UseBlock is used to place or use a block.