Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smithing templates + Table and Armour Trims #861

Merged
merged 16 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/df-mc/dragonfly

go 1.21
go 1.21.0

require (
github.com/brentp/intintmap v0.0.0-20190211203843-30dc0ade9af9
Expand All @@ -12,7 +12,7 @@ require (
github.com/google/uuid v1.4.0
github.com/pelletier/go-toml v1.9.5
github.com/rogpeppe/go-internal v1.11.0
github.com/sandertv/gophertunnel v1.36.0
github.com/sandertv/gophertunnel v1.36.1
github.com/segmentio/fasthash v1.0.3
github.com/sirupsen/logrus v1.9.3
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
Expand All @@ -25,12 +25,12 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/muhammadmuzzammil1998/jsonc v1.0.0 // indirect
github.com/sandertv/go-raknet v1.12.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
github.com/sandertv/go-raknet v1.13.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
Expand Down
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA=
github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y=
github.com/sandertv/gophertunnel v1.36.0 h1:VF2znM3FFUkPqOVnOeH0KgM5iI167AzSB2oqLxrn2F4=
github.com/sandertv/gophertunnel v1.36.0/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
github.com/sandertv/go-raknet v1.13.0 h1:Jkovqz4FrBP7PCIBBirBRoWm7mQKNP/UTYbOOyBK1TY=
github.com/sandertv/go-raknet v1.13.0/go.mod h1:E/DgMFQUMvWOvXwQRLEsTNOoYqzNubfcgzqL0nMoPso=
github.com/sandertv/gophertunnel v1.36.1 h1:Ak078sWePrvhh1U8ylP/92W1muIISkjbII2sHCLHajM=
github.com/sandertv/gophertunnel v1.36.1/go.mod h1:4El8ZfEpUmOMIJhPt5SCc1PyLNiuQ2+grWczrBvSGVs=
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/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand All @@ -67,8 +69,9 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
Expand All @@ -81,8 +84,9 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -96,8 +100,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
16 changes: 16 additions & 0 deletions server/internal/nbtconv/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func MapItem(x map[string]any, k string) item.Stack {
}

s := readItemStack(m, tag)
readArmourTrim(tag, &s)
readDamage(tag, &s, true)
readEnchantments(tag, &s)
readDisplay(tag, &s)
Expand All @@ -171,6 +172,7 @@ func Item(data map[string]any, s *item.Stack) item.Stack {
s = &a
}

readArmourTrim(tag, s)
readAnvilCost(tag, s)
readDamage(tag, s, disk)
readDisplay(tag, s)
Expand Down Expand Up @@ -222,6 +224,20 @@ func readAnvilCost(m map[string]any, s *item.Stack) {
*s = s.WithAnvilCost(int(Int32(m, "RepairCost")))
}

// readArmourTrim reads the armour trim stored in the NBT and saves it to the item.Stack passed.
func readArmourTrim(m map[string]any, s *item.Stack) {
if trim, ok := m["Trim"].(map[string]any); ok {
material, ok := trim["Material"].(string)
pattern, ok2 := trim["Pattern"].(string)
if ok && ok2 {
*s = s.WithArmourTrim(item.ArmourTrim{
Template: item.ArmourSmithingTemplateFromString(pattern),
Material: item.ArmourTrimMaterialFromString(material),
})
}
}
}

// readEnchantments reads the enchantments stored in the ench tag of the NBT passed and stores it into an item.Stack.
func readEnchantments(m map[string]any, s *item.Stack) {
enchantments, ok := m["ench"].([]map[string]any)
Expand Down
11 changes: 11 additions & 0 deletions server/internal/nbtconv/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func WriteItem(s item.Stack, disk bool) map[string]any {
tag[k] = v
}
}
writeArmourTrim(tag, s)
writeAnvilCost(tag, s)
writeDamage(tag, s, disk)
writeDisplay(tag, s)
Expand Down Expand Up @@ -111,6 +112,16 @@ func writeEnchantments(m map[string]any, s item.Stack) {
}
}

// writeArmourTrim writes the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writes the ...?

func writeArmourTrim(m map[string]any, s item.Stack) {
if t, ok := s.ArmourTrim(); ok {
m["Trim"] = map[string]any{
"Material": t.Material.TrimMaterial(),
"Pattern": t.Template.String(),
}
}
}

// writeDisplay writes the display name and lore of an item to a map for NBT encoding.
func writeDisplay(m map[string]any, s item.Stack) {
name, lore := s.CustomName(), s.Lore()
Expand Down
12 changes: 12 additions & 0 deletions server/item/amethyst_shard.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// AmethystShard is a crystalline mineral obtained from mining a fully grown amethyst cluster.
type AmethystShard struct{}

// EncodeItem ...
func (AmethystShard) EncodeItem() (name string, meta int16) {
return "minecraft:amethyst_shard", 0
}

// TrimMaterial ...
func (AmethystShard) TrimMaterial() string {
return "amethyst"
}

// MaterialColour ...
func (AmethystShard) MaterialColour() string {
return text.Amethyst
}
58 changes: 58 additions & 0 deletions server/item/armour_trim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package item

import "github.com/df-mc/dragonfly/server/world"

type ArmourTrim struct {
Template ArmourSmithingTemplate
Material ArmourTrimMaterial
}

type ArmourTrimMaterial interface {
// TrimMaterial returns the material name used for reading and writing trim data.
TrimMaterial() string
// MaterialColour returns the color code used for internal text formatting. Use text.Colourf for proper formatting.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "color" to "colour", can probably remove the text.Colourf reference now we return the constant

MaterialColour() string
}

// ArmourTrimMaterialFromString returns a TrimMaterial from a string.
func ArmourTrimMaterialFromString(name string) ArmourTrimMaterial {
switch name {
case "amethyst":
return AmethystShard{}
case "copper":
return CopperIngot{}
case "diamond":
return Diamond{}
case "emerald":
return Emerald{}
case "gold":
return GoldIngot{}
case "iron":
return IronIngot{}
case "lapis":
return LapisLazuli{}
case "netherite":
return NetheriteIngot{}
case "quartz":
return NetherQuartz{}
}

//TODO: add redstone material once pr is merged

panic("should not happen")
}

// ArmourTrimMaterials returns all the items that can be trim materials.
func ArmourTrimMaterials() []world.Item {
return []world.Item{
AmethystShard{},
CopperIngot{},
Diamond{},
Emerald{},
GoldIngot{},
IronIngot{},
LapisLazuli{},
NetheriteIngot{},
NetherQuartz{},
}
}
12 changes: 12 additions & 0 deletions server/item/copper_ingot.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// CopperIngot is a metal ingot melted from copper ore.
type CopperIngot struct{}

// EncodeItem ...
func (c CopperIngot) EncodeItem() (name string, meta int16) {
return "minecraft:copper_ingot", 0
}

// TrimMaterial ...
func (CopperIngot) TrimMaterial() string {
return "copper"
}

// MaterialColour ...
func (CopperIngot) MaterialColour() string {
return text.Copper
}
12 changes: 12 additions & 0 deletions server/item/diamond.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// Diamond is a rare mineral obtained from diamond ore or loot chests.
type Diamond struct{}

Expand All @@ -8,6 +10,16 @@ func (Diamond) EncodeItem() (name string, meta int16) {
return "minecraft:diamond", 0
}

// TrimMaterial ...
func (Diamond) TrimMaterial() string {
return "diamond"
}

// MaterialColour ...
func (Diamond) MaterialColour() string {
return text.Diamond
}

// PayableForBeacon ...
func (Diamond) PayableForBeacon() bool {
return true
Expand Down
12 changes: 12 additions & 0 deletions server/item/emerald.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// Emerald is a rare mineral obtained from emerald ore or from villagers.
type Emerald struct{}

Expand All @@ -8,6 +10,16 @@ func (Emerald) EncodeItem() (name string, meta int16) {
return "minecraft:emerald", 0
}

// TrimMaterial ...
func (Emerald) TrimMaterial() string {
return "emerald"
}

// MaterialColour ...
func (Emerald) MaterialColour() string {
return text.Emerald
}

// PayableForBeacon ...
func (Emerald) PayableForBeacon() bool {
return true
Expand Down
12 changes: 12 additions & 0 deletions server/item/gold_ingot.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// GoldIngot is a metal ingot melted from raw gold or obtained from loot chests.
type GoldIngot struct{}

Expand All @@ -8,6 +10,16 @@ func (GoldIngot) EncodeItem() (name string, meta int16) {
return "minecraft:gold_ingot", 0
}

// TrimMaterial ...
func (GoldIngot) TrimMaterial() string {
return "gold"
}

// MaterialColour ...
func (GoldIngot) MaterialColour() string {
return text.Gold
}

// PayableForBeacon ...
func (GoldIngot) PayableForBeacon() bool {
return true
Expand Down
12 changes: 12 additions & 0 deletions server/item/iron_ingot.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// IronIngot is a metal ingot melted from raw iron or obtained from loot chests.
type IronIngot struct{}

Expand All @@ -8,6 +10,16 @@ func (IronIngot) EncodeItem() (name string, meta int16) {
return "minecraft:iron_ingot", 0
}

// TrimMaterial ...
func (IronIngot) TrimMaterial() string {
return "iron"
}

// MaterialColour ...
func (IronIngot) MaterialColour() string {
return text.Iron
}

// PayableForBeacon ...
func (IronIngot) PayableForBeacon() bool {
return true
Expand Down
12 changes: 12 additions & 0 deletions server/item/lapis_lazuli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// LapisLazuli is a mineral used for enchanting and decoration.
type LapisLazuli struct{}

// EncodeItem ...
func (LapisLazuli) EncodeItem() (name string, meta int16) {
return "minecraft:lapis_lazuli", 0
}

// TrimMaterial ...
func (LapisLazuli) TrimMaterial() string {
return "lapis"
}

// MaterialColour ...
func (LapisLazuli) MaterialColour() string {
return text.Lapis
}
12 changes: 12 additions & 0 deletions server/item/nether_quartz.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package item

import "github.com/sandertv/gophertunnel/minecraft/text"

// NetherQuartz is a smooth, white mineral found in the Nether.
type NetherQuartz struct{}

// EncodeItem ...
func (NetherQuartz) EncodeItem() (name string, meta int16) {
return "minecraft:quartz", 0
}

// TrimMaterial ...
func (NetherQuartz) TrimMaterial() string {
return "quartz"
}

// MaterialColour ...
func (NetherQuartz) MaterialColour() string {
return text.Quartz
}
Loading
Loading