Skip to content

Commit

Permalink
Living scroll aging
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 3, 2024
1 parent 7b284db commit c291dd4
Show file tree
Hide file tree
Showing 39 changed files with 328 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class IdentifierIota(identifier: Identifier) : Iota(HexicalIota.IDENTIFIER_IOTA,
}
}

fun Identifier.asActionResult(): List<Iota> = listOf(IdentifierIota(this))

fun List<Iota>.getIdentifier(idx: Int, argc: Int = 0): Identifier {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is IdentifierIota)
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/miyucomics/hexical/casting/patterns/OpAgeScroll.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package miyucomics.hexical.casting.patterns

import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getEntity
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapBadEntity
import miyucomics.hexical.entities.LivingScrollEntity

class OpAgeScroll : SpellAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val scroll = args.getEntity(0, argc)
ctx.assertEntityInRange(scroll)
if (scroll !is LivingScrollEntity)
throw MishapBadEntity.of(scroll, "living_scroll")
return Triple(Spell(scroll), 0, listOf())
}

private data class Spell(val scroll: LivingScrollEntity) : RenderedSpell {
override fun cast(ctx: CastingContext) {
scroll.toggleAged()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getPattern
import at.petrak.hexcasting.api.spell.iota.BooleanIota
import at.petrak.hexcasting.api.spell.iota.Iota

class OpCongruentPattern : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val a = args.getPattern(0, argc)
val b = args.getPattern(1, argc)
return listOf(BooleanIota(a.anglesSignature() == b.anglesSignature()))
return (a.anglesSignature() == b.anglesSignature()).asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.Vec3d
import net.minecraft.world.RaycastContext

object OpFluidAxisRaycast : ConstMediaAction {
override val argc = 2
override val mediaCost = MediaConstants.DUST_UNIT / 100
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val origin = args.getVec3(0, argc)
val look = args.getVec3(1, argc)
ctx.assertVecInRange(origin)
val blockHitResult = ctx.world.raycast(
RaycastContext(
origin,
Action.raycastEnd(origin, look),
RaycastContext.ShapeType.COLLIDER,
RaycastContext.FluidHandling.ANY,
ctx.caster
)
)

if (blockHitResult.type == HitResult.Type.BLOCK && ctx.isVecInRange(Vec3d.ofCenter(blockHitResult.blockPos)))
return blockHitResult.side.unitVector.asActionResult
return listOf(NullIota())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.Vec3d
import net.minecraft.world.RaycastContext

object OpFluidRaycast : ConstMediaAction {
override val argc = 2
override val mediaCost = MediaConstants.DUST_UNIT / 100
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val origin = args.getVec3(0, argc)
val look = args.getVec3(1, argc)
ctx.assertVecInRange(origin)
val blockHitResult = ctx.world.raycast(
RaycastContext(
origin,
Action.raycastEnd(origin, look),
RaycastContext.ShapeType.COLLIDER,
RaycastContext.FluidHandling.ANY,
ctx.caster
)
)

if (blockHitResult.type == HitResult.Type.BLOCK && ctx.isVecInRange(Vec3d.ofCenter(blockHitResult.blockPos)))
return blockHitResult.blockPos.asActionResult
return listOf(NullIota())
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getInt
import at.petrak.hexcasting.api.spell.getPattern
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.PatternIota
import at.petrak.hexcasting.api.spell.math.EulerPathFinder

class OpShufflePattern : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val pattern = args.getPattern(0, argc)
val seed = args.getInt(1, argc)
return listOf(PatternIota(EulerPathFinder.findAltDrawing(pattern, seed.toLong())))
return EulerPathFinder.findAltDrawing(pattern, seed.toLong()).asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.BooleanIota
import at.petrak.hexcasting.api.spell.iota.Iota

class OpSimilar : ConstMediaAction {
override val argc = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val a = args[0]
val b = args[1]
return listOf(BooleanIota(a.type == b.type))
return (a.type == b.type).asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getBlockPos
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetBlockData(private val mode: Int) : ConstMediaAction {
Expand All @@ -12,12 +12,10 @@ class OpGetBlockData(private val mode: Int) : ConstMediaAction {
val position = args.getBlockPos(0, argc)
ctx.assertVecInRange(position)
val block = ctx.world.getBlockState(position).block
return listOf(
when (mode) {
0 -> DoubleIota(block.hardness.toDouble())
1 -> DoubleIota(block.blastResistance.toDouble())
else -> throw IllegalStateException()
}
)
return when (mode) {
0 -> block.hardness.asActionResult
1 -> block.blastResistance.asActionResult
else -> throw IllegalStateException()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.casting.iota.getIdentifier
Expand All @@ -19,7 +19,7 @@ class OpGetEnchantmentStrength : ConstMediaAction {
val data = EnchantmentHelper.get(stack)
val enchantment = Registry.ENCHANTMENT.get(id)
if (!data.containsKey(enchantment))
return listOf(DoubleIota(0.0))
return listOf(DoubleIota(data.getValue(enchantment).toDouble()))
return (0).asActionResult
return data.getValue(enchantment).asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getEntity
import at.petrak.hexcasting.api.spell.iota.BooleanIota
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetEntityData(private val mode: Int) : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val entity = args.getEntity(0, argc)
return listOf(
when (mode) {
0 -> BooleanIota(entity.isOnFire)
1 -> DoubleIota(entity.fireTicks.toDouble() / 20)
2 -> BooleanIota(entity.isWet)
else -> throw IllegalStateException()
}
)
return when (mode) {
0 -> entity.isOnFire.asActionResult
1 -> (entity.fireTicks.toDouble() / 20).asActionResult
2 -> entity.isWet.asActionResult
else -> throw IllegalStateException()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.BooleanIota
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota

Expand All @@ -13,14 +12,13 @@ class OpGetFoodData(private val mode: Int) : ConstMediaAction {
val stack = args.getItemStack(0, argc)
if (!stack.isFood)
throw MishapInvalidIota.of(args[0], 0, "food")
return listOf(
when (mode) {
0 -> DoubleIota(stack.item.foodComponent!!.hunger.toDouble())
1 -> DoubleIota(stack.item.foodComponent!!.saturationModifier.toDouble())
2 -> BooleanIota(stack.item.foodComponent!!.isMeat)
3 -> BooleanIota(stack.item.foodComponent!!.isSnack)
else -> throw IllegalStateException()
}
)
val foodComponent = stack.item.foodComponent!!
return when (mode) {
0 -> foodComponent.hunger.asActionResult
1 -> foodComponent.saturationModifier.asActionResult
2 -> foodComponent.isMeat.asActionResult
3 -> foodComponent.isSnack.asActionResult
else -> throw IllegalStateException()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getItemEntity
import at.petrak.hexcasting.api.spell.iota.BooleanIota
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.ListIota
import miyucomics.hexical.casting.iota.IdentifierIota
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.item.EnchantedBookItem
Expand All @@ -18,25 +16,23 @@ class OpGetItemStackData(private val mode: Int) : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val stack = args.getItemStack(0, argc)
return listOf(
when (mode) {
0 -> DoubleIota(stack.count.toDouble())
1 -> DoubleIota(stack.maxCount.toDouble())
2 -> DoubleIota(stack.damage.toDouble())
3 -> DoubleIota(stack.maxDamage.toDouble())
4 -> BooleanIota(stack.isFood)
5 -> {
var data = stack.enchantments
if (stack.isOf(Items.ENCHANTED_BOOK))
data = EnchantedBookItem.getEnchantmentNbt(stack)
val enchantments = mutableListOf<IdentifierIota>()
for ((enchantment, _) in EnchantmentHelper.fromNbt(data))
enchantments.add(IdentifierIota(Registry.ENCHANTMENT.getId(enchantment)!!))
ListIota(enchantments.toList())
}
else -> throw IllegalStateException()
return when (mode) {
0 -> stack.count.asActionResult
1 -> stack.maxCount.asActionResult
2 -> stack.damage.asActionResult
3 -> stack.maxDamage.asActionResult
4 -> stack.isFood.asActionResult
5 -> {
var data = stack.enchantments
if (stack.isOf(Items.ENCHANTED_BOOK))
data = EnchantedBookItem.getEnchantmentNbt(stack)
val enchantments = mutableListOf<IdentifierIota>()
for ((enchantment, _) in EnchantmentHelper.fromNbt(data))
enchantments.add(IdentifierIota(Registry.ENCHANTMENT.getId(enchantment)!!))
enchantments.asActionResult
}
)
else -> throw IllegalStateException()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package miyucomics.hexical.casting.patterns.getters

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import miyucomics.hexical.state.KeybindData

class OpGetKeybind(private val key: String) : ConstMediaAction {
override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
if (!KeybindData.active.containsKey(ctx.caster.uuid))
return listOf(DoubleIota(0.0))
return listOf(DoubleIota(KeybindData.duration[ctx.caster.uuid]!!.getOrDefault(key, 0.0).toDouble()))
return (0).asActionResult
return KeybindData.duration[ctx.caster.uuid]!!.getOrDefault(key, 0.0).asActionResult
}
}
Loading

0 comments on commit c291dd4

Please sign in to comment.