问题描述
尝试制作爆炸附魔,让我在被暴徒击中时触发小爆炸。我不希望爆炸造成破坏,但我希望它造成伤害。
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);