github.com/df-mc/dragonfly@v0.9.13/server/item/enchantment/knock_back.go (about)

     1  package enchantment
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/item"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  )
     7  
     8  // KnockBack is an enchantment to a sword that increases the sword's knock-back.
     9  type KnockBack struct{}
    10  
    11  // Name ...
    12  func (KnockBack) Name() string {
    13  	return "Knockback"
    14  }
    15  
    16  // MaxLevel ...
    17  func (KnockBack) MaxLevel() int {
    18  	return 2
    19  }
    20  
    21  // Cost ...
    22  func (KnockBack) Cost(level int) (int, int) {
    23  	min := 5 + (level-1)*20
    24  	return min, min + 50
    25  }
    26  
    27  // Rarity ...
    28  func (KnockBack) Rarity() item.EnchantmentRarity {
    29  	return item.EnchantmentRarityUncommon
    30  }
    31  
    32  // Force returns the increase in knock-back force from the enchantment.
    33  func (KnockBack) Force(level int) float64 {
    34  	return float64(level) / 2
    35  }
    36  
    37  // CompatibleWithEnchantment ...
    38  func (KnockBack) CompatibleWithEnchantment(item.EnchantmentType) bool {
    39  	return true
    40  }
    41  
    42  // CompatibleWithItem ...
    43  func (KnockBack) CompatibleWithItem(i world.Item) bool {
    44  	t, ok := i.(item.Tool)
    45  	return ok && t.ToolType() == item.TypeSword
    46  }