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

I'm iterating through the item registry like so:

 

for (Object io : Item.itemRegistry)
{
    Item i = (Item)io;
}

 

Now what I want to do is save all the items in the registry to a mysql database. That I can do no problem. What the problem is is that some items have the same unlocalized name but are different Blocks, like wood and stone pressure plates. They have the same unlocalized name but are different objects. If I try something like this:

 

for (Object io : Item.itemRegistry)
{
    if (io.equals(Blocks.stone_pressure_plate))
    {
        System.out.println("Yup this is a stone pressure plate");
    }
}

 

I never get the message.

 

I'm storing all the items in a MySQL table created like so:

 

CREATE TABLE `items` (
  `unlocalized_name` varchar(192) NOT NULL,
  `sub_id` int(11) NOT NULL DEFAULT '0',
  `localized_name` varchar(256) DEFAULT NULL,
  `owning_mod` varchar(128) NOT NULL,
  PRIMARY KEY (`unlocalized_name`,`sub_id`),
  CONSTRAINT `owning_mod` FOREIGN KEY (`owning_mod`) REFERENCES `mods` (`mod`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

Since wood and stone pressure plates have the same unlocalized name (tile.pressurePlate) and the same damage value (0), I can't have both so I'd need to adjust the unlocalized name for both pressure plates.

 

How can I correctly detect if a given instance is a certain block?

I like trains.

getIdFromBlock() should do the trick for the moment - you shouldn't create things with a set ID and otherwise muck about with it directly, but reading it seems to still be kosher for now.

 

if (Block.getIdFromBlock(io) == Block.getIdFromBlock(Blocks.stone_pressure_plate) )
{
    // blah blah blah
}

  • Author
you shouldn't create things with a set ID and otherwise muck about with it directly, but reading it seems to still be kosher for now.

 

Yeah I know that block ids are being phased out which is good. The sub_id column is actually the item's damage value. Water bottle is 343:0 so I'd store the 0 in that column that I may need to change that since all the potions have the same unlocalized name which is dumb.

 

Or use Blocks.getBlockFromItem(theItem) == Blocks.whatever

 

Thanks.

I like trains.

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.