-
Notifications
You must be signed in to change notification settings - Fork 0
[Cursor Review] Implement piercing enchantment #30
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
Changes from all commits
91e32bf
75ac729
8a30c4f
ca905ef
02f2bdf
43f3c01
1d4ffa2
40a93c7
2feda73
0cf3d5a
abbbae7
27a41b7
6960176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package enchantment | ||
|
|
||
| import ( | ||
| "github.com/df-mc/dragonfly/server/item" | ||
| "github.com/df-mc/dragonfly/server/world" | ||
| ) | ||
|
|
||
| // Piercing is an enchantment that allows arrows to damage and pierce through multiple entities, including shields. | ||
| var Piercing piercing | ||
|
|
||
| type piercing struct{} | ||
|
|
||
| func (p piercing) Name() string { | ||
| return "Piercing" | ||
| } | ||
|
|
||
| func (p piercing) MaxLevel() int { | ||
| return 4 | ||
| } | ||
|
|
||
| func (p piercing) Cost(level int) (int, int) { | ||
| return 1 + (level-1)*10, 50 | ||
| } | ||
|
|
||
| func (p piercing) Rarity() item.EnchantmentRarity { | ||
| return item.EnchantmentRarityCommon | ||
| } | ||
|
|
||
| func (p piercing) CompatibleWithEnchantment(t item.EnchantmentType) bool { | ||
| return t != Multishot | ||
| } | ||
|
|
||
| func (p piercing) CompatibleWithItem(i world.Item) bool { | ||
| _, ok := i.(item.Crossbow) | ||
| return ok | ||
| } | ||
|
|
||
| func (p piercing) Pierces() bool { | ||
| return true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,6 +276,21 @@ func (s Stack) WithEnchantments(enchants ...Enchantment) Stack { | |
| // Enchantment is not compatible with the item. | ||
| continue | ||
| } | ||
| compatible := true | ||
| for _, otherEnchant := range s.enchantments { | ||
| addingType := enchant.t | ||
| existingType := otherEnchant.Type() | ||
| addingAcceptsExisting := addingType.CompatibleWithEnchantment(existingType) | ||
| existingAcceptsAdding := existingType.CompatibleWithEnchantment(addingType) | ||
| if addingType != existingType && (!addingAcceptsExisting || !existingAcceptsAdding) { | ||
| compatible = false | ||
| break | ||
| } | ||
| } | ||
| if !compatible { | ||
| // Enchantment is not compatible with another enchantment on the item. | ||
| continue | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| s.enchantments[enchant.t] = enchant | ||
| } | ||
| return s | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
ArrowSpawnConfigzero-value safe here.arrow.Tip.(potion.Potion)andarrow.Owner.H()will panic if a caller omits the tip or spawns an ownerless arrow. The new struct API makes both omissions easy.💡 Suggested fix
Arrow: func(opts world.EntitySpawnOpts, arrow world.ArrowSpawnConfig) *world.EntityHandle { - tip := arrow.Tip.(potion.Potion) + var tip potion.Potion + if t, ok := arrow.Tip.(potion.Potion); ok { + tip = t + } conf := arrowConf - conf.Damage, conf.Potion, conf.Owner = arrow.Damage, tip, arrow.Owner.H() + conf.Damage, conf.Potion = arrow.Damage, tip + if arrow.Owner != nil { + conf.Owner = arrow.Owner.H() + }📝 Committable suggestion
🤖 Prompt for AI Agents