TLHPoE Posted November 18, 2014 Posted November 18, 2014 Hello, I think there's a glitch with using the itemstack-sensitive version of the Item#getIconIndex method. What I'm attempting is using a different texture when a certain tag is true in the itemstack's NBT. Picture: As you can see, the icon in the hotbar changed but not the actual 3D item. Additionally, the item in 3rd person mod has the same texture still too. Code: package tf2crates.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; import tf2crates.ReferenceTC; import tf2crates.ServerProxyTC; import tf2crates.crate.RandomLoot; import tf2crates.entity.DamageSourceBackstab; import tlhpoeCore.network.MessagePlaySound; import tlhpoeCore.util.MiscUtil; public class ItemKnife extends ItemSword { public static double backstabDifficulty = 0.75D; public IIcon goldTexture; public ItemKnife(String name) { super(ServerProxyTC.MOD_WEAPON); this.setUnlocalizedName(name); this.setTextureName(ReferenceTC.ID + ":weapon/" + name); RandomLoot.WEAPONS.add(this); } public ItemKnife(String name, float dmg) { this(name); MiscUtil.replaceField("field_150934_a", ItemSword.class, dmg, this); } @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister register) { super.registerIcons(register); this.goldTexture = register.registerIcon(ReferenceTC.ID + ":weapon/gold/" + this.getUnlocalizedName().substring(5)); } @Override @SideOnly(Side.CLIENT) public IIcon getIconIndex(ItemStack itemStack) { NBTTagCompound nbt = itemStack.getTagCompound(); if(nbt != null && nbt.getBoolean("Golden")) { return this.goldTexture; } return super.getIconIndex(itemStack); } @Override public boolean hitEntity(ItemStack itemStack, EntityLivingBase prey, EntityLivingBase attacker) { itemStack.damageItem(1, attacker); float pYaw = prey.rotationYawHead % 360F; pYaw = pYaw < 0 ? 360 + pYaw : prey.rotationYawHead; float aYaw = attacker.rotationYawHead < 0 ? 360 + attacker.rotationYawHead : attacker.rotationYawHead; float newRot = pYaw - aYaw; if(newRot < (90 * backstabDifficulty) && newRot > (-90 * backstabDifficulty)) { if(!attacker.worldObj.isRemote) { new MessagePlaySound(ReferenceTC.ID + ":tf2crates.crit").sendTo((EntityPlayerMP) attacker); } attacker.heal(prey.getMaxHealth()); prey.attackEntityFrom(DamageSourceBackstab.BACKSTAB, prey.getMaxHealth() * 600); } return false; } } Quote Kain
Ernio Posted November 18, 2014 Posted November 18, 2014 Inventory Icon (ItemIconIndex) is not equal (in terms of renderers) to Item 3d icon (ItemIcon). The itemstack-sensitive version is used to e.g make animated inventory icons (tho it should be made by resourcepacks). Example from my mod: @Override public IIcon getIconIndex(ItemStack stack) { if (stack.getTagCompound() != null) //should be more NBT checks here { return longswordIconStorage.get(stack.getTagCompound().getString("texture")); } return this.itemIcon; } @Override public IIcon getIcon(ItemStack stack, int pass) { if (stack.getTagCompound() != null) //should be more NBT checks here { return longswordIconStorage.get(stack.getTagCompound().getString("texture")); } return this.itemIcon; } Where longswordIconStorage is my Icon registry. And this.itemIcon is my default Icon. Quote 1.7.10 is no longer supported by forge, you are on your own.
Recommended Posts
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.