Skip to content

Commit 6ace504

Browse files
committed
Implement OpImpetusDir and OpImpetusPos for mindsplice table
1 parent 37ecd4a commit 6ace504

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package gay.object.hexdebug.mixin;
2+
3+
import at.petrak.hexcasting.api.casting.OperatorUtils;
4+
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction;
5+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
6+
import at.petrak.hexcasting.api.casting.iota.Iota;
7+
import at.petrak.hexcasting.common.casting.actions.circles.OpImpetusDir;
8+
import gay.object.hexdebug.casting.eval.SplicingTableCastEnv;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
import java.util.List;
15+
16+
@Mixin(OpImpetusDir.class)
17+
public abstract class MixinOpImpetusDir implements ConstMediaAction {
18+
@Inject(method = "execute", at = @At("HEAD"), cancellable = true, remap = false)
19+
private void hexdebug$handleSplicingTableEnv(
20+
List<? extends Iota> args,
21+
CastingEnvironment ctx,
22+
CallbackInfoReturnable<List<? extends Iota>> cir
23+
) {
24+
if (ctx instanceof SplicingTableCastEnv env) {
25+
cir.setReturnValue(OperatorUtils.getAsActionResult(env.getFacing().step()));
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package gay.object.hexdebug.mixin;
2+
3+
import at.petrak.hexcasting.api.casting.OperatorUtils;
4+
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction;
5+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
6+
import at.petrak.hexcasting.api.casting.iota.Iota;
7+
import at.petrak.hexcasting.common.casting.actions.circles.OpImpetusPos;
8+
import gay.object.hexdebug.casting.eval.SplicingTableCastEnv;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
import java.util.List;
15+
16+
@Mixin(OpImpetusPos.class)
17+
public abstract class MixinOpImpetusPos implements ConstMediaAction {
18+
@Inject(method = "execute", at = @At("HEAD"), cancellable = true, remap = false)
19+
private void hexdebug$handleSplicingTableEnv(
20+
List<? extends Iota> args,
21+
CastingEnvironment ctx,
22+
CallbackInfoReturnable<List<? extends Iota>> cir
23+
) {
24+
if (ctx instanceof SplicingTableCastEnv env) {
25+
cir.setReturnValue(OperatorUtils.getAsActionResult(env.getBlockPos()));
26+
}
27+
}
28+
}

Common/src/main/kotlin/gay/object/hexdebug/casting/eval/SplicingTableCastEnv.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import at.petrak.hexcasting.api.utils.extractMedia
99
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds
1010
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
1111
import gay.`object`.hexdebug.config.HexDebugConfig
12+
import net.minecraft.core.BlockPos
13+
import net.minecraft.core.Direction
1214
import net.minecraft.server.level.ServerPlayer
1315
import net.minecraft.sounds.SoundSource
1416
import net.minecraft.world.InteractionHand
17+
import net.minecraft.world.level.block.state.properties.BlockStateProperties
1518
import net.minecraft.world.phys.Vec3
1619
import kotlin.math.min
1720

@@ -21,6 +24,10 @@ class SplicingTableCastEnv(
2124
) : PlayerBasedCastEnv(caster, InteractionHand.MAIN_HAND) {
2225
private var sound = HexEvalSounds.NOTHING
2326

27+
val blockPos: BlockPos get() = table.blockPos
28+
29+
val facing: Direction get() = table.blockState.getValue(BlockStateProperties.FACING)
30+
2431
override fun postExecution(result: CastResult) {
2532
super.postExecution(result)
2633
sound = sound.greaterOf(result.sound)
@@ -30,11 +37,11 @@ class SplicingTableCastEnv(
3037
super.postCast(image)
3138
table.sync() // TODO: is this necessary?
3239
sound.sound?.let {
33-
world.playSound(null, table.blockPos, it, SoundSource.PLAYERS, 1f, 1f)
40+
world.playSound(null, blockPos, it, SoundSource.PLAYERS, 1f, 1f)
3441
}
3542
}
3643

37-
override fun mishapSprayPos(): Vec3 = table.blockPos.center
44+
override fun mishapSprayPos(): Vec3 = blockPos.center
3845

3946
override fun extractMediaEnvironment(cost: Long, simulate: Boolean): Long {
4047
var costLeft = cost
@@ -73,7 +80,7 @@ class SplicingTableCastEnv(
7380
return true
7481
}
7582

76-
return isVecInRadius(vec, table.blockPos.center, HexDebugConfig.server.splicingTableAmbit)
83+
return isVecInRadius(vec, blockPos.center, HexDebugConfig.server.splicingTableAmbit)
7784
}
7885

7986
override fun getCastingHand(): InteractionHand = castingHand

Common/src/main/resources/hexdebug-common.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"MixinDatagenMain",
1212
"MixinMsgShiftScrollC2S",
1313
"MixinOpEval",
14+
"MixinOpImpetusDir",
15+
"MixinOpImpetusPos",
1416
"MixinStaffCastEnv"
1517
],
1618
"plugin": "gay.object.hexdebug.mixin.HexDebugMixinConfigPlugin",

0 commit comments

Comments
 (0)