爆炸附魔织物 Minecraft Modding

问题描述

尝试制作爆炸附魔,让我在被暴徒击中时触发小爆炸。我不希望爆炸造成破坏,但我希望它造成伤害。


import net.minecraft.block.TntBlock;
import net.minecraft.client.util.math.Vector3d;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.TntEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;

public class ExplosiveAspectEnchantment extends Enchantment {

    protected ExplosiveAspectEnchantment(Rarity weight,EnchantmentTarget target,EquipmentSlot[] equipmentSlots) {
        super(weight,target,equipmentSlots);

    }

    @Override
    public int getMinPower(int level) {
        return 100;
    }

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

    @Override
    public void onTargetdamaged(LivingEntity user,net.minecraft.entity.Entity target,int level) {
        World world = user.world;
        if (target instanceof LivingEntity) {
            Vec3d pos = target.getPos();
            world.createExplosion(user,pos.x,pos.y,pos.z,4.0F,);
        }
        super.onTargetdamaged(user,level);
    }
}

解决方法

只需定义 destructionType 参数:

world.createExplosion(user,pos.x,pos.y,pos.z,4.0F,Explosion.DestructionType.NONE);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...