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.

Strange Error - Converting ItemStack to ItemData

Featured Replies

Posted

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]

  • Author

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]

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.