Posted March 5, 201510 yr Hi, How can I change the current slot selected in hotbar? (not the held item) Thanks in advance ...
March 5, 201510 yr Author a) It's a field, not a method. b) You need a server-side player (EntityPlayerMP). You can safely cast EntityPlayer to that if you are on the server thread (check with world.isRemote). Thank You, now works!!! BUT I'm already on server side and I still need to cast the EntityPlayerMP, here my code: @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { if (!event.player.worldObj.isRemote) { for (int s = 0; s < 9; ++s) { if (event.player.inventory.getStackInSlot(s) != null) { if (event.player.inventory.getStackInSlot(s).getItem() == MyItem) { event.player.inventory.currentItem = s; EntityPlayerMP playerMP = (EntityPlayerMP) event.player; playerMP.inventory.currentItem = s; playerMP.playerNetServerHandler.sendPacket(new S09PacketHeldItemChange(playerMP.inventory.currentItem)); } } } } Also I mean, if I need to send the package anyway?
March 5, 201510 yr maybe you can try this: EntityPlayer me=(EntityPlayer)world.playerEntities.get(0); me.inventory.currentItem=0;//or other number in 0-8 sorry,my english is not well
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.