Jump to content

[1.7.10] How would you check if specific inventory slot is empty


Thornack

Recommended Posts

I have an event that gives the player a series of items on player log in

but I want each item to go into its own unique and specific slot in the player HUD inventory if and only if the specified slot is empty and if there is a different item already in that slot then I dont want to give the player my item.

 

What is weird is that for the code below kind of works but the first item adds to slot 1 no problem but the other 2 are not added at all. Does anyone know why? And is there a way to achieve this that works?

 

My PlayerLoggedInEvent

 

 

@SubscribeEvent
public void onPlayerJoin(PlayerLoggedInEvent event) {
	System.out.println("This is called Log In");

	if(!event.player.worldObj.isRemote && !event.player.capabilities.isCreativeMode){
		System.out.println("on server side and not in creative");
		if(event.player.inventory.mainInventory[0] == null){
			System.out.println("Adding Flame Attack");	
			event.player.inventory.addItemStackToInventory(new ItemStack(CommonProxy.itemSelectAttackRanged_FlameAttack));
			} 
		if(event.player.inventory.mainInventory[1] != null){
			System.out.println("Adding Ice Attack");	
			event.player.inventory.addItemStackToInventory(new ItemStack(CommonProxy.itemSelectAttackRanged_itemIceAttack));
		    }
		if(event.player.inventory.mainInventory[2] != null){
			System.out.println("Adding Air Attack");	
			event.player.inventory.addItemStackToInventory(new ItemStack(CommonProxy.itemSelectAttackRanged_itemAirAttack));
		    }
	}

	if (event.player instanceof EntityPlayer && !event.player.worldObj.isRemote) {
		PacketOverlord.sendTo(new PacketSyncPlayerStamina((EntityPlayer) event.player),(EntityPlayerMP) event.player);


	}
}

 

 

Link to comment
Share on other sites

If you are looking for anomalies then in slot[0] you have ==, but in [1] and [2] there is !=.

 

Also, addItemStackToInventory is not quite what you are looking for (might be). In this case it will work, but I'd rather simply use slot[index] = new ItemStack(...)

1.7.10 is no longer supported by forge, you are on your own.

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.



×
×
  • Create New...

Important Information

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