@@ -4,6 +4,8 @@ import at.petrak.hexcasting.api.casting.castables.Action
44import at.petrak.hexcasting.api.casting.eval.env.PackagedItemCastEnv
55import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
66import gay.`object`.hexdebug.debugger.DebugStepType
7+ import gay.`object`.hexdebug.utils.findMediaHolderInHand
8+ import gay.`object`.hexdebug.utils.otherHand
79import net.minecraft.network.chat.Component
810import net.minecraft.server.level.ServerPlayer
911import net.minecraft.world.InteractionHand
@@ -12,6 +14,8 @@ class DebuggerCastEnv(
1214 caster : ServerPlayer ,
1315 castingHand : InteractionHand ,
1416) : PackagedItemCastEnv(caster, castingHand), IDebugCastEnv {
17+ private val item = caster.getItemInHand(castingHand).item
18+
1519 override var lastEvaluatedAction: Action ? = null
1620 override var lastDebugStepType: DebugStepType ? = null
1721
@@ -24,4 +28,29 @@ class DebuggerCastEnv(
2428 super .sendMishapMsgToPlayer(mishap)
2529 printDebugMishap(this , caster, mishap)
2630 }
31+
32+ override fun extractMediaEnvironment (cost : Long ): Long {
33+ if (caster.isCreative) return 0
34+
35+ var costLeft = cost
36+
37+ // allow extracting from a debugger item in either hand, preferring the one we started casting with
38+ // NOTE: if holding two debuggers and the first is empty, this will take the empty one, not the other one
39+ val casterMediaHolder = caster.findMediaHolderInHand(castingHand, item)
40+ ? : caster.findMediaHolderInHand(castingHand.otherHand, item)
41+
42+ // The contracts on the AD and on this function are different.
43+ // ADs return the amount extracted, this wants the amount left
44+ if (casterMediaHolder != null ) {
45+ val extracted = casterMediaHolder.withdrawMedia(costLeft.toInt().toLong(), false )
46+ costLeft - = extracted
47+ }
48+
49+ // debugger can always extract from inventory
50+ if (costLeft > 0 ) {
51+ costLeft = extractMediaFromInventory(costLeft, canOvercast())
52+ }
53+
54+ return costLeft
55+ }
2756}
0 commit comments