Skip to content

Commit 8d1d724

Browse files
committed
Implement canPlaceItem and similar methods, add focus holder blacklist tag, refactor tag datagen (fix #38, fix #53)
1 parent 6b1d298 commit 8d1d724

File tree

19 files changed

+149
-59
lines changed

19 files changed

+149
-59
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Pydantic's HISTORY.md](https://github.com/pydantic/pydantic/blob/main/HISTORY.md), and this project *mostly* adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [UNRELEASED]
8+
9+
### Added
10+
11+
- Added a tag (`hexdebug:focus_holder/blacklist`) to prevent specific items from being inserted into the Focal Frame.
12+
13+
### Fixed
14+
15+
- Fixed a few bugs allowing arbitrary items to be inserted into the Splicing Table and Focal Frame using hoppers or modded item transportation ([#38](https://github.com/object-Object/HexDebug/issues/38), [#53](https://github.com/object-Object/HexDebug/issues/38)).
16+
717
## `0.6.0+1.20.1` - 2025-09-29
818

919
### Added

Common/src/main/java/gay/object/hexdebug/api/HexDebugTags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
@SuppressWarnings("SameParameterValue")
99
public final class HexDebugTags {
1010
public static final class Items {
11+
public static final TagKey<Item> FOCUS_HOLDER_BLACKLIST = create("focus_holder/blacklist");
12+
1113
public static final TagKey<Item> SPLICING_TABLE_MEDIA_BLACKLIST = create("splicing_table/media_blacklist");
1214

1315
private static TagKey<Item> create(String name) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package gay.`object`.hexdebug.blocks.focusholder
22

3-
import at.petrak.hexcasting.xplat.IXplatAbstractions
4-
import gay.`object`.hexdebug.registry.HexDebugBlocks
53
import gay.`object`.hexdebug.utils.isNotEmpty
64
import net.minecraft.core.BlockPos
75
import net.minecraft.world.InteractionHand
@@ -66,7 +64,7 @@ class FocusHolderBlock(properties: Properties) : BaseEntityBlock(properties) {
6664
return InteractionResult.sidedSuccess(level.isClientSide)
6765
}
6866

69-
return if (isValidItem(heldItem)) {
67+
return if (FocusHolderBlockEntity.isValidItem(heldItem)) {
7068
// main hand has valid item, swap with stored
7169
swapItem()
7270
} else if (heldItem.isNotEmpty) {
@@ -125,10 +123,6 @@ class FocusHolderBlock(properties: Properties) : BaseEntityBlock(properties) {
125123
val HAS_ITEM: BooleanProperty = BooleanProperty.create("has_item")
126124

127125
fun getBlockEntity(level: BlockGetter, pos: BlockPos) = level.getBlockEntity(pos) as? FocusHolderBlockEntity
128-
129-
private fun isValidItem(stack: ItemStack) =
130-
IXplatAbstractions.INSTANCE.findDataHolder(stack) != null
131-
&& !stack.`is`(HexDebugBlocks.FOCUS_HOLDER.item) // TODO: use a tag instead?
132126
}
133127
}
134128

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import at.petrak.hexcasting.api.addldata.ADIotaHolder
44
import at.petrak.hexcasting.api.block.HexBlockEntity
55
import at.petrak.hexcasting.api.casting.iota.Iota
66
import at.petrak.hexcasting.xplat.IXplatAbstractions
7+
import gay.`object`.hexdebug.api.HexDebugTags
78
import gay.`object`.hexdebug.blocks.base.BaseContainer
89
import gay.`object`.hexdebug.blocks.base.ContainerSlotDelegate
910
import gay.`object`.hexdebug.registry.HexDebugBlockEntities
11+
import gay.`object`.hexdebug.utils.isIotaHolder
1012
import gay.`object`.hexdebug.utils.isNotEmpty
1113
import gay.`object`.hexdebug.utils.setPropertyIfChanged
1214
import net.minecraft.core.BlockPos
1315
import net.minecraft.nbt.CompoundTag
1416
import net.minecraft.world.ContainerHelper
17+
import net.minecraft.world.item.ItemStack
1518
import net.minecraft.world.level.block.state.BlockState
1619

1720
class FocusHolderBlockEntity(pos: BlockPos, state: BlockState) :
@@ -49,4 +52,11 @@ class FocusHolderBlockEntity(pos: BlockPos, state: BlockState) :
4952
super.setChanged()
5053
setPropertyIfChanged(FocusHolderBlock.HAS_ITEM, isNotEmpty)
5154
}
55+
56+
override fun canPlaceItem(index: Int, stack: ItemStack): Boolean = isValidItem(stack)
57+
58+
companion object {
59+
fun isValidItem(stack: ItemStack): Boolean =
60+
isIotaHolder(stack) && !stack.`is`(HexDebugTags.Items.FOCUS_HOLDER_BLACKLIST)
61+
}
5262
}

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import at.petrak.hexcasting.api.casting.iota.IotaType
1313
import at.petrak.hexcasting.api.casting.iota.ListIota
1414
import at.petrak.hexcasting.api.casting.iota.PatternIota
1515
import at.petrak.hexcasting.api.casting.math.HexPattern
16+
import at.petrak.hexcasting.api.mod.HexTags
1617
import at.petrak.hexcasting.api.pigment.FrozenPigment
1718
import at.petrak.hexcasting.api.utils.*
1819
import at.petrak.hexcasting.xplat.IXplatAbstractions
@@ -30,9 +31,11 @@ import gay.`object`.hexdebug.registry.HexDebugBlockEntities
3031
import gay.`object`.hexdebug.splicing.*
3132
import gay.`object`.hexdebug.utils.Option.None
3233
import gay.`object`.hexdebug.utils.Option.Some
34+
import gay.`object`.hexdebug.utils.isIotaHolder
3335
import gay.`object`.hexdebug.utils.setPropertyIfChanged
3436
import gay.`object`.hexdebug.utils.sigsEqual
3537
import net.minecraft.core.BlockPos
38+
import net.minecraft.core.Direction
3639
import net.minecraft.nbt.CompoundTag
3740
import net.minecraft.nbt.ListTag
3841
import net.minecraft.network.chat.Component
@@ -41,6 +44,7 @@ import net.minecraft.server.level.ServerPlayer
4144
import net.minecraft.world.ContainerHelper
4245
import net.minecraft.world.MenuProvider
4346
import net.minecraft.world.Nameable
47+
import net.minecraft.world.WorldlyContainer
4448
import net.minecraft.world.entity.player.Inventory
4549
import net.minecraft.world.entity.player.Player
4650
import net.minecraft.world.inventory.SimpleContainerData
@@ -53,7 +57,7 @@ import kotlin.math.min
5357

5458
class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
5559
HexBlockEntity(HexDebugBlockEntities.SPLICING_TABLE.value, pos, state),
56-
ISplicingTable, BaseContainer, MenuProvider, Nameable, ADIotaHolder, ADMediaHolder
60+
ISplicingTable, BaseContainer, WorldlyContainer, MenuProvider, Nameable, ADIotaHolder, ADMediaHolder
5761
{
5862
override val stacks = BaseContainer.withSize(SplicingTableItemSlot.container_size)
5963

@@ -170,6 +174,38 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
170174
customNameInner = value
171175
}
172176

177+
// Container
178+
179+
override fun canPlaceItem(index: Int, stack: ItemStack): Boolean {
180+
return when (index) {
181+
SplicingTableItemSlot.LIST.index -> isValidList(stack)
182+
SplicingTableItemSlot.CLIPBOARD.index -> isValidClipboard(stack)
183+
SplicingTableItemSlot.MEDIA.index -> isValidMedia(stack)
184+
SplicingTableItemSlot.STAFF.index -> isValidStaff(stack)
185+
else -> true
186+
}
187+
}
188+
189+
// WorldlyContainer
190+
191+
override fun getSlotsForFace(side: Direction): IntArray {
192+
return when (side) {
193+
Direction.UP, Direction.DOWN -> intArrayOf(
194+
SplicingTableItemSlot.LIST.index,
195+
SplicingTableItemSlot.CLIPBOARD.index,
196+
)
197+
else -> intArrayOf(
198+
SplicingTableItemSlot.MEDIA.index,
199+
)
200+
}
201+
}
202+
203+
override fun canPlaceItemThroughFace(index: Int, stack: ItemStack, side: Direction?): Boolean =
204+
canPlaceItem(index, stack) && (side == null || index in getSlotsForFace(side))
205+
206+
override fun canTakeItemThroughFace(index: Int, stack: ItemStack, side: Direction): Boolean =
207+
index in getSlotsForFace(side)
208+
173209
// more BE stuff
174210

175211
override fun setChanged() {
@@ -525,5 +561,14 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) :
525561
blockEntity.castingCooldown -= 1
526562
}
527563
}
564+
565+
fun isValidList(stack: ItemStack): Boolean = isIotaHolder(stack)
566+
567+
fun isValidClipboard(stack: ItemStack): Boolean = isIotaHolder(stack)
568+
569+
fun isValidMedia(stack: ItemStack): Boolean =
570+
isMediaItem(stack) && !stack.`is`(HexDebugTags.Items.SPLICING_TABLE_MEDIA_BLACKLIST)
571+
572+
fun isValidStaff(stack: ItemStack): Boolean = stack.`is`(HexTags.Items.STAVES)
528573
}
529574
}

Common/src/main/kotlin/gay/object/hexdebug/datagen/HexDebugActionTags.kt renamed to Common/src/main/kotlin/gay/object/hexdebug/datagen/tags/HexDebugActionTags.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gay.`object`.hexdebug.datagen
1+
package gay.`object`.hexdebug.datagen.tags
22

33
import at.petrak.hexcasting.api.casting.ActionRegistryEntry
44
import at.petrak.hexcasting.api.mod.HexTags
@@ -14,11 +14,9 @@ class HexDebugActionTags(output: PackOutput, provider: CompletableFuture<HolderL
1414
{
1515
override fun addTags(provider: HolderLookup.Provider) {
1616
// regular pattern, but requires enlightenment
17-
for (entry in arrayOf(
18-
HexDebugActions.READ_ENLIGHTENED_HEX,
19-
HexDebugActions.WRITE_ENLIGHTENED_HEX,
20-
)) {
21-
tag(HexTags.Actions.REQUIRES_ENLIGHTENMENT).add(entry.key)
22-
}
17+
tag(HexTags.Actions.REQUIRES_ENLIGHTENMENT).add(
18+
HexDebugActions.READ_ENLIGHTENED_HEX.key,
19+
HexDebugActions.WRITE_ENLIGHTENED_HEX.key,
20+
)
2321
}
2422
}

Forge/src/main/kotlin/gay/object/hexdebug/forge/datagen/HexDebugBlockTags.kt renamed to Common/src/main/kotlin/gay/object/hexdebug/datagen/tags/HexDebugBlockTags.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
package gay.`object`.hexdebug.forge.datagen
1+
package gay.`object`.hexdebug.datagen.tags
22

3-
import gay.`object`.hexdebug.HexDebug
43
import gay.`object`.hexdebug.registry.HexDebugBlocks
54
import net.minecraft.core.HolderLookup
65
import net.minecraft.core.registries.Registries
76
import net.minecraft.data.PackOutput
87
import net.minecraft.data.tags.TagsProvider
98
import net.minecraft.tags.BlockTags
109
import net.minecraft.world.level.block.Block
11-
import net.minecraftforge.common.data.ExistingFileHelper
1210
import java.util.concurrent.CompletableFuture
1311

14-
class HexDebugBlockTags(
15-
output: PackOutput,
16-
registries: CompletableFuture<HolderLookup.Provider>,
17-
efh: ExistingFileHelper,
18-
) : TagsProvider<Block>(output, Registries.BLOCK, registries, HexDebug.MODID, efh) {
12+
class HexDebugBlockTags(output: PackOutput, provider: CompletableFuture<HolderLookup.Provider>)
13+
: TagsProvider<Block>(output, Registries.BLOCK, provider)
14+
{
1915
override fun addTags(provider: HolderLookup.Provider) {
2016
tag(BlockTags.MINEABLE_WITH_PICKAXE).add(
2117
HexDebugBlocks.SPLICING_TABLE.key,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package gay.`object`.hexdebug.datagen.tags
2+
3+
import at.petrak.hexcasting.api.mod.HexTags
4+
import gay.`object`.hexdebug.api.HexDebugTags
5+
import gay.`object`.hexdebug.registry.HexDebugBlocks
6+
import gay.`object`.hexdebug.registry.HexDebugItems
7+
import net.minecraft.core.HolderLookup
8+
import net.minecraft.core.registries.Registries
9+
import net.minecraft.data.PackOutput
10+
import net.minecraft.data.tags.TagsProvider
11+
import net.minecraft.world.item.Item
12+
import java.util.concurrent.CompletableFuture
13+
14+
class HexDebugItemTags(output: PackOutput, provider: CompletableFuture<HolderLookup.Provider>)
15+
: TagsProvider<Item>(output, Registries.ITEM, provider)
16+
{
17+
override fun addTags(provider: HolderLookup.Provider) {
18+
tag(HexDebugTags.Items.FOCUS_HOLDER_BLACKLIST).add(
19+
HexDebugBlocks.FOCUS_HOLDER.itemKey,
20+
)
21+
22+
tag(HexTags.Items.STAVES).add(
23+
HexDebugItems.EVALUATOR.key,
24+
)
25+
}
26+
}

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableMenu.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package gay.`object`.hexdebug.gui.splicing
22

3-
import at.petrak.hexcasting.api.mod.HexTags
4-
import at.petrak.hexcasting.api.utils.isMediaItem
5-
import gay.`object`.hexdebug.api.HexDebugTags
63
import gay.`object`.hexdebug.blocks.base.ContainerDataDelegate
74
import gay.`object`.hexdebug.blocks.base.ContainerDataLongDelegate
85
import gay.`object`.hexdebug.blocks.base.ContainerDataSelectionDelegate
96
import gay.`object`.hexdebug.blocks.splicing.ClientSplicingTableContainer
7+
import gay.`object`.hexdebug.blocks.splicing.SplicingTableBlockEntity
108
import gay.`object`.hexdebug.blocks.splicing.SplicingTableDataSlot
119
import gay.`object`.hexdebug.blocks.splicing.SplicingTableItemSlot
1210
import gay.`object`.hexdebug.gui.BaseContainerMenu
@@ -16,7 +14,6 @@ import gay.`object`.hexdebug.networking.msg.MsgSplicingTableNewDataS2C
1614
import gay.`object`.hexdebug.registry.HexDebugMenus
1715
import gay.`object`.hexdebug.splicing.ISplicingTable
1816
import gay.`object`.hexdebug.splicing.SplicingTableClientView
19-
import gay.`object`.hexdebug.utils.isIotaHolder
2017
import net.minecraft.server.level.ServerPlayer
2118
import net.minecraft.world.entity.player.Inventory
2219
import net.minecraft.world.entity.player.Player
@@ -75,17 +72,17 @@ class SplicingTableMenu(
7572

7673
// table
7774
addTableSlot(SplicingTableItemSlot.LIST, 88, 68) {
78-
mayPlace = ::isIotaHolder
75+
mayPlace = SplicingTableBlockEntity.Companion::isValidList
7976
}
8077
addTableSlot(SplicingTableItemSlot.CLIPBOARD, 7, 68) {
81-
mayPlace = ::isIotaHolder
78+
mayPlace = SplicingTableBlockEntity.Companion::isValidClipboard
8279
}
8380
mediaSlot = addTableSlot(SplicingTableItemSlot.MEDIA, 205, 169) {
84-
mayPlace = { isMediaItem(it) && !it.`is`(HexDebugTags.Items.SPLICING_TABLE_MEDIA_BLACKLIST) }
81+
mayPlace = SplicingTableBlockEntity.Companion::isValidMedia
8582
}
8683
staffSlot = addTableSlot(SplicingTableItemSlot.STAFF, -20, 169) {
8784
maxStackSize = 1
88-
mayPlace = { it.`is`(HexTags.Items.STAVES) }
85+
mayPlace = SplicingTableBlockEntity.Companion::isValidStaff
8986
}
9087
for ((index, x, y) in SplicingTableItemSlot.STORAGE) {
9188
addTableSlot(index, 196 + x * 18, 111 + y * 18)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ object HexDebugBlocks : HexDebugRegistrar<Block>(Registries.BLOCK, { BuiltInRegi
5454
) : Entry<B>(blockEntry) {
5555
val block by ::value
5656
val item by itemEntry::value
57+
val itemKey by itemEntry::key
5758
}
5859
}

0 commit comments

Comments
 (0)