Skip to content

Commit

Permalink
Even more scaling damage options
Browse files Browse the repository at this point in the history
  • Loading branch information
jss2a98aj committed May 14, 2023
1 parent 44e269b commit 6e27291
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/jss/bugtorch/config/BugTorchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ public List<String> getMixins(Set<String> 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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 6e27291

Please sign in to comment.