
Poison, Wither, and Levitation kill villagers and friendly mobs
CplPibald opened this issue ยท 5 comments
The negative potion-effect-based abilities affect villagers, farm animals, NPCs, and other neutral mobs as well as hostile ones. Having these abilities makes managing farms or trading with villagers extremely frustrating because just standing near the villager will kill it.
Recommendation is for negative effects to only apply to mobs that are hostile to the player with the ability. Ideally, that means mobs that are attacking. If that isn't possible, then perhaps ignore EntityAgeable, as NPC and farm animals derive from that class.
It looks like you might be able to filter using getAttackTarget()
and/or getAttackingEntity()
.
Another option is to eliminate the passive check every tick and just apply the potion effects in onLivingHurt()
to the attacker (if the player is being hit) or the target (if the player is attacking). Players would lose the ability to harm entities just by walking near them (and through walls), but eliminating the update()
handlers would be a LOT more CPU-friendly.
The latter sounds like a too major change to the current ability.
Perhaps this behaviour might be useful for another variant of the same ability.
I'm using the patch below on my server. It simply filters out EntityAgeable
, which includes animals, vanilla villagers, and NPCs like MineColonies citizens. The effects still hits non-team players and vanilla hostile mobs, but it may not work for mobs added by mods, depending on what class they derive from.
If you want a PR of this I'll send it, but I think there's a better solution out there.
b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypePotionEffectRadius.java
index 5cc15ab..24c65bb 100644
--- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypePotionEffectRadius.java
+++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypePotionEffectRadius.java
@@ -5,2 +5,3 @@ package org.cyclops.everlastingabilities.ability;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.EntityAgeable;
import net.minecraft.potion.Potion;
@@ -43,7 +44,7 @@ public class AbilityTypePotionEffectRadius extends AbilityTypeDefault {
List<EntityLivingBase> mobs = world.getEntitiesWithinAABB(EntityLivingBase.class,
player.getEntityBoundingBox().expandXyz(radius), EntitySelectors.NOT_SPECTATING);
for (EntityLivingBase mob : mobs) {
- if (mob != player && (!(mob instanceof IEntityOwnable) || ((IEntityOwnable) mob).getOwner() != player) && !player.isOnSameTeam(mob)) {
+ if (mob != player && (!(mob instanceof EntityAgeable)) && (!(mob instanceof IEntityOwnable) || ((IEntityOwnable) mob).getOwner() != player) && !player.isOnSameTeam(mob)) {
mob.addPotionEffect(
new PotionEffect(potion, TICK_MODULUS * getDurationMultiplier(), level - 1, true, false));
}