Jump to content

[1.7.10] set current item


deenkayros

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.