diff options
author | nea <nea@nea.moe> | 2023-10-28 04:17:11 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-10-28 04:17:11 +0200 |
commit | 47fbb25ab280b6af9496780672780db78fe36f27 (patch) | |
tree | f4899335e9f1b12a7c7f88a0032693f3ea7d3044 /src/main | |
parent | ad490f2ea7967cb6bb97cb797b33aa3554de46a5 (diff) | |
download | firmament-47fbb25ab280b6af9496780672780db78fe36f27.tar.gz firmament-47fbb25ab280b6af9496780672780db78fe36f27.tar.bz2 firmament-47fbb25ab280b6af9496780672780db78fe36f27.zip |
Fix uuid locking not working in some NPC shops
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt | 24 |
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") } |