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!"));
}
}