Jump to content

Strange Error - Converting ItemStack to ItemData


DrEinsteinium

Recommended Posts

Hey everyone, I am working on my mod and I am trying to figure out how to convert ItemStack into ItemData through the use of NBTTagCompound. Despite trying all three methods to write NBTTagCompounds, I crash every single time.

 

Here is my pastebin of my error. http://pastebin.com/XMHzA826

 

Here is my methodology for converting the itemstack.

 

			ItemStack stackover = gui.manager.getStackMouseOver();

		NBTTagCompound tag  = new NBTTagCompound();

		stackover.writeToNBT(tag);

		ItemData data = new ItemData((NBTTagCompound) tag);

 

It keeps crashing whenever I run the method, even if I use writeToNBT, setTagCompound and stackTagCompound. The whole point of the process is to get an ItemStack from NEI's keybinding and return the @ModId of that particular item's mod (which I can do with ItemData.getModId()).

 

Does someone have an explanation for this? :/ I am really getting annoyed. Here is my GitHub if you want to see the whole code. I am using Wiki and NEIWikiLinkConfig. But just a fair warning, my mod's workspace is so messy. I am in the process of re-writing.

Follow me on twitter! @keepablock

Read up on whats new! www.catacombs.co

width=700 height=60http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]

Link to comment
Share on other sites

I expected it to work because chicken_bones did some magical stuff along the same lines. <Link>

 

Obviously that does not work, however, I tried using the GameRegistry method and all I get is null whenever it returns the UniqueIdentifier for my ItemStack. Here is the code I used.

 

		ItemStack stackover = gui.manager.getStackMouseOver();
        	
        	WikiLink.LogHelper.info("" + GameRegistry.findUniqueIdentifierFor(stackover.getItem()));

 

It should work, as it turns the ItemStack into an Item so the GameRegistry method could read it, but all it returns is null. Here is the code from NEI that I am using to return the ItemStack.

 

    public ItemStack getStackMouseOver()
    {
        Point mousePos = getMousePosition();
        ItemStack item = null;

        for(IContainerObjectHandler objectHandler : objectHandlers)
        {
            item = objectHandler.getStackUnderMouse(window, mousePos.x, mousePos.y);
            if(item != null)
                return item;
        }

        if(!objectUnderMouse(mousePos.x, mousePos.y))
        {
            Slot slot = window.getSlotAtPosition(mousePos.x, mousePos.y);
            if(slot != null)
                item = slot.getStack();
        }
        return item;
    }

 

----

 

Edit: My current solution is this:

				ItemStack stackover = gui.manager.getStackMouseOver();

        	NBTTagList itemDataList = new NBTTagList();
        	GameData.writeItemData(itemDataList);
        	
        	for(int i = 0; i < itemDataList.tagCount(); i++)
        	{
        		ItemData itemData = new ItemData((NBTTagCompound) itemDataList.tagAt(i));
        		
        		if(itemData.getItemId() == stackover.itemID)	
        		{
        			WikiLink.LogHelper.info("The ModId is: " + itemData.getModId());
        		}
        	}

 

It's not exactly the way I want it, as it loops through every item in the game until it matches the ItemData itemId with the ItemStack itemId, but hey. If there's an easier and more efficient solution, do not hesitate to post :)

Follow me on twitter! @keepablock

Read up on whats new! www.catacombs.co

width=700 height=60http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img]

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.