aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/inventory
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-07 21:11:09 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-07 21:11:09 +0200
commit93e6e0ab16df0808ee7720202a32967eddcf5c10 (patch)
tree0939d44ec0c848f8712df8b03f30af1d34eabfa0 /src/main/kotlin/moe/nea/firmament/features/inventory
parent8f3cc34740fcfe1572d23c8f1c1db1a309217b84 (diff)
downloadfirmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.tar.gz
firmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.tar.bz2
firmament-93e6e0ab16df0808ee7720202a32967eddcf5c10.zip
Fix up most of the remaining event handlers
[no changelog]
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/inventory')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/CraftingOverlay.kt62
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt25
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt5
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SaveCursorPosition.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt143
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt56
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt51
7 files changed, 180 insertions, 166 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/CraftingOverlay.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/CraftingOverlay.kt
index e7f821d..866d1cc 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/CraftingOverlay.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/CraftingOverlay.kt
@@ -9,11 +9,12 @@ package moe.nea.firmament.features.inventory
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
import net.minecraft.item.ItemStack
import net.minecraft.util.Formatting
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.SlotRenderEvents
import moe.nea.firmament.features.FirmamentFeature
-import moe.nea.firmament.rei.recipes.SBCraftingRecipe
import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry
import moe.nea.firmament.rei.SBItemEntryDefinition
+import moe.nea.firmament.rei.recipes.SBCraftingRecipe
import moe.nea.firmament.util.MC
object CraftingOverlay : FirmamentFeature {
@@ -35,36 +36,35 @@ object CraftingOverlay : FirmamentFeature {
override val identifier: String
get() = "crafting-overlay"
- override fun onLoad() {
- SlotRenderEvents.After.subscribe { event ->
- val slot = event.slot
- val recipe = this.recipe ?: return@subscribe
- if (slot.inventory != screen?.screenHandler?.inventory) return@subscribe
- val recipeIndex = craftingOverlayIndices.indexOf(slot.index)
- if (recipeIndex < 0) return@subscribe
- val expectedItem = recipe.neuRecipe.inputs[recipeIndex]
- val actualStack = slot.stack ?: ItemStack.EMPTY!!
- val actualEntry = SBItemEntryDefinition.getEntry(actualStack).value
- if ((actualEntry.skyblockId.neuItem != expectedItem.itemId || actualEntry.stackSize < expectedItem.amount) && expectedItem.amount.toInt() != 0) {
- event.context.fill(
- event.slot.x,
- event.slot.y,
- event.slot.x + 16,
- event.slot.y + 16,
- 0x80FF0000.toInt()
- )
- }
- if (!slot.hasStack()) {
- val itemStack = SBItemEntryDefinition.getEntry(expectedItem).asItemEntry().value
- event.context.drawItem(itemStack, event.slot.x, event.slot.y)
- event.context.drawItemInSlot(
- MC.font,
- itemStack,
- event.slot.x,
- event.slot.y,
- "${Formatting.RED}${expectedItem.amount.toInt()}"
- )
- }
+ @Subscribe
+ fun onSlotRender(event: SlotRenderEvents.After) {
+ val slot = event.slot
+ val recipe = this.recipe ?: return
+ if (slot.inventory != screen?.screenHandler?.inventory) return
+ val recipeIndex = craftingOverlayIndices.indexOf(slot.index)
+ if (recipeIndex < 0) return
+ val expectedItem = recipe.neuRecipe.inputs[recipeIndex]
+ val actualStack = slot.stack ?: ItemStack.EMPTY!!
+ val actualEntry = SBItemEntryDefinition.getEntry(actualStack).value
+ if ((actualEntry.skyblockId.neuItem != expectedItem.itemId || actualEntry.stackSize < expectedItem.amount) && expectedItem.amount.toInt() != 0) {
+ event.context.fill(
+ event.slot.x,
+ event.slot.y,
+ event.slot.x + 16,
+ event.slot.y + 16,
+ 0x80FF0000.toInt()
+ )
+ }
+ if (!slot.hasStack()) {
+ val itemStack = SBItemEntryDefinition.getEntry(expectedItem).asItemEntry().value
+ event.context.drawItem(itemStack, event.slot.x, event.slot.y)
+ event.context.drawItemInSlot(
+ MC.font,
+ itemStack,
+ event.slot.x,
+ event.slot.y,
+ "${Formatting.RED}${expectedItem.amount.toInt()}"
+ )
}
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
index ac53546..dde0ddb 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt
@@ -12,6 +12,7 @@ import net.minecraft.client.gui.DrawContext
import net.minecraft.item.ItemStack
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HotbarItemRenderEvent
import moe.nea.firmament.events.SlotRenderEvents
import moe.nea.firmament.features.FirmamentFeature
@@ -65,16 +66,18 @@ object ItemRarityCosmetics : FirmamentFeature {
)
}
- override fun onLoad() {
- HotbarItemRenderEvent.subscribe {
- if (!TConfig.showItemRarityInHotbar) return@subscribe
- val stack = it.item
- drawItemStackRarity(it.context, it.x, it.y, stack)
- }
- SlotRenderEvents.Before.subscribe {
- if (!TConfig.showItemRarityBackground) return@subscribe
- val stack = it.slot.stack ?: return@subscribe
- drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack)
- }
+
+ @Subscribe
+ fun onRenderSlot(it: SlotRenderEvents.Before) {
+ if (!TConfig.showItemRarityBackground) return
+ val stack = it.slot.stack ?: return
+ drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack)
+ }
+
+ @Subscribe
+ fun onRenderHotbarItem(it: HotbarItemRenderEvent) {
+ if (!TConfig.showItemRarityInHotbar) return
+ val stack = it.item
+ drawItemStackRarity(it.context, it.x, it.y, stack)
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
index b511611..fb99c7c 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt
@@ -27,11 +27,8 @@ object PriceData : FirmamentFeature {
override val config get() = TConfig
- override fun onLoad() {
- }
-
@Subscribe
- fun function(it: ItemTooltipEvent) {
+ fun onItemTooltip(it: ItemTooltipEvent) {
if (!TConfig.tooltipEnabled && !TConfig.enableKeybinding.isPressed()) {
return
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SaveCursorPosition.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SaveCursorPosition.kt
index 2748822..e2d48a9 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/SaveCursorPosition.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SaveCursorPosition.kt
@@ -27,10 +27,6 @@ object SaveCursorPosition : FirmamentFeature {
override val config: TConfig
get() = TConfig
- override fun onLoad() {
-
- }
-
var savedPositionedP1: Pair<Double, Double>? = null
var savedPosition: SavedPosition? = null
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
index aee985c..b0fb57b 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
@@ -10,7 +10,7 @@
package moe.nea.firmament.features.inventory
import com.mojang.blaze3d.systems.RenderSystem
-import java.util.*
+import java.util.UUID
import org.lwjgl.glfw.GLFW
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
@@ -18,6 +18,7 @@ import kotlinx.serialization.serializer
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.screen.GenericContainerScreenHandler
+import net.minecraft.screen.slot.Slot
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.util.Identifier
import moe.nea.firmament.annotations.Subscribe
@@ -96,81 +97,89 @@ object SlotLocking : FirmamentFeature {
return (lore.lastOrNull() ?: return false).unformattedString == "Click to buyback!"
}
- override fun onLoad() {
- HandledScreenKeyPressedEvent.subscribe {
- if (!it.matches(TConfig.lockSlot)) return@subscribe
- val inventory = MC.handledScreen ?: return@subscribe
- inventory as AccessorHandledScreen
-
- val slot = inventory.focusedSlot_Firmament ?: return@subscribe
- val lockedSlots = lockedSlots ?: return@subscribe
- if (slot.inventory is PlayerInventory) {
- if (slot.index in lockedSlots) {
- lockedSlots.remove(slot.index)
- } else {
- lockedSlots.add(slot.index)
- }
- DConfig.markDirty()
- CommonSoundEffects.playSuccess()
- }
+ @Subscribe
+ fun onSalvageProtect(event: IsSlotProtectedEvent) {
+ if (event.slot == null) return
+ if (!event.slot.hasStack()) return
+ if (event.slot.stack.displayNameAccordingToNbt?.unformattedString != "Salvage Items") return
+ val inv = event.slot.inventory
+ var anyBlocked = false
+ for (i in 0 until event.slot.index) {
+ val stack = inv.getStack(i)
+ if (IsSlotProtectedEvent.shouldBlockInteraction(null, SlotActionType.THROW, stack))
+ anyBlocked = true
}
- HandledScreenKeyPressedEvent.subscribe {
- if (!it.matches(TConfig.lockUUID)) return@subscribe
- val inventory = MC.handledScreen ?: return@subscribe
- inventory as AccessorHandledScreen
-
- val slot = inventory.focusedSlot_Firmament ?: return@subscribe
- val stack = slot.stack ?: return@subscribe
- val uuid = stack.skyblockUUID ?: return@subscribe
- val lockedUUIDs = lockedUUIDs ?: return@subscribe
- if (uuid in lockedUUIDs) {
- lockedUUIDs.remove(uuid)
- } else {
- lockedUUIDs.add(uuid)
- }
- DConfig.markDirty()
- CommonSoundEffects.playSuccess()
+ if (anyBlocked) {
+ event.protectSilent()
}
- IsSlotProtectedEvent.subscribe {
- if (it.slot != null && it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) {
- it.protect()
- }
+ }
+
+ @Subscribe
+ fun onProtectUuidItems(event: IsSlotProtectedEvent) {
+ val doesNotDeleteItem = event.actionType == SlotActionType.SWAP
+ || event.actionType == SlotActionType.PICKUP
+ || event.actionType == SlotActionType.QUICK_MOVE
+ || event.actionType == SlotActionType.QUICK_CRAFT
+ || event.actionType == SlotActionType.CLONE
+ || event.actionType == SlotActionType.PICKUP_ALL
+ val isSellOrTradeScreen =
+ isNpcShop(MC.handledScreen) || isTradeScreen(MC.handledScreen) || isSalvageScreen(MC.handledScreen)
+ if (!isSellOrTradeScreen && doesNotDeleteItem) return
+ val stack = event.itemStack ?: return
+ val uuid = stack.skyblockUUID ?: return
+ if (uuid in (lockedUUIDs ?: return)) {
+ event.protect()
}
- IsSlotProtectedEvent.subscribe { event ->
- val doesNotDeleteItem = event.actionType == SlotActionType.SWAP
- || event.actionType == SlotActionType.PICKUP
- || event.actionType == SlotActionType.QUICK_MOVE
- || event.actionType == SlotActionType.QUICK_CRAFT
- || event.actionType == SlotActionType.CLONE
- || event.actionType == SlotActionType.PICKUP_ALL
- val isSellOrTradeScreen =
- isNpcShop(MC.handledScreen) || isTradeScreen(MC.handledScreen) || isSalvageScreen(MC.handledScreen)
- if (!isSellOrTradeScreen && doesNotDeleteItem) return@subscribe
- val stack = event.itemStack ?: return@subscribe
- val uuid = stack.skyblockUUID ?: return@subscribe
- if (uuid in (lockedUUIDs ?: return@subscribe)) {
- event.protect()
- }
+ }
+
+ @Subscribe
+ fun onProtectSlot(it: IsSlotProtectedEvent) {
+ if (it.slot != null && it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())) {
+ it.protect()
}
- IsSlotProtectedEvent.subscribe { event ->
- if (event.slot == null) return@subscribe
- if (!event.slot.hasStack()) return@subscribe
- if (event.slot.stack.displayNameAccordingToNbt?.unformattedString != "Salvage Items") return@subscribe
- val inv = event.slot.inventory
- var anyBlocked = false
- for (i in 0 until event.slot.index) {
- val stack = inv.getStack(i)
- if (IsSlotProtectedEvent.shouldBlockInteraction(null, SlotActionType.THROW, stack))
- anyBlocked = true
- }
- if (anyBlocked) {
- event.protectSilent()
+ }
+
+ @Subscribe
+ fun onLockUUID(it: HandledScreenKeyPressedEvent) {
+ if (!it.matches(TConfig.lockUUID)) return
+ val inventory = MC.handledScreen ?: return
+ inventory as AccessorHandledScreen
+
+ val slot = inventory.focusedSlot_Firmament ?: return
+ val stack = slot.stack ?: return
+ val uuid = stack.skyblockUUID ?: return
+ val lockedUUIDs = lockedUUIDs ?: return
+ if (uuid in lockedUUIDs) {
+ lockedUUIDs.remove(uuid)
+ } else {
+ lockedUUIDs.add(uuid)
+ }
+ DConfig.markDirty()
+ CommonSoundEffects.playSuccess()
+ it.cancel()
+ }
+
+ @Subscribe
+ fun onLockSlot(it: HandledScreenKeyPressedEvent) {
+ if (!it.matches(TConfig.lockSlot)) return
+ val inventory = MC.handledScreen ?: return
+ inventory as AccessorHandledScreen
+
+ val slot = inventory.focusedSlot_Firmament ?: return
+ val lockedSlots = lockedSlots ?: return
+ if (slot.inventory is PlayerInventory) {
+ if (slot.index in lockedSlots) {
+ lockedSlots.remove(slot.index)
+ } else {
+ lockedSlots.add(slot.index)
}
+ DConfig.markDirty()
+ CommonSoundEffects.playSuccess()
}
}
@Subscribe
- fun function(it: SlotRenderEvents.After) {
+ fun onRenderSlotOverlay(it: SlotRenderEvents.After) {
val isSlotLocked = it.slot.inventory is PlayerInventory && it.slot.index in (lockedSlots ?: setOf())
val isUUIDLocked = (it.slot.stack?.skyblockUUID) in (lockedUUIDs ?: setOf())
if (isSlotLocked || isUUIDLocked) {
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
index 1fe222d..a6dbb5f 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/buttons/InventoryButtons.kt
@@ -9,6 +9,7 @@ package moe.nea.firmament.features.inventory.buttons
import me.shedaniel.math.Rectangle
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenClickEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
import moe.nea.firmament.events.HandledScreenPushREIEvent
@@ -28,6 +29,7 @@ object InventoryButtons : FirmamentFeature {
openEditor()
}
}
+
object DConfig : DataHolder<Data>(serializer(), identifier, ::Data)
@Serializable
@@ -40,35 +42,39 @@ object InventoryButtons : FirmamentFeature {
get() = TConfig
fun getValidButtons() = DConfig.data.buttons.asSequence().filter { it.isValid() }
- override fun onLoad() {
- HandledScreenForegroundEvent.subscribe {
- val bounds = it.screen.getRectangle()
- for (button in getValidButtons()) {
- val buttonBounds = button.getBounds(bounds)
- it.context.matrices.push()
- it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat(), 0F)
- button.render(it.context)
- it.context.matrices.pop()
- }
- lastRectangle = bounds
+
+ @Subscribe
+ fun onRectangles(it: HandledScreenPushREIEvent) {
+ val bounds = it.screen.getRectangle()
+ for (button in getValidButtons()) {
+ val buttonBounds = button.getBounds(bounds)
+ it.block(buttonBounds)
}
- HandledScreenClickEvent.subscribe {
- val bounds = it.screen.getRectangle()
- for (button in getValidButtons()) {
- val buttonBounds = button.getBounds(bounds)
- if (buttonBounds.contains(it.mouseX, it.mouseY)) {
- MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */)
- break
- }
+ }
+
+ @Subscribe
+ fun onClickScreen(it: HandledScreenClickEvent) {
+ val bounds = it.screen.getRectangle()
+ for (button in getValidButtons()) {
+ val buttonBounds = button.getBounds(bounds)
+ if (buttonBounds.contains(it.mouseX, it.mouseY)) {
+ MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */)
+ break
}
}
- HandledScreenPushREIEvent.subscribe {
- val bounds = it.screen.getRectangle()
- for (button in getValidButtons()) {
- val buttonBounds = button.getBounds(bounds)
- it.block(buttonBounds)
- }
+ }
+
+ @Subscribe
+ fun onRenderForeground(it: HandledScreenForegroundEvent) {
+ val bounds = it.screen.getRectangle()
+ for (button in getValidButtons()) {
+ val buttonBounds = button.getBounds(bounds)
+ it.context.matrices.push()
+ it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat(), 0F)
+ button.render(it.context)
+ it.context.matrices.pop()
}
+ lastRectangle = bounds
}
var lastRectangle: Rectangle? = null
diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt
index b0ebea6..0426e34 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/storageoverlay/StorageOverlay.kt
@@ -6,9 +6,10 @@
package moe.nea.firmament.features.inventory.storageoverlay
-import java.util.*
+import java.util.SortedMap
import kotlinx.serialization.serializer
import net.minecraft.client.gui.screen.Screen
+import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.ScreenChangeEvent
import moe.nea.firmament.events.TickEvent
import moe.nea.firmament.features.FirmamentFeature
@@ -40,31 +41,33 @@ object StorageOverlay : FirmamentFeature {
var shouldReturnToStorageOverlay: Screen? = null
var currentHandler: StorageBackingHandle? = StorageBackingHandle.None
- override fun onLoad() {
- ScreenChangeEvent.subscribe {
- if (lastStorageOverlay != null && it.new != null) {
- shouldReturnToStorageOverlay = lastStorageOverlay
- shouldReturnToStorageOverlayFrom = it.new
- lastStorageOverlay = null
- } else if (it.old === shouldReturnToStorageOverlayFrom) {
- if (shouldReturnToStorageOverlay != null && it.new == null)
- setScreenLater(shouldReturnToStorageOverlay)
- shouldReturnToStorageOverlay = null
- shouldReturnToStorageOverlayFrom = null
- }
- }
+ @Subscribe
+ fun onTick(event: TickEvent) {
+ rememberContent(currentHandler ?: return)
+ }
- ScreenChangeEvent.subscribe { event ->
- currentHandler = StorageBackingHandle.fromScreen(event.new)
- if (event.old is StorageOverlayScreen && !event.old.isClosing) {
- event.old.setHandler(currentHandler)
- if (currentHandler != null)
- // TODO: Consider instead only replacing rendering? might make a lot of stack handling easier
- event.cancel()
- }
+ @Subscribe
+ fun onScreenChangeLegacy(event: ScreenChangeEvent) {
+ currentHandler = StorageBackingHandle.fromScreen(event.new)
+ if (event.old is StorageOverlayScreen && !event.old.isClosing) {
+ event.old.setHandler(currentHandler)
+ if (currentHandler != null)
+ // TODO: Consider instead only replacing rendering? might make a lot of stack handling easier
+ event.cancel()
}
- TickEvent.subscribe {
- rememberContent(currentHandler ?: return@subscribe)
+ }
+
+ @Subscribe
+ fun onScreenChange(it: ScreenChangeEvent) {
+ if (lastStorageOverlay != null && it.new != null) {
+ shouldReturnToStorageOverlay = lastStorageOverlay
+ shouldReturnToStorageOverlayFrom = it.new
+ lastStorageOverlay = null
+ } else if (it.old === shouldReturnToStorageOverlayFrom) {
+ if (shouldReturnToStorageOverlay != null && it.new == null)
+ setScreenLater(shouldReturnToStorageOverlay)
+ shouldReturnToStorageOverlay = null
+ shouldReturnToStorageOverlayFrom = null
}
}