January 24, 20169 yr 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.
January 24, 20169 yr 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]; } }
January 24, 20169 yr 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]; } }
January 24, 20169 yr 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.
January 24, 20169 yr 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]; } }
January 24, 20169 yr 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.
January 24, 20169 yr 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"};
January 24, 20169 yr 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.
January 25, 20169 yr 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.