HexCasting/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpExplode.kt

48 lines
1.6 KiB
Kotlin
Raw Normal View History

package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
2022-04-12 21:13:51 +02:00
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.util.Mth
import net.minecraft.world.level.Explosion
import net.minecraft.world.phys.Vec3
2022-01-16 22:58:32 +01:00
class OpExplode(val fire: Boolean) : SpellOperator {
override val argc: Int
get() = 2
override fun execute(
args: List<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0, argc)
val strength = args.getChecked<Double>(1, argc)
ctx.assertVecInRange(pos)
val clampedStrength = Mth.clamp(strength, 0.0, 10.0)
val cost = ManaConstants.DUST_UNIT * (3 * clampedStrength + if (fire) 0.125 else 1.0)
return Triple(
Spell(pos, clampedStrength, this.fire),
cost.toInt(),
listOf(ParticleSpray.burst(pos, clampedStrength, 50))
)
}
2022-01-16 22:58:32 +01:00
private data class Spell(val pos: Vec3, val strength: Double, val fire: Boolean) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (!ctx.world.mayInteract(ctx.caster, BlockPos(pos)))
return
ctx.world.explode(
ctx.caster,
pos.x,
pos.y,
pos.z,
strength.toFloat(),
2022-01-16 22:58:32 +01:00
this.fire,
Explosion.BlockInteraction.BREAK
)
}
}
2022-04-09 03:12:39 +02:00
}