Skip to content

Commit da11b6b

Browse files
committed
use failure over exception throwing
1 parent f71bfc3 commit da11b6b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/main/kotlin/com/lambda/interaction/material/container/containers/CreativeContainer.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
4949
listen<TickEvent.Pre> {
5050
if (!gamemode.isCreative) {
5151
// ToDo: Maybe switch gamemode?
52-
throw NotInCreativeModeException()
52+
failure(NotInCreativeModeException())
5353
}
5454

5555
inventoryRequest {
@@ -80,7 +80,7 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
8080

8181
if (!gamemode.isCreative) {
8282
// ToDo: Maybe switch gamemode?
83-
throw NotInCreativeModeException()
83+
failure(NotInCreativeModeException())
8484
}
8585

8686
inventoryRequest {
@@ -91,7 +91,7 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
9191
return@listen
9292
}
9393

94-
throw NoOptimalStackException()
94+
failure(IllegalStateException("Cannot move item: no optimal stack"))
9595
}
9696
}
9797
}
@@ -101,5 +101,4 @@ data object CreativeContainer : MaterialContainer(Rank.Creative) {
101101
override fun withdraw(selection: StackSelection) = CreativeWithdrawal(selection, automated)
102102

103103
class NotInCreativeModeException : IllegalStateException("Insufficient permission: not in creative mode")
104-
class NoOptimalStackException : IllegalStateException("Cannot move item: no optimal stack")
105104
}

src/main/kotlin/com/lambda/interaction/material/container/containers/MainHandContainer.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ object MainHandContainer : MaterialContainer(Rank.MainHand) {
6666
return@inventoryRequest
6767
}
6868

69-
val slot = player.currentScreenHandler.slots.firstOrNull { it.stack == moveStack } ?: throw NotInInventoryException()
69+
val slot = player.currentScreenHandler.slots.firstOrNull { it.stack == moveStack }
70+
?: run {
71+
failure(IllegalStateException("Cannot find stack in inventory"))
72+
return@inventoryRequest
73+
}
7074
swap(slot.id, player.inventory.selectedSlot)
7175

7276
if (hand == Hand.OFF_HAND) swapHands()
@@ -79,6 +83,4 @@ object MainHandContainer : MaterialContainer(Rank.MainHand) {
7983

8084
context(automated: Automated)
8185
override fun deposit(selection: StackSelection) = HandDeposit(selection, Hand.MAIN_HAND, automated)
82-
83-
class NotInInventoryException : IllegalStateException("Cannot find stack in inventory")
8486
}

0 commit comments

Comments
 (0)