Rebase this onto the 1.0 branch

This commit is contained in:
gamma-delta 2022-05-25 15:34:46 -05:00
parent 88218deed6
commit 61926ca299
180 changed files with 995 additions and 676 deletions

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.addldata;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.Nullable;
@ -10,19 +10,19 @@ public interface DataHolder {
CompoundTag readRawDatum();
@Nullable
default SpellDatum<?> readDatum(ServerLevel world) {
default LegacySpellDatum<?> readDatum(ServerLevel world) {
var tag = readRawDatum();
if (tag != null) {
return SpellDatum.fromNBT(tag, world);
return LegacySpellDatum.fromNBT(tag, world);
} else {
return null;
}
}
@Nullable
default SpellDatum<?> emptyDatum() {
default LegacySpellDatum<?> emptyDatum() {
return null;
}
boolean writeDatum(@Nullable SpellDatum<?> datum, boolean simulate);
boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate);
}

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.addldata;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.Nullable;
@ -13,9 +13,9 @@ public interface HexHolder {
boolean hasHex();
@Nullable
List<SpellDatum<?>> getHex(ServerLevel level);
List<LegacySpellDatum<?>> getHex(ServerLevel level);
void writeHex(List<SpellDatum<?>> patterns, int mana);
void writeHex(List<LegacySpellDatum<?>> patterns, int mana);
void clearHex();
}

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.misc.ManaConstants;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.spell.ParticleSpray;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.spell.casting.CastingContext;
import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.casting.SpellCircleContext;
@ -287,7 +287,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
if (bs.getBlock() instanceof BlockCircleComponent cc) {
var newPattern = cc.getPattern(tracked, bs, this.level);
if (newPattern != null) {
var info = harness.executeIota(SpellDatum.make(newPattern), splayer.getLevel());
var info = harness.executeIota(LegacySpellDatum.make(newPattern), splayer.getLevel());
if (info.getMakesCastSound()) {
makeSound = true;
}

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.item;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.utils.NBTHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
@ -21,29 +21,34 @@ public interface DataHolderItem {
@Nullable CompoundTag readDatumTag(ItemStack stack);
@Nullable
default SpellDatum<?> readDatum(ItemStack stack, ServerLevel world) {
var tag = readDatumTag(stack);
default LegacySpellDatum<?> readDatum(ItemStack stack, ServerLevel world) {
if (!(stack.getItem() instanceof DataHolderItem dh)) {
// this should be checked via mishap beforehand
throw new IllegalArgumentException("stack's item must be an ItemDataholder but was " + stack.getItem());
}
var tag = dh.readDatumTag(stack);
if (tag != null) {
return SpellDatum.fromNBT(tag, world);
return LegacySpellDatum.fromNBT(tag, world);
} else {
return null;
}
}
@Nullable
default SpellDatum<?> emptyDatum(ItemStack stack) {
default LegacySpellDatum<?> emptyDatum(ItemStack stack) {
return null;
}
boolean canWrite(ItemStack stack, @Nullable SpellDatum<?> datum);
boolean canWrite(ItemStack stack, @Nullable LegacySpellDatum<?> datum);
void writeDatum(ItemStack stack, @Nullable SpellDatum<?> datum);
void writeDatum(ItemStack stack, @Nullable LegacySpellDatum<?> datum);
static void appendHoverText(DataHolderItem self, ItemStack pStack, List<Component> pTooltipComponents,
TooltipFlag pIsAdvanced) {
TooltipFlag pIsAdvanced) {
var datumTag = self.readDatumTag(pStack);
if (datumTag != null) {
var component = SpellDatum.displayFromNBT(datumTag);
var component = LegacySpellDatum.displayFromNBT(datumTag);
pTooltipComponents.add(new TranslatableComponent("hexcasting.spelldata.onitem", component));
if (pIsAdvanced.isAdvanced()) {

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.item;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
@ -14,9 +14,9 @@ public interface HexHolderItem extends ManaHolderItem {
boolean hasHex(ItemStack stack);
@Nullable
List<SpellDatum<?>> getHex(ItemStack stack, ServerLevel level);
List<LegacySpellDatum<?>> getHex(ItemStack stack, ServerLevel level);
void writeHex(ItemStack stack, List<SpellDatum<?>> patterns, int mana);
void writeHex(ItemStack stack, List<LegacySpellDatum<?>> patterns, int mana);
void clearHex(ItemStack stack);
}

View file

@ -13,9 +13,9 @@ interface ConstManaOperator : Operator {
val manaCost: Int
get() = 0
fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>>
fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>>
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult {
if (this.argc > stack.size)
throw MishapNotEnoughArgs(this.argc, stack.size)
val args = stack.takeLast(this.argc)

View file

@ -1,25 +0,0 @@
package at.petrak.hexcasting.api.spell;
import net.minecraft.util.StringRepresentable;
public enum DatumType implements StringRepresentable {
EMPTY("empty"),
ENTITY("entity"),
WIDGET("widget"),
LIST("list"),
PATTERN("pattern"),
DOUBLE("double"),
VEC("vec"),
OTHER("other");
public final String serializedName;
DatumType(String serializedName) {
this.serializedName = serializedName;
}
@Override
public String getSerializedName() {
return this.serializedName;
}
}

View file

@ -28,7 +28,7 @@ import java.util.*
*
*
*/
class SpellDatum<T : Any> private constructor(val payload: T) {
class LegacySpellDatum<T : Any> private constructor(val payload: T) {
val clazz: Class<T> = payload.javaClass
fun serializeToNBT(): CompoundTag = this.serializeToNBTWithDepthCheck(0, 0)?.first
@ -77,12 +77,12 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
override fun toString(): String =
buildString {
append("SpellDatum[")
append(this@SpellDatum.payload.toString())
append(this@LegacySpellDatum.payload.toString())
append(']')
}
override fun equals(other: Any?): Boolean {
return other is SpellDatum<*> && other.payload == payload
return other is LegacySpellDatum<*> && other.payload == payload
}
override fun hashCode(): Int {
@ -111,18 +111,18 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
@JvmStatic
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
fun make(payload: Any): SpellDatum<*> =
if (payload is SpellDatum<*>) {
fun make(payload: Any): LegacySpellDatum<*> =
if (payload is LegacySpellDatum<*>) {
payload
} else if (payload is List<*>) {
SpellDatum(SpellList.LList(0, payload.map {
LegacySpellDatum(SpellList.LList(0, payload.map {
when (it) {
null -> make(Widget.NULL)
else -> make(it)
}
}))
} else if (payload is Vec3) {
SpellDatum(
LegacySpellDatum(
Vec3(
fixNAN(payload.x),
fixNAN(payload.y),
@ -130,17 +130,17 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
)
)
} else if (isValidType(payload)) {
SpellDatum(payload)
LegacySpellDatum(payload)
} else if (payload is java.lang.Double) {
// Check to see if it's a java *boxed* double, for when we call this from Java
val num = payload.toDouble()
SpellDatum(fixNAN(num))
LegacySpellDatum(fixNAN(num))
} else {
throw MishapInvalidSpellDatumType(payload)
}
@JvmStatic
fun fromNBT(nbt: CompoundTag, world: ServerLevel): SpellDatum<*> {
fun fromNBT(nbt: CompoundTag, world: ServerLevel): LegacySpellDatum<*> {
val keys = nbt.allKeys
if (keys.size != 1)
return SpellDatum(Widget.GARBAGE) // Invalid iota format
@ -151,18 +151,18 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
val uuid = subtag.getUUID(TAG_ENTITY_UUID) // and throw away name
val entity = world.getEntity(uuid)
// If the entity died or something return Unit
SpellDatum(if (entity == null || !entity.isAlive) Widget.NULL else entity)
LegacySpellDatum(if (entity == null || !entity.isAlive) Widget.NULL else entity)
}
TAG_DOUBLE -> SpellDatum(nbt.getDouble(key))
TAG_VEC3 -> SpellDatum(vecFromNBT(nbt.getLongArray(key)))
TAG_DOUBLE -> LegacySpellDatum(nbt.getDouble(key))
TAG_VEC3 -> LegacySpellDatum(vecFromNBT(nbt.getLongArray(key)))
TAG_LIST -> {
SpellDatum(SpellList.fromNBT(nbt.getList(key, Tag.TAG_COMPOUND), world))
LegacySpellDatum(SpellList.fromNBT(nbt.getList(key, Tag.TAG_COMPOUND), world))
}
TAG_WIDGET -> {
SpellDatum(Widget.fromString(nbt.getString(key)))
LegacySpellDatum(Widget.fromString(nbt.getString(key)))
}
TAG_PATTERN -> {
SpellDatum(HexPattern.fromNBT(nbt.getCompound(TAG_PATTERN)))
LegacySpellDatum(HexPattern.fromNBT(nbt.getCompound(TAG_PATTERN)))
}
else -> SpellDatum(Widget.GARBAGE) // Invalid iota type
}
@ -175,7 +175,7 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
)
)
@JvmStatic
fun fromNBT(nbt: CompoundTag, ctx: CastingContext): SpellDatum<*> =
fun fromNBT(nbt: CompoundTag, ctx: CastingContext): LegacySpellDatum<*> =
fromNBT(nbt, ctx.world)
@JvmStatic
@ -282,7 +282,5 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
DatumType.OTHER, DatumType.EMPTY -> ""
}
}
}
}

View file

@ -6,4 +6,4 @@ import at.petrak.hexcasting.api.spell.casting.SpellContinuation
/**
* What happens when an operator is through?
*/
data class OperationResult(val newContinuation: SpellContinuation, val newStack: List<SpellDatum<*>>, val newLocalIota: SpellDatum<*>, val sideEffects: List<OperatorSideEffect>)
data class OperationResult(val newContinuation: SpellContinuation, val newStack: List<LegacySpellDatum<*>>, val newLocalIota: LegacySpellDatum<*>, val sideEffects: List<OperatorSideEffect>)

View file

@ -21,7 +21,7 @@ interface Operator {
*
* A particle effect at the cast site and various messages and advancements are done automagically.
*/
fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult
fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult
/**
* Do you need to be enlightened to use this operator? (i.e. is this operator a Great Pattern)
@ -50,11 +50,11 @@ interface Operator {
origin.add(look.normalize().scale(MAX_DISTANCE))
@JvmStatic
fun makeConstantOp(x: SpellDatum<*>): Operator = object : ConstManaOperator {
fun makeConstantOp(x: LegacySpellDatum<*>): Operator = object : ConstManaOperator {
override val argc: Int
get() = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> =
listOf(x)
}
}

View file

@ -13,7 +13,7 @@ import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3
import kotlin.math.abs
fun numOrVec(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, Vec3> =
fun numOrVec(datum: LegacySpellDatum<*>, reverseIdx: Int): Either<Double, Vec3> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is Vec3 -> Either.right(datum.payload)
@ -24,7 +24,7 @@ fun numOrVec(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, Vec3> =
)
}
fun numOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, SpellList> =
fun numOrList(datum: LegacySpellDatum<*>, reverseIdx: Int): Either<Double, SpellList> =
when (datum.payload) {
is Double -> Either.left(datum.payload)
is SpellList -> Either.right(datum.payload)
@ -35,15 +35,15 @@ fun numOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, SpellList>
)
}
fun spellListOf(vararg vs: Any): List<SpellDatum<*>> {
val out = ArrayList<SpellDatum<*>>(vs.size)
fun spellListOf(vararg vs: Any): List<LegacySpellDatum<*>> {
val out = ArrayList<LegacySpellDatum<*>>(vs.size)
for (v in vs) {
out.add(SpellDatum.make(v))
out.add(LegacySpellDatum.make(v))
}
return out
}
inline fun <reified T : Any> List<SpellDatum<*>>.getChecked(idx: Int, argc: Int = 0): T {
inline fun <reified T : Any> List<LegacySpellDatum<*>>.getChecked(idx: Int, argc: Int = 0): T {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x.payload is T)
return x.payload
@ -57,7 +57,7 @@ inline val Double.asSpellResult get() = spellListOf(this)
inline val Number.asSpellResult get() = spellListOf(this.toDouble())
inline val SpellList.asSpellResult get() = spellListOf(this)
inline val List<SpellDatum<*>>.asSpellResult get() = spellListOf(this)
inline val List<LegacySpellDatum<*>>.asSpellResult get() = spellListOf(this)
inline val Widget.asSpellResult get() = spellListOf(this)
@ -74,9 +74,9 @@ fun Any.tolerantEquals(other: Any) = tolerantEquals(other, 64)
private fun Any.tolerantEquals(other: Any, recursionsLeft: Int): Boolean {
return when {
this is SpellDatum<*> && other is SpellDatum<*> -> this.payload.tolerantEquals(other.payload, recursionsLeft)
this is SpellDatum<*> -> this.payload.tolerantEquals(other, recursionsLeft)
other is SpellDatum<*> -> this.tolerantEquals(other.payload, recursionsLeft)
this is LegacySpellDatum<*> && other is LegacySpellDatum<*> -> this.payload.tolerantEquals(other.payload, recursionsLeft)
this is LegacySpellDatum<*> -> this.payload.tolerantEquals(other, recursionsLeft)
other is LegacySpellDatum<*> -> this.tolerantEquals(other.payload, recursionsLeft)
this is HexPattern && other is HexPattern -> this.angles == other.angles
this is Double && other is Double -> abs(this - other) < TOLERANCE

View file

@ -1,35 +1,35 @@
package at.petrak.hexcasting.api.spell
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.server.level.ServerLevel
import at.petrak.hexcasting.api.spell.datum.SpellDatum
/**
* Restricted interface for functional lists.
*
* ...Surely this won't have any performance implications.
*/
sealed class SpellList : Iterable<SpellDatum<*>> {
sealed class SpellList : Iterable<SpellDatum> {
abstract val nonEmpty: Boolean
abstract val car: SpellDatum<*>
abstract val car: SpellDatum
abstract val cdr: SpellList
class LPair(override val car: SpellDatum<*>, override val cdr: SpellList) : SpellList() {
class LPair(override val car: SpellDatum, override val cdr: SpellList) : SpellList() {
override val nonEmpty = true
}
class LList(val idx: Int, val list: List<SpellDatum<*>>) : SpellList() {
class LList(val idx: Int, val list: List<SpellDatum>) : SpellList() {
override val nonEmpty: Boolean
get() = idx < list.size
override val car: SpellDatum<*>
override val car: SpellDatum
get() = list[idx]
override val cdr: SpellList
get() = LList(idx + 1, list)
constructor(list: List<SpellDatum>) : this(0, list)
}
fun modifyAt(startIdx: Int, modify: (SpellList) -> SpellList): SpellList {
val stack = mutableListOf<SpellDatum<*>>()
val stack = mutableListOf<SpellDatum>()
val ptr = iterator()
var idx = startIdx
if (idx < 0) {
@ -49,7 +49,7 @@ sealed class SpellList : Iterable<SpellDatum<*>> {
return value
}
fun getAt(startIdx: Int): SpellDatum<*> {
fun getAt(startIdx: Int): SpellDatum {
var ptr = this
var idx = startIdx
if (idx < 0) {
@ -69,24 +69,12 @@ sealed class SpellList : Iterable<SpellDatum<*>> {
override fun iterator() = SpellListIterator(this)
class SpellListIterator(var list: SpellList) : Iterator<SpellDatum<*>> {
class SpellListIterator(var list: SpellList) : Iterator<SpellDatum> {
override fun hasNext() = list.nonEmpty
override operator fun next(): SpellDatum<*> {
override operator fun next(): SpellDatum {
val car = list.car
list = list.cdr
return car
}
}
companion object {
@JvmStatic
fun fromNBT(nbt: ListTag, world: ServerLevel): LList {
val out = ArrayList<SpellDatum<*>>(nbt.size)
for (subtag in nbt) {
// this is safe because otherwise we wouldn't have been able to get the list before
out.add(SpellDatum.fromNBT(subtag as CompoundTag, world))
}
return LList(0, out)
}
}
}

View file

@ -13,11 +13,11 @@ interface SpellOperator : Operator {
fun awardsCastingStat(ctx: CastingContext): Boolean = true
fun execute(
args: List<SpellDatum<*>>,
args: List<LegacySpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>>?
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult {
if (this.argc > stack.size)
throw MishapNotEnoughArgs(this.argc, stack.size)
val args = stack.takeLast(this.argc)

View file

@ -16,7 +16,7 @@ enum class Widget : ConstManaOperator {
override val argc: Int
get() = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> =
this.asSpellResult
companion object {

View file

@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.mod.HexStatistics
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.datum.SpellDatum
import at.petrak.hexcasting.api.spell.math.HexDir
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.*
@ -27,10 +28,10 @@ import kotlin.math.min
* It's stored as NBT on the wand.
*/
class CastingHarness private constructor(
var stack: MutableList<SpellDatum<*>>,
var localIota: SpellDatum<*>,
var stack: MutableList<LegacySpellDatum<*>>,
var localIota: LegacySpellDatum<*>,
var parenCount: Int,
var parenthesized: List<SpellDatum<*>>,
var parenthesized: List<LegacySpellDatum<*>>,
var escapeNext: Boolean,
val ctx: CastingContext,
val prepackagedColorizer: FrozenColorizer? // for trinkets with colorizers
@ -40,17 +41,17 @@ class CastingHarness private constructor(
constructor(
ctx: CastingContext,
prepackagedColorizer: FrozenColorizer? = null
) : this(mutableListOf(), SpellDatum.make(Widget.NULL), 0, mutableListOf(), false, ctx, prepackagedColorizer)
) : this(mutableListOf(), LegacySpellDatum.make(Widget.NULL), 0, mutableListOf(), false, ctx, prepackagedColorizer)
/**
* Execute a single iota.
*/
fun executeIota(iota: SpellDatum<*>, world: ServerLevel): ControllerInfo = executeIotas(listOf(iota), world)
fun executeIota(iota: LegacySpellDatum<*>, world: ServerLevel): ControllerInfo = executeIotas(listOf(iota), world)
/**
* Given a list of iotas, execute them in sequence.
*/
fun executeIotas(iotas: List<SpellDatum<*>>, world: ServerLevel): ControllerInfo {
fun executeIotas(iotas: List<LegacySpellDatum<*>>, world: ServerLevel): ControllerInfo {
// Initialize the continuation stack to a single top-level eval for all iotas.
var continuation = SpellContinuation.Done.pushFrame(ContinuationFrame.Evaluate(SpellList.LList(0, iotas)))
// Begin aggregating info
@ -79,7 +80,7 @@ class CastingHarness private constructor(
)
}
fun getUpdate(iota: SpellDatum<*>, world: ServerLevel, continuation: SpellContinuation): CastResult {
fun getUpdate(iota: LegacySpellDatum<*>, world: ServerLevel, continuation: SpellContinuation): CastResult {
try {
this.handleParentheses(iota)?.let { (data, resolutionType) ->
return@getUpdate CastResult(continuation, data, resolutionType, listOf())
@ -150,7 +151,7 @@ class CastingHarness private constructor(
val unenlightened = pattern.isGreat && !ctx.isCasterEnlightened
val sideEffects = mutableListOf<OperatorSideEffect>()
var stack2: List<SpellDatum<*>>? = null
var stack2: List<LegacySpellDatum<*>>? = null
var cont2 = continuation
if (!unenlightened || pattern.alwaysProcessGreatSpell) {
@ -237,7 +238,7 @@ class CastingHarness private constructor(
}
}
fun generateDescs() = stack.map(SpellDatum<*>::display)
fun generateDescs() = stack.map(SpellDatum::display)
/**
* Return the functional update represented by the current state (for use with `copy`)
@ -264,7 +265,7 @@ class CastingHarness private constructor(
* Return a non-null value if we handled this in some sort of parenthesey way,
* either escaping it onto the stack or changing the parenthese-handling state.
*/
private fun handleParentheses(iota: SpellDatum<*>): Pair<FunctionalData, ResolvedPatternType>? {
private fun handleParentheses(iota: LegacySpellDatum<*>): Pair<FunctionalData, ResolvedPatternType>? {
val operator = (iota.payload as? HexPattern)?.let {
try {
PatternRegistry.matchPattern(it, this.ctx.world)
@ -297,7 +298,7 @@ class CastingHarness private constructor(
val newParenCount = this.parenCount - 1
if (newParenCount == 0) {
val newStack = this.stack.toMutableList()
newStack.add(SpellDatum.make(this.parenthesized.toList()))
newStack.add(LegacySpellDatum.make(this.parenthesized.toList()))
this.getFunctionalData().copy(
stack = newStack,
parenCount = newParenCount,
@ -457,26 +458,26 @@ class CastingHarness private constructor(
@JvmStatic
fun fromNBT(nbt: CompoundTag, ctx: CastingContext): CastingHarness {
return try {
val stack = mutableListOf<SpellDatum<*>>()
val stack = mutableListOf<LegacySpellDatum<*>>()
val stackTag = nbt.getList(TAG_STACK, Tag.TAG_COMPOUND)
for (subtag in stackTag) {
val datum = SpellDatum.fromNBT(subtag.asCompound, ctx.world)
val datum = LegacySpellDatum.fromNBT(subtag.asCompound, ctx.world)
stack.add(datum)
}
val localTag = nbt.getCompound(TAG_LOCAL)
val localIota =
if (localTag.size() == 1) SpellDatum.fromNBT(localTag, ctx.world) else SpellDatum.make(
if (localTag.size() == 1) LegacySpellDatum.fromNBT(localTag, ctx.world) else LegacySpellDatum.make(
Widget.NULL
)
val parenthesized = mutableListOf<SpellDatum<*>>()
val parenthesized = mutableListOf<LegacySpellDatum<*>>()
val parenTag = nbt.getList(TAG_PARENTHESIZED, Tag.TAG_COMPOUND)
for (subtag in parenTag) {
if (subtag.asCompound.size() != 1)
parenthesized.add(SpellDatum.make(HexPattern.fromNBT(subtag.asCompound)))
parenthesized.add(LegacySpellDatum.make(HexPattern.fromNBT(subtag.asCompound)))
else
parenthesized.add(SpellDatum.fromNBT(subtag.asCompound, ctx.world))
parenthesized.add(LegacySpellDatum.fromNBT(subtag.asCompound, ctx.world))
}
val parenCount = nbt.getInt(TAG_PAREN_COUNT)

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.spell.casting
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingHarness.CastResult
import at.petrak.hexcasting.api.utils.NBTBuilder
@ -36,7 +36,7 @@ sealed interface ContinuationFrame {
* In other words, we should consume Evaluate frames until we hit a FinishEval or Thoth frame.
* @return whether the break should stop here, alongside the new stack state (e.g. for finalizing a Thoth)
*/
fun breakDownwards(stack: List<SpellDatum<*>>): Pair<Boolean, List<SpellDatum<*>>>
fun breakDownwards(stack: List<LegacySpellDatum<*>>): Pair<Boolean, List<LegacySpellDatum<*>>>
/**
* Serializes this frame. Used for things like delays, where we pause execution.
@ -49,7 +49,7 @@ sealed interface ContinuationFrame {
*/
data class Evaluate(val list: SpellList) : ContinuationFrame {
// Discard this frame and keep discarding frames.
override fun breakDownwards(stack: List<SpellDatum<*>>) = false to stack
override fun breakDownwards(stack: List<LegacySpellDatum<*>>) = false to stack
// Step the list of patterns, evaluating a single one.
override fun evaluate(
@ -83,7 +83,7 @@ sealed interface ContinuationFrame {
*/
object FinishEval : ContinuationFrame {
// Don't do anything else to the stack, just finish the halt statement.
override fun breakDownwards(stack: List<SpellDatum<*>>) = true to stack
override fun breakDownwards(stack: List<LegacySpellDatum<*>>) = true to stack
// Evaluating it does nothing; it's only a boundary condition.
override fun evaluate(
@ -116,15 +116,15 @@ sealed interface ContinuationFrame {
data class ForEach(
val data: SpellList,
val code: SpellList,
val baseStack: List<SpellDatum<*>>?,
val acc: MutableList<SpellDatum<*>>
val baseStack: List<LegacySpellDatum<*>>?,
val acc: MutableList<LegacySpellDatum<*>>
) : ContinuationFrame {
/** When halting, we add the stack state at halt to the stack accumulator, then return the original pre-Thoth stack, plus the accumulator. */
override fun breakDownwards(stack: List<SpellDatum<*>>): Pair<Boolean, List<SpellDatum<*>>> {
override fun breakDownwards(stack: List<LegacySpellDatum<*>>): Pair<Boolean, List<LegacySpellDatum<*>>> {
val newStack = baseStack?.toMutableList() ?: mutableListOf()
acc.addAll(stack)
newStack.add(SpellDatum.make(acc))
newStack.add(LegacySpellDatum.make(acc))
return true to newStack
}
@ -154,7 +154,7 @@ sealed interface ContinuationFrame {
.pushFrame(Evaluate(code))
} else {
// Else, dump our final list onto the stack.
SpellDatum.make(acc) to continuation
LegacySpellDatum.make(acc) to continuation
}
val tStack = stack.toMutableList()
tStack.add(stackTop)

View file

@ -1,14 +1,14 @@
package at.petrak.hexcasting.api.spell.casting
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
/**
* A change to the data in a CastHarness after a pattern is drawn.
*/
data class FunctionalData(
val stack: List<SpellDatum<*>>,
val stack: List<LegacySpellDatum<*>>,
val parenCount: Int,
val parenthesized: List<SpellDatum<*>>,
val parenthesized: List<LegacySpellDatum<*>>,
val escapeNext: Boolean,
) {
/**

View file

@ -0,0 +1,49 @@
package at.petrak.hexcasting.api.spell.datum;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DatumDouble extends SpellDatum {
public static final double TOLERANCE = 0.0001;
public DatumDouble(double d) {
super(d);
}
public double getDouble() {
return (Double) this.datum;
}
@Override
public boolean equalsOther(SpellDatum that) {
return that instanceof DatumDouble dd && Math.abs(this.getDouble() - dd.getDouble()) < TOLERANCE;
}
@Override
public @NotNull Tag serialize() {
return DoubleTag.valueOf(this.getDouble());
}
public static SpellDatum.Type<DatumDouble> TYPE = new Type<>() {
@Nullable
@Override
public DatumDouble deserialize(Tag tag, ServerLevel world) throws IllegalArgumentException {
var dtag = (DoubleTag) tag;
return new DatumDouble(dtag.getAsDouble());
}
@Override
public Component display(Tag tag) {
return null;
}
@Override
public int color() {
return 0;
}
};
}

View file

@ -0,0 +1,50 @@
package at.petrak.hexcasting.api.spell.datum;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DatumEntity extends SpellDatum {
protected DatumEntity(@NotNull Entity e) {
super(e);
}
public Entity getEntity() {
return (Entity) this.datum;
}
@Override
public boolean equalsOther(SpellDatum that) {
return that instanceof DatumEntity dent && this.getEntity() == dent.getEntity();
}
@Override
public @NotNull Tag serialize() {
var out = new CompoundTag();
out.putUUID("uuid", this.getEntity().getUUID());
out.putString("name", Component.Serializer.toJson(this.getEntity().getDisplayName()));
return out;
}
public static SpellDatum.Type<DatumEntity> TYPE = new Type<>() {
@Nullable
@Override
public DatumEntity deserialize(Tag tag, ServerLevel world) throws IllegalArgumentException {
return null;
}
@Override
public Component display(Tag tag) {
return null;
}
@Override
public int color() {
return 0;
}
};

View file

@ -0,0 +1,53 @@
package at.petrak.hexcasting.api.spell.datum;
import at.petrak.hexcasting.api.spell.SpellList;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import org.jetbrains.annotations.NotNull;
/**
* Similar to {@link DatumWidget}, this is a <i>wrapper</i> for {@link SpellList}.
*/
public class DatumList extends SpellDatum {
public DatumList(@NotNull SpellList list) {
super(list);
}
public SpellList getList() {
return (SpellList) this.datum;
}
@Override
public boolean equalsOther(SpellDatum that) {
var a = this.getList();
if (!(that instanceof DatumList list)) {
return false;
}
var b = list.getList();
SpellList.SpellListIterator aIter = a.iterator(), bIter = b.iterator();
for (; ; ) {
if (!aIter.hasNext() && !bIter.hasNext()) {
// we ran out together!
return true;
}
if (aIter.hasNext() != bIter.hasNext()) {
// one remains full before the other
return false;
}
SpellDatum x = aIter.next(), y = bIter.next();
if (!SpellDatums.equalsWithTolerance(x, y)) {
return false;
}
}
}
@Override
public @NotNull Tag serialize() {
var out = new ListTag();
for (var subdatum : this.getList()) {
out.add(subdatum.serialize());
}
return out;
}
}

View file

@ -0,0 +1,20 @@
package at.petrak.hexcasting.api.spell.datum;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import net.minecraft.nbt.Tag;
import org.jetbrains.annotations.NotNull;
public class DatumPattern extends SpellDatum {
public DatumPattern(@NotNull HexPattern pattern) {
super(pattern);
}
public HexPattern getPattern() {
return (HexPattern) this.datum;
}
@Override
public @NotNull Tag serialize() {
return this.getPattern().serializeToNBT();
}
}

View file

@ -0,0 +1,20 @@
package at.petrak.hexcasting.api.spell.datum;
import net.minecraft.nbt.Tag;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class DatumVec3 extends SpellDatum {
public DatumVec3(@NotNull Vec3 datum) {
super(datum);
}
public Vec3 getVec3() {
return (Vec3) this.datum;
}
@Override
public @NotNull Tag serialize() {
return null;
}
}

View file

@ -0,0 +1,23 @@
package at.petrak.hexcasting.api.spell.datum;
import at.petrak.hexcasting.api.spell.Widget;
import net.minecraft.nbt.Tag;
import org.jetbrains.annotations.NotNull;
/**
* Note this is different than the widget itself; this is a widget wrapper.
*/
public class DatumWidget extends SpellDatum {
public DatumWidget(@NotNull Widget widget) {
super(widget);
}
public Widget getWidget() {
return (Widget) this.datum;
}
@Override
public Tag serialize() {
return null;
}
}

View file

@ -0,0 +1,56 @@
package at.petrak.hexcasting.api.spell.datum;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public abstract class SpellDatum {
@NotNull
protected final Object datum;
protected SpellDatum(@NotNull Object datum) {
this.datum = datum;
}
public @NotNull Object getDatum() {
return datum;
}
/**
* Compare this to another object, within a tolerance.
* <p>
* Don't call this directly; use {@link SpellDatums#equalsWithTolerance}.
*/
abstract public boolean equalsOther(SpellDatum that);
abstract public @NotNull Tag serialize();
public interface Type<T extends SpellDatum> {
/**
* Spell datums are stored as such: {@code { "type": "modid:type", "datum": a_tag }}.
* <p>
* The {@code type} key is given when registering the spell datum type; this method
* deserializes the tag associated with {@code "datum"}.
* <p>
* Returning {@code null} makes the resulting datum be {@link at.petrak.hexcasting.api.spell.Widget Widget.NULL}.
* Throwing an exception raises a mishap.
*/
@Nullable
T deserialize(Tag tag, ServerLevel world) throws IllegalArgumentException;
/**
* Get a display of this datum from the tag, <i>without</i> the world.
* This is for use on the client.
*/
Component display(Tag tag);
/**
* Get the color associated with this datum type.
*/
int color();
}
}

View file

@ -0,0 +1,87 @@
package at.petrak.hexcasting.api.spell.datum;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.spell.SpellList;
import at.petrak.hexcasting.api.spell.Widget;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.api.utils.HexUtils;
import net.minecraft.nbt.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SpellDatums {
private static final Map<ResourceLocation, SpellDatum.Type<?>> controllers = new ConcurrentHashMap<>();
public static final String
TAG_TYPE = HexAPI.MOD_ID + ":type",
TAG_DATA = HexAPI.MOD_ID + ":data";
public static SpellDatum deserializeFromRootTag(CompoundTag tag,
ServerLevel world) throws IllegalArgumentException {
if (tag.contains(TAG_TYPE, Tag.TAG_STRING) && tag.contains(TAG_DATA)) {
var typeKey = new ResourceLocation(tag.getString(TAG_TYPE));
var overseer = controllers.get(typeKey);
if (overseer == null) {
throw new IllegalArgumentException("Unknown type " + typeKey + "(did you remember to register it?)");
}
var datumTag = tag.get(TAG_DATA);
return overseer.deserialize(datumTag, world);
}
// For legacy reasons we need to check if it's the old serialization method
var legacyKeys = List.of(
"entity", "double", "vec3", "list", "widget", "pattern"
);
for (var legacyKey : legacyKeys) {
if (tag.contains(legacyKey)) {
return legacyDeserialize(legacyKey, tag.get(legacyKey), world);
}
}
throw new IllegalArgumentException("could not deserialize this tag: " + tag);
}
public static boolean equalsWithTolerance(SpellDatum a, SpellDatum b) {
return a == b || a.equalsOther(b) || b.equalsOther(a);
}
private static SpellDatum legacyDeserialize(String key, Tag inner,
ServerLevel world) throws IllegalArgumentException {
return switch (key) {
case "entity" -> {
var subtag = (CompoundTag) inner;
var uuid = subtag.getUUID("uuid"); // throw away the name
var entity = world.getEntity(uuid);
yield (entity == null)
? new DatumWidget(Widget.NULL)
: new DatumEntity(entity);
}
case "double" -> new DatumDouble(((DoubleTag) inner).getAsDouble());
case "vec3" -> new DatumVec3(HexUtils.vecFromNBT(((LongArrayTag) inner).getAsLongArray()));
case "list" -> {
var listTag = (ListTag) inner;
var out = new ArrayList<SpellDatum>();
for (var subtag : listTag) {
var subdatum = deserializeFromRootTag((CompoundTag) subtag, world);
out.add(subdatum);
}
yield new DatumList(new SpellList.LList(out));
}
case "widget" -> {
var str = (StringTag) inner;
yield new DatumWidget(Widget.valueOf(str.getAsString()));
}
case "pattern" -> {
var ctag = (CompoundTag) inner;
yield new DatumPattern(HexPattern.fromNBT(ctag));
}
default -> throw new IllegalArgumentException("bruh this should literally be impossible");
};
}
}

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
import at.petrak.hexcasting.api.spell.math.HexPattern
@ -38,7 +38,7 @@ sealed class Mishap : Throwable() {
*
* You can also mess up the stack with this.
*/
abstract fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>)
abstract fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>)
abstract fun errorMessage(ctx: CastingContext, errorCtx: Context): Component

View file

@ -2,8 +2,8 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.entity.npc.Villager
import net.minecraft.world.item.DyeColor
@ -12,8 +12,8 @@ class MishapAlreadyBrainswept(val villager: Villager) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
trulyHurt(villager, HexDamageSources.overcastDamageFrom(ctx.caster), villager.health)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
villager.hurt(HexDamageSources.overcastDamageFrom(ctx.caster), villager.health)
}
override fun particleSpray(ctx: CastingContext) =

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.core.BlockPos
@ -15,7 +15,7 @@ class MishapBadBlock(val pos: BlockPos, val expected: Component) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.LIME)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
ctx.world.explode(null, pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, 0.25f, Explosion.BlockInteraction.NONE)
}

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.world.entity.npc.Villager
@ -14,7 +14,7 @@ class MishapBadBrainsweep(val villager: Villager, val pos: BlockPos) : Mishap()
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
trulyHurt(villager, HexDamageSources.overcastDamageFrom(ctx.caster), villager.health)
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component
@ -12,7 +12,7 @@ class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
item.deltaMovement = item.deltaMovement.add((Math.random() - 0.5) * 0.05, 0.75, (Math.random() - 0.5) * 0.05)
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component
@ -13,7 +13,7 @@ class MishapBadOffhandItem(val item: ItemStack, val hand: InteractionHand, val w
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
yeetHeldItem(ctx, hand)
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
import net.minecraft.world.item.DyeColor
@ -12,7 +12,7 @@ class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
override fun resolutionType(ctx: CastingContext) = ResolvedPatternType.INVALID
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
// NO-OP
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.utils.asTranslatedComponent
@ -15,8 +15,8 @@ class MishapDivideByZero(val operand1: Component, val operand2: Component, val s
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.RED)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
stack.add(SpellDatum.make(Widget.GARBAGE))
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
stack.add(LegacySpellDatum.make(Widget.GARBAGE))
trulyHurt(ctx.caster, HexDamageSources.OVERCAST, ctx.caster.health / 2)
}
@ -60,14 +60,14 @@ class MishapDivideByZero(val operand1: Component, val operand2: Component, val s
@JvmStatic
fun powerOf(datum: Any) = when (datum) {
0.0 -> zerothPower
else -> powerOf(SpellDatum.make(datum).display())
else -> powerOf(LegacySpellDatum.make(datum).display())
}
@JvmStatic
fun translate(datum: Any): Component = when (datum) {
0.0 -> zero
Vec3.ZERO -> zeroVector
else -> SpellDatum.make(datum).display()
else -> LegacySpellDatum.make(datum).display()
}
}
}

View file

@ -1,8 +1,9 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor
@ -10,10 +11,11 @@ class MishapEntityTooFarAway(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.PINK)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
// Knock the player's items out of their hands
yeetHeldItemsTowards(ctx, entity.position())
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
error("entity_too_far", SpellDatum.make(entity).display(), actionName(errorCtx.action))
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Component =
error("entity_too_far", LegacySpellDatum.make(entity).display(), actionName(errorCtx.action))
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.item.DyeColor
@ -9,7 +9,7 @@ class MishapError(val exception: Exception) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
// NO-OP
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.item.DyeColor
@ -9,7 +9,7 @@ class MishapEvalTooDeep : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
ctx.caster.airSupply -= 290
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor
@ -10,7 +10,7 @@ class MishapImmuneEntity(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
yeetHeldItemsTowards(ctx, entity.position())
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -22,15 +22,15 @@ import net.minecraft.world.phys.Vec3
* [MishapInvalidIota.reverseIdx] is the index from the *back* of the stack.
*/
class MishapInvalidIota(
val perpetrator: SpellDatum<*>,
val perpetrator: LegacySpellDatum<*>,
val reverseIdx: Int,
val expected: Component
) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
stack[stack.size - 1 - reverseIdx] = SpellDatum.make(Widget.GARBAGE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
stack[stack.size - 1 - reverseIdx] = LegacySpellDatum.make(Widget.GARBAGE)
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
@ -39,7 +39,7 @@ class MishapInvalidIota(
companion object {
@JvmStatic
fun ofClass(perpetrator: SpellDatum<*>, reverseIdx: Int, cls: Class<*>): MishapInvalidIota {
fun ofClass(perpetrator: LegacySpellDatum<*>, reverseIdx: Int, cls: Class<*>): MishapInvalidIota {
val key = "hexcasting.mishap.invalid_value.class." + when {
Double::class.java.isAssignableFrom(cls) || Double::class.javaObjectType.isAssignableFrom(cls) -> "double"
Vec3::class.java.isAssignableFrom(cls) -> "vector"

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
@ -13,8 +13,8 @@ class MishapInvalidPattern : Mishap() {
override fun resolutionType(ctx: CastingContext) = ResolvedPatternType.INVALID
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
stack.add(SpellDatum.make(Widget.GARBAGE))
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
stack.add(LegacySpellDatum.make(Widget.GARBAGE))
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =

View file

@ -1,9 +1,8 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.Util
import net.minecraft.world.item.DyeColor
/**
@ -13,10 +12,8 @@ class MishapInvalidSpellDatumType(val perpetrator: Any) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
// Send it twice, just to make it clear
val msg = this.errorMessage(ctx, errorCtx)
ctx.caster.sendMessage(msg, Util.NIL_UUID)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
// NO-OP
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =

View file

@ -1,9 +1,10 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.DyeColor
@ -11,11 +12,13 @@ class MishapLocationInWrongDimension(val properDimension: ResourceLocation) : Mi
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
stack.add(SpellDatum.make(Widget.GARBAGE))
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
stack.add(LegacySpellDatum.make(Widget.GARBAGE))
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
error("wrong_dimension", actionName(errorCtx.action), properDimension.toString(),
ctx.world.dimension().location().toString())
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Component =
error(
"wrong_dimension", actionName(errorCtx.action!!), properDimension.toString(),
ctx.world.dimension().location().toString()
)
}

View file

@ -1,8 +1,9 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor
import net.minecraft.world.phys.Vec3
@ -10,10 +11,10 @@ class MishapLocationTooFarAway(val location: Vec3, val type: String = "too_far")
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
yeetHeldItemsTowards(ctx, location)
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =
error("location_$type", SpellDatum.make(location).display(), actionName(errorCtx.action))
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Component =
error("location_$type", LegacySpellDatum.make(location).display(), actionName(errorCtx.action!!))
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.world.item.DyeColor
@ -10,7 +10,7 @@ class MishapNoAkashicRecord(val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.PURPLE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
ctx.caster.giveExperiencePoints(-100)
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.item.DyeColor
@ -9,7 +9,7 @@ class MishapNoSpellCircle : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.LIGHT_BLUE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
ctx.caster.inventory.dropAll()
}

View file

@ -1,9 +1,9 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor
@ -11,9 +11,9 @@ class MishapNotEnoughArgs(val expected: Int, val got: Int) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.LIGHT_GRAY)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
for (i in got until expected)
stack.add(SpellDatum.make(Widget.GARBAGE))
stack.add(LegacySpellDatum.make(Widget.GARBAGE))
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =

View file

@ -1,10 +1,9 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.player.Player
@ -14,7 +13,7 @@ class MishapOthersName(val other: Player) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
ctx.caster.addEffect(MobEffectInstance(MobEffects.BLINDNESS, 20 * 60))
}
@ -23,14 +22,14 @@ class MishapOthersName(val other: Player) : Mishap() {
companion object {
@JvmStatic
fun getTrueNameFromDatum(datum: SpellDatum<*>, caster: Player): Player? {
fun getTrueNameFromDatum(datum: LegacySpellDatum<*>, caster: Player): Player? {
if (datum.payload is Player && datum.payload != caster)
return datum.payload
else if (datum.payload !is SpellList)
return null
val poolToSearch: MutableList<SpellDatum<*>> =
datum.payload.filterIsInstance<SpellDatum<*>>().toMutableList()
val poolToSearch: MutableList<LegacySpellDatum<*>> =
datum.payload.filterIsInstance<LegacySpellDatum<*>>().toMutableList()
while (poolToSearch.isNotEmpty()) {
val datumToCheck = poolToSearch[0]
@ -39,14 +38,14 @@ class MishapOthersName(val other: Player) : Mishap() {
if (datumToCheck.payload is Player && datumToCheck.payload != caster)
return datumToCheck.payload
else if (datumToCheck.payload is SpellList)
poolToSearch.addAll(datumToCheck.payload.filterIsInstance<SpellDatum<*>>())
poolToSearch.addAll(datumToCheck.payload.filterIsInstance<LegacySpellDatum<*>>())
}
return null
}
@JvmStatic
fun getTrueNameFromArgs(datums: List<SpellDatum<*>>, caster: Player): Player? {
fun getTrueNameFromArgs(datums: List<LegacySpellDatum<*>>, caster: Player): Player? {
return datums.firstNotNullOfOrNull { getTrueNameFromDatum(it, caster) }
}
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor
@ -10,8 +10,8 @@ class MishapTooManyCloseParens : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.ORANGE)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
stack.add(SpellDatum.make(errorCtx.pattern))
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
stack.add(LegacySpellDatum.make(errorCtx.pattern))
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =

View file

@ -1,10 +1,7 @@
package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.DatumType
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.item.DyeColor
@ -12,12 +9,14 @@ import net.minecraft.world.item.DyeColor
* The value was a naked iota without being Considered or Retrospected.
*/
class MishapUnescapedValue(
val perpetrator: SpellDatum<*>
val perpetrator: LegacySpellDatum<*>
) : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer =
dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<SpellDatum<*>>) {
override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<LegacySpellDatum<*>>) {
// TODO
/*
val idx = stack.indexOfLast { it.getType() == DatumType.LIST }
if (idx != -1) {
val list = stack[idx].payload as SpellList
@ -28,6 +27,7 @@ class MishapUnescapedValue(
})
}
}
*/
}
override fun errorMessage(ctx: CastingContext, errorCtx: Context) =

View file

@ -2,7 +2,7 @@
package at.petrak.hexcasting.api.utils
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.math.HexCoord
import net.minecraft.ChatFormatting
@ -88,7 +88,7 @@ fun pxToCoord(px: Vec2, size: Float, offset: Vec2): HexCoord {
else
HexCoord(q, r + (rf + 0.5 * qf).roundToInt())
}
s
fun String.withStyle(op: (Style) -> Style): MutableComponent = asTextComponent.withStyle(op)
fun String.withStyle(style: Style): MutableComponent = asTextComponent.withStyle(style)
fun String.withStyle(formatting: ChatFormatting): MutableComponent = asTextComponent.withStyle(formatting)
@ -234,12 +234,12 @@ inline operator fun <T> WeakValue<T>.setValue(thisRef: Any?, property: KProperty
/**
* Returns an empty list if it's too complicated.
*/
fun Iterable<SpellDatum<*>>.serializeToNBT(): ListTag {
val out = SpellDatum.make(SpellList.LList(0, this.toList())).serializeToNBT()
return if (out.contains(SpellDatum.TAG_WIDGET))
fun Iterable<LegacySpellDatum<*>>.serializeToNBT(): ListTag {
val out = LegacySpellDatum.make(SpellList.LList(0, this.toList())).serializeToNBT()
return if (out.contains(LegacySpellDatum.TAG_WIDGET))
ListTag()
else
out.getList(SpellDatum.TAG_LIST, Tag.TAG_COMPOUND)
out.getList(LegacySpellDatum.TAG_LIST, Tag.TAG_COMPOUND)
}
// Copy the impl from forge

View file

@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry;
import at.petrak.hexcasting.api.item.DataHolderItem;
import at.petrak.hexcasting.api.item.ManaHolderItem;
import at.petrak.hexcasting.api.misc.ManaConstants;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.spell.Widget;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.client.be.BlockEntityAkashicBookshelfRenderer;
@ -266,17 +266,17 @@ public class RegisterClientStuff {
}
return typename == null ? 0f : switch (typename) {
case SpellDatum.TAG_ENTITY -> 1f;
case SpellDatum.TAG_DOUBLE -> 2f;
case SpellDatum.TAG_VEC3 -> 3f;
case SpellDatum.TAG_WIDGET -> 4f;
case SpellDatum.TAG_LIST -> 5f;
case SpellDatum.TAG_PATTERN -> 6f;
case LegacySpellDatum.TAG_ENTITY -> 1f;
case LegacySpellDatum.TAG_DOUBLE -> 2f;
case LegacySpellDatum.TAG_VEC3 -> 3f;
case LegacySpellDatum.TAG_WIDGET -> 4f;
case LegacySpellDatum.TAG_LIST -> 5f;
case LegacySpellDatum.TAG_PATTERN -> 6f;
default -> 0f; // uh oh
};
});
IClientXplatAbstractions.INSTANCE.registerItemProperty((Item) item, ItemFocus.SEALED_PRED,
(stack, level, holder, holderID) -> item.canWrite(stack, SpellDatum.make(Widget.NULL)) ? 0f : 1f);
(stack, level, holder, holderID) -> item.canWrite(stack, LegacySpellDatum.make(Widget.NULL)) ? 0f : 1f);
}
private static void registerPackagedSpellOverrides(ItemPackagedHex item) {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.blocks.akashic;
import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.spell.DatumType;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.lib.HexBlocks;
import at.petrak.hexcasting.common.lib.HexSounds;
@ -59,7 +59,7 @@ public class BlockAkashicBookshelf extends BlockAkashicFloodfiller implements En
var stack = pPlayer.getItemInHand(pHand);
if (stack.getItem() instanceof ItemScroll scroll) {
if (!pLevel.isClientSide()) {
scroll.writeDatum(stack, SpellDatum.make(shelf.getPattern()));
scroll.writeDatum(stack, LegacySpellDatum.make(shelf.getPattern()));
}
pLevel.playSound(pPlayer, pPos, HexSounds.SCROLL_SCRIBBLE, SoundSource.BLOCKS, 1f, 1f);
return InteractionResult.sidedSuccess(pLevel.isClientSide);

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.blocks.akashic;
import at.petrak.hexcasting.api.block.HexBlockEntity;
import at.petrak.hexcasting.api.spell.DatumType;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.spell.math.HexDir;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.common.lib.HexBlockEntities;
@ -45,7 +45,7 @@ public class BlockEntityAkashicRecord extends HexBlockEntity {
* Will never clobber anything.
*/
public @Nullable
BlockPos addNewDatum(HexPattern key, SpellDatum<?> datum) {
BlockPos addNewDatum(HexPattern key, LegacySpellDatum<?> datum) {
String entryKey = getKey(key);
if (this.entries.containsKey(entryKey)) {
return null; // would clobber
@ -76,19 +76,19 @@ public class BlockEntityAkashicRecord extends HexBlockEntity {
}
public @Nullable
SpellDatum<?> lookupPattern(HexPattern key, ServerLevel slevel) {
LegacySpellDatum<?> lookupPattern(HexPattern key, ServerLevel slevel) {
var entry = this.entries.get(getKey(key));
if (entry == null) {
return null;
} else {
return SpellDatum.fromNBT(entry.datum, slevel);
return LegacySpellDatum.fromNBT(entry.datum, slevel);
}
}
public Component getDisplayAt(HexPattern key) {
var entry = this.entries.get(getKey(key));
if (entry != null) {
return SpellDatum.displayFromNBT(entry.datum);
return LegacySpellDatum.displayFromNBT(entry.datum);
} else {
return new TranslatableComponent("hexcasting.spelldata.akashic.nopos").withStyle(ChatFormatting.RED);
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.blocks.circles;
import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.block.circle.BlockCircleComponent;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.common.lib.HexItems;
import net.minecraft.core.BlockPos;
@ -102,7 +102,7 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim
if (be instanceof BlockEntitySlate slate) {
ItemStack stack = new ItemStack(HexItems.SLATE);
if (slate.pattern != null) {
HexItems.SLATE.writeDatum(stack, SpellDatum.make(slate.pattern));
HexItems.SLATE.writeDatum(stack, LegacySpellDatum.make(slate.pattern));
}
return stack;
}

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.common.casting;
import at.petrak.hexcasting.api.PatternRegistry;
import at.petrak.hexcasting.api.misc.ManaConstants;
import at.petrak.hexcasting.api.spell.Operator;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
import at.petrak.hexcasting.api.spell.Widget;
import at.petrak.hexcasting.api.spell.math.HexAngle;
import at.petrak.hexcasting.api.spell.math.HexDir;
@ -352,29 +352,29 @@ public class RegisterPatterns {
PatternRegistry.mapPattern(HexPattern.fromAngles("d", HexDir.EAST), modLoc("const/null"), Widget.NULL);
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqea", HexDir.NORTH_WEST), modLoc("const/vec/px"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(1.0, 0.0, 0.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(1.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqew", HexDir.NORTH_WEST), modLoc("const/vec/py"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, 1.0, 0.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 1.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqqed", HexDir.NORTH_WEST), modLoc("const/vec/pz"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, 0.0, 1.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 1.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqa", HexDir.SOUTH_WEST), modLoc("const/vec/nx"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(-1.0, 0.0, 0.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(-1.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqw", HexDir.SOUTH_WEST), modLoc("const/vec/ny"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, -1.0, 0.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, -1.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("eeeeeqd", HexDir.SOUTH_WEST), modLoc("const/vec/nz"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, 0.0, -1.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, -1.0))));
// Yep, this is what I spend the "plain hexagon" pattern on.
PatternRegistry.mapPattern(HexPattern.fromAngles("qqqqq", HexDir.NORTH_WEST), modLoc("const/vec/0"),
Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, 0.0, 0.0))));
Operator.makeConstantOp(LegacySpellDatum.make(new Vec3(0.0, 0.0, 0.0))));
PatternRegistry.mapPattern(HexPattern.fromAngles("qdwdq", HexDir.NORTH_EAST), modLoc("const/double/pi"),
Operator.makeConstantOp(SpellDatum.make(Math.PI)));
Operator.makeConstantOp(LegacySpellDatum.make(Math.PI)));
PatternRegistry.mapPattern(HexPattern.fromAngles("eawae", HexDir.NORTH_WEST), modLoc("const/double/tau"),
Operator.makeConstantOp(SpellDatum.make(HexUtils.TAU)));
Operator.makeConstantOp(LegacySpellDatum.make(HexUtils.TAU)));
// e
PatternRegistry.mapPattern(HexPattern.fromAngles("aaq", HexDir.EAST), modLoc("const/double/e"),
Operator.makeConstantOp(SpellDatum.make(Math.E)));
Operator.makeConstantOp(LegacySpellDatum.make(Math.E)));
// == Entities ==
@ -490,7 +490,7 @@ public class RegisterPatterns {
if (negate) {
accumulator = -accumulator;
}
return Operator.makeConstantOp(SpellDatum.make(accumulator));
return Operator.makeConstantOp(LegacySpellDatum.make(accumulator));
} else {
return null;
}

View file

@ -10,7 +10,7 @@ import net.minecraft.world.phys.Vec3
object OpBlockAxisRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)

View file

@ -10,7 +10,7 @@ import net.minecraft.world.phys.Vec3
object OpBlockRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -10,7 +10,7 @@ import net.minecraft.world.entity.Entity
object OpEntityHeight : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
return e.bbHeight.asSpellResult

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -10,7 +10,7 @@ import net.minecraft.world.entity.Entity
object OpEntityLook : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
return e.lookAngle.asSpellResult

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -11,7 +11,7 @@ import net.minecraft.world.entity.player.Player
object OpEntityPos : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)
// If this is a player, "expected behavior" is to get the *eye* position so raycasts don't immediately

View file

@ -10,7 +10,7 @@ import net.minecraft.world.phys.Vec3
object OpEntityRaycast : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT / 100
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val origin: Vec3 = args.getChecked(0, argc)
val look: Vec3 = args.getChecked(1, argc)
val endp = Operator.raycastEnd(origin, look)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -12,7 +12,7 @@ import net.minecraft.world.entity.Entity
object OpEntityVelocity : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val e: Entity = args.getChecked(0, argc)
ctx.assertEntityInRange(e)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -9,7 +9,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpRead : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val (handStack, hand) = ctx.getHeldItemToOperateOn {
val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
dataHolder != null && (dataHolder.readDatum(ctx.world) != null || dataHolder.emptyDatum() != null)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -9,7 +9,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpReadable : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val (handStack) = ctx.getHeldItemToOperateOn {
IXplatAbstractions.INSTANCE.findDataHolder(it) != null
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
import at.petrak.hexcasting.xplat.IXplatAbstractions
@ -12,9 +12,9 @@ object OpTheCoolerRead : ConstManaOperator {
override val argc = 1
override fun execute(
args: List<SpellDatum<*>>,
args: List<LegacySpellDatum<*>>,
ctx: CastingContext
): List<SpellDatum<*>> {
): List<LegacySpellDatum<*>> {
val target = args.getChecked<ItemEntity>(0, argc)
ctx.assertEntityInRange(target)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -12,9 +12,9 @@ object OpTheCoolerReadable : ConstManaOperator {
override val argc = 1
override fun execute(
args: List<SpellDatum<*>>,
args: List<LegacySpellDatum<*>>,
ctx: CastingContext
): List<SpellDatum<*>> {
): List<LegacySpellDatum<*>> {
val target = args.getChecked<ItemEntity>(0, argc)
ctx.assertEntityInRange(target)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
@ -10,7 +10,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpWritable : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val datum = args[0]
val (handStack) = ctx.getHeldItemToOperateOn {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
@ -13,7 +13,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
object OpWrite : SpellOperator {
override val argc = 1
override fun execute(
args: List<SpellDatum<*>>,
args: List<LegacySpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val datum = args[0]
@ -41,7 +41,7 @@ object OpWrite : SpellOperator {
)
}
private data class Spell(val datum: SpellDatum<*>) : RenderedSpell {
private data class Spell(val datum: LegacySpellDatum<*>) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val (handStack) = ctx.getHeldItemToOperateOn {
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)

View file

@ -2,10 +2,10 @@ package at.petrak.hexcasting.common.casting.operators.akashic
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.Widget
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
@ -16,7 +16,7 @@ object OpAkashicRead : ConstManaOperator {
override val argc = 2
override val manaCost = ManaConstants.DUST_UNIT
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val pos = args.getChecked<Vec3>(0, argc)
val key = args.getChecked<HexPattern>(1, argc)
@ -27,6 +27,6 @@ object OpAkashicRead : ConstManaOperator {
}
val datum = tile.lookupPattern(key, ctx.world)
return listOf(datum ?: SpellDatum.make(Widget.NULL))
return listOf(datum ?: LegacySpellDatum.make(Widget.NULL))
}
}

View file

@ -20,7 +20,7 @@ object OpAkashicWrite : SpellOperator {
override val causesBlindDiversion = false
override fun execute(
args: List<SpellDatum<*>>,
args: List<LegacySpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pos = args.getChecked<Vec3>(0, argc)
@ -46,7 +46,7 @@ object OpAkashicWrite : SpellOperator {
)
}
private data class Spell(val record: BlockEntityAkashicRecord, val key: HexPattern, val datum: SpellDatum<*>) :
private data class Spell(val record: BlockEntityAkashicRecord, val key: HexPattern, val datum: LegacySpellDatum<*>) :
RenderedSpell {
override fun cast(ctx: CastingContext) {
record.addNewDatum(key, datum)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
@ -10,7 +10,7 @@ import net.minecraft.world.phys.Vec3
class OpCircleBounds(val max: Boolean) : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
if (ctx.spellCircle == null)
throw MishapNoSpellCircle()

View file

@ -2,15 +2,15 @@ package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
object OpImpetusDir : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
if (ctx.spellCircle == null)
throw MishapNoSpellCircle()

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.circles
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNoSpellCircle
@ -10,7 +10,7 @@ import net.minecraft.world.phys.Vec3
object OpImpetusPos : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
if (ctx.spellCircle == null)
throw MishapNoSpellCircle()

View file

@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.spell.casting.ContinuationFrame
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpEval : Operator {
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult {
val instrs: SpellList = stack.getChecked(stack.lastIndex)
stack.removeLastOrNull()

View file

@ -2,12 +2,12 @@ package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpEvalDelay : Operator {
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult {
return OperationResult(continuation, stack, local, listOf())
}
}

View file

@ -1,19 +1,18 @@
package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.CastingHarness
import at.petrak.hexcasting.api.spell.casting.ContinuationFrame
import at.petrak.hexcasting.api.spell.casting.OperatorSideEffect
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
object OpForEach : Operator {
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(
continuation: SpellContinuation,
stack: MutableList<LegacySpellDatum<*>>,
local: LegacySpellDatum<*>,
ctx: CastingContext
): OperationResult {
if (stack.size < 2)
throw MishapNotEnoughArgs(2, stack.size)

View file

@ -1,16 +1,16 @@
package at.petrak.hexcasting.common.casting.operators.eval
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpHalt : Operator {
override fun operate(
continuation: SpellContinuation,
stack: MutableList<SpellDatum<*>>,
local: SpellDatum<*>,
stack: MutableList<LegacySpellDatum<*>>,
local: LegacySpellDatum<*>,
ctx: CastingContext
): OperationResult {
var newStack = stack.toList()

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpAppend : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val datum = args[1]
list.add(datum)

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpConcat : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val lhs = args.getChecked<SpellList>(0, argc).toMutableList()
val rhs = args.getChecked<SpellList>(1, argc)
lhs.addAll(rhs)

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpCons : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val bottom = args.getChecked<SpellList>(0, argc)
val top = args[1]
return SpellList.LPair(top, bottom).asSpellResult

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpEmptyList : ConstManaOperator {
override val argc = 0
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
return emptyList<SpellDatum<*>>().asSpellResult // sorry for taking all the easy impls, hudeler
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
return emptyList<LegacySpellDatum<*>>().asSpellResult // sorry for taking all the easy impls, hudeler
}
}

View file

@ -1,19 +1,15 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.Widget
import kotlin.math.roundToInt
object OpIndex : ConstManaOperator {
override val argc = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc)
val x = list.getOrElse(index.roundToInt()) { SpellDatum.make(Widget.NULL) }
val x = list.getOrElse(index.roundToInt()) { LegacySpellDatum.make(Widget.NULL) }
return listOf(x)
}
}

View file

@ -7,7 +7,7 @@ object OpIndexOf : ConstManaOperator {
override val argc: Int
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val value = args[1]
return list.indexOfFirst(value::tolerantEquals).asSpellResult

View file

@ -10,7 +10,7 @@ import kotlin.math.abs
import kotlin.math.roundToInt
object OpLastNToList : Operator {
override fun operate(continuation: SpellContinuation, stack: MutableList<SpellDatum<*>>, local: SpellDatum<*>, ctx: CastingContext): OperationResult {
override fun operate(continuation: SpellContinuation, stack: MutableList<LegacySpellDatum<*>>, local: LegacySpellDatum<*>, ctx: CastingContext): OperationResult {
if (stack.isEmpty())
throw MishapNotEnoughArgs(1, 0)
val arg = stack.takeLast(1).getChecked<Double>(0)
@ -23,7 +23,7 @@ object OpLastNToList : Operator {
"hexcasting.mishap.invalid_value.int.between".asTranslatedComponent(0, stack.size)
)
}
val output = mutableListOf<SpellDatum<*>>()
val output = mutableListOf<LegacySpellDatum<*>>()
output.addAll(stack.takeLast(arg.toInt()))
val endSize = stack.size - output.toList().size
while (stack.size != endSize) {

View file

@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
// it's still called beancounter's distillation in my heart
object OpListSize : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
return args.getChecked<SpellList>(0, argc).toList().size.asSpellResult // mmm one-liner
}
}

View file

@ -6,7 +6,7 @@ import kotlin.math.roundToInt
object OpModifyInPlace : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc)
val index = args.getChecked<Double>(1, argc).roundToInt()
val iota = args[2]

View file

@ -7,7 +7,7 @@ object OpRemove : ConstManaOperator {
override val argc: Int
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc).toMutableList()
val index = args.getChecked<Double>(1, argc).toInt()
if (index < 0 || index >= list.size)

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpReverski : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
return args.getChecked<SpellList>(0, argc).toList().asReversed().asSpellResult // okay kotlin kinda pogged for this
}
}

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpSingleton : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
return listOf(args[0]).asSpellResult // god i love one-liners
}
}

View file

@ -9,13 +9,13 @@ import kotlin.math.roundToInt
object OpSlice : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc).toList()
val index1 = Mth.clamp(args.getChecked<Double>(1, argc).roundToInt(), 0, list.size)
val index2 = Mth.clamp(args.getChecked<Double>(2, argc).roundToInt(), 0, list.size)
if (index1 == index2)
return emptyList<SpellDatum<*>>().asSpellResult
return emptyList<LegacySpellDatum<*>>().asSpellResult
return list.subList(min(index1, index2), max(index1, index2)).asSpellResult
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.lists
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext
@ -10,6 +10,6 @@ object OpSplat : ConstManaOperator {
override val argc: Int
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> =
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> =
args.getChecked<SpellList>(0, argc).toMutableList()
}

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
object OpUnCons : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val list = args.getChecked<SpellList>(0, argc)
if (list.nonEmpty) {
return spellListOf(list.cdr, list.car)

View file

@ -2,15 +2,15 @@ package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpPeekLocal : Operator {
override fun operate(
continuation: SpellContinuation,
stack: MutableList<SpellDatum<*>>,
local: SpellDatum<*>,
stack: MutableList<LegacySpellDatum<*>>,
local: LegacySpellDatum<*>,
ctx: CastingContext
): OperationResult {
stack.add(local)

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.local
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
@ -10,8 +10,8 @@ import at.petrak.hexcasting.api.spell.casting.SpellContinuation
object OpPushLocal : Operator {
override fun operate(
continuation: SpellContinuation,
stack: MutableList<SpellDatum<*>>,
local: SpellDatum<*>,
stack: MutableList<LegacySpellDatum<*>>,
local: LegacySpellDatum<*>,
ctx: CastingContext
): OperationResult {
if (stack.isEmpty())

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.numOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import kotlin.math.absoluteValue
@ -11,7 +11,7 @@ object OpAbsLen : ConstManaOperator {
override val argc: Int
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val x = numOrVec(args[0], 0)
return x.map({ num -> num.absoluteValue }, { vec -> vec.length() }).asSpellResult

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.numOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.spellListOf
@ -10,7 +10,7 @@ object OpAdd : ConstManaOperator {
override val argc: Int
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val lhs = numOrVec(args[0], 1)
val rhs = numOrVec(args[1], 0)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -11,7 +11,7 @@ object OpCeil : ConstManaOperator {
override val argc: Int
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val value = args.getChecked<Double>(0, argc)
return ceil(value).asSpellResult
}

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -12,7 +12,7 @@ object OpCoerceToAxial : ConstManaOperator {
override val argc: Int
get() = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val vec = args.getChecked<Vec3>(0, argc)
if (vec == Vec3.ZERO)
return vec.asSpellResult

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.asSpellResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
@ -9,7 +9,7 @@ import net.minecraft.world.phys.Vec3
object OpConstructVec : ConstManaOperator {
override val argc = 3
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val x = args.getChecked<Double>(0, argc)
val y = args.getChecked<Double>(1, argc)
val z = args.getChecked<Double>(2, argc)

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.spellListOf
@ -9,7 +9,7 @@ import net.minecraft.world.phys.Vec3
object OpDeconstructVec : ConstManaOperator {
override val argc = 1
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val v = args.getChecked<Vec3>(0, argc)
return spellListOf(v.x, v.y, v.z)
}

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.numOrVec
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.LegacySpellDatum
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapDivideByZero
import at.petrak.hexcasting.api.spell.spellListOf
@ -12,7 +12,7 @@ object OpDivCross : ConstManaOperator {
override val argc: Int
get() = 2
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
val lhs = numOrVec(args[0], 1)
val rhs = numOrVec(args[1], 0)

Some files were not shown because too many files have changed in this diff Show more