@Alwinfy ravenmind semantics

This commit is contained in:
petrak@ 2023-02-08 09:58:02 -06:00
parent a7a5073a74
commit 50554d5bf7
4 changed files with 20 additions and 11 deletions

View file

@ -111,7 +111,7 @@ public interface HexAPI {
/**
* Location in the userdata of the ravenmind
*/
ResourceLocation RAVENMIND_USERDATA = modLoc("ravenmind");
String RAVENMIND_USERDATA = modLoc("ravenmind").toString();
static HexAPI instance() {
return INSTANCE.get();

View file

@ -18,6 +18,7 @@ import at.petrak.hexcasting.api.utils.*
import at.petrak.hexcasting.common.casting.PatternRegistryManifest
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerLevel
@ -177,7 +178,7 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
val result = action.operate(
this.env,
this.image.stack.toMutableList(),
this.image.userData,
this.image.userData.copy(),
continuation
)
cont2 = result.newContinuation
@ -230,8 +231,8 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
fun generateDescs(): Pair<List<Component>, Component?> {
val stackDescs = this.image.stack.map { it.display() }
val ravenmind = if (this.image.userData.contains(HexAPI.RAVENMIND_USERDATA.toString())) {
val tag = this.image.userData.getCompound(HexAPI.RAVENMIND_USERDATA.toString())
val ravenmind = if (this.image.userData.contains(HexAPI.RAVENMIND_USERDATA)) {
val tag = this.image.userData.getCompound(HexAPI.RAVENMIND_USERDATA)
IotaType.getDisplay(tag)
} else null
return Pair(stackDescs, ravenmind)

View file

@ -1,11 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.casting.castables.Action
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.OperationResult
import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.orNull
import at.petrak.hexcasting.api.casting.iota.IotaType
import at.petrak.hexcasting.api.casting.iota.NullIota
import net.minecraft.nbt.CompoundTag
object OpPeekLocal : Action {
@ -15,9 +17,12 @@ object OpPeekLocal : Action {
userData: CompoundTag,
continuation: SpellContinuation
): OperationResult {
// TODO winfy: figure out ravenmind semantics
stack.add(userData.getCompound(CastingEnvironment.TAG_RAVENMIND))
//IotaType.deserialize(subtag.downcast(CompoundTag.TYPE), world)
val rm = if (userData.contains(HexAPI.RAVENMIND_USERDATA)) {
IotaType.deserialize(userData.getCompound(HexAPI.RAVENMIND_USERDATA), env.world)
} else {
NullIota()
}
stack.add(rm)
return OperationResult(stack, userData, listOf(), continuation)
}
}

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.casting.castables.Action
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.OperationResult
@ -15,10 +16,12 @@ object OpPushLocal : Action {
userData: CompoundTag,
continuation: SpellContinuation
): OperationResult {
// TODO winfy: figure out ravenmind semantics
if (stack.isEmpty())
throw MishapNotEnoughArgs(1, 0)
val newLocal = stack.removeLast().serialize()
return OperationResult(stack, newLocal, listOf(), continuation)
val newLocal = stack.removeLast()
userData.put(HexAPI.RAVENMIND_USERDATA, newLocal.serialize())
return OperationResult(stack, userData, listOf(), continuation)
}
}