From 527c538cb75f7d033ea9ae36bde00695b52ded08 Mon Sep 17 00:00:00 2001 From: T14Raptor Date: Tue, 28 May 2024 14:11:07 -0400 Subject: [PATCH 1/8] nbtconv/read.go: Made Slice method generic. --- server/block/banner.go | 2 +- server/block/barrel.go | 2 +- server/block/blast_furnace.go | 2 +- server/block/chest.go | 2 +- server/block/decorated_pot.go | 4 ++-- server/block/furnace.go | 2 +- server/block/smoker.go | 2 +- server/internal/nbtconv/read.go | 8 ++++---- server/item/creative/creative.go | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/block/banner.go b/server/block/banner.go index ad265fa2c..d9cebdf88 100644 --- a/server/block/banner.go +++ b/server/block/banner.go @@ -105,7 +105,7 @@ func (b Banner) EncodeNBT() map[string]any { func (b Banner) DecodeNBT(m map[string]any) any { b.Colour = invertColourID(int16(nbtconv.Int32(m, "Base"))) b.Illager = nbtconv.Int32(m, "Type") == 1 - if patterns := nbtconv.Slice(m, "Patterns"); patterns != nil { + if patterns := nbtconv.Slice[any](m, "Patterns"); patterns != nil { b.Patterns = make([]BannerPatternLayer, len(patterns)) for i, p := range b.Patterns { b.Patterns[i] = p.DecodeNBT(patterns[i].(map[string]any)).(BannerPatternLayer) diff --git a/server/block/barrel.go b/server/block/barrel.go index 749f9a1ec..3558ec1ff 100644 --- a/server/block/barrel.go +++ b/server/block/barrel.go @@ -144,7 +144,7 @@ func (b Barrel) DecodeNBT(data map[string]any) any { b = NewBarrel() b.Facing = facing b.CustomName = nbtconv.String(data, "CustomName") - nbtconv.InvFromNBT(b.inventory, nbtconv.Slice(data, "Items")) + nbtconv.InvFromNBT(b.inventory, nbtconv.Slice[any](data, "Items")) return b } diff --git a/server/block/blast_furnace.go b/server/block/blast_furnace.go index 46956479d..e194f74f2 100644 --- a/server/block/blast_furnace.go +++ b/server/block/blast_furnace.go @@ -116,7 +116,7 @@ func (b BlastFurnace) DecodeNBT(data map[string]interface{}) interface{} { b.Lit = lit b.setExperience(xp) b.setDurations(remaining, maximum, cook) - nbtconv.InvFromNBT(b.Inventory(), nbtconv.Slice(data, "Items")) + nbtconv.InvFromNBT(b.Inventory(), nbtconv.Slice[any](data, "Items")) return b } diff --git a/server/block/chest.go b/server/block/chest.go index 0dc5c07b6..db723f75b 100644 --- a/server/block/chest.go +++ b/server/block/chest.go @@ -155,7 +155,7 @@ func (c Chest) DecodeNBT(data map[string]any) any { c = NewChest() c.Facing = facing c.CustomName = nbtconv.String(data, "CustomName") - nbtconv.InvFromNBT(c.inventory, nbtconv.Slice(data, "Items")) + nbtconv.InvFromNBT(c.inventory, nbtconv.Slice[any](data, "Items")) return c } diff --git a/server/block/decorated_pot.go b/server/block/decorated_pot.go index 62f67e1a3..ef126f3f3 100644 --- a/server/block/decorated_pot.go +++ b/server/block/decorated_pot.go @@ -83,9 +83,9 @@ func (p DecoratedPot) EncodeNBT() map[string]any { // DecodeNBT ... func (p DecoratedPot) DecodeNBT(data map[string]any) any { p.Decorations = [4]PotDecoration{} - if sherds := nbtconv.Slice(data, "sherds"); sherds != nil { + if sherds := nbtconv.Slice[string](data, "sherds"); sherds != nil { for i, name := range sherds { - it, ok := world.ItemByName(name.(string), 0) + it, ok := world.ItemByName(name, 0) if !ok { panic(fmt.Errorf("unknown item %s", name)) } diff --git a/server/block/furnace.go b/server/block/furnace.go index f7e664e3d..4c758bc64 100644 --- a/server/block/furnace.go +++ b/server/block/furnace.go @@ -115,7 +115,7 @@ func (f Furnace) DecodeNBT(data map[string]interface{}) interface{} { f.Lit = lit f.setExperience(xp) f.setDurations(remaining, maximum, cook) - nbtconv.InvFromNBT(f.Inventory(), nbtconv.Slice(data, "Items")) + nbtconv.InvFromNBT(f.Inventory(), nbtconv.Slice[any](data, "Items")) return f } diff --git a/server/block/smoker.go b/server/block/smoker.go index 94c2f8e8d..da94ea200 100644 --- a/server/block/smoker.go +++ b/server/block/smoker.go @@ -116,7 +116,7 @@ func (s Smoker) DecodeNBT(data map[string]interface{}) interface{} { s.Lit = lit s.setExperience(xp) s.setDurations(remaining, maximum, cook) - nbtconv.InvFromNBT(s.Inventory(), nbtconv.Slice(data, "Items")) + nbtconv.InvFromNBT(s.Inventory(), nbtconv.Slice[any](data, "Items")) return s } diff --git a/server/internal/nbtconv/read.go b/server/internal/nbtconv/read.go index a935ebfed..3263dda0d 100644 --- a/server/internal/nbtconv/read.go +++ b/server/internal/nbtconv/read.go @@ -80,9 +80,9 @@ func Float64(m map[string]any, k string) float64 { return v } -// Slice reads a []any value from a map at key k. -func Slice(m map[string]any, k string) []any { - v, _ := m[k].([]any) +// Slice reads a []T value from a map at key k. +func Slice[T any](m map[string]any, k string) []T { + v, _ := m[k].([]T) return v } @@ -242,7 +242,7 @@ func readArmourTrim(m map[string]any, s *item.Stack) { func readEnchantments(m map[string]any, s *item.Stack) { enchantments, ok := m["ench"].([]map[string]any) if !ok { - for _, e := range Slice(m, "ench") { + for _, e := range Slice[any](m, "ench") { if v, ok := e.(map[string]any); ok { enchantments = append(enchantments, v) } diff --git a/server/item/creative/creative.go b/server/item/creative/creative.go index e2e62ba60..9d3507cab 100644 --- a/server/item/creative/creative.go +++ b/server/item/creative/creative.go @@ -80,7 +80,7 @@ func init() { st := item.NewStack(it, 1) if len(data.NBT) > 0 { var invalid bool - for _, e := range nbtconv.Slice(data.NBT, "ench") { + for _, e := range nbtconv.Slice[any](data.NBT, "ench") { if v, ok := e.(map[string]any); ok { t, ok := item.EnchantmentByID(int(nbtconv.Int16(v, "id"))) if !ok { From 7a45453ea2bc80162dd948cc957dd447f43bce80 Mon Sep 17 00:00:00 2001 From: Darya Markova <122279000+Dasciam@users.noreply.github.com> Date: Wed, 29 May 2024 07:02:14 +0500 Subject: [PATCH 2/8] entity: Remove enchantment glint from splash/lingering potions This matches vanilla Minecraft since the enchantment glint was removed from potions in v1.19.80 --- server/entity/lingering_potion.go | 1 - server/entity/splash_potion.go | 1 - 2 files changed, 2 deletions(-) diff --git a/server/entity/lingering_potion.go b/server/entity/lingering_potion.go index c5f74831d..a359c9007 100644 --- a/server/entity/lingering_potion.go +++ b/server/entity/lingering_potion.go @@ -29,7 +29,6 @@ type LingeringPotionType struct{} func (LingeringPotionType) EncodeEntity() string { return "minecraft:lingering_potion" } -func (LingeringPotionType) Glint() bool { return true } func (LingeringPotionType) BBox(world.Entity) cube.BBox { return cube.Box(-0.125, 0, -0.125, 0.125, 0.25, 0.125) } diff --git a/server/entity/splash_potion.go b/server/entity/splash_potion.go index a47484dff..03ea38338 100644 --- a/server/entity/splash_potion.go +++ b/server/entity/splash_potion.go @@ -34,7 +34,6 @@ var splashPotionConf = ProjectileBehaviourConfig{ type SplashPotionType struct{} func (SplashPotionType) EncodeEntity() string { return "minecraft:splash_potion" } -func (SplashPotionType) Glint() bool { return true } func (SplashPotionType) BBox(world.Entity) cube.BBox { return cube.Box(-0.125, 0, -0.125, 0.125, 0.25, 0.125) } From 1676c00cddb4aeaf7d68b7cbb97eebd1262775f1 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Wed, 29 May 2024 02:02:27 +0000 Subject: [PATCH 3/8] updated contributor list --- server/session/enchantment_texts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/session/enchantment_texts.go b/server/session/enchantment_texts.go index ea431b8d2..bca9a9ddc 100644 --- a/server/session/enchantment_texts.go +++ b/server/session/enchantment_texts.go @@ -4,4 +4,4 @@ package session // enchantNames are names translated to the 'Standard Galactic Alphabet' client-side. The names generally have no meaning // on the vanilla server implementation, so we can sneak some easter eggs in here without anyone noticing. -var enchantNames = []string{"abimek", "aericio", "aimjel", "alvin0319", "andreas hgk", "atm85", "blackjack200", "da pig guy", "daft0175", "deniel world", "didntpot", "eminarican", "endermanbugzjfc", "erkam246", "flonja", "hashim the arab", "hochbaum", "hyper flare mc", "im da real ani", "its zodia x", "ivan craft623", "javier leon9966", "just tal develops", "liatoast", "mmm545", "mohamed587100", "myma qc", "natuyasai natuo", "neutronic mc", "nonono697", "provsalt", "restart fu", "riccskn", "robertdudaa", "royal mcpe", "sallypemdas", "sandertv", "sculas", "sqmatheus", "ssaini123456", "t14 raptor", "tadhunt", "thunder33345", "tristanmorgan", "twisted asylum mc", "unickorn", "unknown ore", "uramnoil", "wqrro", "x natsuri", "x4caa", "xd-pro"} +var enchantNames = []string{"abimek", "aericio", "aimjel", "alvin0319", "andreas hgk", "atm85", "blackjack200", "da pig guy", "daft0175", "dasciam", "deniel world", "didntpot", "eminarican", "endermanbugzjfc", "erkam246", "flonja", "hashim the arab", "hochbaum", "hyper flare mc", "im da real ani", "its zodia x", "ivan craft623", "javier leon9966", "just tal develops", "liatoast", "mmm545", "mohamed587100", "myma qc", "natuyasai natuo", "neutronic mc", "nonono697", "provsalt", "restart fu", "riccskn", "robertdudaa", "royal mcpe", "sallypemdas", "sandertv", "sculas", "sqmatheus", "ssaini123456", "t14 raptor", "tadhunt", "thunder33345", "tristanmorgan", "twisted asylum mc", "unickorn", "unknown ore", "uramnoil", "wqrro", "x natsuri", "x4caa", "xd-pro"} From 3ce1c0752c1b447ee70e4a905251f154a8f9fe5c Mon Sep 17 00:00:00 2001 From: Ali <47182802+UnknownOre@users.noreply.github.com> Date: Wed, 29 May 2024 05:34:12 +0300 Subject: [PATCH 4/8] inventory/inventory.go: Clear inventory slot when item is entirely removed --- server/item/inventory/inventory.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/item/inventory/inventory.go b/server/item/inventory/inventory.go index 3cf60757d..005324d1e 100644 --- a/server/item/inventory/inventory.go +++ b/server/item/inventory/inventory.go @@ -218,7 +218,15 @@ func (inv *Inventory) RemoveItemFunc(n int, comparable func(stack item.Stack) bo if slotIt.Empty() || !comparable(slotIt) { continue } - f := inv.setItem(slot, slotIt.Grow(-n)) + c := slotIt.Count() - n + + var f func() + if c <= 0 { + f = inv.setItem(slot, item.Stack{}) + } else { + f = inv.setItem(slot, slotIt.Grow(-n)) + } + //noinspection GoDeferInLoop defer f() From 73a6977d94dafdba963abac32e8e4d86c541eae2 Mon Sep 17 00:00:00 2001 From: Raptor Date: Tue, 28 May 2024 22:44:14 -0400 Subject: [PATCH 5/8] world/world.go: Lazily init NBTers on block read. (#663) --- server/world/world.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/world/world.go b/server/world/world.go index f8bb440b6..dd2cbd107 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -116,7 +116,6 @@ func (w *World) Block(pos cube.Pos) Block { return air() } c := w.chunk(chunkPosFromBlockPos(pos)) - defer c.Unlock() rid := c.Block(uint8(pos[0]), int16(pos[1]), uint8(pos[2]), 0) if nbtBlocks[rid] { @@ -124,7 +123,17 @@ func (w *World) Block(pos cube.Pos) Block { if nbtB, ok := c.BlockEntities[pos]; ok { return nbtB } + b, _ := BlockByRuntimeID(rid) + nbtB := b.(NBTer).DecodeNBT(map[string]any{}).(Block) + c.e[pos] = nbtB + viewers := slices.Clone(c.v) + c.Unlock() + for _, v := range viewers { + v.ViewBlockUpdate(pos, nbtB, 0) + } + return nbtB } + c.Unlock() b, _ := BlockByRuntimeID(rid) return b } From 7258fa2cff210cc9d31806609411cd493c4e24ec Mon Sep 17 00:00:00 2001 From: T14Raptor Date: Tue, 28 May 2024 22:48:08 -0400 Subject: [PATCH 6/8] world/world.go: Updated code from last commit. --- server/world/world.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/world/world.go b/server/world/world.go index dd2cbd107..426155138 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -125,8 +125,8 @@ func (w *World) Block(pos cube.Pos) Block { } b, _ := BlockByRuntimeID(rid) nbtB := b.(NBTer).DecodeNBT(map[string]any{}).(Block) - c.e[pos] = nbtB - viewers := slices.Clone(c.v) + c.BlockEntities[pos] = nbtB + viewers := slices.Clone(c.viewers) c.Unlock() for _, v := range viewers { v.ViewBlockUpdate(pos, nbtB, 0) From 1bc1489dbbf0aece4bebbd2f9587bf443fc467e9 Mon Sep 17 00:00:00 2001 From: Jon <86489758+xNatsuri@users.noreply.github.com> Date: Tue, 28 May 2024 20:49:47 -0700 Subject: [PATCH 7/8] item/smithing_template_type.go: Fix missing "rib" case in `FromString` --- server/item/smithing_template_type.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/item/smithing_template_type.go b/server/item/smithing_template_type.go index db796d19f..75d2eb481 100644 --- a/server/item/smithing_template_type.go +++ b/server/item/smithing_template_type.go @@ -208,6 +208,8 @@ func ArmourSmithingTemplateFromString(name string) ArmourSmithingTemplate { return TemplateTide() case "snout": return TemplateSnout() + case "rib": + return TemplateRib() case "eye": return TemplateEye() case "spire": From 6ae0370388f46d3ec519a701a56a70184505c5ad Mon Sep 17 00:00:00 2001 From: T14Raptor Date: Wed, 29 May 2024 00:10:52 -0400 Subject: [PATCH 8/8] world/world.go: Fixed deadlock. i am dumb --- server/world/world.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/world/world.go b/server/world/world.go index 426155138..fed71a25d 100644 --- a/server/world/world.go +++ b/server/world/world.go @@ -121,6 +121,7 @@ func (w *World) Block(pos cube.Pos) Block { if nbtBlocks[rid] { // The block was also a block entity, so we look it up in the block entity map. if nbtB, ok := c.BlockEntities[pos]; ok { + c.Unlock() return nbtB } b, _ := BlockByRuntimeID(rid)