Jump to content

[1.7.10] getSubItems server side


gegy1000

Recommended Posts

So, I have a mod where you get an item that you can put in your crafting table and get a random item. As the game starts, it goes through all the registered items and adds them and their sub items to a list that the game looks through when you put the item in the crafting table. My current problem is that getSubItems doesn't exist server side, so it crashes the server. I can't think of any way around this, and help would be greatly appreciated. :)

 

Here is the code that finds all registered items:

 

try
        {
            Field creativeTabField = null;
            
            for (Field field : Item.class.getDeclaredFields()) //Since getCreativeTab() is @SideOnly(Side.CLIENT)
            {
                if(field.getType() == CreativeTabs.class)
                {
                    field.setAccessible(true);
                    creativeTabField = field;
                    break;
                }
            }
            
            for (Object object : Item.itemRegistry.getKeys())
            {
                Item item = (Item) Item.itemRegistry.getObject((String) object);
                
                CreativeTabs tab = (CreativeTabs) creativeTabField.get(item);
                
                if(tab != null)
                {
                    List<ItemStack> subtypes = new ArrayList<ItemStack>();
                    
                    if(item.getHasSubtypes())
                    {
                        try
                        {
                            item.getSubItems(item, tab, subtypes);
                        }
                        catch (Exception e)
                        {
                            System.err.println("Error while finding subitems for " + item.getUnlocalizedName() + "!");
                            e.printStackTrace();
                        }
                    }
                    else
                    {
                        subtypes.add(new ItemStack(item, 1, 0));
                    }
                    
                    for (ItemStack subtype : subtypes)
                    {
                        possibleItems.add(new RandomItem(subtype.getItem(), subtype.getItemDamage()));
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

And here is the mod: http://www.planetminecraft.com/mod/randomite-mod/

 

Link to comment
Share on other sites

Nothing you can do about it unfortunately.

I was thinking about sending packets from the client to the server, but firstly that would be quite inefficient and secondly the client could have some mods that the server doesn't.. (Although you could check on the server)
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.