From 88d2dc6c8f91fd3a6b38fa06bd92cde2db1c94db Mon Sep 17 00:00:00 2001 From: LexManos Date: Sat, 13 Jan 2024 12:38:56 -0800 Subject: [PATCH] Fix missing patch for Item.onInventoryTick. Closes #9812 --- .../world/entity/player/Inventory.java.patch | 20 +++++++++++------- .../common/extensions/IForgeItem.java | 21 ++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/entity/player/Inventory.java.patch b/patches/minecraft/net/minecraft/world/entity/player/Inventory.java.patch index e53ae82ac7..852b26cddd 100644 --- a/patches/minecraft/net/minecraft/world/entity/player/Inventory.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/player/Inventory.java.patch @@ -19,15 +19,21 @@ if (p_36049_.m_41782_()) { itemstack.m_41751_(p_36049_.m_41783_().m_6426_()); } -@@ -229,7 +_,7 @@ - } - } - } -- -+ f_35975_.forEach(e -> e.onArmorTick(f_35978_.m_9236_(), f_35978_)); +@@ -222,11 +_,13 @@ } - public boolean m_36054_(ItemStack p_36055_) { + public void m_36068_() { ++ int idx = 0; + for(NonNullList nonnulllist : this.f_35979_) { + for(int i = 0; i < nonnulllist.size(); ++i) { + if (!nonnulllist.get(i).m_41619_()) { +- nonnulllist.get(i).m_41666_(this.f_35978_.m_9236_(), this.f_35978_, i, this.f_35977_ == i); ++ nonnulllist.get(i).onInventoryTick(this.f_35978_.m_9236_(), this.f_35978_, idx, this.f_35977_); + } ++ idx++; + } + } + @@ -277,6 +_,8 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.m_127521_(throwable, "Adding item to inventory"); diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java index 6385cdb683..a7502247fe 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java @@ -340,16 +340,17 @@ public interface IForgeItem */ default void onInventoryTick(ItemStack stack, Level level, Player player, int slotIndex, int selectedIndex) { - // For compatibility reasons we have to use non-local index values, I think this is a vanilla bug but lets maintain compatibility - int vanillaIndex = slotIndex; - if (slotIndex >= 36) { - vanillaIndex -= 36; - if (vanillaIndex >= 4) - vanillaIndex -= 4; - else - onArmorTick(stack, level, player); - } - stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex); + // For compatibility reasons we have to use non-local index values, I think this is a vanilla bug but lets maintain compatibility + var inv = player.getInventory(); + int vanillaIndex = slotIndex; + if (slotIndex >= inv.items.size()) { + vanillaIndex -= inv.items.size(); + if (vanillaIndex >= inv.armor.size()) + vanillaIndex -= inv.armor.size(); + else + onArmorTick(stack, level, player); + } + stack.inventoryTick(level, player, vanillaIndex, selectedIndex == vanillaIndex); } /**