Skip to content

Commit 8cfaba4

Browse files
committed
Implement bundle-style interaction for focus holder item (close #49)
1 parent fbb0de4 commit 8cfaba4

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
2323
- ⚠️ Breaking: The `hexdebug:list` renderer type now has a required field `renderer` to render the iota; the list renderer now only provides the tooltip.
2424
- List iotas now render their first iota (if any) in the Splicing Table.
2525
- MoreIotas' item type iotas now render brackets around the item to distinguish them from item stack iotas.
26+
- A single Focal Frame item can now be used like a bundle to insert/remove items in your inventory.
2627

2728
### Fixed
2829

Common/src/main/kotlin/gay/object/hexdebug/items/FocusHolderBlockItem.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ import at.petrak.hexcasting.api.utils.asTranslatedComponent
66
import at.petrak.hexcasting.api.utils.getList
77
import at.petrak.hexcasting.common.lib.HexItems
88
import gay.`object`.hexdebug.HexDebug
9+
import gay.`object`.hexdebug.blocks.focusholder.FocusHolderBlockEntity
910
import gay.`object`.hexdebug.items.base.ItemPredicateProvider
1011
import gay.`object`.hexdebug.items.base.ModelPredicateEntry
1112
import gay.`object`.hexdebug.registry.HexDebugBlockEntities
1213
import gay.`object`.hexdebug.registry.HexDebugBlocks
1314
import gay.`object`.hexdebug.utils.asItemPredicate
15+
import gay.`object`.hexdebug.utils.isNotEmpty
1416
import gay.`object`.hexdebug.utils.styledHoverName
1517
import net.minecraft.core.NonNullList
1618
import net.minecraft.nbt.CompoundTag
1719
import net.minecraft.nbt.Tag
1820
import net.minecraft.network.chat.Component
1921
import net.minecraft.world.ContainerHelper
22+
import net.minecraft.world.entity.SlotAccess
23+
import net.minecraft.world.entity.player.Player
24+
import net.minecraft.world.inventory.ClickAction
25+
import net.minecraft.world.inventory.Slot
2026
import net.minecraft.world.item.BlockItem
2127
import net.minecraft.world.item.ItemStack
2228
import net.minecraft.world.item.TooltipFlag
@@ -68,6 +74,53 @@ class FocusHolderBlockItem(block: Block, properties: Properties) :
6874
},
6975
)
7076

77+
// bundle behaviour
78+
79+
override fun overrideStackedOnOther(stack: ItemStack, slot: Slot, action: ClickAction, player: Player): Boolean {
80+
val other = slot.item
81+
if (action != ClickAction.SECONDARY || stack.count != 1 || other.count > 1) return false
82+
83+
if (other.isEmpty) {
84+
val (iotaStack, _) = stack.getIotaStack()
85+
if (iotaStack.isNotEmpty) {
86+
stack.setIotaStack(slot.safeInsert(iotaStack))
87+
}
88+
} else if (FocusHolderBlockEntity.isValidItem(other) && !stack.hasIotaStack) {
89+
stack.setIotaStack(slot.safeTake(1, 1, player))
90+
}
91+
92+
return true
93+
}
94+
95+
override fun overrideOtherStackedOnMe(
96+
stack: ItemStack,
97+
other: ItemStack,
98+
slot: Slot,
99+
action: ClickAction,
100+
player: Player,
101+
access: SlotAccess
102+
): Boolean {
103+
if (
104+
action != ClickAction.SECONDARY
105+
|| stack.count != 1
106+
|| other.count > 1
107+
|| !slot.allowModification(player)
108+
) return false
109+
110+
if (other.isEmpty) {
111+
val (iotaStack, _) = stack.getIotaStack()
112+
if (iotaStack.isNotEmpty) {
113+
access.set(iotaStack)
114+
stack.setIotaStack(ItemStack.EMPTY)
115+
}
116+
} else if (FocusHolderBlockEntity.isValidItem(other) && !stack.hasIotaStack) {
117+
stack.setIotaStack(other)
118+
other.shrink(1)
119+
}
120+
121+
return true
122+
}
123+
71124
companion object {
72125
val HAS_ITEM = HexDebug.id("has_item")
73126

0 commit comments

Comments
 (0)