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

Create a

StaffInventory

instance from the

ItemStack

's NBT, then use the methods of

StaffInventory

to check the item in the slot.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

So i did

ย 

public ItemStack stack; // I created a new ItemStack because it needed a parameter

StaffInventory staffInv = new StaffInventory(stack);

ย 

ย 

@Override

public IIcon getIconIndex(ItemStack itemstack)

{

ย  ย  ย  ย  if(staffInv.getStackInSlot(0).equals(MItems.FireCrystal)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[staff.length];

ย  ย  ย  ย  }

ย 

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[empty.length];

ย  ย  ย  ย  }

}

ย 

  • Author

Alright, i moved it in my getIconIndex method and used that ItemStack's parameter.

ย 

ย 

ย 

@Override

public IIcon getIconIndex(ItemStack itemstack)

{

ย  ย  ย  StaffInventory staffInv = new StaffInventory(itemstack);

ย  ย  ย  if(staffInv.getStackInSlot(0).equals(MItems.FireCrystal)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[staff.length];

ย  ย  ย  ย  }

ย 

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[empty.length];

ย  ย  ย  ย  }

}

ย 

ย 

IInventory#getStackInSlot

returns an

ItemStack

,

MItems.FireCrystal

is an

Item

; so the two will never be equal.

ย 

You need to check that the

ItemStack

in the slot isn't

null

, then call

ItemStack#getItem

to get its

Item

.

Item

s are singletons (only one instance exists per item type), so they should be compared with

==

rather than the

equals

method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

ย 

@Override

public IIcon getIconIndex(ItemStack itemstack)

{

ย  ย  ย  StaffInventory staffInv = new StaffInventory(itemstack);

ย  ย  ย  if(staffInv.getStackInSlot(1) != null && itemstack.getItem() == MItems.FireCrystal)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[staff.length];

ย  ย  ย  ย  }

ย 

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  return staffTexture[empty.length];

ย  ย  ย  ย  }

}

ย 

Slot numbers are 0-based, like most things in Minecraft/Java. 0 is the first slot, 1 is the second.

ย 

Why are you using the lengths of two unrelated arrays as indexes to your icon array? Are you ever actually initialising the icon array?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

I would have one array but i don't know how to switch between them

ย 

private IIcon[staffTexture];

private static String[] staff = new String[] {RefStrings.MODID + ":elementStaff_fire"};

private static String[] empty = new String[] {RefStrings.MODID + ":elementStaff_empty"};

You really need to read up on the basics of Java, including how arrays work. What you posted won't even compile.

ย 

You need two fields here: a

String

array containing the names of both icons (set in the field initialiser) and an

IIcon

array containing the icons (not set in the field initialiser).

ย 

In your override of

Item#registerIcons

, do the following:

  • Set the icon array field to a new array of the same length as the icon name array
  • Iterate through the icon name array, calling
    IIconRegister#registerIcon

    for each icon name and storing the returned

    IIcon

    in the same index of the icon array

ย 

In your override of

Item#getIconIndex

, return the appropriate

IIcon

from the icon array (i.e. the one at index 0 or 1).

ย 

Since you only have two icons, you could also use two separate

IIcon

fields instead of an array.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

You really need to go learn programming before modding.ย  What you are trying to do is really quite straight forward.

ย 

This won't solve your problem, but it will show you how I handled something similar.

ย 

	@Override
public IIcon getIcon(ItemStack stack, int pass)
ย  ย  {
	IIcon i = itemIcon;
	if(pass == 0) {
		if(stack.stackTagCompound == null) {
			return itemIcon;
		}
		i = (IIcon) ArtifactsAPI.itemicons.icons.get(stack.stackTagCompound.getString("icon").toLowerCase());
		if(i == null) {
			i = itemIcon;
		}
	}
	else {
		if(stack.stackTagCompound == null) {
			return (IIcon) ArtifactsAPI.itemicons.icons.get("overlay_artifact1");
		}
		i = (IIcon) ArtifactsAPI.itemicons.icons.get("overlay_"+stack.stackTagCompound.getString("icon").toLowerCase());
		if(i == null) {
			i = (IIcon) ArtifactsAPI.itemicons.icons.get("overlay_artifact1");
		}
	}
	return i;
ย  ย  }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.ย  If you think this is the case, JUST REPORT ME.ย  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

ย 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

ย 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.