Hello, everyone. I originally posted this question on Minecraft's official forums but didn't get a response.
What I'm trying to do is create a mod that adds random loot to the game. I've been successful in some regards, but I've run into another problem that's been driving me nuts for days. Specifically, how to give each instance of a tool (in this case, a sword) a separate icon, as well as separate stats, without overriding any previously generated tool with the new tool's data.
I've created a chat command (a copy of CommandGive that makes the player drop a random sword generated by the CreateTestTool function below, instead of whatever item the user asks for) as a debug command, but when I generate more than one piece of loot, the icons of the previous pieces of loot change to the icon of the one that was just generated. Likewise, the stats of the previous piece of loot are overwritten with the stats of the new piece of loot.
I've been trying to wrap my head around why this happens for almost four days and I still can't figure it out. I can't use damage values to change the icons because these are tools, not items, and I've tried using NBTTags but I must be loading them in wrong because nothing really changes.
This is a relatively simple task, so there has to be something key I'm missing.
My code is below.
First is the function that generates the tool:
public ItemStack CreateTestTool()
{
String name = mod_epicloot.Namer.GenerateFullName();
int damage = LootGenHandler.GenerateDamageValue();
int uses = LootGenHandler.GenerateMaxUses();
int imgid = LootGenHandler.getRandomSwordImgID();
ItemStack is = null;
String[] loreText = {mod_epicloot.Namer.GenerateLore(), "",
"§r§7 *** DPS: §b" + Integer.toString(((damage + 4))) + " §7(§b" +
Double.toString((((damage + 4)/2))) + "§7 hearts)",
"§r§7 *** Base Durability: §b" + Integer.toString(uses)};
ItemRandomSword irs = (ItemRandomSword)mod_epicloot.irs;
EnumToolMaterial newMat = LootGenHandler.GenToolMaterialEnum(damage, uses);
is = new ItemStack(irs, 1);
is = LootGenHandler.setIconIndex(is, LootGenHandler.getRandomSwordImgID());
is.getItem().setIconIndex(LootGenHandler.getIconIndex(is));
is = mod_epicloot.Namer.setDisplayName(is, name);
is = mod_epicloot.Namer.setLore(is, loreText);
return is;
}
Next, is the ItemRandomSword class. I extended it from Item because I thought that would make things work but it's not much of a change. I'll probably just have it extend from ItemSword again.
http://pastebin.com/hYzTJGb8
And, finally, my LootGenHandler class, for reference. Everything is static because I'm stupid and thought that Java class functions had to be static in order to use them (which is only the case if you don't make an instance of the class first).
http://pastebin.com/EDBXzRTb
Any help would be appreciated. I think after I get over this hurdle, the rest of the mod would be relatively simple.
EDIT 11/30/12:
Here's my main mod file, if it helps at all:
http://pastebin.com/HMbnxRDE
And, finally, the code for the debug command I use:
package com.boxtop.epicloot;
import net.minecraft.src.*;
public class CommandGiveRand extends CommandBase
{
public String getCommandName()
{
return "gr";
}
/**
* Return the required permission level for this command.
*/
public int getRequiredPermissionLevel()
{
return 0;
}
public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
{
EntityPlayerMP var3 = getCommandSenderAsPlayer(par1ICommandSender);
var3.dropPlayerItem(LootGenHandler.CreateTestTool());
par1ICommandSender.sendChatToPlayer("[DEBUG] Gave you a random weapon.");
}
}