Fix guadian thorns causing damage to players who use bleeding
package slimeknights.tconstruct.tools.modifiers.effect;
-import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.particles.ParticleTypes;
-import net.minecraft.world.effect.MobEffectCategory;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.EntityDamageSource;
-import net.minecraft.server.level.ServerLevel;
+import net.minecraft.world.effect.MobEffectCategory;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.LivingEntity;
+import org.jetbrains.annotations.Nullable;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.tools.helper.ToolAttackUtil;
import slimeknights.tconstruct.tools.modifiers.traits.melee.LaceratingModifier;
@@ -31,11 +33,12 @@ public class BleedingEffect extends NoMilkEffect {
LivingEntity lastAttacker = target.getLastHurtMob();
DamageSource source;
if(lastAttacker != null) {
- source = new EntityDamageSource(SOURCE_KEY, lastAttacker);
+ source = new BleedingDamageSource(SOURCE_KEY, lastAttacker);
}
else {
source = new DamageSource(SOURCE_KEY);
}
+ source.bypassMagic();
// perform damage
int hurtResistantTime = target.invulnerableTime;
@@ -47,4 +50,18 @@ public class BleedingEffect extends NoMilkEffect {
((ServerLevel)target.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getY(0.5), target.getZ(), 1, 0.1, 0, 0.1, 0.2);
}
}
+
+ /** Guardians use the direct entity to determine if they should thorns, while the direct marks for player kills
+ * treat this as indirect damage by making the direct entity null, so guardians treat it like arrows */
+ private static class BleedingDamageSource extends EntityDamageSource {
+ public BleedingDamageSource(String name, Entity entity) {
+ super(name, entity);
+ }
+
+ @Nullable
+ @Override
+ public Entity getDirectEntity() {
+ return null;
+ }
+ }
}
