首發於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);