diff --git a/project/hexic/src/main/scala/org/eu/net/pool/hexic/main.scala b/project/hexic/src/main/scala/org/eu/net/pool/hexic/main.scala index 52a530d..fa5d700 100644 --- a/project/hexic/src/main/scala/org/eu/net/pool/hexic/main.scala +++ b/project/hexic/src/main/scala/org/eu/net/pool/hexic/main.scala @@ -995,21 +995,6 @@ def iotaInt(iota: Iota, under: Int, er: => Nothing): Int = trait MutableFunction[T, R] extends (T => R): def update(key: T, value: R): Unit -extension (img: CastingImage) - def apply(stack: Seq[Iota] = img.getStack.toSeq, - parenCount: Int = img.getParenCount, - parenthesized: Seq[ParenthesizedIota] = img.getParenthesized.toSeq, - escapeNext: Boolean = img.getEscapeNext, - opsConsumed: Long = img.getOpsConsumed, - userData: NbtCompound = img.getUserData) = - CastingImage(stack = stack, - parenCount = parenCount, - parenthesized = parenthesized, - escapeNext = escapeNext, - opsConsumed = opsConsumed, - userData = userData, - null : DefaultConstructorMarker) - def init(): Unit = given_Logger.info: val possible = Seq( @@ -2167,6 +2152,8 @@ trait MediaContainerProvider: @targetName("hexic$MediaContainerProvider$getMediaContainer") def getMediaContainer(c: Context): Option[MediaContainer] +extension [T] (x: => T) def trying: Try[T] = Try(x) + object registerHopperEndpoint extends (() => Unit): def apply(): Unit = HopperEndpointRegistry.INSTANCE.register: (iota: Iota, env: CastingEnvironment, slot: Integer) => diff --git a/util/changelog b/util/changelog index 2bb7803..1243906 100644 --- a/util/changelog +++ b/util/changelog @@ -2,3 +2,5 @@ 0.1.2 documented Flock's Disintegration and Speaker's Distillation for maps 0.1.2 intrusive holder allocation tracking 0.1.2 made maps insertion-ordered +0.1.3 added arm and hand utils +0.1.3 added casting image and cast result updaters diff --git a/util/gradle.properties b/util/gradle.properties index 43d0b1a..96827e5 100644 --- a/util/gradle.properties +++ b/util/gradle.properties @@ -2,7 +2,7 @@ minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 loader_version=0.16.14 scala_loader_version=0.3.1.11 -version=0.1.2 +version=0.1.3 maven_group=org.eu.net.pool modid=phlib archives_base_name=phlib diff --git a/util/src/main/scala/org/eu/net/pool/phlib/main.scala b/util/src/main/scala/org/eu/net/pool/phlib/main.scala index 6ba3456..1cb898b 100644 --- a/util/src/main/scala/org/eu/net/pool/phlib/main.scala +++ b/util/src/main/scala/org/eu/net/pool/phlib/main.scala @@ -22,7 +22,7 @@ import net.minecraft.nbt.* import net.minecraft.server.command.ServerCommandSource import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.server.world.ServerWorld -import net.minecraft.util.Hand +import net.minecraft.util.{Arm, Hand} import net.minecraft.util.dynamic.Codecs import scala.annotation.tailrec @@ -225,6 +225,59 @@ implicit class IterOnceExt[T](i: IterableOnceOps[T, ?, ?]): else Some(x) +extension (arm: Arm) + def ^(hand: Hand): Arm = arm ^ (hand == Hand.MAIN_HAND) + def ^(invert: Boolean): Arm = if invert then arm.getOpposite else arm + def ^(OtherArm: Arm): Hand = arm match + case OtherArm => Hand.MAIN_HAND + case _ => Hand.OFF_HAND +extension (hand: Hand) + def ^(arm: Arm): Arm = arm ^ hand + def ^(invert: Boolean): Hand = + if invert then + hand match + case Hand.MAIN_HAND => Hand.OFF_HAND + case Hand.OFF_HAND => Hand.MAIN_HAND + else hand + +extension (t: Throwable) def toMishap = + t match + case m: Mishap => m + case e: Exception => MishapInternalException(e) + case _ => MishapInternalException(RuntimeException(t)) + +extension [T] (x: => T) def trying: Try[T] = Try(x) + +given castingImageUpdate: AnyRef with + extension (img: CastingImage) + def apply(stack: Seq[Iota] = img.getStack.toSeq, + parenCount: Int = img.getParenCount, + parenthesized: Seq[ParenthesizedIota] = img.getParenthesized.toSeq, + escapeNext: Boolean = img.getEscapeNext, + opsConsumed: Long = img.getOpsConsumed, + userData: NbtCompound = img.getUserData) = + CastingImage(stack = stack, + parenCount = parenCount, + parenthesized = parenthesized, + escapeNext = escapeNext, + opsConsumed = opsConsumed, + userData = userData, + null : DefaultConstructorMarker) +given castResultUpdate: AnyRef with + extension (r: CastResult) + def apply(cast: Iota = r.getCast, + continuation: SpellContinuation = r.getContinuation, + newData: Option[CastingImage] = Option(r.getNewData), + sideEffects: Seq[OperatorSideEffect] = r.getSideEffects.toSeq, + resolutionType: ResolvedPatternType = r.getResolutionType, + sound: EvalSound = r.getSound) = + CastResult(cast = cast, + continuation = continuation, + newData = newData.orNull, + sideEffects = sideEffects, + resolutionType = resolutionType, + sound = sound) + extension (ctx: StringContext) def ifModLoaded(`then`: => Unit, `else`: => Unit = {}): Unit = if isDev || fabric.isModLoaded(ctx.parts(0)) then `then`