mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-14 01:04:24 +00:00
[1.19] Add hook for items to remain in the hotbar when picking blocks/entities (#8872)
This commit is contained in:
1 parent
6609708d14
commit
aab0e4c82e
3 files changed
+40
No files matched your search
@@ -14,6 +14,7 @@ import java.util.function.Consumer;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.food.FoodProperties;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
@@ -828,4 +829,18 @@ public interface IForgeItem
|
||||
return self().getFoodProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given ItemStack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action.
|
||||
* By default, this returns true for enchanted stacks.
|
||||
*
|
||||
* @see Inventory#getSuitableHotbarSlot()
|
||||
* @param player the player performing the picking
|
||||
* @param inventorySlot the inventory slot of the item being up for replacement
|
||||
* @return true to leave this stack in the hotbar if possible
|
||||
*/
|
||||
default boolean isNotReplaceableByPickAction(ItemStack stack, Player player, int inventorySlot)
|
||||
{
|
||||
return stack.isEnchanted();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.common.extensions;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.monster.EnderMan;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.food.FoodProperties;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -556,4 +557,19 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
return self().getItem().getFoodProperties(self(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this stack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action.
|
||||
* By default, this returns true for enchanted stacks.
|
||||
*
|
||||
* @see Inventory#getSuitableHotbarSlot()
|
||||
* @param player the player performing the picking
|
||||
* @param inventorySlot the inventory slot of the item being up for replacement
|
||||
* @return true to leave this stack in the hotbar if possible
|
||||
*/
|
||||
default boolean isNotReplaceableByPickAction(Player player, int inventorySlot)
|
||||
{
|
||||
return self().getItem().isNotReplaceableByPickAction(self(), player, inventorySlot);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user