Skip to content

Commit

Permalink
dragonfly/server: Fix smithing trims and recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Apr 29, 2024
1 parent 0383f85 commit c3e9e96
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
Binary file modified server/item/recipe/smithing_data.nbt
Binary file not shown.
Binary file modified server/item/recipe/smithing_trim_data.nbt
Binary file not shown.
24 changes: 22 additions & 2 deletions server/item/smithing_template_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type ArmourSmithingTemplate struct {
smithingTemplateType
}

// TemplateNetheriteUpgrade returns the Netherrite Upgrade Template
// TemplateNetheriteUpgrade returns the Netherite Upgrade Template
func TemplateNetheriteUpgrade() ArmourSmithingTemplate {
return ArmourSmithingTemplate{0}
}
Expand Down Expand Up @@ -89,6 +89,16 @@ func TemplateSpire() ArmourSmithingTemplate {
return ArmourSmithingTemplate{16}
}

// TemplateFlow returns the Flow Template.
func TemplateFlow() ArmourSmithingTemplate {
return ArmourSmithingTemplate{17}
}

// TemplateBolt returns the Bolt Template.
func TemplateBolt() ArmourSmithingTemplate {
return ArmourSmithingTemplate{18}
}

// SmithingTemplates returns all the ArmourSmithingTemplates
func SmithingTemplates() []ArmourSmithingTemplate {
return []ArmourSmithingTemplate{
Expand All @@ -109,6 +119,8 @@ func SmithingTemplates() []ArmourSmithingTemplate {
TemplateRib(),
TemplateEye(),
TemplateSpire(),
TemplateFlow(),
TemplateBolt(),
}
}

Expand All @@ -123,7 +135,7 @@ func (s smithingTemplateType) Uint8() uint8 {
func (s smithingTemplateType) String() string {
switch s {
case 0:
return "netherrite_upgrade"
return "netherite_upgrade"
case 1:
return "sentry"
case 2:
Expand Down Expand Up @@ -156,6 +168,10 @@ func (s smithingTemplateType) String() string {
return "eye"
case 16:
return "spire"
case 17:
return "flow"
case 18:
return "bolt"
}

panic("should never happen")
Expand Down Expand Up @@ -196,6 +212,10 @@ func ArmourSmithingTemplateFromString(name string) ArmourSmithingTemplate {
return TemplateEye()
case "spire":
return TemplateSpire()
case "flow":
return TemplateFlow()
case "bolt":
return TemplateBolt()
}

panic("unknown template type")
Expand Down
3 changes: 3 additions & 0 deletions server/session/handler_crafting.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func duplicateStack(input item.Stack, newType world.Item) item.Stack {
WithLore(input.Lore()...).
WithEnchantments(input.Enchantments()...).
WithAnvilCost(input.AnvilCost())
if trim, ok := input.ArmourTrim(); ok {
outputStack = outputStack.WithArmourTrim(trim)
}
for k, v := range input.Values() {
outputStack = outputStack.WithValue(k, v)
}
Expand Down
22 changes: 19 additions & 3 deletions server/session/handler_smithing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package session

import (
"fmt"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/item/recipe"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
Expand All @@ -22,12 +23,14 @@ func (h *ItemStackRequestHandler) handleSmithing(a *protocol.CraftRecipeStackReq
if !ok {
return fmt.Errorf("recipe with network id %v does not exist", a.RecipeNetworkID)
}
if _, shapeless := craft.(recipe.SmithingTransform); !shapeless {
return fmt.Errorf("recipe with network id %v is not a smithing recipe", a.RecipeNetworkID)
}
if craft.Block() != "smithing_table" {
return fmt.Errorf("recipe with network id %v is not a smithing table recipe", a.RecipeNetworkID)
}
switch craft.(type) {
case recipe.SmithingTransform, recipe.SmithingTrim:
default:
return fmt.Errorf("recipe with network id %v is not a smithing recipe", a.RecipeNetworkID)
}

// Check if the input item and material item match what the recipe requires.
expectedInputs := craft.Input()
Expand Down Expand Up @@ -66,5 +69,18 @@ func (h *ItemStackRequestHandler) handleSmithing(a *protocol.CraftRecipeStackReq
ContainerID: protocol.ContainerSmithingTableTemplate,
Slot: smithingTemplateSlot,
}, template.Grow(-1), s)

if _, ok = craft.(recipe.SmithingTrim); ok {
var trim item.ArmourTrim
if t, ok := template.Item().(item.SmithingTemplate); ok {
trim.Template = t.Template
} else {
return fmt.Errorf("template item is not a smithing template")
}
if trim.Material, ok = material.Item().(item.ArmourTrimMaterial); !ok {
return fmt.Errorf("material item is not an armour trim material")
}
return h.createResults(s, duplicateStack(input.WithArmourTrim(trim), input.Item()))
}
return h.createResults(s, duplicateStack(input, craft.Output()[0].Item()))
}
3 changes: 3 additions & 0 deletions server/session/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func (s *Session) sendArmourTrimData() {
var trimMaterials []protocol.TrimMaterial

for _, t := range item.SmithingTemplates() {
if t == item.TemplateNetheriteUpgrade() {
continue
}
name, _ := item.SmithingTemplate{Template: t}.EncodeItem()
trimPatterns = append(trimPatterns, protocol.TrimPattern{
ItemName: name,
Expand Down

0 comments on commit c3e9e96

Please sign in to comment.