From 436ec9c010a97666cc41aa32a679101b237682ed Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 20:32:40 +0000 Subject: [PATCH 01/15] Implement curse of binding --- server/item/enchantment/curse_of_binding.go | 41 ++++++++++++++++++++ server/item/enchantment/register.go | 2 +- server/session/handler_item_stack_request.go | 26 +++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 server/item/enchantment/curse_of_binding.go diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go new file mode 100644 index 000000000..323a2e6ed --- /dev/null +++ b/server/item/enchantment/curse_of_binding.go @@ -0,0 +1,41 @@ +package enchantment + +import ( + "github.com/df-mc/dragonfly/server/item" + "github.com/df-mc/dragonfly/server/world" +) + +// Curse of Binding is an enchantment that prevents removal of a cursed item from its armour slot. +type CurseOfBinding struct{} + +// Name ... +func (CurseOfBinding) Name() string { + return "Curse of Binding" +} + +// MaxLevel ... +func (CurseOfBinding) MaxLevel() int { + return 1 +} + +// Cost ... +func (CurseOfBinding) Cost(level int) (int, int) { + return 0, 0 +} + +// Rarity ... +func (CurseOfBinding) Rarity() item.EnchantmentRarity { + return item.EnchantmentRarityCommon +} + +// CompatibleWithEnchantment ... +func (CurseOfBinding) CompatibleWithEnchantment(item.EnchantmentType) bool { + return true +} + +// CompatibleWithItem ... +func (CurseOfBinding) CompatibleWithItem(i world.Item) bool { + _, isArmour := i.(item.Armour) + + return isArmour +} diff --git a/server/item/enchantment/register.go b/server/item/enchantment/register.go index 0f22a86f6..e21083bb1 100644 --- a/server/item/enchantment/register.go +++ b/server/item/enchantment/register.go @@ -30,7 +30,7 @@ func init() { // TODO: (24) Lure. // TODO: (25) Frost Walker. item.RegisterEnchantment(26, Mending{}) - // TODO: (27) Curse of Binding. + item.RegisterEnchantment(27, CurseOfBinding{}) item.RegisterEnchantment(28, CurseOfVanishing{}) // TODO: (29) Impaling. // TODO: (30) Riptide. diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 79b40e447..1037c3db2 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -6,6 +6,7 @@ import ( "github.com/df-mc/dragonfly/server/entity" "github.com/df-mc/dragonfly/server/event" "github.com/df-mc/dragonfly/server/item" + "github.com/df-mc/dragonfly/server/item/enchantment" "github.com/df-mc/dragonfly/server/item/inventory" "github.com/go-gl/mathgl/mgl64" "github.com/sandertv/gophertunnel/minecraft/protocol" @@ -157,6 +158,15 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS if (dest.Count()+int(count) > dest.MaxCount()) && !dest.Empty() { return fmt.Errorf("client tried adding %v to item count %v, but max is %v", count, dest.Count(), dest.MaxCount()) } + + // Do not allow an equipped item cursed with binding to be transferred. + if from.ContainerID == protocol.ContainerArmor { + i, _ := h.itemInSlot(from, s) + if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { + return nil + } + } + if dest.Empty() { dest = i.Grow(-math.MaxInt32) } @@ -197,6 +207,14 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, return err } + // Do not allow an equipped item cursed with binding to be swapped out. + if a.Destination.ContainerID == protocol.ContainerArmor { + i, _ := h.itemInSlot(a.Destination, s) + if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { + return nil + } + } + h.setItemInSlot(a.Source, dest, s) h.setItemInSlot(a.Destination, i, s) h.collectRewards(s, invA, int(a.Source.Slot)) @@ -254,6 +272,14 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, return err } + // Do not allow an equipped item cursed with binding to be dropped. + if a.Source.ContainerID == protocol.ContainerArmor { + i, _ := h.itemInSlot(a.Source, s) + if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { + return nil + } + } + n := s.c.Drop(i.Grow(int(a.Count) - i.Count())) h.setItemInSlot(a.Source, i.Grow(-n), s) return nil From 64dccf61089fc9ae2a0a0966ce4be1ebfa517e92 Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 20:43:29 +0000 Subject: [PATCH 02/15] Implement creative mode bypass for curse of binding --- server/session/handler_item_stack_request.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 1037c3db2..b820fcf59 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -160,7 +160,8 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS } // Do not allow an equipped item cursed with binding to be transferred. - if from.ContainerID == protocol.ContainerArmor { + creativeMode := s.c.GameMode().CreativeInventory() + if from.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(from, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil @@ -208,7 +209,8 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, } // Do not allow an equipped item cursed with binding to be swapped out. - if a.Destination.ContainerID == protocol.ContainerArmor { + creativeMode := s.c.GameMode().CreativeInventory() + if a.Destination.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(a.Destination, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil @@ -273,7 +275,8 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, } // Do not allow an equipped item cursed with binding to be dropped. - if a.Source.ContainerID == protocol.ContainerArmor { + creativeMode := s.c.GameMode().CreativeInventory() + if a.Source.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(a.Source, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil From 08e7050c89699c96416e652af285fc9e438f6de9 Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 20:52:06 +0000 Subject: [PATCH 03/15] Implement Treasure() and Curse() functions for curse of binding type --- server/item/enchantment/curse_of_binding.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go index 323a2e6ed..ec8701e9b 100644 --- a/server/item/enchantment/curse_of_binding.go +++ b/server/item/enchantment/curse_of_binding.go @@ -39,3 +39,13 @@ func (CurseOfBinding) CompatibleWithItem(i world.Item) bool { return isArmour } + +// Treasure ... +func (CurseOfBinding) Treasure() bool { + return true +} + +// Curse ... +func (CurseOfBinding) Curse() bool { + return true +} From 49e7a49a48dccd4527656991c32517a320b3f952 Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 20:57:22 +0000 Subject: [PATCH 04/15] Change rarity of curse of binding enchantment --- server/item/enchantment/curse_of_binding.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go index ec8701e9b..f9d1b0915 100644 --- a/server/item/enchantment/curse_of_binding.go +++ b/server/item/enchantment/curse_of_binding.go @@ -25,7 +25,7 @@ func (CurseOfBinding) Cost(level int) (int, int) { // Rarity ... func (CurseOfBinding) Rarity() item.EnchantmentRarity { - return item.EnchantmentRarityCommon + return item.EnchantmentRarityVeryRare } // CompatibleWithEnchantment ... From b906658ee85108597521a5b96f1d7c651210cd14 Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 21:02:43 +0000 Subject: [PATCH 05/15] Run gofmt on changed files --- server/item/enchantment/curse_of_binding.go | 4 ++-- server/session/handler_item_stack_request.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go index f9d1b0915..5c8d55e96 100644 --- a/server/item/enchantment/curse_of_binding.go +++ b/server/item/enchantment/curse_of_binding.go @@ -42,10 +42,10 @@ func (CurseOfBinding) CompatibleWithItem(i world.Item) bool { // Treasure ... func (CurseOfBinding) Treasure() bool { - return true + return true } // Curse ... func (CurseOfBinding) Curse() bool { - return true + return true } diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index b820fcf59..e61ed3dc7 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -160,7 +160,7 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS } // Do not allow an equipped item cursed with binding to be transferred. - creativeMode := s.c.GameMode().CreativeInventory() + creativeMode := s.c.GameMode().CreativeInventory() if from.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(from, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { @@ -209,7 +209,7 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, } // Do not allow an equipped item cursed with binding to be swapped out. - creativeMode := s.c.GameMode().CreativeInventory() + creativeMode := s.c.GameMode().CreativeInventory() if a.Destination.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(a.Destination, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { @@ -275,7 +275,7 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, } // Do not allow an equipped item cursed with binding to be dropped. - creativeMode := s.c.GameMode().CreativeInventory() + creativeMode := s.c.GameMode().CreativeInventory() if a.Source.ContainerID == protocol.ContainerArmor && !creativeMode { i, _ := h.itemInSlot(a.Source, s) if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { From 684fe45c1407088fe43fc7ce8044ddba43529c39 Mon Sep 17 00:00:00 2001 From: curzodo Date: Wed, 21 Dec 2022 21:05:54 +0000 Subject: [PATCH 06/15] Fixed comment --- server/item/enchantment/curse_of_binding.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go index 5c8d55e96..ddf422c07 100644 --- a/server/item/enchantment/curse_of_binding.go +++ b/server/item/enchantment/curse_of_binding.go @@ -5,7 +5,7 @@ import ( "github.com/df-mc/dragonfly/server/world" ) -// Curse of Binding is an enchantment that prevents removal of a cursed item from its armour slot. +// CurseOfBinding is an enchantment that prevents the removal of an equipped item enchanted with the curse of binding from its armour slot. type CurseOfBinding struct{} // Name ... From df853c9c0d2ba6f2ae0ae53f7b5776c69fe8a319 Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 03:25:08 +0000 Subject: [PATCH 07/15] Make requested PR changes --- server/item/enchantment/curse_of_binding.go | 2 +- server/session/handler_item_stack_request.go | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/server/item/enchantment/curse_of_binding.go b/server/item/enchantment/curse_of_binding.go index ddf422c07..cb4d2c596 100644 --- a/server/item/enchantment/curse_of_binding.go +++ b/server/item/enchantment/curse_of_binding.go @@ -20,7 +20,7 @@ func (CurseOfBinding) MaxLevel() int { // Cost ... func (CurseOfBinding) Cost(level int) (int, int) { - return 0, 0 + return 25, 50 } // Rarity ... diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index e61ed3dc7..a7eda0c9c 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -160,9 +160,7 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS } // Do not allow an equipped item cursed with binding to be transferred. - creativeMode := s.c.GameMode().CreativeInventory() - if from.ContainerID == protocol.ContainerArmor && !creativeMode { - i, _ := h.itemInSlot(from, s) + if from.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil } @@ -209,10 +207,8 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, } // Do not allow an equipped item cursed with binding to be swapped out. - creativeMode := s.c.GameMode().CreativeInventory() - if a.Destination.ContainerID == protocol.ContainerArmor && !creativeMode { - i, _ := h.itemInSlot(a.Destination, s) - if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { + if a.Destination.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { + if _, isCursed := dest.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil } } @@ -275,9 +271,7 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, } // Do not allow an equipped item cursed with binding to be dropped. - creativeMode := s.c.GameMode().CreativeInventory() - if a.Source.ContainerID == protocol.ContainerArmor && !creativeMode { - i, _ := h.itemInSlot(a.Source, s) + if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { return nil } From 32ba0eba0e2b22041437e413d317f2962df90dd7 Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 03:35:43 +0000 Subject: [PATCH 08/15] Make requested changes --- server/item/enchantment/{vanishing.go => curse_of_vanishing.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/item/enchantment/{vanishing.go => curse_of_vanishing.go} (100%) diff --git a/server/item/enchantment/vanishing.go b/server/item/enchantment/curse_of_vanishing.go similarity index 100% rename from server/item/enchantment/vanishing.go rename to server/item/enchantment/curse_of_vanishing.go From 6245872be2ee5b3e45ba3462ef749d90c77db40a Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 04:44:53 +0000 Subject: [PATCH 09/15] Handle armour swap with right click involving curse of binding --- server/player/player.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/player/player.go b/server/player/player.go index 8c52bdbc2..444be06a1 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -2932,6 +2932,11 @@ func (p *Player) useContext() *item.UseContext { src, dst, srcInv, dstInv := int(p.heldSlot.Load()), i, p.inv, p.armour.Inventory() srcIt, _ := srcInv.Item(src) dstIt, _ := dstInv.Item(dst) + + // If dstIt is enchanted with curse of binding, do not swap. + if _, isCursed := dstIt.Enchantment(enchantment.CurseOfBinding{}); isCursed && !p.GameMode().CreativeInventory() { + return + } ctx := event.C() _ = call(ctx, src, srcIt, srcInv.Handler().HandleTake) From 104efd388c6a9f9716793e4ec1cefbbe91c508d1 Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 04:46:38 +0000 Subject: [PATCH 10/15] Run gofmt --- server/player/player.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/player/player.go b/server/player/player.go index 444be06a1..8032a170d 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -2932,11 +2932,11 @@ func (p *Player) useContext() *item.UseContext { src, dst, srcInv, dstInv := int(p.heldSlot.Load()), i, p.inv, p.armour.Inventory() srcIt, _ := srcInv.Item(src) dstIt, _ := dstInv.Item(dst) - - // If dstIt is enchanted with curse of binding, do not swap. - if _, isCursed := dstIt.Enchantment(enchantment.CurseOfBinding{}); isCursed && !p.GameMode().CreativeInventory() { - return - } + + // If dstIt is enchanted with curse of binding, do not swap. + if _, isCursed := dstIt.Enchantment(enchantment.CurseOfBinding{}); isCursed && !p.GameMode().CreativeInventory() { + return + } ctx := event.C() _ = call(ctx, src, srcIt, srcInv.Handler().HandleTake) From 5105b3db669bb24c72e47cc8c9b39cb629ec0876 Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 13:23:25 +0000 Subject: [PATCH 11/15] Check both inventories in handleSwap --- server/session/handler_item_stack_request.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index a7eda0c9c..7cb048017 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -213,6 +213,12 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, } } + if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { + if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { + return nil + } + } + h.setItemInSlot(a.Source, dest, s) h.setItemInSlot(a.Destination, i, s) h.collectRewards(s, invA, int(a.Source.Slot)) From ab730d1d05067d71d49f70673020d6ee61b230e9 Mon Sep 17 00:00:00 2001 From: curzodo Date: Thu, 22 Dec 2022 13:29:07 +0000 Subject: [PATCH 12/15] Return error when client attempts to bypass curse of binding rules --- server/session/handler_item_stack_request.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 7cb048017..8314e13aa 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -162,7 +162,7 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS // Do not allow an equipped item cursed with binding to be transferred. if from.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return nil + return fmt.Errorf("client attempted to transfer an equipped armour item enchanted with the curse of binding") } } @@ -209,13 +209,13 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, // Do not allow an equipped item cursed with binding to be swapped out. if a.Destination.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := dest.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return nil + return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") } } if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return nil + return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") } } @@ -279,7 +279,7 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, // Do not allow an equipped item cursed with binding to be dropped. if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return nil + return fmt.Errorf("client attempted to drop an equipped armour item enchanted with the curse of binding") } } From 5f96079eb7c44921e10499fa62aa3c47ed4b1234 Mon Sep 17 00:00:00 2001 From: curzodo Date: Fri, 23 Dec 2022 02:06:52 +0000 Subject: [PATCH 13/15] Create curseOfBinding function --- server/session/handler_item_stack_request.go | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 8314e13aa..32e86df9f 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -160,10 +160,8 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS } // Do not allow an equipped item cursed with binding to be transferred. - if from.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { - if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return fmt.Errorf("client attempted to transfer an equipped armour item enchanted with the curse of binding") - } + if curseOfBinding(from.ContainerID, i, s) { + return fmt.Errorf("client attempted to transfer an equipped armour item enchanted with the curse of binding") } if dest.Empty() { @@ -206,17 +204,13 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, return err } - // Do not allow an equipped item cursed with binding to be swapped out. - if a.Destination.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { - if _, isCursed := dest.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") - } + // Do not allow an equipped item cursed with binding to be swapped out by cursor or touch screen. + if curseOfBinding(a.Destination.ContainerID, dest, s) { + return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") } - if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { - if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") - } + if curseOfBinding(a.Source.ContainerID, i, s) { + return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") } h.setItemInSlot(a.Source, dest, s) @@ -277,10 +271,8 @@ func (h *ItemStackRequestHandler) handleDrop(a *protocol.DropStackRequestAction, } // Do not allow an equipped item cursed with binding to be dropped. - if a.Source.ContainerID == protocol.ContainerArmor && !s.c.GameMode().CreativeInventory() { - if _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}); isCursed { - return fmt.Errorf("client attempted to drop an equipped armour item enchanted with the curse of binding") - } + if curseOfBinding(a.Source.ContainerID, i, s) { + return fmt.Errorf("client attempted to drop an equipped armour item enchanted with the curse of binding") } n := s.c.Drop(i.Grow(int(a.Count) - i.Count())) @@ -541,3 +533,15 @@ func call(ctx *event.Context, slot int, it item.Stack, f func(ctx *event.Context } return nil } + +// curseOfBinding returns true if an ItemStackRequestHandler should be cancelled as a result of the given combination of +// containerID, item and session. containerID should be the ID of the container where i is currently. +func curseOfBinding(containerID byte, i item.Stack, s *Session) bool { + if containerID != protocol.ContainerArmor || s.c.GameMode().CreativeInventory() { + return false + } + + _, isCursed := i.Enchantment(enchantment.CurseOfBinding{}) + + return isCursed +} From e4f7c92dc568131ff8640b1d29a8004daa54e4cb Mon Sep 17 00:00:00 2001 From: curzodo Date: Fri, 23 Dec 2022 02:09:27 +0000 Subject: [PATCH 14/15] Merge if statements --- server/session/handler_item_stack_request.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 32e86df9f..4d65337ff 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -205,11 +205,7 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, } // Do not allow an equipped item cursed with binding to be swapped out by cursor or touch screen. - if curseOfBinding(a.Destination.ContainerID, dest, s) { - return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") - } - - if curseOfBinding(a.Source.ContainerID, i, s) { + if curseOfBinding(a.Destination.ContainerID, dest, s) || curseOfBinding(a.Source.ContainerID, i, s) { return fmt.Errorf("client attempted to swap an equipped armour item enchanted with the curse of binding") } From a472e5a3be5ec3d2972c6add2412cc2886f0e17e Mon Sep 17 00:00:00 2001 From: curzodo <96948113+curzodo@users.noreply.github.com> Date: Tue, 27 Dec 2022 13:16:46 +0000 Subject: [PATCH 15/15] Update server/session/handler_item_stack_request.go Co-authored-by: DaPigGuy --- server/session/handler_item_stack_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 4d65337ff..9b089c8e9 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -160,7 +160,7 @@ func (h *ItemStackRequestHandler) handleTransfer(from, to protocol.StackRequestS } // Do not allow an equipped item cursed with binding to be transferred. - if curseOfBinding(from.ContainerID, i, s) { + if curseOfBinding(from.ContainerID, i, s) || curseOfBinding(to.ContainerID, dest, s) { return fmt.Errorf("client attempted to transfer an equipped armour item enchanted with the curse of binding") }