I just created a little API to rename any item you want in Minecraft 1.4. It changes itemnames like using an anvil. You can easily copy+paste it from here: http://pastie.org/5126792 Easy to use: Code: ItemStack anvil = new ItemStack(Material.ANVIL); NamedItemStack namedItemStack = new NamedItemStack(anvil); // Give it a name namedItemStack.setName("Minecraft 1.4 is there!"); // Reset the name to default namedItemStack.setName(null); // Get the item's name (returns null if it hasn't been renamed) namedItemStack.getName();
I get an exception: Code: Caused by: java.lang.ClassCastException: org.bukkit.inventory.ItemStack cannot b e cast to org.bukkit.craftbukkit.inventory.CraftItemStack On this line: (Line 14) Code: CraftItemStack cis = ((CraftItemStack)this.itemStack); How can I fix this?
Have you checked your imports? I believe you're casting a net.minecraft-ItemStack to a CraftItemStack.
That's because the class above expects a CraftItemStack - that is, an item stack that's created by Minecraft and wrapped by Craftbukkit, and not a bog standard "Bukkit" item stack. To be fair, that's exactly what OP did in the code example (which is clearly not tested). To fix this, convert the ItemStack you created to a CraftItemStack first: Code:java private void performAction(Player player) { ItemStack brick = toCraftBukkit(new ItemStack(Material.BRICK)); NamedItemStack namedItemStack = new NamedItemStack(brick); namedItemStack.setName("Minecraft 1.4 is there!"); player.setItemInHand(brick);} private static ItemStack toCraftBukkit(ItemStack stack) { if (!(stack instanceof CraftItemStack)) return new CraftItemStack(stack); else return stack;}
The code was tested and works fine for me. EDIIT: Ahhh.. now I know what you mean, I'll fix it when I come home.
This doesn't work right... And by that i mean that there are no errors or anything, it just doesn't rename it... and in case it matters i'm trying to rename a redstone