From 6e272914cfe5a47b332da5c85fe58c5de8a79ff5 Mon Sep 17 00:00:00 2001 From: jss2a98aj Date: Sat, 13 May 2023 23:52:13 -0400 Subject: [PATCH] Even more scaling damage options --- .../jss/bugtorch/config/BugTorchConfig.java | 8 +++++ .../mixinplugin/BugTorchEarlyMixins.java | 7 ++++ .../tweaks/damage/MixinFireDamage_Entity.java | 36 +++++++++++++++++++ .../damage/MixinFireDamage_EntityPlayer.java | 23 ++++++++++++ .../tweaks/damage/MixinLavaDamage.java | 31 ++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_Entity.java create mode 100644 src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_EntityPlayer.java create mode 100644 src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinLavaDamage.java diff --git a/src/main/java/jss/bugtorch/config/BugTorchConfig.java b/src/main/java/jss/bugtorch/config/BugTorchConfig.java index a8526ef..c3eadfd 100644 --- a/src/main/java/jss/bugtorch/config/BugTorchConfig.java +++ b/src/main/java/jss/bugtorch/config/BugTorchConfig.java @@ -98,6 +98,10 @@ public class BugTorchConfig { public static boolean removeEntityDuplicateExtendedPropertiesIdentifierSpam; public static float scaledDrowningDamageMaxHealthFlat; public static float scaledDrowningDamageMaxHealthMult; + public static float scaledFireDamageMaxHealthFlat; + public static float scaledFireDamageMaxHealthMult; + public static float scaledLavaDamageMaxHealthFlat; + public static float scaledLavaDamageMaxHealthMult; public static float scaledPoisonDamageMaxHealthFlat; public static float scaledPoisonDamageMaxHealthMult; public static float scaledStarvationDamageMaxHealthFlat; @@ -240,6 +244,10 @@ public static void loadBaseMixinConfig(File configFile) { removeEntityDuplicateExtendedPropertiesIdentifierSpam = config.getBoolean("removeEntityDuplicateExtendedPropertiesIdentifierSpam", categoryTweaks, true, "Removes \"An attempt was made to register extended properties using an existing key\" log spam caused by some mods."); scaledDrowningDamageMaxHealthFlat = config.getFloat("scaledDrowningDamageMaxHealthFlat", categoryTweaks, 0f, 0f, 20000f, "Amount of flat player health to remove each drowning tick.\nSet to 0 to disable."); scaledDrowningDamageMaxHealthMult = config.getFloat("scaledDrowningDamageMaxHealthMult", categoryTweaks, 0f, 0f, 1f, "Portion of max player health to remove each drowning tick.\nSet to 0 to disable."); + scaledFireDamageMaxHealthFlat = config.getFloat("scaledFireDamageMaxHealthFlat", categoryTweaks, 0f, 0f, 20000f, "Amount of flat player health to remove each fire tick.\nSet to 0 to disable."); + scaledFireDamageMaxHealthMult = config.getFloat("scaledFireDamageMaxHealthMult", categoryTweaks, 0f, 0f, 1f, "Portion of max player health to remove each fire tick.\nSet to 0 to disable."); + scaledLavaDamageMaxHealthFlat = config.getFloat("scaledLavaDamageMaxHealthFlat", categoryTweaks, 0f, 0f, 20000f, "Amount of flat player health to remove each lava tick.\nSet to 0 to disable."); + scaledLavaDamageMaxHealthMult = config.getFloat("scaledLavaDamageMaxHealthMult", categoryTweaks, 0f, 0f, 1f, "Portion of max player health to remove each lava tick.\nSet to 0 to disable."); scaledPoisonDamageMaxHealthFlat = config.getFloat("scaledPoisonDamageMaxHealthFlat", categoryTweaks, 0f, 0f, 20000f, "Portion of max player health to remove each poison effect tick.\nSet to 0 to disable."); scaledPoisonDamageMaxHealthMult = config.getFloat("scaledPoisonDamageMaxHealthMult", categoryTweaks, 0f, 0f, 1f, "Portion of max player health to remove each poison effect tick.\nSet to 0 to disable."); scaledStarvationDamageMaxHealthFlat = config.getFloat("scaledStarvationDamageMaxHealthFlat", categoryTweaks, 0f, 0f, 20000f, "Amount of flat player health to remove each starvation tick.\nSet to 0 to disable."); diff --git a/src/main/java/jss/bugtorch/mixinplugin/BugTorchEarlyMixins.java b/src/main/java/jss/bugtorch/mixinplugin/BugTorchEarlyMixins.java index 83479e3..ac52d5b 100644 --- a/src/main/java/jss/bugtorch/mixinplugin/BugTorchEarlyMixins.java +++ b/src/main/java/jss/bugtorch/mixinplugin/BugTorchEarlyMixins.java @@ -217,6 +217,13 @@ public List getMixins(Set loadedCoreMods) { if(BugTorchConfig.scaledDrowningDamageMaxHealthFlat > 0f || BugTorchConfig.scaledDrowningDamageMaxHealthMult > 0f) { mixins.add("minecraft.tweaks.entitylivingbase.MixinScalingDrowningDamage"); } + if(BugTorchConfig.scaledLavaDamageMaxHealthFlat > 0f || BugTorchConfig.scaledLavaDamageMaxHealthMult > 0f) { + mixins.add("minecraft.tweaks.damage.MixinLavaDamage"); + } + if(BugTorchConfig.scaledFireDamageMaxHealthFlat > 0f || BugTorchConfig.scaledFireDamageMaxHealthMult > 0f) { + mixins.add("minecraft.tweaks.damage.MixinFireDamage_Entity"); + mixins.add("minecraft.tweaks.damage.MixinFireDamage_EntityPlayer"); + } if(BugTorchConfig.scaledStarvationDamageMaxHealthFlat > 0f || BugTorchConfig.scaledStarvationDamageMaxHealthMult > 0f) { mixins.add("minecraft.tweaks.MixinFoodStats"); } diff --git a/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_Entity.java b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_Entity.java new file mode 100644 index 0000000..f68813f --- /dev/null +++ b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_Entity.java @@ -0,0 +1,36 @@ +package jss.bugtorch.mixins.early.minecraft.tweaks.damage; + +import jss.bugtorch.BugTorch; +import net.minecraft.entity.Entity; +import net.minecraft.util.DamageSource; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(value = Entity.class) +public abstract class MixinFireDamage_Entity { + + /** + * @author jss2a98aj + * @reason Makes fire damage scale with max health. + */ + @Redirect( + method = "onEntityUpdate()V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z" + ) + ) + private boolean bugTorch$scalingFireDamage(Entity entity, DamageSource source, float damage) { + return bugTorch$doFireDamage(); + } + + public boolean bugTorch$doFireDamage() { + return attackEntityFrom(DamageSource.onFire, 1.0F); + } + + @Shadow + public abstract boolean attackEntityFrom(DamageSource source, float amount); + +} diff --git a/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_EntityPlayer.java b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_EntityPlayer.java new file mode 100644 index 0000000..4870caa --- /dev/null +++ b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinFireDamage_EntityPlayer.java @@ -0,0 +1,23 @@ +package jss.bugtorch.mixins.early.minecraft.tweaks.damage; + +import jss.bugtorch.config.BugTorchConfig; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(value = EntityPlayer.class) +public abstract class MixinFireDamage_EntityPlayer extends EntityLivingBase { + + public boolean bugTorch$doFireDamage() { + return attackEntityFrom(DamageSource.onFire, + BugTorchConfig.scaledFireDamageMaxHealthMult * getMaxHealth() + BugTorchConfig.scaledFireDamageMaxHealthFlat + ); + } + + public MixinFireDamage_EntityPlayer(World world) { + super(world); + } + +} diff --git a/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinLavaDamage.java b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinLavaDamage.java new file mode 100644 index 0000000..31ff3f0 --- /dev/null +++ b/src/main/java/jss/bugtorch/mixins/early/minecraft/tweaks/damage/MixinLavaDamage.java @@ -0,0 +1,31 @@ +package jss.bugtorch.mixins.early.minecraft.tweaks.damage; + +import jss.bugtorch.config.BugTorchConfig; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(value = EntityPlayer.class) +public abstract class MixinLavaDamage extends EntityLivingBase { + + /** + * @author jss2a98aj + * @reason Makes lava damage scale with max health. + */ + @Override + protected void setOnFireFromLava() { + if(!isImmuneToFire) { + attackEntityFrom(DamageSource.lava, + BugTorchConfig.scaledLavaDamageMaxHealthMult * getMaxHealth() + BugTorchConfig.scaledLavaDamageMaxHealthFlat + ); + setFire(15); + } + } + + public MixinLavaDamage(World world) { + super(world); + } + +}