Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface CommonConfigAccess {

int artifactCooldown();

int explosionScaling();

long DEFAULT_DUST_MEDIA_AMOUNT = MediaConstants.DUST_UNIT;
long DEFAULT_SHARD_MEDIA_AMOUNT = MediaConstants.SHARD_UNIT;
long DEFAULT_CHARGED_MEDIA_AMOUNT = MediaConstants.CRYSTAL_UNIT;
Expand All @@ -36,6 +38,7 @@ public interface CommonConfigAccess {
int DEFAULT_TRINKET_COOLDOWN = 5;
int DEFAULT_ARTIFACT_COOLDOWN = 3;

int DEFAULT_EXPLOSION_SCALING = 100;
}

public interface ClientConfigAccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.casting.getVec3
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.common.casting.actions.selectors.OpGetEntitiesBy
import at.petrak.hexcasting.helper.ExplosionSourceTracker
import net.minecraft.core.BlockPos
import net.minecraft.util.Mth
import net.minecraft.world.level.Level
Expand Down Expand Up @@ -53,15 +54,20 @@ class OpExplode(val fire: Boolean) : SpellAction {
if (!env.canEditBlockAt(BlockPos.containing(pos)))
return

env.world.explode(
env.castingEntity,
pos.x,
pos.y,
pos.z,
strength.toFloat(),
this.fire,
Level.ExplosionInteraction.TNT
)
ExplosionSourceTracker.setSpellSource(true)
try {
env.world.explode(
env.castingEntity,
pos.x,
pos.y,
pos.z,
strength.toFloat(),
this.fire,
Level.ExplosionInteraction.TNT
)
} finally {
ExplosionSourceTracker.setSpellSource(false)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package at.petrak.hexcasting.helper;

public final class ExplosionSourceTracker {
private static final ThreadLocal<Boolean> IS_SPELL_SOURCE = ThreadLocal.withInitial(() -> false);

public static boolean isSpellSource() {
return IS_SPELL_SOURCE.get();
}

public static void setSpellSource(boolean spellSource) {
IS_SPELL_SOURCE.set(spellSource);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package at.petrak.hexcasting.mixin;

import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.helper.ExplosionSourceTracker;
import net.minecraft.world.level.Explosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(Explosion.class)
public abstract class MixinExplosion {
@ModifyArgs(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private void scaleEntityExplosionDamage(Args args) {
if (ExplosionSourceTracker.isSpellSource()) {
args.set(1, (Float) args.get(1) * HexConfig.common().explosionScaling() / 100f);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@
"": "Artifact Cooldown",
"@Tooltip": "Cooldown of an artifact in ticks",
},
explosionScaling: {
"": "Explosion Scaling",
"@Tooltip": "Scaling for entity damage caused by explosion spells in %",
},
},

client: {
Expand Down
1 change: 1 addition & 0 deletions Common/src/main/resources/hexplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"MixinVillager",
"MixinWanderingTrader",
"MixinWitch",
"MixinExplosion",
"accessor.AccessorAbstractArrow",
"accessor.AccessorEntity",
"accessor.AccessorLivingEntity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public static final class Common implements HexConfig.CommonConfigAccess, Config
@ConfigEntry.Gui.Tooltip
private int artifactCooldown = DEFAULT_ARTIFACT_COOLDOWN;

@ConfigEntry.Gui.Tooltip
private int explosionScaling = DEFAULT_EXPLOSION_SCALING;

@Override
public void validatePostLoad() throws ValidationException {
Expand Down Expand Up @@ -123,6 +125,12 @@ public int trinketCooldown() {
public int artifactCooldown() {
return artifactCooldown;
}

@Override
public int explosionScaling() {
return explosionScaling;
}

}

@Config(name = "client")
Expand Down
12 changes: 12 additions & 0 deletions Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ForgeHexConfig implements HexConfig.CommonConfigAccess {
private static ForgeConfigSpec.IntValue trinketCooldown;
private static ForgeConfigSpec.IntValue artifactCooldown;

private static ForgeConfigSpec.IntValue explosionScaling;

public ForgeHexConfig(ForgeConfigSpec.Builder builder) {
builder.push("Media Amounts");
dustMediaAmount = builder.comment("How much media a single Amethyst Dust item is worth")
Expand All @@ -43,6 +45,11 @@ public ForgeHexConfig(ForgeConfigSpec.Builder builder) {
artifactCooldown = builder.comment("Cooldown in ticks of a artifact")
.defineInRange("artifactCooldown", DEFAULT_ARTIFACT_COOLDOWN, 0, Integer.MAX_VALUE);
builder.pop();

builder.push("Misc");
explosionScaling = builder.comment("Scaling for entity damage caused by explosion spells in %")
.defineInRange("explosionScaling", DEFAULT_EXPLOSION_SCALING, 0, Integer.MAX_VALUE);
builder.pop();
}

@Override
Expand Down Expand Up @@ -80,6 +87,11 @@ public int artifactCooldown() {
return artifactCooldown.get();
}

@Override
public int explosionScaling() {
return explosionScaling.get();
}

public static class Client implements HexConfig.ClientConfigAccess {
private static ForgeConfigSpec.BooleanValue ctrlTogglesOffStrokeOrder;
private static ForgeConfigSpec.BooleanValue disableInworldScrolling;
Expand Down