I'm making a tool that uses a custom keybind for additional functionality and used inventoryTick() to check for key presses. Now i want to do a check if the correct item is held in hand, but no matter what i do i can't manage to get the current item held in player's hand. It always outputs the item the player held at the time of joining the world after building the debug project and it never changes after that.
@Override
public void inventoryTick(ItemStack stack, ServerWorld world, Entity entity, EquipmentSlot slot)
{
if (entity.isPlayer()) {
ItemStack itemStack = entity.getEntity().getStackInHand(Hand.MAIN_HAND);
KeyBinding keyBinding = KeyBinding.byId("key.blockpallettemod.test");
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while(keyBinding.wasPressed()) {
if (itemStack.isOf(stack.getItem())) {
client.player.sendMessage(Text.literal("Pallette opened"), false);
}
}
});
}
}
What java magic do i do to get the currently held item stack?