Minecraft Fabric 教程 #8 添加附魔书

简介: 这就创建了一个FireBoom附魔书onTargetDamaged //当目标被攻击在mc FireballEntity类有一个 方法就是当火球碰撞了就创建一个火焰爆炸的效果

首发于Enaium的个人博客


创建一个附魔书类

public class FireBoomEnchantment extends Enchantment {
    [...]
}
AI 代码解读

在类中添一下

    @Override
    public int getMinimumPower(int level) {
        return 15;
    }

    @Override
    public int getMaximumLevel() {
        return 1;
    }

    @Override
    public void onTargetDamaged(LivingEntity user, Entity target, int level) {
        if(target instanceof LivingEntity) {
            World world = user.world;
            boolean bl = world.getGameRules().getBoolean(GameRules.MOB_GRIEFING);
            world.createExplosion(target, target.prevX, target.prevY, target.prevZ, 1.0f, bl, bl ? Explosion.DestructionType.DESTROY : Explosion.DestructionType.NONE);
            world.spawnEntity(target);
        }
    }
AI 代码解读

这就创建了一个FireBoom附魔书

onTargetDamaged //当目标被攻击

在mc FireballEntity类有一个 方法就是当火球碰撞了就创建一个火焰爆炸的效果

   protected void onCollision(HitResult hitResult) {
      super.onCollision(hitResult);
      if (!this.world.isClient) {
         if (hitResult.getType() == HitResult.Type.ENTITY) {
            Entity entity = ((EntityHitResult)hitResult).getEntity();
            entity.damage(DamageSource.explosiveProjectile(this, this.owner), 6.0F);
            this.dealDamage(this.owner, entity);
         }

         boolean bl = this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING);
         this.world.createExplosion((Entity)null, this.getX(), this.getY(), this.getZ(), (float)this.explosionPower, bl, bl ? Explosion.DestructionType.DESTROY : Explosion.DestructionType.NONE);
         this.remove();
      }

   }
AI 代码解读

我们可以加以利用

    boolean bl = world.getGameRules().getBoolean(GameRules.MOB_GRIEFING);
    world.createExplosion(target, target.prevX, target.prevY, target.prevZ, 1.0f, bl, bl ? Explosion.DestructionType.DESTROY : 
    Explosion.DestructionType.NONE);
AI 代码解读

this.world.createExplosion()

我们替换相对应的参数 参数一就是实体 target就是攻击目标 参数二、三、四 就是目标 X Y Z 由于 xyz是private 只能用 public 的 prevX prevY prevZ 参数五就是爆炸大小 参数六不用管
world.spawnEntity(target);//生成实体在target

创建附魔书

    private static final FireBoomEnchantment END_FIRE_BOOM_ENCHANTMENT = new FireBoomEnchantment(
            Enchantment.Weight.VERY_RARE,
            EnchantmentTarget.WEAPON,
            new EquipmentSlot[] {
                    EquipmentSlot.MAINHAND
            }
    );
AI 代码解读

注册

        Registry.register(Registry.ENCHANTMENT,new Identifier("endarmor","end_fire_boom_enchantment"),END_FIRE_BOOM_ENCHANTMENT);
AI 代码解读

8-1.jpg

8-2.jpg

8-3.jpg

Enaium
+关注
目录
打赏
0
0
0
0
3
分享
相关文章
Minecraft Fabric 进阶教程 #2 绘制界面
绘制界面不需用注入Mixin
136 0
Minecraft Fabric 教程 #9 添加盔甲
参数一 材料名字 参数二 耐久倍数 参数三 盔甲数也就是穿上盔甲加的盔甲值 参数四 使用的时候发出的声音 参数五 耐性
134 0
Minecraft Fabric 教程 #9 添加盔甲
Minecraft Fabric 教程 #5 添加语言文件
lang也就是你模组的翻译比如 中文简体 zh_cn 中文正體 zh_tw 英文 en_us
105 0
Hyperledger fabric智能合约编写(一)
本篇文章主要对链码编写的主要思路和部分API进行梳理。
274 1
Hyperledger Fabric相关概念介绍
在学习Hyperledger Fabric的过程中,初步对相关概念的了解。
370 0
Hyperledger Fabric相关概念介绍

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等