I'm trying to change the name of an item, but I just cant seem to get it right. The closest I've come is getting the server to recognize that it's a custom-named item, but it doesn't actually show the name in the tooltip. Anyone know what's wrong? Here's my code for the command: Code: if(commandLabel.equalsIgnoreCase("nugget")){ ItemStack nugget = new ItemStack(Material.GOLD_NUGGET); Namer.setName(nugget, "My nuggets"); PlayerInventory pi = player.getInventory(); pi.addItem(nugget); } Also here's a link to the page of the Library that I'm using for it : http://forums.bukkit.org/threads/lib-prettyscarylib.110164/ Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You can change the name of items with an anvil, so this Library just enables you to do it without an anvil. I'm going to assume you don't know how to do it Right.
This is a method I got from someone for renaming items. I use it in my auto-rename plugin Code: public ItemStack renameItem(ItemStack is, String newName) { //Get the nms item stack CraftItemStack cis = ((CraftItemStack)is); //Gets the NBTTagCompound for the item stack NBTTagCompound tag = cis.getHandle().getTag(); //If the tag doesnt exist, create one. if(tag == null) { cis.getHandle().setTag(new NBTTagCompound()); tag = cis.getHandle().getTag(); } //Check if the item stacks tag has a sub tag called "display" (im assuming this holds all of the new stuff for the item stack display and lore stuff, such as name and flavor text) If it doesnt have the tag, create one. It will most likely not have the tag if it doesnt have any display information. The server may use this to determine whether or not to color the items nameplate purple or not. But thats just me speculating. if(tag.getCompound("display") != null) { tag.setCompound("display", new NBTTagCompound()); } // Gets the display tag. NBTTagCompound display = tag.getCompound("display"); //Removes the old name display.remove("Name"); //sets the new name display.setString("Name", newName); //Returns the item stack. Technically it is the same object that you passed into the method, but returning is just for convenience. You need to remove, and readd the item stack to the players inventory for the effects to show up. return is; } EDIT: This works without any library
Very impressive, I'll try it now Not to be a bother but could you explain the renameItem part? Eclipse isn't recognizing it. Forgive the noobishness, I'm a beginner at Java. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I'm sorry 1.4 does allow you to rename items as you go, but I had thought you were asking how to get the client to universally recognize all of one type of item as a different name, which isn't the same thing. My bad/
All good man! I'm trying to rename all of the gold nuggets that drop to be named "Token". It still functions as a gold nugget but its a little cooler if it's named a token, since that's what it represents on my server. Anyway, honest mistake. Don't suppose you understand the code block Jogy34 posted?
Appljuze If you are wishing to modify the name every time it's dropped, check the itemdropevent, if the item is goldnugget, change it to your thing
I would assume you need to import CraftBukkit in addition to Bukkit to use NBT tags and CraftItemStacks.(I am guessing that you probably had forgotten or not realized that) Also just remember that gold nuggets can also be obtained by craftbenching gold ingots so don't forget to rename during that too.
That's it's own method. Call it when the nugget is dropped or whatever. Note: Renaming items doesn't work with plugins like MultiInv which serialize itemstacks, as they don't serialize the names.
ItemStack is an immuatble object, meaning that you cannot change it using static methods. here's some pseudo-code to redefine a String (which also happens to be immutable) Code:java String boom = "BOOM";boom.toLowerCase(); System.out.println(boom); //Prints BOOM boom = boom.toLowerCase(); System.out.println(boom); //Prints boom in your case, you would have to use something like: Code:java nugget = Namer.setName(nugget, "Nugget");
Okay that makes sense, ill try this out THATS what i was looking for. Thanks! Let me try it. THATS what i was looking for. Thanks! Let me try it. Do you know offhand what the player-picked-up-an-item method is? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Auto rename does the same thing this thread is describing, however the itemrenamer is... interesting... I guess I may have to admit defeat and say I was wrong.