Enchantment: use Translatable instead of hardcoded translation keys

This commit is contained in:
Dylan K. Taylor
2021-09-03 20:52:05 +01:00
parent fbbaef4401
commit aa5a9f6d12
7 changed files with 212 additions and 24 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\item\enchantment;
use pocketmine\lang\Translatable;
use function constant;
/**
@@ -32,7 +33,7 @@ class Enchantment{
public function __construct(
private int $internalRuntimeId,
private string $name,
private Translatable|string $name,
private int $rarity,
private int $primaryItemFlags,
private int $secondaryItemFlags,
@@ -50,7 +51,7 @@ class Enchantment{
/**
* Returns a translation key for this enchantment's name.
*/
public function getName() : string{
public function getName() : Translatable|string{
return $this->name;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item\enchantment;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\lang\Translatable;
use function array_flip;
use function floor;
@@ -38,7 +39,7 @@ class ProtectionEnchantment extends Enchantment{
*
* @param int[]|null $applicableDamageTypes EntityDamageEvent::CAUSE_* constants which this enchantment type applies to, or null if it applies to all types of damage.
*/
public function __construct(int $internalRuntimeId, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel, float $typeModifier, ?array $applicableDamageTypes){
public function __construct(int $internalRuntimeId, Translatable|string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel, float $typeModifier, ?array $applicableDamageTypes){
parent::__construct($internalRuntimeId, $name, $rarity, $primaryItemFlags, $secondaryItemFlags, $maxLevel);
$this->typeModifier = $typeModifier;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item\enchantment;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\utils\RegistryTrait;
/**
@@ -64,44 +65,44 @@ final class VanillaEnchantments{
}
protected static function setup() : void{
self::register("PROTECTION", new ProtectionEnchantment(self::newRtId(), "%enchantment.protect.all", Rarity::COMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 0.75, null));
self::register("FIRE_PROTECTION", new ProtectionEnchantment(self::newRtId(), "%enchantment.protect.fire", Rarity::UNCOMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.25, [
self::register("PROTECTION", new ProtectionEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_protect_all(), Rarity::COMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 0.75, null));
self::register("FIRE_PROTECTION", new ProtectionEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_protect_fire(), Rarity::UNCOMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.25, [
EntityDamageEvent::CAUSE_FIRE,
EntityDamageEvent::CAUSE_FIRE_TICK,
EntityDamageEvent::CAUSE_LAVA
//TODO: check fireballs
]));
self::register("FEATHER_FALLING", new ProtectionEnchantment(self::newRtId(), "%enchantment.protect.fall", Rarity::UNCOMMON, ItemFlags::FEET, ItemFlags::NONE, 4, 2.5, [
self::register("FEATHER_FALLING", new ProtectionEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_protect_fall(), Rarity::UNCOMMON, ItemFlags::FEET, ItemFlags::NONE, 4, 2.5, [
EntityDamageEvent::CAUSE_FALL
]));
self::register("BLAST_PROTECTION", new ProtectionEnchantment(self::newRtId(), "%enchantment.protect.explosion", Rarity::RARE, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.5, [
self::register("BLAST_PROTECTION", new ProtectionEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_protect_explosion(), Rarity::RARE, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.5, [
EntityDamageEvent::CAUSE_BLOCK_EXPLOSION,
EntityDamageEvent::CAUSE_ENTITY_EXPLOSION
]));
self::register("PROJECTILE_PROTECTION", new ProtectionEnchantment(self::newRtId(), "%enchantment.protect.projectile", Rarity::UNCOMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.5, [
self::register("PROJECTILE_PROTECTION", new ProtectionEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_protect_projectile(), Rarity::UNCOMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.5, [
EntityDamageEvent::CAUSE_PROJECTILE
]));
self::register("THORNS", new Enchantment(self::newRtId(), "%enchantment.thorns", Rarity::MYTHIC, ItemFlags::TORSO, ItemFlags::HEAD | ItemFlags::LEGS | ItemFlags::FEET, 3));
self::register("RESPIRATION", new Enchantment(self::newRtId(), "%enchantment.oxygen", Rarity::RARE, ItemFlags::HEAD, ItemFlags::NONE, 3));
self::register("THORNS", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_thorns(), Rarity::MYTHIC, ItemFlags::TORSO, ItemFlags::HEAD | ItemFlags::LEGS | ItemFlags::FEET, 3));
self::register("RESPIRATION", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_oxygen(), Rarity::RARE, ItemFlags::HEAD, ItemFlags::NONE, 3));
self::register("SHARPNESS", new SharpnessEnchantment(self::newRtId(), "%enchantment.damage.all", Rarity::COMMON, ItemFlags::SWORD, ItemFlags::AXE, 5));
self::register("SHARPNESS", new SharpnessEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_damage_all(), Rarity::COMMON, ItemFlags::SWORD, ItemFlags::AXE, 5));
//TODO: smite, bane of arthropods (these don't make sense now because their applicable mobs don't exist yet)
self::register("KNOCKBACK", new KnockbackEnchantment(self::newRtId(), "%enchantment.knockback", Rarity::UNCOMMON, ItemFlags::SWORD, ItemFlags::NONE, 2));
self::register("FIRE_ASPECT", new FireAspectEnchantment(self::newRtId(), "%enchantment.fire", Rarity::RARE, ItemFlags::SWORD, ItemFlags::NONE, 2));
self::register("KNOCKBACK", new KnockbackEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_knockback(), Rarity::UNCOMMON, ItemFlags::SWORD, ItemFlags::NONE, 2));
self::register("FIRE_ASPECT", new FireAspectEnchantment(self::newRtId(), KnownTranslationFactory::enchantment_fire(), Rarity::RARE, ItemFlags::SWORD, ItemFlags::NONE, 2));
self::register("EFFICIENCY", new Enchantment(self::newRtId(), "%enchantment.digging", Rarity::COMMON, ItemFlags::DIG, ItemFlags::SHEARS, 5));
self::register("SILK_TOUCH", new Enchantment(self::newRtId(), "%enchantment.untouching", Rarity::MYTHIC, ItemFlags::DIG, ItemFlags::SHEARS, 1));
self::register("UNBREAKING", new Enchantment(self::newRtId(), "%enchantment.durability", Rarity::UNCOMMON, ItemFlags::DIG | ItemFlags::ARMOR | ItemFlags::FISHING_ROD | ItemFlags::BOW, ItemFlags::TOOL | ItemFlags::CARROT_STICK | ItemFlags::ELYTRA, 3));
self::register("EFFICIENCY", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_digging(), Rarity::COMMON, ItemFlags::DIG, ItemFlags::SHEARS, 5));
self::register("SILK_TOUCH", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_untouching(), Rarity::MYTHIC, ItemFlags::DIG, ItemFlags::SHEARS, 1));
self::register("UNBREAKING", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_durability(), Rarity::UNCOMMON, ItemFlags::DIG | ItemFlags::ARMOR | ItemFlags::FISHING_ROD | ItemFlags::BOW, ItemFlags::TOOL | ItemFlags::CARROT_STICK | ItemFlags::ELYTRA, 3));
self::register("POWER", new Enchantment(self::newRtId(), "%enchantment.arrowDamage", Rarity::COMMON, ItemFlags::BOW, ItemFlags::NONE, 5));
self::register("PUNCH", new Enchantment(self::newRtId(), "%enchantment.arrowKnockback", Rarity::RARE, ItemFlags::BOW, ItemFlags::NONE, 2));
self::register("FLAME", new Enchantment(self::newRtId(), "%enchantment.arrowFire", Rarity::RARE, ItemFlags::BOW, ItemFlags::NONE, 1));
self::register("INFINITY", new Enchantment(self::newRtId(), "%enchantment.arrowInfinite", Rarity::MYTHIC, ItemFlags::BOW, ItemFlags::NONE, 1));
self::register("POWER", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_arrowDamage(), Rarity::COMMON, ItemFlags::BOW, ItemFlags::NONE, 5));
self::register("PUNCH", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_arrowKnockback(), Rarity::RARE, ItemFlags::BOW, ItemFlags::NONE, 2));
self::register("FLAME", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_arrowFire(), Rarity::RARE, ItemFlags::BOW, ItemFlags::NONE, 1));
self::register("INFINITY", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_arrowInfinite(), Rarity::MYTHIC, ItemFlags::BOW, ItemFlags::NONE, 1));
self::register("MENDING", new Enchantment(self::newRtId(), "%enchantment.mending", Rarity::RARE, ItemFlags::NONE, ItemFlags::ALL, 1));
self::register("MENDING", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_mending(), Rarity::RARE, ItemFlags::NONE, ItemFlags::ALL, 1));
self::register("VANISHING", new Enchantment(self::newRtId(), "%enchantment.curse.vanishing", Rarity::MYTHIC, ItemFlags::NONE, ItemFlags::ALL, 1));
self::register("VANISHING", new Enchantment(self::newRtId(), KnownTranslationFactory::enchantment_curse_vanishing(), Rarity::MYTHIC, ItemFlags::NONE, ItemFlags::ALL, 1));
}
protected static function register(string $name, Enchantment $member) : void{