repo for my hex addons :3
0
fork

Configure Feed

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

that's stupid actually this way is really simple

+12 -16
+12 -16
project/iotaworks/src/main/scala/org/eu/net/pool/iotaworks/main.scala
··· 92 92 c 93 93 def size = 0 94 94 def evaluate(cont: SpellContinuation, world: ServerWorld, vm: CastingVM): CastResult = 95 - CastResult(GarbageIota(), cont, DeltaFrame.shift(vm.getImage, delta), Seq(), ResolvedPatternType.EVALUATED, HexEvalSounds.NOTHING) 95 + CastResult(GarbageIota(), cont, DeltaFrame.shift(vm.getImage, delta)(using world), Seq(), ResolvedPatternType.EVALUATED, HexEvalSounds.NOTHING) 96 96 object DeltaFrame extends ContinuationFrame.Type[DeltaFrame]: 97 97 def deserializeFromNBT(data: NbtCompound, world: ServerWorld): DeltaFrame = 98 98 DeltaFrame(data.getInt("d")) 99 - def shift(image: CastingImage, delta: Int): CastingImage = 99 + def shift(image: CastingImage, delta: Int)(using ServerWorld): CastingImage = 100 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 101 + val list: NbtList = data.getList("iotaworks:stack", NbtElement.COMPOUND_TYPE) // stack[0] .. stack[n] | list[n] .. list[0] 102 + // We can always optimize this later. Go with the dumb method for now. 103 + val newStack = collection.mutable.Buffer.from(image.getStack) 104 + if delta > 0 then 105 + // move from end of stack to end of hold 106 + delta times list.add(IotaType.serialize(if newStack.nonEmpty then newStack.remove(newStack.length - 1) else NullIota())) 107 107 else 108 - val stolen = list.subList(0, (list.size + delta) max 0) 109 - val neededNulls = Seq.fill(-delta - stolen.size)(NullIota()) 110 - if isDev then println(s"stolen[${stolen.size}]=$stolen, neededNulls[${neededNulls.size}]=$neededNulls, total[${toAdd.length}]=${toAdd} delta=$delta, list.size=${list.size}") 111 - val toAdd = stolen ++ neededNulls 112 - assert(toAdd.size == -delta) 113 - stolen.clear() 114 - image.getStack ++ toAdd 108 + // move from end of hold to end of stack 109 + (-delta) times newStack.append(if list.nonEmpty then IotaType.deserialize(list.remove(list.length - 1).downcast, summon) else NullIota()) 110 + data.put("iotaworks:stack", list) 115 111 CastingImage(newStack, image.getParenCount, image.getParenthesized, image.getEscapeNext, image.getOpsConsumed, data, null) 116 112 117 113 private[iotaworks] object Extern: 118 114 def handleExecute(pattern: PatternIota, vm: CastingVM, world: ServerWorld, continuation: SpellContinuation, original: (CastingVM, ServerWorld, SpellContinuation) => CastResult): CastResult = 119 115 val delta = pattern.getPattern.asInstanceOf[HexPatternAccessor].depth 120 116 if delta != 0 then 121 - vm.setImage(DeltaFrame.shift(vm.getImage, delta)) 117 + vm.setImage(DeltaFrame.shift(vm.getImage, delta)(using world)) 122 118 original(vm, world, continuation.pushFrame(DeltaFrame(-delta))) 123 119 else 124 120 original(vm, world, continuation)