Skip to content

Commit

Permalink
feat: add Bleed Status Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Jun 16, 2023
1 parent 7cf9389 commit 81792ba
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ private void addDamageTranslations() {
addDeathMessage(ModDamageSources.IMPALED_BY_SPIKE, "%1$s was skewered by a sharp spike");

addDeathMessage(ModDamageSources.CORROSIVE_ACID, "%1$s died from severe acid burns");
addDeathMessage(ModDamageSources.BLEED, "%1$s died from severe blood loss");

addDeathMessage(ModEntityTypes.TOOTH_PROJECTILE, "[WIP] %1$s was forcefully implanted with teeth by %2$s", "[WIP] %1$s received a lethal dental implant by %2$s using %3$s");
addDeathMessage(ModEntityTypes.CORROSIVE_ACID_PROJECTILE, "[WIP] %1$s was doused with corrosive acid by %2$s", "[WIP] %1$s was showered in corrosive acid by %2$s using %3$s");
Expand All @@ -297,8 +298,9 @@ private void addSerumTranslations() {
private void addStatusEffectTranslations() {
addEffect(ModMobEffects.CORROSIVE, "Corrosive Acid");
addEffect(ModMobEffects.ARMOR_SHRED, "Armor Shred");
addEffect(ModMobEffects.ESSENCE_ANEMIA, "[PH] Essence Anemia");
addEffect(ModMobEffects.LIBIDO, "Fertility");
addEffect(ModMobEffects.BLEED, "Bleed");
addEffect(ModMobEffects.ESSENCE_ANEMIA, "[PH] Essence Anemia");
}

private void addEnchantmentTranslations() {
Expand Down
4 changes: 3 additions & 1 deletion src/generated/resources/assets/biomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,16 @@
"enchantment.biomancy.anesthetic.desc": "Prevents the Damage & Aggro caused by injecting mobs with the Injector. Mobs won't know who attacked them and animals won't panic anymore.",
"effect.biomancy.corrosive": "Corrosive Acid",
"effect.biomancy.armor_shred": "Armor Shred",
"effect.biomancy.essence_anemia": "[PH] Essence Anemia",
"effect.biomancy.libido": "Fertility",
"effect.biomancy.bleed": "Bleed",
"effect.biomancy.essence_anemia": "[PH] Essence Anemia",
"serum.biomancy.empty": "ERROR: INVALID SERUM",
"death.attack.biomancy.chest_bite": "%1$s tried touching a chest but was eaten instead",
"death.attack.biomancy.creator_spikes": "%1$s angered the Maykrs and was impaled by bone spikes",
"death.attack.biomancy.spike_fall_on": "%1$s fell on a sharp spike",
"death.attack.biomancy.spike_impale": "%1$s was skewered by a sharp spike",
"death.attack.biomancy.corrosive_acid": "%1$s died from severe acid burns",
"death.attack.biomancy.bleed": "%1$s died from severe blood loss",
"death.attack.biomancy.tooth_projectile": "[WIP] %1$s was forcefully implanted with teeth by %2$s",
"death.attack.biomancy.tooth_projectile.item": "[WIP] %1$s received a lethal dental implant by %2$s using %3$s",
"death.attack.biomancy.corrosive_acid_projectile": "[WIP] %1$s was doused with corrosive acid by %2$s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class ModDamageSources {
public static final DamageSource CHEST_BITE = createDamage("chest_bite").bypassArmor();

public static final DamageSource CORROSIVE_ACID = createDamage("corrosive_acid");
public static final DamageSource BLEED = createDamage("bleed").bypassArmor().bypassMagic().bypassInvul();

public static final DamageSource FALL_ON_SPIKE = createDamage("spike_fall_on").bypassArmor().setIsFall();
public static final DamageSource IMPALED_BY_SPIKE = createDamage("spike_impale").bypassArmor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class ModMobEffects {
public static final RegistryObject<CorrosiveEffect> CORROSIVE = EFFECTS.register("corrosive", () -> new CorrosiveEffect(MobEffectCategory.HARMFUL, 0xbee040));
public static final RegistryObject<StatusEffect> ARMOR_SHRED = EFFECTS.register("armor_shred", () -> new ArmorShredEffect(MobEffectCategory.HARMFUL, 20, 0xbee040)
.addModifier(Attributes.ARMOR, "a15ed03e-c5db-4cf8-a0f5-4eb4657bb731", -1f, AttributeModifier.Operation.ADDITION));
public static final RegistryObject<BleedEffect> BLEED = EFFECTS.register("bleed", () -> new BleedEffect(MobEffectCategory.HARMFUL, 0x8a0303, 2));

public static final RegistryObject<EssenceAnemiaEffect> ESSENCE_ANEMIA = EFFECTS.register("essence_anemia", () -> new EssenceAnemiaEffect(MobEffectCategory.HARMFUL, 0x986c76));
public static final RegistryObject<LibidoEffect> LIBIDO = EFFECTS.register("libido", () -> new LibidoEffect(MobEffectCategory.NEUTRAL, 0xe06a78));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Optional;

@Mixin(MobEffectInstance.class)
public interface MobEffectInstanceAccessor {

@Accessor("amplifier")
void setAmplifier(int amplifier);

@Accessor("duration")
void setDuration(int ticks);

@Accessor("factorData")
Optional<MobEffectInstance.FactorData> getFactorData();

}
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public static void hurtWithAcid(LivingEntity livingEntity, float damage) {
livingEntity.hurt(ModDamageSources.CORROSIVE_ACID, damage);
}

public static void applyBleedEffect(LivingEntity livingEntity, int seconds) {
livingEntity.addEffect(new MobEffectInstance(ModMobEffects.BLEED.get(), seconds * 20, 0, false, false, true));
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 81792ba

Please sign in to comment.