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.

Featured Replies

Posted

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/

 

  • Author

You simply can't. You have to hard-code it.

That's unfortunate, because then it would be incompatible with other mods... :/

  • Author

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)

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.