From 72efd81285c06a4357d3660dca82b0e02644aa46 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Fri, 31 Mar 2023 21:29:39 +1000 Subject: [PATCH] asdf tried to get things working but there's a lot broken! --- .../circles/BlockEntityAbstractImpetus.java | 1 + .../api/casting/eval/env/CircleCastEnv.java | 18 ++++++++++++++++++ .../api/casting/eval/env/StaffCastEnv.java | 10 ++++++++++ .../api/casting/eval/vm/FrameForEach.kt | 2 +- .../operators/circles/OpCircleBounds.kt | 7 ++++--- .../casting/operators/circles/OpImpetusDir.kt | 9 +++------ .../casting/operators/circles/OpImpetusPos.kt | 6 +++--- .../casting/operators/spells/OpMakeBattery.kt | 4 ++-- .../operators/spells/OpMakePackagedSpell.kt | 2 +- .../casting/operators/spells/OpPlaceBlock.kt | 7 ++++--- .../common/casting/operators/spells/OpPrint.kt | 2 +- 11 files changed, 48 insertions(+), 20 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java index 0c1564d8..dee81c51 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/BlockEntityAbstractImpetus.java @@ -25,6 +25,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.text.DecimalFormat; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java index 885bcc5e..55f603f5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java @@ -1,6 +1,7 @@ package at.petrak.hexcasting.api.casting.eval.env; import at.petrak.hexcasting.api.casting.ParticleSpray; +import at.petrak.hexcasting.api.casting.circles.BlockEntityAbstractImpetus; import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; @@ -12,6 +13,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @@ -32,6 +34,22 @@ public class CircleCastEnv extends CastingEnvironment { return null; } + public @Nullable BlockEntityAbstractImpetus getCircle() { + var entity = this.world.getBlockEntity(impetusLoc); + + if (entity instanceof BlockEntityAbstractImpetus) + return (BlockEntityAbstractImpetus) entity; + return null; + } + + public BlockPos getImpetusLoc() { + return impetusLoc; + } + + public Direction getStartDir() { + return startDir; + } + @Override public MishapEnvironment getMishapEnvironment() { return null; diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/StaffCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/StaffCastEnv.java index 91ac91c8..a3cbe0e9 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/StaffCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/StaffCastEnv.java @@ -20,8 +20,13 @@ import java.util.HashSet; import java.util.List; public class StaffCastEnv extends PlayerBasedCastEnv { + private InteractionHand castingHand; + + public StaffCastEnv(ServerPlayer caster, InteractionHand castingHand) { super(caster, castingHand); + + this.castingHand = castingHand; } @Override @@ -43,6 +48,11 @@ public class StaffCastEnv extends PlayerBasedCastEnv { return remaining; } + @Override + public InteractionHand castingHand() { + return castingHand; + } + @Override public FrozenColorizer getColorizer() { return HexAPI.instance().getColorizer(this.caster); diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt index 573611fd..fef9c0d4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/FrameForEach.kt @@ -54,7 +54,7 @@ data class FrameForEach( val (stackTop, newImage, newCont) = if (data.nonEmpty) { // Increment the evaluation depth, // push the next datum to the top of the stack, - Triple(data.car, harness.image.incDepth(), continuation + Triple(data.car, harness.image.copy(userData = CastingImage.incDepth(harness.image.userData)), continuation // put the next Thoth object back on the stack for the next Thoth cycle, .pushFrame(FrameForEach(data.cdr, code, stack, acc)) // and prep the Thoth'd code block for evaluation. diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt index d1b16df3..b5736426 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpCircleBounds.kt @@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.circles import at.petrak.hexcasting.api.casting.castables.ConstMediaAction import at.petrak.hexcasting.api.casting.asActionResult import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.mishaps.MishapNoSpellCircle import net.minecraft.world.phys.Vec3 @@ -11,11 +12,11 @@ class OpCircleBounds(val max: Boolean) : ConstMediaAction { override val argc = 0 override fun execute(args: List, ctx: CastingEnvironment): List { - val circle = ctx.spellCircle - if (circle == null) + if (ctx !is CircleCastEnv) throw MishapNoSpellCircle() + val circle = ctx.circle ?: throw MishapNoSpellCircle() - val aabb = circle.aabb + val aabb = circle.getBounds(listOf()) return if (max) Vec3(aabb.maxX - 0.5, aabb.maxY - 0.5, aabb.maxZ - 0.5).asActionResult diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusDir.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusDir.kt index a024d342..6a88cbac 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusDir.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusDir.kt @@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus import at.petrak.hexcasting.api.casting.castables.ConstMediaAction import at.petrak.hexcasting.api.casting.asActionResult import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.mishaps.MishapNoSpellCircle @@ -11,13 +12,9 @@ object OpImpetusDir : ConstMediaAction { override val argc = 0 override fun execute(args: List, ctx: CastingEnvironment): List { - val circle = ctx.spellCircle - if (circle == null) + if (ctx !is CircleCastEnv) throw MishapNoSpellCircle() - val pos = circle.impetusPos - val bs = ctx.world.getBlockState(pos) - val dir = bs.getValue(BlockAbstractImpetus.FACING) - return dir.step().asActionResult + return ctx.startDir.step().asActionResult } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusPos.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusPos.kt index e9570985..b262e577 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusPos.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/circles/OpImpetusPos.kt @@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.circles import at.petrak.hexcasting.api.casting.castables.ConstMediaAction import at.petrak.hexcasting.api.casting.asActionResult import at.petrak.hexcasting.api.casting.eval.CastingEnvironment +import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.mishaps.MishapNoSpellCircle @@ -10,10 +11,9 @@ object OpImpetusPos : ConstMediaAction { override val argc = 0 override fun execute(args: List, ctx: CastingEnvironment): List { - val circle = ctx.spellCircle - if (circle == null) + if (ctx !is CircleCastEnv) throw MishapNoSpellCircle() - return circle.impetusPos.asActionResult + return ctx.impetusLoc.asActionResult } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt index 03b1adfc..1efd9fe5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt @@ -68,10 +68,10 @@ object OpMakeBattery : SpellAction { val entityStack = itemEntity.item.copy() val mediamount = extractMedia(entityStack, drainForBatteries = true) if (mediamount > 0) { - ctx.caster.setItemInHand( + ctx.caster?.setItemInHand( hand, ItemMediaHolder.withMedia(ItemStack(HexItems.BATTERY), mediamount, mediamount) - ) + ) ?: return } itemEntity.item = entityStack diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt index a875f504..52d71442 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt @@ -47,7 +47,7 @@ class OpMakePackagedSpell(val itemType: T, val cost: Int) : ) } - val trueName = MishapOthersName.getTrueNameFromArgs(patterns, ctx.caster) + val trueName = ctx.caster?.let { MishapOthersName.getTrueNameFromArgs(patterns, it) } if (trueName != null) throw MishapOthersName(trueName) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt index e04e3a4f..b1d412b4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt @@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.core.particles.BlockParticleOption import net.minecraft.core.particles.ParticleTypes import net.minecraft.sounds.SoundSource @@ -27,14 +28,14 @@ object OpPlaceBlock : SpellAction { override fun execute( args: List, ctx: CastingEnvironment - ): Triple>? { + ): Triple> { val pos = args.getBlockPos(0, argc) ctx.assertVecInRange(pos) val blockHit = BlockHitResult( - Vec3.atCenterOf(pos), ctx.caster.direction, pos, false + Vec3.atCenterOf(pos), ctx.caster?.direction ?: Direction.NORTH, pos, false ) - val itemUseCtx = UseOnContext(ctx.caster, ctx.castingHand, blockHit) + val itemUseCtx = UseOnContext(ctx.caster, ctx.castingHand(), blockHit) val placeContext = BlockPlaceContext(itemUseCtx) val worldState = ctx.world.getBlockState(pos) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt index 14ad1bdd..309386b9 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPrint.kt @@ -31,7 +31,7 @@ object OpPrint : Action { private data class Spell(val datum: Iota) : RenderedSpell { override fun cast(ctx: CastingEnvironment) { - ctx.caster.sendSystemMessage(datum.display()) + ctx.caster?.sendSystemMessage(datum.display()) } } }