Skip to content

Commit

Permalink
hi guys
Browse files Browse the repository at this point in the history
  • Loading branch information
martimavocado committed Dec 13, 2024
1 parent bd58e6d commit b552d71
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
class ReplaceItemEvent(val inventory: IInventory, val originalItem: ItemStack, val slot: Int) : SkyHanniEvent() {
var replacement: ItemStack? = null
private set
var shouldRemove = false
private set

fun replace(replacement: ItemStack?) {
fun replace(replacement: ItemStack) {
this.replacement = replacement
}

fun remove() {
shouldRemove = true
}

companion object {
@JvmStatic
fun postEvent(
Expand All @@ -25,6 +31,10 @@ class ReplaceItemEvent(val inventory: IInventory, val originalItem: ItemStack, v
val originalItem = inventoryContents.getOrNull(slot) ?: return
val event = ReplaceItemEvent(inventory, originalItem, slot)
event.post()
if (event.shouldRemove) {
cir.returnValue = null
return
}
event.replacement?.let { cir.returnValue = it }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object GardenPlotIcon {
lastClickedSlotId = -1
return
}
event.replace(cachedStack[event.slot])
event.replace(cachedStack[event.slot] ?: return)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ object CarnivalShopHelper {

private fun tryReplaceShopSpecificStack(event: ReplaceItemEvent) {
if (currentProgress == null || event.isUnknownShop()) return
shopSpecificInfoItemStack.let { event.replace(it) }
event.replace(shopSpecificInfoItemStack ?: return)
}

private fun tryReplaceOverviewStack(event: ReplaceItemEvent) {
if (!overviewInventoryNamesPattern.matches(event.inventory.name)) return
overviewInfoItemStack.let { event.replace(it) }
event.replace(overviewInfoItemStack ?: return)
}

@HandleEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object EssenceShopHelper {
fun replaceItem(event: ReplaceItemEvent) {
if (!isEnabled() || essenceShops.isEmpty() || currentProgress == null || event.slot != CUSTOM_STACK_LOCATION) return
if (!essenceShopPattern.matches(event.inventory.name)) return
infoItemStack.let { event.replace(it) }
event.replace(infoItemStack ?: return)
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object UserLuckBreakdown {
10 -> event.replace(skillsItem)
11 -> event.replace(limboItem)

in validItemSlots -> event.replace(null)
in validItemSlots -> event.remove()

in invalidItemSlots -> {
if (event.originalItem.item == limboID.getItemStack().item) return
Expand Down

0 comments on commit b552d71

Please sign in to comment.