Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Oct 27, 2024
1 parent cf055ae commit 0ce699e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import at.petrak.hexcasting.api.spell.getList
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import miyucomics.hexical.enums.FakeGambit
import miyucomics.hexical.enums.InjectedGambit
import miyucomics.hexical.interfaces.FrameForEachMinterface

object OpSisyphus : Action, FakeGambit {
object OpSisyphus : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, ravenmind: Iota?, ctx: CastingContext): OperationResult {
if (stack.size == 0)
throw MishapNotEnoughArgs(1, 0)
Expand All @@ -31,15 +30,17 @@ object OpSisyphus : Action, FakeGambit {
return OperationResult(continuation.pushFrame(frame), stack, ravenmind, listOf())
}

override fun breakDownwards(baseStack: List<Iota>, accumulator: MutableList<Iota>): Pair<Boolean, List<Iota>> = true to baseStack
@JvmStatic
fun breakDownwards(baseStack: List<Iota>): Pair<Boolean, List<Iota>> = true to baseStack

override fun evaluate(continuation: SpellContinuation, harness: CastingHarness, data: SpellList, code: SpellList, baseStack: List<Iota>?, accumulator: MutableList<Iota>): CastingHarness.CastResult {
@JvmStatic
fun evaluate(continuation: SpellContinuation, harness: CastingHarness, code: SpellList, baseStack: List<Iota>): CastingHarness.CastResult {
harness.ctx.incDepth()
val frame = FrameForEach(SpellList.LList(0, listOf()), code, baseStack, mutableListOf())
(frame as FrameForEachMinterface).overwrite(InjectedGambit.SISYPHUS)
return CastingHarness.CastResult(
continuation.pushFrame(frame).pushFrame(FrameEvaluate(code, true)),
FunctionalData(baseStack!!, 0, listOf(), false, harness.ravenmind),
FunctionalData(baseStack, 0, listOf(), false, harness.ravenmind),
ResolvedPatternType.EVALUATED,
listOf(),
HexEvalSounds.THOTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import at.petrak.hexcasting.api.spell.iota.PatternIota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import miyucomics.hexical.casting.mishaps.ThemisMishap
import miyucomics.hexical.enums.FakeGambit
import miyucomics.hexical.enums.InjectedGambit
import miyucomics.hexical.interfaces.FrameForEachMinterface

object OpThemis : Action, FakeGambit {
object OpThemis : Action {
override fun operate(continuation: SpellContinuation, stack: MutableList<Iota>, ravenmind: Iota?, ctx: CastingContext): OperationResult {
if (stack.size < 2)
throw MishapNotEnoughArgs(1, 0)
Expand All @@ -38,7 +37,8 @@ object OpThemis : Action, FakeGambit {
return OperationResult(continuation.pushFrame(frame), stack, ravenmind, listOf())
}

override fun breakDownwards(baseStack: List<Iota>, accumulator: MutableList<Iota>): Pair<Boolean, List<Iota>> {
@JvmStatic
fun breakDownwards(baseStack: List<Iota>, accumulator: MutableList<Iota>): Pair<Boolean, List<Iota>> {
val final = mutableListOf<Iota>()
val itemPriorityPairs = accumulator.chunked(2)
val sortedPairs = itemPriorityPairs.sortedBy { (it[1] as DoubleIota).double }
Expand All @@ -49,7 +49,8 @@ object OpThemis : Action, FakeGambit {
return true to newStack
}

override fun evaluate(continuation: SpellContinuation, harness: CastingHarness, data: SpellList, code: SpellList, baseStack: List<Iota>?, accumulator: MutableList<Iota>): CastingHarness.CastResult {
@JvmStatic
fun evaluate(continuation: SpellContinuation, harness: CastingHarness, data: SpellList, code: SpellList, baseStack: List<Iota>?, accumulator: MutableList<Iota>): CastingHarness.CastResult {
val stack: List<Iota> = if (baseStack == null) {
harness.stack.toList()
} else {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/miyucomics/hexical/enums/InjectedGambit.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package miyucomics.hexical.enums

import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingHarness
import at.petrak.hexcasting.api.spell.casting.eval.SpellContinuation
import at.petrak.hexcasting.api.spell.iota.Iota

enum class InjectedGambit {
THEMIS,
SISYPHUS,
NONE
}

interface FakeGambit {
fun breakDownwards(baseStack: List<Iota>, accumulator: MutableList<Iota>): Pair<Boolean, List<Iota>>
fun evaluate(continuation: SpellContinuation, harness: CastingHarness, data: SpellList, code: SpellList, baseStack: List<Iota>?, accumulator: MutableList<Iota>): CastingHarness.CastResult
}
11 changes: 8 additions & 3 deletions src/main/java/miyucomics/hexical/mixin/FrameForEachMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import kotlin.Pair;
import miyucomics.hexical.casting.patterns.eval.OpSisyphus;
import miyucomics.hexical.casting.patterns.eval.OpThemis;
import miyucomics.hexical.enums.FakeGambit;
import miyucomics.hexical.enums.InjectedGambit;
import miyucomics.hexical.interfaces.FrameForEachMinterface;
import net.minecraft.server.world.ServerWorld;
Expand Down Expand Up @@ -43,14 +42,20 @@ public abstract class FrameForEachMixin implements FrameForEachMinterface {
void hijackBreaking(List<? extends Iota> stack, CallbackInfoReturnable<Pair<Boolean, List<Iota>>> cir) {
if (hexical$injectedGambit == InjectedGambit.NONE)
return;
cir.setReturnValue(((FakeGambit) this).breakDownwards(getBaseStack(), getAcc()));
if (hexical$injectedGambit == InjectedGambit.SISYPHUS)
cir.setReturnValue(OpSisyphus.breakDownwards(getBaseStack()));
if (hexical$injectedGambit == InjectedGambit.THEMIS)
cir.setReturnValue(OpThemis.breakDownwards(getBaseStack(), getAcc()));
}

@Inject(method = "evaluate", at = @At("HEAD"), cancellable = true)
void hijackEvaluate(SpellContinuation continuation, ServerWorld level, CastingHarness harness, CallbackInfoReturnable<CastingHarness.CastResult> cir) {
if (hexical$injectedGambit == InjectedGambit.NONE)
return;
cir.setReturnValue(((FakeGambit) this).evaluate(continuation, harness, getData(), getCode(), getBaseStack(), getAcc()));
if (hexical$injectedGambit == InjectedGambit.SISYPHUS)
cir.setReturnValue(OpSisyphus.evaluate(continuation, harness, getCode(), getBaseStack()));
if (hexical$injectedGambit == InjectedGambit.THEMIS)
cir.setReturnValue(OpThemis.evaluate(continuation, harness, getData(), getCode(), getBaseStack(), getAcc()));
}

@Override
Expand Down

0 comments on commit 0ce699e

Please sign in to comment.