mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Fix invalid index when ticking itemstacks in a player nventory by adding a new onInventoryTick event. Closes #9453
This commit is contained in:
2 files changed
+28
No files matched your search
@@ -330,10 +330,28 @@ public interface IForgeItem
|
||||
/**
|
||||
* Called to tick armor in the armor slot. Override to do something
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1") // Use onInventoryTick
|
||||
default void onArmorTick(ItemStack stack, Level level, Player player)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specific ItemStack can be placed in the specified armor
|
||||
* slot, for the entity.
|
||||
|
||||
@@ -292,11 +292,21 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
|
||||
/**
|
||||
* Called to tick armor in the armor slot. Override to do something
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1") // Use onInventoryTick
|
||||
default void onArmorTick(Level level, Player player)
|
||||
{
|
||||
self().getItem().onArmorTick(self(), level, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to tick this items in a players inventory, the indexes are the global slot index.
|
||||
*/
|
||||
default void onInventoryTick(Level level, Player player, int slotIndex, int selectedIndex)
|
||||
{
|
||||
self().getItem().onInventoryTick(self(), level, player, slotIndex, selectedIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called every tick from {@code Horse#playGallopSound(SoundEvent)} on the item in the
|
||||
* armor slot.
|
||||
|
||||
Reference in new issue
Block a user