首发于Enaium的我的博客ide
建立一个附魔书类ui
public class FireBoomEnchantment extends Enchantment { [...] }
在类中添一下this
@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); } }
这就建立了一个FireBoom附魔书spa
onTargetDamaged //当目标被攻击code
在mc FireballEntity类有一个 方法就是当火球碰撞了就建立一个火焰爆炸的效果blog
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(); } }
咱们能够加以利用ip
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);
this.world.createExplosion()rem
咱们替换相对应的参数 参数一就是实体 target就是攻击目标 参数2、3、四 就是目标 X Y Z 因为 xyz是private 只能用 public 的 prevX prevY prevZ 参数五就是爆炸大小 参数六不用管
world.spawnEntity(target);//生成实体在targetget
private static final FireBoomEnchantment END_FIRE_BOOM_ENCHANTMENT = new FireBoomEnchantment( Enchantment.Weight.VERY_RARE, EnchantmentTarget.WEAPON, new EquipmentSlot[] { EquipmentSlot.MAINHAND } );
Registry.register(Registry.ENCHANTMENT,new Identifier("endarmor","end_fire_boom_enchantment"),END_FIRE_BOOM_ENCHANTMENT);