首发于Enaium的个人博客
public class FireBoomEnchantment extends Enchantment {
public FireBoomEnchantment(Rarity rarity, EnchantmentTarget target, EquipmentSlot[] slotTypes) {
super(rarity, target, slotTypes);
}
}
如果目标被攻击,目标就会爆炸,这里直接使用FireballEntity
类中onCollision
方法的部分代码。
@Override
public void onTargetDamaged(LivingEntity user, Entity target, int level) {
if (target instanceof LivingEntity) {
boolean bl = user.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING);
user.getWorld().createExplosion(target, target.getX(), target.getY(), target.getZ(), 1, bl, World.ExplosionSourceType.MOB);
}
}
创建FireBoomEnchantment
对象的时候,需要传入Enchantment.Rarity
、EnchantmentTarget
和EquipmentSlot[]
,其中VERY_RARE
表示非常稀有,EnchantmentTarget.WEAPON
表示只能附魔武器,EquipmentSlot[]
表示只能附魔主手。
public static final FireBoomEnchantment FIRE_BOOM = Registry.register(Registries.ENCHANTMENT, new Identifier("awesome", "fire_boom"), new FireBoomEnchantment(Enchantment.Rarity.VERY_RARE, EnchantmentTarget.WEAPON, new EquipmentSlot[]{
EquipmentSlot.MAINHAND
}));
{
"enchantment.awesome.fire_boom": "Fire Boom"
}
附魔书在在原材料的最后