Skip to content

Commit

Permalink
Support 1.18.2 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer authored May 1, 2022
1 parent 21e40a6 commit de4073c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/edition/java/proto/packet/available_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package packet
import (
"errors"
"fmt"
"io"

"github.com/gammazero/deque"
"go.minekube.com/brigodier"

"go.minekube.com/gate/pkg/edition/java/proto/packet/brigadier"
"go.minekube.com/gate/pkg/edition/java/proto/util"
"go.minekube.com/gate/pkg/gate/proto"
"io"
)

const (
Expand Down
20 changes: 19 additions & 1 deletion pkg/edition/java/proto/packet/brigadier/codecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package brigadier

import (
"fmt"
"io"

"go.minekube.com/brigodier"

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

// ArgumentPropertyCodecFuncs implements ArgumentPropertyCodec.
Expand Down Expand Up @@ -80,6 +82,22 @@ var (
}
},
}
RegistryKeyArgumentPropertyCodec ArgumentPropertyCodec = &ArgumentPropertyCodecFuncs{
EncodeFn: func(wr io.Writer, v interface{}) error {
i, ok := v.(*RegistryKeyArgumentType)
if !ok {
return fmt.Errorf("expected *RegistryKeyArgumentType but got %T", v)
}
return util.WriteString(wr, i.Identifier)
},
DecodeFn: func(rd io.Reader) (interface{}, error) {
id, err := util.ReadString(rd)
if err != nil {
return nil, err
}
return &RegistryKeyArgumentType{Identifier: id}, nil
},
}

Float64ArgumentPropertyCodec ArgumentPropertyCodec = &ArgumentPropertyCodecFuncs{
EncodeFn: func(wr io.Writer, v interface{}) error {
Expand Down
7 changes: 6 additions & 1 deletion pkg/edition/java/proto/packet/brigadier/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"io"

"go.minekube.com/brigodier"

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

type ArgumentPropertyCodec interface {
Expand Down Expand Up @@ -123,6 +125,9 @@ func init() {
register("brigadier:double", brigodier.Float64, Float64ArgumentPropertyCodec)
register("brigadier:bool", brigodier.Bool, BoolArgumentPropertyCodec)

register("minecraft:resource", RegistryKeyArgument, RegistryKeyArgumentPropertyCodec) // added in 1.18.2
register("minecraft:resource_or_tag", RegistryKeyArgument, RegistryKeyArgumentPropertyCodec) // added in 1.18.2 // added in 1.18.2

// Minecraft argument types with extra properties
emptyWithCodec("minecraft:entity", ByteArgumentPropertyCodec)
emptyWithCodec("minecraft:score_holder", ByteArgumentPropertyCodec)
Expand Down
17 changes: 17 additions & 0 deletions pkg/edition/java/proto/packet/brigadier/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package brigadier

import "go.minekube.com/brigodier"

var (
RegistryKeyArgument brigodier.ArgumentType = &RegistryKeyArgumentType{}
)

type RegistryKeyArgumentType struct {
Identifier string
}

func (r *RegistryKeyArgumentType) Parse(rd *brigodier.StringReader) (interface{}, error) {
return rd.ReadString()
}

func (r *RegistryKeyArgumentType) String() string { return "registry_key_argument" }
3 changes: 2 additions & 1 deletion pkg/edition/java/proto/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
Minecraft_1_17 = &proto.Version{Protocol: 755, Names: s("1.17")}
Minecraft_1_17_1 = &proto.Version{Protocol: 756, Names: s("1.17.1")}
Minecraft_1_18 = &proto.Version{Protocol: 757, Names: s("1.18", "1.18.1")}
Minecraft_1_18_2 = &proto.Version{Protocol: 758, Names: s("1.18.2")}

// Versions ordered from lowest to highest
Versions = []*proto.Version{
Expand All @@ -51,7 +52,7 @@ var (
Minecraft_1_15,
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, Minecraft_1_18_2,
}
)

Expand Down

0 comments on commit de4073c

Please sign in to comment.