I'm new to modding, and trying to create an enchantment that causes killed mobs to drop extra experience. I've learned that you can spawn entities, such as extra experience orbs, using the doPostAttack method. How could I make it so that the extra experience is only spawned once the target is killed?
Here's the enchantment I'm working on, which currently spawns 1 experience orb when the player hits an entity:
public class ProficiencyEnchantment extends Enchantment {
public ProficiencyEnchantment(Rarity pRarity, EnchantmentCategory pCategory, EquipmentSlot... pApplicableSlots) {
super(pRarity, pCategory, pApplicableSlots);
}
public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) {
if(!pAttacker.level().isClientSide()) {
ServerLevel world = ((ServerLevel) pAttacker.level());
BlockPos position = pTarget.blockPosition();
if(pLevel == 1) {
EntityType.EXPERIENCE_ORB.spawn(world, (ItemStack) null, null, position,
MobSpawnType.TRIGGERED, true, true);
}
}
}
@Override
public int getMaxLevel() {
return 1;
}
}