Skip to content

Commit

Permalink
Fixed bug with Dodge, Leech and Misanthropy working even though the p…
Browse files Browse the repository at this point in the history
…layer blocked the damage with a shield
  • Loading branch information
Majrusz committed Oct 15, 2022
1 parent a4dad5a commit cc327c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Modifier( DodgeEnchantment enchantment ) {

OnPreDamagedContext onDamaged = new OnPreDamagedContext( this::dodgeDamage );
onDamaged.addCondition( new Condition.HasEnchantment( enchantment) )
.addCondition( data->data.event.getAmount() > 0.0f )
.addCondition( data->Random.tryChance( enchantment.getEnchantmentLevel( data.target ) * this.chance.asFloat() ) );

this.addConfigs( this.chance, this.pantsDamageMultiplier );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.majruszsenchantments.enchantments;

import com.majruszsenchantments.Registries;
import com.majruszsenchantments.configs.VampirismDoubleConfig;
import com.majruszsenchantments.gamemodifiers.EnchantmentModifier;
import com.mlib.EquipmentSlots;
import com.mlib.Random;
import com.mlib.Utility;
import com.mlib.effects.EffectHelper;
import com.mlib.enchantments.CustomEnchantment;
import com.mlib.gamemodifiers.Condition;
import com.mlib.gamemodifiers.contexts.OnDamagedContext;
import com.mlib.gamemodifiers.data.OnDamagedData;
import com.mlib.gamemodifiers.contexts.OnDamaged;
import com.mlib.math.VectorHelper;
import com.majruszsenchantments.Registries;
import com.majruszsenchantments.configs.VampirismDoubleConfig;
import com.majruszsenchantments.gamemodifiers.EnchantmentModifier;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -48,14 +47,16 @@ private static class Modifier extends EnchantmentModifier< LeechEnchantment > {
public Modifier( LeechEnchantment enchantment ) {
super( enchantment, "Leech", "Gives a chance to steal positive effects, health and hunger points from enemies." );

OnDamagedContext onDamaged = new OnDamagedContext( this::tryToLeechAnything );
onDamaged.addCondition( new Condition.IsServer() ).addCondition( data->data.attacker != null && enchantment.hasEnchantment( data.attacker ) );
OnDamaged.Context onDamaged = new OnDamaged.Context( this::tryToLeechAnything );
onDamaged.addCondition( new Condition.IsServer() )
.addCondition( data->data.attacker != null && enchantment.hasEnchantment( data.attacker ) )
.addCondition( OnDamaged.DEALT_ANY_DAMAGE );

this.addConfigs( this.healthChance, this.hungerChance, this.effectChance );
this.addContext( onDamaged );
}

private void tryToLeechAnything( OnDamagedData data ) {
private void tryToLeechAnything( OnDamaged.Data data ) {
assert data.attacker != null && data.level != null;
boolean leechedAnything;
leechedAnything = tryToLeech( this.healthChance, this::leechHealth, data );
Expand All @@ -67,7 +68,7 @@ private void tryToLeechAnything( OnDamagedData data ) {
}
}

private boolean tryToLeech( VampirismDoubleConfig chanceConfig, BiFunction< LivingEntity, LivingEntity, Boolean > function, OnDamagedData data ) {
private boolean tryToLeech( VampirismDoubleConfig chanceConfig, BiFunction< LivingEntity, LivingEntity, Boolean > function, OnDamaged.Data data ) {
return Random.tryChance( chanceConfig.getTotalChance( data.attacker ) ) ? function.apply( data.attacker, data.target ) : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mlib.enchantments.CustomEnchantment;
import com.mlib.entities.EntityHelper;
import com.mlib.gamemodifiers.Condition;
import com.mlib.gamemodifiers.contexts.OnDamaged;
import com.mlib.gamemodifiers.contexts.OnDamagedContext;
import com.mlib.gamemodifiers.data.OnDamagedData;
import com.majruszsenchantments.Registries;
Expand Down Expand Up @@ -33,16 +34,17 @@ private static class Modifier extends EnchantmentModifier< MisanthropyEnchantmen
public Modifier( MisanthropyEnchantment enchantment ) {
super( enchantment, "Misanthropy", "Increases the damage against villagers, pillagers, witches and other players." );

OnDamagedContext onDamaged = new OnDamagedContext( this::modifyDamage );
OnDamaged.Context onDamaged = new OnDamaged.Context( this::modifyDamage );
onDamaged.addCondition( new Condition.IsServer() )
.addCondition( data->data.attacker != null && enchantment.hasEnchantment( data.attacker ) )
.addCondition( data->EntityHelper.isHuman( data.target ) );
.addCondition( data->EntityHelper.isHuman( data.target ) )
.addCondition( OnDamaged.DEALT_ANY_DAMAGE );

this.addConfig( this.damageBonus );
this.addContext( onDamaged );
}

private void modifyDamage( OnDamagedData data ) {
private void modifyDamage( OnDamaged.Data data ) {
assert data.attacker != null && data.level != null;
float extraDamage = this.enchantment.getEnchantmentLevel( data.attacker ) * this.damageBonus.asFloat();
Vec3 position = data.target.position();
Expand Down

0 comments on commit cc327c8

Please sign in to comment.