Posted February 20, 20169 yr 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
February 20, 20169 yr Try implementing IRecipe. public class RecipeMySword implements IRecipe { @Override public boolean matches(InventoryCrafting inv, World worldIn) { //this function return whether the item can be //crafted in the current crafting grid (InventoryCrafting object) //and world (Word object) } @Override public ItemStack getCraftingResult(InventoryCrafting inv) { //the item stack the player receive after the crafting //true output of the crafting so calculate here what he will get } @Override public ItemStack[] getRemainingItems(InventoryCrafting inv) { //delete the items from the grid using InventoryCrafting object return new ItemStack[0]; } @Override public int getRecipeSize() { //i heard that this is only for sorting purposes return 2; } @Override public ItemStack getRecipeOutput() { //Theoretical output of the crafting return new ItemStack(youritem); } } Then simply register it: GameRegistry.addRecipe(new RecipeMySword()); Also maybe you'll find this useful: http://www.minecraftforge.net/forum/index.php/topic,23133.0.html
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.