repo for my hex addons :3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

subscript execution

+47 -2
+47 -2
project/iotaworks/src/main/scala/org/eu/net/pool/iotaworks/main.scala
··· 3 3 4 4 import at.petrak.hexcasting.api.casting.eval.vm.{CastingImage, CastingVM, SpellContinuation} 5 5 import at.petrak.hexcasting.api.casting.eval.{CastResult, CastingEnvironment, ResolvedPatternType} 6 - import at.petrak.hexcasting.api.casting.iota.{GarbageIota, Iota, IotaType, PatternIota, DoubleIota, Vec3Iota} 6 + import at.petrak.hexcasting.api.casting.iota.{GarbageIota, Iota, IotaType, PatternIota, DoubleIota, NullIota, Vec3Iota} 7 7 import at.petrak.hexcasting.api.casting.math.HexPattern 8 8 import at.petrak.hexcasting.api.casting.mishaps.Mishap 9 9 import at.petrak.hexcasting.api.casting.mishaps.Mishap.Context ··· 11 11 import at.petrak.hexcasting.common.casting.actions.eval.OpEval 12 12 import com.google.gson.JsonElement 13 13 import miyucomics.hexcellular.{PropertyIota, StateStorage} 14 - import net.minecraft.nbt.{NbtCompound, NbtElement, NbtString} 14 + import net.minecraft.nbt.{NbtCompound, NbtList, NbtElement, NbtString} 15 15 import net.minecraft.server.world.ServerWorld 16 16 import net.minecraft.text.Text 17 17 import net.minecraft.util.{DyeColor, Identifier} ··· 19 19 import org.slf4j.{Logger, LoggerFactory} 20 20 21 21 import java.{lang, util, util as ju} 22 + import at.petrak.hexcasting.api.casting.eval.vm.ContinuationFrame 23 + import kotlin.Pair 24 + import at.petrak.hexcasting.api.casting.eval.vm.ContinuationFrame.Type 25 + import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound 26 + import at.petrak.hexcasting.common.lib.hex.HexEvalSounds 22 27 23 28 private[iotaworks] given Logger = LoggerFactory.getLogger("iotaworks") 24 29 private[iotaworks] given Conversion[String, Identifier] = Identifier.of("iotaworks", _) ··· 77 82 val validValues = Seq(0x0, 0x3, 0x6, 0x9, 0xC, 0xF) 78 83 val colors: Map[(Int, Int, Int), MetatableIotaType] = (for r <- validValues; g <- validValues; b <- validValues yield (r, g, b) -> MetatableIotaType((r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b)).toMap 79 84 println(s"Metatables: $colors") 85 + 86 + class DeltaFrame(delta: Int) extends ContinuationFrame: 87 + def breakDownwards(stack: ju.List[? <: Iota]): Pair[java.lang.Boolean, ju.List[Iota]] = Pair(true, stack.toSeq) 88 + def getType(): Type[DeltaFrame] = DeltaFrame 89 + def serializeToNBT = 90 + val c = NbtCompound() 91 + c.putInt("d", delta) 92 + c 93 + def size = 0 94 + def evaluate(cont: SpellContinuation, world: ServerWorld, vm: CastingVM): CastResult = 95 + CastResult(GarbageIota(), cont, DeltaFrame.shift(vm.getImage, delta), Seq(), ResolvedPatternType.EVALUATED, HexEvalSounds.NOTHING) 96 + object DeltaFrame extends ContinuationFrame.Type[DeltaFrame]: 97 + def deserializeFromNBT(data: NbtCompound, world: ServerWorld): DeltaFrame = 98 + DeltaFrame(data.getInt("d")) 99 + def shift(image: CastingImage, delta: Int): CastingImage = 100 + val data = image.getUserData 101 + val list: NbtList = data.getList("iotaworks:stack", NbtElement.COMPOUND_TYPE) 102 + val newStack = if delta > 0 then 103 + val (stack, held) = image.getStack.splitAt(image.getStack.size - delta) 104 + for iota <- held do list.add(IotaType.serialize(iota)) 105 + data.put("iotaworks:stack", list) 106 + stack.toSeq 107 + else 108 + val stolen = list.subList(0, (list.size + delta) max 0) 109 + val neededNulls = Seq.fill(-delta - stolen.size)(NullIota()) 110 + val toAdd = stolen +: neededNulls 111 + if isDev then println(s"stolen[${stolen.size}]=$stolen, neededNulls[${neededNulls.size}]=$neededNulls, total[${toAdd.length}]=${toAdd} delta=$delta, list.size=${list.size}") 112 + assert(toAdd.size == -delta) 113 + stolen.clear() 114 + image.getStack :+ toAdd 115 + CastingImage(newStack, image.getParenCount, image.getParenthesized, image.getEscapeNext, image.getOpsConsumed, data, null) 116 + 117 + private[iotaworks] object Extern: 118 + def handleExecute(pattern: PatternIota, vm: CastingVM, world: ServerWorld, continuation: SpellContinuation, original: (CastingVM, ServerWorld, SpellContinuation) => CastResult): CastResult = 119 + val delta = pattern.getPattern.asInstanceOf[HexPatternAccessor].depth 120 + if delta != 0 then 121 + vm.setImage(DeltaFrame.shift(vm.getImage, delta)) 122 + original(vm, world, continuation.pushFrame(DeltaFrame(-delta))) 123 + else 124 + original(vm, world, continuation) 80 125 81 126 trait HexPatternAccessor: 82 127 var depth: Int