Jump to content

Recommended Posts

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.

Posted

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
}

Posted
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...

×   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.