爆炸附魔织物 Minecraft 改装

Explosion Enchantment Fabric 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, target, level);
    }
}

只需定义destructionType参数:

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