From 2f9a223a66450f02dca46d2919acb48abcc19ad9 Mon Sep 17 00:00:00 2001 From: "yrsegal@gmail.com" Date: Sun, 10 Apr 2022 20:22:32 -0400 Subject: [PATCH] trig names and descriptions subject to change --- .../common/casting/RegisterPatterns.java | 26 ++++++++-- .../casting/mishaps/MishapDivideByZero.kt | 6 +++ .../casting/operators/math/trig/OpArcCos.kt | 26 ++++++++++ .../casting/operators/math/trig/OpArcSin.kt | 27 +++++++++++ .../casting/operators/math/trig/OpArcTan.kt | 21 ++++++++ .../casting/operators/math/trig/OpCos.kt | 19 ++++++++ .../casting/operators/math/trig/OpSin.kt | 18 +++++++ .../casting/operators/math/trig/OpTan.kt | 23 +++++++++ .../assets/hexcasting/lang/en_us.json | 21 +++++++- .../en_us/entries/patterns/consts.json | 16 ++++++- .../en_us/entries/patterns/math.json | 48 +++++++++++++++++++ 11 files changed, 245 insertions(+), 6 deletions(-) create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcCos.kt create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcSin.kt create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcTan.kt create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpCos.kt create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpSin.kt create mode 100644 src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpTan.kt diff --git a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java index 54b2c3cf..1d8fc2b4 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java +++ b/src/main/java/at/petrak/hexcasting/common/casting/RegisterPatterns.java @@ -15,6 +15,7 @@ import at.petrak.hexcasting.common.casting.operators.eval.OpForEach; import at.petrak.hexcasting.common.casting.operators.lists.*; import at.petrak.hexcasting.common.casting.operators.math.*; import at.petrak.hexcasting.common.casting.operators.math.logic.*; +import at.petrak.hexcasting.common.casting.operators.math.trig.*; import at.petrak.hexcasting.common.casting.operators.selectors.OpGetCaster; import at.petrak.hexcasting.common.casting.operators.selectors.OpGetEntitiesBy; import at.petrak.hexcasting.common.casting.operators.selectors.OpGetEntityAt; @@ -127,10 +128,18 @@ public class RegisterPatterns { PatternRegistry.mapPattern(HexPattern.FromAnglesSig("aw", HexDir.NORTH_EAST), prefix("identity"), OpIdentityKindOf.INSTANCE); - PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqwqqqqqaq", HexDir.WEST), prefix("akashic/read"), - OpAkashicRead.INSTANCE); - PatternRegistry.mapPattern(HexPattern.FromAnglesSig("eeeweeeeede", HexDir.EAST), prefix("akashic/write"), - OpAkashicWrite.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqqqaa", HexDir.SOUTH_EAST), prefix("sin"), + OpSin.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqqqad", HexDir.SOUTH_EAST), prefix("cos"), + OpCos.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("wqqqqqadq", HexDir.SOUTH_WEST), prefix("tan"), + OpTan.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("ddeeeee", HexDir.SOUTH_EAST), prefix("arcsin"), + OpArcSin.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("adeeeee", HexDir.NORTH_EAST), prefix("arccos"), + OpArcCos.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("eadeeeeew", HexDir.NORTH_EAST), prefix("arctan"), + OpArcTan.INSTANCE); // == Spells == @@ -257,6 +266,10 @@ public class RegisterPatterns { prefix("brainsweep"), OpBrainsweep.INSTANCE, true); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqwqqqqqaq", HexDir.WEST), prefix("akashic/read"), + OpAkashicRead.INSTANCE); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("eeeweeeeede", HexDir.EAST), prefix("akashic/write"), + OpAkashicWrite.INSTANCE); // == Meta stuff == @@ -297,6 +310,11 @@ public class RegisterPatterns { PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqqq", HexDir.NORTH_WEST), prefix("const/vec/0"), Operator.makeConstantOp(SpellDatum.make(new Vec3(0.0, 0.0, 0.0)))); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qdwdq", HexDir.NORTH_EAST), prefix("const/double/pi"), + Operator.makeConstantOp(SpellDatum.make(Math.PI))); + PatternRegistry.mapPattern(HexPattern.FromAnglesSig("eawae", HexDir.NORTH_WEST), prefix("const/double/tau"), + Operator.makeConstantOp(SpellDatum.make(Math.PI * 2))); + // == Entities == PatternRegistry.mapPattern(HexPattern.FromAnglesSig("qqqqqdaqa", HexDir.SOUTH_EAST), prefix("get_entity"), diff --git a/src/main/java/at/petrak/hexcasting/common/casting/mishaps/MishapDivideByZero.kt b/src/main/java/at/petrak/hexcasting/common/casting/mishaps/MishapDivideByZero.kt index 073ed625..30c4a351 100644 --- a/src/main/java/at/petrak/hexcasting/common/casting/mishaps/MishapDivideByZero.kt +++ b/src/main/java/at/petrak/hexcasting/common/casting/mishaps/MishapDivideByZero.kt @@ -34,6 +34,12 @@ class MishapDivideByZero(val operand1: Component, val operand2: Component, val s return MishapDivideByZero(translate(operand1), translate(operand2), suffix) } + @JvmStatic + fun tan(angle: Double): MishapDivideByZero { + val translatedAngle = translate(angle) + return MishapDivideByZero(TranslatableComponent("$PREFIX.sin", translatedAngle), TranslatableComponent("$PREFIX.cos", translatedAngle)) + } + @JvmStatic val zero get() = TranslatableComponent("$PREFIX.zero") @JvmStatic diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcCos.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcCos.kt new file mode 100644 index 00000000..991b91c3 --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcCos.kt @@ -0,0 +1,26 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.mishaps.MishapInvalidIota +import net.minecraft.network.chat.TranslatableComponent +import kotlin.math.acos + +object OpArcCos : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val value = args.getChecked(0) + if (value < -1 || value > 1) + throw MishapInvalidIota( + SpellDatum.make(value), + 0, + TranslatableComponent("hexcasting.mishap.invalid_value.double.between", -1, 1) + ) + return spellListOf(acos(value)) + } +} diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcSin.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcSin.kt new file mode 100644 index 00000000..588710ff --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcSin.kt @@ -0,0 +1,27 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.mishaps.MishapInvalidIota +import net.minecraft.network.chat.TranslatableComponent +import kotlin.math.acos +import kotlin.math.asin + +object OpArcSin : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val value = args.getChecked(0) + if (value < -1 || value > 1) + throw MishapInvalidIota( + SpellDatum.make(value), + 0, + TranslatableComponent("hexcasting.mishap.invalid_value.double.between", -1, 1) + ) + return spellListOf(asin(value)) + } +} diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcTan.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcTan.kt new file mode 100644 index 00000000..a678696e --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpArcTan.kt @@ -0,0 +1,21 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.mishaps.MishapInvalidIota +import net.minecraft.network.chat.TranslatableComponent +import kotlin.math.acos +import kotlin.math.atan + +object OpArcTan : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val value = args.getChecked(0) + return spellListOf(atan(value)) + } +} diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpCos.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpCos.kt new file mode 100644 index 00000000..8308f246 --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpCos.kt @@ -0,0 +1,19 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import kotlin.math.cos +import kotlin.math.sin + +object OpCos : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val angle = args.getChecked(0) + return spellListOf(cos(angle)) + } +} diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpSin.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpSin.kt new file mode 100644 index 00000000..d879062b --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpSin.kt @@ -0,0 +1,18 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import kotlin.math.sin + +object OpSin : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val angle = args.getChecked(0) + return spellListOf(sin(angle)) + } +} diff --git a/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpTan.kt b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpTan.kt new file mode 100644 index 00000000..9eea4d4e --- /dev/null +++ b/src/main/java/at/petrak/hexcasting/common/casting/operators/math/trig/OpTan.kt @@ -0,0 +1,23 @@ +package at.petrak.hexcasting.common.casting.operators.math.trig + +import at.petrak.hexcasting.api.spell.ConstManaOperator +import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked +import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf +import at.petrak.hexcasting.api.spell.SpellDatum +import at.petrak.hexcasting.common.casting.CastingContext +import at.petrak.hexcasting.common.casting.mishaps.MishapDivideByZero +import kotlin.math.cos +import kotlin.math.sin +import kotlin.math.tan + +object OpTan : ConstManaOperator { + override val argc: Int + get() = 1 + + override fun execute(args: List>, ctx: CastingContext): List> { + val angle = args.getChecked(0) + if (cos(angle) == 0.0) + throw MishapDivideByZero.tan(angle) + return spellListOf(tan(angle)) + } +} diff --git a/src/main/resources/assets/hexcasting/lang/en_us.json b/src/main/resources/assets/hexcasting/lang/en_us.json index 20d739cd..8532d25c 100644 --- a/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/src/main/resources/assets/hexcasting/lang/en_us.json @@ -218,6 +218,12 @@ "hexcasting.spell.hexcasting:not_equals": "Inequality Distillation", "hexcasting.spell.hexcasting:not": "Negation Purification", "hexcasting.spell.hexcasting:identity": "Identity Purification", + "hexcasting.spell.hexcasting:sin": "Sine Purification", + "hexcasting.spell.hexcasting:cos": "Cosine Purification", + "hexcasting.spell.hexcasting:tan": "Tangent Purification", + "hexcasting.spell.hexcasting:arcsin": "Inverse Sine Prfn.", + "hexcasting.spell.hexcasting:arccos": "Inverse Cosine Prfn.", + "hexcasting.spell.hexcasting:arctan": "Inverse Tangent Prfn.", "hexcasting.spell.hexcasting:print": "Reveal", "hexcasting.spell.hexcasting:explode": "Explosion", "hexcasting.spell.hexcasting:explode/fire": "Fireball", @@ -276,6 +282,8 @@ "hexcasting.spell.hexcasting:const/vec/ny": "Vector Reflection -Y", "hexcasting.spell.hexcasting:const/vec/nz": "Vector Reflection -Z", "hexcasting.spell.hexcasting:const/vec/0": "Vector Reflection Zero", + "hexcasting.spell.hexcasting:const/double/pi": "Arc's Reflection", + "hexcasting.spell.hexcasting:const/double/tau": "Circle's Reflection", "hexcasting.spell.hexcasting:number": "Numerical Reflection", "hexcasting.spell.hexcasting:mask": "Bookkeeper's Gambit", "hexcasting.spell.unknown": "Special Handler", @@ -297,6 +305,7 @@ "hexcasting.mishap.invalid_value.numvec": "a number or vector", "hexcasting.mishap.invalid_value.list.pattern": "a list of patterns", "hexcasting.mishap.invalid_value.int": "an integer", + "hexcasting.mishap.invalid_value.double.between": "a number between %d and %d", "hexcasting.mishap.invalid_value.int.between": "an integer between %d and %d", "hexcasting.mishap.not_enough_args": "%s expected %s or more arguments but the stack was only %s tall", "hexcasting.mishap.too_many_close_parens": "Used Retrospection without first using Introspection", @@ -330,6 +339,8 @@ "hexcasting.mishap.divide_by_zero.zero.power": "zeroth power", "hexcasting.mishap.divide_by_zero.zero.vec": "the zero vector", "hexcasting.mishap.divide_by_zero.power": "power of %s", + "hexcasting.mishap.divide_by_zero.sin": "the sine of %s", + "hexcasting.mishap.divide_by_zero.cos": "the cosine of %s", "hexcasting.mishap.no_akashic_record": "No akashic record at %s", "hexcasting.landing": "I seem to have discovered a new method of magical arts, in which one draws patterns strange and wild onto a hexagonal grid. It fascinates me. I've decided to start a journal of my thoughts and findings.$(br2)$(l:https://discord.gg/4xxHGYteWk)Discord Server Link/$", @@ -590,13 +601,21 @@ "hexcasting.page.math.13": "$(li)With two numbers, combines them by raising the first to the power of the second.$(li)With a number and a vector, removes the number and raises each component of the vector to the number's power.$(li)With two vectors, combines them into the $(l:https://en.wikipedia.org/wiki/Vector_projection)vector projection/$ of the top of the stack onto the second-from-the-top.$(br2)In the first and second cases, the first argument or its components are the base, and the second argument or its components are the exponent.", "hexcasting.page.math.14": "Combine three numbers at the top of the stack into a vector's X, Y, and Z components (top to bottom).", "hexcasting.page.math.15": "Split a vector into its X, Y, and Z components (top to bottom).", + "hexcasting.page.math.16": "Take the sine of an angle in radians, the vertical component of that angle drawn on a circle of radius 1.", + "hexcasting.page.math.17": "Take the cosine of an angle in radians, the horizontal component of that angle drawn on a circle of radius 1.", + "hexcasting.page.math.18": "Take the tangent of an angle in radians, the slope of that angle drawn on a circle.", + "hexcasting.page.math.19": "Take the inverse sine of a value with absolute value 1 or less, the angle whose sine is that value.", + "hexcasting.page.math.20": "Take the inverse cosine of a value with absolute value 1 or less, the angle whose sine is that value.", + "hexcasting.page.math.21": "Take the inverse tangent of a value, the angle whose tangent is that value.", "hexcasting.entry.consts": "Constants", "hexcasting.page.consts.1": "The left-hand counter-clockwise pattern adds [1, 0, 0] to the stack; the right-hand clockwise pattern adds [-1, 0, 0].", "hexcasting.page.consts.2": "The left-hand counter-clockwise pattern adds [0, 1, 0] to the stack; the right-hand clockwise pattern adds [0, -1, 0].", "hexcasting.page.consts.3": "The left-hand counter-clockwise pattern adds [0, 0, 1]; the right-hand clockwise pattern adds [0, 0, -1].", "hexcasting.page.consts.4": "Adds [0, 0, 0] to the stack.", - "hexcasting.page.consts.5": "Adds the Null influence to the top of the stack.", + "hexcasting.page.consts.5": "Adds τ, the radial representation of a complete circle, to the stack.", + "hexcasting.page.consts.6": "Adds π, the radial representation of half a circle, to the stack.", + "hexcasting.page.consts.7": "Adds the Null influence to the top of the stack.", "hexcasting.entry.stackmanip": "Stack Manipulation", "hexcasting.page.stackmanip.1": "Swaps the top two iotas of the stack.", diff --git a/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/consts.json b/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/consts.json index bc87074d..1042d10c 100644 --- a/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/consts.json +++ b/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/consts.json @@ -70,12 +70,26 @@ "output": "vector", "text": "hexcasting.page.consts.4" }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:const/double/tau", + "input": "", + "output": "num", + "text": "hexcasting.page.consts.5" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:const/double/pi", + "input": "", + "output": "num", + "text": "hexcasting.page.consts.6" + }, { "type": "hexcasting:pattern", "op_id": "hexcasting:const/null", "input": "", "output": "influence", - "text": "hexcasting.page.consts.5" + "text": "hexcasting.page.consts.7" } ] } diff --git a/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/math.json b/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/math.json index 0ef24f75..e3648bf7 100644 --- a/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/math.json +++ b/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/patterns/math.json @@ -100,6 +100,54 @@ "input": "vector", "output": "num, num, num", "text": "hexcasting.page.math.15" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:sin", + "anchor": "hexcasting:sin", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.16" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:cos", + "anchor": "hexcasting:cos", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.17" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:tan", + "anchor": "hexcasting:tan", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.18" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:arcsin", + "anchor": "hexcasting:arcsin", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.19" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:arccos", + "anchor": "hexcasting:arccos", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.20" + }, + { + "type": "hexcasting:pattern", + "op_id": "hexcasting:arctan", + "anchor": "hexcasting:arctan", + "input": "num", + "output": "num", + "text": "hexcasting.page.math.21" } ] }