Skip to content

Commit

Permalink
refactor: cleanup CreativeItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 2, 2024
1 parent 7cfd0bd commit 33bae28
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/kotlin/com/mineinabyss/guiy/components/CreativeItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ fun CreativeItem(
) {
Item(itemStack, modifier.clickable {
// Mimic all vanilla interactions
val shiftClick = clickType == ClickType.SHIFT_LEFT || clickType == ClickType.SHIFT_RIGHT
val result: ItemStack? = when {
(shiftClick || clickType == ClickType.MIDDLE) && cursor == null -> itemStack?.clone()
?.apply { amount = maxStackSize }
(clickType.isShiftClick || clickType == ClickType.MIDDLE) && cursor == null ->
itemStack?.asQuantity(itemStack.maxStackSize)

clickType == ClickType.MIDDLE -> return@clickable

(clickType == ClickType.SHIFT_LEFT && cursor != null && cursor.isSimilar(itemStack)) ->
cursor.clone().apply { amount = maxStackSize }
clickType == ClickType.SHIFT_LEFT && cursor != null && cursor.isSimilar(itemStack) ->
cursor.asQuantity(cursor.maxStackSize)

cursor == null -> itemStack?.clone()?.apply { amount = 1 }
cursor == null -> itemStack?.clone()?.asOne()

clickType == ClickType.RIGHT || clickType == ClickType.SHIFT_RIGHT -> cursor.clone().subtract()
clickType.isRightClick -> cursor.clone().subtract()

(clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) && !cursor.isSimilar(itemStack) -> null
clickType.isLeftClick && !cursor.isSimilar(itemStack) -> null

else -> cursor.clone().add()
}
Expand Down

0 comments on commit 33bae28

Please sign in to comment.