Skip to content

Commit

Permalink
session/handler_loom.go: Fix cost of creating multiple banners (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy authored Nov 16, 2024
1 parent 5743097 commit 16b4c61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 11 additions & 6 deletions server/session/handler_loom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}

0 comments on commit 16b4c61

Please sign in to comment.