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

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:

2K9lmOq.png

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;
}
}

Kain

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.

1.7.10 is no longer supported by forge, you are on your own.

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.