strega Posted June 5, 2023 Share Posted June 5, 2023 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 Quote Link to comment Share on other sites More sharing options...
MFMods Posted June 5, 2023 Share Posted June 5, 2023 player.inventory.add(Items.CARROT) Quote Link to comment Share on other sites More sharing options...
strega Posted June 8, 2023 Author Share Posted June 8, 2023 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!")); } } Quote Link to comment Share on other sites More sharing options...
Naamah Posted June 9, 2023 Share Posted June 9, 2023 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. 1 Quote Not even gonna lie, I think I have autism Link to comment Share on other sites More sharing options...
strega Posted June 9, 2023 Author Share Posted June 9, 2023 Okay, I checked this method and everything works! Thanks! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.