aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob <55346310+Kathund@users.noreply.github.com>2025-07-01 19:46:19 +0800
committerGitHub <noreply@github.com>2025-07-01 13:46:19 +0200
commit073a62c2e3eb67ac00da09a5f4aad39b1a5bff17 (patch)
tree53b46fe914a9b65984b7a063bec7132402323aec /src
parent89d16bf3f3ca8e4a7750b45210116309fa579b18 (diff)
downloadFirmament-073a62c2e3eb67ac00da09a5f4aad39b1a5bff17.tar.gz
Firmament-073a62c2e3eb67ac00da09a5f4aad39b1a5bff17.tar.bz2
Firmament-073a62c2e3eb67ac00da09a5f4aad39b1a5bff17.zip
feat: inventory buttons rendering in other guys toggle
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtons.kt20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
index 15f57d9..ab80d97 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
@@ -6,14 +6,13 @@ import me.shedaniel.math.Rectangle
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import kotlin.time.Duration.Companion.seconds
-import net.minecraft.client.MinecraftClient
+import net.minecraft.client.gui.screen.ingame.HandledScreen
+import net.minecraft.client.gui.screen.ingame.InventoryScreen
import net.minecraft.text.Text
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.HandledScreenClickEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
import moe.nea.firmament.events.HandledScreenPushREIEvent
-import moe.nea.firmament.features.FirmamentFeature
-import moe.nea.firmament.gui.FirmHoverComponent
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.ScreenUtil
@@ -29,6 +28,7 @@ object InventoryButtons {
openEditor()
}
val hoverText by toggle("hover-text") { true }
+ val onlyInv by toggle("only-inv") { false }
}
object DConfig : DataHolder<Data>(serializer(), "inventory-buttons", ::Data)
@@ -38,13 +38,17 @@ object InventoryButtons {
var buttons: MutableList<InventoryButton> = mutableListOf()
)
+ fun getValidButtons(screen: HandledScreen<*>): Sequence<InventoryButton> {
+ return DConfig.data.buttons.asSequence().filter { button ->
+ button.isValid() && (!TConfig.onlyInv || screen is InventoryScreen)
+ }
+ }
- fun getValidButtons() = DConfig.data.buttons.asSequence().filter { it.isValid() }
@Subscribe
fun onRectangles(it: HandledScreenPushREIEvent) {
val bounds = it.screen.getRectangle()
- for (button in getValidButtons()) {
+ for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
it.block(buttonBounds)
}
@@ -53,7 +57,7 @@ object InventoryButtons {
@Subscribe
fun onClickScreen(it: HandledScreenClickEvent) {
val bounds = it.screen.getRectangle()
- for (button in getValidButtons()) {
+ for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
if (buttonBounds.contains(it.mouseX, it.mouseY)) {
MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */)
@@ -67,10 +71,10 @@ object InventoryButtons {
@Subscribe
fun onRenderForeground(it: HandledScreenForegroundEvent) {
- val bounds = it.screen.getRectangle()
+ val bounds = it.screen.getRectangle()
var hoveredComponent: InventoryButton? = null
- for (button in getValidButtons()) {
+ for (button in getValidButtons(it.screen)) {
val buttonBounds = button.getBounds(bounds)
it.context.matrices.push()
it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat(), 0F)