Posted March 25, 20214 yr public class KeyInputHandler { private static final Logger LOGGER = LogManager.getLogger(); @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { PlayerEntity player = Minecraft.getInstance().player; if (Keybinds.test_item_gui_key.isPressed() && player.getHeldItemMainhand().getItem() instanceof ItemTestItem){ LOGGER.info("KEY PRESSED"); } } } How can I open my ItemTestItem's GUI when I press the C key? Right Now I am opening it from NetworkHooks in my ItemTestItem class. @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand handIn) { ItemStack stack = player.getHeldItem(handIn).getStack(); if (!world.isRemote){ if (player.isSneaking()){ INamedContainerProvider containerProviderTestItem = new ContainerProviderTestItem(this, stack); final int NUMBER_OF_SLOTS = 8; NetworkHooks.openGui((ServerPlayerEntity) player, containerProviderTestItem, (packetBuffer)-> packetBuffer.writeInt(NUMBER_OF_SLOTS);}); return ActionResult.resultSuccess(stack); } } } Here's the git repo if needed: https://github.com/NindyBun/TestMod/blob/master/src/main/java/com/nindybun/miningtool/KeyInputHandler.java Apologies in advance if my code is crude.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.