Jump to content

Recommended Posts

Posted

so im making an item that consumes itself, but adds another item to the inventory. and vise versa for the added item. Problem is, if the Item is in the first hotbar slot it doesn't add the item to anywhere in the inventory.

 

Here is my method.

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){

	if(player.isSneaking()){
		if (player.inventory.hasItem(ModItems.Riptide)){
			player.inventory.consumeInventoryItem(ModItems.Riptide);


	player.inventory.addItemStackToInventory(new ItemStack(ModItems.anklamolses));
		}
	}
	return stack;

}
}

 

Thank you all for your time.

Im serious don't look at it!!

Posted

actually this is unrelated but my player.isSneaking is ineffective, any ideas?

 

Edit:

Ive tried doing this:

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){

	if(player.inventory.hasItem(ModItems.Riptide)){
	player.inventory.consumeInventoryItem(ModItems.Riptide);
	}else{
		player.isSneaking();
	}


	}



	return new ItemStack(ModItems.anklamolses);
	}

}

and this

if(player.isSneaking()||player.inventory.consumeInventoryItem(ModItems.anklamolses)){

but it doesn't work, im sure im missing something big im just not sure what it is

Im serious don't look at it!!

Posted

Edit: Congrats xD I'll leave the rest of my comment anyway.

 

Well your first bit of code in your last post shouldn't even compile - you have an extra closing curly brace that ends the method before you return anything.

 

player.isSneaking() returns a boolean value - it doesn't actually do anything. The only use for it is to check if the player is sneaking or not, and for that it must be in an if statement.

 

In your last code snippet, what are you trying to do? The way it is written, the item is only consumed if the player is NOT sneaking, because if isSneaking returns true, the rest of the condition is ignored. You may want to review basic logic operators and their uses - especially the examples later on down that page may prove instructive.

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.