Skip to content

Commit

Permalink
Add Minecraft 1.20.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Jun 12, 2023
1 parent e41e41a commit 6b33d13
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 73 deletions.
36 changes: 17 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gammazero/deque v0.2.1
github.com/go-faker/faker/v4 v4.1.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.3
github.com/go-logr/zapr v1.2.4
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/google/uuid v1.3.0
github.com/gookit/color v1.5.2
Expand All @@ -18,24 +18,25 @@ require (
github.com/robinbraemer/event v0.0.1
github.com/rs/xid v1.5.0
github.com/sandertv/go-raknet v1.12.0
github.com/sandertv/gophertunnel v1.28.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.25.1
github.com/sandertv/gophertunnel v1.30.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.3
github.com/urfave/cli/v2 v2.25.6
go.minekube.com/brigodier v0.0.1
go.minekube.com/common v0.0.5
go.minekube.com/connect v0.5.2
go.uber.org/atomic v1.10.0
go.minekube.com/connect v0.5.3
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
golang.org/x/text v0.8.0
golang.org/x/text v0.9.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.54.0
google.golang.org/grpc v1.55.0
gopkg.in/yaml.v3 v3.0.1
nhooyr.io/websocket v1.8.7
)

require (
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.30.0-20230517110945-04c17e7d2fd9.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/df-mc/atomic v1.10.0 // indirect
Expand All @@ -48,28 +49,25 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/goleak v1.1.12 // indirect
golang.org/x/image v0.6.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20230330200707-38013875ee22 // indirect
golang.org/x/image v0.7.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
90 changes: 41 additions & 49 deletions go.sum

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkg/edition/java/proto/packet/joingame.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type JoinGame struct {
PreviousGamemode int16 // 1.16+
SimulationDistance int // 1.18+
LastDeadPosition *DeathPosition // 1.19+
PortalCooldown int // 1.20+
}

type DimensionInfo struct {
Expand Down Expand Up @@ -208,6 +209,14 @@ func (j *JoinGame) encode116Up(c *proto.PacketContext, wr io.Writer) error {
return err
}
}

if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
err = util.WriteVarInt(wr, j.PortalCooldown)
if err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -477,6 +486,13 @@ func (j *JoinGame) decode116Up(c *proto.PacketContext, rd io.Reader) (err error)
return err
}
}

if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
j.PortalCooldown, err = util.ReadVarInt(rd)
if err != nil {
return err
}
}
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/edition/java/proto/packet/respawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Respawn struct {
PreviousGamemode int16 // 1.16+
CurrentDimensionData util.NBT // 1.16.2+
LastDeathPosition *DeathPosition // 1.19+
PortalCooldown int // 1.20+
}

func (r *Respawn) Encode(c *proto.PacketContext, wr io.Writer) (err error) {
Expand Down Expand Up @@ -102,6 +103,12 @@ func (r *Respawn) Encode(c *proto.PacketContext, wr io.Writer) (err error) {
return err
}
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
err = util.WriteVarInt(wr, r.PortalCooldown)
if err != nil {
return err
}
}
return nil
}

Expand Down Expand Up @@ -199,6 +206,12 @@ func (r *Respawn) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
return err
}
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
r.PortalCooldown, err = util.ReadVarInt(rd)
if err != nil {
return err
}
}
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/edition/java/proto/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
Minecraft_1_19_1 = &proto.Version{Protocol: 760, Names: s("1.19.1", "1.19.2")}
Minecraft_1_19_3 = &proto.Version{Protocol: 761, Names: s("1.19.3")}
Minecraft_1_19_4 = &proto.Version{Protocol: 762, Names: s("1.19.4")}
Minecraft_1_20 = &proto.Version{Protocol: 763, Names: s("1.20", "1.20.1")}

// Versions ordered from lowest to highest
Versions = []*proto.Version{
Expand All @@ -57,8 +58,8 @@ var (
Minecraft_1_16, Minecraft_1_16_1, Minecraft_1_16_2, Minecraft_1_16_3, Minecraft_1_16_4,
Minecraft_1_17, Minecraft_1_17_1,
Minecraft_1_18, Minecraft_1_18_2,
Minecraft_1_19, Minecraft_1_19_1, Minecraft_1_19_3,
Minecraft_1_19_4,
Minecraft_1_19, Minecraft_1_19_1, Minecraft_1_19_3, Minecraft_1_19_4,
Minecraft_1_20,
}
)

Expand Down
1 change: 1 addition & 0 deletions pkg/edition/java/proxy/session_client_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ func respawnFromJoinGame(joinGame *packet.JoinGame) *packet.Respawn {
PreviousGamemode: joinGame.PreviousGamemode,
CurrentDimensionData: joinGame.CurrentDimensionData,
LastDeathPosition: joinGame.LastDeadPosition,
PortalCooldown: joinGame.PortalCooldown,
}
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/edition/java/proxy/session_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ func (h *statusSessionHandler) HandlePacket(pc *proto.PacketContext) {
var versionName = fmt.Sprintf("Gate %s", version.SupportedVersionsString)

func newInitialPing(p *Proxy, protocol proto.Protocol) *ping.ServerPing {
shownVersion := protocol
if !version.Protocol(protocol).Supported() {
shownVersion = version.MaximumVersion.Protocol
protocol = version.MaximumVersion.Protocol
}
var modInfo *modinfo.ModInfo
if p.config().AnnounceForge {
modInfo = modinfo.Default
}
return &ping.ServerPing{
Version: ping.Version{
Protocol: shownVersion,
Protocol: protocol,
Name: versionName,
},
Players: &ping.Players{
Expand Down

0 comments on commit 6b33d13

Please sign in to comment.