From 784f6bae1f0ee3bfb6d7b642130c0c71b283b2ba Mon Sep 17 00:00:00 2001 From: Aurora Dawn <131844170+StellarWitch7@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:10:38 -0400 Subject: [PATCH] Talons and Scales --- .gitignore | 4 ++ .../ram/RandomAccessMindClient.kt | 9 --- .../ram/RandomAccessMindClient.scala | 9 +++ .../stellarwitch7/ram/RandomAccessMind.kt | 22 ------ .../stellarwitch7/ram/cca/ModComponents.kt | 10 --- .../stellarwitch7/ram/cca/RAMComponent.kt | 30 -------- .../ram/cca/world/CellsComponent.kt | 68 ------------------- .../ram/cca/world/ModWorldComponents.kt | 11 --- .../blunder/CellNotWithinWorldBlunder.kt | 11 --- .../ram/spell/blunder/ImmutableCellBlunder.kt | 11 --- .../blunder/NotWithinRAMBoundsBlunder.kt | 11 --- .../ram/spell/blunder/OutOfRAMBlunder.kt | 11 --- .../spell/blunder/RAMNotSupportedBlunder.kt | 11 --- .../ram/spell/fragment/CellFragment.kt | 42 ------------ .../ram/spell/fragment/ModFragmentTypes.kt | 14 ---- .../ram/spell/mind/DefaultRAM.kt | 61 ----------------- .../stellarwitch7/ram/spell/mind/RAM.kt | 26 ------- .../ram/spell/trick/ModTricks.kt | 32 --------- .../ram/spell/trick/cell/WriteCellTrick.kt | 16 ----- .../trick/meta/PatternFromIntListTrick.kt | 24 ------- .../spell/trick/meta/PatternFromIntTrick.kt | 11 --- .../ram/spell/trick/mind/RAMReadTrick.kt | 19 ------ .../ram/spell/trick/mind/RAMWriteTrick.kt | 23 ------- .../entries/tome_of_tomfoolery/ram.md | 4 +- src/main/resources/fabric.mod.json | 14 ++-- .../stellarwitch7/ram/RandomAccessMind.scala | 22 ++++++ .../stellarwitch7/ram/cca/ModComponents.scala | 10 +++ .../stellarwitch7/ram/cca/RAMComponent.scala | 32 +++++++++ .../ram/cca/block/ModBlockComponents.scala} | 8 +-- .../ram/cca/entity/ModEntityComponents.scala} | 8 +-- .../ram/cca/world/CellsComponent.scala | 67 ++++++++++++++++++ .../ram/cca/world/ModWorldComponents.scala | 11 +++ .../blunder/CellNotWithinWorldBlunder.scala | 10 +++ .../spell/blunder/ImmutableCellBlunder.scala | 10 +++ .../blunder/NotWithinRAMBoundsBlunder.scala | 10 +++ .../ram/spell/blunder/OutOfRAMBlunder.scala | 10 +++ .../blunder/RAMNotSupportedBlunder.scala | 10 +++ .../ram/spell/fragment/CellFragment.scala | 32 +++++++++ .../ram/spell/fragment/ModFragmentTypes.scala | 14 ++++ .../ram/spell/mind/DefaultRAM.scala | 64 +++++++++++++++++ .../stellarwitch7/ram/spell/mind/RAM.scala | 23 +++++++ .../ram/spell/mind/RAMSlot.scala} | 18 +++-- .../ram/spell/trick/ModTricks.scala | 32 +++++++++ .../spell/trick/cell/AcquireCellTrick.scala} | 9 ++- .../ram/spell/trick/cell/ReadCellTrick.scala} | 10 +-- .../ram/spell/trick/cell/WriteCellTrick.scala | 18 +++++ .../trick/meta/GlyphFromSpellPartTrick.scala} | 10 +-- .../spell/trick/meta/PatternAsIntTrick.scala} | 10 +-- .../trick/meta/PatternFromIntListTrick.scala | 21 ++++++ .../trick/meta/PatternFromIntTrick.scala | 14 ++++ .../ram/spell/trick/mind/RAMAllocTrick.scala} | 13 ++-- .../ram/spell/trick/mind/RAMFreeTrick.scala} | 19 +++--- .../ram/spell/trick/mind/RAMReadTrick.scala | 20 ++++++ .../ram/spell/trick/mind/RAMWriteTrick.scala | 24 +++++++ 54 files changed, 527 insertions(+), 536 deletions(-) delete mode 100644 src/client/kotlin/stellarwitch7/ram/RandomAccessMindClient.kt create mode 100644 src/client/scala/stellarwitch7/ram/RandomAccessMindClient.scala delete mode 100644 src/main/kotlin/stellarwitch7/ram/RandomAccessMind.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/cca/ModComponents.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/cca/RAMComponent.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/cca/world/CellsComponent.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/cca/world/ModWorldComponents.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/fragment/CellFragment.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/fragment/ModFragmentTypes.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/mind/DefaultRAM.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/mind/RAM.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/ModTricks.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.kt delete mode 100644 src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.kt create mode 100644 src/main/scala/stellarwitch7/ram/RandomAccessMind.scala create mode 100644 src/main/scala/stellarwitch7/ram/cca/ModComponents.scala create mode 100644 src/main/scala/stellarwitch7/ram/cca/RAMComponent.scala rename src/main/{kotlin/stellarwitch7/ram/cca/block/ModBlockComponents.kt => scala/stellarwitch7/ram/cca/block/ModBlockComponents.scala} (54%) rename src/main/{kotlin/stellarwitch7/ram/cca/entity/ModEntityComponents.kt => scala/stellarwitch7/ram/cca/entity/ModEntityComponents.scala} (58%) create mode 100644 src/main/scala/stellarwitch7/ram/cca/world/CellsComponent.scala create mode 100644 src/main/scala/stellarwitch7/ram/cca/world/ModWorldComponents.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/fragment/CellFragment.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/fragment/ModFragmentTypes.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/mind/DefaultRAM.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/mind/RAM.scala rename src/main/{kotlin/stellarwitch7/ram/spell/mind/RAMSlot.kt => scala/stellarwitch7/ram/spell/mind/RAMSlot.scala} (54%) create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/ModTricks.scala rename src/main/{kotlin/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.kt => scala/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.scala} (54%) rename src/main/{kotlin/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.kt => scala/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.scala} (54%) create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.scala rename src/main/{kotlin/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.kt => scala/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.scala} (51%) rename src/main/{kotlin/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.kt => scala/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.scala} (53%) create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.scala rename src/main/{kotlin/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.kt => scala/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.scala} (55%) rename src/main/{kotlin/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.kt => scala/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.scala} (51%) create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.scala create mode 100644 src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.scala diff --git a/.gitignore b/.gitignore index 1cdd3b2..8c6fc98 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,7 @@ replay_*.log # direnv .direnv/ .envrc + +# metals +.metals/ +.bloop/ diff --git a/src/client/kotlin/stellarwitch7/ram/RandomAccessMindClient.kt b/src/client/kotlin/stellarwitch7/ram/RandomAccessMindClient.kt deleted file mode 100644 index f74d502..0000000 --- a/src/client/kotlin/stellarwitch7/ram/RandomAccessMindClient.kt +++ /dev/null @@ -1,9 +0,0 @@ -package stellarwitch7.ram - -import net.fabricmc.api.ClientModInitializer - -object RandomAccessMindClient : ClientModInitializer { - override fun onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - } -} \ No newline at end of file diff --git a/src/client/scala/stellarwitch7/ram/RandomAccessMindClient.scala b/src/client/scala/stellarwitch7/ram/RandomAccessMindClient.scala new file mode 100644 index 0000000..35edde3 --- /dev/null +++ b/src/client/scala/stellarwitch7/ram/RandomAccessMindClient.scala @@ -0,0 +1,9 @@ +package stellarwitch7.ram + +import net.fabricmc.api.ClientModInitializer + +object RandomAccessMindClient extends ClientModInitializer { + override def onInitializeClient(): Unit = { + // This entrypoint is suitable for setting up client-specific logic, such as rendering. + } +} diff --git a/src/main/kotlin/stellarwitch7/ram/RandomAccessMind.kt b/src/main/kotlin/stellarwitch7/ram/RandomAccessMind.kt deleted file mode 100644 index d4f1f98..0000000 --- a/src/main/kotlin/stellarwitch7/ram/RandomAccessMind.kt +++ /dev/null @@ -1,22 +0,0 @@ -package stellarwitch7.ram - -import net.fabricmc.api.ModInitializer -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import stellarwitch7.ram.spell.fragment.ModFragmentTypes -import stellarwitch7.ram.spell.trick.ModTricks - -object RandomAccessMind : ModInitializer { - const val MOD_ID: String = "ram" - val logger: Logger = LoggerFactory.getLogger(MOD_ID) - - override fun onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - logger.info("SIGSEGV") - - ModTricks.register() - ModFragmentTypes.register() - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/cca/ModComponents.kt b/src/main/kotlin/stellarwitch7/ram/cca/ModComponents.kt deleted file mode 100644 index 6486672..0000000 --- a/src/main/kotlin/stellarwitch7/ram/cca/ModComponents.kt +++ /dev/null @@ -1,10 +0,0 @@ -package stellarwitch7.ram.cca - -import stellarwitch7.libstellar.registry.cca.CCAGenericComponentRegistrar -import stellarwitch7.ram.RandomAccessMind - -object ModComponents : CCAGenericComponentRegistrar { - override val modID: String = RandomAccessMind.MOD_ID - - val ram = makeKey("ram", RAMComponent::class) -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/cca/RAMComponent.kt b/src/main/kotlin/stellarwitch7/ram/cca/RAMComponent.kt deleted file mode 100644 index 73c0cbe..0000000 --- a/src/main/kotlin/stellarwitch7/ram/cca/RAMComponent.kt +++ /dev/null @@ -1,30 +0,0 @@ -package stellarwitch7.ram.cca - -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.Entity -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtOps -import net.minecraft.registry.RegistryWrapper -import org.ladysnake.cca.api.v3.component.Component -import stellarwitch7.ram.spell.mind.DefaultRAM -import stellarwitch7.ram.spell.mind.RAM - -class RAMComponent : Component { - var ram: RAM = DefaultRAM(12u) - private set - - constructor(entity: Entity) - - constructor(blockEntity: BlockEntity) - - override fun readFromNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { - val result = RAM.codec.parse(NbtOps.INSTANCE, tag.get("ram")) - - if (result.hasResultOrPartial()) - ram = result.resultOrPartial().orElseThrow() - } - - override fun writeToNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { - tag.put("ram", RAM.codec.encodeStart(NbtOps.INSTANCE, ram).result().orElseThrow()) - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/cca/world/CellsComponent.kt b/src/main/kotlin/stellarwitch7/ram/cca/world/CellsComponent.kt deleted file mode 100644 index 468fb91..0000000 --- a/src/main/kotlin/stellarwitch7/ram/cca/world/CellsComponent.kt +++ /dev/null @@ -1,68 +0,0 @@ -package stellarwitch7.ram.cca.world - -import dev.enjarai.trickster.EndecTomfoolery -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.fragment.VoidFragment -import dev.enjarai.trickster.spell.trick.Trick -import io.wispforest.endec.Endec -import io.wispforest.endec.StructEndec -import io.wispforest.endec.impl.KeyedEndec -import io.wispforest.endec.impl.StructEndecBuilder -import net.minecraft.nbt.NbtCompound -import net.minecraft.registry.RegistryWrapper -import net.minecraft.world.World -import org.ladysnake.cca.api.v3.component.Component -import stellarwitch7.ram.spell.fragment.CellFragment -import stellarwitch7.ram.spell.blunder.CellNotWithinWorldBlunder -import stellarwitch7.ram.spell.blunder.ImmutableCellBlunder -import java.util.* -import kotlin.collections.HashMap - -class CellsComponent(private val world: World) : Component { - private var cells: MutableMap = HashMap() - - override fun readFromNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { - cells = tag.get(endec) - } - - override fun writeToNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup) { - tag.put(endec, cells) - } - - fun acquireCell(): CellFragment { - var uuid = UUID.randomUUID() - - while (cells.contains(uuid)) { - uuid = UUID.randomUUID() - } - - cells[uuid] = Cell(false, VoidFragment.INSTANCE) - return CellFragment(uuid) - } - - fun writeCell(source: Trick, uuid: UUID, value: Fragment) { - val cell = cells[uuid] ?: throw CellNotWithinWorldBlunder(source) - if (cell.locked) throw ImmutableCellBlunder(source) - cell.locked = true - cell.value = value - } - - fun readCell(source: Trick, uuid: UUID): Fragment { - val cell = cells[uuid] ?: throw CellNotWithinWorldBlunder(source) - return cell.value - } - - companion object { - val endec: KeyedEndec> = KeyedEndec("cells", Endec.map(EndecTomfoolery.UUID, Cell.endec), HashMap()) - } - - data class Cell(var locked: Boolean, var value: Fragment) { - companion object { - val endec: StructEndec = StructEndecBuilder.of( - Endec.BOOLEAN.fieldOf("locked", Cell::locked), - Fragment.ENDEC.fieldOf("value", Cell::value), - ::Cell - ) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/cca/world/ModWorldComponents.kt b/src/main/kotlin/stellarwitch7/ram/cca/world/ModWorldComponents.kt deleted file mode 100644 index 188157d..0000000 --- a/src/main/kotlin/stellarwitch7/ram/cca/world/ModWorldComponents.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.cca.world - -import org.ladysnake.cca.api.v3.component.ComponentKey -import stellarwitch7.libstellar.registry.cca.world.CCAWorldComponentRegistrar -import stellarwitch7.ram.RandomAccessMind - -object ModWorldComponents : CCAWorldComponentRegistrar() { - override val modID: String = RandomAccessMind.MOD_ID - - val cells: ComponentKey = register("cells", CellsComponent::class, ::CellsComponent, null) -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.kt b/src/main/kotlin/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.kt deleted file mode 100644 index 2f0f821..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.blunder - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.blunder.TrickBlunderException -import net.minecraft.text.MutableText - -class CellNotWithinWorldBlunder(source: Trick) : TrickBlunderException(source) { - override fun createMessage(): MutableText { - return super.createMessage().append("Cell cannot be accessed as it does not exist") - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.kt b/src/main/kotlin/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.kt deleted file mode 100644 index 7123809..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.blunder - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.blunder.TrickBlunderException -import net.minecraft.text.MutableText - -class ImmutableCellBlunder(source: Trick) : TrickBlunderException(source) { - override fun createMessage(): MutableText { - return super.createMessage().append("Cannot write to cell as it has already been written to") - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.kt b/src/main/kotlin/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.kt deleted file mode 100644 index 2b867fa..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.blunder - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.blunder.TrickBlunderException -import net.minecraft.text.MutableText - -class NotWithinRAMBoundsBlunder(source: Trick, private val size: UInt, private val given: Int) : TrickBlunderException(source) { - override fun createMessage(): MutableText { - return super.createMessage().append("Invalid RAM slot address. Got $given, but must be greater or equal to zero and lesser than $size") - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.kt b/src/main/kotlin/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.kt deleted file mode 100644 index 3447f1e..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.blunder - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.blunder.TrickBlunderException -import net.minecraft.text.MutableText - -class OutOfRAMBlunder(source: Trick) : TrickBlunderException(source) { - override fun createMessage(): MutableText { - return super.createMessage().append("Cannot allocate any Random Access Mind slot as none are free") - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.kt b/src/main/kotlin/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.kt deleted file mode 100644 index 79c0abc..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.blunder - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.blunder.TrickBlunderException -import net.minecraft.text.MutableText - -class RAMNotSupportedBlunder(source: Trick) : TrickBlunderException(source) { - override fun createMessage(): MutableText { - return super.createMessage().append("Caster does not support RAM") - } -} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/fragment/CellFragment.kt b/src/main/kotlin/stellarwitch7/ram/spell/fragment/CellFragment.kt deleted file mode 100644 index 58ab0eb..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/fragment/CellFragment.kt +++ /dev/null @@ -1,42 +0,0 @@ -package stellarwitch7.ram.spell.fragment - -import dev.enjarai.trickster.EndecTomfoolery -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.fragment.BooleanFragment -import dev.enjarai.trickster.spell.fragment.FragmentType -import dev.enjarai.trickster.spell.trick.Trick -import io.wispforest.endec.StructEndec -import io.wispforest.endec.impl.StructEndecBuilder -import net.minecraft.server.world.ServerWorld -import net.minecraft.text.Text -import stellarwitch7.ram.cca.world.ModWorldComponents -import java.util.UUID - -data class CellFragment(val uuid: UUID) : Fragment { - fun get(source: Trick, world: ServerWorld): Fragment { - return ModWorldComponents.cells.get(world).readCell(source, uuid) - } - - fun set(source: Trick, world: ServerWorld, value: Fragment) { - ModWorldComponents.cells.get(world).writeCell(source, uuid, value) - } - - override fun type(): FragmentType<*> { - return ModFragmentTypes.cell - } - - override fun asText(): Text { - return Text.literal(uuid.toString()) - } - - override fun asBoolean(): BooleanFragment { - return BooleanFragment.TRUE - } - - companion object { - val endec: StructEndec = StructEndecBuilder.of( - EndecTomfoolery.UUID.fieldOf("uuid", CellFragment::uuid), - ::CellFragment - ) - } -} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/fragment/ModFragmentTypes.kt b/src/main/kotlin/stellarwitch7/ram/spell/fragment/ModFragmentTypes.kt deleted file mode 100644 index 977022f..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/fragment/ModFragmentTypes.kt +++ /dev/null @@ -1,14 +0,0 @@ -package stellarwitch7.ram.spell.fragment - -import dev.enjarai.trickster.spell.fragment.FragmentType -import net.minecraft.registry.Registry -import stellarwitch7.libstellar.registry.Registrar -import stellarwitch7.ram.RandomAccessMind -import java.util.* - -object ModFragmentTypes : Registrar> { - override val modID: String = RandomAccessMind.MOD_ID - override val registry: Registry> = FragmentType.REGISTRY - - val cell: FragmentType = register("cell", FragmentType(CellFragment.endec, OptionalInt.empty())) -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/mind/DefaultRAM.kt b/src/main/kotlin/stellarwitch7/ram/spell/mind/DefaultRAM.kt deleted file mode 100644 index 9808cff..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/mind/DefaultRAM.kt +++ /dev/null @@ -1,61 +0,0 @@ -package stellarwitch7.ram.spell.mind - -import com.mojang.serialization.MapCodec -import com.mojang.serialization.codecs.RecordCodecBuilder -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.fragment.VoidFragment -import dev.enjarai.trickster.spell.trick.Trick -import stellarwitch7.libstellar.registry.codec.CodecType -import stellarwitch7.libstellar.utils.KCodecUtils -import stellarwitch7.ram.spell.blunder.NotWithinRAMBoundsBlunder -import stellarwitch7.ram.spell.blunder.OutOfRAMBlunder - -open class DefaultRAM(val size: UInt) : RAM { - override val type: CodecType = RAM.default - protected var slots = Array(size.toInt(), { _ -> RAMSlot(true, VoidFragment.INSTANCE) }) - - private constructor(size: UInt, slots: List) : this(size) { - this.slots = slots.toTypedArray() - } - - override fun alloc(source: Trick): UInt { - for ((i, slot) in slots.withIndex()) { - if (slot.free) { - slot.free = false - return i.toUInt() - } - } - - throw OutOfRAMBlunder(source) - } - - override fun free(source: Trick, address: Int) { - if (address < 0 || address >= slots.size) - throw NotWithinRAMBoundsBlunder(source, slots.size.toUInt(), address) - - slots[address].free = true - } - - override fun write(source: Trick, address: Int, value: Fragment) { - if (address < 0 || address >= slots.size) - throw NotWithinRAMBoundsBlunder(source, slots.size.toUInt(), address) - - slots[address].value = value - } - - override fun read(source: Trick, address: Int): Fragment { - if (address < 0 || address >= slots.size) - throw NotWithinRAMBoundsBlunder(source, slots.size.toUInt(), address) - - return slots[address].value - } - - companion object { - val codec: MapCodec = RecordCodecBuilder.mapCodec { builder -> - builder.group( - KCodecUtils.uIntCodec.fieldOf("size").forGetter(DefaultRAM::size), - RAMSlot.codec.listOf().fieldOf("slots").forGetter { it.slots.asList() } - ).apply(builder, ::DefaultRAM) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/mind/RAM.kt b/src/main/kotlin/stellarwitch7/ram/spell/mind/RAM.kt deleted file mode 100644 index 768a73a..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/mind/RAM.kt +++ /dev/null @@ -1,26 +0,0 @@ -package stellarwitch7.ram.spell.mind - -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.trick.Trick -import net.minecraft.registry.Registry -import stellarwitch7.libstellar.registry.codec.CodecRegistrar -import stellarwitch7.libstellar.registry.codec.CodecType -import stellarwitch7.libstellar.registry.codec.CodecTypeProvider -import stellarwitch7.ram.RandomAccessMind - -interface RAM : CodecTypeProvider { - fun alloc(source: Trick): UInt - - fun free(source: Trick, address: Int) - - fun write(source: Trick, address: Int, value: Fragment) - - fun read(source: Trick, address: Int): Fragment - - companion object : CodecRegistrar { - override val modID: String = RandomAccessMind.MOD_ID - override val registry: Registry> = makeReg("ram") - - val default = register("default", DefaultRAM.codec) - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/ModTricks.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/ModTricks.kt deleted file mode 100644 index df2ae87..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/ModTricks.kt +++ /dev/null @@ -1,32 +0,0 @@ -package stellarwitch7.ram.spell.trick - -import dev.enjarai.trickster.spell.trick.Trick -import dev.enjarai.trickster.spell.trick.Tricks -import net.minecraft.registry.Registry -import stellarwitch7.libstellar.registry.Registrar -import stellarwitch7.ram.RandomAccessMind -import stellarwitch7.ram.spell.trick.mind.* -import stellarwitch7.ram.spell.trick.meta.* -import stellarwitch7.ram.spell.trick.cell.* - -object ModTricks : Registrar { - override val modID: String = RandomAccessMind.MOD_ID - override val registry: Registry = Tricks.REGISTRY - - // ram - val alloc = register("alloc", RAMAllocTrick()) - val free = register("free", RAMFreeTrick()) - val read = register("read", RAMReadTrick()) - val write = register("write", RAMWriteTrick()) - - // meta - val patternAsInt = register("pattern_as_int", PatternAsIntTrick()) - val patternFromInt = register("pattern_from_int", PatternFromIntTrick()) - val patternFromIntList = register("pattern_from_int_list", PatternFromIntListTrick()) - val glyphFromSpellPart = register("glyph_from_spell_part", GlyphFromSpellPartTrick()) - - // cell - val acquireCell = register("acquire_cell", AcquireCellTrick()) - val readCell = register("read_cell", ReadCellTrick()) - val writeCell = register("write_cell", WriteCellTrick()) -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.kt deleted file mode 100644 index 0c90033..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.kt +++ /dev/null @@ -1,16 +0,0 @@ -package stellarwitch7.ram.spell.trick.cell - -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.Pattern -import dev.enjarai.trickster.spell.SpellContext -import dev.enjarai.trickster.spell.trick.Trick -import stellarwitch7.ram.spell.fragment.ModFragmentTypes - -class WriteCellTrick : Trick(Pattern.of(4, 6, 0, 4, 8)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - val cell = expectInput(fragments, ModFragmentTypes.cell, 0) - val value = expectInput(fragments, 1) - cell.set(this, ctx.source.world, value.applyEphemeral()) - return cell - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.kt deleted file mode 100644 index b1d515b..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.kt +++ /dev/null @@ -1,24 +0,0 @@ -package stellarwitch7.ram.spell.trick.meta - -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.Pattern -import dev.enjarai.trickster.spell.PatternGlyph -import dev.enjarai.trickster.spell.SpellContext -import dev.enjarai.trickster.spell.fragment.FragmentType -import dev.enjarai.trickster.spell.fragment.ListFragment -import dev.enjarai.trickster.spell.trick.Trick - -class PatternFromIntListTrick : Trick(Pattern.of(0, 4, 8, 6, 4, 2, 1)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return PatternGlyph( - supposeInput(fragments, 0) - .flatMap { - supposeType(it, FragmentType.LIST).map(ListFragment::fragments) - } - .orElse(fragments) - .map { - expectType(it, FragmentType.NUMBER).asInt().toByte() - } - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.kt deleted file mode 100644 index 0dcd2ae..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.kt +++ /dev/null @@ -1,11 +0,0 @@ -package stellarwitch7.ram.spell.trick.meta - -import dev.enjarai.trickster.spell.* -import dev.enjarai.trickster.spell.fragment.FragmentType -import dev.enjarai.trickster.spell.trick.Trick - -class PatternFromIntTrick : Trick(Pattern.of(0, 4, 8, 7, 4, 1)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return PatternGlyph(Pattern.from(expectInput(fragments, FragmentType.NUMBER, 0).asInt())) - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.kt deleted file mode 100644 index 5247d33..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.kt +++ /dev/null @@ -1,19 +0,0 @@ -package stellarwitch7.ram.spell.trick.mind - -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.Pattern -import dev.enjarai.trickster.spell.SpellContext -import dev.enjarai.trickster.spell.fragment.FragmentType -import dev.enjarai.trickster.spell.trick.Trick -import stellarwitch7.ram.cca.entity.ModEntityComponents -import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder - -class RAMReadTrick : Trick(Pattern.of(1, 4, 3, 6, 8, 5)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - val number = expectInput(fragments, FragmentType.NUMBER, 0).number() - - return ctx.source.getComponent(ModEntityComponents.ram).orElseThrow { - RAMNotSupportedBlunder(this) - }.ram.read(this, number.toInt()) - } -} \ No newline at end of file diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.kt b/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.kt deleted file mode 100644 index e93df44..0000000 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.kt +++ /dev/null @@ -1,23 +0,0 @@ -package stellarwitch7.ram.spell.trick.mind - -import dev.enjarai.trickster.spell.Fragment -import dev.enjarai.trickster.spell.Pattern -import dev.enjarai.trickster.spell.SpellContext -import dev.enjarai.trickster.spell.fragment.FragmentType -import dev.enjarai.trickster.spell.fragment.VoidFragment -import dev.enjarai.trickster.spell.trick.Trick -import stellarwitch7.ram.cca.entity.ModEntityComponents -import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder - -class RAMWriteTrick : Trick(Pattern.of(1, 4, 5, 8, 6, 3)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - val number = expectInput(fragments, FragmentType.NUMBER, 0).number() - val any = expectInput(fragments, 1) - - ctx.source.getComponent(ModEntityComponents.ram).orElseThrow { - RAMNotSupportedBlunder(this) - }.ram.write(this, number.toInt(), any) - - return VoidFragment.INSTANCE - } -} \ No newline at end of file diff --git a/src/main/resources/assets/ram/lavender/entries/tome_of_tomfoolery/ram.md b/src/main/resources/assets/ram/lavender/entries/tome_of_tomfoolery/ram.md index 9934d0f..97b44df 100644 --- a/src/main/resources/assets/ram/lavender/entries/tome_of_tomfoolery/ram.md +++ b/src/main/resources/assets/ram/lavender/entries/tome_of_tomfoolery/ram.md @@ -44,8 +44,8 @@ Returns the fragment stored within the RAM slot at the given address. <|glyph@trickster:templates|trick-id=ram:write,title=Ploy of Caching|> -number, any -> +number, any -> any --- -Stores the given fragment in the RAM slot at the given address, overwriting what was there previously. \ No newline at end of file +Stores the given fragment in the RAM slot at the given address, overwriting what was there previously. diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4399073..567bee8 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,31 +18,31 @@ "main": [ { "value": "stellarwitch7.ram.RandomAccessMind", - "adapter": "kotlin" + "adapter": "kotori_scala" } ], "client": [ { "value": "stellarwitch7.ram.RandomAccessMindClient", - "adapter": "kotlin" + "adapter": "kotori_scala" } ], "cardinal-components-entity": [ { "value": "stellarwitch7.ram.cca.entity.ModEntityComponents", - "adapter": "kotlin" + "adapter": "kotori_scala" } ], "cardinal-components-block": [ { "value": "stellarwitch7.ram.cca.block.ModBlockComponents", - "adapter": "kotlin" + "adapter": "kotori_scala" } ], "cardinal-components-world": [ { "value": "stellarwitch7.ram.cca.world.ModWorldComponents", - "adapter": "kotlin" + "adapter": "kotori_scala" } ] }, @@ -64,9 +64,9 @@ "minecraft": "~1.21", "java": ">=21", "fabric-api": "*", - "fabric-language-kotlin": "*", + "kotori_scala": "*", "libstellar": ">=1.1.8", - "trickster": ">=2.0.0-alpha.37" + "trickster": ">=2.0.0-alpha.39" }, "suggests": { } diff --git a/src/main/scala/stellarwitch7/ram/RandomAccessMind.scala b/src/main/scala/stellarwitch7/ram/RandomAccessMind.scala new file mode 100644 index 0000000..9298ba3 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/RandomAccessMind.scala @@ -0,0 +1,22 @@ +package stellarwitch7.ram + +import net.fabricmc.api.ModInitializer +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import stellarwitch7.ram.spell.fragment.ModFragmentTypes +import stellarwitch7.ram.spell.trick.ModTricks + +object RandomAccessMind extends ModInitializer { + val MOD_ID = "ram" + val LOGGER = LoggerFactory.getLogger(MOD_ID) + + override def onInitialize(): Unit = { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + LOGGER.info("SIGSEGV") + + ModTricks.register() + ModFragmentTypes.register() + } +} diff --git a/src/main/scala/stellarwitch7/ram/cca/ModComponents.scala b/src/main/scala/stellarwitch7/ram/cca/ModComponents.scala new file mode 100644 index 0000000..9ff5821 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/cca/ModComponents.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.cca + +import stellarwitch7.libstellar.registry.cca.CCAGenericComponentRegistrar +import stellarwitch7.ram.RandomAccessMind + +object ModComponents extends CCAGenericComponentRegistrar { + override val modID: String = RandomAccessMind.MOD_ID + + val ram = makeKey("ram", classOf[RAMComponent]) +} diff --git a/src/main/scala/stellarwitch7/ram/cca/RAMComponent.scala b/src/main/scala/stellarwitch7/ram/cca/RAMComponent.scala new file mode 100644 index 0000000..c8a7a43 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/cca/RAMComponent.scala @@ -0,0 +1,32 @@ +package stellarwitch7.ram.cca + +import net.minecraft.block.entity.BlockEntity +import net.minecraft.entity.Entity +import net.minecraft.nbt.NbtCompound +import net.minecraft.nbt.NbtOps +import net.minecraft.registry.RegistryWrapper +import org.ladysnake.cca.api.v3.component.Component +import stellarwitch7.ram.spell.mind.DefaultRAM +import stellarwitch7.ram.spell.mind.RAM + +class RAMComponent extends Component { + private var _ram: RAM = DefaultRAM(12) + def ram = _ram + + override def readFromNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup): Unit = { + val result = RAM.codec.parse(NbtOps.INSTANCE, tag.get("ram")) + + if result.hasResultOrPartial() then + _ram = result.resultOrPartial().orElseThrow() + end if + } + + override def writeToNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup): Unit = { + tag.put("ram", RAM.codec.encodeStart(NbtOps.INSTANCE, ram).result().orElseThrow()) + } +} + +object RAMComponent { + def apply(entity: Entity): RAMComponent = new RAMComponent() + def apply(blockEntity: BlockEntity): RAMComponent = new RAMComponent() +} diff --git a/src/main/kotlin/stellarwitch7/ram/cca/block/ModBlockComponents.kt b/src/main/scala/stellarwitch7/ram/cca/block/ModBlockComponents.scala similarity index 54% rename from src/main/kotlin/stellarwitch7/ram/cca/block/ModBlockComponents.kt rename to src/main/scala/stellarwitch7/ram/cca/block/ModBlockComponents.scala index 891c55d..9c59ce1 100644 --- a/src/main/kotlin/stellarwitch7/ram/cca/block/ModBlockComponents.kt +++ b/src/main/scala/stellarwitch7/ram/cca/block/ModBlockComponents.scala @@ -6,8 +6,8 @@ import stellarwitch7.ram.RandomAccessMind import stellarwitch7.ram.cca.ModComponents import stellarwitch7.ram.cca.RAMComponent -object ModBlockComponents : CCABlockComponentRegistrar() { - override val modID: String = RandomAccessMind.MOD_ID +object ModBlockComponents extends CCABlockComponentRegistrar() { + override val modID: String = RandomAccessMind.MOD_ID - val ram = register(ModComponents.ram, ::RAMComponent, SpellCircleBlockEntity::class) -} \ No newline at end of file + val ram = register[RAMComponent, SpellCircleBlockEntity](ModComponents.ram, RAMComponent(_), classOf[SpellCircleBlockEntity]) +} diff --git a/src/main/kotlin/stellarwitch7/ram/cca/entity/ModEntityComponents.kt b/src/main/scala/stellarwitch7/ram/cca/entity/ModEntityComponents.scala similarity index 58% rename from src/main/kotlin/stellarwitch7/ram/cca/entity/ModEntityComponents.kt rename to src/main/scala/stellarwitch7/ram/cca/entity/ModEntityComponents.scala index 3af5a89..7d2b152 100644 --- a/src/main/kotlin/stellarwitch7/ram/cca/entity/ModEntityComponents.kt +++ b/src/main/scala/stellarwitch7/ram/cca/entity/ModEntityComponents.scala @@ -6,8 +6,8 @@ import stellarwitch7.ram.RandomAccessMind import stellarwitch7.ram.cca.ModComponents import stellarwitch7.ram.cca.RAMComponent -object ModEntityComponents : CCAEntityComponentRegistrar() { - override val modID: String = RandomAccessMind.MOD_ID +object ModEntityComponents extends CCAEntityComponentRegistrar() { + override val modID: String = RandomAccessMind.MOD_ID - val ram = register(ModComponents.ram, ::RAMComponent, RespawnCopyStrategy.LOSSLESS_ONLY) -} \ No newline at end of file + val ram = register(ModComponents.ram, RAMComponent(_), RespawnCopyStrategy.LOSSLESS_ONLY) +} diff --git a/src/main/scala/stellarwitch7/ram/cca/world/CellsComponent.scala b/src/main/scala/stellarwitch7/ram/cca/world/CellsComponent.scala new file mode 100644 index 0000000..7b7a909 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/cca/world/CellsComponent.scala @@ -0,0 +1,67 @@ +package stellarwitch7.ram.cca.world + +import dev.enjarai.trickster.EndecTomfoolery +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.fragment.VoidFragment +import dev.enjarai.trickster.spell.trick.Trick +import io.wispforest.endec.Endec +import io.wispforest.endec.StructEndec +import io.wispforest.endec.impl.KeyedEndec +import io.wispforest.endec.impl.StructEndecBuilder +import net.minecraft.nbt.NbtCompound +import net.minecraft.registry.RegistryWrapper +import net.minecraft.world.World +import org.ladysnake.cca.api.v3.component.Component +import stellarwitch7.ram.spell.fragment.CellFragment +import stellarwitch7.ram.spell.blunder.CellNotWithinWorldBlunder +import stellarwitch7.ram.spell.blunder.ImmutableCellBlunder +import scala.collection.mutable.HashMap +import java.util.UUID +import scala.collection.JavaConverters._ + +class CellsComponent(private val world: World) extends Component { + private val cells: HashMap[UUID, Cell] = HashMap() + + override def readFromNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup): Unit = + cells.addAll(tag.get(CellsComponent.endec).asScala) + + override def writeToNbt(tag: NbtCompound, registryLookup: RegistryWrapper.WrapperLookup): Unit = + tag.put(CellsComponent.endec, cells.asJava) + + def acquireCell(): CellFragment = { + var uuid = UUID.randomUUID() + + while (cells.contains(uuid)) { + uuid = UUID.randomUUID() + } + + cells.put(uuid, Cell(false, VoidFragment.INSTANCE)) + CellFragment(uuid) + } + + def writeCell(source: Trick, uuid: UUID, value: Fragment): Unit = + cells.get(uuid).map(cell => + if cell.locked then + throw ImmutableCellBlunder(source) + else + cell.locked = true + cell.value = value + ).getOrElse(throw CellNotWithinWorldBlunder(source)) + + def readCell(source: Trick, uuid: UUID): Fragment = + cells.get(uuid).map(_.value).getOrElse(throw CellNotWithinWorldBlunder(source)) +} + +object CellsComponent { + val endec: KeyedEndec[java.util.Map[UUID, Cell]] = KeyedEndec("cells", Endec.map(EndecTomfoolery.UUID, Cell.endec), new java.util.HashMap()) +} + +private class Cell(var locked: Boolean, var value: Fragment) { } + +private object Cell { + val endec: StructEndec[Cell] = StructEndecBuilder.of( + Endec.BOOLEAN.fieldOf("locked", _.locked), + Fragment.ENDEC.fieldOf("value", _.value), + new Cell(_, _) + ) +} diff --git a/src/main/scala/stellarwitch7/ram/cca/world/ModWorldComponents.scala b/src/main/scala/stellarwitch7/ram/cca/world/ModWorldComponents.scala new file mode 100644 index 0000000..9b1c581 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/cca/world/ModWorldComponents.scala @@ -0,0 +1,11 @@ +package stellarwitch7.ram.cca.world + +import org.ladysnake.cca.api.v3.component.ComponentKey +import stellarwitch7.libstellar.registry.cca.world.CCAWorldComponentRegistrar +import stellarwitch7.ram.RandomAccessMind + +object ModWorldComponents extends CCAWorldComponentRegistrar() { + override val modID: String = RandomAccessMind.MOD_ID + + val cells: ComponentKey[CellsComponent] = register("cells", classOf[CellsComponent], CellsComponent(_), None) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.scala b/src/main/scala/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.scala new file mode 100644 index 0000000..df69cf8 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/blunder/CellNotWithinWorldBlunder.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.spell.blunder + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.blunder.TrickBlunderException +import net.minecraft.text.MutableText + +class CellNotWithinWorldBlunder(source: Trick) extends TrickBlunderException(source) { + override def createMessage(): MutableText = + super.createMessage().append("Cell cannot be accessed as it does not exist") +} diff --git a/src/main/scala/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.scala b/src/main/scala/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.scala new file mode 100644 index 0000000..07ffc43 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/blunder/ImmutableCellBlunder.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.spell.blunder + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.blunder.TrickBlunderException +import net.minecraft.text.MutableText + +class ImmutableCellBlunder(source: Trick) extends TrickBlunderException(source) { + override def createMessage(): MutableText = + super.createMessage().append("Cannot write to cell as it has already been written to") +} diff --git a/src/main/scala/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.scala b/src/main/scala/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.scala new file mode 100644 index 0000000..0f78b01 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/blunder/NotWithinRAMBoundsBlunder.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.spell.blunder + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.blunder.TrickBlunderException +import net.minecraft.text.MutableText + +class NotWithinRAMBoundsBlunder(source: Trick, val size: Int, val `given`: Int) extends TrickBlunderException(source) { + override def createMessage(): MutableText = + super.createMessage().append("Invalid RAM slot address. Got $given, but must be greater or equal to zero and lesser than $size") +} diff --git a/src/main/scala/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.scala b/src/main/scala/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.scala new file mode 100644 index 0000000..7a373b7 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/blunder/OutOfRAMBlunder.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.spell.blunder + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.blunder.TrickBlunderException +import net.minecraft.text.MutableText + +class OutOfRAMBlunder(source: Trick) extends TrickBlunderException(source) { + override def createMessage(): MutableText = + super.createMessage().append("Cannot allocate any Random Access Mind slot as none are free") +} diff --git a/src/main/scala/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.scala b/src/main/scala/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.scala new file mode 100644 index 0000000..2ff7d9d --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/blunder/RAMNotSupportedBlunder.scala @@ -0,0 +1,10 @@ +package stellarwitch7.ram.spell.blunder + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.blunder.TrickBlunderException +import net.minecraft.text.MutableText + +class RAMNotSupportedBlunder(source: Trick) extends TrickBlunderException(source) { + override def createMessage(): MutableText = + super.createMessage().append("Caster does not support RAM") +} diff --git a/src/main/scala/stellarwitch7/ram/spell/fragment/CellFragment.scala b/src/main/scala/stellarwitch7/ram/spell/fragment/CellFragment.scala new file mode 100644 index 0000000..1d97f60 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/fragment/CellFragment.scala @@ -0,0 +1,32 @@ +package stellarwitch7.ram.spell.fragment + +import dev.enjarai.trickster.EndecTomfoolery +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.fragment.BooleanFragment +import dev.enjarai.trickster.spell.fragment.FragmentType +import dev.enjarai.trickster.spell.trick.Trick +import io.wispforest.endec.StructEndec +import io.wispforest.endec.impl.StructEndecBuilder +import net.minecraft.server.world.ServerWorld +import net.minecraft.text.Text +import java.util.UUID +import stellarwitch7.ram.cca.world.ModWorldComponents + +class CellFragment(val uuid: UUID) extends Fragment { + def get(source: Trick, world: ServerWorld): Fragment = + ModWorldComponents.cells.get(world).readCell(source, uuid) + + def set(source: Trick, world: ServerWorld, value: Fragment) = + ModWorldComponents.cells.get(world).writeCell(source, uuid, value) + + override def `type`(): FragmentType[?] = ModFragmentTypes.cell + override def asText(): Text = Text.literal(uuid.toString()) + override def asBoolean(): BooleanFragment = BooleanFragment.TRUE +} + +object CellFragment { + val endec: StructEndec[CellFragment] = StructEndecBuilder.of( + EndecTomfoolery.UUID.fieldOf("uuid", _.uuid), + CellFragment(_) + ) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/fragment/ModFragmentTypes.scala b/src/main/scala/stellarwitch7/ram/spell/fragment/ModFragmentTypes.scala new file mode 100644 index 0000000..9e1fcb8 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/fragment/ModFragmentTypes.scala @@ -0,0 +1,14 @@ +package stellarwitch7.ram.spell.fragment + +import dev.enjarai.trickster.spell.fragment.FragmentType +import net.minecraft.registry.Registry +import stellarwitch7.libstellar.registry.Registrar +import stellarwitch7.ram.RandomAccessMind +import java.util.* + +object ModFragmentTypes extends Registrar[FragmentType[?]] { + override val modID: String = RandomAccessMind.MOD_ID + override val registry: Registry[FragmentType[?]] = FragmentType.REGISTRY + + val cell: FragmentType[CellFragment] = register("cell", FragmentType(CellFragment.endec, OptionalInt.empty())) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/mind/DefaultRAM.scala b/src/main/scala/stellarwitch7/ram/spell/mind/DefaultRAM.scala new file mode 100644 index 0000000..7e20644 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/mind/DefaultRAM.scala @@ -0,0 +1,64 @@ +package stellarwitch7.ram.spell.mind + +import com.mojang.serialization.MapCodec +import com.mojang.serialization.codecs.RecordCodecBuilder +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.fragment.VoidFragment +import dev.enjarai.trickster.spell.trick.Trick +import stellarwitch7.libstellar.registry.codec.CodecType +import stellarwitch7.ram.spell.blunder.NotWithinRAMBoundsBlunder +import stellarwitch7.ram.spell.blunder.OutOfRAMBlunder +import com.mojang.serialization.Codec +import scala.collection.JavaConverters._ + +class DefaultRAM private(val size: Int, protected var slots: Array[RAMSlot]) extends RAM { + override val `type`: CodecType[RAM] = RAM.default + + override def alloc(source: Trick): Int = { + for ((slot, i) <- slots.view.zipWithIndex) { + if (slot.free) { + slot.free = false + return i + } + } + + throw OutOfRAMBlunder(source) + } + + override def free(source: Trick, address: Int): Unit = { + if address < 0 || address >= slots.size then + throw NotWithinRAMBoundsBlunder(source, slots.size, address) + end if + + slots(address).free = true + } + + override def write(source: Trick, address: Int, value: Fragment): Unit = { + if address < 0 || address >= slots.size then + throw NotWithinRAMBoundsBlunder(source, slots.size, address) + end if + + slots(address).value = value + } + + override def read(source: Trick, address: Int): Fragment = { + if address < 0 || address >= slots.size then + throw NotWithinRAMBoundsBlunder(source, slots.size, address) + end if + + slots(address).value + } +} + +object DefaultRAM { + val codec: MapCodec[DefaultRAM] = RecordCodecBuilder.mapCodec(builder => builder.group( + Codec.INT.fieldOf("size").forGetter(_.size), + RAMSlot.codec.listOf().fieldOf("slots").forGetter(_.slots.toList.asJava) + ).apply(builder, DefaultRAM(_, _))) + + def apply(size: Int): DefaultRAM = + new DefaultRAM(size, Array.fill(size) { RAMSlot(true, VoidFragment.INSTANCE) }) + + private def apply(size: Int, slots: java.util.List[RAMSlot]): DefaultRAM = + new DefaultRAM(size, slots.asScala.toArray) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/mind/RAM.scala b/src/main/scala/stellarwitch7/ram/spell/mind/RAM.scala new file mode 100644 index 0000000..35f4cfd --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/mind/RAM.scala @@ -0,0 +1,23 @@ +package stellarwitch7.ram.spell.mind + +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.trick.Trick +import net.minecraft.registry.Registry +import stellarwitch7.libstellar.registry.codec.CodecRegistrar +import stellarwitch7.libstellar.registry.codec.CodecType +import stellarwitch7.libstellar.registry.codec.CodecTypeProvider +import stellarwitch7.ram.RandomAccessMind + +trait RAM extends CodecTypeProvider[RAM] { + def alloc(source: Trick): Int + def free(source: Trick, address: Int): Unit + def write(source: Trick, address: Int, value: Fragment): Unit + def read(source: Trick, address: Int): Fragment +} + +object RAM extends CodecRegistrar[RAM] { + override val modID: String = RandomAccessMind.MOD_ID + override val registry: Registry[CodecType[RAM]] = makeReg("ram") + + val default = register("default", DefaultRAM.codec) +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/mind/RAMSlot.kt b/src/main/scala/stellarwitch7/ram/spell/mind/RAMSlot.scala similarity index 54% rename from src/main/kotlin/stellarwitch7/ram/spell/mind/RAMSlot.kt rename to src/main/scala/stellarwitch7/ram/spell/mind/RAMSlot.scala index ef27bcb..089e81f 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/mind/RAMSlot.kt +++ b/src/main/scala/stellarwitch7/ram/spell/mind/RAMSlot.scala @@ -10,13 +10,11 @@ import io.wispforest.accessories.endec.CodecUtils * @property free Whether the slot may be reserved. * @property value The value contained within the slot. A VoidFragment by default, but is not cleared when the slot is freed. */ -data class RAMSlot(var free: Boolean, var value: Fragment) { - companion object { - val codec: Codec = RecordCodecBuilder.create { builder -> - builder.group( - Codec.BOOL.fieldOf("free").forGetter(RAMSlot::free), - CodecUtils.ofEndec(Fragment.ENDEC).fieldOf("value").forGetter(RAMSlot::value) - ).apply(builder, ::RAMSlot) - } - } -} \ No newline at end of file +class RAMSlot(var free: Boolean, var value: Fragment) { } + +object RAMSlot { + val codec: Codec[RAMSlot] = RecordCodecBuilder.create(builder => builder.group( + Codec.BOOL.fieldOf("free").forGetter(_.free), + CodecUtils.ofEndec(Fragment.ENDEC).fieldOf("value").forGetter(_.value) + ).apply(builder, RAMSlot(_, _))) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/ModTricks.scala b/src/main/scala/stellarwitch7/ram/spell/trick/ModTricks.scala new file mode 100644 index 0000000..6b2d66e --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/ModTricks.scala @@ -0,0 +1,32 @@ +package stellarwitch7.ram.spell.trick + +import dev.enjarai.trickster.spell.trick.Trick +import dev.enjarai.trickster.spell.trick.Tricks +import net.minecraft.registry.Registry +import stellarwitch7.libstellar.registry.Registrar +import stellarwitch7.ram.RandomAccessMind +import stellarwitch7.ram.spell.trick.mind.* +import stellarwitch7.ram.spell.trick.meta.* +import stellarwitch7.ram.spell.trick.cell.* + +object ModTricks extends Registrar[Trick] { + override val modID: String = RandomAccessMind.MOD_ID + override val registry: Registry[Trick] = Tricks.REGISTRY + + // ram + val alloc = register("alloc", RAMAllocTrick()) + val free = register("free", RAMFreeTrick()) + val read = register("read", RAMReadTrick()) + val write = register("write", RAMWriteTrick()) + + // meta + val patternAsInt = register("pattern_as_int", PatternAsIntTrick()) + val patternFromInt = register("pattern_from_int", PatternFromIntTrick()) + val patternFromIntList = register("pattern_from_int_list", PatternFromIntListTrick()) + val glyphFromSpellPart = register("glyph_from_spell_part", GlyphFromSpellPartTrick()) + + // cell + val acquireCell = register("acquire_cell", AcquireCellTrick()) + val readCell = register("read_cell", ReadCellTrick()) + val writeCell = register("write_cell", WriteCellTrick()) +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.scala similarity index 54% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.scala index 7228d21..c6927d3 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/cell/AcquireCellTrick.scala @@ -6,8 +6,7 @@ import dev.enjarai.trickster.spell.SpellContext import dev.enjarai.trickster.spell.trick.Trick import stellarwitch7.ram.cca.world.ModWorldComponents -class AcquireCellTrick : Trick(Pattern.of(4, 6, 0, 4, 5)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return ModWorldComponents.cells.get(ctx.source.world).acquireCell() - } -} \ No newline at end of file +class AcquireCellTrick extends Trick(Pattern.of(4, 6, 0, 4, 5)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + ModWorldComponents.cells.get(ctx.source.getWorld()).acquireCell() +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.scala similarity index 54% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.scala index f833d8b..3a0d748 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/cell/ReadCellTrick.scala @@ -6,9 +6,9 @@ import dev.enjarai.trickster.spell.SpellContext import dev.enjarai.trickster.spell.trick.Trick import stellarwitch7.ram.cca.world.ModWorldComponents import stellarwitch7.ram.spell.fragment.ModFragmentTypes +import scala.collection.JavaConverters._ -class ReadCellTrick : Trick(Pattern.of(4, 6, 0, 4, 2)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return expectInput(fragments, ModFragmentTypes.cell, 0).get(this, ctx.source.world) - } -} \ No newline at end of file +class ReadCellTrick extends Trick(Pattern.of(4, 6, 0, 4, 2)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + expectInput(fragments, ModFragmentTypes.cell, 0).get(this, ctx.source.getWorld()) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.scala b/src/main/scala/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.scala new file mode 100644 index 0000000..98c94e3 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/cell/WriteCellTrick.scala @@ -0,0 +1,18 @@ +package stellarwitch7.ram.spell.trick.cell + +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.Pattern +import dev.enjarai.trickster.spell.SpellContext +import dev.enjarai.trickster.spell.trick.Trick +import stellarwitch7.ram.spell.fragment.ModFragmentTypes +import scala.collection.JavaConverters._ + +class WriteCellTrick extends Trick(Pattern.of(4, 6, 0, 4, 8)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = { + val cell = expectInput(fragments, ModFragmentTypes.cell, 0) + val value = expectInput(fragments, 1) + cell.set(this, ctx.source.getWorld(), value.applyEphemeral()) + + cell + } +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.scala similarity index 51% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.scala index 04b938f..a36466b 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/meta/GlyphFromSpellPartTrick.scala @@ -5,9 +5,9 @@ import dev.enjarai.trickster.spell.Pattern import dev.enjarai.trickster.spell.SpellContext import dev.enjarai.trickster.spell.fragment.FragmentType import dev.enjarai.trickster.spell.trick.Trick +import scala.collection.JavaConverters._ -class GlyphFromSpellPartTrick : Trick(Pattern.of(3, 0, 1, 2, 5)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return expectInput(fragments, FragmentType.SPELL_PART, 0).glyph - } -} \ No newline at end of file +class GlyphFromSpellPartTrick extends Trick(Pattern.of(3, 0, 1, 2, 5)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + expectInput(fragments, FragmentType.SPELL_PART, 0).glyph +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.scala similarity index 53% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.scala index dd2abd1..4effc49 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternAsIntTrick.scala @@ -6,9 +6,9 @@ import dev.enjarai.trickster.spell.SpellContext import dev.enjarai.trickster.spell.fragment.FragmentType import dev.enjarai.trickster.spell.fragment.NumberFragment import dev.enjarai.trickster.spell.trick.Trick +import scala.collection.JavaConverters._ -class PatternAsIntTrick : Trick(Pattern.of(2, 4, 6, 7, 4, 1)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return NumberFragment(expectInput(fragments, FragmentType.PATTERN, 0).pattern.toInt().toDouble()) - } -} \ No newline at end of file +class PatternAsIntTrick extends Trick(Pattern.of(2, 4, 6, 7, 4, 1)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + NumberFragment(expectInput(fragments, FragmentType.PATTERN, 0).pattern.toInt().toDouble) +} diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.scala b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.scala new file mode 100644 index 0000000..9e20f49 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntListTrick.scala @@ -0,0 +1,21 @@ +package stellarwitch7.ram.spell.trick.meta + +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.Pattern +import dev.enjarai.trickster.spell.PatternGlyph +import dev.enjarai.trickster.spell.SpellContext +import dev.enjarai.trickster.spell.fragment.FragmentType +import dev.enjarai.trickster.spell.fragment.ListFragment +import dev.enjarai.trickster.spell.trick.Trick +import scala.collection.JavaConverters._ + +class PatternFromIntListTrick extends Trick(Pattern.of(0, 4, 8, 6, 4, 2, 1)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + PatternGlyph( + supposeInput(fragments, 0) + .flatMap(supposeType(_, FragmentType.LIST).map(_.fragments)) + .map(_.asScala) + .orElse(fragments.asScala) + .map(expectType(_, FragmentType.NUMBER).asInt().asInstanceOf[java.lang.Byte]).asJava) +} + diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.scala b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.scala new file mode 100644 index 0000000..2092ad5 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/meta/PatternFromIntTrick.scala @@ -0,0 +1,14 @@ +package stellarwitch7.ram.spell.trick.meta + +import dev.enjarai.trickster.spell.fragment.FragmentType +import dev.enjarai.trickster.spell.trick.Trick +import scala.collection.JavaConverters._ +import dev.enjarai.trickster.spell.Pattern +import dev.enjarai.trickster.spell.SpellContext +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.PatternGlyph + +class PatternFromIntTrick extends Trick(Pattern.of(0, 4, 8, 7, 4, 1)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + PatternGlyph(Pattern.from(expectInput(fragments, FragmentType.NUMBER, 0).asInt())) +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.scala similarity index 55% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.scala index c522c75..64c48e4 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMAllocTrick.scala @@ -8,10 +8,9 @@ import dev.enjarai.trickster.spell.trick.Trick import stellarwitch7.ram.cca.entity.ModEntityComponents import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder -class RAMAllocTrick : Trick(Pattern.of(1, 4, 0, 6, 4, 8, 2, 4)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - return NumberFragment(ctx.source.getComponent(ModEntityComponents.ram).orElseThrow { - RAMNotSupportedBlunder(this) - }.ram.alloc(this).toDouble()) - } -} \ No newline at end of file +class RAMAllocTrick extends Trick(Pattern.of(1, 4, 0, 6, 4, 8, 2, 4)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = + NumberFragment(ctx.source.getComponent(ModEntityComponents.ram).orElseThrow(() => + RAMNotSupportedBlunder(this) + ).ram.alloc(this)) +} diff --git a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.kt b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.scala similarity index 51% rename from src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.kt rename to src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.scala index 743a6e0..9924ec3 100644 --- a/src/main/kotlin/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.kt +++ b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMFreeTrick.scala @@ -8,15 +8,16 @@ import dev.enjarai.trickster.spell.fragment.VoidFragment import dev.enjarai.trickster.spell.trick.Trick import stellarwitch7.ram.cca.entity.ModEntityComponents import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder +import scala.collection.JavaConverters._ -class RAMFreeTrick : Trick(Pattern.of(1, 4, 6, 8, 4)) { - override fun activate(ctx: SpellContext, fragments: List): Fragment { - val number = expectInput(fragments, FragmentType.NUMBER, 0).number() +class RAMFreeTrick extends Trick(Pattern.of(1, 4, 6, 8, 4)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = { + val number = expectInput(fragments, FragmentType.NUMBER, 0).asInt() - ctx.source.getComponent(ModEntityComponents.ram).orElseThrow { - RAMNotSupportedBlunder(this) - }.ram.free(this, number.toInt()) + ctx.source.getComponent(ModEntityComponents.ram).orElseThrow(() => + RAMNotSupportedBlunder(this) + ).ram.free(this, number) - return VoidFragment.INSTANCE - } -} \ No newline at end of file + VoidFragment.INSTANCE + } +} diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.scala b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.scala new file mode 100644 index 0000000..418a2b7 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMReadTrick.scala @@ -0,0 +1,20 @@ +package stellarwitch7.ram.spell.trick.mind + +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.Pattern +import dev.enjarai.trickster.spell.SpellContext +import dev.enjarai.trickster.spell.fragment.FragmentType +import dev.enjarai.trickster.spell.trick.Trick +import stellarwitch7.ram.cca.entity.ModEntityComponents +import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder +import scala.collection.JavaConverters._ + +class RAMReadTrick extends Trick(Pattern.of(1, 4, 3, 6, 8, 5)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = { + val number = expectInput(fragments, FragmentType.NUMBER, 0).asInt() + + ctx.source.getComponent(ModEntityComponents.ram).orElseThrow(() => + RAMNotSupportedBlunder(this) + ).ram.read(this, number) + } +} diff --git a/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.scala b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.scala new file mode 100644 index 0000000..ef5baf1 --- /dev/null +++ b/src/main/scala/stellarwitch7/ram/spell/trick/mind/RAMWriteTrick.scala @@ -0,0 +1,24 @@ +package stellarwitch7.ram.spell.trick.mind + +import dev.enjarai.trickster.spell.Fragment +import dev.enjarai.trickster.spell.Pattern +import dev.enjarai.trickster.spell.SpellContext +import dev.enjarai.trickster.spell.fragment.FragmentType +import dev.enjarai.trickster.spell.fragment.VoidFragment +import dev.enjarai.trickster.spell.trick.Trick +import stellarwitch7.ram.cca.entity.ModEntityComponents +import stellarwitch7.ram.spell.blunder.RAMNotSupportedBlunder +import scala.collection.JavaConverters._ + +class RAMWriteTrick extends Trick(Pattern.of(1, 4, 5, 8, 6, 3)) { + override def activate(ctx: SpellContext, fragments: java.util.List[Fragment]): Fragment = { + val number = expectInput(fragments, FragmentType.NUMBER, 0).asInt() + val any = expectInput(fragments, 1) + + ctx.source.getComponent(ModEntityComponents.ram).orElseThrow(() => + RAMNotSupportedBlunder(this) + ).ram.write(this, number, any) + + any + } +}