-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cf9389
commit 81792ba
Showing
8 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/github/elenterius/biomancy/statuseffect/BleedEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.github.elenterius.biomancy.statuseffect; | ||
|
||
import com.github.elenterius.biomancy.init.ModDamageSources; | ||
import com.github.elenterius.biomancy.mixin.MobEffectInstanceAccessor; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.effect.MobEffects; | ||
import net.minecraft.world.entity.LivingEntity; | ||
|
||
public class BleedEffect extends StatusEffect implements StackingStatusEffect { | ||
|
||
private int maxEffectStack; | ||
|
||
public BleedEffect(MobEffectCategory category, int color, int maxEffectStack) { | ||
super(category, color, false); | ||
this.maxEffectStack = maxEffectStack; | ||
} | ||
|
||
@Override | ||
public boolean isDurationEffectTick(int duration, int amplifier) { | ||
return duration % 40 == 0; | ||
} | ||
|
||
@Override | ||
public void applyEffectTick(LivingEntity livingEntity, int amplifier) { | ||
if (livingEntity.hasEffect(MobEffects.REGENERATION) || livingEntity.hasEffect(MobEffects.HEAL)) { | ||
livingEntity.removeEffect(this); | ||
return; | ||
} | ||
|
||
if (livingEntity.isSprinting()) { | ||
increaseEffectDurationBy(livingEntity, 200); | ||
} | ||
else if (livingEntity.isCrouching()) { | ||
reduceEffectDurationBy(livingEntity, 200); | ||
} | ||
|
||
int effectLevel = amplifier + 1; | ||
livingEntity.hurt(ModDamageSources.BLEED, effectLevel); | ||
} | ||
|
||
private void reduceEffectDurationBy(LivingEntity livingEntity, int ticks) { | ||
MobEffectInstance effectInstance = livingEntity.getEffect(this); | ||
if (effectInstance == null) return; | ||
|
||
int reducedDuration = effectInstance.getDuration() - ticks; | ||
if (reducedDuration > 0) { | ||
((MobEffectInstanceAccessor) effectInstance).setDuration(reducedDuration); | ||
((MobEffectInstanceAccessor) effectInstance).getFactorData().ifPresent(factorData -> factorData.update(effectInstance)); | ||
} | ||
else { | ||
livingEntity.removeEffect(this); | ||
} | ||
} | ||
|
||
private void increaseEffectDurationBy(LivingEntity livingEntity, int ticks) { | ||
MobEffectInstance effectInstance = livingEntity.getEffect(this); | ||
if (effectInstance == null) return; | ||
|
||
int increasedDuration = effectInstance.getDuration() + ticks; | ||
((MobEffectInstanceAccessor) effectInstance).setDuration(increasedDuration); | ||
((MobEffectInstanceAccessor) effectInstance).getFactorData().ifPresent(factorData -> factorData.update(effectInstance)); | ||
} | ||
|
||
@Override | ||
public int getMaxEffectStack() { | ||
return maxEffectStack; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.