Skip to content

Commit c176d21

Browse files
committed
Add patterns to manipulate spellbook page indices in the splicing table
1 parent 410e9f3 commit c176d21

File tree

14 files changed

+240
-17
lines changed

14 files changed

+240
-17
lines changed

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlockEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
4444
{
4545
override val stacks = BaseContainer.withSize(SplicingTableItemSlot.container_size)
4646

47-
private var listStack by SplicingTableItemSlot.LIST.delegate
48-
private var clipboardStack by SplicingTableItemSlot.CLIPBOARD.delegate
47+
var listStack by SplicingTableItemSlot.LIST.delegate
48+
var clipboardStack by SplicingTableItemSlot.CLIPBOARD.delegate
4949
private var mediaStack by SplicingTableItemSlot.MEDIA.delegate
5050
private var staffStack by SplicingTableItemSlot.STAFF.delegate
5151

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpReadClipboard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object OpReadClipboard : ConstMediaAction {
1111
override val argc = 1
1212

1313
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
14-
val pos = args.getBlockPos(0, OpReadSelection.argc)
14+
val pos = args.getBlockPos(0, argc)
1515
env.assertPosInRange(pos)
1616

1717
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gay.`object`.hexdebug.casting.actions.splicing
2+
3+
import at.petrak.hexcasting.api.casting.asActionResult
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.getBlockPos
7+
import at.petrak.hexcasting.api.casting.iota.Iota
8+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
9+
import at.petrak.hexcasting.common.items.storage.ItemSpellbook
10+
import at.petrak.hexcasting.common.lib.HexItems
11+
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
12+
13+
class OpReadSpellbookIndex(private val useListItem: Boolean) : ConstMediaAction {
14+
override val argc = 1
15+
16+
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
17+
val pos = args.getBlockPos(0, argc)
18+
env.assertPosInRange(pos)
19+
20+
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity
21+
?: throw MishapBadBlock.of(pos, "splicing_table")
22+
23+
val stack = if (useListItem) table.listStack else table.clipboardStack
24+
if (!stack.`is`(HexItems.SPELLBOOK) || ItemSpellbook.arePagesEmpty(stack)) {
25+
throw MishapBadBlock.of(pos, "splicing_table.${if (useListItem) "list" else "clipboard"}.spellbook")
26+
}
27+
28+
return ItemSpellbook.getPage(stack, 1).asActionResult
29+
}
30+
}

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpReadViewIndex.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object OpReadViewIndex : ConstMediaAction {
1212
override val argc = 1
1313

1414
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
15-
val pos = args.getBlockPos(0, OpReadSelection.argc)
15+
val pos = args.getBlockPos(0, argc)
1616
env.assertPosInRange(pos)
1717

1818
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpReadableClipboard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object OpReadableClipboard : ConstMediaAction {
1111
override val argc = 1
1212

1313
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
14-
val pos = args.getBlockPos(0, OpReadSelection.argc)
14+
val pos = args.getBlockPos(0, argc)
1515
env.assertPosInRange(pos)
1616

1717
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package gay.`object`.hexdebug.casting.actions.splicing
2+
3+
import at.petrak.hexcasting.api.casting.asActionResult
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.getBlockPos
7+
import at.petrak.hexcasting.api.casting.iota.Iota
8+
import at.petrak.hexcasting.common.items.storage.ItemSpellbook
9+
import at.petrak.hexcasting.common.lib.HexItems
10+
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
11+
12+
class OpReadableSpellbookIndex(private val useListItem: Boolean) : ConstMediaAction {
13+
override val argc = 1
14+
15+
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
16+
val pos = args.getBlockPos(0, argc)
17+
env.assertPosInRange(pos)
18+
19+
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity
20+
?: return false.asActionResult
21+
22+
val stack = if (useListItem) table.listStack else table.clipboardStack
23+
if (!stack.`is`(HexItems.SPELLBOOK) || ItemSpellbook.arePagesEmpty(stack)) {
24+
return false.asActionResult
25+
}
26+
27+
return true.asActionResult
28+
}
29+
}

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpWritableClipboard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object OpWritableClipboard : ConstMediaAction {
1111
override val argc = 1
1212

1313
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
14-
val pos = args.getBlockPos(0, OpReadSelection.argc)
14+
val pos = args.getBlockPos(0, argc)
1515
env.assertPosInRange(pos)
1616

1717
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpWriteClipboard.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object OpWriteClipboard : SpellAction {
1616
override val argc = 2
1717

1818
override fun execute(args: List<Iota>, env: CastingEnvironment): SpellAction.Result {
19-
val pos = args.getBlockPos(0, OpReadSelection.argc)
19+
val pos = args.getBlockPos(0, argc)
2020
val datum = args[1]
2121

2222
env.assertPosInRangeForEditing(pos)
@@ -36,15 +36,16 @@ object OpWriteClipboard : SpellAction {
3636
}
3737

3838
return SpellAction.Result(
39-
Spell(clipboardHolder, datum),
39+
Spell(table, clipboardHolder, datum),
4040
0,
4141
listOf(ParticleSpray(pos.center, Vec3(1.0, 0.0, 0.0), 0.25, 3.14, 40))
4242
)
4343
}
4444

45-
private data class Spell(val clipboardHolder: ADIotaHolder, val datum: Iota) : RenderedSpell {
45+
private data class Spell(val table: SplicingTableBlockEntity, val clipboardHolder: ADIotaHolder, val datum: Iota) : RenderedSpell {
4646
override fun cast(env: CastingEnvironment) {
4747
clipboardHolder.writeIota(datum, false)
48+
table.sync()
4849
}
4950
}
5051
}

Common/src/main/kotlin/gay/object/hexdebug/casting/actions/splicing/OpWriteSelection.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ object OpWriteSelection : SpellAction {
4646
private data class Spell(val table: SplicingTableBlockEntity, val selection: Selection?) : RenderedSpell {
4747
override fun cast(env: CastingEnvironment) {
4848
table.writeSelection(selection)
49+
table.sync()
4950
}
5051
}
5152
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package gay.`object`.hexdebug.casting.actions.splicing
2+
3+
import at.petrak.hexcasting.api.casting.ParticleSpray
4+
import at.petrak.hexcasting.api.casting.RenderedSpell
5+
import at.petrak.hexcasting.api.casting.castables.SpellAction
6+
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
7+
import at.petrak.hexcasting.api.casting.getBlockPos
8+
import at.petrak.hexcasting.api.casting.getIntBetween
9+
import at.petrak.hexcasting.api.casting.iota.Iota
10+
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
11+
import at.petrak.hexcasting.api.utils.getCompound
12+
import at.petrak.hexcasting.api.utils.getString
13+
import at.petrak.hexcasting.api.utils.putInt
14+
import at.petrak.hexcasting.common.items.storage.ItemSpellbook
15+
import at.petrak.hexcasting.common.lib.HexItems
16+
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
17+
import net.minecraft.network.chat.Component
18+
import net.minecraft.world.item.ItemStack
19+
import net.minecraft.world.phys.Vec3
20+
import kotlin.math.max
21+
22+
class OpWriteSpellbookIndex(private val useListItem: Boolean) : SpellAction {
23+
override val argc = 2
24+
25+
override fun execute(args: List<Iota>, env: CastingEnvironment): SpellAction.Result {
26+
val pos = args.getBlockPos(0, argc)
27+
val index = args.getIntBetween(idx=1, min=1, max=ItemSpellbook.MAX_PAGES, argc=argc)
28+
29+
env.assertPosInRangeForEditing(pos)
30+
31+
val table = env.world.getBlockEntity(pos) as? SplicingTableBlockEntity
32+
?: throw MishapBadBlock.of(pos, "splicing_table")
33+
34+
val stack = if (useListItem) table.listStack else table.clipboardStack
35+
if (!stack.`is`(HexItems.SPELLBOOK) || ItemSpellbook.arePagesEmpty(stack)) {
36+
throw MishapBadBlock.of(pos, "splicing_table.${if (useListItem) "list" else "clipboard"}.spellbook")
37+
}
38+
39+
return SpellAction.Result(
40+
Spell(table, stack, index),
41+
0,
42+
listOf(ParticleSpray(pos.center, Vec3(1.0, 0.0, 0.0), 0.25, 3.14, 40))
43+
)
44+
}
45+
46+
private data class Spell(val table: SplicingTableBlockEntity, val stack: ItemStack, val index: Int) : RenderedSpell {
47+
override fun cast(env: CastingEnvironment) {
48+
// copied from ItemSpellbook.rotatePageIdx with modifications
49+
stack.putInt(ItemSpellbook.TAG_SELECTED_PAGE, index)
50+
51+
val names = stack.getCompound(ItemSpellbook.TAG_PAGE_NAMES)
52+
val shiftedIndex = max(1, index)
53+
val nameKey = shiftedIndex.toString()
54+
val name = names.getString(nameKey)
55+
if (name != null) {
56+
stack.setHoverName(Component.Serializer.fromJson(name))
57+
} else {
58+
stack.resetHoverName()
59+
}
60+
61+
table.sync()
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)