Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes to the creative inventory #581

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# players to the server list directly.
ShutdownMessage = "Server closed."
# AuthEnabled controls whether or not players must be connected to Xbox Live in order to join the server.
AuthEnabled = true
AuthEnabled = false
JustTalDevelops marked this conversation as resolved.
Show resolved Hide resolved
# JoinMessage is the message that appears when a player joins the server. Leave this empty to disable it.
# %v is the placeholder for the username of the player. Set this to "" to disable.
JoinMessage = "%v has joined the game"
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/df-mc/goleveldb v1.1.9
github.com/go-gl/mathgl v1.0.0
github.com/google/uuid v1.3.0
github.com/kr/pretty v0.1.0
github.com/pelletier/go-toml v1.9.4
github.com/rogpeppe/go-internal v1.3.0
github.com/sandertv/gophertunnel v1.22.3
Expand All @@ -22,6 +23,7 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
github.com/sandertv/go-raknet v1.11.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A=
github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/muhammadmuzzammil1998/jsonc v1.0.0 h1:8o5gBQn4ZA3NBA9DlTujCj2a4w0tqWrPVjDwhzkgTIs=
github.com/muhammadmuzzammil1998/jsonc v1.0.0/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
Expand Down
36 changes: 32 additions & 4 deletions server/block/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (b Banner) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:standing_banner", map[string]any{"ground_sign_direction": int32(b.Attach.o)}
}

// EncodeNBT ...
func (b Banner) EncodeNBT() map[string]any {
// EncodeBlockNBT ...
func (b Banner) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
patterns := make([]any, 0, len(b.Patterns))
for _, p := range b.Patterns {
patterns = append(patterns, p.EncodeNBT())
Expand All @@ -100,8 +100,8 @@ func (b Banner) EncodeNBT() map[string]any {
}
}

// DecodeNBT ...
func (b Banner) DecodeNBT(data map[string]any) any {
// DecodeBlockNBT ...
func (b Banner) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
b.Colour = invertColourID(int16(nbtconv.Map[int32](data, "Base")))
b.Illager = nbtconv.Map[int32](data, "Type") == 1
if patterns, ok := data["Patterns"].([]any); ok {
Expand All @@ -113,6 +113,34 @@ func (b Banner) DecodeNBT(data map[string]any) any {
return b
}
Sandertv marked this conversation as resolved.
Show resolved Hide resolved

// EncodeItemNBT ...
func (b Banner) EncodeItemNBT() map[string]any {
data := map[string]any{}
if b.Illager {
data["Type"] = int32(1)
}
if len(b.Patterns) > 0 {
patterns := make([]any, 0, len(b.Patterns))
for _, p := range b.Patterns {
patterns = append(patterns, p.EncodeNBT())
}
data["Patterns"] = patterns
}
return data
}

// DecodeItemNBT ...
func (b Banner) DecodeItemNBT(data map[string]any) any {
b.Illager = nbtconv.Map[int32](data, "Type") == 1
if patterns, ok := data["Patterns"].([]any); ok {
b.Patterns = make([]BannerPatternLayer, len(patterns))
for i, p := range b.Patterns {
b.Patterns[i] = p.DecodeNBT(patterns[i].(map[string]any)).(BannerPatternLayer)
}
}
return b
}

// invertColour converts the item.Colour passed and returns the colour ID inverted.
func invertColour(c item.Colour) int16 {
return ^int16(c.Uint8()) & 0xf
Expand Down
8 changes: 4 additions & 4 deletions server/block/barrel.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func (Barrel) FuelInfo() item.FuelInfo {
return newFuelInfo(time.Second * 15)
}

// DecodeNBT ...
func (b Barrel) DecodeNBT(data map[string]any) any {
// DecodeBlockNBT ...
func (b Barrel) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
facing := b.Facing
//noinspection GoAssignmentToReceiver
b = NewBarrel()
Expand All @@ -148,8 +148,8 @@ func (b Barrel) DecodeNBT(data map[string]any) any {
return b
}

// EncodeNBT ...
func (b Barrel) EncodeNBT() map[string]any {
// EncodeBlockNBT ...
func (b Barrel) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
if b.inventory == nil {
facing, customName := b.Facing, b.CustomName
//noinspection GoAssignmentToReceiver
Expand Down
8 changes: 4 additions & 4 deletions server/block/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (b Beacon) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User,
return true
}

// DecodeNBT ...
func (b Beacon) DecodeNBT(data map[string]any) any {
// DecodeBlockNBT ...
func (b Beacon) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
b.level = int(nbtconv.Map[int32](data, "Levels"))
if primary, ok := effect.ByID(int(nbtconv.Map[int32](data, "Primary"))); ok {
b.Primary = primary.(effect.LastingType)
Expand All @@ -59,8 +59,8 @@ func (b Beacon) DecodeNBT(data map[string]any) any {
return b
}

// EncodeNBT ...
func (b Beacon) EncodeNBT() map[string]any {
// EncodeBlockNBT ...
func (b Beacon) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
m := map[string]any{
"id": "Beacon",
"Levels": int32(b.level),
Expand Down
16 changes: 8 additions & 8 deletions server/block/blast_furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func (b BlastFurnace) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (b BlastFurnace) EncodeBlock() (name string, properties map[string]interface{}) {
func (b BlastFurnace) EncodeBlock() (name string, properties map[string]any) {
if b.Lit {
return "minecraft:lit_blast_furnace", map[string]interface{}{"facing_direction": int32(b.Facing)}
return "minecraft:lit_blast_furnace", map[string]any{"facing_direction": int32(b.Facing)}
}
return "minecraft:blast_furnace", map[string]interface{}{"facing_direction": int32(b.Facing)}
return "minecraft:blast_furnace", map[string]any{"facing_direction": int32(b.Facing)}
}

// UseOnBlock ...
Expand Down Expand Up @@ -85,14 +85,14 @@ func (b BlastFurnace) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item
return false
}

// EncodeNBT ...
func (b BlastFurnace) EncodeNBT() map[string]interface{} {
// EncodeBlockNBT ...
func (b BlastFurnace) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
if b.smelter == nil {
//noinspection GoAssignmentToReceiver
b = NewBlastFurnace(b.Facing)
}
remaining, maximum, cook := b.Durations()
return map[string]interface{}{
return map[string]any{
"BurnTime": int16(remaining.Milliseconds() / 50),
"CookTime": int16(cook.Milliseconds() / 50),
"BurnDuration": int16(maximum.Milliseconds() / 50),
Expand All @@ -102,8 +102,8 @@ func (b BlastFurnace) EncodeNBT() map[string]interface{} {
}
}

// DecodeNBT ...
func (b BlastFurnace) DecodeNBT(data map[string]interface{}) interface{} {
// DecodeBlockNBT ...
func (b BlastFurnace) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
remaining := time.Duration(nbtconv.Map[int16](data, "BurnTime")) * time.Millisecond * 50
maximum := time.Duration(nbtconv.Map[int16](data, "BurnDuration")) * time.Millisecond * 50
cook := time.Duration(nbtconv.Map[int16](data, "CookTime")) * time.Millisecond * 50
Expand Down
7 changes: 7 additions & 0 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ type Frictional interface {
Friction() float64
}

var (
// unknownDirection is a direction that is used for certain block items. This should not be exposed in the API.
unknownDirection = cube.Direction(len(cube.Directions()))
// unknownFace is a face that is used for certain block items. This should not be exposed in the API.
unknownFace = cube.Face(len(cube.Faces()))
)

func calculateFace(user item.User, placePos cube.Pos) cube.Face {
userPos := user.Position()
pos := cube.PosFromVec3(userPos)
Expand Down
13 changes: 8 additions & 5 deletions server/block/chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func (c Chest) FlammabilityInfo() FlammabilityInfo {
return newFlammabilityInfo(0, 0, true)
}

// DecodeNBT ...
func (c Chest) DecodeNBT(data map[string]any) any {
// DecodeBlockNBT ...
func (c Chest) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
facing := c.Facing
//noinspection GoAssignmentToReceiver
c = NewChest()
Expand All @@ -159,8 +159,8 @@ func (c Chest) DecodeNBT(data map[string]any) any {
return c
}

// EncodeNBT ...
func (c Chest) EncodeNBT() map[string]any {
// EncodeBlockNBT ...
func (c Chest) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
if c.inventory == nil {
facing, customName := c.Facing, c.CustomName
//noinspection GoAssignmentToReceiver
Expand All @@ -184,12 +184,15 @@ func (Chest) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (c Chest) EncodeBlock() (name string, properties map[string]any) {
if c.Facing == unknownDirection {
return "minecraft:chest", map[string]any{"facing_direction": int32(0)}
}
return "minecraft:chest", map[string]any{"facing_direction": 2 + int32(c.Facing)}
}

// allChests ...
func allChests() (chests []world.Block) {
for _, direction := range cube.Directions() {
for _, direction := range append(cube.Directions(), unknownDirection) {
chests = append(chests, Chest{Facing: direction})
}
return
Expand Down
2 changes: 1 addition & 1 deletion server/block/crafting_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (c CraftingTable) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (c CraftingTable) EncodeBlock() (name string, properties map[string]interface{}) {
func (c CraftingTable) EncodeBlock() (name string, properties map[string]any) {
return "minecraft:crafting_table", nil
}

Expand Down
6 changes: 4 additions & 2 deletions server/block/cube/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (f Face) Direction() Direction {
// and vice versa.
func (f Face) Opposite() Face {
switch f {
default:
case FaceDown:
return FaceUp
case FaceUp:
return FaceDown
Expand All @@ -41,19 +41,21 @@ func (f Face) Opposite() Face {
case FaceEast:
return FaceWest
}
panic("invalid face")
}

// Axis returns the axis the face is facing. FaceEast and west correspond to the x-axis, north and south to the z
// axis and up and down to the y-axis.
func (f Face) Axis() Axis {
switch f {
default:
case FaceDown, FaceUp:
return Y
case FaceEast, FaceWest:
return X
case FaceNorth, FaceSouth:
return Z
}
panic("invalid face")
}

// RotateRight rotates the face 90 degrees to the right horizontally and returns the new face.
Expand Down
11 changes: 6 additions & 5 deletions server/block/enchanting_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ func (EnchantingTable) EncodeBlock() (string, map[string]any) {
return "minecraft:enchanting_table", nil
}

// EncodeNBT is used to encode the block to NBT, so that the enchanting table book will be rendered properly client-side.
// The actual rotation value doesn't need to be set in the NBT, we just need to write the default NBT for the block.
func (e EnchantingTable) EncodeNBT() map[string]any {
// EncodeBlockNBT is used to encode the block to NBT, so that the enchanting table book will be rendered properly
// client-side. The actual rotation value doesn't need to be set in the NBT, we just need to write the default NBT for
// the block.
func (e EnchantingTable) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
return map[string]any{"id": "EnchantTable"}
}

// DecodeNBT is used to implement world.NBTer.
func (e EnchantingTable) DecodeNBT(map[string]any) any {
// DecodeBlockNBT is used to implement world.NBTer.
func (e EnchantingTable) DecodeBlockNBT(cube.Pos, *world.World, map[string]any) any {
return e
}
19 changes: 11 additions & 8 deletions server/block/ender_chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func (c EnderChest) close(w *world.World, pos cube.Pos) {
w.PlaySound(pos.Vec3Centre(), sound.ChestClose{})
}

// EncodeNBT ...
func (c EnderChest) EncodeNBT() map[string]interface{} {
return map[string]interface{}{"id": "EnderChest"}
// EncodeBlockNBT ...
func (c EnderChest) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
return map[string]any{"id": "EnderChest"}
}

// DecodeNBT ...
func (c EnderChest) DecodeNBT(map[string]interface{}) interface{} {
// DecodeBlockNBT ...
func (c EnderChest) DecodeBlockNBT(cube.Pos, *world.World, map[string]any) any {
return NewEnderChest()
}

Expand All @@ -122,13 +122,16 @@ func (EnderChest) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (c EnderChest) EncodeBlock() (name string, properties map[string]interface{}) {
return "minecraft:ender_chest", map[string]interface{}{"facing_direction": 2 + int32(c.Facing)}
func (c EnderChest) EncodeBlock() (name string, properties map[string]any) {
if c.Facing == unknownDirection {
return "minecraft:ender_chest", map[string]any{"facing_direction": int32(0)}
}
return "minecraft:ender_chest", map[string]any{"facing_direction": 2 + int32(c.Facing)}
}

// allEnderChests ...
func allEnderChests() (chests []world.Block) {
for _, direction := range cube.Directions() {
for _, direction := range append(cube.Directions(), unknownDirection) {
chests = append(chests, EnderChest{Facing: direction})
}
return
Expand Down
16 changes: 8 additions & 8 deletions server/block/furnace.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (f Furnace) EncodeItem() (name string, meta int16) {
}

// EncodeBlock ...
func (f Furnace) EncodeBlock() (name string, properties map[string]interface{}) {
func (f Furnace) EncodeBlock() (name string, properties map[string]any) {
if f.Lit {
return "minecraft:lit_furnace", map[string]interface{}{"facing_direction": int32(f.Facing)}
return "minecraft:lit_furnace", map[string]any{"facing_direction": int32(f.Facing)}
}
return "minecraft:furnace", map[string]interface{}{"facing_direction": int32(f.Facing)}
return "minecraft:furnace", map[string]any{"facing_direction": int32(f.Facing)}
}

// UseOnBlock ...
Expand Down Expand Up @@ -84,14 +84,14 @@ func (f Furnace) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User
return false
}

// EncodeNBT ...
func (f Furnace) EncodeNBT() map[string]interface{} {
// EncodeBlockNBT ...
func (f Furnace) EncodeBlockNBT(cube.Pos, *world.World) map[string]any {
if f.smelter == nil {
//noinspection GoAssignmentToReceiver
f = NewFurnace(f.Facing)
}
remaining, maximum, cook := f.Durations()
return map[string]interface{}{
return map[string]any{
"BurnTime": int16(remaining.Milliseconds() / 50),
"CookTime": int16(cook.Milliseconds() / 50),
"BurnDuration": int16(maximum.Milliseconds() / 50),
Expand All @@ -101,8 +101,8 @@ func (f Furnace) EncodeNBT() map[string]interface{} {
}
}

// DecodeNBT ...
func (f Furnace) DecodeNBT(data map[string]interface{}) interface{} {
// DecodeBlockNBT ...
func (f Furnace) DecodeBlockNBT(_ cube.Pos, _ *world.World, data map[string]any) any {
remaining := time.Duration(nbtconv.Map[int16](data, "BurnTime")) * time.Millisecond * 50
maximum := time.Duration(nbtconv.Map[int16](data, "BurnDuration")) * time.Millisecond * 50
cook := time.Duration(nbtconv.Map[int16](data, "CookTime")) * time.Millisecond * 50
Expand Down
5 changes: 4 additions & 1 deletion server/block/glazed_terracotta.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func (t GlazedTerracotta) EncodeItem() (name string, meta int16) {

// EncodeBlock ...
func (t GlazedTerracotta) EncodeBlock() (name string, properties map[string]any) {
if t.Facing == unknownDirection {
return "minecraft:" + t.Colour.String() + "_glazed_terracotta", map[string]any{"facing_direction": int32(0)}
}
return "minecraft:" + t.Colour.String() + "_glazed_terracotta", map[string]any{"facing_direction": int32(2 + t.Facing)}
}

Expand All @@ -47,7 +50,7 @@ func (t GlazedTerracotta) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3,

// allGlazedTerracotta returns glazed terracotta blocks with all possible colours.
func allGlazedTerracotta() (b []world.Block) {
for dir := cube.Direction(0); dir < 4; dir++ {
for _, dir := range append(cube.Directions(), unknownDirection) {
for _, c := range item.Colours() {
b = append(b, GlazedTerracotta{Colour: c, Facing: dir})
}
Expand Down
Loading