From ecb14a442c0c4a54bb92dcb9db19cabd37c9f5f1 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Wed, 25 Sep 2024 18:16:20 -0700 Subject: [PATCH] ## [1.0.4] - 2024-09-25 ### Fixed - Fixed crash when dying with GPS equipped in Curio/Trinket/Accessories slot. --- CHANGELOG.md | 5 ++++ .../fabric/event/InventoryEvent.java | 12 ++++------ .../pocketgps/forge/event/InventoryEvent.java | 24 +++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6ab05a..441eeec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +## [1.0.4] - 2024-09-25 + +### Fixed +- Fixed crash when dying with GPS equipped in Curio/Trinket/Accessories slot. + ## [1.0.3] - 2024-09-22 ### Fixed diff --git a/fabric/src/main/java/club/iananderson/pocketgps/fabric/event/InventoryEvent.java b/fabric/src/main/java/club/iananderson/pocketgps/fabric/event/InventoryEvent.java index b4ebe26..99138f7 100644 --- a/fabric/src/main/java/club/iananderson/pocketgps/fabric/event/InventoryEvent.java +++ b/fabric/src/main/java/club/iananderson/pocketgps/fabric/event/InventoryEvent.java @@ -18,17 +18,13 @@ private static boolean findCurio(Player player, Item item) { return false; } - int slot = 0; - if (PocketGps.curiosLoaded()) { - Optional curiosInventory = TrinketsApi.getTrinketComponent(player); - if (curiosInventory.isPresent()) { - if (curiosInventory.get().isEquipped(item)) { - slot += 1; - } + Optional trinketInventory = TrinketsApi.getTrinketComponent(player); + if (trinketInventory.isPresent()) { + return trinketInventory.get().isEquipped(item); } } - return slot > 0; + return false; } public static void register() { diff --git a/forge/src/main/java/club/iananderson/pocketgps/forge/event/InventoryEvent.java b/forge/src/main/java/club/iananderson/pocketgps/forge/event/InventoryEvent.java index 4a1a802..5dea143 100644 --- a/forge/src/main/java/club/iananderson/pocketgps/forge/event/InventoryEvent.java +++ b/forge/src/main/java/club/iananderson/pocketgps/forge/event/InventoryEvent.java @@ -4,9 +4,7 @@ import club.iananderson.pocketgps.forge.registry.ForgeRegistration; import club.iananderson.pocketgps.minimap.CurrentMinimap; import io.wispforest.accessories.api.AccessoriesCapability; -import io.wispforest.accessories.api.AccessoriesContainer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; +import java.util.Optional; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraftforge.api.distmarker.Dist; @@ -25,19 +23,21 @@ private static boolean findCurio(Player player, Item item) { return false; } - int slot = 0; - if (PocketGps.curiosLoaded()) { - ICuriosItemHandler curiosInventory = CuriosApi.getCuriosInventory(player).resolve().get(); - if (curiosInventory.findFirstCurio(item).isPresent()) { - slot += 1; + Optional curiosInventory = CuriosApi.getCuriosInventory(player).resolve(); + if (curiosInventory.isPresent()) { + return curiosInventory.get().isEquipped(item); } } + if (PocketGps.accessoriesLoaded() && !PocketGps.curiosLoaded()) { - AccessoriesContainer accessoriesContainer = AccessoriesCapability.get(player).getContainers().get("gps_slot"); - slot += accessoriesContainer.getAccessories().countItem(item); + Optional accessoriesInventory = AccessoriesCapability.getOptionally(player); + if (accessoriesInventory.isPresent()) { + + return accessoriesInventory.get().isEquipped(item); + } } - return slot > 0; + return false; } @SubscribeEvent @@ -48,7 +48,7 @@ public static void onPlayerTickEvent(PlayerTickEvent event) { boolean hasGpsInv = CurrentMinimap.hasGps(player, ForgeRegistration.POCKET_GPS.get()); boolean hasGpsCurio = findCurio(player, ForgeRegistration.POCKET_GPS.get()); - CurrentMinimap.displayMinimap(player,hasGpsInv || hasGpsCurio); + CurrentMinimap.displayMinimap(player, hasGpsInv || hasGpsCurio); } } }