brainsweeping fail now attributes the damage to the caster
this is to prevent Murder Villager from being a cheap and easy disposal solution for all your pesky mindflayed problems
This commit is contained in:
parent
123bc988ca
commit
22919b5f56
10 changed files with 57 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
package at.petrak.hexcasting.common.misc;
|
package at.petrak.hexcasting.api.misc;
|
||||||
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package at.petrak.hexcasting.api.misc;
|
||||||
|
|
||||||
|
import net.minecraft.world.damagesource.EntityDamageSource;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
|
public class EntityDamageSourceOvercast extends EntityDamageSource {
|
||||||
|
public EntityDamageSourceOvercast(Entity entity) {
|
||||||
|
super("hexcasting.overcast", entity);
|
||||||
|
this.bypassArmor();
|
||||||
|
this.bypassMagic();
|
||||||
|
this.setMagic();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,12 @@
|
||||||
package at.petrak.hexcasting.api.misc;
|
package at.petrak.hexcasting.api.misc;
|
||||||
|
|
||||||
import at.petrak.hexcasting.common.misc.DamageSourceOvercast;
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
public final class HexDamageSources {
|
public final class HexDamageSources {
|
||||||
public static final DamageSource OVERCAST = new DamageSourceOvercast();
|
public static final DamageSource OVERCAST = new DamageSourceOvercast();
|
||||||
|
|
||||||
|
public static DamageSource overcastDamageFrom(Entity cause) {
|
||||||
|
return new EntityDamageSourceOvercast(cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ class CastingHarness private constructor(
|
||||||
HexAdvancementTriggers.OVERCAST_TRIGGER.trigger(this.ctx.caster, manaToActuallyPayFor)
|
HexAdvancementTriggers.OVERCAST_TRIGGER.trigger(this.ctx.caster, manaToActuallyPayFor)
|
||||||
this.ctx.caster.awardStat(HexStatistics.MANA_OVERCASTED, manaCost - costLeft)
|
this.ctx.caster.awardStat(HexStatistics.MANA_OVERCASTED, manaCost - costLeft)
|
||||||
|
|
||||||
this.ctx.caster.hurt(HexDamageSources.OVERCAST, healthtoRemove.toFloat())
|
Mishap.trulyHurt(this.ctx.caster, HexDamageSources.OVERCAST, healthtoRemove.toFloat())
|
||||||
costLeft -= manaToActuallyPayFor
|
costLeft -= manaToActuallyPayFor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,15 @@ import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
import at.petrak.hexcasting.api.spell.math.HexPattern
|
import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||||
import at.petrak.hexcasting.common.lib.HexItems
|
import at.petrak.hexcasting.common.lib.HexItems
|
||||||
|
import at.petrak.hexcasting.mixin.accessor.AccessorLivingEntity
|
||||||
import net.minecraft.ChatFormatting
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.Util
|
import net.minecraft.Util
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.network.chat.Style
|
import net.minecraft.network.chat.Style
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import net.minecraft.world.damagesource.DamageSource
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
import net.minecraft.world.entity.item.ItemEntity
|
import net.minecraft.world.entity.item.ItemEntity
|
||||||
import net.minecraft.world.item.DyeColor
|
import net.minecraft.world.item.DyeColor
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
@ -61,4 +64,17 @@ sealed class Mishap : Throwable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Context(val pattern: HexPattern, val action: ResourceLocation?)
|
data class Context(val pattern: HexPattern, val action: ResourceLocation?)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun trulyHurt(entity: LivingEntity, source: DamageSource, amount: Float) {
|
||||||
|
if (entity.invulnerableTime > 10) {
|
||||||
|
val lastHurt = (entity as AccessorLivingEntity).`hex$getLastHurt`()
|
||||||
|
if (lastHurt < amount)
|
||||||
|
entity.invulnerableTime = 0
|
||||||
|
else
|
||||||
|
entity.`hex$setLastHurt`(lastHurt - amount)
|
||||||
|
}
|
||||||
|
entity.hurt(source, amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MishapAlreadyBrainswept(val villager: Villager) : Mishap() {
|
||||||
dyeColor(DyeColor.GREEN)
|
dyeColor(DyeColor.GREEN)
|
||||||
|
|
||||||
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
||||||
villager.hurt(HexDamageSources.OVERCAST, villager.health)
|
villager.hurt(HexDamageSources.overcastDamageFrom(ctx.caster), villager.health)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun particleSpray(ctx: CastingContext): ParticleSpray {
|
override fun particleSpray(ctx: CastingContext): ParticleSpray {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MishapBadBrainsweep(val villager: Villager, val pos: BlockPos) : Mishap()
|
||||||
dyeColor(DyeColor.GREEN)
|
dyeColor(DyeColor.GREEN)
|
||||||
|
|
||||||
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
||||||
villager.hurt(HexDamageSources.OVERCAST, villager.health)
|
trulyHurt(villager, HexDamageSources.overcastDamageFrom(ctx.caster), villager.health)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun particleSpray(ctx: CastingContext): ParticleSpray {
|
override fun particleSpray(ctx: CastingContext): ParticleSpray {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class MishapDivideByZero(val operand1: Component, val operand2: Component, val s
|
||||||
|
|
||||||
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
|
||||||
stack.add(SpellDatum.make(Widget.GARBAGE))
|
stack.add(SpellDatum.make(Widget.GARBAGE))
|
||||||
ctx.caster.hurt(HexDamageSources.OVERCAST, ctx.caster.health / 2)
|
trulyHurt(ctx.caster, HexDamageSources.OVERCAST, ctx.caster.health / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Component {
|
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Component {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package at.petrak.hexcasting.mixin.accessor;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(LivingEntity.class)
|
||||||
|
public interface AccessorLivingEntity {
|
||||||
|
@Accessor("lastHurt")
|
||||||
|
float hex$getLastHurt();
|
||||||
|
|
||||||
|
@Accessor("lastHurt")
|
||||||
|
void hex$setLastHurt(float lastHurt);
|
||||||
|
}
|
|
@ -5,7 +5,10 @@
|
||||||
"refmap": "hexcasting.mixins.refmap.json",
|
"refmap": "hexcasting.mixins.refmap.json",
|
||||||
"package": "at.petrak.hexcasting.mixin",
|
"package": "at.petrak.hexcasting.mixin",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinMob", "MixinVillager", "accessor.AccessorUseOnContext",
|
"MixinMob",
|
||||||
|
"MixinVillager",
|
||||||
|
"accessor.AccessorLivingEntity",
|
||||||
|
"accessor.AccessorUseOnContext",
|
||||||
"accessor.CriteriaTriggersAccessor"
|
"accessor.CriteriaTriggersAccessor"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue