From fcd39cf95869a5293ac88210925069f8ca174e69 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Sat, 16 Nov 2024 03:29:15 -0800 Subject: [PATCH] session/handler_loom.go: Fix cost of creating multiple banners --- go.mod | 2 +- go.sum | 4 ++-- server/session/handler_loom.go | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b634c1190..553ca420e 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/go-gl/mathgl v1.1.0 github.com/google/uuid v1.6.0 github.com/pelletier/go-toml v1.9.5 - github.com/sandertv/gophertunnel v1.42.0 + github.com/sandertv/gophertunnel v1.42.2 github.com/segmentio/fasthash v1.0.3 golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c golang.org/x/mod v0.21.0 diff --git a/go.sum b/go.sum index 2d531cf1f..e581e5a30 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sandertv/go-raknet v1.14.2 h1:UZLyHn5yQU2Dq2GVq/LlxwAUikaq4q4AA1rl/Pf3AXQ= github.com/sandertv/go-raknet v1.14.2/go.mod h1:/yysjwfCXm2+2OY8mBazLzcxJ3irnylKCyG3FLgUPVU= -github.com/sandertv/gophertunnel v1.42.0 h1:qOc/Dht/Kvh67uxJ6sgkL0oP+jhuXkVwk7KEf3d1p9M= -github.com/sandertv/gophertunnel v1.42.0/go.mod h1:krvLSeRUNQ2iEYJNEgzrKtWO8W5ybZxN5lFfSCkHoNk= +github.com/sandertv/gophertunnel v1.42.2 h1:YWi4vAkq9IpNFIDxOrSMeGh2wkWMCMO8Kg45/R7VTQs= +github.com/sandertv/gophertunnel v1.42.2/go.mod h1:krvLSeRUNQ2iEYJNEgzrKtWO8W5ybZxN5lFfSCkHoNk= github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM= github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/server/session/handler_loom.go b/server/session/handler_loom.go index 4d73ee14e..cb3d98c77 100644 --- a/server/session/handler_loom.go +++ b/server/session/handler_loom.go @@ -26,13 +26,18 @@ func (h *ItemStackRequestHandler) handleLoomCraft(a *protocol.CraftLoomRecipeSta return fmt.Errorf("no loom container opened") } + timesCrafted := int(a.TimesCrafted) + if timesCrafted < 1 { + return fmt.Errorf("times crafted must be least 1") + } + // Next, check if the input slot has a valid banner item. input, _ := h.itemInSlot(protocol.StackRequestSlotInfo{ Container: protocol.FullContainerName{ContainerID: protocol.ContainerLoomInput}, Slot: loomInputSlot, }, s) - if input.Empty() { - return fmt.Errorf("input item is empty") + if input.Count() < timesCrafted { + return fmt.Errorf("input item count is less than times crafted") } b, ok := input.Item().(block.Banner) if !ok { @@ -47,8 +52,8 @@ func (h *ItemStackRequestHandler) handleLoomCraft(a *protocol.CraftLoomRecipeSta Container: protocol.FullContainerName{ContainerID: protocol.ContainerLoomDye}, Slot: loomDyeSlot, }, s) - if dye.Empty() { - return fmt.Errorf("dye item is empty") + if dye.Count() < timesCrafted { + return fmt.Errorf("dye item count is less than times crafted") } d, ok := dye.Item().(item.Dye) if !ok { @@ -86,10 +91,10 @@ func (h *ItemStackRequestHandler) handleLoomCraft(a *protocol.CraftLoomRecipeSta h.setItemInSlot(protocol.StackRequestSlotInfo{ Container: protocol.FullContainerName{ContainerID: protocol.ContainerLoomInput}, Slot: loomInputSlot, - }, input.Grow(-1), s) + }, input.Grow(-timesCrafted), s) h.setItemInSlot(protocol.StackRequestSlotInfo{ Container: protocol.FullContainerName{ContainerID: protocol.ContainerLoomDye}, Slot: loomDyeSlot, - }, dye.Grow(-1), s) + }, dye.Grow(-timesCrafted), s) return h.createResults(s, duplicateStack(input, b)) }