Skip to content

Commit afed9ea

Browse files
vgskyeAlwinfy
authored andcommitted
Make ConstMediaAction check for media cost later
Throwing MishapNotEnoughMedia early actually broke parity with SpellActions and pre-1.20 behaviour, since validation mishaps comes before MishapNotEnoughMedia. This moves simulated media extraction to after execution to restore parity. Note that this still doesn't let you raycast for free because a mishap thrown will void the new stack.
1 parent 295ebdb commit afed9ea

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/castables/ConstMediaAction.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ interface ConstMediaAction : Action {
2828
override fun operate(env: CastingEnvironment, image: CastingImage, continuation: SpellContinuation): OperationResult {
2929
val stack = image.stack.toMutableList()
3030

31-
if (env.extractMedia(this.mediaCost, true) > 0)
32-
throw MishapNotEnoughMedia(this.mediaCost)
3331
if (this.argc > stack.size)
3432
throw MishapNotEnoughArgs(this.argc, stack.size)
3533
val args = stack.takeLast(this.argc)
3634
repeat(this.argc) { stack.removeLast() }
3735
val result = this.executeWithOpCount(args, env)
3836
stack.addAll(result.resultStack)
3937

38+
if (env.extractMedia(this.mediaCost, true) > 0)
39+
throw MishapNotEnoughMedia(this.mediaCost)
40+
4041
val sideEffects = mutableListOf<OperatorSideEffect>(OperatorSideEffect.ConsumeMedia(this.mediaCost))
4142

4243
val image2 = image.copy(stack = stack, opsConsumed = image.opsConsumed + result.opCount)

0 commit comments

Comments
 (0)