From 041803cf6b96c25808eb46aa33e46a1914c8d450 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Sun, 11 Aug 2024 08:54:26 +0200 Subject: [PATCH] Fix crash when vengeance enchantment is active on bow --- ...mentEntityEffectSummonVengeanceSpirit.java | 4 +++ .../evilcraft/item/ItemVengeanceRing.java | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/cyclops/evilcraft/enchantment/entityeffect/EnchantmentEntityEffectSummonVengeanceSpirit.java b/src/main/java/org/cyclops/evilcraft/enchantment/entityeffect/EnchantmentEntityEffectSummonVengeanceSpirit.java index 1cc106ad09..f77d126734 100644 --- a/src/main/java/org/cyclops/evilcraft/enchantment/entityeffect/EnchantmentEntityEffectSummonVengeanceSpirit.java +++ b/src/main/java/org/cyclops/evilcraft/enchantment/entityeffect/EnchantmentEntityEffectSummonVengeanceSpirit.java @@ -5,6 +5,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.enchantment.EnchantedItemInUse; import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect; import net.minecraft.world.phys.Vec3; @@ -30,6 +31,9 @@ public void apply(ServerLevel level, int enchantmentLevel, EnchantedItemInUse en if (enchantmentLevel > 0) { int chance = Math.max(1, chance() / enchantmentLevel); if (chance > 0 && level.random.nextInt(chance) == 0) { + if (entity instanceof Projectile projectile) { + entity = projectile.getEffectSource(); + } ItemVengeanceRing.toggleVengeanceArea(level, entity, area * enchantmentLevel, true, true, true); } } diff --git a/src/main/java/org/cyclops/evilcraft/item/ItemVengeanceRing.java b/src/main/java/org/cyclops/evilcraft/item/ItemVengeanceRing.java index a3c5b9f2d3..c89d25173f 100644 --- a/src/main/java/org/cyclops/evilcraft/item/ItemVengeanceRing.java +++ b/src/main/java/org/cyclops/evilcraft/item/ItemVengeanceRing.java @@ -12,7 +12,6 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -102,11 +101,13 @@ public boolean apply(Entity entity) { // Vengeance all the spirits in the neighbourhood for(EntityVengeanceSpirit spirit : spirits) { - spirit.setEnabledVengeance((Player) entity, enableVengeance); - if(enableVengeance) { - spirit.setTarget((LivingEntity) entity); - } else if(spirit.getTarget() == entity) { - spirit.setTarget(null); + if (entity instanceof Player player) { + spirit.setEnabledVengeance(player, enableVengeance); + if (enableVengeance) { + spirit.setTarget(player); + } else if (spirit.getTarget() == player) { + spirit.setTarget(null); + } } } @@ -114,12 +115,14 @@ public boolean apply(Entity entity) { if(spirits.size() == 0 && enableVengeance) { EntityVengeanceSpirit spirit = EntityVengeanceSpirit.spawnRandom(world, blockPos, area / 4); if(spirit != null) { - if(forceGlobal) { - spirit.setGlobalVengeance(true); - } else { - spirit.setEnabledVengeance((Player) entity, true); + if (entity instanceof Player player) { + if (forceGlobal) { + spirit.setGlobalVengeance(true); + } else { + spirit.setEnabledVengeance(player, true); + } + spirit.setTarget(player); } - spirit.setTarget((LivingEntity) entity); int chance = EntityVengeanceSpiritConfig.nonDegradedSpawnChance; spirit.setSwarm(chance <= 0 || world.random.nextInt(chance) > 0); }