Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);


	}
}

 

 

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.