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

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, ...));

 

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.