Hello guys,
i am trying to learn modding with forge and got my first problem and i don't have a solution for this. I hope you can help me.
I tried to make a sword, which can be "upgraded" by crafting it with a diamond.
GameRegistry.addShapelessRecipe(stackSaphire_sword, stackSaphire_sword, stackDiamond);
So I used the on-Crafted method in my SaphireSword class and nbt tags to make the "upgrade" become visible. But it should not everytime succeed. First you have a 50% to 50% chance to succeed.
Got all this with the on-Crafted method but now I tried to delete the crafting result but only if it fails. The idea is that you have a 50% chance upgrading your item. On the other hand it could be deleted. And I don't know how i can do this. How do I delete a crafting result after getting it out of the craftingtable?
I tried to dmg the Item to delete it but i was still there full damaged. Here is my Code Snippet.
My whole class is on pastebin: http://pastebin.com/dGguFT5A
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
tooltip.add("Dieses Item gehört: " + getNBTTag(stack, TAG_PLAYERNAME));
if(upgrade >= 1) {
tooltip.add("Stufe: " + upgrade);
}
}
@Override
public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) {
if(!playerIn.worldObj.isRemote) {
checkUpdate();
if (getRandomNumber() == 2 && upgrade < 10) {
addOneToUpgrade();
setNBTData(stack, playerIn);
}
else {
//How do i delet the crafting result?
}
}
}
public static void addOneToUpgrade() {
upgrade++;
}
public int getRandomNumber() {
int zufallszahl = (int) ((Math.random()*range)+1);
return zufallszahl;
}
public static void checkUpdate() {
switch (upgrade) {
case 0:
range = 2; //50%
break;
case 1:
range = 2; //50%
break;
case 2:
range = 3; //33%
break;
case 3:
range = 3; //33%
break;
case 4:
range = 3; //33%
break;
case 5:
range = 4; //25%
break;
case 6:
range = 4; //25%
break;
case 7:
range = 5; //20%
break;
case 8:
range = 5; //20%
break;
case 9:
range = 6; //17%
break;
default:
break;
}
}
I hope you can help me.
Greeting Dennis