Jump to content

[1.7.2]Override Item in Inventory


korti11

Recommended Posts

Good evening everybody,

 

my problem is when I override a item in the inventory from the player and I use then I get the old item back.

Here is my code:

 

		Item[] items = new Item[]{Tools.redSword, Tools.redSwordCharged};

	if(invert.isPressed()){
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
		InventoryPlayer inventory = player.inventory;
		ItemStack newItemStack;
		ItemStack oldItemStack;

		for(int i = 0; i < items.length && inventory.getCurrentItem() != null; i += 2){
			if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i]).getUnlocalizedName())){
				newItemStack = new ItemStack(items[i + 1]);
				oldItemStack = inventory.getCurrentItem();
				newItemStack.setItemDamage(oldItemStack.getItemDamage());
				inventory.mainInventory[inventory.currentItem] = ItemStack.copyItemStack(newItemStack);
			}
			else if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i + 1]).getUnlocalizedName())){
				newItemStack = new ItemStack(items[i]);
				oldItemStack = inventory.getCurrentItem();
				newItemStack.setItemDamage(oldItemStack.getItemDamage());
				inventory.mainInventory[inventory.currentItem] = ItemStack.copyItemStack(newItemStack);
			}
		}
	}

 

Sorry for my English it is not the best :D

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.