Jump to content

Item constructor id sentinel (for metadata items)


LostCoder

Recommended Posts

Add a sentinel for Item constructor which will prevent item from been registered into Item.itemsList, but still create an instance of an Item. It will be very helpful in creating metadata based items. Like:

 

[spoiler=Item constructor]public Item(int par1)

    {

        this.itemID = 256 + par1;

 

        if (this.itemID < 0 || this.itemID >= itemsList.length) return;

 

        if (itemsList[256 + par1] != null)

        {

            System.out.println("CONFLICT @ " + par1 + " item slot already occupied by " + itemsList[256 + par1] + " while adding " + this);

        }

 

        itemsList[256 + par1] = this;

 

        GameData.newItemAdded(this);

    }

[spoiler=MetaItem example]public class MetaItem extends Item

{

    // int metadata ->Item item

    public Set<Integer,Item> metaItems = new HashSet<Integer,Item>();

 

    public MetaItem(int itemID)

    {

        super(itemID);

        setNoRepair();

        setMaxDamage(0);

        setHasSubTypes(true);

    }

 

    public void put(int metadata, Item item)

    {

        item.setNoRepair();

        item.setMaxDamage(0);

        item.setHasSubTypes(true);

 

        metaItems.put(metadata, item);

    }

 

    // do hooks to desired functions, like this:

 

    @Override

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister iconRegister)

    {

        for (Item i : metaItems.values())

        {

            i.icon = iconRegister.registerIcon(i.iconName);

        }

    }

 

    @Override

    public Icon getIconFromDamage(int metadata)

    {

        Item i = metaItems.get(metadata);

        return (i != null) ? i.icon : null;

    }

 

    // ...

}

[spoiler=MetaItem usage example]

public static final int METAID = -257

 

MetaItem mi = new MetaItem(metaItemID);

 

mi.metaItems.put(0, new ItemGeneric(METAID, ...));

mi.metaItems.put(20, new ItemFood(METAID, ...)); // own subclass from ItemFood

mi.metaItems.put(40, new ItemArmor(METAID, ...)); // own subclass from ItemArmor, possibly will work only for non damageable armor, e.g. damage handling need to be moved to nbt by mod developer

mi.metaItems.put(60, new ItemTool(METAID, ...)); // own subclass from ItemTool, possibly will work only for non damageable tools, e.g. damage handling need to be moved to nbt by mod developer

mi.metaItems.put(100, new ItemDust(METAID, ...));

mi.metaItems.put(200, new ItemIngot(METAID , ...));

mi.metaItems.put(300, new ItemPlate(METAID, ...));

 

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.