Skip to content

Commit 3d94791

Browse files
committed
Allow spellbook page patterns to be used on focus holder
1 parent b90c210 commit 3d94791

File tree

5 files changed

+53
-38
lines changed

5 files changed

+53
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
2828
- A single Focal Frame item can now be used like a bundle to insert/remove items in your inventory ([#49](https://github.com/object-Object/HexDebug/issues/49)).
2929
- The Focal Frame now gives comparator output and can be broken by pushing it with a piston.
3030
- Splicing Table iota renderers are now cached to improve performance.
31+
- Projectionist's Purification, Projectionist's Gambit, and Shutter's Purification (but not the II variants) now work on Focal Frames in addition to Splicing Tables.
3132

3233
### Fixed
3334

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gay.`object`.hexdebug.casting.actions.splicing
22

3+
import at.petrak.hexcasting.api.block.HexBlockEntity
34
import at.petrak.hexcasting.api.casting.asActionResult
45
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
56
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
@@ -8,7 +9,10 @@ import at.petrak.hexcasting.api.casting.iota.Iota
89
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
910
import at.petrak.hexcasting.common.items.storage.ItemSpellbook
1011
import at.petrak.hexcasting.common.lib.HexItems
12+
import gay.`object`.hexdebug.blocks.focusholder.FocusHolderBlockEntity
1113
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
14+
import net.minecraft.core.BlockPos
15+
import net.minecraft.world.item.ItemStack
1216

1317
class OpReadSpellbookIndex(private val useListItem: Boolean) : ConstMediaAction {
1418
override val argc = 1
@@ -17,14 +21,36 @@ class OpReadSpellbookIndex(private val useListItem: Boolean) : ConstMediaAction
1721
val pos = args.getBlockPos(0, argc)
1822
env.assertPosInRange(pos)
1923

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-
}
24+
val (_, stack) = getSpellbook(env, pos, useListItem)
2725

2826
return ItemSpellbook.getPage(stack, 1).asActionResult
2927
}
28+
29+
companion object {
30+
fun getSpellbook(
31+
env: CastingEnvironment,
32+
pos: BlockPos,
33+
useListItem: Boolean,
34+
): Pair<HexBlockEntity, ItemStack> {
35+
val hexBlockEntity = env.world.getBlockEntity(pos) as? HexBlockEntity
36+
37+
val (stack, notSpellbookMishap) = when (hexBlockEntity) {
38+
is SplicingTableBlockEntity -> when (useListItem) {
39+
true -> hexBlockEntity.listStack to "splicing_table_or_focus_holder.spellbook"
40+
false -> hexBlockEntity.clipboardStack to "splicing_table.clipboard.spellbook"
41+
}
42+
is FocusHolderBlockEntity -> when (useListItem) {
43+
true -> hexBlockEntity.iotaStack to "splicing_table_or_focus_holder.spellbook"
44+
false -> throw MishapBadBlock.of(pos, "splicing_table")
45+
}
46+
else -> throw MishapBadBlock.of(pos, "splicing_table_or_focus_holder")
47+
}
48+
49+
if (!stack.`is`(HexItems.SPELLBOOK) || ItemSpellbook.arePagesEmpty(stack)) {
50+
throw MishapBadBlock.of(pos, notSpellbookMishap)
51+
}
52+
53+
return hexBlockEntity to stack
54+
}
55+
}
3056
}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
55
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
66
import at.petrak.hexcasting.api.casting.getBlockPos
77
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
8+
import at.petrak.hexcasting.api.casting.mishaps.Mishap
119

1210
class OpReadableSpellbookIndex(private val useListItem: Boolean) : ConstMediaAction {
1311
override val argc = 1
@@ -16,14 +14,11 @@ class OpReadableSpellbookIndex(private val useListItem: Boolean) : ConstMediaAct
1614
val pos = args.getBlockPos(0, argc)
1715
env.assertPosInRange(pos)
1816

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
17+
return try {
18+
OpReadSpellbookIndex.getSpellbook(env, pos, useListItem)
19+
true
20+
} catch (e: Mishap) {
21+
false
22+
}.asActionResult
2823
}
2924
}

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package gay.`object`.hexdebug.casting.actions.splicing
22

3+
import at.petrak.hexcasting.api.block.HexBlockEntity
34
import at.petrak.hexcasting.api.casting.ParticleSpray
45
import at.petrak.hexcasting.api.casting.RenderedSpell
56
import at.petrak.hexcasting.api.casting.castables.SpellAction
67
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
78
import at.petrak.hexcasting.api.casting.getBlockPos
89
import at.petrak.hexcasting.api.casting.getIntBetween
910
import at.petrak.hexcasting.api.casting.iota.Iota
10-
import at.petrak.hexcasting.api.casting.mishaps.MishapBadBlock
1111
import at.petrak.hexcasting.api.utils.getCompound
1212
import at.petrak.hexcasting.api.utils.getString
1313
import at.petrak.hexcasting.api.utils.putInt
1414
import at.petrak.hexcasting.common.items.storage.ItemSpellbook
15-
import at.petrak.hexcasting.common.lib.HexItems
16-
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
1715
import net.minecraft.network.chat.Component
1816
import net.minecraft.world.item.ItemStack
1917
import net.minecraft.world.phys.Vec3
@@ -28,22 +26,16 @@ class OpWriteSpellbookIndex(private val useListItem: Boolean) : SpellAction {
2826

2927
env.assertPosInRangeForEditing(pos)
3028

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-
}
29+
val (blockEntity, stack) = OpReadSpellbookIndex.getSpellbook(env, pos, useListItem)
3830

3931
return SpellAction.Result(
40-
Spell(table, stack, index),
32+
Spell(blockEntity, stack, index),
4133
0,
4234
listOf(ParticleSpray(pos.center, Vec3(1.0, 0.0, 0.0), 0.25, 3.14, 40))
4335
)
4436
}
4537

46-
private data class Spell(val table: SplicingTableBlockEntity, val stack: ItemStack, val index: Int) : RenderedSpell {
38+
private data class Spell(val blockEntity: HexBlockEntity, val stack: ItemStack, val index: Int) : RenderedSpell {
4739
override fun cast(env: CastingEnvironment) {
4840
// copied from ItemSpellbook.rotatePageIdx with modifications
4941
stack.putInt(ItemSpellbook.TAG_SELECTED_PAGE, index)
@@ -58,7 +50,7 @@ class OpWriteSpellbookIndex(private val useListItem: Boolean) : SpellAction {
5850
stack.resetHoverName()
5951
}
6052

61-
table.sync()
53+
blockEntity.sync()
6254
}
6355
}
6456
}

Common/src/main/resources/assets/hexdebug/lang/en_us.flatten.json5

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,16 @@
229229
splicing_table: {
230230
"": "a Splicing Table",
231231
enlightened: "a Mindsplice Table",
232-
list: {
233-
spellbook: "a Splicing Table with a non-empty spellbook in the main item slot",
234-
},
235232
clipboard: {
236233
read: "a Splicing Table with a readable secondary item",
237234
write: "a Splicing Table with a writable secondary item",
238235
spellbook: "a Splicing Table with a non-empty spellbook in the secondary item slot",
239236
},
240237
},
238+
splicing_table_or_focus_holder: {
239+
"": "a Splicing Table or Focal Frame",
240+
spellbook: "a Splicing Table or Focal Frame with a non-empty spellbook in the main item slot",
241+
},
241242
},
242243
invalid_value: {
243244
int: {
@@ -380,9 +381,9 @@
380381
},
381382
"list/": {
382383
"spellbook_index/": {
383-
read: "Remove a vector from the stack, then push the current page number (starting at 1) of the $(l:items/spellbook)$(item)Spellbook/$ in the main slot of the $(l:items/splicing_table)$(item)Splicing Table/$ at that position.",
384-
write: "Remove a vector and number from the stack, then flip the $(l:items/spellbook)$(item)Spellbook/$ in the main slot of the $(l:items/splicing_table)$(item)Splicing Table/$ at that position to the given page number.",
385-
readable: "Replace the vector at the top of the stack with $(thing)True/$ if there is a $(l:items/splicing_table)$(item)Splicing Table/$ at that position with a $(l:items/spellbook)$(item)Spellbook/$ in its main slot that contains at least one page, or $(thing)False/$ otherwise.",
384+
read: "Remove a vector from the stack, then push the current page number (starting at 1) of the $(l:items/spellbook)$(item)Spellbook/$ in the main slot of the $(l:items/splicing_table)$(item)Splicing Table/$ or $(l:items/focus_holder)$(item)Focal Frame/$ at that position.",
385+
write: "Remove a vector and number from the stack, then flip the $(l:items/spellbook)$(item)Spellbook/$ in the main slot of the $(l:items/splicing_table)$(item)Splicing Table/$ or $(l:items/focus_holder)$(item)Focal Frame/$ at that position to the given page number.",
386+
readable: "Replace the vector at the top of the stack with $(thing)True/$ if there is a $(l:items/splicing_table)$(item)Splicing Table/$ or $(l:items/focus_holder)$(item)Focal Frame/$ at that position with a $(l:items/spellbook)$(item)Spellbook/$ in its main slot that contains at least one page, or $(thing)False/$ otherwise.",
386387
},
387388
},
388389
"clipboard/": {

0 commit comments

Comments
 (0)