Skip to content

Commit 2b7e360

Browse files
committed
Add temporary implementation of FallingColors/HexMod#412 since there's no 1.20 gloop
1 parent cca7a48 commit 2b7e360

File tree

5 files changed

+101
-4
lines changed

5 files changed

+101
-4
lines changed

Common/src/main/kotlin/gay/object/hexdebug/blocks/focusholder/FocusHolderBlockEntity.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ class FocusHolderBlockEntity(pos: BlockPos, state: BlockState) :
3535

3636
override fun readIotaTag() = iotaHolder?.readIotaTag()
3737

38-
override fun writeIota(iota: Iota?, simulate: Boolean) = iotaHolder?.writeIota(iota, simulate) ?: false
38+
override fun writeIota(iota: Iota?, simulate: Boolean): Boolean {
39+
val success = iotaHolder?.writeIota(iota, simulate) ?: false
40+
if (!simulate && success) {
41+
sync() // sync container to clients, eg. to update scrying lens readout
42+
}
43+
return success
44+
}
3945

4046
override fun writeable() = iotaHolder?.writeable() ?: false
4147

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package gay.`object`.hexdebug.casting.actions
2+
3+
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
4+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
5+
import at.petrak.hexcasting.api.casting.getBlockPos
6+
import at.petrak.hexcasting.api.casting.iota.Iota
7+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
8+
import gay.`object`.hexdebug.utils.findDataHolder
9+
10+
// temporary implementation of FallingColors/HexMod#412 since there's no 1.20 gloop
11+
object OpReadBlock : ConstMediaAction {
12+
override val argc = 1
13+
14+
override fun execute(
15+
args: List<Iota>,
16+
env: CastingEnvironment,
17+
): List<Iota> {
18+
val pos = args.getBlockPos(0, argc)
19+
20+
env.assertPosInRange(pos)
21+
22+
val datumHolder = findDataHolder(env.world, pos)
23+
?: throw MishapBadBlock.of(pos, "iota.read")
24+
25+
val datum = datumHolder.readIota(env.world)
26+
?: datumHolder.emptyIota()
27+
?: throw MishapBadBlock.of(pos, "iota.read")
28+
29+
return listOf(datum)
30+
}
31+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package gay.`object`.hexdebug.casting.actions
2+
3+
import at.petrak.hexcasting.api.addldata.ADIotaHolder
4+
import at.petrak.hexcasting.api.casting.ParticleSpray
5+
import at.petrak.hexcasting.api.casting.RenderedSpell
6+
import at.petrak.hexcasting.api.casting.castables.SpellAction
7+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
8+
import at.petrak.hexcasting.api.casting.getBlockPos
9+
import at.petrak.hexcasting.api.casting.iota.Iota
10+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
11+
import at.petrak.hexcasting.api.casting.mishaps.MishapOthersName
12+
import gay.`object`.hexdebug.utils.findDataHolder
13+
import net.minecraft.world.phys.Vec3
14+
15+
// temporary implementation of FallingColors/HexMod#412 since there's no 1.20 gloop
16+
object OpWriteBlock : SpellAction {
17+
override val argc = 2
18+
19+
override fun execute(
20+
args: List<Iota>,
21+
env: CastingEnvironment,
22+
): SpellAction.Result {
23+
val pos = args.getBlockPos(0, argc)
24+
val datum = args[1]
25+
26+
env.assertPosInRange(pos)
27+
28+
val datumHolder = findDataHolder(env.world, pos)
29+
?: throw MishapBadBlock.of(pos, "iota.write")
30+
31+
if (!datumHolder.writeIota(datum, true))
32+
throw MishapBadBlock.of(pos, "iota.write")
33+
34+
val trueName = MishapOthersName.getTrueNameFromDatum(datum, null)
35+
if (trueName != null)
36+
throw MishapOthersName(trueName)
37+
38+
return SpellAction.Result(
39+
Spell(datum, datumHolder),
40+
0,
41+
listOf(ParticleSpray(pos.center, Vec3(1.0, 0.0, 0.0), 0.25, 3.14, 40))
42+
)
43+
}
44+
45+
private data class Spell(val datum: Iota, val datumHolder: ADIotaHolder) : RenderedSpell {
46+
override fun cast(env: CastingEnvironment) {
47+
datumHolder.writeIota(datum, false)
48+
}
49+
}
50+
}

Common/src/main/kotlin/gay/object/hexdebug/registry/HexDebugActions.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import at.petrak.hexcasting.common.casting.actions.spells.OpMakePackagedSpell
99
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex
1010
import at.petrak.hexcasting.common.lib.HexRegistries
1111
import at.petrak.hexcasting.common.lib.hex.HexActions
12-
import gay.`object`.hexdebug.casting.actions.OpBreakpoint
13-
import gay.`object`.hexdebug.casting.actions.OpIsDebugging
14-
import gay.`object`.hexdebug.casting.actions.OpNextEvalIndex
12+
import gay.`object`.hexdebug.casting.actions.*
1513

1614
object HexDebugActions : HexDebugRegistrar<ActionRegistryEntry>(HexRegistries.ACTION, { HexActions.REGISTRY }) {
1715
val IS_DEBUGGING = make("const/debugging", HexDir.EAST, "qqqqqewaa", OpIsDebugging)
@@ -25,6 +23,10 @@ object HexDebugActions : HexDebugRegistrar<ActionRegistryEntry>(HexRegistries.AC
2523
OpMakePackagedSpell(HexDebugItems.DEBUGGER.value as ItemPackagedHex, 10 * MediaConstants.CRYSTAL_UNIT)
2624
}
2725

26+
// temporary implementation of FallingColors/HexMod#412 since there's no 1.20 gloop
27+
val BLOCK_READ = make("block_read", HexDir.EAST, "aqqqqqeawqwaw", OpReadBlock)
28+
val BLOCK_WRITE = make("block_write", HexDir.EAST, "deeeeeqdwewewewdw", OpWriteBlock)
29+
2830
private fun make(name: String, startDir: HexDir, signature: String, action: Action) =
2931
make(name, startDir, signature) { action }
3032

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package gay.`object`.hexdebug.utils
22

3+
import at.petrak.hexcasting.api.addldata.ADIotaHolder
34
import at.petrak.hexcasting.xplat.IXplatAbstractions
5+
import net.minecraft.core.BlockPos
46
import net.minecraft.world.item.ItemStack
7+
import net.minecraft.world.level.Level
58

69
fun isIotaHolder(stack: ItemStack) = IXplatAbstractions.INSTANCE.findDataHolder(stack) != null
10+
11+
fun findDataHolder(world: Level, pos: BlockPos): ADIotaHolder? {
12+
return world.getBlockState(pos).block as? ADIotaHolder
13+
?: world.getBlockEntity(pos) as? ADIotaHolder
14+
}

0 commit comments

Comments
 (0)