Posted June 5, 20232 yr Hi, i want to add an item to player's inventory when specific event is fired, but i don't know how to do that
June 8, 20232 yr Author Hi! I tried the above method, but it did not work. There's my function. The message appears in the chat, but the item is not added to the inventory. I can’t figure out what the problem is, so please help. @SubscribeEvent public void onJoin(EntityJoinLevelEvent event) { if (event.getEntity() instanceof Player && event.getEntity().getCommandSenderWorld().isClientSide) { Minecraft.getInstance().player.getInventory().add(new ItemStack(Items.CARROT)); Entity playerEntity = event.getEntity(); playerEntity.sendSystemMessage(Component.nullToEmpty("Hello!")); } }
June 9, 20232 yr I wanna say you would use something along the lines of: @SubscribeEvent public void onJoin(EntityJoinWorldEvent event) { if (event.getEntity() instanceof Player && !event.getWorld().isClient()) { Player player = (Player) event.getEntity(); player.getInventory().add(new ItemStack(Items.CARROT)); player.sendMessage(Component.nullToEmpty("Hello!")); } } I may be wrong though. Not even gonna lie, I think I have autism
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.