Skip to content

Commit

Permalink
1.21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Jun 17, 2024
1 parent e97381a commit a09ea2e
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
35 changes: 35 additions & 0 deletions pkg/edition/java/proto/packet/customreportdetails.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package packet

import (
protoutil "go.minekube.com/gate/pkg/edition/java/proto/util"
"go.minekube.com/gate/pkg/gate/proto"
"io"
)

type CustomReportDetails struct {
Details map[string]string
}

func (p *CustomReportDetails) Encode(c *proto.PacketContext, wr io.Writer) error {
w := protoutil.PanicWriter(wr)
w.VarInt(len(p.Details))
for key, value := range p.Details {
w.String(key)
w.String(value)
}
return nil
}

func (p *CustomReportDetails) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
r := protoutil.PanicReader(rd)
var detailsCount int
r.VarInt(&detailsCount)
p.Details = make(map[string]string, detailsCount)
for i := 0; i < detailsCount; i++ {
var key, value string
r.String(&key)
r.String(&value)
p.Details[key] = value
}
return
}
4 changes: 2 additions & 2 deletions pkg/edition/java/proto/packet/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (s *ServerLoginSuccess) Encode(c *proto.PacketContext, wr io.Writer) (err e
return err
}
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20_5) {
if c.Protocol == version.Minecraft_1_20_5.Protocol || c.Protocol == version.Minecraft_1_21.Protocol {
err = util.WriteBool(wr, serverLoginSuccessStrictErrorHandling)
if err != nil {
return err
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *ServerLoginSuccess) Decode(c *proto.PacketContext, rd io.Reader) (err e
return
}
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20_5) {
if c.Protocol == version.Minecraft_1_20_5.Protocol || c.Protocol == version.Minecraft_1_21.Protocol {
_, err = util.ReadBool(rd)
if err != nil {
return
Expand Down
75 changes: 75 additions & 0 deletions pkg/edition/java/proto/packet/serverlinks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package packet

import (
"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
protoutil "go.minekube.com/gate/pkg/edition/java/proto/util"
"go.minekube.com/gate/pkg/gate/proto"
"io"
)

type ServerLinks struct {
ServerLinks []*ServerLink
}

func (p *ServerLinks) Encode(c *proto.PacketContext, wr io.Writer) error {
w := protoutil.PanicWriter(wr)
w.VarInt(len(p.ServerLinks))
for _, serverLink := range p.ServerLinks {
err := serverLink.Encode(c, wr)
if err != nil {
return err
}
}
return nil
}

func (p *ServerLinks) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
r := protoutil.PanicReader(rd)
var serverLinksCount int
r.VarInt(&serverLinksCount)
p.ServerLinks = make([]*ServerLink, serverLinksCount)
for i := 0; i < serverLinksCount; i++ {
p.ServerLinks[i] = new(ServerLink)
err = p.ServerLinks[i].Decode(c, rd)
if err != nil {
return err
}
}
return
}

type ServerLink struct {
ID int
DisplayName chat.ComponentHolder
URL string
}

func (p *ServerLink) Encode(c *proto.PacketContext, wr io.Writer) error {
if p.ID >= 0 {
protoutil.PWriteBool(wr, true)
protoutil.PWriteVarInt(wr, p.ID)
} else {
protoutil.PWriteBool(wr, false)
err := p.DisplayName.Write(wr, c.Protocol)
if err != nil {
return err
}
}
return protoutil.WriteString(wr, p.URL)
}

func (p *ServerLink) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
r := protoutil.PanicReader(rd)
if r.Ok() {
r.VarInt(&p.ID)
r.String(&p.URL)
} else {
p.ID = -1
p.DisplayName, err = chat.ReadComponentHolderNP(rd, c.Protocol)
if err != nil {
return err
}
r.String(&p.URL)
}
return
}
12 changes: 12 additions & 0 deletions pkg/edition/java/proto/state/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func init() {
Config.ClientBound.Register(&config.KnownPacks{},
m(0x0E, version.Minecraft_1_20_5),
)
Config.ClientBound.Register(&p.CustomReportDetails{},
m(0x0F, version.Minecraft_1_21),
)
Config.ClientBound.Register(&p.ServerLinks{},
m(0x10, version.Minecraft_1_21),
)

Login.ServerBound.Register(&p.ServerLogin{},
m(0x00, version.Minecraft_1_7_2))
Expand Down Expand Up @@ -530,4 +536,10 @@ func init() {
Play.ClientBound.Register(&p.Transfer{},
m(0x73, version.Minecraft_1_20_5),
)
Play.ClientBound.Register(&p.CustomReportDetails{},
m(0x7A, version.Minecraft_1_21),
)
Play.ClientBound.Register(&p.ServerLinks{},
m(0x7B, version.Minecraft_1_21),
)
}
2 changes: 2 additions & 0 deletions pkg/edition/java/proto/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
Minecraft_1_20_2 = v(764, "1.20.2")
Minecraft_1_20_3 = v(765, "1.20.3", "1.20.4")
Minecraft_1_20_5 = v(766, "1.20.5", "1.20.6")
Minecraft_1_21 = v(767, "1.21")

// Versions ordered from lowest to highest
Versions = []*proto.Version{
Expand All @@ -63,6 +64,7 @@ var (
Minecraft_1_18, Minecraft_1_18_2,
Minecraft_1_19, Minecraft_1_19_1, Minecraft_1_19_3, Minecraft_1_19_4,
Minecraft_1_20, Minecraft_1_20_2, Minecraft_1_20_3, Minecraft_1_20_5,
Minecraft_1_21,
}
)

Expand Down

0 comments on commit a09ea2e

Please sign in to comment.