Posted March 25, 201411 yr I am trying to trigger a texture and name change on a tool when some NBT stored data reaches a limit. Is there any way I can get this to work? I know that the follow code does not work because I have tried it myself and also from what little understanding on programming I have. Could I get some assistance with this please. I am a bit stuck to be honest. I have made lots of progress with the rest of my mod thanks to coolAlias and others help but I just need a little more feedback. Sorry if I am being a little impatient but I can't help my personality and psychology. if (evometer.getInteger("evolutionMeter") >= 30) { this.setTextureName("evolvinggearmod:FleshBoundPick"); this.setUnlocalizedName(toolNameFlesh); } } return When the evolution meter reaches 30 + changed item texture and name but not swap the actual item. Just change the way it looks and its name. But when I do this the texture doesn't change and the name becomes weird. Like name.FleshBoundPickaxe.## etc Any thoughts? The issue I think I am having is with that current code I am effectivly changing the entire item types name and texture. When what I want to be doing is just changing the texture and name and stats of the currently held item as its own thing. I just don't know how to work that out. Would I be able to do something with NBT data? //////// The other option I have is that I swap items entirely but then I need to somehow carry over NBT data. Is that possible? If so, how? An example of some kind helps a lot. That is the best way I absorb information. By example and practical applications.
March 25, 201411 yr Don't use the setters after the initialization. Override the getters for your behavior. @Override public IIcon getIcon(ItemStack stack){ if(stack.hasTagCompound){ //etc. } return default; }
March 26, 201411 yr Author Could you explain a little more in depth? I understand that I don't want to be using the setters because that is messing things up, changing the item type in general but I don't see how I can use a getter because don't they only get the information? Not let me change the information? getIcon doesn't let me change the icon does it? I also want to change the texture in game or is the icon part of it misleading?
March 26, 201411 yr Hi This link might help http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html In particular http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-inventory-items.html .getIcon is called by the renderer every time your item is rendered. If you override getIcon to return a different texture, the item will be rendered using that different texture. -TGG
March 26, 201411 yr Author The method getIcon(ItemStack) of type FusedBonePickaxe must override or implement a supertype method Thats what I get when I try what you suggested GotoLink. Nice posts by TheGreyGhost. Is helping in some ways but I still can quite understand how to get my texture to change when the if statement tells it to. Also how would I change the name of an item in real time like I am trying to change the texture. I am basically wanting my item to transform into another while keeping all its NBT data. The only way I can think of getting this to work is that the item stays the same and its texture and name changes. OR the item does change but I then somehow have to get the NBT data to transfer over. I am not an experience programmer by any means. I am just trying to work my way through this and learn as I go. Also my source files dont work as I get a gradle setup issue. Forge could not decomp. No idea why. I have posted many topics on different forums and noone knows how to fix it.
March 27, 201411 yr Author Hi guys! I still have figure out how to change texture of a tool in realtime without changing the actual item which is not possible for the mod I am making. Any help with getting a texture to change would be appreciated. Those guides by TheGreyGhost are great but I still can't get my tools textures to change.
March 27, 201411 yr Hi You could try something like this (In your Item class:) private static Icon itemIcon1; private static Icon itemIcon1; @Override public void registerIcons(IconRegister iconRegister) { itemIcon1 = iconRegister.registerIcon("myMod:itemIcon1"); itemIcon2 = iconRegister.registerIcon("myMod:itemIcon1"); } @Override public Icon getIconIndex(ItemStack thisItem) { int evolutionMeter = thisItem.getTagCompound.getInteger("evolutionMeter"); // add error -checking here yourself... if (evolutionMeter >= 30) { return itemIcon1; } else { return itemIcon2; } } Disclaimer: I haven't tried to compile this code so it might have some errors in it, but the concepts should work. (Based on GotoLink's answer, just that the method name was slightly wrong) -TGG
March 27, 201411 yr Author Dude! Thanks for the fast response! Will give this ago. Appreciate the help! Also what do you think of Eclipse vs IntelliJ ? Or are they more or less the same really ?
March 27, 201411 yr Author @Override public Icon getIconIndex(ItemStack thisItem){ } gives me attempting to use incompatible return type. Any ideas? I am currently using IntelliJ Idea btw. I actually prefer it for the most part.
March 27, 201411 yr Author Ahh I figured it out, its IIcon for 1.7.2 latest version. Not Icon. Thats all
March 27, 201411 yr Hi keen, glad you figured it out :-) I use IntelliJ and I think it's awesome. With the gradle build it's become really easy to set up. I've had no experience with Eclipse so I can't really comment, except that plenty of other folks use it so it must be good enough! -TGG
March 27, 201411 yr Author Right I have it working. In fashion anyway! @Override public IIcon getIconIndex(ItemStack thisItem) { NBTTagCompound evopoints = thisItem.getTagCompound(); if (evopoints == null) {evopoints = new NBTTagCompound();} if (!evopoints.hasKey("evolutionPoints")) {evopoints.setInteger("evolutionPoints", 0);} thisItem.setTagCompound(evopoints); if (evopoints.getInteger("evolutionPoints") >= 20) { System.out.println("Changing Icon"); return itemIconFleshBound; } else { return itemIconFusedBone; } } At the right number as in >= 20 it swaps texture. But it swaps to a texture that is blank. The black and purple checkerboard texture. Any ideas? I have my @Override registerIcons method just above that or does that need to be at the top of my items class file? Right at the top? I will check it out.
March 27, 201411 yr Hi The checkerboard probably means that your itemIconFleshBound texture file was not found. Check the error log for "Using missing texture, unable to load". If you search this forum for that keyword, you'll turn up a number of posts talking about how to fix that. -TGG
March 27, 201411 yr Author Right I solved that issue. But not the item is invisible in my hands. The icon on the hotbar and inventory changes but its invisible in my hands both as the original tool and as the new texture Yeah I have no idea how to solve this. Hehe
March 27, 201411 yr Author Sorry for bumping but I just need a little help. Many google and forge forum searches has yielded no results related to my problem. I have found people with invisible block which were then solves by changing texture locations but I am not have that issue. It finds the textures. No errors or anything. The textures of the items change as items in my inventory and in my hotbar as well as when thrown onto the ground. The problem is that when I hold the items / tools to use them to break stuff etc, they do not render. They are invisible. Any ideas anyone? Appreciated.
March 27, 201411 yr I don't believe that getIconIndex is used by the in-hand render calls, though I haven't double-checked. Try overriding a different method(s) in your Item class, such as: public IIcon getIcon(ItemStack stack, int pass) Alternatively, you could implement an IItemRender for your Item and handle the NBT data that way, but I doubt that will be necessary. http://i.imgur.com/NdrFdld.png[/img]
March 27, 201411 yr Author What you suggested coolAlias has not solved my item being invisible issue but not the icon in the inventory and hot bar is purple and black checkerboard
March 27, 201411 yr What you suggested coolAlias has not solved my item being invisible issue but not the icon in the inventory and hot bar is purple and black checkerboard I just tried it and it worked perfectly. That method did not change the inventory Icon, but it DID change the one held in my hand, so you need to use both. This is the code I used for testing: public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } int icon = (stack.getTagCompound().getInteger("icon") + 1) % 3; stack.getTagCompound().setInteger("icon", icon); return stack; } public IIcon getIcon(ItemStack stack, int pass) { int icon = (stack.hasTagCompound() ? stack.getTagCompound().getInteger("icon") : 0); switch (icon) { case 1: return Items.wooden_axe.getIconFromDamage(0); case 2: return Items.iron_axe.getIconFromDamage(0); case 3: return Items.diamond_axe.getIconFromDamage(0); default: return itemIcon; } } If you have registered your IIcons and stored them in your Item class, you can return them directly. I used vanilla items just for the sake of testing. http://i.imgur.com/NdrFdld.png[/img]
March 27, 201411 yr Author This is my IIcon getIcon Stuff @Override public IIcon getIcon(ItemStack thisItem, int pass) { NBTTagCompound evopoints = thisItem.getTagCompound(); if (evopoints == null) {evopoints = new NBTTagCompound();} if (!evopoints.hasKey("evolutionPoints")) {evopoints.setInteger("evolutionPoints", 0);} thisItem.setTagCompound(evopoints); if (evopoints.getInteger("evolutionPoints") >= 5 && (evopoints.getInteger("evolutionPoints") <= 9)) { //this.setMaxDamage(45); return itemIconFleshBound; } else if (evopoints.getInteger("evolutionPoints") >= 10 && (evopoints.getInteger("evolutionPoints") <= 14)) { //this.setMaxDamage(46); return itemIconHideCoated; } else if (evopoints.getInteger("evolutionPoints") >= 15) { //this.setMaxDamage(47); return itemIconScaleArmored; } else{ return itemIconFusedBone; } } This is my registerIcons @Override public void registerIcons(IIconRegister iconRegister) { itemIconFusedBone = iconRegister.registerIcon("evolvinggearmod:FusedBonePick"); itemIconFleshBound = iconRegister.registerIcon("evolvinggearmod:FleshBoundPick"); itemIconHideCoated = iconRegister.registerIcon("evolvinggearmod:HideCoatedPick"); itemIconScaleArmored = iconRegister.registerIcon("evolvinggearmod:ScaleArmoredPick"); } This setup gives me my items in my hand visible but the items in my inv and on the floor as purple and black btw. Will give you suggestion a try but they are effectively the same are they not? So what is causing my weird texture problem?
March 27, 201411 yr Author Yeah you were right. Running both of those fixed the issue. Any idea or explanation as to why it works this way?
March 27, 201411 yr Author Having a hard time thinking today. If I wanted to create a method to change my tools durability and efficiency and then have it called to change the durability when a variable is reached? I can change the weapons durability easily however I am struggling with changing its efficiency. I would prefer having a method that is called when a number is reached and it then applies a load of stats to the tool at that point. I just can't think of how. I have tried loads of this which have failed and I had one working earlier but I hastily deleted it thinking I could do it again later. Arghhg
March 27, 201411 yr Author I HAVE DONE IT! VICTORY! YAY! HURRAY! Thanks for your help guys. Made huge progress today thanks to all your help and guidance!
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.