aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-10-28 04:17:11 +0200
committernea <nea@nea.moe>2023-10-28 04:17:11 +0200
commit47fbb25ab280b6af9496780672780db78fe36f27 (patch)
treef4899335e9f1b12a7c7f88a0032693f3ea7d3044
parentad490f2ea7967cb6bb97cb797b33aa3554de46a5 (diff)
downloadFirmament-47fbb25ab280b6af9496780672780db78fe36f27.tar.gz
Firmament-47fbb25ab280b6af9496780672780db78fe36f27.tar.bz2
Firmament-47fbb25ab280b6af9496780672780db78fe36f27.zip
Fix uuid locking not working in some NPC shops
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt24
1 files changed, 13 insertions, 11 deletions
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 2f4f84b..43243f1 100644
--- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt
@@ -15,6 +15,7 @@ import kotlinx.serialization.UseSerializers
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.SlotActionType
import net.minecraft.util.Identifier
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
@@ -74,21 +75,21 @@ object SlotLocking : FirmamentFeature {
fun isTradeScreen(screen: HandledScreen<*>?): Boolean {
if (screen == null) return false
- val handler = screen.screenHandler
- if (handler.slots.size < 9) return false
- val middlePane = handler.getSlot(4)
- if (!middlePane.hasStack()) return false
- return middlePane.stack.displayNameAccordingToNbt?.unformattedString == "⇦ Your stuff"
+ val handler = screen.screenHandler as? GenericContainerScreenHandler ?: return false
+ if (handler.inventory.size() < 9) return false
+ val middlePane = handler.inventory.getStack(handler.inventory.size() - 5)
+ if (middlePane == null) return false
+ return middlePane.displayNameAccordingToNbt?.unformattedString == "⇦ Your stuff"
}
fun isNpcShop(screen: HandledScreen<*>?): Boolean {
if (screen == null) return false
- val handler = screen.screenHandler
- if (handler.slots.size < 9) return false
- val sellItem = handler.getSlot(handler.slots.size - 5)
- if (!sellItem.hasStack()) return false
- if (sellItem.stack.displayNameAccordingToNbt?.unformattedString == "Sell Item") return true
- val lore = sellItem.stack.loreAccordingToNbt
+ val handler = screen.screenHandler as? GenericContainerScreenHandler ?: return false
+ if (handler.inventory.size() < 9) return false
+ val sellItem = handler.inventory.getStack(handler.inventory.size() - 5)
+ if (sellItem == null) return false
+ if (sellItem.displayNameAccordingToNbt?.unformattedString == "Sell Item") return true
+ val lore = sellItem.loreAccordingToNbt
return (lore.lastOrNull() ?: return false).value?.unformattedString == "Click to buyback!"
}
@@ -178,6 +179,7 @@ object SlotLocking : FirmamentFeature {
isUUIDLocked ->
(Identifier("firmament:uuid_locked"))
+
else ->
error("unreachable")
}