alwinfyyyyyyyy

This commit is contained in:
yrsegal@gmail.com 2022-05-20 00:08:03 +01:00
parent cb8b4be953
commit a3d915f90f
3 changed files with 13 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package at.petrak.hexcasting.api.spell.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.effect.MobEffectInstance import net.minecraft.world.effect.MobEffectInstance
@ -26,7 +27,7 @@ class MishapOthersName(val other: Player) : Mishap() {
fun getTrueNameFromDatum(datum: SpellDatum<*>, caster: Player): Player? { fun getTrueNameFromDatum(datum: SpellDatum<*>, caster: Player): Player? {
if (datum.payload is Player && datum.payload != caster) if (datum.payload is Player && datum.payload != caster)
return datum.payload return datum.payload
else if (datum.payload !is List<*>) else if (datum.payload !is SpellList)
return null return null
val poolToSearch: MutableList<SpellDatum<*>> = val poolToSearch: MutableList<SpellDatum<*>> =
@ -38,7 +39,7 @@ class MishapOthersName(val other: Player) : Mishap() {
if (datumToCheck.payload is Player && datumToCheck.payload != caster) if (datumToCheck.payload is Player && datumToCheck.payload != caster)
return datumToCheck.payload return datumToCheck.payload
else if (datumToCheck.payload is List<*>) else if (datumToCheck.payload is SpellList)
poolToSearch.addAll(datumToCheck.payload.filterIsInstance<SpellDatum<*>>()) poolToSearch.addAll(datumToCheck.payload.filterIsInstance<SpellDatum<*>>())
} }

View file

@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.casting.operators.math package at.petrak.hexcasting.common.casting.operators.math
import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import com.mojang.datafixers.util.Either import com.mojang.datafixers.util.Either
import net.minecraft.network.chat.TranslatableComponent import net.minecraft.network.chat.TranslatableComponent
@ -18,10 +19,10 @@ object MathOpUtils {
) )
} }
fun GetNumOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, List<SpellDatum<*>>> = fun GetNumOrList(datum: SpellDatum<*>, reverseIdx: Int): Either<Double, SpellList> =
when (datum.payload) { when (datum.payload) {
is Double -> Either.left(datum.payload) is Double -> Either.left(datum.payload)
is List<*> -> Either.right(datum.payload.filterIsInstance<SpellDatum<*>>()) is SpellList -> Either.right(datum.payload)
else -> throw MishapInvalidIota( else -> throw MishapInvalidIota(
datum, datum,
reverseIdx, reverseIdx,

View file

@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.math.logic
import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.ConstManaOperator
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellList
import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import kotlin.math.abs import kotlin.math.abs
@ -21,11 +22,13 @@ class OpEquality(val invert: Boolean) : ConstManaOperator {
return when { return when {
a is Double && b is Double -> abs(a - b) < 0.0001 a is Double && b is Double -> abs(a - b) < 0.0001
a is Vec3 && b is Vec3 -> a.subtract(b).lengthSqr() < 0.0000001 a is Vec3 && b is Vec3 -> a.subtract(b).lengthSqr() < 0.0000001
a is List<*> && b is List<*> -> { a is SpellList && b is SpellList -> {
if (a.size != b.size || recursionsLeft == 0) val castA = a.toList()
val castB = b.toList()
if (castA.size != castB.size || recursionsLeft == 0)
return false return false
for (i in a.indices) for (i in castA.indices)
if (!checkEquals((a[i] as SpellDatum<*>).payload, (b[i] as SpellDatum<*>).payload, recursionsLeft - 1)) if (!checkEquals(castA[i].payload, castB[i].payload, recursionsLeft - 1))
return false return false
true true
} }