2022-01-23 04:53:59 +01:00
|
|
|
package at.petrak.hexcasting.common.casting.operators.spells
|
2021-12-28 00:08:57 +01:00
|
|
|
|
2022-04-28 03:39:14 +02:00
|
|
|
import at.petrak.hexcasting.api.misc.ManaConstants
|
2022-05-20 17:56:33 +02:00
|
|
|
import at.petrak.hexcasting.api.spell.*
|
2022-04-12 21:13:51 +02:00
|
|
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
2022-04-19 02:55:00 +02:00
|
|
|
import net.minecraft.core.BlockPos
|
2021-12-30 23:00:20 +01:00
|
|
|
import net.minecraft.util.Mth
|
2021-12-28 00:08:57 +01:00
|
|
|
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 {
|
2021-12-28 00:08:57 +01:00
|
|
|
override val argc: Int
|
2021-12-30 23:00:20 +01:00
|
|
|
get() = 2
|
2021-12-28 00:08:57 +01:00
|
|
|
|
2022-03-05 01:44:51 +01:00
|
|
|
override fun execute(
|
|
|
|
args: List<SpellDatum<*>>,
|
|
|
|
ctx: CastingContext
|
|
|
|
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
|
2022-05-20 17:56:33 +02:00
|
|
|
val pos = args.getChecked<Vec3>(0, argc)
|
|
|
|
val strength = args.getChecked<Double>(1, argc)
|
2021-12-30 23:00:20 +01:00
|
|
|
ctx.assertVecInRange(pos)
|
2022-06-12 22:06:10 +02:00
|
|
|
val clampedStrength = Mth.clamp(strength, 0.0, 10.0)
|
|
|
|
val cost = ManaConstants.DUST_UNIT * (3 * clampedStrength + if (fire) 0.125 else 1.0)
|
2022-01-30 01:14:33 +01:00
|
|
|
return Triple(
|
2022-06-12 22:06:10 +02:00
|
|
|
Spell(pos, clampedStrength, this.fire),
|
|
|
|
cost.toInt(),
|
|
|
|
listOf(ParticleSpray.burst(pos, clampedStrength, 50))
|
2021-12-30 23:00:20 +01:00
|
|
|
)
|
2021-12-28 00:08:57 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 22:58:32 +01:00
|
|
|
private data class Spell(val pos: Vec3, val strength: Double, val fire: Boolean) : RenderedSpell {
|
2021-12-31 02:54:32 +01:00
|
|
|
override fun cast(ctx: CastingContext) {
|
2022-04-19 02:55:00 +02:00
|
|
|
if (!ctx.world.mayInteract(ctx.caster, BlockPos(pos)))
|
|
|
|
return
|
|
|
|
|
2021-12-31 02:54:32 +01:00
|
|
|
ctx.world.explode(
|
|
|
|
ctx.caster,
|
|
|
|
pos.x,
|
|
|
|
pos.y,
|
|
|
|
pos.z,
|
2022-06-12 22:06:10 +02:00
|
|
|
strength.toFloat(),
|
2022-01-16 22:58:32 +01:00
|
|
|
this.fire,
|
2021-12-31 02:54:32 +01:00
|
|
|
Explosion.BlockInteraction.BREAK
|
|
|
|
)
|
|
|
|
}
|
2021-12-28 00:08:57 +01:00
|
|
|
}
|
2022-04-09 03:12:39 +02:00
|
|
|
}
|